[MERGE] forward port of branch saas-3 up to revid 9345 dle@openerp.com-20140324110349...
authorChristophe Simonis <chs@openerp.com>
Mon, 24 Mar 2014 13:38:11 +0000 (14:38 +0100)
committerChristophe Simonis <chs@openerp.com>
Mon, 24 Mar 2014 13:38:11 +0000 (14:38 +0100)
bzr revid: chs@openerp.com-20140324133811-4az1kvbznd26seow

1  2 
addons/auth_oauth/controllers/main.py
addons/auth_signup/controllers/main.py
addons/auth_signup/res_users.py
addons/crm/wizard/crm_lead_to_opportunity.py
addons/website/static/src/js/website.editor.js
addons/website/static/src/js/website.snippets.editor.js
addons/website_sale/controllers/main.py
addons/website_sale/views/website_sale.xml

@@@ -77,7 -73,9 +77,10 @@@ class OAuthLogin(openerp.addons.web.con
  
      @http.route()
      def web_login(self, *args, **kw):
 +        ensure_db()
+         if request.httprequest.method == 'GET' and request.session.uid and request.params.get('redirect'):
+             # Redirect if already logged in and redirect param is present
+             return http.redirect_with_hash(request.params.get('redirect'))
          providers = self.list_providers()
  
          response = super(OAuthLogin, self).web_login(*args, **kw)
@@@ -34,68 -34,21 +34,71 @@@ class AuthSignupHome(openerp.addons.web
  
      @http.route()
      def web_login(self, *args, **kw):
 -        mode = request.params.get('mode')
 -        qcontext = request.params.copy()
 -        super_response = None
 +        ensure_db()
 +        response = super(AuthSignupHome, self).web_login(*args, **kw)
 +        response.qcontext.update(self.get_auth_signup_config())
+         if request.httprequest.method == 'GET' and request.session.uid and request.params.get('redirect'):
+             # Redirect if already logged in and redirect param is present
+             return http.redirect_with_hash(request.params.get('redirect'))
 -        if request.httprequest.method != 'POST' or mode not in ('reset', 'signup'):
 -            # Default behavior is to try to login,  which in reset or signup mode in a non-sense.
 -            super_response = super(AuthSignup, self).web_login(*args, **kw)
 -        response = webmain.render_bootstrap_template(request.session.db, 'auth_signup.signup', qcontext, lazy=True)
 -        if isinstance(super_response, LazyResponse):
 -            response.params['values'].update(super_response.params['values'])
 -        token = qcontext.get('token', None)
 -        token_infos = None
 -        if token:
 +        return response
 +
 +    @http.route('/web/signup', type='http', auth='public', website=True, multilang=True)
 +    def web_auth_signup(self, *args, **kw):
 +        qcontext = self.get_auth_signup_qcontext()
 +
 +        if not qcontext.get('token') and not qcontext.get('signup_enabled'):
 +            raise werkzeug.exceptions.NotFound()
 +
 +        if 'error' not in qcontext and request.httprequest.method == 'POST':
 +            try:
 +                self.do_signup(qcontext)
 +                return super(AuthSignupHome, self).web_login(*args, **kw)
 +            except (SignupError, AssertionError), e:
 +                qcontext['error'] = _(e.message)
 +
 +        return request.render('auth_signup.signup', qcontext)
 +
 +    @http.route('/web/reset_password', type='http', auth='public', website=True, multilang=True)
 +    def web_auth_reset_password(self, *args, **kw):
 +        qcontext = self.get_auth_signup_qcontext()
 +
 +        if not qcontext.get('token') and not qcontext.get('reset_password_enabled'):
 +            raise werkzeug.exceptions.NotFound()
 +
 +        if 'error' not in qcontext and request.httprequest.method == 'POST':
 +            try:
 +                if qcontext.get('token'):
 +                    self.do_signup(qcontext)
 +                    return super(AuthSignupHome, self).web_login(*args, **kw)
 +                else:
 +                    login = qcontext.get('login')
 +                    assert login, "No login provided."
 +                    res_users = request.registry.get('res.users')
 +                    res_users.reset_password(request.cr, openerp.SUPERUSER_ID, login)
 +                    qcontext['message'] = _("An email has been sent with credentials to reset your password")
 +            except SignupError:
 +                qcontext['error'] = _("Could not reset your password")
 +                _logger.exception('error when resetting password')
 +            except Exception, e:
 +                qcontext['error'] = _(e.message)
 +
 +
 +        return request.render('auth_signup.reset_password', qcontext)
 +
 +    def get_auth_signup_config(self):
 +        """retrieve the module config (which features are enabled) for the login page"""
 +
 +        icp = request.registry.get('ir.config_parameter')
 +        return {
 +            'signup_enabled': icp.get_param(request.cr, openerp.SUPERUSER_ID, 'auth_signup.allow_uninvited') == 'True',
 +            'reset_password_enabled': icp.get_param(request.cr, openerp.SUPERUSER_ID, 'auth_signup.reset_password') == 'True',
 +        }
 +
 +    def get_auth_signup_qcontext(self):
 +        """ Shared helper returning the rendering context for signup and reset password """
 +        qcontext = request.params.copy()
 +        qcontext.update(self.get_auth_signup_config())
 +        if qcontext.get('token'):
              try:
                  # retrieve the user info (name, login or email) corresponding to a signup token
                  res_partner = request.registry.get('res.partner')
@@@ -90,7 -91,10 +92,10 @@@ class res_partner(osv.Model)
              if res_id:
                  fragment['id'] = res_id
  
-             res[partner.id] = urljoin(base_url, "/web/%s?%s#%s" % (route, urlencode(query), urlencode(fragment)))
+             if fragment:
+                 query['redirect'] = '/web#' + werkzeug.url_encode(fragment)
 -            res[partner.id] = urljoin(base_url, "/web/login?%s" % werkzeug.url_encode(query))
++            res[partner.id] = urljoin(base_url, "/web/%s?%s" % (route, werkzeug.url_encode(query)))
  
          return res
  
@@@ -18,8 -18,7 +18,7 @@@
          },
          edit: function () {
              var self = this;
 -            $("body").off('click');
 +            $("[data-oe-model] *, [data-oe-type=html] *").off('click');
-             website.snippet.stop_animation();
              window.snippets = this.snippets = new website.snippet.BuildingBlock(this);
              this.snippets.appendTo(this.$el);
              this.on('rte:ready', this, function () {
                      }
  
                      $('.oe_drop_zone').droppable('destroy').remove();
 +                    
                      if (dropped) {
                          var $target = false;
 -                        if(action === 'insert'){
 -                            $target = $toInsert;
 +                        $target = $toInsert;
 +
 +                        setTimeout(function () {
 +                            $("#oe_snippets").trigger('snippet-dropped', $target);
  
 +                            website.snippet.start_animation(true, $target);
 +                            // drop_and_build_snippet
                              self.create_overlay($target);
                              if ($target.data("snippet-editor")) {
                                  $target.data("snippet-editor").drop_and_build_snippet($target);
              this.grid.size = 8;
              return this.grid;
          },
 -        drop_and_build_snippet: function() {
 -            var id = $(".carousel").length;
 -            this.id = "myCarousel" + id;
 -            this.$target.attr("id", this.id);
 -            this.$target.find(".carousel-control").attr("href", "#myCarousel" + id);
 -            this.$target.find("[data-target]").attr("data-target", "#myCarousel" + id);
 -
 -            this.rebind_event();
 -        },
 -        // rebind event to active carousel on edit mode
 -        rebind_event: function () {
 -            var self = this;
 -            this.$target.find('.carousel-indicators [data-target]').off('click').on('click', function () {
 -                self.$target.carousel(+$(this).data('slide-to')); });
 -
 -            this.$target.attr('contentEditable', 'false');
 -            this.$target.find('.oe_structure, .content>.row').attr('contentEditable', 'true');
 -        },
 -        clean_for_save: function () {
 -            this._super();
 -            this.$target.find(".item").removeClass("next prev left right");
 -            if(!this.$target.find(".item.active").length) {
 -                this.$target.find(".item:first").addClass("active");
 -            }
 -        },
 -        start : function () {
 -            var self = this;
 -            this._super();
+             this.$target.carousel({interval: false});
 -            this.id = this.$target.attr("id");
 -            this.$inner = this.$target.find('.carousel-inner');
 -            this.$indicators = this.$target.find('.carousel-indicators');
 -
 -            this.$editor.find(".js_add").on('click', function () {self.on_add_slide(); return false;});
 -            this.$editor.find(".js_remove").on('click', function () {self.on_remove_slide(); return false;});
 -
 -            this.rebind_event();
 -        },
 -        on_add_slide: function () {
 -            var self = this;
 -            var cycle = this.$inner.find('.item').length;
 -            var $active = this.$inner.find('.item.active, .item.prev, .item.next').first();
 -            var index = $active.index();
 -            this.$target.find('.carousel-control, .carousel-indicators').removeClass("hidden");
 -            this.$indicators.append('<li data-target="#' + this.id + '" data-slide-to="' + cycle + '"></li>');
 -
 -            var $clone = this.$el.find(".item.active").clone();
 -
 -            // insert
 -            $clone.removeClass('active').insertAfter($active);
 -            setTimeout(function() {
 -                self.$target.carousel().carousel(++index);
 -                self.rebind_event();
 -            },0);
 -            return $clone;
 -        },
 -        on_remove_slide: function () {
 -            if (this.remove_process) {
 -                return;
 -            }
 -            var self = this;
 -            var new_index = 0;
 -            var cycle = this.$inner.find('.item').length - 1;
 -            var index = this.$inner.find('.item.active').index();
 -
 -            if (cycle > 0) {
 -                this.remove_process = true;
 -                var $el = this.$inner.find('.item.active');
 -                self.$target.on('slid.bs.carousel', function (event) {
 -                    $el.remove();
 -                    self.$indicators.find("li:last").remove();
 -                    self.$target.off('slid.bs.carousel');
 -                    self.rebind_event();
 -                    self.remove_process = false;
 -                    if (cycle == 1) {
 -                        self.on_remove_slide(event);
 -                    }
 -                });
 -                setTimeout(function () {
 -                    self.$target.carousel( index > 0 ? --index : cycle );
 -                }, 500);
 -            } else {
 -                this.$target.find('.carousel-control, .carousel-indicators').addClass("hidden");
 -            }
 -        },
 -    });
 -
 -    website.snippet.editorRegistry.carousel = website.snippet.editorRegistry.slider.extend({
 -        clean_for_save: function () {
 -            this._super();
 -            this.$target.css("background-image", "");
 -            this.$target.removeClass(this._class);
 -        },
 -        load_style_options : function () {
 -            this._super();
 -            $(".snippet-style-size li[data-class='']").remove();
 -        },
 -        start : function () {
 -            var self = this;
 -            this._super();
 -
 -            // set background and prepare to clean for save
 -            var add_class = function (c){
 -                if (c) self._class = (self._class || "").replace(new RegExp("[ ]+" + c.replace(" ", "|[ ]+")), '') + ' ' + c;
 -                return self._class || "";
 -            };
 -            this.$target.on('snippet-style-change snippet-style-preview', function (event, style, np) {
 -                var $active = self.$target.find(".item.active");
 -                if (style['snippet-style-id'] === "size") return;
 -                if (style['snippet-style-id'] === "background") {
 -                    $active.css("background-image", self.$target.css("background-image"));
 -                }
 -                if (np.$prev) {
 -                    $active.removeClass(np.$prev.data("class"));
 -                }
 -                if (np.$next) {
 -                    $active.addClass(np.$next.data("class"));
 -                    add_class(np.$next.data("class"));
 -                }
 -            });
 -            this.$target.on('slid', function () { // slide.bs.carousel
 -                var $active = self.$target.find(".item.active");
 -                self.$target
 -                    .css("background-image", $active.css("background-image"))
 -                    .removeClass(add_class($active.attr("class")))
 -                    .addClass($active.attr("class"))
 -                    .trigger("snippet-style-reset");
 -
 -                self.$target.carousel();
 -            });
 -            this.$target.trigger('slid');
 -        },
 -        on_add_slide: function () {
 -            var $clone = this._super();
 -
 -            // choose an other background
 -            var $styles = this.$target.data("snippet-style-ids").background.$el.find("li[data-class]:not(.oe_custom_bg)");
 -            var styles_index = $styles.index($styles.filter(".active")[0]);
 -            var $select = $($styles[styles_index >= $styles.length-1 ? 0 : styles_index+1]);
 -            $clone.css("background-image", $select.data("src") ? "url('"+ $select.data("src") +"')" : "");
 -            $clone.addClass($select.data("class") || "");
 -
 -            return $clone;
 -        },
 -        // rebind event to active carousel on edit mode
 -        rebind_event: function () {
 -            var self = this;
 -            this.$target.find('.carousel-control').off('click').on('click', function () {
 -                self.$target.carousel( $(this).data('slide')); });
 -
 -            this.$target.find('.carousel-image, .carousel-inner .content > div').attr('contentEditable', 'true');
 -            this.$target.find('.carousel-image').attr('attributeEditable', 'true');
 -            this._super();
 -        },
      });
  
 -    website.snippet.editorRegistry.parallax = website.snippet.editorRegistry.resize.extend({
 +    website.snippet.options.parallax = website.snippet.Option.extend({
          getSize: function () {
              this.grid = this._super();
              this.grid.size = 8;