[FIX] website_mail, websit_mail_group: moved discussion group snippet to the right...
authorThibault Delavallée <tde@openerp.com>
Wed, 28 May 2014 09:12:33 +0000 (11:12 +0200)
committerThibault Delavallée <tde@openerp.com>
Wed, 28 May 2014 09:12:33 +0000 (11:12 +0200)
addons/website_mail/controllers/main.py
addons/website_mail/static/src/js/website_mail.editor.js [deleted file]
addons/website_mail/static/src/js/website_mail.js [deleted file]
addons/website_mail/views/snippets.xml
addons/website_mail/views/website_mail.xml
addons/website_mail_group/__openerp__.py
addons/website_mail_group/controllers/main.py
addons/website_mail_group/static/src/js/website_mail_group.editor.js [new file with mode: 0644]
addons/website_mail_group/static/src/js/website_mail_group.snippet.js [new file with mode: 0644]
addons/website_mail_group/views/snippets.xml [new file with mode: 0644]
addons/website_mail_group/views/website_mail_group.xml

index 8cdb730..081ba93 100644 (file)
@@ -100,20 +100,3 @@ class WebsiteMail(http.Controller):
                         ], context=context)) == 1
 
         return values
-
-    @http.route(['/website_mail/get_alias_info'], type='json', auth='public', website=True)
-    def get_alias_info(self, model, id, **post):
-        id = int(id)
-        cr, uid, context = request.cr, request.uid, request.context
-        obj = request.registry.get(model)
-
-        values = {'alias_name': False}
-
-        if not obj:
-            return values
-        obj_ids = obj.exists(cr, SUPERUSER_ID, [id], context=context)
-        if obj_ids and 'alias_id' in obj._all_columns:
-            alias_id = obj.browse(cr, SUPERUSER_ID, obj_ids[0], context=context).alias_id
-            values['alias_name'] = alias_id and alias_id.alias_domain and '%s@%s' % (alias_id.alias_name, alias_id.alias_domain) or False
-
-        return values
diff --git a/addons/website_mail/static/src/js/website_mail.editor.js b/addons/website_mail/static/src/js/website_mail.editor.js
deleted file mode 100644 (file)
index fdfb948..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-(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("Add a Subscribe Button"),
-                select: _t("Discussion 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();
-        },
-        clean_for_save: function () {
-            this.$target.addClass("hidden");
-        },
-    });
-})();
-
-
diff --git a/addons/website_mail/static/src/js/website_mail.js b/addons/website_mail/static/src/js/website_mail.js
deleted file mode 100644 (file)
index 2a79bcc..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-(function () {
-    'use strict';
-
-    var website = openerp.website;
-
-    website.snippet.animationRegistry.follow = website.snippet.Animation.extend({
-        selector: ".js_follow",
-        start: function (editable_mode) {
-            var self = this;
-            this.is_user = false;
-
-            openerp.jsonRpc('/website_mail/is_follower', 'call', {
-                model: this.$target.data('object'),
-                id: this.$target.data('id'),
-                get_alias_info: true,
-            }).always(function (data) {
-                self.is_user = data.is_user;
-                self.email = data.email;
-                self.$target.find('.js_mg_link').attr('href', '/groups/' + self.$target.data('id'));
-                self.toggle_subscription(data.is_follower, data.email);
-                self.$target.removeClass("hidden");
-            });
-
-            // not if editable mode to allow designer to edit alert field
-            if (!editable_mode) {
-                $('.js_follow > .alert').addClass("hidden");
-                $('.js_follow > .input-group-btn.hidden').removeClass("hidden");
-                this.$target.find('.js_follow_btn, .js_unfollow_btn').on('click', function (event) {
-                    event.preventDefault();
-                    self.on_click();
-                });
-            }
-            return;
-        },
-        on_click: function () {
-            var self = this;
-            var $email = this.$target.find(".js_follow_email");
-
-            if ($email.length && !$email.val().match(/.+@.+/)) {
-                this.$target.addClass('has-error');
-                return false;
-            }
-            this.$target.removeClass('has-error');
-
-            openerp.jsonRpc('/website_mail/follow', 'call', {
-                'id': +this.$target.data('id'),
-                'object': this.$target.data('object'),
-                'message_is_follower': this.$target.attr("data-follow") || "off",
-                'email': $email.length ? $email.val() : false,
-            }).then(function (follow) {
-                self.toggle_subscription(follow, self.email);
-            });
-        },
-        toggle_subscription: function(follow, email) {
-            var alias_done = this.get_alias_info();
-            if (follow) {
-                this.$target.find(".js_mg_follow_form").addClass("hidden");
-                this.$target.find(".js_mg_details").removeClass("hidden");
-            }
-            else {
-                this.$target.find(".js_mg_follow_form").removeClass("hidden");
-                this.$target.find(".js_mg_details").addClass("hidden");
-            }
-            this.$target.find('input.js_follow_email')
-                .val(email ? email : "")
-                .attr("disabled", follow || (email.length && this.is_user) ? "disabled" : false);
-            this.$target.attr("data-follow", follow ? 'on' : 'off');
-            return $.when(alias_done);
-        },
-        get_alias_info: function() {
-            var self = this;
-            return openerp.jsonRpc('/website_mail/get_alias_info', 'call', {
-                model: this.$target.data('object'),
-                id: this.$target.data('id'),
-            }).then(function (data) {
-                self.$target.find('.js_mg_email').attr('href', 'mailto:' + data.alias_name);
-            });
-        }
-    });
-
-    $(document).ready(function () {
-        $('.js_follow_btn').on('click', function (ev) {
-            var email = $(ev.currentTarget).parents('.js_mg_follow_form').first().find('.js_follow_email').val();
-            $(document).find('.js_follow_email').val(email);
-        });
-    });
-})();
index 8a737b9..ebbcf6d 100644 (file)
 
 </template>
 
