X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=addons%2Fweb%2Fstatic%2Fsrc%2Fjs%2Fview_form.js;h=d0698cc13b87e62842581ff3700969c35513b7c1;hb=59d0d15b03125bd0d0cff0729326c9e35c6e6212;hp=99344e1121741f5f8d37460ba4539b38b2f69e94;hpb=860a1cbbe2d6aca7b146233bfb4b40c01c0cc62e;p=odoo%2Fodoo.git diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 99344e1..d0698cc 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -208,8 +208,9 @@ instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form. } } }, - do_show: function () { + do_show: function (options) { var self = this; + options = options || {}; if (this.sidebar) { this.sidebar.$element.show(); } @@ -233,6 +234,9 @@ instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form. }).pipe(self.on_record_loaded); } result.pipe(function() { + if (options.editable) { + self.set({mode: "edit"}); + } self.$element.css('visibility', 'visible'); }); return result; @@ -468,7 +472,7 @@ instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form. return self.on_processed_onchange(response, processed); } catch(e) { - console.error(e); + instance.webclient.crashmanager.on_javascript_exception(e); return $.Deferred().reject(); } }); @@ -495,7 +499,8 @@ instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form. this.on_form_changed(); } if (!_.isEmpty(result.warning)) { - instance.web.dialog($(QWeb.render("CrashManagerWarning", result.warning)), { + instance.web.dialog($(QWeb.render("CrashManager.warning", result.warning)), { + title:result.warning.title, modal: true, buttons: [ {text: _t("Ok"), click: function() { $(this).dialog("close"); }} @@ -521,6 +526,7 @@ instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form. switch_mode: function() { var self = this; if(this.get("mode") == "view") { + self.$element.removeClass('oe_form_editable').addClass('oe_form_readonly'); self.$buttons.find('.oe_form_buttons_edit').hide(); self.$buttons.find('.oe_form_buttons_view').show(); self.$sidebar.show(); @@ -528,6 +534,7 @@ instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form. field.set({"force_readonly": true}); }); } else { + self.$element.removeClass('oe_form_readonly').addClass('oe_form_editable'); self.$buttons.find('.oe_form_buttons_edit').show(); self.$buttons.find('.oe_form_buttons_view').hide(); self.$sidebar.hide(); @@ -640,6 +647,9 @@ instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form. } if (form_invalid) { self.set({'display_invalid_fields': true}); + for (var f in self.fields) { + self.fields[f]._check_css_flags(); + } first_invalid_field.focus(); self.on_invalid(); return $.Deferred().reject(); @@ -673,7 +683,7 @@ instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form. var msg = ""; @@ -718,7 +728,6 @@ instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form. if (this.sidebar) { this.sidebar.do_attachement_update(this.dataset, this.datarecord.id); } - //instance.log("The record has been created with id #" + this.datarecord.id); this.reload(); return $.when(_.extend(r, {created: true})).then(success); } @@ -794,41 +803,36 @@ instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form. var self = this; var fields = _.chain(this.fields) .map(function (field, name) { - var value_ = field.get_value(); + var value = field.get_value(); // ignore fields which are empty, invisible, readonly, o2m // or m2m - if (!value_ + if (!value || field.get('invisible') || field.get("readonly") || field.field.type === 'one2many' || field.field.type === 'many2many') { return false; } - var displayed; - switch(field.field.type) { + var displayed = value; + switch (field.field.type) { case 'selection': displayed = _(field.values).find(function (option) { - return option[0] === value_; + return option[0] === value; })[1]; break; - case 'many2one': - displayed = value_; - break; - default: - displayed = value_; } return { name: name, - string: field.node_atts.string, - value: value_, + string: field.node.attrs.string || field.field.string, + value: value, displayed: displayed, // convert undefined to false change_default: !!field.field.change_default } }) .compact() - .sortBy(function (field) { return field.node_atts.string; }) + .sortBy(function (field) { return field.string; }) .value(); var conditions = _.chain(fields) .filter(function (field) { return field.change_default; }) @@ -909,6 +913,10 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt }, set_fields_view: function(fvg) { this.fvg = fvg; + this.version = parseFloat(this.fvg.arch.attrs.version); + if (isNaN(this.version)) { + this.version = 6.1; + } }, set_tags_registry: function(tags_registry) { this.tags_registry = tags_registry; @@ -916,6 +924,18 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt set_fields_registry: function(fields_registry) { this.fields_registry = fields_registry; }, + // Backward compatibility tools, current default version: v6.1 + process_version: function() { + if (this.version < 7.0) { + this.$form.find('form:first').wrapInner(''); + this.$form.find('page').each(function() { + if (!$(this).parents('field').length) { + $(this).wrapInner(''); + } + }); + } + selector = 'form[version!="7.0"] page,form[version!="7.0"]'; + }, render_to: function($target) { var self = this; this.$target = $target; @@ -924,9 +944,8 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt // but one day, we will have to get rid of xml2json var xml = instance.web.json_node_to_xml(this.fvg.arch); this.$form = $('
' + xml + '
'); - if (this.fvg.arch.attrs && this.fvg.arch.attrs['layout'] !== 'manual') { - this.$form.attr('layout', 'auto'); - } + + this.process_version(); this.fields_to_init = []; this.tags_to_init = []; @@ -942,7 +961,7 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt } var obj = self.fields_registry.get_any([$elem.attr('widget'), self.fvg.fields[name].type]); if (!obj) { - throw new Error("Widget type '"+ key + "' is not implemented"); + throw new Error("Widget type '"+ $elem.attr('widget') + "' is not implemented"); } var w = new (obj)(self.view, instance.web.xml_to_json($elem[0])); var $label = self.labels[$elem.attr("name")]; @@ -958,16 +977,13 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt var obj = self.tags_registry.get_object(tag_name); var w = new (obj)(self.view, instance.web.xml_to_json($elem[0])); w.replace($elem); - }) + }); // TODO: return a deferred }, - render_element: function(template, layout/* dictionaries */) { - var dicts = [].slice.call(arguments).slice(2); - dicts.unshift({ 'layout' : layout }); + render_element: function(template /* dictionaries */) { + var dicts = [].slice.call(arguments).slice(1); var dict = _.extend.apply(_, dicts); dict['classnames'] = dict['class'] || ''; // class is a reserved word and might caused problem to Safari when used from QWeb - var alt_template = template + '.' + layout; - template = QWeb.has_template(alt_template) ? alt_template : template; return $(QWeb.render(template, dict)); }, alter_field: function(field) { @@ -982,10 +998,8 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt } this.$target.toggleClass('oe_layout_debugging'); }, - process: function($tag, layout) { + process: function($tag) { var self = this; - layout = $tag.attr('layout') || layout || 'auto'; - $tag.removeAttr('layout'); var tagname = $tag[0].nodeName.toLowerCase(); if (this.tags_registry.contains(tagname)) { this.tags_to_init.push($tag); @@ -995,39 +1009,45 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt if (fn) { var args = [].slice.call(arguments); args[0] = $tag; - args[1] = layout; return fn.apply(self, args); } else { // generic tag handling, just process children $tag.children().each(function() { - self.process($(this), layout); + self.process($(this)); }); self.handle_common_properties($tag, $tag); $tag.removeAttr("modifiers"); return $tag; } }, - process_sheet: function($sheet, layout) { - var $new_sheet = this.render_element('FormRenderingSheet', layout, $sheet.getAttributes()); + process_sheet: function($sheet) { + var $new_sheet = this.render_element('FormRenderingSheet', $sheet.getAttributes()); this.handle_common_properties($new_sheet, $sheet); - var $dst = (layout === 'auto') ? $new_sheet.find('group:first') : $new_sheet.find('.oe_form_sheet'); - $sheet.children().appendTo($dst); + var $dst = $new_sheet.find('.oe_form_sheet'); + $sheet.contents().appendTo($dst); $sheet.before($new_sheet).remove(); - this.process($new_sheet, layout); + this.process($new_sheet); }, - process_form: function($form, layout) { - var $new_form = this.render_element('FormRenderingForm', layout, $form.getAttributes()); + process_form: function($form) { + if ($form.find('> sheet').length === 0) { + $form.addClass('oe_form_nosheet'); + } + var $new_form = this.render_element('FormRenderingForm', $form.getAttributes()); this.handle_common_properties($new_form, $form); - var $dst = (layout === 'auto') ? $new_form.find('group:first') : $new_form; - $form.children().appendTo($dst); + $form.contents().appendTo($new_form); if ($form[0] === this.$form[0]) { // If root element, replace it this.$form = $new_form; } else { $form.before($new_form).remove(); } - this.process($new_form, layout); + this.process($new_form); }, + /* + * Used by direct children of a tag only + * This method will add the implicit for every field + * in the + */ preprocess_field: function($field) { var self = this; var name = $field.attr('name'), @@ -1053,6 +1073,7 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt "modifiers": JSON.stringify({invisible: field_modifiers.invisible}), "string": $field.attr('string'), "help": $field.attr('help'), + "class": $field.attr('class'), }); $label.insertBefore($field); if (field_colspan > 1) { @@ -1060,31 +1081,34 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt } return $label; }, - process_field: function($field, layout) { - var $label = this.preprocess_field($field); - if ($label) - this.process($label, layout); + process_field: function($field) { + if ($field.parent().is('group')) { + // No implicit labels for normal fields, only for direct children + var $label = this.preprocess_field($field); + if ($label) { + this.process($label); + } + } this.fields_to_init.push($field); return $field; }, - process_group: function($group, layout) { + process_group: function($group) { var self = this; - if ($group.parent().is('.oe_form_group_cell')) { - $group.parent().addClass('oe_form_group_nested'); - } $group.children('field').each(function() { self.preprocess_field($(this)); }); - var $new_group = this.render_element('FormRenderingGroup', layout, $group.getAttributes()), - $table; - if ($new_group.is('table')) { + var $new_group = this.render_element('FormRenderingGroup', $group.getAttributes()); + var $table; + if ($new_group.first().is('table.oe_form_group')) { $table = $new_group; + } else if ($new_group.filter('table.oe_form_group').length) { + $table = $new_group.filter('table.oe_form_group').first(); } else { - $table = $new_group.find('table:first'); + $table = $new_group.find('table.oe_form_group').first(); } - $table.addClass('oe_form_group'); + var $tr, $td, - cols = parseInt($group.attr('col') || 4, 10), + cols = parseInt($group.attr('col') || 2, 10), row_cols = cols; var children = []; @@ -1094,6 +1118,8 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt var tagName = $child[0].tagName.toLowerCase(); var $td = $('').addClass('oe_form_group_cell').attr('colspan', colspan); var newline = tagName === 'newline'; + + // Note FME: those classes are used in layout debug mode if ($tr && row_cols > 0 && (newline || row_cols < colspan)) { $tr.addClass('oe_form_group_row_incomplete'); if (newline) { @@ -1123,7 +1149,6 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt } $group.before($new_group).remove(); - // Now compute width of cells $table.find('> tbody > tr').each(function() { var to_compute = [], row_cols = cols, @@ -1136,13 +1161,14 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt if ($child.attr('orientation') === 'vertical') { $td.addClass('oe_vertical_separator').attr('width', '1'); $td.empty(); - row_cols--; + row_cols-= $td.attr('colspan') || 1; + total--; } break; case 'label': if ($child.attr('for')) { $td.attr('width', '1%').addClass('oe_form_group_cell_label'); - row_cols--; + row_cols-= $td.attr('colspan') || 1; total--; } break; @@ -1159,20 +1185,22 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt } $td.attr('width', width); $child.removeAttr('width'); - row_cols--; + row_cols-= $td.attr('colspan') || 1; } else { to_compute.push($td); } } }); - var unit = Math.floor(total / row_cols); - if (!$(this).is('.oe_form_group_row_incomplete')) { - _.each(to_compute, function($td, i) { - var width = parseInt($td.attr('colspan'), 10) * unit; - $td.attr('width', ((i == to_compute.length - 1) ? total : width) + '%'); - total -= width; - }); + if (row_cols) { + var unit = Math.floor(total / row_cols); + if (!$(this).is('.oe_form_group_row_incomplete')) { + _.each(to_compute, function($td, i) { + var width = parseInt($td.attr('colspan'), 10) * unit; + $td.attr('width', width + '%'); + total -= width; + }); + } } }); _.each(children, function(el) { @@ -1181,37 +1209,57 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt this.handle_common_properties($new_group, $group); return $new_group; }, - process_notebook: function($notebook, layout) { + process_notebook: function($notebook) { var self = this; var pages = []; $notebook.find('> page').each(function() { var $page = $(this); var page_attrs = $page.getAttributes(); page_attrs.id = _.uniqueId('notebook_page_'); - pages.push(page_attrs); - var $new_page = self.render_element('FormRenderingNotebookPage', layout, page_attrs); - var $dst = (layout === 'auto') ? $new_page.find('group:first') : $new_page; - $page.children().appendTo($dst); + var $new_page = self.render_element('FormRenderingNotebookPage', page_attrs); + $page.contents().appendTo($new_page); $page.before($new_page).remove(); - self.handle_common_properties($new_page, $page); + var ic = self.handle_common_properties($new_page, $page).invisibility_changer; + page_attrs.__page = $new_page; + page_attrs.__ic = ic; + pages.push(page_attrs); + + $new_page.children().each(function() { + self.process($(this)); + }); }); - var $new_notebook = this.render_element('FormRenderingNotebook', layout, { pages : pages }); - $notebook.children().appendTo($new_notebook); + var $new_notebook = this.render_element('FormRenderingNotebook', { pages : pages }); + $notebook.contents().appendTo($new_notebook); $notebook.before($new_notebook).remove(); - $new_notebook.children().each(function() { - self.process($(this)); - }); + self.process($($new_notebook.children()[0])); + //tabs and invisibility handling $new_notebook.tabs(); + _.each(pages, function(page, i) { + if (! page.__ic) + return; + page.__ic.on("change:effective_invisible", null, function() { + var current = $new_notebook.tabs("option", "selected"); + if (! pages[current].__ic || ! pages[current].__ic.get("effective_invisible")) + return; + var first_visible = _.find(_.range(pages.length), function(i2) { + return (! pages[i2].__ic) || (! pages[i2].__ic.get("effective_invisible")); + }); + if (first_visible !== undefined) { + $new_notebook.tabs('select', first_visible); + } + }); + }); + this.handle_common_properties($new_notebook, $notebook); return $new_notebook; }, - process_separator: function($separator, layout) { - var $new_separator = this.render_element('FormRenderingSeparator', layout, $separator.getAttributes()); + process_separator: function($separator) { + var $new_separator = this.render_element('FormRenderingSeparator', $separator.getAttributes()); $separator.before($new_separator).remove(); this.handle_common_properties($new_separator, $separator); return $new_separator; }, - process_label: function($label, layout) { + process_label: function($label) { var name = $label.attr("for"), field_orm = this.fvg.fields[name]; var dict = { @@ -1228,7 +1276,7 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt align = 'center'; } dict.align = align; - var $new_label = this.render_element('FormRenderingLabel', layout, dict); + var $new_label = this.render_element('FormRenderingLabel', dict); $label.before($new_label).remove(); this.handle_common_properties($new_label, $label); if (name) { @@ -1239,10 +1287,12 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt handle_common_properties: function($new_element, $node) { var str_modifiers = $node.attr("modifiers") || "{}" var modifiers = JSON.parse(str_modifiers); + var ic = null; if (modifiers.invisible !== undefined) - new instance.web.form.InvisibilityChanger(this.view, this.view, modifiers.invisible, $new_element); + ic = new instance.web.form.InvisibilityChanger(this.view, this.view, modifiers.invisible, $new_element); $new_element.addClass($node.attr("class") || ""); $new_element.attr('style', $node.attr('style')); + return {invisibility_changer: ic,}; }, }); @@ -1380,15 +1430,11 @@ instance.web.form.InvisibilityChangerMixin = { _.bind(check, this)(); }, start: function() { - var check_visibility = function() { - if (this.get("effective_invisible")) { - this.$element.hide(); - } else { - this.$element.show(); - } - }; - this.on("change:effective_invisible", this, check_visibility); - _.bind(check_visibility, this)(); + this.on("change:effective_invisible", this, this._check_visibility); + this._check_visibility(); + }, + _check_visibility: function() { + this.$element.toggleClass('oe_form_invisible', this.get("effective_invisible")); }, }; @@ -1735,6 +1781,8 @@ instance.web.form.AbstractField = instance.web.form.FormWidget.extend(_.extend({ this.on("change:required", this, this._set_required); this._set_required(); } + this._check_visibility(); + this._check_css_flags(); }, /** * Private. Do not use. @@ -1837,6 +1885,7 @@ instance.web.form.ReinitializeFieldMixin = { instance.web.form.FieldChar = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, { template: 'FieldChar', + widget_class: 'oe_form_field_char', init: function (field_manager, node) { this._super(field_manager, node); this.password = this.node.attrs.password === 'True' || this.node.attrs.password === '1'; @@ -1874,7 +1923,7 @@ instance.web.form.FieldChar = instance.web.form.AbstractField.extend(_.extend({} return true; }, is_false: function() { - return this.get('value') === ''; + return this.get('value') === '' || this._super(); }, focus: function() { this.delay_focus(this.$element.find('input:first')); @@ -1941,6 +1990,7 @@ instance.web.form.FieldUrl = instance.web.form.FieldChar.extend({ instance.web.form.FieldFloat = instance.web.form.FieldChar.extend({ is_field_number: true, + widget_class: 'oe_form_field_float', init: function (field_manager, node) { this._super(field_manager, node); this.set({'value': 0}); @@ -1960,7 +2010,7 @@ instance.web.form.FieldFloat = instance.web.form.FieldChar.extend({ }); instance.web.DateTimeWidget = instance.web.OldWidget.extend({ - template: "web.datetimepicker", + template: "web.datepicker", jqueryui_object: 'datetimepicker', type_of_date: "datetime", init: function(parent) { @@ -2045,7 +2095,7 @@ instance.web.DateWidget = instance.web.DateTimeWidget.extend({ }); instance.web.form.FieldDatetime = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, { - template: "EmptyComponent", + template: "FieldDatetime", build_widget: function() { return new instance.web.DateTimeWidget(this); }, @@ -2082,7 +2132,7 @@ instance.web.form.FieldDatetime = instance.web.form.AbstractField.extend(_.exten return true; }, is_false: function() { - return this.get('value') === ''; + return this.get('value') === '' || this._super(); }, focus: function() { if (this.datewidget && this.datewidget.$input) @@ -2091,6 +2141,7 @@ instance.web.form.FieldDatetime = instance.web.form.AbstractField.extend(_.exten })); instance.web.form.FieldDate = instance.web.form.FieldDatetime.extend({ + template: "FieldDate", build_widget: function() { return new instance.web.DateWidget(this); } @@ -2131,7 +2182,7 @@ instance.web.form.FieldText = instance.web.form.AbstractField.extend(_.extend({} return true; }, is_false: function() { - return this.get('value') === ''; + return this.get('value') === '' || this._super(); }, focus: function($element) { this.delay_focus(this.$textarea); @@ -2322,9 +2373,11 @@ instance.web.form.CompletionFieldMixin = { var self = this; var dataset = new instance.web.DataSet(this, this.field.relation, self.build_context()); + var blacklist = this.get_search_blacklist(); return this.orderer.add(dataset.name_search( - search_val, self.build_domain(), 'ilike', this.limit + 1)).pipe(function(data) { + search_val, new instance.web.CompoundDomain(self.build_domain(), [["id", "not in", blacklist]]), + 'ilike', this.limit + 1)).pipe(function(data) { self.last_search = data; // possible selections for the m2o var values = _.map(data, function(x) { @@ -2362,6 +2415,9 @@ instance.web.form.CompletionFieldMixin = { return values; }); }, + get_search_blacklist: function() { + return []; + }, _quick_create: function(name) { var self = this; var slow_create = function () { @@ -2487,6 +2543,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(_.exten var tip_delay = 200; var tip_duration = 3000; var anyoneLoosesFocus = function() { + var used = false; if (self.floating) { if (self.last_search.length > 0) { if (self.last_search[0][0] != self.get("value")) { @@ -2494,13 +2551,17 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(_.exten self.display_value["" + self.last_search[0][0]] = self.last_search[0][1]; self.set({value: self.last_search[0][0]}); } else { + used = true; self.render_value(); } } else { + used = true; self.set({value: false}); + self.render_value(); } + self.floating = false; } - if (! self.get("value")) { + if (used) { tip_def.reject(); untip_def.reject(); tip_def = $.Deferred(); @@ -2547,7 +2608,8 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(_.exten e.preventDefault(); }, html: true, - close: anyoneLoosesFocus, + // disabled to solve a bug, but may cause others + //close: anyoneLoosesFocus, minLength: 0, delay: 0 }); @@ -2685,6 +2747,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ }, start: function() { this._super.apply(this, arguments); + this.$element.addClass('oe_form_field_one2many'); var self = this; @@ -2692,7 +2755,6 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ this.dataset.o2m = this; this.dataset.parent_view = this.view; this.dataset.child_name = this.name; - //this.dataset.child_name = this.dataset.on_change.add_last(function() { self.trigger_on_change(); }); @@ -2724,6 +2786,13 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ modes = !!modes ? modes.split(",") : ["tree"]; var views = []; _.each(modes, function(mode) { + if (! _.include(["list", "tree", "graph", "kanban"], mode)) { + try { + throw new Error(_.str.sprintf("View type '%s' is not supported in One2Many.", mode)); + } catch(e) { + instance.webclient.crashmanager.on_javascript_exception(e) + } + } var view = { view_id: false, view_type: mode == "tree" ? "list" : mode, @@ -2744,9 +2813,13 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ } view.options.not_interactible_on_create = true; } else if (view.view_type === "kanban") { + view.options.confirm_on_delete = false; + view.options.sortable = false; if (self.get("effective_readonly")) { view.options.action_buttons = false; view.options.quick_creatable = false; + view.options.creatable = false; + view.options.read_only_mode = true; } } views.push(view); @@ -2754,6 +2827,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ this.views = views; this.viewmanager = new instance.web.form.One2ManyViewManager(this, this.dataset, views, {}); + this.viewmanager.$element.addClass("oe_view_manager_one2many"); this.viewmanager.o2m = self; var once = $.Deferred().then(function() { self.init_form_last_update.resolve(); @@ -2957,6 +3031,12 @@ instance.web.form.One2ManyViewManager = instance.web.ViewManager.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, + create_function: function(data) { + return self.o2m.dataset.create(data).then(function(r) { + self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r.result])); + self.o2m.dataset.on_change(); + }); + }, write_function: function(id, data, options) { return self.o2m.dataset.write(id, data, {}).then(function() { self.o2m.reload_current_view(); @@ -2971,6 +3051,9 @@ instance.web.form.One2ManyViewManager = instance.web.ViewManager.extend({ form_view_options: {'not_interactible_on_create':true}, readonly: self.o2m.get("effective_readonly") }); + pop.on_select_elements.add_last(function() { + self.o2m.reload_current_view(); + }); }, }); @@ -3087,7 +3170,7 @@ instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend(_. if (this.get("effective_readonly")) return; var self = this; - self. $text = $("textarea", this.$element); + self.$text = $("textarea", this.$element); self.$text.textext({ plugins : 'tags arrow autocomplete', autocomplete: { @@ -3139,27 +3222,14 @@ instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend(_. return _.extend(el, {index:i}); })}); }); - }).bind('tagClick', function(e, tag, value, callback) { - var pop = new instance.web.form.FormOpenPopup(self.view); - pop.show_element( - self.field.relation, - value.id, - self.build_context(), - { - title: _t("Open: ") + (self.string || self.name) - } - ); - pop.on_write_completed.add_last(function() { - self.render_value(); - }); }).bind('hideDropdown', function() { self._drop_shown = false; - }).bind('hideDropdown', function() { + }).bind('showDropdown', function() { self._drop_shown = true; }); self.tags = self.$text.textext()[0].tags(); $("textarea", this.$element).focusout(function() { - $("textarea", this.$element).val(""); + self.$text.trigger("setInputData", ""); }).keydown(function(e) { if (event.keyCode === 9 && self._drop_shown) { self.$text.textext()[0].autocomplete().selectFromDropdown(); @@ -3177,6 +3247,9 @@ instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend(_. var tmp = [commands.replace_with(this.get("value"))]; return tmp; }, + get_search_blacklist: function() { + return this.get("value"); + }, render_value: function() { var self = this; var dataset = new instance.web.DataSetStatic(this, this.field.relation, self.view.dataset.get_context()); @@ -3192,17 +3265,6 @@ instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend(_. self.tags.addTags(_.map(data, function(el) {return {name: el[1], id:el[0]};})); } else { self.$element.html(QWeb.render("FieldMany2ManyTags.box", {elements: data})); - $(".oe_form_field_many2manytags_box", self.$element).click(function() { - var index = Number($(this).data("index")); - self.do_action({ - type: 'ir.actions.act_window', - res_model: self.field.relation, - res_id: self.get("value")[index], - context: self.build_context(), - views: [[false, 'form']], - target: 'current' - }); - }); } }; if (! self.get('values') || self.get('values').length > 0) { @@ -3230,6 +3292,7 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ }, start: function() { this._super.apply(this, arguments); + this.$element.addClass('oe_form_field_many2many'); var self = this; @@ -3238,7 +3301,7 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ this.dataset.on_unlink.add_last(function(ids) { self.dataset_changed(); }); - + this.is_setted.then(function() { self.load_view(); }); @@ -3251,7 +3314,7 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ }); }); }); - }) + }); }, set_value: function(value_) { value_ = value_ || []; @@ -3264,12 +3327,16 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ self.reload_content(); this.is_setted.resolve(); }, + get_value: function() { + return [commands.replace_with(this.get('value'))]; + }, load_view: function() { var self = this; this.list_view = new instance.web.form.Many2ManyListView(this, this.dataset, false, { 'addable': self.get("effective_readonly") ? null : _t("Add"), 'deletable': self.get("effective_readonly") ? false : true, 'selectable': self.multi_selection, + 'sortable': false, }); var embedded = (this.field.views || {}).tree; if (embedded) { @@ -3293,7 +3360,7 @@ instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({ }); }, dataset_changed: function() { - this.set({'value': [commands.replace_with(this.dataset.ids)]}); + this.set({'value': this.dataset.ids}); }, }); @@ -3343,6 +3410,211 @@ instance.web.form.Many2ManyListView = instance.web.ListView.extend(/** @lends in } }); +instance.web.form.FieldMany2ManyKanban = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.CompletionFieldMixin, { + disable_utility_classes: true, + init: function(field_manager, node) { + this._super(field_manager, node); + instance.web.form.CompletionFieldMixin.init.call(this); + m2m_kanban_lazy_init(); + this.is_loaded = $.Deferred(); + this.initial_is_loaded = this.is_loaded; + this.is_setted = $.Deferred(); + }, + start: function() { + this._super.apply(this, arguments); + + var self = this; + + this.dataset = new instance.web.form.Many2ManyDataSet(this, this.field.relation); + this.dataset.m2m = this; + this.dataset.on_unlink.add_last(function(ids) { + self.dataset_changed(); + }); + + this.is_setted.then(function() { + self.load_view(); + }); + this.is_loaded.then(function() { + self.on("change:effective_readonly", self, function() { + self.is_loaded = self.is_loaded.pipe(function() { + self.kanban_view.destroy(); + return $.when(self.load_view()).then(function() { + self.reload_content(); + }); + }); + }); + }) + }, + set_value: function(value_) { + value_ = value_ || []; + if (value_.length >= 1 && value_[0] instanceof Array) { + value_ = value_[0][2]; + } + this._super(value_); + this.dataset.set_ids(value_); + var self = this; + self.reload_content(); + this.is_setted.resolve(); + }, + load_view: function() { + var self = this; + this.kanban_view = new instance.web.form.Many2ManyKanbanView(this, this.dataset, false, { + 'create_text': _t("Add"), + 'creatable': self.get("effective_readonly") ? false : true, + 'quick_creatable': self.get("effective_readonly") ? false : true, + 'read_only_mode': self.get("effective_readonly") ? true : false, + 'confirm_on_delete': false, + }); + var embedded = (this.field.views || {}).kanban; + if (embedded) { + this.kanban_view.set_embedded_view(embedded); + } + this.kanban_view.m2m = this; + var loaded = $.Deferred(); + this.kanban_view.on_loaded.add_last(function() { + self.initial_is_loaded.resolve(); + loaded.resolve(); + }); + this.kanban_view.do_switch_view.add_last(_.bind(this.open_popup, this)); + $.async_when().then(function () { + self.kanban_view.appendTo(self.$element); + }); + return loaded; + }, + reload_content: function() { + var self = this; + this.is_loaded = this.is_loaded.pipe(function() { + return self.kanban_view.do_search(self.build_domain(), self.dataset.get_context(), []); + }); + }, + dataset_changed: function() { + this.set({'value': [commands.replace_with(this.dataset.ids)]}); + }, + open_popup: function(type, unused) { + if (type !== "form") + return; + var self = this; + if (this.dataset.index === null) { + var pop = new instance.web.form.SelectCreatePopup(this); + pop.select_element( + this.field.relation, + { + title: _t("Add: ") + this.name + }, + new instance.web.CompoundDomain(this.build_domain(), ["!", ["id", "in", this.dataset.ids]]), + this.build_context() + ); + pop.on_select_elements.add(function(element_ids) { + _.each(element_ids, function(one_id) { + if(! _.detect(self.dataset.ids, function(x) {return x == one_id;})) { + self.dataset.set_ids([].concat(self.dataset.ids, [one_id])); + self.dataset_changed(); + self.reload_content(); + } + }); + }); + } else { + var id = self.dataset.ids[self.dataset.index]; + var pop = new instance.web.form.FormOpenPopup(self.view); + pop.show_element(self.field.relation, id, self.build_context(), { + title: _t("Open: ") + self.name, + write_function: function(id, data, options) { + return self.dataset.write(id, data, {}).then(function() { + self.reload_content(); + }); + }, + alternative_form_view: self.field.views ? self.field.views["form"] : undefined, + parent_view: self.view, + child_name: self.name, + readonly: self.get("effective_readonly") + }); + } + }, + add_id: function(id) { + this.quick_create.add_id(id); + }, +})); + +function m2m_kanban_lazy_init() { +if (instance.web.form.Many2ManyKanbanView) + return; +instance.web.form.Many2ManyKanbanView = instance.web_kanban.KanbanView.extend({ + quick_create_class: 'instance.web.form.Many2ManyQuickCreate', + _is_quick_create_enabled: function() { + return this._super() && ! this.group_by; + }, +}); +instance.web.form.Many2ManyQuickCreate = instance.web.Widget.extend({ + template: 'Many2ManyKanban.quick_create', + + /** + * close_btn: If true, the widget will display a "Close" button able to trigger + * a "close" event. + */ + init: function(parent, dataset, context, buttons) { + this._super(parent); + this.m2m = this.getParent().view.m2m; + this.m2m.quick_create = this; + this._dataset = dataset; + this._buttons = buttons || false; + this._context = context || {}; + }, + start: function () { + var self = this; + self.$text = this.$element.find('input').css("width", "200px"); + self.$text.textext({ + plugins : 'arrow autocomplete', + autocomplete: { + render: function(suggestion) { + return $(''). + data('index', suggestion['index']).html(suggestion['label']); + } + }, + ext: { + autocomplete: { + selectFromDropdown: function() { + $(this).trigger('hideDropdown'); + var index = Number(this.selectedSuggestionElement().children().children().data('index')); + var data = self.search_result[index]; + if (data.id) { + self.add_id(data.id); + } else { + data.action(); + } + }, + }, + itemManager: { + itemToString: function(item) { + return item.name; + }, + }, + }, + }).bind('getSuggestions', function(e, data) { + var _this = this; + var str = !!data ? data.query || '' : ''; + self.m2m.get_search_result(str).then(function(result) { + self.search_result = result; + $(_this).trigger('setSuggestions', {result : _.map(result, function(el, i) { + return _.extend(el, {index:i}); + })}); + }); + }); + self.$text.focusout(function() { + self.$text.val(""); + }); + }, + focus: function() { + this.$text.focus(); + }, + add_id: function(id) { + var self = this; + self.$text.val(""); + self.trigger('added', id); + this.m2m.dataset_changed(); + }, +}); +} + /** * Class with everything which is common between FormOpenPopup and SelectCreatePopup. */ @@ -3393,7 +3665,7 @@ instance.web.form.AbstractFormPopup = instance.web.OldWidget.extend({ width: '90%', min_width: '800px', close: function() { - self.check_exit(); + self.check_exit(true); }, title: this.options.title || "", }, this.$element).open(); @@ -3451,9 +3723,10 @@ instance.web.form.AbstractFormPopup = instance.web.OldWidget.extend({ }, on_select_elements: function(element_ids) { }, - check_exit: function() { + check_exit: function(no_destroy) { if (this.created_elements.length > 0) { this.on_select_elements(this.created_elements); + this.created_elements = []; } this.destroy(); }, @@ -3542,7 +3815,8 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend self.view_list = new instance.web.form.SelectCreateListView(self, self.dataset, false, _.extend({'deletable': false, - 'selectable': !self.options.disable_multiple_selection + 'selectable': !self.options.disable_multiple_selection, + 'read_only': true, }, self.options.list_view_options || {})); self.view_list.popup = self; self.view_list.appendTo($(".oe-select-create-popup-view-list", self.$element)).pipe(function() { @@ -3708,13 +3982,22 @@ instance.web.form.FieldReference = instance.web.form.AbstractField.extend(_.exte instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, { init: function(field_manager, node) { + var self = this; this._super(field_manager, node); - this.iframe = this.element_id + '_iframe'; this.binary_value = false; + this.fileupload_id = _.uniqueId('oe_fileupload'); + $(window).on(this.fileupload_id, function() { + var args = [].slice.call(arguments).slice(1); + self.on_file_uploaded.apply(self, args); + }); + }, + stop: function() { + $(window).off(this.fileupload_id); + this._super.apply(this, arguments); }, initialize_content: function() { this.$element.find('input.oe-binary-file').change(this.on_file_change); - this.$element.find('button.oe-binary-file-save').click(this.on_save_as); + this.$element.find('button.oe_binary_file_save').click(this.on_save_as); this.$element.find('.oe-binary-file-clear').click(this.on_clear); }, human_filesize : function(size) { @@ -3730,8 +4013,8 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend( // TODO: on modern browsers, we could directly read the file locally on client ready to be used on image cropper // http://www.html5rocks.com/tutorials/file/dndfiles/ // http://deepliquid.com/projects/Jcrop/demos.php?demo=handler - window[this.iframe] = this.on_file_uploaded; - if ($(e.target).val() != '') { + + if ($(e.target).val() !== '') { this.$element.find('form.oe-binary-form input[name=session_id]').val(this.session.session_id); this.$element.find('form.oe-binary-form').submit(); this.$element.find('.oe-binary-progress').show(); @@ -3739,12 +4022,12 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend( } }, on_file_uploaded: function(size, name, content_type, file_base64) { - delete(window[this.iframe]); if (size === false) { this.do_warn("File Upload", "There was a problem while uploading your file"); // TODO: use openerp web crashmanager console.warn("Error while uploading file : ", name); } else { + this.filename = name; this.on_file_uploaded_and_valid.apply(this, arguments); } this.$element.find('.oe-binary-progress').hide(); @@ -3752,20 +4035,33 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend( }, on_file_uploaded_and_valid: function(size, name, content_type, file_base64) { }, - on_save_as: function() { - $.blockUI(); - this.session.get_file({ - url: '/web/binary/saveas_ajax', - data: {data: JSON.stringify({ - model: this.view.dataset.model, - id: (this.view.datarecord.id || ''), - field: this.name, - filename_field: (this.node.attrs.filename || ''), - context: this.view.dataset.get_context() - })}, - complete: $.unblockUI, - error: instance.webclient.crashmanager.on_rpc_error - }); + on_save_as: function(ev) { + var value = this.get('value'); + if (!value) { + this.do_warn(_t("Save As..."), _t("The field is empty, there's nothing to save !")); + ev.stopPropagation(); + } else if (this._dirty_flag) { + var link = this.$('.oe_binary_file_save_data')[0]; + link.download = this.filename || "download.bin"; // Works on only on Google Chrome + //link.target = '_blank'; + link.href = "data:application/octet-stream;base64," + value; + } else { + $.blockUI(); + this.session.get_file({ + url: '/web/binary/saveas_ajax', + data: {data: JSON.stringify({ + model: this.view.dataset.model, + id: (this.view.datarecord.id || ''), + field: this.name, + filename_field: (this.node.attrs.filename || ''), + context: this.view.dataset.get_context() + })}, + complete: $.unblockUI, + error: instance.webclient.crashmanager.on_rpc_error + }); + ev.stopPropagation(); + return false; + } }, on_clear: function() { if (this.get('value') !== false) { @@ -3833,14 +4129,6 @@ instance.web.form.FieldBinaryFile = instance.web.form.FieldBinary.extend({ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({ template: 'FieldBinaryImage', - initialize_content: function() { - this._super(); - this.$placeholder = $(".oe_form_field-binary-image-placeholder", this.$element); - if (!this.get("effective_readonly")) - this.$element.find('.oe-binary').show(); - else - this.$element.find('.oe-binary').hide(); - }, set_value: function(value_) { this._super.apply(this, arguments); this.render_value(); @@ -3855,8 +4143,9 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({ } else { url = "/web/static/src/img/placeholder.png"; } - var rendered = QWeb.render("FieldBinaryImage-img", {widget: this, url: url});; - this.$placeholder.html(rendered); + var img = QWeb.render("FieldBinaryImage-img", { widget: this, url: url }); + this.$element.find('> img').remove(); + this.$element.prepend(img); }, on_file_change: function() { this.render_value(); @@ -3873,158 +4162,122 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({ } }); -instance.web.form.FieldStatusO2M = instance.web.form.AbstractField.extend({ - template: "EmptyComponent", +instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ + tagName: "span", start: function() { this._super(); this.selected_value = null; - - this.render_list(); + // preview in start only for selection fields, because of the dynamic behavior of many2one fields. + if (this.field.type in ['selection']) { + this.render_list(); + } }, set_value: function(value_) { - this._super(value_); - this.selected_value = value_; - - this.render_list(); - }, - render_list: function() { var self = this; - var shown = _.map(((this.node.attrs || {}).statusbar_visible || "").split(","), - function(x) { return _.str.trim(x); }); - shown = _.select(shown, function(x) { return x.length > 0; }); - - if (shown.length == 0) { - this.to_show = this.field.selection; + this._super(value_); + // find selected value: + // - many2one: [2, "New"] -> 2 + // - selection: new -> new + if (this.field.type == "many2one") { + this.selected_value = value_[0]; } else { - this.to_show = _.select(this.field.selection, function(x) { - return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value; - }); + this.selected_value = value_; } - - // get a DataSet on the current model (ex: crm.lead) - this.model = new instance.web.DataSet(this, this.field_manager.dataset.model); - - // get the domain of the current field (ex: crm.lead.stage_id -> section_ids = section_id) - var fields_get_defer = this.model.call('fields_get', [[this.name]]).pipe( function (record) { - this.field_domain = record.domain; + // trick to be sure all values are loaded in the form, therefore + // enabling the evaluation of dynamic domains + $.async_when().then(function() { + return self.render_list(); }); - - // get a DataSetSearch on the current field relation (ex: crm.lead.stage_id -> crm.case.stage) - this.model_ext = new instance.web.DataSetSearch(this, this.field.relation); - - // search in the external relation for all possible values, then render them - var rendering_done = $.when(fields_get_defer).pipe( function () { - self.model_ext.read_slice(['name'], {'domain': self.field_domain}).pipe( function (records) { - self.to_show = []; - _(records).each(function (record) { - self.to_show.push([record.id, record.name]); - }); - }).then(self.proxy('render_elements')); - }); - - return rendering_done; }, - render_elements: function () { - var content = instance.web.qweb.render("FieldStatus.content", {widget: this, _:_}); - this.$element.html(content); - - var colors = JSON.parse((this.node.attrs || {}).statusbar_colors || "{}"); - var color = colors[this.selected_value]; - if (color) { - var elem = this.$element.find("li.oe-arrow-list-selected span"); - elem.css("border-color", color); - if (this.check_white(color)) - elem.css("color", "white"); - elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-before"); - elem.css("border-left-color", "rgba(0,0,0,0)"); - elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-after"); - elem.css("border-color", "rgba(0,0,0,0)"); - elem.css("border-left-color", color); - } - }, - check_white: function(color) { - var div = $("
"); - div.css("display", "none"); - div.css("color", color); - div.appendTo($("body")); - var ncolor = div.css("color"); - div.remove(); - var res = /^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/.exec(ncolor); - if (!res) { - return false; - } - var comps = [parseInt(res[1]), parseInt(res[2]), parseInt(res[3])]; - var lum = comps[0] * 0.3 + comps[1] * 0.59 + comps[1] * 0.11; - if (lum < 128) { - return true; - } - return false; - } -}); - -instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ - template: "EmptyComponent", - start: function() { - this._super(); - this.selected_value = null; - this.render_list(); + /** Get the status list and render them + * to_show: [[identifier, value_to_display]] where + * - identifier = key for a selection, id for a many2one + * - display_val = label that will be displayed + * - ex: [[0, "New"]] (many2one) or [["new", "In Progress"]] (selection) + */ + render_list: function() { + var self = this; + // get selection values, filter them and render them + var selection_done = this.get_selection().pipe(self.proxy('filter_selection')).pipe(self.proxy('render_elements')); }, - set_value: function(value_) { - this._super(value_); - this.selected_value = value_; - this.render_list(); + /** Get the selection list to be displayed in the statusbar widget. + * For selection fields: this is directly given by this.field.selection + * For many2one fields : + * - perform a search on the relation of the many2one field (given by + * field.relation ) + * - get the field domain for the search + * - self.build_domain() gives the domain given by the view or by + * the field + * - if the optional statusbar_fold attribute is set to true, make + * an AND with build_domain to hide all 'fold=true' columns + * - make an OR with current value, to be sure it is displayed, + * with the correct order, even if it is folded + */ + get_selection: function() { + var self = this; + if (this.field.type == "many2one") { + this.selection = []; + // get fold information from widget + var fold = ((this.node.attrs || {}).statusbar_fold || true); + // build final domain: if fold option required, add the + if (fold == true) { + var domain = new instance.web.CompoundDomain(['|'], ['&'], self.build_domain(), [['fold', '=', false]], [['id', '=', self.selected_value]]); + } else { + var domain = new instance.web.CompoundDomain(['|'], self.build_domain(), [['id', '=', self.selected_value]]); + } + // get a DataSetSearch on the current field relation (ex: crm.lead.stage_id -> crm.case.stage) + var model_ext = new instance.web.DataSetSearch(this, this.field.relation, self.build_context(), domain); + // fetch selection + var read_defer = model_ext.read_slice(['name'], {}).pipe( function (records) { + _(records).each(function (record) { + self.selection.push([record.id, record.name]); + }); + }); + } else { + this.selection = this.field.selection; + var read_defer = new $.Deferred().resolve(); + } + return read_defer; }, - render_list: function() { + + /** Filters this.selection, according to values coming from the statusbar_visible + * attribute of the field. For example: statusbar_visible="draft,open" + * Currently, the key of (key, label) pairs has to be used in the + * selection of visible items. This feature is not meant to be used + * with many2one fields. + */ + filter_selection: function() { var self = this; var shown = _.map(((this.node.attrs || {}).statusbar_visible || "").split(","), function(x) { return _.str.trim(x); }); shown = _.select(shown, function(x) { return x.length > 0; }); - + if (shown.length == 0) { - this.to_show = this.field.selection; + this.to_show = this.selection; } else { - this.to_show = _.select(this.field.selection, function(x) { + this.to_show = _.select(this.selection, function(x) { return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value; }); } + }, + /** Renders the widget. This function also checks for statusbar_colors='{"pending": "blue"}' + * attribute in the widget. This allows to set a given color to a given + * state (given by the key of (key, label)). + */ + render_elements: function () { var content = instance.web.qweb.render("FieldStatus.content", {widget: this, _:_}); this.$element.html(content); var colors = JSON.parse((this.node.attrs || {}).statusbar_colors || "{}"); var color = colors[this.selected_value]; if (color) { - var elem = this.$element.find("li.oe-arrow-list-selected span"); - elem.css("border-color", color); - if (this.check_white(color)) - elem.css("color", "white"); - elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-before"); - elem.css("border-left-color", "rgba(0,0,0,0)"); - elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-after"); - elem.css("border-color", "rgba(0,0,0,0)"); - elem.css("border-left-color", color); - } - }, - check_white: function(color) { - var div = $("
"); - div.css("display", "none"); - div.css("color", color); - div.appendTo($("body")); - var ncolor = div.css("color"); - div.remove(); - var res = /^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/.exec(ncolor); - if (!res) { - return false; + var elem = this.$element.find("li.oe_form_steps_active span"); + elem.css("color", color); } - var comps = [parseInt(res[1]), parseInt(res[2]), parseInt(res[3])]; - var lum = comps[0] * 0.3 + comps[1] * 0.59 + comps[1] * 0.11; - if (lum < 128) { - return true; - } - return false; - } + }, }); /** @@ -4044,7 +4297,8 @@ instance.web.form.widgets = new instance.web.Registry({ 'selection' : 'instance.web.form.FieldSelection', 'many2one' : 'instance.web.form.FieldMany2One', 'many2many' : 'instance.web.form.FieldMany2Many', - 'many2manytags' : 'instance.web.form.FieldMany2ManyTags', + 'many2many_tags' : 'instance.web.form.FieldMany2ManyTags', + 'many2many_kanban' : 'instance.web.form.FieldMany2ManyKanban', 'one2many' : 'instance.web.form.FieldOne2Many', 'one2many_list' : 'instance.web.form.FieldOne2Many', 'reference' : 'instance.web.form.FieldReference', @@ -4055,8 +4309,7 @@ instance.web.form.widgets = new instance.web.Registry({ 'progressbar': 'instance.web.form.FieldProgressBar', 'image': 'instance.web.form.FieldBinaryImage', 'binary': 'instance.web.form.FieldBinaryFile', - 'statusbar': 'instance.web.form.FieldStatus', - 'statusbaro2m': 'instance.web.form.FieldStatusO2M', + 'statusbar': 'instance.web.form.FieldStatus' }); /**