diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index de9bc618048..ba1f885d2e6 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -121,6 +121,15 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
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();
},
@@ -631,6 +640,67 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
},
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({
diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js
index 7c1f7385927..34e2b521e24 100644
--- a/addons/web/static/src/js/views.js
+++ b/addons/web/static/src/js/views.js
@@ -821,10 +821,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 +859,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');
@@ -1222,8 +1232,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();
},
diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml
index 6b068679310..fd1fda36753 100644
--- a/addons/web/static/src/xml/base.xml
+++ b/addons/web/static/src/xml/base.xml
@@ -529,11 +529,11 @@