diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 5d2102630cb..c19a6c8f5b5 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -1,4 +1,4 @@ -@charset "UTF-8"; +@charset "utf-8"; @font-face { font-family: "mnmliconsRegular"; src: url("/web/static/src/font/mnmliconsv21-webfont.eot") format("eot"); @@ -117,6 +117,9 @@ float: right; margin-left: 8px; } +.openerp .oe_text_right { + text-align: right; +} .openerp .oe_clear { clear: both; } @@ -1415,7 +1418,7 @@ } .openerp .oe_form_topbar button { font-size: 12px; - height: 24px; + height: 24px !important; line-height: 24px; vertical-align: top; padding: 0 10px; @@ -1508,44 +1511,30 @@ -webkit-box-shadow: 0 0 10px rgba(0, 0, 0, 0.3); -box-shadow: 0 0 10px rgba(0, 0, 0, 0.3); } -.openerp .oe_form_autolayout .oe_button { - height: 20px; -} -.openerp .oe_form_autolayout .oe_form_group_cell { +.openerp .oe_form .oe_form_group_cell { line-height: 18px; padding: 2px; height: 20px; } -.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_many2one, -.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_many2one input, -.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_char input, -.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_text textarea, -.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_email, -.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_email input, -.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_url, -.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_url input, -.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_float input, -.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_selection select, -.openerp .oe_form_autolayout .oe_form_group_cell > div > .oe_datepicker_root, -.openerp .oe_form_autolayout .oe_form_group_cell > div > .oe_datepicker_root > input.oe_datepicker_master { +.openerp .oe_form .oe_form_group_cell > .oe_form_field_many2one, +.openerp .oe_form .oe_form_group_cell > .oe_form_field_many2one input, +.openerp .oe_form .oe_form_group_cell > .oe_form_field_char input, +.openerp .oe_form .oe_form_group_cell > .oe_form_field_text textarea, +.openerp .oe_form .oe_form_group_cell > .oe_form_field_email, +.openerp .oe_form .oe_form_group_cell > .oe_form_field_email input, +.openerp .oe_form .oe_form_group_cell > .oe_form_field_url, +.openerp .oe_form .oe_form_group_cell > .oe_form_field_url input, +.openerp .oe_form .oe_form_group_cell > .oe_form_field_float input, +.openerp .oe_form .oe_form_group_cell > .oe_form_field_selection select, +.openerp .oe_form .oe_form_group_cell > div > .oe_datepicker_root, +.openerp .oe_form .oe_form_group_cell > div > .oe_datepicker_root > input.oe_datepicker_master { width: 100%; } -.openerp .oe_form_autolayout .oe_form_button.oe_button { - color: #4c4c4c; -} -.openerp .oe_form_autolayout .oe_form_button.oe_button span { - position: relative; - vertical-align: top; -} -.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_button.oe_button { - white-space: nowrap; - min-width: 100%; - width: 100%; -} -.openerp .oe_form_autolayout .oe_form_group_cell.oe_form_group_nested { +.openerp .oe_form .oe_form_group_cell.oe_form_group_nested { padding: 0; } .openerp .oe_form .oe_form_label_help[for], .openerp .oe_form .oe_form_label[for] { + font-weight: bold; white-space: nowrap; padding-right: 8px; } @@ -1673,6 +1662,7 @@ border: 1px solid #dd0000 !important; } .openerp .oe_form .oe_button.oe_field_button { + display: block; -webkit-border-top-left-radius: 0px; -webkit-border-bottom-left-radius: 0px; -moz-border-radius-topleft: 0px; @@ -1695,10 +1685,24 @@ right: 5px; top: 3px; } +.openerp .oe_form .oe_form_button.oe_button { + height: 22px; + color: #4c4c4c; +} +.openerp .oe_form .oe_form_button.oe_button span { + position: relative; + vertical-align: top; +} .openerp .oe_form .oe_form_button > img { vertical-align: -3px; padding: 0 2px; } +.openerp .oe_form .oe_form_group_cell > .oe_form_button.oe_button { + display: block; + white-space: nowrap; + min-width: 100%; + width: 100%; +} .openerp .oe_form .oe-binary-file-set { overflow: hidden; position: relative; @@ -1718,6 +1722,9 @@ margin: 0; padding: 0; } +.openerp .oe_horizontal_border { + border-bottom: 1px solid black; +} .openerp .oe_horizontal_separator { font-weight: bold; font-size: 16px; @@ -1842,7 +1849,30 @@ } .openerp .oe_form .oe_form_group_odd_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell, .openerp .oe_form .oe_form_group_label_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell { - padding: 2px 2px 2px 8px !important; + padding-left: 8px; +} +.openerp .oe_form .oe_form_subtotal_footer { + float: right; +} +.openerp .oe_form .oe_form_subtotal_footer > div { + text-align: right; + padding: 3px; +} +.openerp .oe_form .oe_form_subtotal_footer label { + font-weight: normal !important; +} +.openerp .oe_form .oe_form_subtotal_footer span { + display: inline-block; + min-width: 80px; + text-align: right; +} +.openerp .oe_form .oe_form_subtotal_footer .oe_form_subtotal_footer_separator { + border-top: 1px solid #cacaca; + font-size: 120%; + font-weight: bold; +} +.openerp .oe_form .oe_form_subtotal_footer .oe_form_subtotal_footer_separator label { + font-weight: bold !important; } .openerp .oe-listview-content { width: 100%; diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index 567732ed080..d7e42639254 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -143,6 +143,8 @@ $colour4: #8a89ba .oe_right float: right margin-left: 8px + .oe_text_right + text-align: right .oe_clear clear: both .oe_wait @@ -1152,7 +1154,7 @@ $colour4: #8a89ba line-height: 30px button font-size: 12px - height: 24px + height: 24px !important line-height: 24px vertical-align: top padding: 0 10px @@ -1229,10 +1231,8 @@ $colour4: #8a89ba border: 1px solid #afafb6 @include box-shadow(0 0 10px rgba(0,0,0,0.3)) // }}} - // FormView.autolayout {{{ - .oe_form_autolayout - .oe_button - height: 20px + // FormView.layout {{{ + .oe_form .oe_form_group_cell line-height: 18px padding: 2px @@ -1250,21 +1250,13 @@ $colour4: #8a89ba .oe_form_group_cell > div > .oe_datepicker_root, .oe_form_group_cell > div > .oe_datepicker_root > input.oe_datepicker_master width: 100% - .oe_form_button.oe_button - color: #4c4c4c - span - position: relative - vertical-align: top - .oe_form_group_cell > .oe_form_button.oe_button - white-space: nowrap - min-width: 100% - width: 100% .oe_form_group_cell.oe_form_group_nested padding: 0 // }}} // FormView.label {{{ .oe_form .oe_form_label_help[for], .oe_form_label[for] + font-weight: bold white-space: nowrap padding-right: 8px span @@ -1373,10 +1365,8 @@ $colour4: #8a89ba input, select, textarea background-color: #F66 !important border: 1px solid #D00 !important - // }}} - // FormView.buttons {{{ - .oe_form .oe_button.oe_field_button + display: block -webkit-border-top-left-radius: 0px -webkit-border-bottom-left-radius: 0px -moz-border-radius-topleft: 0px @@ -1396,9 +1386,23 @@ $colour4: #8a89ba filter: alpha(opacity=50) right: 5px top: 3px + // }}} + // FormView.buttons {{{ + .oe_form + .oe_form_button.oe_button + height: 22px + color: #4c4c4c + span + position: relative + vertical-align: top .oe_form_button > img vertical-align: -3px padding: 0 2px + .oe_form_group_cell > .oe_form_button.oe_button + display: block + white-space: nowrap + min-width: 100% + width: 100% // }}} // FormView.binaryfile {{{ /* http://www.quirksmode.org/dom/inputfile.html @@ -1425,6 +1429,8 @@ $colour4: #8a89ba padding: 0 // }}} // FormView.separator {{{ + .oe_horizontal_border + border-bottom: 1px solid black .oe_horizontal_separator font-weight: bold font-size: 16px @@ -1536,7 +1542,24 @@ $colour4: #8a89ba min-width: 120px .oe_form_group_odd_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell, .oe_form_group_label_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell - padding: 2px 2px 2px 8px !important + padding-left: 8px + .oe_form_subtotal_footer + float: right + > div + text-align: right + padding: 3px + label + font-weight: normal !important + span + display: inline-block + min-width: 80px + text-align: right + .oe_form_subtotal_footer_separator + border-top: 1px solid #cacaca + font-size: 120% + font-weight: bold + label + font-weight: bold !important // }}} // ListView {{{ .oe-listview-content diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index b71a504b52f..47983ed322d 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -43,6 +43,10 @@ instance.web.Notification = instance.web.Widget.extend({ } }); +/** + * The very minimal function everything should call to create a dialog + * in OpenERP Web Client. + */ instance.web.dialog = function(element) { var result = element.dialog.apply(element, _.rest(_.toArray(arguments))); result.dialog("widget").addClass("openerp"); diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 2dc66aaa135..fdb15d598af 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -1079,44 +1079,44 @@ instance.web.ProxyDataSet = instance.web.DataSetSearch.extend({ this.create_function = null; this.write_function = null; this.read_function = null; + this.default_get_function = null; + this.unlink_function = null; }, - read_ids: function () { + read_ids: function (ids, fields, options) { if (this.read_function) { - return this.read_function.apply(null, arguments); + return this.read_function(ids, fields, options, this._super); } else { return this._super.apply(this, arguments); } }, default_get: function(fields, options) { - return this._super(fields, options).then(this.on_default_get); + if (this.default_get_function) { + return this.default_get_function(fields, options, this._super); + } else { + return this._super.apply(this, arguments); + } }, - on_default_get: function(result) {}, create: function(data, callback, error_callback) { - this.on_create(data); if (this.create_function) { - return this.create_function(data, callback, error_callback); + return this.create_function(data, this._super).then(callback, error_callback); } else { - console.warn("trying to create a record using default proxy dataset behavior"); - return $.async_when({"result": undefined}).then(callback); + return this._super.apply(this, arguments); } }, - on_create: function(data) {}, - write: function (id, data, options, callback) { - this.on_write(id, data); + write: function (id, data, options, callback, error_callback) { if (this.write_function) { - return this.write_function(id, data, options, callback); + return this.write_function(id, data, options, this._super).then(callback, error_callback); } else { - console.warn("trying to write a record using default proxy dataset behavior"); - return $.async_when({"result": true}).then(callback); + return this._super.apply(this, arguments); } }, - on_write: function(id, data) {}, unlink: function(ids, callback, error_callback) { - this.on_unlink(ids); - console.warn("trying to unlink a record using default proxy dataset behavior"); - return $.async_when({"result": true}).then(callback); + if (this.unlink_function) { + return this.unlink_function(ids, this._super).then(callback, error_callback); + } else { + return this._super.apply(this, arguments); + } }, - on_unlink: function(ids) {} }); instance.web.CompoundContext = instance.web.Class.extend({ diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 2bbdf4a3b22..99344e11217 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -984,9 +984,6 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt }, process: function($tag, layout) { var self = this; - if ($tag.attr('layout') === 'auto') { - $tag.addClass('oe_form_autolayout'); - } layout = $tag.attr('layout') || layout || 'auto'; $tag.removeAttr('layout'); var tagname = $tag[0].nodeName.toLowerCase(); @@ -2310,16 +2307,6 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(_.exte }); })(); -instance.web.form.dialog = function(content, options) { - options = _.extend({ - width: '90%', - height: 'auto', - min_width: '800px' - }, options || {}); - var dialog = new instance.web.Dialog(null, options, content).open(); - return dialog.$element; -}; - /** * A mixin containing some useful methods to handle completion inputs. */ @@ -2756,20 +2743,18 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ view.view_type = 'form'; } view.options.not_interactible_on_create = true; + } else if (view.view_type === "kanban") { + if (self.get("effective_readonly")) { + view.options.action_buttons = false; + view.options.quick_creatable = false; + } } views.push(view); }); this.views = views; - this.viewmanager = new instance.web.ViewManager(this, this.dataset, views, { - $sidebar: false, - }); - this.viewmanager.template = 'One2Many.viewmanager'; - this.viewmanager.registry = instance.web.views.extend({ - list: 'instance.web.form.One2ManyListView', - form: 'instance.web.form.One2ManyFormView', - kanban: 'instance.web.form.One2ManyKanbanView', - }); + this.viewmanager = new instance.web.form.One2ManyViewManager(this, this.dataset, views, {}); + this.viewmanager.o2m = self; var once = $.Deferred().then(function() { self.init_form_last_update.resolve(); }); @@ -2953,6 +2938,42 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ }, }); +instance.web.form.One2ManyViewManager = instance.web.ViewManager.extend({ + template: 'One2Many.viewmanager', + init: function(parent, dataset, views, flags) { + this._super(parent, dataset, views, _.extend({}, flags, {$sidebar: false})); + this.registry = this.registry.extend({ + list: 'instance.web.form.One2ManyListView', + form: 'instance.web.form.One2ManyFormView', + kanban: 'instance.web.form.One2ManyKanbanView', + }); + }, + switch_view: function(mode, unused) { + if (mode !== 'form') { + return this._super(mode, unused); + } + var self = this; + var id = self.o2m.dataset.index !== null ? self.o2m.dataset.ids[self.o2m.dataset.index] : null; + var pop = new instance.web.form.FormOpenPopup(self.o2m.view); + pop.show_element(self.o2m.field.relation, id, self.o2m.build_context(), { + title: _t("Open: ") + self.name, + write_function: function(id, data, options) { + return self.o2m.dataset.write(id, data, {}).then(function() { + self.o2m.reload_current_view(); + }); + }, + alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined, + parent_view: self.o2m.view, + child_name: self.o2m.name, + read_function: function() { + return self.o2m.dataset.read_ids.apply(self.o2m.dataset, arguments); + }, + form_view_options: {'not_interactible_on_create':true}, + readonly: self.o2m.get("effective_readonly") + }); + }, +}); + instance.web.form.One2ManyDataSet = instance.web.BufferedDataSet.extend({ get_context: function() { this.context = this.o2m.build_context([this.o2m.name]); @@ -2968,7 +2989,6 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ } else { var self = this; var pop = new instance.web.form.SelectCreatePopup(this); - pop.on_default_get.add(self.dataset.on_default_get); pop.select_element( self.o2m.field.relation, { @@ -3001,7 +3021,11 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ var pop = new instance.web.form.FormOpenPopup(self.o2m.view); pop.show_element(self.o2m.field.relation, id, self.o2m.build_context(), { title: _t("Open: ") + self.name, - auto_write: false, + write_function: function(id, data) { + return self.o2m.dataset.write(id, data, {}, function(r) { + self.o2m.reload_current_view(); + }); + }, alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined, parent_view: self.o2m.view, child_name: self.o2m.name, @@ -3011,11 +3035,6 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ form_view_options: {'not_interactible_on_create':true}, readonly: self.o2m.get("effective_readonly") }); - pop.on_write.add(function(id, data) { - self.o2m.dataset.write(id, data, {}, function(r) { - self.o2m.reload_current_view(); - }); - }); }, do_button_action: function (name, id, callback) { var self = this; @@ -3046,28 +3065,6 @@ var lazy_build_o2m_kanban_view = function() { if (! instance.web_kanban || instance.web.form.One2ManyKanbanView) return; instance.web.form.One2ManyKanbanView = instance.web_kanban.KanbanView.extend({ - open_record: function(id) { - var self = this; - var pop = new instance.web.form.FormOpenPopup(self.o2m.view); - pop.show_element(self.o2m.field.relation, id, self.o2m.build_context(), { - title: _t("Open: ") + self.name, - auto_write: false, - alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined, - parent_view: self.o2m.view, - child_name: self.o2m.name, - read_function: function() { - return self.o2m.dataset.read_ids.apply(self.o2m.dataset, arguments); - }, - form_view_options: {'not_interactible_on_create':true}, - readonly: self.o2m.get("effective_readonly"), - }); - pop.on_write.add(function(id, data) { - self.o2m.dataset.write(id, data, {}, function(r) { - self.o2m.reload_current_view(); - }); - }); - - }, }); } @@ -3223,7 +3220,6 @@ instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend(_. * TODO niv: clean those deferred stuff, it could be better */ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ - template: "FieldMany2Many.render", multi_selection: false, disable_utility_classes: true, init: function(field_manager, node) { @@ -3274,7 +3270,6 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ 'addable': self.get("effective_readonly") ? null : _t("Add"), 'deletable': self.get("effective_readonly") ? false : true, 'selectable': self.multi_selection, - '$buttons': $(".oe_form_view_m2m_buttons", self.$element), }); var embedded = (this.field.views || {}).tree; if (embedded) { @@ -3287,7 +3282,7 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ loaded.resolve(); }); $.async_when().then(function () { - self.list_view.appendTo($(".oe_form_view_m2m_view", self.$element)); + self.list_view.appendTo(self.$element); }); return loaded; }, @@ -3349,60 +3344,166 @@ instance.web.form.Many2ManyListView = instance.web.ListView.extend(/** @lends in }); /** - * @class - * @extends instance.web.OldWidget + * Class with everything which is common between FormOpenPopup and SelectCreatePopup. */ -instance.web.form.SelectCreatePopup = instance.web.OldWidget.extend(/** @lends instance.web.form.SelectCreatePopup# */{ - template: "SelectCreatePopup", +instance.web.form.AbstractFormPopup = instance.web.OldWidget.extend({ + template: "AbstractFormPopup.render", + /** + * options: + * -readonly: only applicable when not in creation mode, default to false + * - alternative_form_view + * - write_function + * - read_function + * - create_function + * - parent_view + * - child_name + * - form_view_options + */ + init_popup: function(model, row_id, domain, context, options) { + this.row_id = row_id; + this.model = model; + this.domain = domain || []; + this.context = context || {}; + this.options = options; + _.defaults(this.options, { + }); + }, + init_dataset: function() { + var self = this; + this.created_elements = []; + this.dataset = new instance.web.ProxyDataSet(this, this.model, this.context); + this.dataset.read_function = this.options.read_function; + this.dataset.create_function = function(data, sup) { + var fct = self.options.create_function || sup; + return fct.call(this, data).then(function(r) { + self.created_elements.push(r.result); + }); + }; + this.dataset.write_function = function(id, data, options, sup) { + var fct = self.options.write_function || sup; + return fct.call(this, id, data, options).then(self.on_write_completed); + }; + this.dataset.parent_view = this.options.parent_view; + this.dataset.child_name = this.options.child_name; + }, + display_popup: function() { + var self = this; + this.renderElement(); + new instance.web.Dialog(this, { + width: '90%', + min_width: '800px', + close: function() { + self.check_exit(); + }, + title: this.options.title || "", + }, this.$element).open(); + this.start(); + }, + on_write_completed: function() {}, + setup_form_view: function() { + var self = this; + if (this.row_id) { + this.dataset.ids = [this.row_id]; + this.dataset.index = 0; + } else { + this.dataset.index = null; + } + var options = _.clone(self.options.form_view_options) || {}; + if (this.row_id !== null) { + options.initial_mode = this.options.readonly ? "view" : "edit"; + } + this.view_form = new instance.web.FormView(this, this.dataset, false, options); + if (this.options.alternative_form_view) { + this.view_form.set_embedded_view(this.options.alternative_form_view); + } + this.view_form.appendTo(this.$element.find(".oe-form-view-popup-form-placeholder")); + this.view_form.on_loaded.add_last(function() { + var $buttons = self.view_form.$element.find(".oe_form_buttons"); + var multi_select = self.row_id === null && ! self.options.disable_multiple_selection; + $buttons.html(QWeb.render("AbstractFormPopup.buttons", {multi_select: multi_select})); + var $snbutton = $buttons.find(".oe_abstractformpopup-form-save-new"); + $snbutton.click(function() { + $.when(self.view_form.do_save()).then(function() { + self.view_form.reload_mutex.exec(function() { + self.view_form.on_button_new(); + }); + }); + }); + var $sbutton = $buttons.find(".oe_abstractformpopup-form-save"); + $sbutton.click(function() { + $.when(self.view_form.do_save()).then(function() { + self.view_form.reload_mutex.exec(function() { + self.check_exit(); + }); + }); + }); + var $cbutton = $buttons.find(".oe_abstractformpopup-form-close"); + $cbutton.click(function() { + self.check_exit(); + }); + if (self.row_id !== null && self.options.readonly) { + $snbutton.hide(); + $sbutton.hide(); + $cbutton.text(_t("Close")); + } + self.view_form.do_show(); + }); + }, + on_select_elements: function(element_ids) { + }, + check_exit: function() { + if (this.created_elements.length > 0) { + this.on_select_elements(this.created_elements); + } + this.destroy(); + }, + destroy: function () { + this.$element.dialog('close'); + this._super(); + }, +}); + +/** + * Class to display a popup containing a form view. + */ +instance.web.form.FormOpenPopup = instance.web.form.AbstractFormPopup.extend({ + show_element: function(model, row_id, context, options) { + this.init_popup(model, row_id, [], context, options); + _.defaults(this.options, { + }); + this.display_popup(); + }, + start: function() { + this._super(); + this.init_dataset(); + this.setup_form_view(); + }, +}); + +/** + * Class to display a popup to display a list to search a row. It also allows + * to switch to a form view to create a new row. + */ +instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend({ /** * options: * - initial_ids * - initial_view: form or search (default search) * - disable_multiple_selection - * - alternative_form_view - * - create_function (defaults to a naive saving behavior) - * - parent_view - * - child_name - * - form_view_options * - list_view_options - * - read_function */ select_element: function(model, options, domain, context) { + this.init_popup(model, null, domain, context, options); var self = this; - this.model = model; - this.domain = domain || []; - this.context = context || {}; - this.options = _.defaults(options || {}, {"initial_view": "search", "create_function": function() { - return self.create_row.apply(self, arguments); - }, read_function: null}); - this.initial_ids = this.options.initial_ids; - this.created_elements = []; - this.renderElement(); - instance.web.form.dialog(this.$element, { - close: function() { - self.check_exit(); - }, - title: options.title || "" + _.defaults(this.options, { + initial_view: "search", }); - this.start(); + this.initial_ids = this.options.initial_ids; + this.display_popup(); }, start: function() { - this._super(); var self = this; - this.dataset = new instance.web.ProxyDataSet(this, this.model, - this.context); - this.dataset.create_function = function() { - return self.options.create_function.apply(null, arguments).then(function(r) { - self.created_elements.push(r.result); - }); - }; - this.dataset.write_function = function() { - return self.write_row.apply(self, arguments); - }; - this.dataset.read_function = this.options.read_function; - this.dataset.parent_view = this.options.parent_view; - this.dataset.child_name = this.options.child_name; - this.dataset.on_default_get.add(this.on_default_get); + this.init_dataset(); if (this.options.initial_view == "search") { self.rpc('/web/session/eval_domain_and_context', { domains: [], @@ -3421,10 +3522,6 @@ instance.web.form.SelectCreatePopup = instance.web.OldWidget.extend(/** @lends i this.new_object(); } }, - stop: function () { - this.$element.dialog('close'); - this._super(); - }, setup_search_view: function(search_defaults) { var self = this; if (this.searchview) { @@ -3482,22 +3579,6 @@ instance.web.form.SelectCreatePopup = instance.web.OldWidget.extend(/** @lends i self.view_list.do_search(results.domain, results.context, results.group_by); }); }, - create_row: function() { - var self = this; - var wdataset = new instance.web.DataSetSearch(this, this.model, this.context, this.domain); - wdataset.parent_view = this.options.parent_view; - wdataset.child_name = this.options.child_name; - return wdataset.create.apply(wdataset, arguments); - }, - write_row: function() { - var self = this; - var wdataset = new instance.web.DataSetSearch(this, this.model, this.context, this.domain); - wdataset.parent_view = this.options.parent_view; - wdataset.child_name = this.options.child_name; - return wdataset.write.apply(wdataset, arguments); - }, - on_select_elements: function(element_ids) { - }, on_click_element: function(ids) { this.selected_ids = ids || []; if(this.selected_ids.length > 0) { @@ -3507,52 +3588,14 @@ instance.web.form.SelectCreatePopup = instance.web.OldWidget.extend(/** @lends i } }, new_object: function() { - var self = this; if (this.searchview) { this.searchview.hide(); } if (this.view_list) { this.view_list.$element.hide(); } - this.dataset.index = null; - this.view_form = new instance.web.FormView(this, this.dataset, false, self.options.form_view_options); - if (this.options.alternative_form_view) { - this.view_form.set_embedded_view(this.options.alternative_form_view); - } - this.view_form.appendTo(this.$element.find(".oe-select-create-popup-view-form")); - this.view_form.on_loaded.add_last(function() { - var $buttons = self.view_form.$element.find(".oe_form_buttons"); - $buttons.html(QWeb.render("SelectCreatePopup.form.buttons", {widget:self})); - var $nbutton = $buttons.find(".oe_selectcreatepopup-form-save-new"); - $nbutton.click(function() { - $.when(self.view_form.do_save()).then(function() { - self.view_form.reload_mutex.exec(function() { - self.view_form.on_button_new(); - }); - }); - }); - var $nbutton = $buttons.find(".oe_selectcreatepopup-form-save"); - $nbutton.click(function() { - $.when(self.view_form.do_save()).then(function() { - self.view_form.reload_mutex.exec(function() { - self.check_exit(); - }); - }); - }); - var $cbutton = $buttons.find(".oe_selectcreatepopup-form-close"); - $cbutton.click(function() { - self.check_exit(); - }); - }); - this.view_form.do_show(); + this.setup_form_view(); }, - check_exit: function() { - if (this.created_elements.length > 0) { - this.on_select_elements(this.created_elements); - } - this.destroy(); - }, - on_default_get: function(res) {} }); instance.web.form.SelectCreateListView = instance.web.ListView.extend({ @@ -3569,101 +3612,6 @@ instance.web.form.SelectCreateListView = instance.web.ListView.extend({ } }); -/** - * @class - * @extends instance.web.OldWidget - */ -instance.web.form.FormOpenPopup = instance.web.OldWidget.extend(/** @lends instance.web.form.FormOpenPopup# */{ - template: "FormOpenPopup", - /** - * options: - * - alternative_form_view - * - auto_write (default true) - * - read_function - * - parent_view - * - child_name - * - form_view_options - * - readonly - */ - show_element: function(model, row_id, context, options) { - this.model = model; - this.row_id = row_id; - this.context = context || {}; - this.options = _.defaults(options || {}, {"auto_write": true}); - this.renderElement(); - instance.web.dialog(this.$element, { - title: options.title || '', - modal: true, - width: 960, - height: 600 - }); - this.start(); - }, - start: function() { - this._super(); - this.dataset = new instance.web.form.FormOpenDataset(this, this.model, this.context); - this.dataset.fop = this; - this.dataset.ids = [this.row_id]; - this.dataset.index = 0; - this.dataset.parent_view = this.options.parent_view; - this.dataset.child_name = this.options.child_name; - this.setup_form_view(); - }, - on_write: function(id, data) { - if (!this.options.auto_write) - return; - var self = this; - var wdataset = new instance.web.DataSetSearch(this, this.model, this.context, this.domain); - wdataset.parent_view = this.options.parent_view; - wdataset.child_name = this.options.child_name; - wdataset.write(id, data, {}, function(r) { - self.on_write_completed(); - }); - }, - on_write_completed: function() {}, - setup_form_view: function() { - var self = this; - var FormClass = instance.web.views.get_object('form'); - var options = _.clone(self.options.form_view_options) || {}; - options.initial_mode = this.options.readonly ? "view" : "edit"; - this.view_form = new FormClass(this, this.dataset, false, options); - if (this.options.alternative_form_view) { - this.view_form.set_embedded_view(this.options.alternative_form_view); - } - this.view_form.appendTo(this.$element.find(".oe-form-open-popup-form-view")); - this.view_form.on_loaded.add_last(function() { - var $buttons = self.view_form.$element.find(".oe_form_buttons"); - $buttons.html(QWeb.render("FormOpenPopup.form.buttons")); - var $nbutton = $buttons.find(".oe_formopenpopup-form-save"); - $nbutton.click(function() { - self.view_form.do_save().then(function() { - self.destroy(); - }); - }); - var $cbutton = $buttons.find(".oe_formopenpopup-form-close"); - $cbutton.click(function() { - self.destroy(); - }); - if (self.options.readonly) { - $nbutton.hide(); - $cbutton.text(_t("Close")); - } - self.view_form.do_show(); - }); - this.dataset.on_write.add(this.on_write); - } -}); - -instance.web.form.FormOpenDataset = instance.web.ProxyDataSet.extend({ - read_ids: function() { - if (this.fop.options.read_function) { - return this.fop.options.read_function.apply(null, arguments); - } else { - return this._super.apply(this, arguments); - } - } -}); - instance.web.form.FieldReference = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, { template: 'FieldReference', init: function(field_manager, node) { diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 5c9f41806c2..e1d2e4326cc 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -20,6 +20,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi 'sortable': true, // whether the view rows can be reordered (via vertical drag & drop) 'reorderable': true, + 'action_buttons': true, }, /** * Core class for list-type displays. diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index de2ff53a71a..d0af4811142 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -295,7 +295,7 @@ instance.web.ViewManager = instance.web.Widget.extend({ if (view.embedded_view) { controller.set_embedded_view(view.embedded_view); } - controller.do_switch_view.add_last(this.on_mode_switch); + controller.do_switch_view.add_last(_.bind(this.switch_view, this)); controller.do_prev_view.add_last(this.on_prev_view); var container = this.$element.find(".oe_view_manager_view_" + view_type); view_promise = controller.appendTo(container); @@ -342,6 +342,14 @@ instance.web.ViewManager = instance.web.Widget.extend({ }); return view_promise; }, + /** + * Method used internally when a view asks to switch view. This method is meant + * to be extended by child classes to change the default behavior, which simply + * consist to switch to the asked view. + */ + switch_view: function(view_type, no_store) { + return this.on_mode_switch(view_type, no_store); + }, /** * Returns to the view preceding the caller view in this manager's * navigation history (the navigation history is appended to via diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index b2af11b7078..97eeab36657 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1054,12 +1054,6 @@ - -
-
-
-
-
@@ -1525,7 +1519,7 @@ - +
@@ -1539,31 +1533,22 @@
-
+
- - - + + + - - - + + + - - - -
-
-
-
- - - +