add url error BootstrapDialog and LinkEditor

This commit is contained in:
Mariela Michalek 2014-05-04 15:59:12 -03:00
parent faf34707d1
commit 9d0ba4b30d
2 changed files with 30 additions and 9 deletions

View File

@ -6,6 +6,7 @@ var BootstrapDialog = new Class({
closeButton: false, closeButton: false,
acceptButton: true, acceptButton: true,
removeButton:false, removeButton:false,
errorMessage: false,
onRemoveClickData:{} onRemoveClickData:{}
}, },
@ -18,12 +19,17 @@ var BootstrapDialog = new Class({
if (header) { if (header) {
content.append(header); content.append(header);
} }
content.append('<div class="modal-body"></div>'); var body = $('<div class="modal-body"></div>');
if(this.options.errorMessage){
var error = $('<div class="alert alert-danger"></div>');
error.hide();
body.append(error);
}
content.append(body);
var footer = this._buildFooter(); var footer = this._buildFooter();
if (footer) { if (footer) {
content.append(footer); content.append(footer);
} }
this._native.find(".modal-dialog").append(content); this._native.find(".modal-dialog").append(content);
}, },
@ -84,7 +90,7 @@ var BootstrapDialog = new Class({
this._native.find('.modal-body').append(content); this._native.find('.modal-body').append(content);
}, },
css:function(options){ css: function(options){
this._native.find('.modal-dialog').css(options); this._native.find('.modal-dialog').css(options);
}, },
@ -92,6 +98,11 @@ var BootstrapDialog = new Class({
this._native.modal('hide'); this._native.modal('hide');
}, },
alertError: function(message){
this._native.find('.alert-danger').text(message);
this._native.find('.alert-danger').show();
},
showRemoveButton: function(){ showRemoveButton: function(){
this.removeButton.show(); this.removeButton.show();
} }

View File

@ -27,6 +27,7 @@ mindplot.widget.LinkEditor = new Class({
closeButton: true, closeButton: true,
acceptButton: true, acceptButton: true,
removeButton: true, removeButton: true,
errorMessage: true,
onRemoveClickData: {model: this._model} onRemoveClickData: {model: this._model}
}); });
this.css({width:"600px"}); this.css({width:"600px"});
@ -73,22 +74,25 @@ mindplot.widget.LinkEditor = new Class({
openButton.click(function(){ openButton.click(function(){
window.open(input.val(),"_blank", "status=1,width=700,height=450,resize=1"); window.open(input.val(),"_blank", "status=1,width=700,height=450,resize=1");
}); });
var spanControl = $('<span class="input-group-btn"></span>').append(openButton) var spanControl = $('<span class="input-group-btn"></span>').append(openButton);
section.append(input); section.append(input);
section.append(spanControl); section.append(spanControl);
form.append(section); form.append(section);
var me = this;
$(document).ready(function () { $(document).ready(function () {
var me = this;
$(document).on('submit','#linkFormId',function (event) { $(document).on('submit','#linkFormId',function (event) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
var inputValue = input.val(); if(me.checkURL(input.val())){
if (inputValue != null && inputValue.trim() != "") { var inputValue = input.val();
model.setValue(inputValue); 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; 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() { onAcceptClick: function() {
$("#linkFormId").submit(); $("#linkFormId").submit();
} }
}); });