-
-<template id="subscribe" inherit_id="website.snippets" name="Snippet Subscribe">
-
-    <xpath expr="//div[@id='snippet_content']" position="inside">
-        <div>
-            <div class="oe_snippet_thumbnail">
-                <img class="oe_snippet_thumbnail_img" src="/website_mail/static/src/img/blocks/button_group_subscribe.png"/>
-                <span class="oe_snippet_thumbnail_title">Discussion Group</span>
-            </div>
-
-            <div class="oe_snippet_body js_follow"
-                      data-id="0"
-                      data-object="mail.group"
-                      data-follow="off">
-                <div class="input-group js_mg_follow_form">
-                    <input
-                          type="email"
-                          name="email"
-                          class="js_follow_email form-control"
-                          placeholder="your email..."/>
-                    <span class="input-group-btn">
-                        <button href="#" class="btn btn-primary js_follow_btn">Subscribe</button>
-                    </span>
-                </div>
-                <p class="js_mg_details hidden well well-sm">
-                    <i class="fa fa-envelope-o"/><a href="#" class="js_mg_email"> send mail</a> -
-                    <i class="fa fa-file-o"/><a href="#" class="js_mg_link"> archives</a> -
-                    <i class="fa fa-times"/><a href="#" class="js_unfollow_btn"> unsubscribe</a>
-                </p>
-            </div>
-
-        </div>
-    </xpath>
-
-
-    <xpath expr="//div[@id='snippet_options']" position="inside">
-        <div data-snippet-option-id='subscribe'
-            data-selector=".js_follow"
-            data-selector-siblings="p, h1, h2, h3, blockquote, .well, .panel"
-           >
-            <li>
-                <a href="#" class="button js_mailing_list">Change Discussion List</a>
-            </li>
-        </div>
-    </xpath>
-
-</template>
-
 </data>
 </openerp>
index 2882125..6202e00 100644 (file)
@@ -21,8 +21,6 @@
 
 <template id="head" inherit_id="website.layout" name="Mail customization">
     <xpath expr="//head" position="inside">
-        <script type="text/javascript" src="/website_mail/static/src/js/website_mail.editor.js" groups="base.group_website_publisher"></script>
-        <script type="text/javascript" src="/website_mail/static/src/js/website_mail.js"></script>
         <link rel='stylesheet' href='/website_mail/static/src/css/website_mail.css'/>
     </xpath>
 </template>
index f83fc38..768e7f2 100644 (file)
@@ -11,7 +11,8 @@ OpenERP Mail Group : Mailing List Archives
     'author': 'OpenERP SA',
     'depends': ['website_mail'],
     'data': [
-        'views/website_mail_group.xml'
+        'views/website_mail_group.xml',
+        'views/snippets.xml',
     ],
     'qweb': [],
     'installable': True,
index 7320ebc..a28b808 100644 (file)
@@ -129,3 +129,9 @@ class MailGroup(http.Controller):
             'replies_per_page': self._replies_per_page,
         }
         return request.registry['ir.ui.view'].render(request.cr, request.uid, 'website_mail_group.messages_short', values, engine='ir.qweb', context=request.context)
