Xavier (Open ERP) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-set-default-xmo into lp:openerp-web.

Requested reviews:
  Olivier Dony (OpenERP) (odo-openerp)
  OpenERP R&D Web Team (openerp-dev-web)

For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-set-default-xmo/+merge/92019

Shitty UI roughly equivalent to right click -> set as default in the GTK client:

* Item in sidebar for all users (section "Customize", item "Set Default")
* Requires selecting a value to set as default, and optionally a single 
condition
* Defaults to setting for current user only, can also set for all users
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-set-default-xmo/+merge/92019
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openerp-web/trunk-set-default-xmo.
=== modified file 'addons/web/static/src/js/view_form.js'
--- addons/web/static/src/js/view_form.js	2012-02-08 11:11:10 +0000
+++ addons/web/static/src/js/view_form.js	2012-02-08 12:27:22 +0000
@@ -117,6 +117,15 @@
             this.sidebar.attachments = new openerp.web.form.SidebarAttachments(this.sidebar, this);
             this.sidebar.add_toolbar(this.fields_view.toolbar);
             this.set_common_sidebar_sections(this.sidebar);
+
+            this.sidebar.add_section(_t('Customize'), 'customize');
+            this.sidebar.add_items('customize', [{
+                label: _t('Set Default'),
+                form: this,
+                callback: function (item) {
+                    item.form.open_defaults_dialog();
+                }
+            }]);
         }
         this.has_been_loaded.resolve();
     },
@@ -627,6 +636,67 @@
     },
     sidebar_context: function () {
         return this.do_save().pipe(_.bind(function() {return this.get_fields_values();}, this));
+    },
+    open_defaults_dialog: function () {
+        var self = this;
+        var fields = _.chain(this.fields)
+            .map(function (field, name) {
+                var value = field.get_value();
+                // ignore fields which are empty, invisible, readonly, o2m
+                // or m2m
+                if (!value
+                        || field.invisible
+                        || field.readonly
+                        || field.field.type === 'one2many'
+                        || field.field.type === 'many2many') {
+                    return false;
+                }
+                return {
+                    name: name,
+                    string: field.string,
+                    value: value,
+                    // convert undefined to false
+                    change_default: !!field.field.change_default
+                }
+            })
+            .compact()
+            .sortBy(function (field) { return field.string; })
+            .value();
+        var conditions = _.chain(fields)
+            .filter(function (field) { return field.change_default; })
+            .value();
+
+        var d = new openerp.web.Dialog(this, {
+            title: _t("Set Default"),
+            args: {
+                fields: fields,
+                conditions: conditions
+            },
+            buttons: [
+                {text: _t("Close"), click: function () { d.close(); }},
+                {text: _t("Save default"), click: function () {
+                    var $defaults = d.$element.find('#formview_default_fields');
+                    var field_to_set = $defaults.val();
+                    if (!field_to_set) {
+                        $defaults.parent().addClass('invalid');
+                        return;
+                    }
+                    var condition = d.$element.find('#formview_default_conditions').val(),
+                        all_users = d.$element.find('#formview_default_all').is(':checked');
+                    new openerp.web.DataSet(self, 'ir.values').call(
+                        'set_default', [
+                            self.dataset.model,
+                            field_to_set,
+                            self.fields[field_to_set].get_value(),
+                            all_users,
+                            false,
+                            condition || false
+                    ]).then(function () { d.close(); });
+                }}
+            ]
+        });
+        d.template = 'FormView.set_default';
+        d.open();
     }
 });
 openerp.web.FormDialog = openerp.web.Dialog.extend({

=== modified file 'addons/web/static/src/js/views.js'
--- addons/web/static/src/js/views.js	2012-02-01 15:44:42 +0000
+++ addons/web/static/src/js/views.js	2012-02-08 12:27:22 +0000
@@ -821,10 +821,6 @@
             }, {
                 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 +859,32 @@
         }
         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');
@@ -1222,8 +1232,6 @@
             view_mode : "list"
         });
     },
-    on_sidebar_view_log: function() {
-    },
     sidebar_context: function () {
         return $.when();
     },

=== modified file 'addons/web/static/src/xml/base.xml'
--- addons/web/static/src/xml/base.xml	2012-02-08 11:11:10 +0000
+++ addons/web/static/src/xml/base.xml	2012-02-08 12:27:22 +0000
@@ -529,11 +529,11 @@
     </div>
 </t>
 <t t-name="Sidebar.section.items">
-            <li t-foreach="items" t-as="item" t-att-class="item.classname">
-                <a class="oe_sidebar_action_a" t-att-id="item.element_id" t-att-title="item.title" href="#">
-                    <t t-esc="item.label"/>
-                </a>
-            </li>
+    <li t-foreach="items" t-as="item" t-att-class="item.classname">
+        <a class="oe_sidebar_action_a" t-att-id="item.element_id" t-att-title="item.title" href="#">
+            <t t-esc="item.label"/>
+        </a>
+    </li>
 </t>
 
 <t t-name="TranslateDialog">
@@ -792,6 +792,62 @@
         </li>
     </ul>
 </t>
+<form t-name="FormView.set_default" class="oe_forms oe_frame">
+    <t t-set="args" t-value="widget.dialog_options.args"/>
+    <table style="width: 100%">
+        <tr>
+            <td>
+                <label for="formview_default_fields"
+                       class="oe_label oe_align_right">
+                    Default:
+                </label>
+            </td>
+            <td class="required">
+                <select id="formview_default_fields">
+                    <option value=""/>
+                    <option t-foreach="args.fields" t-as="field"
+                            t-att-value="field.name">
+                        <t t-esc="field.string"/> = <t t-esc="field.value"/>
+                    </option>
+                </select>
+            </td>
+        </tr>
+        <tr t-if="args.conditions.length">
+            <td>
+                <label for="formview_default_conditions"
+                       class="oe_label oe_align_right">
+                    Condition:
+                </label>
+            </td>
+            <td>
+                <select id="formview_default_conditions">
+                    <option value=""/>
+                    <option t-foreach="args.conditions" t-as="cond"
+                            t-att-value="cond.name + '=' + cond.value">
+                        <t t-esc="cond.string"/>=<t t-esc="cond.value"/>
+                    </option>
+                </select>
+            </td>
+        </tr>
+        <tr>
+            <td colspan="2">
+                <input type="radio" id="formview_default_self"
+                       value="self" name="scope" checked="checked"/>
+                <label for="formview_default_self" class="oe_label"
+                       style="display: inline;">
+                    Only you
+                </label>
+                <br/>
+                <input type="radio" id="formview_default_all"
+                       value="all" name="scope"/>
+                <label for="formview_default_all" class="oe_label"
+                       style="display: inline;">
+                    All users
+                </label>
+            </td>
+        </tr>
+    </table>
+</form>
 <t t-name="Widget">
     Unhandled widget
     <t t-js="dict">console.warn('Unhandled widget', dict.widget);</t>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to