[IMP] website: dynamic website_mail snippet with js
bzr revid: chm@openerp.com-20140306130240-cpsd5mssziuvrpf8
This commit is contained in:
parent
7cf77276fb
commit
58a5f90758
|
@ -38,7 +38,9 @@
|
|||
}
|
||||
});
|
||||
};
|
||||
$(document).ready(function () {website.snippet.start_animation();});
|
||||
$(document).ready(function () {
|
||||
website.snippet.start_animation();
|
||||
});
|
||||
|
||||
|
||||
website.snippet.animationRegistry = {};
|
||||
|
@ -110,7 +112,7 @@
|
|||
img.onload = function () {
|
||||
var offset = 0;
|
||||
var padding = parseInt($(document.body).css("padding-top"));
|
||||
if (speed < 1) {
|
||||
if (speed > 1) {
|
||||
var inner_offset = - self.$target.outerHeight() + this.height / this.width * document.body.clientWidth;
|
||||
var outer_offset = self.$target.offset().top - (document.body.clientHeight - self.$target.outerHeight()) - padding;
|
||||
offset = - outer_offset * speed + inner_offset;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
},
|
||||
edit: function () {
|
||||
var self = this;
|
||||
$("body").off('click');
|
||||
$("[data-oe-model] *, [data-oe-type=html] *").off('click');
|
||||
window.snippets = this.snippets = new website.snippet.BuildingBlock(this);
|
||||
this.snippets.appendTo(this.$el);
|
||||
|
||||
|
|
|
@ -829,6 +829,16 @@
|
|||
|
||||
<div id="snippet_options" class="hidden">
|
||||
|
||||
<t t-call="website.snippet_options"/>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="snippet_options">
|
||||
|
||||
<div data-snippet-option-id='blog-style'
|
||||
data-selector="section:not(.carousel):not(.parallax)">
|
||||
<li class="dropdown-submenu">
|
||||
|
@ -957,10 +967,14 @@
|
|||
</li>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div data-snippet-option-id='content'
|
||||
data-selector="p, h1, h2, h3, blockquote, .well, .panel"
|
||||
data-selector-siblings="p, h1, h2, h3, blockquote, .well, .panel"
|
||||
data-selector-children=".content">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -56,3 +56,13 @@ class WebsiteMail(http.Controller):
|
|||
follower_ids = [p.id for p in obj.message_follower_ids]
|
||||
|
||||
return partner_ids[0] in follower_ids and 1 or 0
|
||||
|
||||
@http.route(['/website_mail/is_follower/'], type='json', auth="public", website=True)
|
||||
def call(self, model, id, **post):
|
||||
public_id = request.registry['website'].get_public_user(request.cr, request.uid, request.context)
|
||||
value = request.registry.get(model).read(request.cr, request.uid, [id], ['message_is_follower'], request.context)
|
||||
return {
|
||||
'is_public': request.uid == public_id,
|
||||
'is_follower': value and value[0]['message_is_follower'] or False
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
.js_follow[data-follow='on'] .js_follow_btn ,
|
||||
.js_follow[data-follow='on'] .js_follow_email,
|
||||
.js_follow[data-follow='off'] .js_unfollow_btn {
|
||||
display: none;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
var website = openerp.website;
|
||||
var _t = openerp._t;
|
||||
|
||||
website.snippet.options.subscribe = website.snippet.Option.extend({
|
||||
on_prompt: function () {
|
||||
var self = this;
|
||||
return website.prompt({
|
||||
id: "editor_new_subscribe_button",
|
||||
window_title: _t("New Subscribe Button"),
|
||||
select: _t("Mailing List"),
|
||||
init: function (field) {
|
||||
return website.session.model('mail.group')
|
||||
.call('name_search', ['', [['public','=','public']]], { context: website.get_context() });
|
||||
},
|
||||
}).then(function (mail_group_id) {
|
||||
self.$target.attr("data-id", mail_group_id);
|
||||
});
|
||||
},
|
||||
drop_and_build_snippet: function() {
|
||||
var self = this;
|
||||
this._super();
|
||||
this.on_prompt().fail(function () {
|
||||
self.editor.on_remove();
|
||||
});
|
||||
},
|
||||
start : function () {
|
||||
var self = this;
|
||||
this.$el.find(".js_mailing_list").on("click", _.bind(this.on_prompt, this));
|
||||
this._super();
|
||||
},
|
||||
});
|
||||
})();
|
||||
|
||||
|
|
@ -1,30 +1,62 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
var website = openerp.website;
|
||||
|
||||
website.snippet.animationRegistry.follow = website.snippet.Animation.extend({
|
||||
selector: ".js_follow",
|
||||
start: function () {
|
||||
var self = this;
|
||||
|
||||
openerp.jsonRpc('/website_mail/is_follower/', 'call', {
|
||||
model: this.$target.data('object'),
|
||||
id: +this.$target.data('id'),
|
||||
}).always(function (data) {
|
||||
|
||||
var $input = self.$target.find('input.js_follow_email');
|
||||
if(data.is_public) {
|
||||
$input.removeClass("hidden");
|
||||
} else {
|
||||
$input.addClass("hidden");
|
||||
}
|
||||
|
||||
self.$target.attr("data-follow", data.is_follower ? 'on' : 'off');
|
||||
});
|
||||
},
|
||||
});
|
||||
})();
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
$(document).on('click', '.js_follow_btn, .js_unfollow_btn', function (ev) {
|
||||
$('.js_follow > .alert').addClass("hidden");
|
||||
$('.js_follow > .input-group-btn.hidden').removeClass("hidden");
|
||||
|
||||
$('.js_follow_btn, .js_unfollow_btn').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
var self = this;
|
||||
var $data = $(this).parents("div.js_follow");
|
||||
var $email = $data.find(".js_follow_email");
|
||||
var $follow = $(this).parents("div.js_follow");
|
||||
var $email = $follow.find(".js_follow_email:visible");
|
||||
|
||||
if ($email.length && !$email.val().match(/.+@.+/)) {
|
||||
$follow.addClass('has-error');
|
||||
return false;
|
||||
}
|
||||
|
||||
var message_is_follower = $data.attr("data-follow") || "off";
|
||||
$data.attr("data-follow", message_is_follower == 'off' ? 'on' : 'off');
|
||||
$email.removeClass('has-error');
|
||||
|
||||
var message_is_follower = $follow.attr("data-follow") || "off";
|
||||
$follow.attr("data-follow", message_is_follower == 'off' ? 'on' : 'off');
|
||||
|
||||
openerp.jsonRpc('/website_mail/follow', 'call', {
|
||||
'id': $data.data('id'),
|
||||
'object': $data.data('object'),
|
||||
'id': +$follow.data('id'),
|
||||
'object': $follow.data('object'),
|
||||
'message_is_follower': message_is_follower,
|
||||
'email': $email.length ? $email.val() : false,
|
||||
}).then(function (result) {
|
||||
if (result) {
|
||||
$data.find(" > *").toggleClass("hidden");
|
||||
}).then(function (follow) {
|
||||
if (follow) {
|
||||
$follow.find(" > *").toggleClass("hidden");
|
||||
}
|
||||
$data.attr("data-follow", result ? 'on' : 'off');
|
||||
$follow.attr("data-follow", follow ? 'on' : 'off');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<div id="snippet_email_structure" class="tab-pane fade in active">
|
||||
|
||||
|
||||
<div data-snippet-id="text-image" data-selector-children=".oe_structure, [data-oe-type=html]">
|
||||
<div>
|
||||
<div class="oe_snippet_thumbnail">
|
||||
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_text_block.png"/>
|
||||
<span class="oe_snippet_thumbnail_title">Text Block</span>
|
||||
|
@ -63,7 +63,7 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div data-snippet-id="text-image" data-selector-children=".oe_structure, [data-oe-type=html]">
|
||||
<div>
|
||||
<div class="oe_snippet_thumbnail">
|
||||
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_text_image.png"/>
|
||||
<span class="oe_snippet_thumbnail_title">Text-Image</span>
|
||||
|
@ -104,7 +104,7 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div data-snippet-id="image-text" data-selector-children=".oe_structure, [data-oe-type=html]">
|
||||
<div>
|
||||
<div class="oe_snippet_thumbnail">
|
||||
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_image_text.png"/>
|
||||
<span class="oe_snippet_thumbnail_title">Image-Text</span>
|
||||
|
@ -145,7 +145,7 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div data-snippet-id="three-columns" data-selector-children=".oe_structure, [data-oe-type=html]">
|
||||
<div>
|
||||
<div class="oe_snippet_thumbnail">
|
||||
<img class="oe_snippet_thumbnail_img" src="/website_mail/static/src/img/blocks/block_two_columns.png"/>
|
||||
<span class="oe_snippet_thumbnail_title">Two Columns</span>
|
||||
|
@ -185,7 +185,7 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div data-snippet-id="three-columns" data-selector-children=".oe_structure, [data-oe-type=html]">
|
||||
<div>
|
||||
<div class="oe_snippet_thumbnail">
|
||||
<img class="oe_snippet_thumbnail_img" src="/website_mail/static/src/img/blocks/block_three_columns.png"/>
|
||||
<span class="oe_snippet_thumbnail_title">Three Columns</span>
|
||||
|
@ -236,7 +236,7 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div data-snippet-id="hr" data-selector-children=".oe_structure, [data-oe-type=html]">
|
||||
<div>
|
||||
<div class="oe_snippet_thumbnail">
|
||||
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_separator.png"/>
|
||||
<span class="oe_snippet_thumbnail_title">Separator</span>
|
||||
|
@ -262,7 +262,7 @@
|
|||
<div id="snippet_email_feature" class="tab-pane fade">
|
||||
|
||||
|
||||
<div data-snippet-id="big-picture" data-selector-children=".oe_structure, [data-oe-type=html]">
|
||||
<div>
|
||||
<div class="oe_snippet_thumbnail">
|
||||
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_big_picture.png"/>
|
||||
<span class="oe_snippet_thumbnail_title">Big Picture</span>
|
||||
|
@ -298,7 +298,7 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div data-snippet-id="pricing" data-selector-children=".oe_structure, [data-oe-type=html]">
|
||||
<div>
|
||||
<div class="oe_snippet_thumbnail">
|
||||
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_comparison.png"/>
|
||||
<span class="oe_snippet_thumbnail_title">Comparisons</span>
|
||||
|
@ -389,7 +389,7 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div data-snippet-id="text-image" data-selector-children=".oe_structure, [data-oe-type=html]">
|
||||
<div>
|
||||
<div class="oe_snippet_thumbnail">
|
||||
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_jumbotron.png"/>
|
||||
<span class="oe_snippet_thumbnail_title">Big Message</span>
|
||||
|
@ -413,7 +413,7 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div data-snippet-id="cta" data-selector-children=".oe_structure, [data-oe-type=html]">
|
||||
<div>
|
||||
<div class="oe_snippet_thumbnail">
|
||||
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block_button.png"/>
|
||||
<span class="oe_snippet_thumbnail_title">Button</span>
|
||||
|
@ -482,7 +482,10 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div id="snippet_styles" class="hidden">
|
||||
<div id="snippet_options" class="hidden">
|
||||
|
||||
<t t-call="website.snippet_options"/>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -510,11 +513,10 @@
|
|||
type="email"
|
||||
name="email"
|
||||
class="js_follow_email form-control"
|
||||
t-att-value="email or ''"
|
||||
placeholder="your email..."/>
|
||||
<span class="input-group-btn">
|
||||
<button href="#" class="btn btn-default js_unfollow_btn">Unsubscribe</button>
|
||||
<button href="#" class="btn btn-primary js_follow_btn">Subscribe</button>
|
||||
<a href="#" class="btn btn-default js_unfollow_btn">Unsubscribe</a>
|
||||
<a href="#" class="btn btn-primary js_follow_btn">Subscribe</a>
|
||||
</span>
|
||||
<div class="alert alert-success hidden">Thanks for your subscription!</div>
|
||||
</div>
|
||||
|
@ -527,9 +529,9 @@
|
|||
<div data-snippet-option-id='subscribe'
|
||||
data-selector=".js_follow"
|
||||
data-selector-siblings="p, h1, h2, h3, blockquote, .well, .panel"
|
||||
data-selector-children=".content">
|
||||
>
|
||||
<li>
|
||||
<a href="#" class="button js_mailing_list">Select a mailing list</a>
|
||||
<a href="#" class="button js_mailing_list">Change mailing list</a>
|
||||
</li>
|
||||
</div>
|
||||
</xpath>
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
<input
|
||||
type="email" name="email"
|
||||
class="js_follow_email form-control"
|
||||
t-att-value="email or ''"
|
||||
placeholder="your email..."
|
||||
groups="base.group_public"/>
|
||||
<span class="input-group-btn">
|
||||
|
|
Loading…
Reference in New Issue