Fixed the dialog service to be able to call registered callbacks even if the dialog is an iframe, this helps fix the legacy tree pickers, fixed up the legacy tree control so that it can load in new trees as well

This commit is contained in:
Shannon
2013-09-04 20:06:41 +10:00
parent b105bd305b
commit ecdfecd173
4 changed files with 84 additions and 80 deletions

View File

@@ -165,8 +165,12 @@ Umbraco.Sys.registerNamespace("Umbraco.Application");
//get our angular navigation service
var injector = getRootInjector();
var dialogService = injector.get("dialogService");
var dialogService = injector.get("dialogService");
var self = this;
//TODO: need to get the closeTriggers working for compatibility too somehow.
var dialog = dialogService.open({
template: url,
width: width,
@@ -174,57 +178,29 @@ Umbraco.Sys.registerNamespace("Umbraco.Application");
iframe: true,
show: true,
callback: function (result) {
if (typeof onCloseCallback == "function") {
onCloseCallback.apply(self, [result]);
}
dialog.hide();
}
});
// var m = new Umbraco.Controls.ModalWindow();
// this._modal.push(m);
// m.open(url, name, showHeader, width, height, top, leftOffset, closeTriggers, onCloseCallback);
//throw "Not implemented!";
////if this is the top window, or if the top window doesn't have a client manager, create the modal in this manager
//if (window == this.mainWindow() || !this.mainWindow().UmbClientMgr) {
// var m = new Umbraco.Controls.ModalWindow();
// this._modal.push(m);
// m.open(url, name, showHeader, width, height, top, leftOffset, closeTriggers, onCloseCallback);
//}
//else {
// //if the main window has a client manager, then call the main window's open modal method whilst keeping the context of it's manager.
// if (this.mainWindow().UmbClientMgr) {
// this.mainWindow().UmbClientMgr.openModalWindow.apply(this.mainWindow().UmbClientMgr,
// [url, name, showHeader, width, height, top, leftOffset, closeTriggers, onCloseCallback]);
// }
// else {
// return; //exit recurse.
// }
//}
});
return dialog;
},
closeModalWindow: function(rVal) {
getRootScope().$emit("closeDialogs");
if (rVal) {
//trigger the closeDialogs event with arguments, note: using the term 'outVal' since that is what is expected in the tree picker.
getRootScope().$emit("closeDialogs", { outVal: rVal });
}
else {
//no arg vals
getRootScope().$emit("closeDialogs");
}
//if (this._modal != null && this._modal.length > 0) {
// this._modal.pop().close(rVal);
//}
//else {
// //this will recursively try to close a modal window until the parent window has a modal object or the window is the top and has the modal object
// var mgr = null;
// if (window.parent == null || window.parent == window) {
// //we are at the root window, check if we can close the modal window from here
// if (window.UmbClientMgr != null && window.UmbClientMgr._modal != null && window.UmbClientMgr._modal.length > 0) {
// mgr = window.UmbClientMgr;
// }
// else {
// return; //exit recursion.
// }
// }
// else if (typeof window.parent.UmbClientMgr != "undefined") {
// mgr = window.parent.UmbClientMgr;
// }
// mgr.closeModalWindow.call(mgr, rVal);
//}
},
_debug: function(strMsg) {
if (this._isDebug) {

View File

@@ -34,16 +34,25 @@ angular.module('umbraco.services')
var dialogs = [];
/** Internal method that removes all dialogs */
function removeAllDialogs() {
function removeAllDialogs(args) {
for (var i = 0; i < dialogs.length; i++) {
var dialog = dialogs[i];
removeDialog(dialog);
removeDialog(dialog, args);
dialogs.splice(i, 1);
}
}
/** Internal method that handles closing a specific dialog */
function removeDialog(dialog) {
function removeDialog(dialog, args) {
//if there's arguments passed in then check if there's a callback registered in the current modal then call it.
//this occurs when the "closeDialogs" event is triggered with arguments.
if (args && dialog.data("modalCb") != null && angular.isFunction(dialog.data("modalCb"))) {
var cb = dialog.data("modalCb");
cb.apply(dialog, [args]);
}
dialog.modal("hide");
$timeout(function () {
@@ -72,9 +81,7 @@ angular.module('umbraco.services')
//Modal dom obj and unique id
var $modal = $('<div data-backdrop="false"></div>');
var id = templateUrl.replace('.html', '').replace('.aspx', '').replace(/[\/|\.|:\&\?\=]/g, "-") + '-' + scope.$id;
if(options.inline){
animationClass = "";
modalClass = "";
@@ -115,6 +122,9 @@ angular.module('umbraco.services')
$modal.modal('show');
}
//store the callback in the modal jquery data
$modal.data("modalCb", callback);
return $modal;
}
else {
@@ -133,6 +143,9 @@ angular.module('umbraco.services')
//append to body or other container element
container.append($modal);
//store the callback in the modal jquery data
$modal.data("modalCb", callback);
// Compile modal content
$timeout(function() {
$compile($modal)(scope);
@@ -207,8 +220,8 @@ angular.module('umbraco.services')
}
/** Handles the closeDialogs event */
$rootScope.$on("closeDialogs", function () {
removeAllDialogs();
$rootScope.$on("closeDialogs", function (evt, args) {
removeAllDialogs(args);
});
return {