From a2e16b492208de3ced7ba4b9eac9a13912d8597c Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 25 Jun 2013 14:02:31 +1000 Subject: [PATCH] Fixed up gravatar with a watch, started implementing legacy proxy JS notification calls to our angular services. --- .../lib/umbraco/LegacySpeechBubble.js | 58 +++++ .../lib/umbraco/LegacyUmbClientMgr.js | 221 ++++++++---------- .../common/directives/umbavatar.directive.js | 8 +- .../common/services/notifications.service.js | 34 ++- .../src/common/services/utill.service.js | 27 +++ .../umbraco_client/Panel/style.css | 2 +- src/Umbraco.Web/UI/JavaScript/JsInitialize.js | 1 + 7 files changed, 208 insertions(+), 143 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/lib/umbraco/LegacySpeechBubble.js diff --git a/src/Umbraco.Web.UI.Client/lib/umbraco/LegacySpeechBubble.js b/src/Umbraco.Web.UI.Client/lib/umbraco/LegacySpeechBubble.js new file mode 100644 index 0000000000..6efb8ad8f3 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/lib/umbraco/LegacySpeechBubble.js @@ -0,0 +1,58 @@ + +//TODO: WE NEED TO CONVERT ALL OF THESE METHODS TO PROXY TO OUR APPLICATION SINCE MANY CUSTOM APPS USE THIS! + +Umbraco.Sys.registerNamespace("Umbraco.Application"); + +(function($) { + Umbraco.Application.SpeechBubble = function() { + + /** + * @ngdoc function + * @name getRootScope + * @methodOf UmbClientMgr + * @function + * + * @description + * Returns the root angular scope + */ + function getRootScope() { + return angular.element(document.getElementById("umbracoMainPageBody")).scope(); + } + + /** + * @ngdoc function + * @name getRootInjector + * @methodOf UmbClientMgr + * @function + * + * @description + * Returns the root angular injector + */ + function getRootInjector() { + return angular.element(document.getElementById("umbracoMainPageBody")).injector(); + } + + + return { + + /** + * @ngdoc function + * @name ShowMessage + * @methodOf Umbraco.Application.SpeechBubble + * @function + * + * @description + * Proxies a legacy call to the new notification service + */ + ShowMessage: function (icon, header, message) { + //get our angular navigation service + var injector = getRootInjector(); + var notifyService = injector.get("notificationsService"); + notifyService.success(header, message); + } + }; + }; +})(jQuery); + +//define alias for use throughout application +var UmbSpeechBubble = new Umbraco.Application.SpeechBubble(); diff --git a/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js b/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js index 7fdd2c4c25..5bf8adb0e3 100644 --- a/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js +++ b/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js @@ -42,11 +42,14 @@ Umbraco.Sys.registerNamespace("Umbraco.Application"); _rootPath: "/umbraco", //this is the default _modal: new Array(), //track all modal window objects (they get stacked) - historyManager: function() { - if (!this._historyMgr) { - this._historyMgr = new Umbraco.Controls.HistoryManager(); - } - return this._historyMgr; + historyManager: function () { + + throw "Not implemented!"; + + //if (!this._historyMgr) { + // this._historyMgr = new Umbraco.Controls.HistoryManager(); + //} + //return this._historyMgr; }, setUmbracoPath: function(strPath) { @@ -58,69 +61,60 @@ Umbraco.Sys.registerNamespace("Umbraco.Application"); }, mainWindow: function() { - /// - /// Returns a reference to the main frame of the application - /// return top; }, mainTree: function() { - /// - /// Returns a reference to the main UmbracoTree API object. - /// Sometimes an Umbraco page will need to be opened without being contained in the iFrame from the main window - /// so this method is will construct a false tree to be returned if this is the case as to avoid errors. - /// - /// + + throw "Not implemented!"; - if (this._mainTree == null) { - if (this.mainWindow().jQuery == null - || this.mainWindow().jQuery(".umbTree").length == 0 - || this.mainWindow().jQuery(".umbTree").UmbracoTreeAPI() == null) { - //creates a false tree with all the public tree params set to a false method. - var tmpTree = {}; - var treeProps = ["init", "setRecycleBinNodeId", "clearTreeCache", "toggleEditMode", "refreshTree", "rebuildTree", "saveTreeState", "syncTree", "childNodeCreated", "moveNode", "copyNode", "findNode", "selectNode", "reloadActionNode", "getActionNode", "setActiveTreeType", "getNodeDef"]; - for (var p in treeProps) { - tmpTree[treeProps[p]] = function() { return false; }; - } - this._mainTree = tmpTree; - } - else { - this._mainTree = this.mainWindow().jQuery(".umbTree").UmbracoTreeAPI(); - } - } - return this._mainTree; + //if (this._mainTree == null) { + // if (this.mainWindow().jQuery == null + // || this.mainWindow().jQuery(".umbTree").length == 0 + // || this.mainWindow().jQuery(".umbTree").UmbracoTreeAPI() == null) { + // //creates a false tree with all the public tree params set to a false method. + // var tmpTree = {}; + // var treeProps = ["init", "setRecycleBinNodeId", "clearTreeCache", "toggleEditMode", "refreshTree", "rebuildTree", "saveTreeState", "syncTree", "childNodeCreated", "moveNode", "copyNode", "findNode", "selectNode", "reloadActionNode", "getActionNode", "setActiveTreeType", "getNodeDef"]; + // for (var p in treeProps) { + // tmpTree[treeProps[p]] = function() { return false; }; + // } + // this._mainTree = tmpTree; + // } + // else { + // this._mainTree = this.mainWindow().jQuery(".umbTree").UmbracoTreeAPI(); + // } + //} + //return this._mainTree; }, appActions: function() { - /// - /// Returns a reference to the application actions object - /// + + throw "Not implemented!"; - //if the main window has no actions, we'll create some - if (this._appActions == null) { - if (typeof this.mainWindow().appActions == 'undefined') { - this._appActions = new Umbraco.Application.Actions(); - } - else this._appActions = this.mainWindow().appActions; - } - return this._appActions; + ////if the main window has no actions, we'll create some + //if (this._appActions == null) { + // if (typeof this.mainWindow().appActions == 'undefined') { + // this._appActions = new Umbraco.Application.Actions(); + // } + // else this._appActions = this.mainWindow().appActions; + //} + //return this._appActions; }, uiKeys: function() { - /// - /// Returns a reference to the main windows uiKeys object for globalization - /// - - //TODO: If there is no main window, we need to go retrieve the appActions from the server! - return this.mainWindow().uiKeys; + + throw "Not implemented!"; + + ////TODO: If there is no main window, we need to go retrieve the appActions from the server! + //return this.mainWindow().uiKeys; }, - // windowMgr: function() - // return null; - // }, contentFrameAndSection: function(app, rightFrameUrl) { - //this.appActions().shiftApp(app, this.uiKeys()['sections_' + app]); - var self = this; - self.mainWindow().UmbClientMgr.historyManager().addHistory(app, true); - window.setTimeout(function() { - self.mainWindow().UmbClientMgr.contentFrame(rightFrameUrl); - }, 200); + + throw "Not implemented!"; + + ////this.appActions().shiftApp(app, this.uiKeys()['sections_' + app]); + //var self = this; + //self.mainWindow().UmbClientMgr.historyManager().addHistory(app, true); + //window.setTimeout(function() { + // self.mainWindow().UmbClientMgr.contentFrame(rightFrameUrl); + //}, 200); }, /** @@ -137,7 +131,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Application"); if (!strLocation || strLocation == "") { //SD: NOTE: We used to return the content iframe object but now I'm not sure we should do that ?! - return null; + return; } this._debug("contentFrame: " + strLocation); @@ -158,82 +152,53 @@ Umbraco.Sys.registerNamespace("Umbraco.Application"); navService.loadLegacyIFrame(strLocation); - //if (strLocation == null || strLocation == "") { - // if (typeof this.mainWindow().right != "undefined") { - // return this.mainWindow().right; - // } - // else { - // return this.mainWindow(); //return the current window if the content frame doesn't exist in the current context - // } - //} - //else { - // //if the path doesn't start with "/" or with the root path then - // //prepend the root path - // if (strLocation.substr(0, 1) != "/") { - // strLocation = this._rootPath + "/" + strLocation; - // } - // else if (strLocation.length >= this._rootPath.length - // && strLocation.substr(0, this._rootPath.length) != this._rootPath) { - // strLocation = this._rootPath + "/" + strLocation; - // } - - // this._debug("contentFrame: parsed location: " + strLocation); - // var self = this; - // window.setTimeout(function() { - // if (typeof self.mainWindow().right != "undefined") { - // self.mainWindow().right.location.href = strLocation; - // } - // else { - // self.mainWindow().location.href = strLocation; //set the current windows location if the right frame doesn't exist int he current context - // } - // }, 200); - //} }, openModalWindow: function(url, name, showHeader, width, height, top, leftOffset, closeTriggers, onCloseCallback) { //need to create the modal on the top window if the top window has a client manager, if not, create it on the current window - //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. - } - } + 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. + // } + //} }, closeModalWindow: function(rVal) { - /// - /// will close the latest open modal window. - /// if an rVal is passed in, then this will be sent to the onCloseCallback method if it was specified. - /// - 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); - } + + throw "Not implemented!"; + + //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) { diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/umbavatar.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/umbavatar.directive.js index c92e25b876..df7c709ea4 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/umbavatar.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/umbavatar.directive.js @@ -14,8 +14,12 @@ function avatarDirective() { hash: '@' }, link: function(scope, element, attr, ctrl) { - //set the gravatar url - scope.gravatar = "http://www.gravatar.com/avatar/" + scope.hash + "?s=40"; + + scope.$watch("hash", function (val) { + //set the gravatar url + scope.gravatar = "http://www.gravatar.com/avatar/" + val + "?s=40"; + }); + } }; } diff --git a/src/Umbraco.Web.UI.Client/src/common/services/notifications.service.js b/src/Umbraco.Web.UI.Client/src/common/services/notifications.service.js index 1ade740a08..51301fff90 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/notifications.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/notifications.service.js @@ -1,5 +1,5 @@ angular.module('umbraco.services') -.factory('notificationsService', function ($rootScope, $timeout) { +.factory('notificationsService', function ($rootScope, $timeout, angularHelper) { var nArray = []; @@ -9,7 +9,7 @@ angular.module('umbraco.services') $timeout(function () { - $rootScope.$apply(function() { + angularHelper.safeApply($rootScope, function () { nArray.splice(index, 1); }); @@ -19,20 +19,30 @@ angular.module('umbraco.services') } return { - success: function (headline, message) { - return add({ headline: headline, message: message, type: 'success', time: new Date() }); + success: function (headline, message) { + angularHelper.safeApply($rootScope, function () { + return add({ headline: headline, message: message, type: 'success', time: new Date() }); + }); }, - error: function (headline, message) { - return add({ headline: headline, message: message, type: 'error', time: new Date() }); + error: function (headline, message) { + angularHelper.safeApply($rootScope, function() { + return add({ headline: headline, message: message, type: 'error', time: new Date() }); + }); }, - warning: function (headline, message) { - return add({ headline: headline, message: message, type: 'warning', time: new Date() }); + warning: function (headline, message) { + angularHelper.safeApply($rootScope, function() { + return add({ headline: headline, message: message, type: 'warning', time: new Date() }); + }); }, - remove: function (index) { - nArray.splice(index, 1); + remove: function (index) { + angularHelper.safeApply($rootScope, function() { + nArray.splice(index, 1); + }); }, - removeAll: function () { - nArray = []; + removeAll: function () { + angularHelper.safeApply($rootScope, function() { + nArray = []; + }); }, current: nArray, diff --git a/src/Umbraco.Web.UI.Client/src/common/services/utill.service.js b/src/Umbraco.Web.UI.Client/src/common/services/utill.service.js index ea124d9ba8..e81cfe4566 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/utill.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/utill.service.js @@ -1,5 +1,32 @@ /*Contains multiple services for various helper tasks */ +/** + * @ngdoc function + * @name umbraco.services.angularHelper + * @function + * + * @description + * Some angular helper/extension methods + */ +function angularHelper() { + return { + + /** + * @ngdoc function + * @name safeApply + * @methodOf angularHelper + * @function + * + * @description + * This checks if a digest/apply is already occuring, if not it will force an apply call + */ + safeApply: function (scope, fn) { + (scope.$$phase || scope.$root.$$phase) ? fn() : scope.$apply(fn); + } + }; +} +angular.module('umbraco.services').factory('angularHelper', angularHelper); + /** * @ngdoc factory * @name umbraco.services:umbPropertyEditorHelper diff --git a/src/Umbraco.Web.UI/umbraco_client/Panel/style.css b/src/Umbraco.Web.UI/umbraco_client/Panel/style.css index 7d188df5d4..c59ecd925a 100644 --- a/src/Umbraco.Web.UI/umbraco_client/Panel/style.css +++ b/src/Umbraco.Web.UI/umbraco_client/Panel/style.css @@ -1,6 +1,6 @@ .panel { margin: 0 auto; /* center for now */ - width: 17em; /* ems so it will grow */ + background: url(images/panel_bg.gif) top repeat-x; font-size: 100%; padding: 0px; diff --git a/src/Umbraco.Web/UI/JavaScript/JsInitialize.js b/src/Umbraco.Web/UI/JavaScript/JsInitialize.js index 7fd423feb0..a4a5eacec6 100644 --- a/src/Umbraco.Web/UI/JavaScript/JsInitialize.js +++ b/src/Umbraco.Web/UI/JavaScript/JsInitialize.js @@ -7,6 +7,7 @@ 'lib/umbraco/Extensions.js', 'lib/umbraco/NamespaceManager.js', 'lib/umbraco/LegacyUmbClientMgr.js', + 'lib/umbraco/LegacySpeechBubble.js', 'js/app.js',