diff --git a/mindplot/pom.xml b/mindplot/pom.xml index 53144cd4..69ffc0d9 100644 --- a/mindplot/pom.xml +++ b/mindplot/pom.xml @@ -195,6 +195,7 @@ collaboration/CollaborationManager.js collaboration/framework/AbstractCollaborativeFramework.js collaboration/framework/AbstractCollaborativeModelFactory.js + widget/ModalDialogNotifier.js widget/ToolbarNotifier.js widget/ToolbarItem.js widget/ToolbarPaneItem.js diff --git a/mindplot/src/main/javascript/LocalStorageManager.js b/mindplot/src/main/javascript/LocalStorageManager.js index 5156413c..1df06dfb 100644 --- a/mindplot/src/main/javascript/LocalStorageManager.js +++ b/mindplot/src/main/javascript/LocalStorageManager.js @@ -24,7 +24,7 @@ mindplot.LocalStorageManager = new Class({ saveMapXml:function (mapId, mapXml, pref, saveHistory, events) { localStorage.setItem(mapId + "-xml", mapXml); - events.onSuccess(); + events.onError({message:"It's not possible to save your changes because your mindmap has been modified by '%s'. Refresh the page and try again.", severity:"FATAL"}); }, discardChanges:function (mapId) { @@ -49,7 +49,6 @@ mindplot.LocalStorageManager = new Class({ if (xml == null) { throw new Error("Map could not be loaded"); } - } var parser = new DOMParser(); diff --git a/mindplot/src/main/javascript/PersistenceManager.js b/mindplot/src/main/javascript/PersistenceManager.js index 76caaf18..387a179d 100644 --- a/mindplot/src/main/javascript/PersistenceManager.js +++ b/mindplot/src/main/javascript/PersistenceManager.js @@ -44,10 +44,10 @@ mindplot.PersistenceManager = new Class({ var pref = JSON.encode(editorProperties); try { - this.saveMapXml(mapId, mapXml, pref, saveHistory, events,sync); + this.saveMapXml(mapId, mapXml, pref, saveHistory, events, sync); } catch (e) { console.log(e); - events.onError(); + events.onError(this._buildError()); } }, @@ -65,7 +65,7 @@ mindplot.PersistenceManager = new Class({ throw new Error("Method must be implemented"); }, - saveMapXml:function (mapId, mapXml, pref, saveHistory, events,sync) { + saveMapXml:function (mapId, mapXml, pref, saveHistory, events, sync) { throw new Error("Method must be implemented"); }, diff --git a/mindplot/src/main/javascript/RestPersistenceManager.js b/mindplot/src/main/javascript/RestPersistenceManager.js index 79842e32..82c0d2cd 100644 --- a/mindplot/src/main/javascript/RestPersistenceManager.js +++ b/mindplot/src/main/javascript/RestPersistenceManager.js @@ -55,7 +55,7 @@ mindplot.RESTPersistenceManager = new Class({ persistence.timestamp = responseText; }, onException:function (headerName, value) { - events.onError(); + events.onError(persistence._buildError()); }, onFailure:function (xhr) { var responseText = xhr.responseText; @@ -65,11 +65,12 @@ mindplot.RESTPersistenceManager = new Class({ if (contentType != null && contentType.indexOf("application/json") != -1) { try { error = JSON.decode(responseText); + events.onError(persistence._buildError(error)); } catch (e) { - throw "Unexpected error saving. Error response is not json object:" + responseText; + events.onError(persistence._buildError()); + throw new Error("Unexpected error saving. Error response is not json object:" + responseText); } } - events.onError(error); }, headers:{"Content-Type":"application/json", "Accept":"application/json"}, emulation:false, @@ -114,6 +115,20 @@ mindplot.RESTPersistenceManager = new Class({ urlEncoded:false }); request.put("false"); + }, + + _buildError:function (jsonSeverResponse) { + var message = jsonSeverResponse ? jsonSeverResponse.globalErrors[0] : null; + var severity = jsonSeverResponse ? jsonSeverResponse.globalSeverity : null; + + if (!message) { + message = $msg('SAVE_COULD_NOT_BE_COMPLETED'); + } + + if (!severity) { + severity = "INFO"; + } + return {severity:severity, message:message}; } } ); diff --git a/mindplot/src/main/javascript/widget/IMenu.js b/mindplot/src/main/javascript/widget/IMenu.js index 902a6f5b..3a79afb9 100644 --- a/mindplot/src/main/javascript/widget/IMenu.js +++ b/mindplot/src/main/javascript/widget/IMenu.js @@ -72,8 +72,6 @@ mindplot.widget.IMenu = new Class({ if (saveHistory) { $notify($msg('SAVING')); saveElem.setStyle('cursor', 'wait'); - } else { - console.log("Saving without history ..."); } // Call persistence manager for saving ... @@ -87,14 +85,16 @@ mindplot.widget.IMenu = new Class({ } menu.setRequireChange(false); }, + onError:function (error) { if (saveHistory) { saveElem.setStyle('cursor', 'pointer'); - var msg = error ? error.globalErrors : null; - if (!msg) { - msg = $msg('SAVE_COULD_NOT_BE_COMPLETED'); + + if (error.severity == "INFO") { + $notify(error.message); + } else { + $notifyModal(error.message); } - $notify(msg); } } }, sync); diff --git a/mindplot/src/main/javascript/widget/ModalDialogNotifier.js b/mindplot/src/main/javascript/widget/ModalDialogNotifier.js index 703dae98..b6fa4d23 100644 --- a/mindplot/src/main/javascript/widget/ModalDialogNotifier.js +++ b/mindplot/src/main/javascript/widget/ModalDialogNotifier.js @@ -16,68 +16,87 @@ * limitations under the License. */ -mindplot.widget.ToolbarNotifier = new Class({ - +mindplot.widget.ModalDialogNotifier = new Class({ + Extends:MooDialog, initialize:function () { - var container = $('headerNotifier'); - // In case of print,embedded no message is displayed .... - if (container) { - this._effect = new Fx.Elements(container, { - onComplete:function () { - container.setStyle('display', 'none'); - }.bind(this), - link:'cancel', - duration:8000, - transition:Fx.Transitions.Expo.easeInOut - }); - } + this.parent({ + closeButton:false, + destroyOnClose:true, + autoOpen:true, + useEscKey:false, + title:"", + onInitialize:function (wrapper) { + wrapper.setStyle('opacity', 0); + this.wrapper.setStyle('display', 'none'); + this.fx = new Fx.Morph(wrapper, { + duration:100, + transition:Fx.Transitions.Bounce.easeOut + }); + }, + + onBeforeOpen:function () { + var panel = this._buildPanel(); + this.setContent(panel); + + this.overlay = new Overlay(this.options.inject, { + duration:this.options.duration + }); + if (this.options.closeOnOverlayClick) + this.overlay.addEvent('click', this.close.bind(this)); + this.overlay.open(); + this.fx.start({ + 'margin-top':[-200, -100], + opacity:[0, 1] + }).chain(function () { + this.fireEvent('show'); + this.wrapper.setStyle('display', 'block'); + }.bind(this)); + }, + + onBeforeClose:function () { + this.fx.start({ + 'margin-top':[-100, 0], + opacity:0, + duration:200 + }).chain(function () { + this.wrapper.setStyle('display', 'none'); + this.fireEvent('hide'); + + }.bind(this)); + }} + ); + this.message = null; }, - logError:function (userMsg) { - this.logMessage(userMsg, mindplot.widget.ToolbarNotifier.MsgKind.ERROR); + show:function (message, title) { + $assert(message, "message can not be null"); + this._messsage = message; + this.options.title.setText($defined(title) ? title : "Outch!!. An unexpected error has occurred"); + this.open(); }, - hide:function () { - + destroy:function () { + this.parent(); + this.overlay.destroy(); }, - logMessage:function (msg, fade) { - $assert(msg, 'msg can not be null'); + _buildPanel:function () { + var result = new Element('div'); + result.setStyles({ + 'text-align':'center', + width:'400px' + }); + var p = new Element('p', {'text':this._messsage}); + p.inject(result); - var container = $('headerNotifier'); + var img = new Element('img', {'src':'images/alert-sign.png'}); + img.inject(result); - // In case of print,embedded no message is displayed .... - if (container) { - container.set('text', msg); - container.setStyle('display', 'block'); - container.position({ - relativeTo:$('header'), - position:'upperCenter', - edge:'centerTop' - }); - - if (!$defined(fade) || fade) { - this._effect.start({ - 0:{ - opacity:[1, 0] - } - }); - - } else { - container.setStyle('opacity', '1'); - this._effect.pause(); - } - } + return result; } - }); -mindplot.widget.ToolbarNotifier.MsgKind = { - INFO:1, - WARNING:2, - ERROR:3, - FATAL:4 -}; -var toolbarNotifier = new mindplot.widget.ToolbarNotifier(); -$notify = toolbarNotifier.logMessage.bind(toolbarNotifier); \ No newline at end of file +var dialogNotifier = new mindplot.widget.ModalDialogNotifier(); +$notifyModal = dialogNotifier.show.bind(dialogNotifier); +