[FIX] Error while deleting a record when there is only one record in pageview
[odoo/odoo.git] / addons / web / static / src / js / views.js
index 5ec9262..fd080c8 100644 (file)
@@ -57,7 +57,7 @@ session.web.ActionManager = session.web.OldWidget.extend({
             this.widget_parent.do_push_state(state);
         }
     },
-    do_load_state: function(state) {
+    do_load_state: function(state, warm) {
         var self = this,
             action_loaded;
         if (state.action_id) {
@@ -92,7 +92,7 @@ session.web.ActionManager = session.web.OldWidget.extend({
 
         $.when(action_loaded || null).then(function() {
             if (self.inner_viewmanager) {
-                self.inner_viewmanager.do_load_state(state);
+                self.inner_viewmanager.do_load_state(state, warm);
             }
         });
     },
@@ -364,6 +364,7 @@ session.web.ViewManager =  session.web.OldWidget.extend(/** @lends session.web.V
      * @returns {$.Deferred} switching end signal
      */
     on_prev_view: function (options) {
+       options = options || {};
         var current_view = this.views_history.pop();
         var previous_view = this.views_history[this.views_history.length - 1] || options['default'];
         if (options.created && current_view === 'form' && previous_view === 'list') {
@@ -408,6 +409,9 @@ session.web.ViewManager =  session.web.OldWidget.extend(/** @lends session.web.V
             var groupby = results.group_by.length
                         ? results.group_by
                         : action_context.group_by;
+            if (_.isString(groupby)) {
+                groupby = [groupby];
+            }
             controller.do_search(results.domain, results.context, groupby || []);
         });
     },
@@ -602,16 +606,6 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner
                         width: '95%'}, $root).open();
                 });
                 break;
-            case 'customize_object':
-                this.rpc('/web/dataset/search_read', {
-                    model: 'ir.model',
-                    fields: ['id'],
-                    domain: [['model', '=', this.dataset.model]]
-                }, function (result) {
-                    self.do_edit_resource('ir.model', result.ids[0], {
-                        name : _t("Customize Object") });
-                });
-                break;
             case 'manage_views':
                 if (current_view.fields_view && current_view.fields_view.arch) {
                     var view_editor = new session.web.ViewEditor(current_view, current_view.$element, this.dataset, current_view.fields_view.arch);
@@ -695,7 +689,7 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner
             this.widget_parent.do_push_state(state);
         }
     },
-    do_load_state: function(state) {
+    do_load_state: function(state, warm) {
         var self = this,
             defs = [];
         if (state.view_type && state.view_type !== this.active_view) {
@@ -707,7 +701,7 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner
         } 
 
         $.when(defs).then(function() {
-            self.views[self.active_view].controller.do_load_state(state);
+            self.views[self.active_view].controller.do_load_state(state, warm);
         });
     },
     shortcut_check : function(view) {
@@ -765,16 +759,21 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner
         var $logs_list = $logs.find('ul').empty();
         $logs.toggleClass('oe-has-more', log_records.length > cutoff);
         _(log_records.reverse()).each(function (record) {
+            var context = {};
+            if (record.context) {
+                try { context = py.eval(record.context).toJSON(); }
+                catch (e) { /* TODO: what do I do now? */ }
+            }
             $(_.str.sprintf('<li><a href="#">%s</a></li>', record.name))
                 .appendTo($logs_list)
-                .delegate('a', 'click', function (e) {
+                .delegate('a', 'click', function () {
                     self.do_action({
                         type: 'ir.actions.act_window',
                         res_model: record.res_model,
                         res_id: record.res_id,
                         // TODO: need to have an evaluated context here somehow
-                        //context: record.context,
-                        views: [[false, 'form']]
+                        context: context,
+                        views: [[context.view_id || false, 'form']]
                     });
                     return false;
                 });
@@ -821,10 +820,6 @@ session.web.Sidebar = session.web.OldWidget.extend({
             }, {
                 label: _t("Export"),
                 callback: view.on_sidebar_export
-            }, {
-                label: _t("View Log"),
-                callback: view.on_sidebar_view_log,
-                classname: 'oe_hide oe_sidebar_view_log'
             }
         ]);
     },
@@ -863,18 +858,32 @@ session.web.Sidebar = session.web.OldWidget.extend({
         }
         return $section;
     },
-
+    /**
+     * For each item added to the section:
+     *
+     * ``label``
+     *     will be used as the item's name in the sidebar
+     *
+     * ``action``
+     *     descriptor for the action which will be executed, ``action`` and
+     *     ``callback`` should be exclusive
+     *
+     * ``callback``
+     *     function to call when the item is clicked in the sidebar, called
+     *     with the item descriptor as its first argument (so information
+     *     can be stored as additional keys on the object passed to
+     *     ``add_items``)
+     *
+     * ``classname`` (optional)
+     *     ``@class`` set on the sidebar serialization of the item
+     *
+     * ``title`` (optional)
+     *     will be set as the item's ``@title`` (tooltip)
+     *
+     * @param {String} section_code
+     * @param {Array<{label, action | callback[, classname][, title]}>} items
+     */
     add_items: function(section_code, items) {
-        // An item is a dictonary : {
-        //    label: label to be displayed for the link,
-        //    action: action to be launch when the link is clicked,
-        //    callback: a function to be executed when the link is clicked,
-        //    classname: optional dom class name for the line,
-        //    title: optional title for the link
-        // }
-        // Note: The item should have one action or/and a callback
-        //
-
         var self = this,
             $section = this.add_section(_.str.titleize(section_code.replace('_', ' ')), section_code),
             section_id = $section.attr('id');
@@ -954,8 +963,8 @@ session.web.TranslateDialog = session.web.Dialog.extend({
         // TODO fme: should add the language to fields_view_get because between the fields view get
         // and the moment the user opens the translation dialog, the user language could have been changed
         this.view_language = view.session.user_context.lang;
-        this['on_button' + _t("Save")] = this.on_button_Save;
-        this['on_button' + _t("Close")] = this.on_button_Close;
+        this['on_button_' + _t("Save")] = this.on_btn_save;
+        this['on_button_' + _t("Close")] = this.on_btn_close;
         this._super(view, {
             width: '80%',
             height: '80%'
@@ -1036,9 +1045,10 @@ session.web.TranslateDialog = session.web.Dialog.extend({
             }
         });
     },
-    on_button_Save: function() {
+    on_btn_save: function() {
         var trads = {},
-            self = this;
+            self = this,
+            trads_mutex = new $.Mutex();
         self.$fields_form.find('.oe_trad_field.touched').each(function() {
             var field = $(this).attr('name').split('-');
             if (!trads[field[0]]) {
@@ -1051,13 +1061,14 @@ session.web.TranslateDialog = session.web.Dialog.extend({
                 _.each(data, function(value, field) {
                     self.view.fields[field].set_value(value);
                 });
-            } else {
-                self.view.dataset.write(self.view.datarecord.id, data, { 'lang': code });
             }
+            trads_mutex.exec(function() {
+                return self.view.dataset.write(self.view.datarecord.id, data, { context : { 'lang': code } });
+            });
         });
         this.close();
     },
-    on_button_Close: function() {
+    on_btn_close: function() {
         this.close();
     }
 });
@@ -1181,7 +1192,7 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{
             this.widget_parent.do_push_state(state);
         }
     },
-    do_load_state: function(state) {
+    do_load_state: function(state, warm) {
     },
     /**
      * Switches to a specific view type
@@ -1222,8 +1233,6 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{
             view_mode : "list"
         });
     },
-    on_sidebar_view_log: function() {
-    },
     sidebar_context: function () {
         return $.when();
     },