[MERGE] account_followup: small fixes in views
authorThibault Delavallée <tde@openerp.com>
Thu, 12 Jan 2012 10:27:23 +0000 (11:27 +0100)
committerThibault Delavallée <tde@openerp.com>
Thu, 12 Jan 2012 10:27:23 +0000 (11:27 +0100)
bzr revid: tde@openerp.com-20120112102723-13m2kni11irx5e1f

addons/account_followup/account_followup_view.xml
addons/account_followup/wizard/account_followup_print_view.xml
addons/survey/survey.py
addons/survey/survey_view.xml
addons/web/static/src/js/chrome.js
addons/web/static/src/js/core.js
addons/web/static/src/js/data.js
addons/web/static/src/js/view_list.js
addons/web/static/src/js/view_list_editable.js
addons/web/static/src/xml/base.xml
openerp/addons/base/res/res_users.py

index 4d708dd..764ab81 100644 (file)
             <field name="type">form</field>
             <field name="arch" type="xml">
                 <field name="overdue_msg" nolabel="1" colspan="4" position="after">
-                   <separator string="Follow-up Message" colspan="4"/>
+                    <separator string="Follow-up Message" colspan="4"/>
                     <field name="follow_up_msg" nolabel="1" colspan="4"/>
                 </field>
             </field>
index aa06b88..8203a2b 100644 (file)
             <field name="arch" type="xml">
             <form string="Summary">
                 <group col="4" colspan="6">
-                   <separator string="Summary" colspan="4"/>
+                    <separator string="Summary" colspan="4"/>
                     <field name="summary" height="300" width="800" nolabel="1"/>
                 </group>
                 <separator colspan="4"/>
index bf5ec4e..0101cef 100644 (file)
@@ -178,7 +178,6 @@ class survey_page(osv.osv):
         if context is None:
             context = {}
         data = super(survey_page, self).default_get(cr, uid, fields, context)
-        self.pool.get('survey.question').data_get(cr,uid,data,context)
         if context.has_key('survey_id'):
             data['survey_id'] = context.get('survey_id', False)
         return data
@@ -499,21 +498,10 @@ class survey_question(osv.osv):
             'context': context
         }
 
-    def data_get(self, cr, uid, data, context):
-        if data and context:
-            if context.get('line_order', False):
-                lines =  context.get('line_order')
-                seq = data.get('sequence', 0)
-                for line in  lines:
-                    seq = seq + 1
-                data.update({'sequence': seq})
-        return data
-
     def default_get(self, cr, uid, fields, context=None):
         if context is None:
             context = {}
         data = super(survey_question, self).default_get(cr, uid, fields, context)
-        self.data_get(cr,uid,data,context)
         if context.has_key('page_id'):
             data['page_id']= context.get('page_id', False)
         return data
@@ -606,7 +594,6 @@ class survey_answer(osv.osv):
         if context is None:
             context = {}
         data = super(survey_answer, self).default_get(cr, uid, fields, context)
-        self.pool.get('survey.question').data_get(cr,uid,data,context)
         return data
 
 survey_answer()
index 5296970..3dd7ca1 100644 (file)
                     </group>
                     <notebook colspan="4">
                         <page string="Survey">
-                            <field name="page_ids" colspan="4" nolabel="1" mode="form,tree" context="{'line_order': page_ids}">
+                            <field name="page_ids" colspan="4" nolabel="1" mode="form,tree">
                                 <form string="Survey Page">
                                     <field name="title" select="1"/>
                                     <field name="sequence" groups="base.group_extended"/>
                                     <separator string="Description" colspan="4"/>
                                     <field name="note" colspan="4" nolabel="1"/>
-                                    <field name="question_ids" height="200" width="200" colspan="4" nolabel="1" context="{'line_order': question_ids}">
+                                    <field name="question_ids" height="200" width="200" colspan="4">
                                         <form string="Survey Question" >
                                             <group col="6" colspan="6" height="600" width="200">
                                             <field name="question" colspan="4" select="1"/>
@@ -54,7 +54,7 @@
                                                     <group attrs="{'invisible':[('type','!=','multiple_textboxes_diff_type'),('type','!=','multiple_choice_only_one_ans'), ('type','!=','multiple_choice_multiple_ans'),('type','!=','matrix_of_choices_only_one_ans'),('type','!=','matrix_of_choices_only_multi_ans'),('type','!=','matrix_of_drop_down_menus'),('type','!=','rating_scale'),('type','!=','multiple_textboxes'),('type','!=','numerical_textboxes'),('type','!=','date'),('type','!=','date_and_time'),('type','!=','table')]}">
                                                       <separator string="Answer" colspan="4"/>
                                                        <group colspan="4" attrs="{'invisible':[('type','=','table')]}">
