-openerp.web.form = function (instance) {
+(function() {
+
+var instance = openerp;
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;
this.has_been_loaded.resolve();
// Add bounce effect on button 'Edit' when click on readonly page view.
- this.$el.find(".oe_form_group_row,.oe_form_field,label").on('click', function (e) {
+ this.$el.find(".oe_form_group_row,.oe_form_field,label,h1,.oe_title,.oe_notebook_page, .oe_list_content").on('click', function (e) {
if(self.get("actual_mode") == "view") {
var $button = self.options.$buttons.find(".oe_form_button_edit");
$button.openerpBounce();
self.on_form_changed();
self.rendering_engine.init_fields();
self.is_initialized.resolve();
- self.do_update_pager(record.id == null);
+ self.do_update_pager(record.id === null || record.id === undefined);
if (self.sidebar) {
self.sidebar.do_attachement_update(self.dataset, self.datarecord.id);
}
var method = call[1];
if (!_.str.trim(call[2])) {
- return {method: method, args: []}
+ return {method: method, args: []};
}
var argument_replacement = {
// form field
if (self.fields[field]) {
var value_ = self.fields[field].get_value();
- return value_ == null ? false : value_;
+ return value_ === null || value_ === undefined ? false : value_;
}
// parent field
var splitted = field.split('.');
}
var p_val = parent_fields[_.str.trim(splitted[1])];
if (p_val !== undefined) {
- return p_val == null ? false : p_val;
+ return p_val === null || p_val === undefined ? false : p_val;
}
}
// string literal
}
return $.when();
});
- };
+ }
return iterate();
});
},
} else {
$.async_when().done(function () {
def.reject();
- })
+ });
}
});
return def.promise();
reload: function() {
var self = this;
return this.reload_mutex.exec(function() {
- if (self.dataset.index == null) {
+ if (self.dataset.index === null || self.dataset.index === undefined) {
self.trigger("previous_view");
return $.Deferred().reject().promise();
}
- if (self.dataset.index == null || self.dataset.index < 0) {
+ if (self.dataset.index < 0) {
return $.when(self.on_button_new());
} else {
var fields = _.keys(self.fields_view.fields);
return field.get_displayed();
}
return value;
- }
+ };
var fields = _.chain(this.fields)
.map(function (field) {
var value = field.get_value();
string: field.string,
value: value,
displayed: display(field, value),
- }
+ };
})
.compact()
.sortBy(function (field) { return field.string; })
string: field.string,
value: value,
displayed: display(field, value),
- }
+ };
})
.value();
row_cols = cols;
} else if (tagName==='group') {
// When <group> <group/><group/> </group>, we need a spacing between the two groups
- $td.addClass('oe_group_right')
+ $td.addClass('oe_group_right');
}
row_cols -= colspan;
};
instance.web.form.is_bin_size = function(v) {
- return /^\d+(\.\d*)? \w+$/.test(v);
+ return (/^\d+(\.\d*)? \w+$/).test(v);
};
/**
return QWeb.render(template, {
debug: instance.session.debug,
widget: widget
- })},
+ });
+ },
gravity: $.fn.tipsy.autoBounds(50, 'nw'),
html: true,
opacity: 0.85,
* @param node
*/
init: function(field_manager, node) {
- var self = this
+ var self = this;
this._super(field_manager, node);
this.name = this.node.attrs.name;
this.field = this.field_manager.get_field_desc(this.name);
if (! this.get("effective_readonly")) {
var show_value = instance.web.format_value(this.get('value'), this, '');
if (show_value === '') {
- this.$textarea.css('height', parseInt(this.default_height)+"px");
+ this.$textarea.css('height', parseInt(this.default_height, 10)+"px");
}
this.$textarea.val(show_value);
if (! this.auto_sized) {
}, this));
var check_readonly = function() {
self.$checkbox.prop('disabled', self.get("effective_readonly"));
+ self.click_disabled_boolean();
};
this.on("change:effective_readonly", this, check_readonly);
check_readonly.call(this);
focus: function() {
var input = this.$checkbox && this.$checkbox[0];
return input ? input.focus() : false;
+ },
+ click_disabled_boolean: function(){
+ var $disabled = this.$el.find('input[type=checkbox]:disabled');
+ $disabled.each(function (){
+ $(this).next('div').remove();
+ $(this).closest("span").append($('<div class="boolean"></div>'));
+ });
}
});
set_value: function (value_) {
if (value_) {
if (this.field.type == "selection") {
- value_ = _.find(this.field.selection, function (sel) { return sel[0] == value_});
+ value_ = _.find(this.field.selection, function (sel) { return sel[0] == value_;});
}
else if (!this.selection.length) {
this.selection = [value_];
this.$el.toggleClass("oe_readonly", this.get('effective_readonly'));
this.$("input:checked").prop("checked", false);
if (this.get_value()) {
- this.$("input").filter(function () {return this.value == self.get_value()}).prop("checked", true);
+ this.$("input").filter(function () {return this.value == self.get_value();}).prop("checked", true);
this.$(".oe_radio_readonly").text(this.get('value') ? this.get('value')[1] : "");
}
}
})();
/**
- * A mixin containing some useful methods to handle completion inputs.
- */
+ A mixin containing some useful methods to handle completion inputs.
+
+ The widget containing this option can have these arguments in its widget options:
+ - no_quick_create: if true, it will disable the quick create
+*/
instance.web.form.CompletionFieldMixin = {
init: function() {
this.limit = 7;
}
// quick create
var raw_result = _(data.result).map(function(x) {return x[1];});
- if (search_val.length > 0 && !_.include(raw_result, search_val)) {
+ if (search_val.length > 0 && !_.include(raw_result, search_val) &&
+ ! (self.options && self.options.no_quick_create)) {
values.push({
label: _.str.sprintf(_t('Create "<strong>%s</strong>"'),
$('<span />').text(search_val).html()),
self.field.relation,
{
title: (view === 'search' ? _t("Search: ") : _t("Create: ")) + this.string,
- initial_ids: ids ? _.map(ids, function(x) {return x[0]}) : undefined,
+ initial_ids: ids ? _.map(ids, function(x) {return x[0];}) : undefined,
initial_view: view,
disable_multiple_selection: true
},
this.$input.keydown(input_changed);
this.$input.change(input_changed);
this.$drop_down.click(function() {
- self.$input.focus();
+ self.$input.focus();
if (self.$input.autocomplete("widget").is(":visible")) {
self.$input.autocomplete("close");
} else {
var self = this;
if (value_ instanceof Array) {
this.display_value = {};
- this.display_value_backup = {}
+ this.display_value_backup = {};
if (! this.options.always_reload) {
this.display_value["" + value_[0]] = value_[1];
}
});
controller.on('pager_action_executed',self,self.save_any_view);
} else if (view_type == "graph") {
- self.reload_current_view()
+ self.reload_current_view();
}
def.resolve();
});
},
reload_current_view: function() {
var self = this;
- return self.is_loaded = self.is_loaded.then(function() {
+ self.is_loaded = self.is_loaded.then(function() {
var active_view = self.viewmanager.active_view;
var view = self.viewmanager.views[active_view].controller;
if(active_view === "list") {
return view.do_search(self.build_domain(), self.dataset.get_context(), []);
}
}, undefined);
+ return self.is_loaded;
},
set_value: function(value_) {
value_ = value_ || [];
var self = this;
this.dataset.reset_ids([]);
+ var ids;
if(value_.length >= 1 && value_[0] instanceof Array) {
- var ids = [];
+ ids = [];
_.each(value_, function(command) {
var obj = {values: command[2]};
switch (command[0]) {
this._super(ids);
this.dataset.set_ids(ids);
} else if (value_.length >= 1 && typeof(value_[0]) === "object") {
- var ids = [];
+ ids = [];
this.dataset.delete_all = true;
_.each(value_, function(command) {
var obj = {values: command};
this.viewmanager.views[this.viewmanager.active_view].controller) {
var view = this.viewmanager.views[this.viewmanager.active_view].controller;
if (this.viewmanager.active_view === "form") {
- if (!view.is_initialized.state() === 'resolved') {
+ if (view.is_initialized.state() !== 'resolved') {
return $.when(false);
}
return $.when(view.save());
.invoke('is_valid')
.all(_.identity)
.value();
- break;
case 'list':
return view.is_valid();
}
var form = editor.form;
// If no edition is pending, the listview can not be invalid (?)
if (!editor.record) {
- return true
+ return true;
}
// If the form has not been modified, the view can only be valid
// NB: is_dirty will also be set on defaults/onchanges/whatever?
if ($padding.length) {
$padding.before($newrow);
} else {
- this.$current.append($newrow)
+ this.$current.append($newrow);
}
}
});
},
core: {
onSetInputData: function(e, data) {
- if (data == '') {
+ if (data === '') {
this._plugins.autocomplete._suggestions = null;
}
this.input().val(data);
if (type !== "form")
return;
var self = this;
+ var pop;
if (this.dataset.index === null) {
- var pop = new instance.web.form.SelectCreatePopup(this);
+ pop = new instance.web.form.SelectCreatePopup(this);
pop.select_element(
this.field.relation,
{
});
} else {
var id = self.dataset.ids[self.dataset.index];
- var pop = new instance.web.form.FormOpenPopup(this);
+ pop = new instance.web.form.FormOpenPopup(this);
pop.show_element(self.field.relation, id, self.build_context(), {
title: _t("Open: ") + self.string,
write_function: function(id, data, options) {
self.select_elements(self.selected_ids);
self.destroy();
});
- var $cbutton = self.$buttonpane.find(".oe_selectcreatepopup-search-create");
+ $cbutton = self.$buttonpane.find(".oe_selectcreatepopup-search-create");
$cbutton.click(function() {
self.new_object();
});
this.selection.on("change:value", this, this.on_selection_changed);
this.selection.appendTo(this.$(".oe_form_view_reference_selection"));
this.selection
- .on('focused', null, function () {self.trigger('focused')})
- .on('blurred', null, function () {self.trigger('blurred')});
+ .on('focused', null, function () {self.trigger('focused');})
+ .on('blurred', null, function () {self.trigger('blurred');});
this.m2o = new instance.web.form.FieldMany2One(fm, { attrs: {
name: 'm2o',
this.m2o.on("change:value", this, this.data_changed);
this.m2o.appendTo(this.$(".oe_form_view_reference_m2o"));
this.m2o
- .on('focused', null, function () {self.trigger('focused')})
- .on('blurred', null, function () {self.trigger('blurred')});
+ .on('focused', null, function () {self.trigger('focused');})
+ .on('blurred', null, function () {self.trigger('blurred');});
},
on_selection_changed: function() {
if (this.reference_ready) {
}
},
render_value: function() {
+ var show_value;
if (!this.get("effective_readonly")) {
- var show_value;
if (this.node.attrs.filename) {
show_value = this.view.datarecord[this.node.attrs.filename] || '';
} else {
- show_value = (this.get('value') != null && this.get('value') !== false) ? this.get('value') : '';
+ show_value = (this.get('value') !== null && this.get('value') !== undefined && this.get('value') !== false) ? this.get('value') : '';
}
this.$el.find('input').eq(0).val(show_value);
} else {
this.$el.find('a').toggle(!!this.get('value'));
if (this.get('value')) {
- var show_value = _t("Download")
+ show_value = _t("Download");
if (this.view)
show_value += " " + (this.view.datarecord[this.node.attrs.filename] || '');
this.$el.find('a').text(show_value);
url = this.placeholder;
}
var $img = $(QWeb.render("FieldBinaryImage-img", { widget: this, url: url }));
+ $($img).click(function(e) {
+ if(self.view.get("actual_mode") == "view") {
+ var $button = $(".oe_form_button_edit");
+ $button.openerpBounce();
+ e.stopPropagation();
+ }
+ });
this.$el.find('> img').remove();
this.$el.prepend($img);
$img.load(function() {
values.push(result.id);
this.set({'value': values});
}
- this.render_value()
+ this.render_value();
},
on_file_delete: function (event) {
event.stopPropagation();
this.options.clickable = this.options.clickable || (this.node.attrs || {}).clickable || false;
this.options.visible = this.options.visible || (this.node.attrs || {}).statusbar_visible || false;
this.set({value: false});
- this.selection = [];
- this.set("selection", []);
+ this.selection = {'unfolded': [], 'folded': []};
+ this.set("selection", {'unfolded': [], 'folded': []});
this.selection_dm = new instance.web.DropMisordered();
+ this.dataset = new instance.web.DataSetStatic(this, this.field.relation, this.build_context());
},
start: function() {
this.field_manager.on("view_content_has_changed", this, this.calc_domain);
this.calc_domain();
- this.on("change:value", this, this.get_selection);
this.on("change:evaluated_selection_domain", this, this.get_selection);
this.on("change:selection", this, function() {
this.selection = this.get("selection");
});
this.get_selection();
if (this.options.clickable) {
- this.$el.on('click','li',this.on_click_stage);
+ this.$el.on('click','li[data-id]',this.on_click_stage);
}
if (this.$el.parent().is('header')) {
this.$el.after('<div class="oe_clear"/>');
},
render_value: function() {
var self = this;
- var content = QWeb.render("FieldStatus.content", {widget: self});
+ var content = QWeb.render("FieldStatus.content", {
+ 'widget': self,
+ 'value_folded': _.find(self.selection.folded, function(i){return i[0] === self.get('value');})
+ });
self.$el.html(content);
},
calc_domain: function() {
var d = instance.web.pyeval.eval('domain', this.build_domain());
var domain = []; //if there is no domain defined, fetch all the records
-
+
if (d.length) {
domain = ['|',['id', '=', this.get('value')]].concat(d);
}
-
+
if (! _.isEqual(domain, this.get("evaluated_selection_domain"))) {
this.set("evaluated_selection_domain", domain);
}
*/
get_selection: function() {
var self = this;
- var selection = [];
+ var selection_unfolded = [];
+ var selection_folded = [];
var calculation = _.bind(function() {
if (this.field.type == "many2one") {
- var domain = [];
- var ds = new instance.web.DataSetSearch(this, this.field.relation,
- self.build_context(), this.get("evaluated_selection_domain"));
- return ds.read_slice(['name'], {}).then(function (records) {
- for(var i = 0; i < records.length; i++) {
- selection.push([records[i].id, records[i].name]);
- }
- });
+ /* :deprecated: fold feature will probably be removed */
+ // return self.get_distant_fields().then(function(fields) {
+ self.distant_fields = {};
+ return new instance.web.DataSetSearch(self, self.field.relation, self.build_context(), self.get("evaluated_selection_domain"))
+ .read_slice(_.union(_.keys(self.distant_fields), ['id']), {}).then(function (records) {
+ var ids = _.pluck(records, 'id');
+ return self.dataset.name_get(ids).then(function (records_name) {
+ _.each(records, function (record) {
+ var name = _.find(records_name, function (val) {return val[0] == record.id;})[1];
+ if (record.fold && record.id != self.get('value')) {
+ selection_folded.push([record.id, name]);
+ } else {
+ selection_unfolded.push([record.id, name]);
+ }
+ });
+ });
+ });
} else {
// For field type selection filter values according to
// statusbar_visible attribute of the field. For example:
for(var i=0; i < select.length; i++) {
var key = select[i][0];
if(key == this.get('value') || !this.options.visible || this.options.visible.indexOf(key) != -1) {
- selection.push(select[i]);
+ selection_unfolded.push(select[i]);
}
}
return $.when();
}
}, this);
this.selection_dm.add(calculation()).then(function () {
+ var selection = {'unfolded': selection_unfolded, 'folded': selection_folded};
if (! _.isEqual(selection, self.get("selection"))) {
self.set("selection", selection);
}
});
},
+ /*
+ * :deprecated: this feature will probably be removed with OpenERP v8
+ */
+ get_distant_fields: function() {
+ var self = this;
+ if (this.distant_fields) {
+ return $.when(this.distant_fields);
+ }
+ return new instance.web.Model(self.field.relation).call("fields_get", [["fold"]]).then(function(fields) {
+ self.distant_fields = fields;
+ return fields;
+ });
+ },
on_click_stage: function (ev) {
var self = this;
var $li = $(ev.currentTarget);
- var val = parseInt($li.data("id"));
+ var val;
+ if (this.field.type == "many2one") {
+ val = parseInt($li.data("id"), 10);
+ }
+ else {
+ val = $li.data("id");
+ }
if (val != self.get('value')) {
this.view.recursive_save().done(function() {
var change = {};
instance.web.form.custom_widgets = new instance.web.Registry({
});
-};
+})();
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: