[FIX] website snippet: clean_for_save; display email in subscribe snippet

bzr revid: chm@openerp.com-20140306134746-oi0p580c3s3t2a24
This commit is contained in:
chm@openerp.com 2014-03-06 14:47:46 +01:00
parent 58a5f90758
commit 73446943f5
4 changed files with 22 additions and 25 deletions

View File

@ -31,10 +31,6 @@
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
}, },
save: function () { save: function () {
this.snippets.make_active(false);
// FIXME: call clean_for_save on all snippets of the page, not only modified ones
// important for banner of parallax that changes data automatically.
this.snippets.clean_for_save(); this.snippets.clean_for_save();
this._super(); this._super();
}, },
@ -55,6 +51,7 @@
if (!website.snippet) website.snippet = {}; if (!website.snippet) website.snippet = {};
website.snippet.templateOptions = {}; website.snippet.templateOptions = {};
website.snippet.globalSelector = "";
website.snippet.selector = []; website.snippet.selector = [];
website.snippet.BuildingBlock = openerp.Widget.extend({ website.snippet.BuildingBlock = openerp.Widget.extend({
template: 'website.snippets', template: 'website.snippets',
@ -132,6 +129,7 @@
.then(function (html) { .then(function (html) {
var $html = $(html); var $html = $(html);
var selector = [];
var $styles = $html.find("[data-snippet-option-id]"); var $styles = $html.find("[data-snippet-option-id]");
$styles.each(function () { $styles.each(function () {
var $style = $(this); var $style = $(this);
@ -144,8 +142,10 @@
'selector-children': $style.data('selector-children'), 'selector-children': $style.data('selector-children'),
'selector-vertical-children': $style.data('selector-vertical-children') 'selector-vertical-children': $style.data('selector-vertical-children')
}; };
selector.push($style.data('selector'));
}); });
$styles.addClass("hidden"); $styles.addClass("hidden");
website.snippet.globalSelector = selector.join(",");
self.$snippets = $html.find(".tab-content > div > div").addClass("oe_snippet"); self.$snippets = $html.find(".tab-content > div > div").addClass("oe_snippet");
self.$el.append($html); self.$el.append($html);
@ -195,17 +195,12 @@
return; return;
} }
snipped_event_flag = true; snipped_event_flag = true;
var selector = [];
for (var k in website.snippet.templateOptions) {
selector.push(website.snippet.templateOptions[k].selector);
}
selector = selector.join(",");
setTimeout(function () {snipped_event_flag = false;}, 0); setTimeout(function () {snipped_event_flag = false;}, 0);
var $target = $(event.srcElement); var $target = $(event.srcElement);
if (!$target.is(selector)) { if (!$target.is(website.snippet.globalSelector)) {
$target = $target.parents(selector).first(); $target = $target.parents(website.snippet.globalSelector).first();
} }
if (!self.dom_filter($target).length) { if (!self.dom_filter($target).length) {
$target = false; $target = false;
@ -231,13 +226,16 @@
} }
}, },
clean_for_save: function () { clean_for_save: function () {
for (var k in this.snippets) { var self = this;
if (!this.snippets.hasOwnProperty(k)) { continue; } $(website.snippet.globalSelector).each(function () {
var editor = $(this.snippets[k]).data("snippet-editor"); var $snippet = $(this);
self.make_active($snippet);
self.make_active(false);
var editor = $snippet.data("snippet-editor");
if (editor) { if (editor) {
editor.clean_for_save(); editor.clean_for_save();
} }
} });
}, },
make_active: function ($snippet) { make_active: function ($snippet) {
if ($snippet && this.$active_snipped_id && this.$active_snipped_id.get(0) === $snippet.get(0)) { if ($snippet && this.$active_snipped_id && this.$active_snipped_id.get(0) === $snippet.get(0)) {

View File

@ -59,10 +59,10 @@ class WebsiteMail(http.Controller):
@http.route(['/website_mail/is_follower/'], type='json', auth="public", website=True) @http.route(['/website_mail/is_follower/'], type='json', auth="public", website=True)
def call(self, model, id, **post): def call(self, model, id, **post):
public_id = request.registry['website'].get_public_user(request.cr, request.uid, request.context) email = request.registry['res.users'].browse(request.cr, request.uid, request.uid, request.context).partner_id.email
value = request.registry.get(model).read(request.cr, request.uid, [id], ['message_is_follower'], request.context) value = request.registry.get(model).read(request.cr, request.uid, [id], ['message_is_follower'], request.context)
return { return {
'is_public': request.uid == public_id, 'email': email,
'is_follower': value and value[0]['message_is_follower'] or False 'is_follower': value and value[0]['message_is_follower'] or False
} }

View File

@ -31,6 +31,9 @@
this.$el.find(".js_mailing_list").on("click", _.bind(this.on_prompt, this)); this.$el.find(".js_mailing_list").on("click", _.bind(this.on_prompt, this));
this._super(); this._super();
}, },
clean_for_save: function () {
this.$target.addClass("hidden");
},
}); });
})(); })();

View File

@ -12,15 +12,11 @@
model: this.$target.data('object'), model: this.$target.data('object'),
id: +this.$target.data('id'), id: +this.$target.data('id'),
}).always(function (data) { }).always(function (data) {
self.$target.find('input.js_follow_email')
var $input = self.$target.find('input.js_follow_email'); .val(data.email ? data.email : "")
if(data.is_public) { .attr("disabled", data.email.length ? "disabled" : false);
$input.removeClass("hidden");
} else {
$input.addClass("hidden");
}
self.$target.attr("data-follow", data.is_follower ? 'on' : 'off'); self.$target.attr("data-follow", data.is_follower ? 'on' : 'off');
self.$target.removeClass("hidden");
}); });
}, },
}); });