-                                                           <field name="answer_choice_ids" nolabel="1" colspan="4" context="{'line_order': answer_choice_ids, 'in_visible_answer_type': in_visible_answer_type}"/>
+                                                           <field name="answer_choice_ids" nolabel="1" colspan="4" context="{'in_visible_answer_type': in_visible_answer_type}"/>
                                                        </group>
                                                        <group colspan="4" attrs="{'invisible':[('type','!=','matrix_of_choices_only_multi_ans'),('type','!=','matrix_of_choices_only_one_ans'),('type','!=','matrix_of_drop_down_menus'),('type','!=','rating_scale'),('type','!=','table')]}">
                                                            <field name="column_heading_ids" colspan="4" nolabel="1" context="{'in_visible_rating_weight':in_visible_rating_weight,'in_visible_menu_choice':in_visible_menu_choice}"/>
                     <field name="sequence"/>
                     <separator string="Description" colspan="4"/>
                     <field name="note" colspan="4" nolabel="1"/>
-                    <field name="question_ids" colspan="4" nolabel="1" context="{'line_order': question_ids}">
+                    <field name="question_ids" colspan="4" nolabel="1">
                     <form string="Survey Question">
                         <field name="question" colspan="4" select="1"/>
                         <field name="sequence"/>
                                 <group attrs="{'invisible':[('type','!=','multiple_textboxes_diff_type'),('type','!=','multiple_choice_only_one_ans'), ('type','!=','multiple_choice_multiple_ans'),('type','!=','matrix_of_choices_only_one_ans'),('type','!=','matrix_of_choices_only_multi_ans'),('type','!=','matrix_of_drop_down_menus'),('type','!=','rating_scale'),('type','!=','multiple_textboxes'),('type','!=','numerical_textboxes'),('type','!=','date'),('type','!=','date_and_time'),('type','!=','table')]}">
                                   <separator string="Answer" colspan="4"/>
                                    <group colspan="4" attrs="{'invisible':[('type','=','table')]}">
-                                       <field name="answer_choice_ids" nolabel="1" colspan="4" context="{'line_order': answer_choice_ids, 'in_visible_answer_type': in_visible_answer_type}"/>
+                                       <field name="answer_choice_ids" nolabel="1" colspan="4" context="{'in_visible_answer_type': in_visible_answer_type}"/>
                                    </group>
                                    <group colspan="4" attrs="{'invisible':[('type','!=','matrix_of_choices_only_multi_ans'),('type','!=','matrix_of_choices_only_one_ans'),('type','!=','matrix_of_drop_down_menus'),('type','!=','rating_scale'),('type','!=','table')]}">
                                        <field name="column_heading_ids" colspan="4" nolabel="1" context="{'in_visible_rating_weight':in_visible_rating_weight,'in_visible_menu_choice':in_visible_menu_choice}"/>
                             <group attrs="{'invisible':[('type','!=','multiple_textboxes_diff_type'),('type','!=','multiple_choice_only_one_ans'), ('type','!=','multiple_choice_multiple_ans'),('type','!=','matrix_of_choices_only_one_ans'),('type','!=','matrix_of_choices_only_multi_ans'),('type','!=','matrix_of_drop_down_menus'),('type','!=','rating_scale'),('type','!=','multiple_textboxes'),('type','!=','numerical_textboxes'),('type','!=','date'),('type','!=','date_and_time'),('type','!=','table')]}">
                               <separator string="Answer" colspan="4"/>
                                <group colspan="4" attrs="{'invisible':[('type','=','table')]}">
-                                   <field name="answer_choice_ids" nolabel="1" colspan="4" context="{'line_order': answer_choice_ids, 'in_visible_answer_type': in_visible_answer_type}"/>
+                                   <field name="answer_choice_ids" nolabel="1" colspan="4" context="{'in_visible_answer_type': in_visible_answer_type}"/>
                                </group>
                                <group colspan="4" attrs="{'invisible':[('type','!=','matrix_of_choices_only_multi_ans'),('type','!=','matrix_of_choices_only_one_ans'),('type','!=','matrix_of_drop_down_menus'),('type','!=','rating_scale'),('type','!=','table')]}">
                                    <field name="column_heading_ids" colspan="4" nolabel="1" context="{'in_visible_rating_weight':in_visible_rating_weight,'in_visible_menu_choice':in_visible_menu_choice}"/>
                             <group attrs="{'invisible':[('type','!=','multiple_textboxes_diff_type'),('type','!=','multiple_choice_only_one_ans'), ('type','!=','multiple_choice_multiple_ans'),('type','!=','matrix_of_choices_only_one_ans'),('type','!=','matrix_of_choices_only_multi_ans'),('type','!=','matrix_of_drop_down_menus'),('type','!=','rating_scale'),('type','!=','multiple_textboxes'),('type','!=','numerical_textboxes'),('type','!=','date'),('type','!=','date_and_time'),('type','!=','table')]}">
                               <separator string="Answer" colspan="4"/>
                                <group colspan="4" attrs="{'invisible':[('type','=','table')]}">
