2014-10-02 16:05:44 -04:00
'use strict' ;
2013-11-08 15:35:30 -05:00
2014-11-20 09:14:39 -05:00
var axe = require ( 'axe-logger' ) ;
var DialogCtrl = function ( $scope , $q , dialog ) {
var callback ;
//
// Set dialog disply functions
//
dialog . displayInfo = function ( options ) {
return $q ( function ( resolve ) {
setOptions ( options ) ;
resolve ( ) ;
} ) ;
} ;
dialog . displayError = function ( options ) {
return $q ( function ( resolve ) {
if ( options ) {
axe . error ( ( options . errMsg || options . message ) + ( options . stack ? ( '\n' + options . stack ) : '' ) ) ;
setOptions ( options ) ;
$scope . title = options . title || 'Error' ;
$scope . showBugReporter = ( typeof options . showBugReporter !== 'undefined' ? options . showBugReporter : ! options . title ) ; // if title is set, presume it's not an error by default
}
resolve ( ) ;
} ) ;
} ;
dialog . displayConfirm = function ( options ) {
return $q ( function ( resolve ) {
setOptions ( options ) ;
resolve ( ) ;
} ) ;
} ;
function setOptions ( options ) {
$scope . open = true ;
$scope . title = options . title ;
$scope . message = options . errMsg || options . message ;
$scope . faqLink = options . faqLink ;
$scope . positiveBtnStr = options . positiveBtnStr || 'Ok' ;
$scope . negativeBtnStr = options . negativeBtnStr || 'Cancel' ;
$scope . showNegativeBtn = options . showNegativeBtn || false ;
callback = options . callback ;
}
//
// Scope functions
//
2014-10-02 16:05:44 -04:00
$scope . confirm = function ( ok ) {
2014-11-20 09:14:39 -05:00
$scope . open = false ;
2013-11-08 15:35:30 -05:00
2014-11-20 09:14:39 -05:00
if ( callback ) {
callback ( ok ) ;
2014-10-02 16:05:44 -04:00
}
2014-11-20 09:14:39 -05:00
callback = undefined ;
2013-11-08 15:35:30 -05:00
} ;
2014-10-02 16:05:44 -04:00
} ;
2013-11-08 15:35:30 -05:00
2014-10-08 06:34:34 -04:00
module . exports = DialogCtrl ;