+
+    @http.route("/groups/<model('mail.group'):group>/get_alias_info", type='json', auth='public', website=True)
+    def get_alias_info(self, group, **post):
+        return {
+            'alias_name': group.alias_id and group.alias_id.alias_name and group.alias_id.alias_domain and '%s@%s' % (group.alias_id.alias_name, group.alias_id.alias_domain) or False
+        }
diff --git a/addons/website_mail_group/static/src/js/website_mail_group.editor.js b/addons/website_mail_group/static/src/js/website_mail_group.editor.js
new file mode 100644 (file)
index 0000000..fdfb948
--- /dev/null
@@ -0,0 +1,40 @@
+(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("Add a Subscribe Button"),
+                select: _t("Discussion 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();
+        },
+        clean_for_save: function () {
+            this.$target.addClass("hidden");
+        },
+    });
+})();
+
+
diff --git a/addons/website_mail_group/static/src/js/website_mail_group.snippet.js b/addons/website_mail_group/static/src/js/website_mail_group.snippet.js
new file mode 100644 (file)
index 0000000..fc0e2bb
--- /dev/null
@@ -0,0 +1,94 @@
+(function () {
+    'use strict';
+
+    var website = openerp.website;
+
+    website.snippet.animationRegistry.follow = website.snippet.Animation.extend({
+        selector: ".js_follow",
+        start: function (editable_mode) {
+            var self = this;
+            this.is_user = false;
+
+            openerp.jsonRpc('/website_mail/is_follower', 'call', {
+                model: this.$target.data('object'),
+                id: this.$target.data('id'),
+                get_alias_info: true,
+            }).always(function (data) {
+                self.is_user = data.is_user;
+                self.email = data.email;
+                self.$target.find('.js_mg_link').attr('href', '/groups/' + self.$target.data('id'));
+                self.toggle_subscription(data.is_follower, data.email);
+                self.$target.removeClass("hidden");
+            });
+
+            // not if editable mode to allow designer to edit alert field
+            if (!editable_mode) {
+                $('.js_follow > .alert').addClass("hidden");
+                $('.js_follow > .input-group-btn.hidden').removeClass("hidden");
+                this.$target.find('.js_follow_btn, .js_unfollow_btn').on('click', function (event) {
+                    event.preventDefault();
+                    self.on_click();
+                });
+            }
+            return;
+        },
+        on_click: function () {
+            event.preventDefault();
+            var self = this;
+            var $email = this.$target.find(".js_follow_email");
+
+            if ($email.length && !$email.val().match(/.+@.+/)) {
+                this.$target.addClass('has-error');
+                return false;
+            }
+            this.$target.removeClass('has-error');
+
+            openerp.jsonRpc('/website_mail/follow', 'call', {
+                'id': +this.$target.data('id'),
+                'object': this.$target.data('object'),
+                'message_is_follower': this.$target.attr("data-follow") || "off",
+                'email': $email.length ? $email.val() : false,
+            }).then(function (follow) {
+                self.toggle_subscription(follow, self.email);
+            });
+        },
+        toggle_subscription: function(follow, email) {
+            var alias_done = this.get_alias_info();
+            if (follow) {
+                this.$target.find(".js_mg_follow_form").addClass("hidden");
+                this.$target.find(".js_mg_details").removeClass("hidden");
+            }
+            else {
+                this.$target.find(".js_mg_follow_form").removeClass("hidden");
+                this.$target.find(".js_mg_details").addClass("hidden");
+            }
+            this.$target.find('input.js_follow_email')
+                .val(email ? email : "")
+                .attr("disabled", follow || (email.length && this.is_user) ? "disabled" : false);
+            this.$target.attr("data-follow", follow ? 'on' : 'off');
+            return $.when(alias_done);
+        },
+        get_alias_info: function() {
+            var self = this;
+            if (! this.$target.data('id')) {
+                return $.Deferred().resolve();
+            }
+            return openerp.jsonRpc('/groups/' + this.$target.data('id') + '/get_alias_info', 'call', {}).then(function (data) {
+                if (data.alias_name) {
+                    self.$target.find('.js_mg_email').attr('href', 'mailto:' + data.alias_name);
+                    self.$target.find('.js_mg_email').removeClass('hidden');
+                }
+                else {
+                    self.$target.find('.js_mg_email').addClass('hidden');
+                }
+            });
+        }
+    });
+
+    $(document).ready(function () {
+        $('.js_follow_btn').on('click', function (ev) {
+            var email = $(ev.currentTarget).parents('.js_mg_follow_form').first().find('.js_follow_email').val();
+            $(document).find('.js_follow_email').val(email);
+        });
+    });
+})();
diff --git a/addons/website_mail_group/views/snippets.xml b/addons/website_mail_group/views/snippets.xml
new file mode 100644 (file)
index 0000000..56ba81d
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+<data>
+
+<template id="subscribe" inherit_id="website.snippets" name="Snippet Subscribe">
+
+    <xpath expr="//div[@id='snippet_content']" position="inside">
+        <div>
+            <div class="oe_snippet_thumbnail">
+                <img class="oe_snippet_thumbnail_img" src="/website_mail/static/src/img/blocks/button_group_subscribe.png"/>
+                <span class="oe_snippet_thumbnail_title">Discussion Group</span>
+            </div>
+
+            <div class="oe_snippet_body js_follow"
+                      data-id="0"
+                      data-object="mail.group"
+                      data-follow="off">
+                <div class="input-group js_mg_follow_form">
+                    <input
+                          type="email"
+                          name="email"
+                          class="js_follow_email form-control"
+                          placeholder="your email..."/>
+                    <span class="input-group-btn">
+                        <button href="#" class="btn btn-primary js_follow_btn">Subscribe</button>
+                    </span>
+                </div>
+                <p class="js_mg_details hidden well well-sm">
+                    <span class="js_mg_email hidden"><i class="fa fa-envelope-o"/><a href="#" class="js_mg_email"> send mail</a> - </span>
+                    <i class="fa fa-file-o"/><a href="#" class="js_mg_link"> archives</a> -
+                    <i class="fa fa-times"/><a href="#" class="js_unfollow_btn"> unsubscribe</a>
+                </p>
+            </div>
+
+        </div>
+    </xpath>
+
+
+    <xpath expr="//div[@id='snippet_options']" position="inside">
+        <div data-snippet-option-id='subscribe'
+            data-selector=".js_follow"
+            data-selector-siblings="p, h1, h2, h3, blockquote, .well, .panel"
+           >
+            <li>
+                <a href="#" class="button js_mailing_list">Change Discussion List</a>
+            </li>
+        </div>
+    </xpath>
+
+</template>
+
+</data>
+</openerp>
\ No newline at end of file
index 76edd52..1c0ee08 100644 (file)
@@ -8,6 +8,13 @@
     </xpath>
 </template>
 
