114 lines
3.2 KiB
JavaScript
Raw Normal View History

2011-10-07 01:30:55 -03:00
/*
2012-10-04 20:48:01 -03:00
* Copyright [2012] [wisemapping]
2011-10-07 01:30:55 -03:00
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
mindplot.widget.LinkEditor = new Class({
2014-03-29 17:13:31 -03:00
Extends:BootstrapDialog,
2014-04-03 22:39:23 -03:00
initialize:function (model) {
2011-10-07 01:30:55 -03:00
$assert(model, "model can not be null");
2014-04-10 19:33:20 -03:00
this.parent($msg("LINK"), {
cancelButton: true,
closeButton: true,
2014-04-18 17:13:44 -03:00
acceptButton: true,
removeButton: true
2014-04-10 19:33:20 -03:00
});
2014-04-18 17:54:24 -03:00
this.setStyle("500px");
2014-04-18 17:13:44 -03:00
this._model = model;
2011-10-07 01:30:55 -03:00
var panel = this._buildPanel(model);
2014-04-03 22:39:23 -03:00
this.setContent(panel);
2011-10-07 01:30:55 -03:00
},
_buildPanel:function (model) {
2014-04-01 07:24:36 -03:00
var result = $('<div></div>').css("padding-top", "5px");
2014-04-02 15:57:32 -03:00
var form = $('<form></form>').attr({
'action':'none',
'id':'linkFormId'
});
2014-04-01 07:24:36 -03:00
var text = $('<p></p>').text("Paste your url here:");
text.css('margin','0px 0px 10px');
2011-10-08 20:36:47 -03:00
2014-03-29 17:13:31 -03:00
form.append(text);
2014-04-01 07:24:36 -03:00
// Add Input
2014-04-02 15:57:32 -03:00
var input = $('<input>').attr({
'placeholder':'http://www.example.com/',
'type':'url', //FIXME: THIS not work on IE, see workaround below
2014-04-02 15:57:32 -03:00
'required':'true',
'autofocus':'autofocus'
});
2014-04-01 07:24:36 -03:00
input.css('width','70%').css('margin','0px 20px');
if (model.getValue() != null){
2014-04-12 15:00:51 -03:00
input.val(model.getValue());
}
2014-03-29 17:13:31 -03:00
// type:Browser.ie ? 'text' : 'url', // IE workaround
2011-10-07 01:30:55 -03:00
2014-04-01 07:24:36 -03:00
// Open Button
2014-04-02 15:57:32 -03:00
var open = $('<input/>').attr({
'type':'button',
'value':$msg('OPEN_LINK')
});
2014-04-01 07:24:36 -03:00
open.click(function(){
alert('clicked!');
});
form.append(input);
form.append(open);
2014-04-10 19:33:20 -03:00
$(document).ready(function () {
2014-04-12 15:00:51 -03:00
var me = this;
$(document).on('submit','#linkFormId',function (event) {
2014-04-10 19:33:20 -03:00
event.stopPropagation();
event.preventDefault();
2014-04-12 15:00:51 -03:00
var inputValue = input.val();
if (inputValue != null && inputValue.trim() != "") {
model.setValue(inputValue);
2014-04-10 19:33:20 -03:00
}
2014-04-12 15:00:51 -03:00
me.close();
2014-04-10 19:33:20 -03:00
});
});
2014-04-01 07:24:36 -03:00
2014-04-18 17:13:44 -03:00
if (typeof model.getValue() != 'undefined'){
this.showRemoveButton();
}
2014-04-01 07:24:36 -03:00
result.append(form);
2011-10-07 01:30:55 -03:00
return result;
2014-04-12 15:00:51 -03:00
},
onAcceptClick: function() {
$("#linkFormId").submit();
},
2014-04-18 17:13:44 -03:00
onRemoveClick: function() {
this._model.setValue(null);
this.close();
},
hideRemoveButton:function(){
this.parent();
},
2014-04-12 15:00:51 -03:00
close:function () {
this.parent();
2011-10-07 01:30:55 -03:00
}
});