From b9ec5b1bf3bdf7ad1e20b2733c8e1164f140d317 Mon Sep 17 00:00:00 2001 From: Mariela Michalek Date: Sat, 10 May 2014 17:58:29 -0300 Subject: [PATCH] update submit functionality on link editor --- .../libraries/bootstrap/BootstrapDialog.js | 6 +++- .../src/main/javascript/widget/LinkEditor.js | 32 +++++++++++-------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/mindplot/src/main/javascript/libraries/bootstrap/BootstrapDialog.js b/mindplot/src/main/javascript/libraries/bootstrap/BootstrapDialog.js index ea90474c..0bd72b6f 100644 --- a/mindplot/src/main/javascript/libraries/bootstrap/BootstrapDialog.js +++ b/mindplot/src/main/javascript/libraries/bootstrap/BootstrapDialog.js @@ -41,7 +41,7 @@ var BootstrapDialog = new Class({ if (this.options.acceptButton) { this.acceptButton = $(''); footer.append(this.acceptButton); - this.acceptButton.on('click', this.onAcceptClick) + this.acceptButton.unbind('click').click(this.onAcceptClick) } if (this.options.removeButton) { this.removeButton = $(''); @@ -103,6 +103,10 @@ var BootstrapDialog = new Class({ this._native.find('.alert-danger').show(); }, + cleanError: function(){ + this._native.find('.alert-danger').hide(); + }, + showRemoveButton: function(){ this.removeButton.show(); } diff --git a/mindplot/src/main/javascript/widget/LinkEditor.js b/mindplot/src/main/javascript/widget/LinkEditor.js index 81c0120a..091af5f8 100644 --- a/mindplot/src/main/javascript/widget/LinkEditor.js +++ b/mindplot/src/main/javascript/widget/LinkEditor.js @@ -37,14 +37,14 @@ mindplot.widget.LinkEditor = new Class({ _buildPanel:function (model) { var result = $('
').css("padding-top", "5px"); - var form = $('
').attr({ + this.form = $('
').attr({ 'action': 'none', 'id': 'linkFormId' }); var text = $('

').text("Paste your url here:"); text.css('margin','0px 0px 20px'); - form.append(text); + this.form.append(text); var section = $('
').attr({ 'class': 'input-group' @@ -78,30 +78,32 @@ mindplot.widget.LinkEditor = new Class({ section.append(input); section.append(spanControl); - form.append(section); + this.form.append(section); var me = this; - $(document).ready(function () { - $(document).on('submit','#linkFormId',function (event) { - event.stopPropagation(); + this.form.unbind('submit').submit( + function (event) { event.preventDefault(); if(me.checkURL(input.val())){ + me.cleanError(); var inputValue = input.val(); if (inputValue != null && inputValue.trim() != "") { model.setValue(inputValue); } me.close(); + this.formSubmitted = true; + } else { + me.alertError($msg('URL_ERROR')); + event.stopPropagation(); } - me.alertError($msg("URL_ERROR")); //FIXME: add msg - }); - - }); + } + ); if (typeof model.getValue() != 'undefined'){ this.showRemoveButton(); } - result.append(form); + result.append(this.form); return result; }, @@ -110,8 +112,12 @@ mindplot.widget.LinkEditor = new Class({ return(regex.test(url)); }, - onAcceptClick: function() { - $("#linkFormId").submit(); + onAcceptClick: function(event) { + this.formSubmitted = false; + $("#linkFormId").trigger('submit'); + if (!this.formSubmitted) { + event.stopPropagation(); + } } });