+<template id="head" inherit_id="website.layout" name="Mail Group Customization">
+    <xpath expr="//head" position="inside">
+        <script type="text/javascript" src="/website_mail_group/static/src/js/website_mail_group.editor.js" groups="base.group_website_publisher"></script>
+        <script type="text/javascript" src="/website_mail_group/static/src/js/website_mail_group.snippet.js"></script>
+    </xpath>
+</template>
+
 <template id="mail_groups" name="Mailing Lists">
     <t t-call="website.layout">
         <div id="wrap" class="oe_structure oe_empty">
                 <div class="col-md-3">
                     <img t-att-src="'/website/image?model=mail.group&amp;field=image_small&amp;id='+str(group['id'])" class="pull-left"/>
                     <strong><a t-attf-href="/groups/#{ slug(group) }" t-esc="group.name"/></strong><br />
-                    <i class='fa fa-envelope-o'/>
-                    <a t-attf-href="mailto:#{group.alias_id.alias_name}@#{group.alias_id.alias_domain}"><span t-field="group.alias_id"/></a>
+                    <t t-if="group.alias_id and group.alias_id.alias_name and group.alias_id.alias_domain">
+                        <i class='fa fa-envelope-o'/>
+                        <a t-attf-href="mailto:#{group.alias_id.alias_name}@#{group.alias_id.alias_domain}"><span t-field="group.alias_id"/></a>
+                    </t>
                 </div>
                 <div class="col-md-4">
                     <div t-esc="group.description" class="text-muted"/>
@@ -59,7 +68,7 @@
             <div class="row">
                 <h1 class="text-center">
                     <t t-esc="group.name"/> mailing list archives
-                </h1><h4 class="text-center text-muted">
+                </h1><h4 class="text-center text-muted" t-if="group.alias_id and group.alias_id.alias_name and group.alias_id.alias_domain">
                     <i class='fa fa-envelope-o'/>
                     <a t-attf-href="mailto:#{group.alias_id.alias_name}@#{group.alias_id.alias_domain}"><span t-field="group.alias_id"/></a>
                 </h4>
             <div class="row">
                 <h1 class="text-center">
                     <t t-esc="group.name"/> mailing list archives
-                </h1><h4 class="text-center text-muted">
+                </h1><h4 class="text-center text-muted" t-if="group.alias_id and group.alias_id.alias_name and group.alias_id.alias_domain">
                     <i class='fa fa-envelope-o'/>
                     <a t-attf-href="mailto:#{group.alias_id.alias_name}@#{group.alias_id.alias_domain}"><span t-field="group.alias_id"/></a>
                 </h4>