diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 95c7ad82e2b..b155317d826 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -378,6 +378,14 @@ class Website(openerp.addons.web.controllers.main.Home): del response.headers['Content-Length'] return response + + @http.route(['/website/current_user/'], type='json', auth="public", website=True) + def get_current_user(self, fields): + cr, uid, context = request.cr, request.uid, request.context + if request.registry["website"].get_public_user(cr, uid, context=context) != uid: + return request.registry["res.users"].read(cr, openerp.SUPERUSER_ID, [uid], fields, context=context)[0] + else: + return None #------------------------------------------------------ # Server actions diff --git a/addons/website/static/src/js/website.snippets.animation.js b/addons/website/static/src/js/website.snippets.animation.js index 933f4b8e6ed..173cdf39a58 100644 --- a/addons/website/static/src/js/website.snippets.animation.js +++ b/addons/website/static/src/js/website.snippets.animation.js @@ -127,4 +127,41 @@ } }); + website.snippet.animationRegistry.share = website.snippet.Animation.extend({ + selector: ".oe_share", + start: function () { + var self = this; + var url = encodeURIComponent(window.location.href); + var title = encodeURIComponent($("title").text()); + this.$target.find(".oe_share_facebook").attr("href", + "https://www.facebook.com/sharer/sharer.php?u="+url); + this.$target.find(".oe_share_twitter").attr("href", + "https://twitter.com/intent/tweet?text="+title+"&related=&url="+url); + this.$target.find(".oe_share_linkedin").attr("href", + "http://www.linkedin.com/shareArticle?mini=true&url="+url+"&title="+title+"&summary=&source="); + this.$target.find(".oe_share_google").attr("href", + "https://plus.google.com/share?url="+url); + this.$target.find("a").click(function () { + window.open(this.href,'','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=550,width=600'); + }); + + var $modal = this.$target.find(".oe_share_mail_modal"); + var $from = $modal.find("input[name='from']").parent().parent(); + this.$target.find(".oe_share_mail").off("click").click(function () { + // open popover + $modal.modal("show"); + }); + $modal.find("input[name='url']").attr("value", window.location.href); + openerp.jsonRpc('/website/current_user/', 'call', { + fields: ["email"] + }).then(function (result) { + if (result) $from.addClass("hidden"); + else $from.removeClass("hidden"); + }); + $modal.find(".btn-primary").click(function () { + $modal.modal("hide"); + console.log("valid"); + }); + }, + }); })(); diff --git a/addons/website/views/snippets.xml b/addons/website/views/snippets.xml index 53e2d87186d..f592286c8f7 100644 --- a/addons/website/views/snippets.xml +++ b/addons/website/views/snippets.xml @@ -336,6 +336,73 @@