From 6d50e0769e7b3a1b0f5a1fb97f513f54b422c583 Mon Sep 17 00:00:00 2001 From: Mariela Michalek Date: Sun, 4 May 2014 15:59:12 -0300 Subject: [PATCH] add url error BootstrapDialog and LinkEditor --- .../libraries/bootstrap/BootstrapDialog.js | 17 +++++++++++--- .../src/main/javascript/widget/LinkEditor.js | 22 ++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/mindplot/src/main/javascript/libraries/bootstrap/BootstrapDialog.js b/mindplot/src/main/javascript/libraries/bootstrap/BootstrapDialog.js index 691091d4..ea90474c 100644 --- a/mindplot/src/main/javascript/libraries/bootstrap/BootstrapDialog.js +++ b/mindplot/src/main/javascript/libraries/bootstrap/BootstrapDialog.js @@ -6,6 +6,7 @@ var BootstrapDialog = new Class({ closeButton: false, acceptButton: true, removeButton:false, + errorMessage: false, onRemoveClickData:{} }, @@ -18,12 +19,17 @@ var BootstrapDialog = new Class({ if (header) { content.append(header); } - content.append(''); + var body = $(''); + if(this.options.errorMessage){ + var error = $('
'); + error.hide(); + body.append(error); + } + content.append(body); var footer = this._buildFooter(); if (footer) { content.append(footer); } - this._native.find(".modal-dialog").append(content); }, @@ -84,7 +90,7 @@ var BootstrapDialog = new Class({ this._native.find('.modal-body').append(content); }, - css:function(options){ + css: function(options){ this._native.find('.modal-dialog').css(options); }, @@ -92,6 +98,11 @@ var BootstrapDialog = new Class({ this._native.modal('hide'); }, + alertError: function(message){ + this._native.find('.alert-danger').text(message); + this._native.find('.alert-danger').show(); + }, + showRemoveButton: function(){ this.removeButton.show(); } diff --git a/mindplot/src/main/javascript/widget/LinkEditor.js b/mindplot/src/main/javascript/widget/LinkEditor.js index 8d25181a..81c0120a 100644 --- a/mindplot/src/main/javascript/widget/LinkEditor.js +++ b/mindplot/src/main/javascript/widget/LinkEditor.js @@ -27,6 +27,7 @@ mindplot.widget.LinkEditor = new Class({ closeButton: true, acceptButton: true, removeButton: true, + errorMessage: true, onRemoveClickData: {model: this._model} }); this.css({width:"600px"}); @@ -73,22 +74,25 @@ mindplot.widget.LinkEditor = new Class({ openButton.click(function(){ window.open(input.val(),"_blank", "status=1,width=700,height=450,resize=1"); }); - var spanControl = $('').append(openButton) + var spanControl = $('').append(openButton); section.append(input); section.append(spanControl); form.append(section); + var me = this; $(document).ready(function () { - var me = this; $(document).on('submit','#linkFormId',function (event) { event.stopPropagation(); event.preventDefault(); - var inputValue = input.val(); - if (inputValue != null && inputValue.trim() != "") { - model.setValue(inputValue); + if(me.checkURL(input.val())){ + var inputValue = input.val(); + if (inputValue != null && inputValue.trim() != "") { + model.setValue(inputValue); + } + me.close(); } - me.close(); + me.alertError($msg("URL_ERROR")); //FIXME: add msg }); }); @@ -101,7 +105,13 @@ mindplot.widget.LinkEditor = new Class({ return result; }, + checkURL: function(url){ + var regex = /^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i; + return(regex.test(url)); + }, + onAcceptClick: function() { $("#linkFormId").submit(); } + });