}
}
},
- 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();
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);
}
},
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.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;
- 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);
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.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.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();
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('showDropdown', function() {
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) {
},
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,
+ 'sortable': false,
});
var embedded = (this.field.views || {}).tree;
if (embedded) {
});
},
dataset_changed: function() {
- this.set({'value': [commands.replace_with(this.dataset.ids)]});
+ this.set({'value': this.dataset.ids});
},
});
'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) {
var self = this;
self.$text.val("");
self.trigger('added', id);
+ this.m2m.dataset_changed();
},
});
}
width: '90%',
min_width: '800px',
close: function() {
- self.check_exit();
+ self.check_exit(true);
},
title: this.options.title || "",
}, this.$element).open();
},
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();
},
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() {
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.FieldStatus = instance.web.form.AbstractField.extend({
- template: "EmptyComponent",
+ 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;
+ // get selection values, filter them and render them
+ var selection_done = this.get_selection().pipe(self.proxy('filter_selection')).pipe(self.proxy('render_elements'));
+ },
+
+ /** 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;
+ },
+
+ /** 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 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;
+ var elem = this.$element.find("li.oe_form_steps_active span");
+ elem.css("color", color);
}
- return false;
- }
+ },
});
/**