The current error dialog controller code is laid out like this:
/**
* Error Dialog Controller
*/
.controller('errorDialogCtrl',['$scope','$modalInstance','$translate','header','msg',function($scope,$modalInstance,$translate,header,msg){
//-- Variables -----//
$scope.header = (angular.isDefined(header)) ? header : $translate.instant('DIALOGS_ERROR');
$scope.msg = (angular.isDefined(msg)) ? msg : $translate.instant('DIALOGS_ERROR_MSG');
//-- Methods -----//
$scope.close = function(){
$modalInstance.close();
$scope.$destroy();
}; // end close
}]) // end ErrorDialogCtrl
And it is called like:
return {
/**
* Error Dialog
*
* @param header string
* @param msg string
* @param opts object
*/
error : function(header,msg,opts){
opts = _setOpts(opts);
return $modal.open({
templateUrl : '/dialogs/error.html',
controller : 'errorDialogCtrl',
backdrop: opts.bd,
keyboard: opts.kb,
windowClass: opts.wc,
size: opts.ws,
resolve : {
header : function() { return angular.copy(header); },
msg : function() { return angular.copy(msg); }
}
}); // end modal.open
}, // end error
Because resolve 2 uses pieces (header
and msg
), it is very difficult to extend the error dialog to support an error dialog that uses a different template.
Lets say I have a list of errors that need to be displayed, that list needs html intermixed with it to make the error more readable. Or say that I'd rather the designer make it look pretty and I just need to get that information to them.
So I set about using decorate ( #59 ) to extend the error dialog and bump into the issue of not being able to specify the template. No problem, I'll just call $modal.open
directly with a different templateUrl and essentially duplicate the error function in my decorator; at least I didn't have to write a new controller.... Oops, I can't do that because errorDialogCtrl
takes 2 and only 2 params in its resolve, header
and msg
which it then puts thru the translate function, effectively closing the door on extension.
Since resolve is completely internalized within the dialogs, I'm suggesting a change to pass resolve like this:
resolve : {
data: function( ) {
return {
header : angular.copy(header),
msg : angular.copy(msg);
}
}
And implementing the errorDialogCtrl like this:
.controller('errorDialogCtrl',['$scope','$modalInstance','$translate','data',function($scope,$modalInstance,$translate,data){
//-- Variables -----//
$scope.data = data;
$scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_ERROR');
$scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_ERROR_MSG');
//-- Methods -----//
$scope.close = function(){
$modalInstance.close();
$scope.$destroy();
}; // end close
}]) // end ErrorDialogCtrl
This allows all the old code and templates to function as before, but allows anyone to use the errorDialogCtrl
beyond it's current capabilities. data
might be the wrong name to use, maybe errorObj
or errorDetails
makes more sense, and this has not yet dealt with the difficulty in overriding the template still, but template could be moved to the opts
object easily enough and that would make the whole thing pretty easy to deal with using decorate.