}
}
},
- do_show: function () {
+ do_show: function (options) {
var self = this;
+ options = options || {};
if (this.sidebar) {
this.sidebar.$element.show();
}
}).pipe(self.on_record_loaded);
}
result.pipe(function() {
+ if (options.editable) {
+ self.set({mode: "edit"});
+ }
self.$element.css('visibility', 'visible');
});
return result;
return self.on_processed_onchange(response, processed);
} catch(e) {
- console.error(e);
+ instance.webclient.crashmanager.on_javascript_exception(e);
return $.Deferred().reject();
}
});
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"); }}
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();
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();
}
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();
var msg = "<ul>";
_.each(this.fields, function(f) {
if (!f.is_valid()) {
- msg += "<li>" + f.node.attrs.string + "</li>";
+ msg += "<li>" + (f.node.attrs.string || f.field.string) + "</li>";
}
});
msg += "</ul>";
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);
}
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; })
},
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;
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('<group col="4"/>');
+ this.$form.find('page').each(function() {
+ if (!$(this).parents('field').length) {
+ $(this).wrapInner('<group col="4"/>');
+ }
+ });
+ }
+ selector = 'form[version!="7.0"] page,form[version!="7.0"]';
+ },
render_to: function($target) {
var self = this;
this.$target = $target;
// but one day, we will have to get rid of xml2json
var xml = instance.web.json_node_to_xml(this.fvg.arch);
this.$form = $('<div class="oe_form">' + xml + '</div>');
- 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 = [];
}
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")];
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) {
}
this.$target.toggleClass('oe_layout_debugging');
},
- process: function($tag, layout) {
+ process: function($tag) {
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();
if (this.tags_registry.contains(tagname)) {
this.tags_to_init.push($tag);
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 <field> children of a <group> tag only
+ * This method will add the implicit <label...> for every field
+ * in the <group>
+ */
preprocess_field: function($field) {
var self = this;
var name = $field.attr('name'),
"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) {
}
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 <group> 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 = [];
var tagName = $child[0].tagName.toLowerCase();
var $td = $('<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) {
}
$group.before($new_group).remove();
- // Now compute width of cells
$table.find('> tbody > tr').each(function() {
var to_compute = [],
row_cols = cols,
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;
}
$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) {
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 = {
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) {
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,};
},
});
_.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"));
},
};
this.on("change:required", this, this._set_required);
this._set_required();
}
+ this._check_visibility();
+ this._check_css_flags();
},
/**
* Private. Do not use.
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';
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'));
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});
});
instance.web.DateTimeWidget = instance.web.OldWidget.extend({
- template: "web.datetimepicker",
+ template: "web.datepicker",
jqueryui_object: 'datetimepicker',
type_of_date: "datetime",
init: function(parent) {
});
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);
},
return true;
},
is_false: function() {
- return this.get('value') === '';
+ return this.get('value') === '' || this._super();
},
focus: function() {
if (this.datewidget && this.datewidget.$input)
}));
instance.web.form.FieldDate = instance.web.form.FieldDatetime.extend({
+ template: "FieldDate",
build_widget: function() {
return new instance.web.DateWidget(this);
}
return true;
},
is_false: function() {
- return this.get('value') === '';
+ return this.get('value') === '' || this._super();
},
focus: function($element) {
this.delay_focus(this.$textarea);
});
})();
-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.
*/
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) {
return values;
});
},
+ get_search_blacklist: function() {
+ return [];
+ },
_quick_create: function(name) {
var self = this;
var slow_create = function () {
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")) {
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();
e.preventDefault();
},
html: true,
- close: anyoneLoosesFocus,
+ // disabled to solve a bug, but may cause others
+ //close: anyoneLoosesFocus,
minLength: 0,
delay: 0
});
},
start: function() {
this._super.apply(this, arguments);
+ this.$element.addClass('oe_form_field_one2many');
var self = this;
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();
});
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,
view.view_type = 'form';
}
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);
});
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.$element.addClass("oe_view_manager_one2many");
+ this.viewmanager.o2m = self;
var once = $.Deferred().then(function() {
self.init_form_last_update.resolve();
});
},
});
+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,
+ 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();
+ });
+ },
+ 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_select_elements.add_last(function() {
+ self.o2m.reload_current_view();
+ });
+ },
+});
+
instance.web.form.One2ManyDataSet = instance.web.BufferedDataSet.extend({
get_context: function() {
this.context = this.o2m.build_context([this.o2m.name]);
} 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,
{
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,
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;
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();
- });
- });
-
- },
});
}
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: {
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();
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());
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) {
* 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) {
},
start: function() {
this._super.apply(this, arguments);
+ this.$element.addClass('oe_form_field_many2many');
var self = this;
this.dataset.on_unlink.add_last(function(ids) {
self.dataset_changed();
});
-
+
this.is_setted.then(function() {
self.load_view();
});
});
});
});
- })
+ });
},
set_value: function(value_) {
value_ = value_ || [];
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,
- '$buttons': $(".oe_form_view_m2m_buttons", self.$element),
+ 'sortable': false,
});
var embedded = (this.field.views || {}).tree;
if (embedded) {
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;
},
});
},
dataset_changed: function() {
- this.set({'value': [commands.replace_with(this.dataset.ids)]});
+ this.set({'value': this.dataset.ids});
},
});
}
});
-/**
- * @class
- * @extends instance.web.OldWidget
- */
-instance.web.form.SelectCreatePopup = instance.web.OldWidget.extend(/** @lends instance.web.form.SelectCreatePopup# */{
- template: "SelectCreatePopup",
- /**
- * 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) {
+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.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 || ""
+
+ 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.start();
+
+ 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();
+ });
+ });
+ });
+ })
},
- start: function() {
- this._super();
+ 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;
- 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);
+ 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,
});
- };
- 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);
- if (this.options.initial_view == "search") {
- self.rpc('/web/session/eval_domain_and_context', {
- domains: [],
- contexts: [this.context]
- }, function (results) {
- var search_defaults = {};
- _.each(results.context, function (value_, key) {
- var match = /^search_default_(.*)$/.exec(key);
- if (match) {
- search_defaults[match[1]] = value_;
+ 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();
}
});
- self.setup_search_view(search_defaults);
});
- } else { // "form"
- this.new_object();
+ } 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")
+ });
}
},
- stop: function () {
- this.$element.dialog('close');
- this._super();
+ add_id: function(id) {
+ this.quick_create.add_id(id);
},
- setup_search_view: function(search_defaults) {
- var self = this;
- if (this.searchview) {
- this.searchview.destroy();
- }
+}));
+
+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 $('<span class="text-label"/>').
+ 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.
+ */
+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(true);
+ },
+ 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(no_destroy) {
+ if (this.created_elements.length > 0) {
+ this.on_select_elements(this.created_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
+ * - list_view_options
+ */
+ select_element: function(model, options, domain, context) {
+ this.init_popup(model, null, domain, context, options);
+ var self = this;
+ _.defaults(this.options, {
+ initial_view: "search",
+ });
+ this.initial_ids = this.options.initial_ids;
+ this.display_popup();
+ },
+ start: function() {
+ var self = this;
+ this.init_dataset();
+ if (this.options.initial_view == "search") {
+ self.rpc('/web/session/eval_domain_and_context', {
+ domains: [],
+ contexts: [this.context]
+ }, function (results) {
+ var search_defaults = {};
+ _.each(results.context, function (value_, key) {
+ var match = /^search_default_(.*)$/.exec(key);
+ if (match) {
+ search_defaults[match[1]] = value_;
+ }
+ });
+ self.setup_search_view(search_defaults);
+ });
+ } else { // "form"
+ this.new_object();
+ }
+ },
+ setup_search_view: function(search_defaults) {
+ var self = this;
+ if (this.searchview) {
+ this.searchview.destroy();
+ }
this.searchview = new instance.web.SearchView(this,
this.dataset, false, search_defaults);
this.searchview.on_search.add(function(domains, contexts, groupbys) {
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() {
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) {
}
},
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();
- },
- check_exit: function() {
- if (this.created_elements.length > 0) {
- this.on_select_elements(this.created_elements);
- }
- this.destroy();
+ this.setup_form_view();
},
- on_default_get: function(res) {}
});
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) {
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) {
// 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();
}
},
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();
},
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) {
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();
} 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();
}
});
-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_) {
+ var self = this;
this._super(value_);
- this.selected_value = value_;
-
- this.render_list();
+ // find selected value:
+ // - many2one: [2, "New"] -> 2
+ // - selection: new -> new
+ if (this.field.type == "many2one") {
+ this.selected_value = value_[0];
+ } else {
+ this.selected_value = value_;
+ }
+ // 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 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;
- var shown = _.map(((this.node.attrs || {}).statusbar_visible || "").split(","),
- function(x) { return _.str.trim(x); });
- shown = _.select(shown, function(x) { return x.length > 0; });
+ // get selection values, filter them and render them
+ var selection_done = this.get_selection().pipe(self.proxy('filter_selection')).pipe(self.proxy('render_elements'));
+ },
- if (shown.length == 0) {
- this.to_show = this.field.selection;
- } else {
- this.to_show = _.select(this.field.selection, function(x) {
- return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value;
+ /** 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();
}
-
- 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></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();
+ return read_defer;
},
- set_value: function(value_) {
- this._super(value_);
- this.selected_value = value_;
- this.render_list();
- },
- 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></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;
- }
+ },
});
/**
'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',
'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'
});
/**