[MERGE] forward port of branch saas-3 up to fdc6271
[odoo/odoo.git] / addons / web / static / src / js / chrome.js
index 0aa46eb..f965879 100644 (file)
@@ -46,6 +46,8 @@ instance.web.Notification =  instance.web.Widget.extend({
     }
 });
 
+var opened_modal = [];
+
 instance.web.action_notify = function(element, action) {
     element.do_notify(action.params.title, action.params.text, action.params.sticky);
 };
@@ -113,6 +115,9 @@ instance.web.Dialog = instance.web.Widget.extend({
             this.init_dialog();
         }
         this.$buttons.insertAfter(this.$dialog_box.find(".modal-body"));
+        $('.tooltip').remove(); //remove open tooltip if any to prevent them staying when modal is opened
+        //add to list of currently opened modal
+        opened_modal.push(this.$dialog_box);
         return this;
     },
     _add_buttons: function(buttons) {
@@ -152,7 +157,7 @@ instance.web.Dialog = instance.web.Widget.extend({
             'keyboard': true,
         });
         if (options.size !== 'large'){
-            var dialog_class_size = this.$dialog_box.find('.modal-lg').removeClass('modal-lg')
+            var dialog_class_size = this.$dialog_box.find('.modal-lg').removeClass('modal-lg');
             if (options.size === 'small'){
                 dialog_class_size.addClass('modal-sm');
             }
@@ -165,7 +170,7 @@ instance.web.Dialog = instance.web.Widget.extend({
         }
         $dialog_content.openerpClass();
 
-        this.$dialog_box.on('hidden.bs.modal', this, function(){
+        this.$dialog_box.on('hidden.bs.modal', this, function() {
             self.close();
         });
         this.$dialog_box.modal('show');
@@ -175,14 +180,17 @@ instance.web.Dialog = instance.web.Widget.extend({
         return res;
     },
     /**
-        Closes the popup, if destroy_on_close was passed to the constructor, it is also destroyed.
+        Closes (hide) the popup, if destroy_on_close was passed to the constructor, it will be destroyed instead.
     */
     close: function(reason) {
-        if (this.dialog_inited) {
-            this.trigger("closing", reason);
+        if (this.dialog_inited && !this.__tmp_dialog_hiding) {
+            $('.tooltip').remove(); //remove open tooltip if any to prevent them staying when modal has disappeared
             if (this.$el.is(":data(bs.modal)")) {     // may have been destroyed by closing signal
-               this.$el.parents('.modal').modal('hide');
+                this.__tmp_dialog_hiding = true;
+                this.$dialog_box.modal('hide');
+                this.__tmp_dialog_hiding = undefined;
             }
+            this.trigger("closing", reason);
         }
     },
     _closing: function() {
@@ -212,9 +220,17 @@ instance.web.Dialog = instance.web.Widget.extend({
             //we need this to put the instruction to remove modal from DOM at the end
             //of the queue, otherwise it might already have been removed before the modal-backdrop
             //is removed when pressing escape key
-            var $parent = this.$el.parents('.modal');
+            var $element = this.$dialog_box;
             setTimeout(function () {
-                $parent.remove();
+                //remove modal from list of opened modal since we just destroy it
+                var modal_list_index = $.inArray($element, opened_modal);
+                if (modal_list_index > -1){
+                    opened_modal.splice(modal_list_index,1)[0].remove();
+                }
+                if (opened_modal.length > 0){
+                    //we still have other opened modal so we should focus it
+                    opened_modal[opened_modal.length-1].focus();
+                }
             },0);
         }
         this._super();
@@ -239,8 +255,7 @@ instance.web.CrashManager = instance.web.Class.extend({
             this.show_warning({type: "Session Expired", data: { message: _t("Your OpenERP session expired. Please refresh the current web page.") }});
             return;
         }
-        if (error.data.exception_type === "except_osv" || error.data.exception_type === "warning"
-                || error.data.exception_type === "access_error") {
+        if (error.data.exception_type === "except_osv" || error.data.exception_type === "warning" || error.data.exception_type === "access_error") {
             this.show_warning(error);
         } else {
             this.show_error(error);
@@ -480,7 +495,7 @@ instance.web.DatabaseManager = instance.web.Widget.extend({
             size: 'medium',
             title: error.title,
             buttons: [
-                {text: _t("Ok"), click: function() { this.$el.parents('.modal').modal('hide'); }}
+                {text: _t("Ok"), click: function() { this.parents('.modal').modal('hide'); }}
             ]
         }, $('<div>').html(error.error)).open();
     },
@@ -693,7 +708,7 @@ instance.web.ChangePassword =  instance.web.Widget.extend({
         var $button = self.$el.find('.oe_form_button');
         $button.appendTo(this.getParent().$buttons);
         $button.eq(2).click(function(){
-           self.getParent().close();
+           self.$el.parents('.modal').modal('hide');
         });
         $button.eq(0).click(function(){
           self.rpc("/web/session/change_password",{
@@ -713,7 +728,7 @@ instance.web.ChangePassword =  instance.web.Widget.extend({
             size: 'medium',
             title: error.title,
             buttons: [
-                {text: _t("Ok"), click: function() { this.$el.parents('.modal').modal('hide'); }}
+                {text: _t("Ok"), click: function() { this.parents('.modal').modal('hide'); }}
             ]
         }, $('<div>').html(error.error)).open();
     },
@@ -859,8 +874,9 @@ instance.web.Menu =  instance.web.Widget.extend({
                 $clicked_menu.parent().addClass('active');
             }
         }
+        // add a tooltip to cropped menu items
         this.$secondary_menus.find('.oe_secondary_submenu li a span').each(function() {
-            $(this).tooltip(this.scrollWidth > this.clientWidth? {title: $(this).text().trim()} :'destroy');
+            $(this).tooltip(this.scrollWidth > this.clientWidth ? {title: $(this).text().trim(), placement: 'auto right'} :'destroy');
        });
     },
     /**
@@ -992,7 +1008,7 @@ instance.web.UserMenu =  instance.web.Widget.extend({
         this.update_promise = this.update_promise.then(fct, fct);
     },
     on_menu_help: function() {
-        window.open('http://help.openerp.com', '_blank');
+        window.open('http://help.odoo.com', '_blank');
     },
     on_menu_logout: function() {
         this.trigger('user_logout');
@@ -1021,7 +1037,10 @@ instance.web.UserMenu =  instance.web.Widget.extend({
                     state: JSON.stringify(state),
                     scope: 'userinfo',
                 };
-                instance.web.redirect('https://accounts.openerp.com/oauth2/auth?'+$.param(params));
+                instance.web.redirect('https://accounts.odoo.com/oauth2/auth?'+$.param(params));
+            }).fail(function(result, ev){
+                ev.preventDefault();
+                instance.web.redirect('https://accounts.odoo.com/web');
             });
         }
     },
@@ -1106,7 +1125,7 @@ instance.web.Client = instance.web.Widget.extend({
             }, 0);
         });
         instance.web.bus.on('click', this, function(ev) {
-            $.fn.tooltip('destroy');
+            $('.tooltip').remove();
             if (!$(ev.target).is('input[type=file]')) {
                 self.$el.find('.oe_dropdown_menu.oe_opened, .oe_dropdown_toggle.oe_opened').removeClass('oe_opened');
             }