From 3df56a4d9791eca063b1e0b528e82f958cc358e0 Mon Sep 17 00:00:00 2001 From: Mariela Michalek Date: Thu, 10 Apr 2014 19:33:20 -0300 Subject: [PATCH] update editors --- .../src/main/javascript/widget/LinkEditor.js | 71 ++---- .../src/main/javascript/widget/NoteEditor.js | 236 +++++------------- 2 files changed, 81 insertions(+), 226 deletions(-) diff --git a/mindplot/src/main/javascript/widget/LinkEditor.js b/mindplot/src/main/javascript/widget/LinkEditor.js index 258a395c..db2a7d35 100644 --- a/mindplot/src/main/javascript/widget/LinkEditor.js +++ b/mindplot/src/main/javascript/widget/LinkEditor.js @@ -21,7 +21,11 @@ mindplot.widget.LinkEditor = new Class({ initialize:function (model) { $assert(model, "model can not be null"); - this.parent($msg("LINK")); + this.parent($msg("LINK"), { + cancelButton: true, + closeButton: true, + acceptButton: true + }); var panel = this._buildPanel(model); this.setContent(panel); }, @@ -64,64 +68,25 @@ mindplot.widget.LinkEditor = new Class({ form.append(input); form.append(open); - // Register submit event ... - form.submit(function (event) { -// event.stopPropagation(); - event.preventDefault(); + $(document).ready(function () { + $(document).on('submit','#linkFormId',function () { + event.stopPropagation(); + event.preventDefault(); + if (input.value != null && input.value.trim() != "") { + model.setValue(input.value); + } + this.close(); + }); - if (input.value != null && input.value.trim() != "") { - model.setValue(input.value); - } - this.close(); - }.bind(this)); - -// form.addEvent('submit', function (event) { -// event.stopPropagation(); -// event.preventDefault(); -// -// if (input.value != null && input.value.trim() != "") { -// model.setValue(input.value); -// } -// this.close(); -// }.bind(this)); - - - // Add buttons ... - - var buttonContainer = $('
'); - buttonContainer.css('paddingTop','5').css('textAlign','center'); -// var buttonContainer = new Element('div').setStyles({paddingTop:5, textAlign:'center'}); -// - // Create remove button ... - - -// if ($defined(model.getValue())) { -// var rmButton = new Element('input', {type:'button', value:$msg('REMOVE'), 'class':'btn-primary'}); -// rmButton.setStyle('margin', '5px'); -// rmButton.addClass('button'); -// rmButton.inject(buttonContainer); -// rmButton.addEvent('click', function (event) { -// model.setValue(null); -// event.stopPropagation(); -// this.close(); -// }.bind(this)); -// buttonContainer.inject(form); -// } - - form.append(buttonContainer); -// var cButton = new Element('input', {type:'button', value:$msg('CANCEL'), 'class':'btn-secondary'}); -// cButton.setStyle('margin', '5px'); -// cButton.addClass('button'); -// cButton.addEvent('click', function () { -// this.close(); -// }.bind(this)); -// buttonContainer.inject(form); + $(document).on('click','#acceptBtn',function () { + $("#linkFormId").submit(); + }); + }); // result.addEvent('keydown', function (event) { // event.stopPropagation(); // }); // - result.append(form); return result; } diff --git a/mindplot/src/main/javascript/widget/NoteEditor.js b/mindplot/src/main/javascript/widget/NoteEditor.js index 34cebb6d..352fd2d7 100644 --- a/mindplot/src/main/javascript/widget/NoteEditor.js +++ b/mindplot/src/main/javascript/widget/NoteEditor.js @@ -1,3 +1,66 @@ +mindplot.widget.NoteEditor = new Class({ + Extends:BootstrapDialog, + initialize:function (model) { + $assert(model, "model can not be null"); + this.parent($msg("Note"), { + cancelButton: true, + closeButton: true, + acceptButton: true + }); + var panel = this._buildPanel(model); + this.setContent(panel); + }, + + +_buildPanel:function (model) { + var result = $('
').css("padding-top", "5px"); + + var form = $('
').attr({ + 'action':'none', + 'id':'noteFormId' + }); + // Add textarea + var textArea = $('').attr({ + 'placeholder':$msg('WRITE_YOUR_TEXT_HERE'), + 'required':'true', + 'autofocus':'autofocus' + }); + textArea.css({ + 'width':'100%', + 'height':80, + 'resize':'none' + }); + + form.append(textArea); + + if (model.getValue() != null){ + textArea.val(model.getValue()); + } + + result.append(form); + + $(document).ready(function () { + $(document).on('submit','#noteFormId',function () { + event.stopPropagation(); + event.preventDefault(); + if (textArea.val()) { + model.setValue(textArea.val()); + } + this.close(); + }); + + $(document).on('click','#acceptBtn',function () { + $("#noteFormId").submit(); + }); + }); + return result; + }, + + close:function () { + this.close(); + } +}); + /* * Copyright [2012] [wisemapping] * @@ -15,176 +78,3 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -mindplot.widget.NoteEditor = new Class({ - Extends:BootstrapDialog, - initialize:function (model) { - console.log("Re-impl required ...."); - $assert(model, "model can not be null"); - this.parent(); - var panel = this._buildPanel(model); -// this.parent({ -// closeButton:true, -// destroyOnClose:true, -// title:$msg('NOTE'), -// onInitialize:function (wrapper) { -// wrapper.setStyle('opacity', 0); -// this.fx = new Fx.Morph(wrapper, { -// duration:600, -// transition:Fx.Transitions.Bounce.easeOut -// }); -// }, -// -// onBeforeOpen:function () { -// 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'); -// }.bind(this)); -// }, -// -// onBeforeClose:function () { -// this.fx.start({ -// 'margin-top':[-100, 0], -// opacity:0 -// }).chain(function () { -// this.fireEvent('hide'); -// }.bind(this)); -// this.overlay.destroy(); -// } -// }); -// this.setContent(panel); - this.setContent(panel); - }, - - _buildPanel:function (model) { - var result = $('
').css("padding-top", "5px"); - var form = $('
').attr({ - 'action':'none', - 'id':'noteFormId' - }); - - // Add textarea - var textArea = $('').attr({ - 'placeholder':$msg('WRITE_YOUR_TEXT_HERE'), - 'required':'true', - 'autofocus':'autofocus' - }); - textArea.css({ - 'width':'100%', - 'height':80, - 'resize':'none' - }); - form.append(textArea); - -// var textArea = new Element('textarea', -// {placeholder:$msg('WRITE_YOUR_TEXT_HERE'), -// required:true, -// autofocus:'autofocus' -// }); -// textArea.setStyles({ -// 'width':'100%', -// 'height':80, resize:'none' -// }); - - if (model.getValue() != null){ - textArea.value = model.getValue(); - } - - // Register submit event - - form.submit(function (event) { - event.preventDefault(); - event.stopPropagation(); - if (textArea.value) { - model.setValue(textArea.value); - } - this.close(); - }.bind(this)); - -// form.addEvent('submit', function (event) { -// event.preventDefault(); -// event.stopPropagation(); -// if (textArea.value) { -// model.setValue(textArea.value); -// } -// this.close(); -// }.bind(this)); - - // Add buttons ... - var buttonContainer = $('
'); - buttonContainer.css({ - 'paddingTop':'5', - 'textAlign':'center' - }); - - // Create accept button ... - var okButton = $(''); - okButton.attr('type','submit').attr( - 'value',$msg('ACCEPT')).attr( - 'class','btn-primary'); - buttonContainer.append(okButton); - -// var okButton = new Element('input', {type:'submit', value:$msg('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:$msg('REMOVE'), 'class':'btn-primary'}); -// rmButton.setStyle('margin', '5px'); -// rmButton.addClass('button'); -// rmButton.inject(buttonContainer); -// rmButton.addEvent('click', function () { -// model.setValue(null); -// this.close(); -// }.bind(this)); -// buttonContainer.inject(form); -// } - - // Create cancel button ... - var cancelButton = $(''); - cancelButton.attr('id','cancel').attr('type','button').attr( - 'value',$msg('CANCEL')).attr( - 'class','btn-secondary'); - cancelButton.css('margin','5px'); -// cancelButton.on('click','input', function (e) { -// console.log('this is the click'); -// e.preventDefault(); -// }); - $(document).on('click', "input.btn-secondary", function () { - $(modal-dialog).hide(); - }); - buttonContainer.append(cancelButton); - - form.append(buttonContainer); - -// var cButton = new Element('input', {type:'button', value:$msg('CANCEL'), 'class':'btn-secondary'}); -// cButton.setStyle('margin', '5px'); -// cButton.addClass('button'); -// cButton.inject(buttonContainer); -// cButton.addEvent('click', function () { -// this.close(); -// }.bind(this)); -// buttonContainer.inject(form); - -// result.addEvent('keydown', function (event) { -// event.stopPropagation(); -// }); - result.append(form); - return result; - }, - - show:function () { - this.parent("Note"); - } - -});