From c4f4756e4a6ab5203d3079c3e4f3044234280704 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 1 Sep 2012 10:17:15 -0300 Subject: [PATCH] Bug message: uncaught exception: text can not be null, line:0, : fixed. --- .../src/main/javascript/model/NoteModel.js | 11 ++-- .../persistence/XMLSerializer_Pela.js | 4 +- .../src/main/javascript/widget/NoteEditor.js | 56 +++++++++---------- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/mindplot/src/main/javascript/model/NoteModel.js b/mindplot/src/main/javascript/model/NoteModel.js index d41ec317..8b3de968 100644 --- a/mindplot/src/main/javascript/model/NoteModel.js +++ b/mindplot/src/main/javascript/model/NoteModel.js @@ -17,17 +17,18 @@ */ mindplot.model.NoteModel = new Class({ - Extends: mindplot.model.FeatureModel, - initialize : function(attributes) { + Extends:mindplot.model.FeatureModel, + initialize:function (attributes) { this.parent(mindplot.model.NoteModel.FEATURE_TYPE); - this.setText(attributes.text); + if (attributes.text) + this.setText(attributes.text); }, - getText:function() { + getText:function () { return this.getAttribute('text'); }, - setText : function(text) { + setText:function (text) { $assert(text, 'text can not be null'); this.setAttribute('text', text); } diff --git a/mindplot/src/main/javascript/persistence/XMLSerializer_Pela.js b/mindplot/src/main/javascript/persistence/XMLSerializer_Pela.js index 78bd4f3b..4870f2a8 100644 --- a/mindplot/src/main/javascript/persistence/XMLSerializer_Pela.js +++ b/mindplot/src/main/javascript/persistence/XMLSerializer_Pela.js @@ -170,7 +170,7 @@ mindplot.persistence.XMLSerializer_Pela = new Class({ }, _noteTextToXML:function (document, elem, text) { - if (text.indexOf('\n') == -1) { + if (text.indexOf('\n') == -1 && text.indexOf("&") == -1 && text.indexOf("<") == -1 && text.indexOf("\"") == -1) { elem.setAttribute('text', text); } else { var textDom = document.createElement("text"); @@ -256,7 +256,7 @@ mindplot.persistence.XMLSerializer_Pela = new Class({ var topic = mindmap.createNode(type, id); var text = domElem.getAttribute('text'); - if ($defined(text)) { + if ($defined(text) && text) { topic.setText(text); } diff --git a/mindplot/src/main/javascript/widget/NoteEditor.js b/mindplot/src/main/javascript/widget/NoteEditor.js index 1d0c1c89..ec43f49f 100644 --- a/mindplot/src/main/javascript/widget/NoteEditor.js +++ b/mindplot/src/main/javascript/widget/NoteEditor.js @@ -18,42 +18,42 @@ mindplot.widget.NoteEditor = new Class({ Extends:MooDialog, - initialize : function(model) { + initialize:function (model) { $assert(model, "model can not be null"); var panel = this._buildPanel(model); this.parent({ closeButton:true, destroyOnClose:true, title:'Note', - onInitialize: function(wrapper) { + onInitialize:function (wrapper) { wrapper.setStyle('opacity', 0); this.fx = new Fx.Morph(wrapper, { - duration: 600, - transition: Fx.Transitions.Bounce.easeOut + duration:600, + transition:Fx.Transitions.Bounce.easeOut }); }, - onBeforeOpen: function() { + onBeforeOpen:function () { this.overlay = new Overlay(this.options.inject, { - duration: this.options.duration + 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() { + 'margin-top':[-200, -100], + opacity:[0, 1] + }).chain(function () { this.fireEvent('show'); }.bind(this)); }, - onBeforeClose: function() { + onBeforeClose:function () { this.fx.start({ - 'margin-top': [-100, 0], - opacity: 0 - }).chain(function() { + 'margin-top':[-100, 0], + opacity:0 + }).chain(function () { this.fireEvent('hide'); }.bind(this)); this.overlay.destroy(); @@ -62,13 +62,13 @@ mindplot.widget.NoteEditor = new Class({ this.setContent(panel); }, - _buildPanel : function (model) { + _buildPanel:function (model) { var result = new Element('div'); - var form = new Element('form', {'action': 'none', 'id':'noteFormId'}); + var form = new Element('form', {'action':'none', 'id':'noteFormId'}); // Add textarea ... var textArea = new Element('textarea', - {placeholder: 'Write your note here ...', + {placeholder:'Write your note here ...', required:true, autofocus:'autofocus' }); @@ -77,17 +77,17 @@ mindplot.widget.NoteEditor = new Class({ textArea.setStyles({ 'width':'100%', - 'height':80 - ,resize: 'none' + 'height':80, resize:'none' }); textArea.inject(form); // Register submit event ... - form.addEvent('submit', function(event) { + form.addEvent('submit', function (event) { event.preventDefault(); event.stopPropagation(); - - model.setValue(textArea.value); + if (textArea.value ) { + model.setValue(textArea.value); + } this.close(); }.bind(this)); @@ -96,17 +96,17 @@ mindplot.widget.NoteEditor = new Class({ var buttonContainer = new Element('div').setStyles({paddingTop:5, textAlign:'right'}); // Create accept button ... - var okButton = new Element('input', {type:'submit', value:'Accept','class':'btn-primary'}); + var okButton = new Element('input', {type:'submit', value:'Accept', 'class':'btn-primary'}); okButton.addClass('button'); okButton.inject(buttonContainer); // Create remove button ... if ($defined(model.getValue())) { - var rmButton = new Element('input', {type:'button', value:'Remove','class':'btn-primary'}); + var rmButton = new Element('input', {type:'button', value:'Remove', 'class':'btn-primary'}); rmButton.setStyle('margin', '5px'); rmButton.addClass('button'); rmButton.inject(buttonContainer); - rmButton.addEvent('click', function() { + rmButton.addEvent('click', function () { model.setValue(null); this.close(); }.bind(this)); @@ -114,16 +114,16 @@ mindplot.widget.NoteEditor = new Class({ } // Create cancel button ... - var cButton = new Element('input', {type:'button', value:'Cancel','class':'btn-secondary'}); + var cButton = new Element('input', {type:'button', value:'Cancel', 'class':'btn-secondary'}); cButton.setStyle('margin', '5px'); cButton.addClass('button'); cButton.inject(buttonContainer); - cButton.addEvent('click', function() { + cButton.addEvent('click', function () { this.close(); }.bind(this)); buttonContainer.inject(form); - result.addEvent('keydown', function(event) { + result.addEvent('keydown', function (event) { event.stopPropagation(); }); @@ -131,7 +131,7 @@ mindplot.widget.NoteEditor = new Class({ return result; }, - show : function() { + show:function () { this.open(); }