[FIX] Reuse website.editor.LinkDialog#bind_data()

bzr revid: fme@openerp.com-20131031165117-13yo8nrfg1ru4cp8
This commit is contained in:
Fabien Meghazi 2013-10-31 17:51:17 +01:00
parent 9f97b24318
commit 35d469d51f
3 changed files with 19 additions and 34 deletions

View File

@ -806,10 +806,13 @@
this.text = null;
},
start: function () {
var self = this;
return $.when(
this.fetch_pages().done(this.proxy('fill_pages')),
this._super()
).done(this.proxy('bind_data'));
).done(function () {
self.bind_data();
});
},
save: function () {
var self = this, _super = this._super.bind(this);
@ -840,17 +843,24 @@
},
make_link: function (url, new_window, label) {
},
bind_data: function () {
var href = this.element && (this.element.data( 'cke-saved-href')
bind_data: function (text, href, new_window) {
href = href || this.element && (this.element.data( 'cke-saved-href')
|| this.element.getAttribute('href'));
if (!href) { return; }
if (new_window === undefined) {
new_window = this.element.getAttribute('target') === '_blank';
}
if (text === undefined) {
text = this.element.getText();
}
var match, $control;
if (match = /mailto:(.+)/.exec(href)) {
if ((match = /mailto:(.+)/.exec(href))) {
$control = this.$('input.email-address').val(match[1]);
} else if (href in this.pages) {
$control = this.$('select.existing').val(href);
} else if (match = /\/page\/(.+)/.exec(href)) {
} else if ((match = /\/page\/(.+)/.exec(href))) {
var actual_href = '/page/website.' + match[1];
if (actual_href in this.pages) {
$control = this.$('select.existing').val(actual_href);
@ -862,9 +872,8 @@
this.changed($control);
this.$('input#link-text').val(this.element.getText());
this.$('input.window-new').prop(
'checked', this.element.getAttribute('target') === '_blank');
this.$('input#link-text').val(text);
this.$('input.window-new').prop('checked', new_window);
},
changed: function ($e) {
this.$('.url-source').not($e).val('');

View File

@ -141,34 +141,10 @@
var self = this;
return $.when(this._super.apply(this, arguments)).then(function () {
if (self.data) {
self.manual_fill(self.data);
self.bind_data(self.data.name, self.data.url, self.data.new_window);
}
});
},
manual_fill: function (data) {
if (data.name) {
this.$('#link-text').val(this.data.name)[0].focus();
}
if (data.url) {
var target;
var target = this.$('#link-existing');
target.val(data.url);
if (!target.val()) {
var mailto = data.url.match(/^mailto:(.*)/);
if (mailto) {
target = this.$('#link-email');
target.val(mailto[1]);
} else {
target = this.$('#link-external');
target.val(data.url);
if (data.new_window !== undefined) {
this.$('input.window-new').prop('checked', data.new_window);
}
}
}
this.changed(target);
}
},
make_link: function (url, new_window, label) {
var menu_label = this.$('input#link-text').val() || label;
if (this.data) {

View File

@ -44,7 +44,7 @@
<t t-jquery="form > div.form-horizontal" t-operation="replace"/>
<t t-jquery="ul.list-group" t-operation="before">
<div class="list-group">
<div class="form-group list-group-item">
<div class="form-group list-group-item active">
<h3 class="list-group-item-heading">
<label for="link-new" class="control-label">
Menu Label