-                                   <field name="answer_choice_ids" nolabel="1" colspan="4" context="{'line_order': answer_choice_ids, 'in_visible_answer_type': in_visible_answer_type}"/>
+                                   <field name="answer_choice_ids" nolabel="1" colspan="4" context="{'in_visible_answer_type': in_visible_answer_type}"/>
                                </group>
                                <group colspan="4" attrs="{'invisible':[('type','!=','matrix_of_choices_only_multi_ans'),('type','!=','matrix_of_choices_only_one_ans'),('type','!=','matrix_of_drop_down_menus'),('type','!=','rating_scale'),('type','!=','table')]}">
                                    <field name="column_heading_ids" colspan="4" nolabel="1" context="{'in_visible_rating_weight':in_visible_rating_weight,'in_visible_menu_choice':in_visible_menu_choice}"/>
index 85a7c9f..39ddd0e 100644 (file)
@@ -1102,11 +1102,11 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie
         self.$table = $(QWeb.render("Interface", {}));
         self.$element.append(self.$table);
         self.header = new openerp.web.Header(self);
-        self.header.on_logout.add(self.on_logout);
-        self.header.on_action.add(self.on_menu_action);
+        self.header.on_logout.add(this.proxy('on_logout'));
+        self.header.on_action.add(this.proxy('on_menu_action'));
         self.header.appendTo($("#oe_header"));
         self.menu = new openerp.web.Menu(self, "oe_menu", "oe_secondary_menu");
-        self.menu.on_action.add(self.on_menu_action);
+        self.menu.on_action.add(this.proxy('on_menu_action'));
         self.menu.start();
     },
     show_common: function() {
index a194c34..d5c096d 100644 (file)
@@ -348,6 +348,31 @@ openerp.web.CallbackEnabled = openerp.web.Class.extend(/** @lends openerp.web.Ca
                 }
             }
         }
+    },
+    /**
+     * Proxies a method of the object, in order to keep the right ``this`` on
+     * method invocations.
+     *
+     * This method is similar to ``Function.prototype.bind`` or ``_.bind``, and
+     * even more so to ``jQuery.proxy`` with a fundamental difference: its
+     * resolution of the method being called is lazy, meaning it will use the
+     * method as it is when the proxy is called, not when the proxy is created.
+     *
+     * Other methods will fix the bound method to what it is when creating the
+     * binding/proxy, which is fine in most javascript code but problematic in
+     * OpenERP Web where developers may want to replace existing callbacks with
+     * theirs.
+     *
+     * The semantics of this precisely replace closing over the method call.
+     *
+     * @param {String} method_name name of the method to invoke
+     * @returns {Function} proxied method
+     */
+    proxy: function (method_name) {
+        var self = this;
+        return function () {
+            return self[method_name].apply(self, arguments);
+        }
     }
 });
 
index 663e596..447b95d 100644 (file)
@@ -422,7 +422,7 @@ openerp.web.DataSet =  openerp.web.Widget.extend( /** @lends openerp.web.DataSet
      * @param {Number} [domain_index] index of a domain to evaluate in the args array
      * @param {Number} [context_index] index of a context to evaluate in the args array
      * @param {Function} callback
-     * @param {Function }error_callback
+     * @param {Function} error_callback
      * @returns {$.Deferred}
      */
     call_and_eval: function (method, args, domain_index, context_index, callback, error_callback) {
index 63f9dfd..e654b77 100644 (file)
@@ -217,11 +217,11 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
         });
 
         this.$element.find('.oe-list-add')
-                .click(this.do_add_record)
+                .click(this.proxy('do_add_record'))
                 .attr('disabled', grouped && this.options.editable);
         this.$element.find('.oe-list-delete')
                 .attr('disabled', true)
-                .click(this.do_delete_selected);
+                .click(this.proxy('do_delete_selected'));
         this.$element.find('thead').delegate('th.oe-sortable[data-id]', 'click', function (e) {
             e.stopPropagation();
 
@@ -512,7 +512,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
         this.no_leaf = !!context['group_by_no_leaf'];
 
         this.reload_view(!!group_by, context).then(
-            $.proxy(this, 'reload_content'));
+            this.proxy('reload_content'));
     },
     /**
      * Handles the signal to delete lines from the records list
@@ -795,7 +795,7 @@ openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.Lis
                 $row.remove();
                 self.refresh_zebra(index);
             },
-            'reset': $.proxy(this, 'on_records_reset'),
+            'reset': function () { return self.on_records_reset(); },
             'change': function (event, record) {
                 var $row = self.$current.find('[data-id=' + record.get('id') + ']');
                 $row.replaceWith(self.render_record(record));
@@ -917,13 +917,15 @@ openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.Lis
         });
     },
     render: function () {
+        var self = this;
         if (this.$current) {
             this.$current.remove();
         }
         this.$current = this.$_element.clone(true);
         this.$current.empty().append(
             QWeb.render('ListView.rows', _.extend({
-                render_cell: $.proxy(this, 'render_cell')}, this)));
+                    render_cell: function () { return self.render_cell(); }
+                }, this)));
         this.pad_table_to(5);
     },
     pad_table_to: function (count) {
@@ -1038,7 +1040,7 @@ openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.Lis
             record: record,
             row_parity: (index % 2 === 0) ? 'even' : 'odd',
             view: this.view,
-            render_cell: $.proxy(this, 'render_cell')
+            render_cell: function () { return this.render_cell(); }
         });
     },
     /**
@@ -1092,7 +1094,9 @@ openerp.web.ListView.Groups = openerp.web.Class.extend( /** @lends openerp.web.L
 
         this.page = 0;
 
-        this.records.bind('reset', $.proxy(this, 'on_records_reset'));
+        var self = this;
+        this.records.bind('reset', function () {
+            return self.on_records_reset(); });
     },
     make_fragment: function () {
         return document.createDocumentFragment();
index daf7081..dcbd22f 100644 (file)
@@ -211,7 +211,7 @@ openerp.web.list_editable = function (openerp) {
                     .delegate('button', 'keyup', function (e) {
                         e.stopImmediatePropagation();
                     })
-                    .keyup($.proxy(self, 'on_row_keyup'));
+                    .keyup(function () { return self.on_row_keyup(); });
                 if (row) {
                     $new_row.replaceAll(row);
                 } else if (self.options.editable) {
@@ -359,7 +359,8 @@ openerp.web.list_editable = function (openerp) {
             this.render_row_as_form();
         },
         render_record: function (record) {
-            var index = this.records.indexOf(record);
+            var index = this.records.indexOf(record),
+                 self = this;
             // FIXME: context dict should probably be extracted cleanly
             return QWeb.render('ListView.row', {
                 columns: this.columns,
@@ -367,7 +368,7 @@ openerp.web.list_editable = function (openerp) {
                 record: record,
                 row_parity: (index % 2 === 0) ? 'even' : 'odd',
                 view: this.view,
-                render_cell: $.proxy(this, 'render_cell'),
+                render_cell: function () { return self.render_cell(); },
                 edited: !!this.edition_form
             });
         }
index 642f1f8..9580b18 100644 (file)
 <t t-name="ImportDataView">
 <form name="import_data" id="import_data" action="" method="post" enctype="multipart/form-data"
         class="oe-import oe-import-no-result">
-    <input type="hidden" name="session_id" t-att-value="session.session_id"/>
+    <input type="hidden" name="session_id" t-att-value="widget.session.session_id"/>
     <h2 class="separator horizontal">1. Import a .CSV file</h2>
     <p>Select a .CSV file to import. If you need a sample of file to import,
        you should use the export tool with the "Import Compatible" option.
index 67b9c01..8962f6d 100644 (file)
@@ -471,12 +471,17 @@ class users(osv.osv):
             return False
         cr = pooler.get_db(db).cursor()
         try:
+            # We autocommit: our single request will be performed atomically.
+            # (In this way, there is no opportunity to have two transactions
+            # interleaving ther cr.execute()..cr.commit() calls and have one
+            # of them rollbacked due to a concurrent access.)
+            # We effectively unconditionally write the res_users line.
+            cr.autocommit(True)
             cr.execute("""UPDATE res_users
                             SET date = now() AT TIME ZONE 'UTC'
                             WHERE login=%s AND password=%s AND active RETURNING id""",
                        (tools.ustr(login), tools.ustr(password)))
             res = cr.fetchone()
-            cr.commit()
             if res:
                 return res[0]
             else: