if (this.embedded_view) {
return $.Deferred().then(this.on_loaded).resolve({fields_view: this.embedded_view});
} else {
- var context = new openerp.base.CompoundContext(this.dataset.context);
+ var context = new openerp.base.CompoundContext(this.dataset.get_context());
if (this.view_manager.action && this.view_manager.action.context) {
context.add(this.view_manager.action.context);
}
toolbar:!!this.flags.sidebar, context: context}, this.on_loaded);
}
},
+ stop: function() {
+ _.each(this.widgets, function(w) {
+ w.stop();
+ });
+ },
on_loaded: function(data) {
var self = this;
this.fields_view = data.fields_view;
on_form_changed: function() {
for (var w in this.widgets) {
w = this.widgets[w];
- w.process_attrs();
+ w.process_modifiers();
w.update_dom();
}
},
var $pager = this.$element.find('#' + this.element_id + '_header div.oe_form_pager');
var index = hide_index ? '-' : this.dataset.index + 1;
$pager.find('span.oe_pager_index').html(index);
- $pager.find('span.oe_pager_count').html(this.dataset.count);
+ $pager.find('span.oe_pager_count').html(this.dataset.ids.length);
},
do_onchange: function(widget, processed) {
processed = processed || [];
this.ready = false;
var onchange = _.trim(widget.node.attrs.on_change);
var call = onchange.match(/^\s?(.*?)\((.*?)\)\s?$/);
- console.log("Onchange triggered for field '%s' -> %s", widget.name, onchange);
if (call) {
var method = call[1], args = [];
+ var context_index = null;
var argument_replacement = {
- 'False' : false,
- 'True' : true,
- 'None' : null
+ 'False' : function() {return false;},
+ 'True' : function() {return true;},
+ 'None' : function() {return null;},
+ 'context': function(i) {
+ context_index = i;
+ var ctx = widget.build_context ? widget.build_context() : {};
+ return ctx;
+ }
}
- _.each(call[2].split(','), function(a) {
+ var parent_fields = null;
+ _.each(call[2].split(','), function(a, i) {
var field = _.trim(a);
if (field in argument_replacement) {
- args.push(argument_replacement[field]);
+ args.push(argument_replacement[field](i));
+ return;
} else if (self.fields[field]) {
- var value = self.fields[field].get_value();
+ var value = self.fields[field].get_on_change_value();
args.push(value == null ? false : value);
+ return;
} else {
- args.push(false);
- self.log("warning : on_change can't find field " + field, onchange);
+ var splitted = field.split('.');
+ if (splitted.length > 1 && _.trim(splitted[0]) === "parent" && self.dataset.parent_view) {
+ if (parent_fields === null) {
+ parent_fields = self.dataset.parent_view.get_fields_values();
+ }
+ var p_val = parent_fields[_.trim(splitted[1])];
+ if (p_val !== undefined) {
+ args.push(p_val == null ? false : p_val);
+ return;
+ }
+ }
}
+ throw "Could not get field with name '" + field +
+ "' for onchange '" + onchange + "'";
});
var ajax = {
url: '/base/dataset/call',
return this.rpc(ajax, {
model: this.dataset.model,
method: method,
- args: [(this.datarecord.id == null ? [] : [this.datarecord.id])].concat(args)
+ args: [(this.datarecord.id == null ? [] : [this.datarecord.id])].concat(args),
+ context_id: context_index === null ? null : context_index + 1
}, function(response) {
self.on_processed_onchange(response, processed);
});
on_processed_onchange: function(response, processed) {
var result = response.result;
if (result.value) {
- console.log(" |-> Onchange Response :", result.value);
for (var f in result.value) {
var field = this.fields[f];
if (field) {
var value = result.value[f];
processed.push(field.name);
if (field.get_value() != value) {
- console.log(" |-> Onchange Action : change '%s' value from '%s' to '%s'", field.name, field.get_value(), value);
field.set_value(value);
+ field.touched = true;
if (_.indexOf(processed, field.name) < 0) {
this.do_onchange(field, processed);
}
}
} else {
- this.log("warning : on_processed_onchange can't find field " + field, result);
+ // this is a common case, the normal behavior should be to ignore it
}
}
this.on_form_changed();
}
- if (result.warning) {
+ if (!_.isEmpty(result.warning)) {
$(QWeb.render("DialogWarning", result.warning)).dialog({
modal: true,
buttons: {
this.dataset.ids.unshift(this.datarecord.id);
this.dataset.index = 0;
}
- this.dataset.count++;
this.do_update_pager();
this.do_update_sidebar();
this.notification.notify("Record created", "The record has been created with id #" + this.datarecord.id);
this.on_attachments_loaded([]);
} else {
// TODO fme: modify this so it doesn't try to load attachments when there is not sidebar
- /*this.rpc('/base/dataset/search_read', {
- model: 'ir.attachment',
- fields: ['name', 'url', 'type'],
- domain: [['res_model', '=', this.dataset.model], ['res_id', '=', this.datarecord.id], ['type', 'in', ['binary', 'url']]],
- context: this.dataset.context
- }, this.on_attachments_loaded);*/
+ /*(new openerp.base.DataSetSearch(
+ this.session, 'ir.attachment', this.dataset.get_context(),
+ [['res_model', '=', this.dataset.model],
+ ['res_id', '=', this.datarecord.id],
+ ['type', 'in', ['binary', 'url']]])).read_slice(
+ ['name', 'url', 'type'], false, false,
+ this.on_attachments_loaded);*/
}
},
on_attachments_loaded: function(attachments) {
get_fields_values: function() {
var values = {};
_.each(this.fields, function(value, key) {
- values[key] = value.get_value();
+ var val = value.get_value();
+ values[key] = val;
});
return values;
}
stack.push(!_(val).contains(field));
break;
default:
- this.log("Unsupported operator in attrs :", op);
+ this.log("Unsupported operator in modifiers :", op);
}
}
return _.all(stack);
init: function(view, node) {
this.view = view;
this.node = node;
- this.attrs = JSON.parse(this.node.attrs.attrs || '{}');
+ this.modifiers = JSON.parse(this.node.attrs.modifiers || '{}');
this.type = this.type || node.tag;
this.element_name = this.element_name || this.type;
this.element_id = [this.view.element_id, this.element_name, this.view.widgets_counter++].join("_");
this.string = this.string || node.attrs.string;
this.help = this.help || node.attrs.help;
- this.invisible = (node.attrs.invisible == '1');
+ this.invisible = this.modifiers['invisible'] === true;
},
start: function() {
this.$element = $('#' + this.element_id);
},
- process_attrs: function() {
+ stop: function() {
+ this.$element.remove();
+ },
+ process_modifiers: function() {
var compute_domain = openerp.base.form.compute_domain;
- for (var a in this.attrs) {
- this[a] = compute_domain(this.attrs[a], this.view.fields);
+ for (var a in this.modifiers) {
+ this[a] = compute_domain(this.modifiers[a], this.view.fields);
}
},
update_dom: function() {
}
},
handle_node: function(node) {
- var type = this.view.fields_view.fields[node.attrs.name] || {};
+ var type = {};
+ if (node.tag == 'field') {
+ type = this.view.fields_view.fields[node.attrs.name] || {};
+ }
var widget = new (this.view.registry.get_any(
[node.attrs.widget, type.type, node.tag])) (this.view, node);
if (node.tag == 'field') {
});
openerp.base.form.WidgetNotebook = openerp.base.form.Widget.extend({
+ template: 'WidgetNotebook',
init: function(view, node) {
this._super(view, node);
- this.template = "WidgetNotebook";
this.pages = [];
for (var i = 0; i < node.children.length; i++) {
var n = node.children[i];
if (n.tag == "page") {
- var page = new openerp.base.form.WidgetFrame(this.view, n);
+ var page = new openerp.base.form.WidgetNotebookPage(this.view, n, this, this.pages.length);
this.pages.push(page);
}
}
}
});
+openerp.base.form.WidgetNotebookPage = openerp.base.form.WidgetFrame.extend({
+ template: 'WidgetNotebookPage',
+ init: function(view, node, notebook, index) {
+ this.notebook = notebook;
+ this.index = index;
+ this.element_name = 'page_' + index;
+ this._super(view, node);
+ this.element_tab_id = this.element_id + '_tab';
+ },
+ start: function() {
+ this._super.apply(this, arguments);
+ this.$element_tab = $('#' + this.element_tab_id);
+ },
+ update_dom: function() {
+ if (this.invisible) {
+ this.notebook.$element.tabs('select', 0);
+ }
+ this.$element_tab.toggle(!this.invisible);
+ this.$element.toggle(!this.invisible);
+ }
+});
+
openerp.base.form.WidgetSeparator = openerp.base.form.Widget.extend({
init: function(view, node) {
this._super(view, node);
this.field = view.fields_view.fields[node.attrs.name] || {};
this.string = node.attrs.string || this.field.string;
this.help = node.attrs.help || this.field.help;
- this.invisible = (this.invisible || this.field.invisible == '1');
- this.nolabel = (this.field.nolabel || node.attrs.nolabel) == '1';
- this.readonly = (this.field.readonly || node.attrs.readonly) == '1';
- this.required = (this.field.required || node.attrs.required) == '1';
+ this.nolabel = (this.field.nolabel || node.attrs.nolabel) === '1';
+ this.readonly = this.modifiers['readonly'] === true;
+ this.required = this.modifiers['required'] === true;
this.invalid = false;
this.touched = false;
},
get_value: function() {
return this.value;
},
+ get_on_change_value: function() {
+ return this.get_value();
+ },
update_dom: function() {
this._super.apply(this, arguments);
this.$element.toggleClass('disabled', this.readonly);
this.invalid = false;
},
focus: function() {
+ },
+ _build_view_fields_values: function() {
+ var a_dataset = this.view.dataset || {};
+ var fields_values = this.view.get_fields_values();
+ var parent_values = a_dataset.parent_view ? a_dataset.parent_view.get_fields_values() : {};
+ fields_values.parent = parent_values;
+ return fields_values;
+ },
+ /**
+ * Builds a new context usable for operations related to fields by merging
+ * the fields'context with the action's context.
+ */
+ build_context: function() {
+ var a_context = this.view.dataset.get_context() || {};
+ var f_context = this.field.context || {};
+ var v_context1 = this.node.attrs.default_get || {};
+ var v_context2 = this.node.attrs.context || {};
+ var v_context = new openerp.base.CompoundContext(v_context1, v_context2);
+ if (v_context1.__ref || v_context2.__ref || true) { //TODO niv: remove || true
+ var fields_values = this._build_view_fields_values();
+ v_context.set_eval_context(fields_values);
+ }
+ var ctx = new openerp.base.CompoundContext(a_context, f_context, v_context);
+ return ctx;
+ },
+ build_domain: function() {
+ var f_domain = this.field.domain || [];
+ var v_domain = this.node.attrs.domain || [];
+ if (!(v_domain instanceof Array) || true) { //TODO niv: remove || true
+ var fields_values = this._build_view_fields_values();
+ v_domain = new openerp.base.CompoundDomain(v_domain).set_eval_context(fields_values);
+ }
+ return new openerp.base.CompoundDomain(f_domain, v_domain);
}
});
if (value === false || value === undefined) {
// As in GTK client, floats default to 0
value = 0;
+ this.touched = true;
}
var show_value = value.toFixed(2);
this.$element.find('input').val(show_value);
}
});
+openerp.base.form.FieldInteger = openerp.base.form.FieldFloat.extend({
+ init: function(view, node) {
+ this._super(view, node);
+ this.validation_regex = /^-?\d+$/;
+ },
+ set_value: function(value) {
+ this._super.apply(this, [value]);
+ if (value === false || value === undefined) {
+ // TODO fme: check if GTK client default integers to 0 (like it does with floats)
+ value = 0;
+ this.touched = true;
+ }
+ var show_value = parseInt(value, 10);
+ this.$element.find('input').val(show_value);
+ },
+ set_value_from_ui: function() {
+ this.value = Number(this.$element.find('input').val());
+ }
+});
+
openerp.base.form.FieldDatetime = openerp.base.form.Field.extend({
init: function(view, node) {
this._super(view, node);
this.template = "FieldDate";
this.jqueryui_object = 'datetimepicker';
+ this.validation_regex = /^\d+-\d+-\d+( \d+:\d+(:\d+)?)?$/;
},
start: function() {
this._super.apply(this, arguments);
this.$element.find('input').change(this.on_ui_change)[this.jqueryui_object]({
dateFormat: 'yy-mm-dd',
- timeFormat: 'hh:mm:ss'
+ timeFormat: 'hh:mm:ss',
+ showOn: 'button',
+ buttonImage: '/base/static/src/img/ui/field_calendar.png',
+ buttonImageOnly: true,
+ constrainInput: false
});
},
set_value: function(value) {
this._super.apply(this, arguments);
- if (value == null || value == false) {
+ if (!value) {
this.$element.find('input').val('');
} else {
this.$element.find('input').unbind('change');
this.value = this.format(this.value);
}
},
+ update_dom: function() {
+ this._super.apply(this, arguments);
+ this.$element.find('input').datepicker(this.readonly ? 'disable' : 'enable');
+ },
validate: function() {
- this.invalid = this.required && !this.$element.find('input')[this.jqueryui_object]('getDate');
+ this.invalid = false;
+ var value = this.$element.find('input').val();
+ if (value === "") {
+ this.invalid = this.required;
+ } else if (this.validation_regex) {
+ this.invalid = !this.validation_regex.test(value);
+ } else {
+ this.invalid = !this.$element.find('input')[this.jqueryui_object]('getDate');
+ }
},
focus: function() {
this.$element.find('input').focus();
init: function(view, node) {
this._super(view, node);
this.jqueryui_object = 'datepicker';
+ this.validation_regex = /^\d+-\d+-\d+$/;
},
parse: openerp.base.parse_date,
format: openerp.base.format_date
if (value === false || value === undefined) {
// As in GTK client, floats default to 0
value = 0;
+ this.touched = true;
}
var show_value = _.sprintf("%02d:%02d", Math.floor(value), Math.round((value % 1) * 60));
this.$element.find('input').val(show_value);
set_value: function(value) {
this._super.apply(this, arguments);
var show_value = Number(value);
- if (show_value === NaN) {
+ if (isNaN(show_value)) {
show_value = 0;
}
this.$element.find('div').progressbar('option', 'value', show_value).find('span').html(show_value + '%');
init: function(view, node) {
this._super(view, node);
this.template = "FieldSelection";
+ this.field_index = _.map(this.field.selection, function(x, index) {
+ return {"ikey": "" + index, "ekey": x[0], "label": x[1]};
+ });
},
start: function() {
+ // Flag indicating whether we're in an event chain containing a change
+ // event on the select, in order to know what to do on keyup[RETURN]:
+ // * If the user presses [RETURN] as part of changing the value of a
+ // selection, we should just let the value change and not let the
+ // event broadcast further (e.g. to validating the current state of
+ // the form in editable list view, which would lead to saving the
+ // current row or switching to the next one)
+ // * If the user presses [RETURN] with a select closed (side-effect:
+ // also if the user opened the select and pressed [RETURN] without
+ // changing the selected value), takes the action as validating the
+ // row
+ var ischanging = false;
this._super.apply(this, arguments);
- this.$element.find('select').change(this.on_ui_change);
+ this.$element.find('select')
+ .change(this.on_ui_change)
+ .change(function () { ischanging = true; })
+ .click(function () { ischanging = false; })
+ .keyup(function (e) {
+ if (e.which !== 13 || !ischanging) { return; }
+ e.stopPropagation();
+ ischanging = false;
+ });
},
set_value: function(value) {
- this._super.apply(this, arguments);
- if (value != null && value !== false) {
- this.$element.find('select').val(value);
- } else {
- this.$element.find('select').val('false');
- }
+ value = value === null ? false : value;
+ value = value instanceof Array ? value[0] : value;
+ this._super(value);
+ var option = _.detect(this.field_index, function(x) {return x.ekey === value;});
+ this.$element.find('select').val(option === undefined ? '' : option.ikey);
},
set_value_from_ui: function() {
- this.value = this.$element.find('select').val();
+ var ikey = this.$element.find('select').val();
+ var option = _.detect(this.field_index, function(x) {return x.ikey === ikey;});
+ this.value = option === undefined ? false : option.ekey;
},
update_dom: function() {
this._super.apply(this, arguments);
this.$element.find('select').attr('disabled', this.readonly);
},
validate: function() {
- this.invalid = this.required && this.$element.find('select').val() === "";
+ var ikey = this.$element.find('select').val();
+ var option = _.detect(this.field_index, function(x) {return x.ikey === ikey;});
+ this.invalid = this.required && (option === undefined || option.ekey === false);
},
focus: function() {
this.$element.find('select').focus();
});
})();
-/**
- * Builds a new context usable for operations related to fields by merging
- * the fields'context with the action's context.
- */
-var build_relation_context = function(relation_field) {
- var a_context = relation_field.view.dataset.context || {};
- var fields_values = relation_field.view.get_fields_values();
- var parent_values = a_context.get_eval_context ? a_context.get_eval_context() || {} : {};
- parent_values = _.clone(parent_values);
- delete parent_values.parent;
- fields_values.parent = parent_values;
- var f_context = new openerp.base.CompoundContext(relation_field.field.context || {}).set_eval_context(fields_values);
- var ctx = new openerp.base.CompoundContext(a_context, f_context);
- return ctx;
-}
-var build_relation_domain = function(relation_field) {
- var a_context = relation_field.view.dataset.context || {};
- var fields_values = relation_field.view.get_fields_values();
- var parent_values = a_context.get_eval_context ? a_context.get_eval_context() || {} : {};
- parent_values = _.clone(parent_values);
- delete parent_values.parent;
- fields_values.parent = parent_values;
- var f_domain = new openerp.base.CompoundDomain(relation_field.field.domain || []).set_eval_context(fields_values);
- return f_domain;
-}
-
openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
init: function(view, node) {
this._super(view, node);
if (!self.value) {
return;
}
- self.session.action_manager.do_action({
- "res_model": self.field.relation,
- "views":[[false,"form"]],
- "res_id": self.value[0],
- "type":"ir.actions.act_window",
- "view_type":"form",
- "view_mode":"form",
- "target":"new",
- "context": build_relation_context(self)
+ var pop = new openerp.base.form.FormOpenPopup(null, self.view.session);
+ pop.show_element(self.field.relation, self.value[0],self.build_context(), {});
+ pop.on_write_completed.add_last(function() {
+ self.set_value(self.value[0]);
});
};
var cmenu = this.$menu_btn.contextMenu(this.cm_id, {'leftClickToo': true,
}
this.$input.focusout(anyoneLoosesFocus);
+ var isSelecting = false;
// autocomplete
this.$input.autocomplete({
source: function(req, resp) { self.get_search_result(req, resp); },
select: function(event, ui) {
+ isSelecting = true;
var item = ui.item;
if (item.id) {
self._change_int_value([item.id, item.name]);
minLength: 0,
delay: 0
});
+ // used to correct a bug when selecting an element by pushing 'enter' in an editable list
+ this.$input.keyup(function(e) {
+ if (e.which === 13) {
+ if (isSelecting)
+ e.stopPropagation();
+ }
+ isSelecting = false;
+ });
},
// autocomplete component content handling
get_search_result: function(request, response) {
var search_val = request.term;
var self = this;
- var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, build_relation_context(self));
+ var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, self.build_context());
- dataset.name_search(search_val, build_relation_domain(self), 'ilike',
+ dataset.name_search(search_val, self.build_domain(), 'ilike',
this.limit + 1, function(data) {
self.last_search = data.result;
// possible selections for the m2o
if (values.length > self.limit) {
values = values.slice(0, self.limit);
values.push({label: "<em> Search More...</em>", action: function() {
- dataset.name_search(search_val, build_relation_domain(self), 'ilike'
+ dataset.name_search(search_val, self.build_domain(), 'ilike'
, false, function(data) {
self._change_int_value(null);
self._search_create_popup("search", data.result);
// create...
values.push({label: "<em> Create and Edit...</em>", action: function() {
self._change_int_value(null);
- self._search_create_popup("form");
+ self._search_create_popup("form", undefined, {"default_name": search_val});
}});
response(values);
},
_quick_create: function(name) {
var self = this;
- var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, build_relation_context(self));
+ var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, self.build_context());
dataset.name_create(name, function(data) {
self._change_int_ext_value(data.result);
- }).fail(function() {
+ }).fail(function(error, event) {
+ event.preventDefault();
self._change_int_value(null);
self._search_create_popup("form", undefined, {"default_name": name});
});
initial_ids: ids ? _.map(ids, function(x) {return x[0]}) : undefined,
initial_view: view,
disable_multiple_selection: true
- }, build_relation_domain(self),
- new openerp.base.CompoundContext(build_relation_context(self), context || {}));
+ }, self.build_domain(),
+ new openerp.base.CompoundContext(self.build_context(), context || {}));
pop.on_select_elements.add(function(element_ids) {
- var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, build_relation_context(self));
+ var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, self.build_context());
dataset.name_get([element_ids[0]], function(data) {
self._change_int_ext_value(data.result[0]);
pop.stop();
self._change_int_ext_value(rval);
};
if(typeof(value) === "number") {
- var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, build_relation_context(self));
+ var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, self.build_context());
dataset.name_get([value], function(data) {
real_set_value(data.result[0]);
}).fail(function() {self.tmp_value = undefined;});
return [commands.LINK_TO, id, false];
},
// (5[, _[, _]])
- FORGET_ALL: 5,
- 'forget_all': function () {
+ DELETE_ALL: 5,
+ 'delete_all': function () {
return [5, false, false];
},
// (6, _, ids) replaces all linked records with provided ids
}
};
openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
+ multi_selection: false,
init: function(view, node) {
this._super(view, node);
this.template = "FieldOne2Many";
var self = this;
- this.dataset = new openerp.base.BufferedDataSet(this.session, this.field.relation);
+ this.dataset = new openerp.base.form.One2ManyDataSet(this.session, this.field.relation);
+ this.dataset.o2m = this;
+ this.dataset.parent_view = this.view;
this.dataset.on_change.add_last(function() {
self.on_ui_change();
});
}
if(view.view_type === "list") {
view.options = {
+ 'selectable': self.multi_selection
};
}
views.push(view);
}
self.is_started.resolve();
});
- this.viewmanager.start();
+ setTimeout(function () {
+ self.viewmanager.start();
+ }, 0);
},
reload_current_view: function() {
var self = this;
set_value: function(value) {
value = value || [];
var self = this;
+ this.dataset.reset_ids([]);
if(value.length >= 1 && value[0] instanceof Array) {
var ids = [];
_.each(value, function(command) {
case commands.LINK_TO:
ids.push(command[1]);
return;
+ case commands.DELETE_ALL:
+ self.dataset.delete_all = true;
+ return;
}
});
this._super(ids);
this.dataset.set_ids(ids);
+ } else if (value.length >= 1 && typeof(value[0]) === "object") {
+ var ids = [];
+ this.dataset.delete_all = true;
+ _.each(value, function(command) {
+ var obj = {values: command};
+ obj['id'] = _.uniqueId(self.dataset.virtual_id_prefix);
+ self.dataset.to_create.push(obj);
+ self.dataset.cache.push(_.clone(obj));
+ ids.push(obj.id);
+ });
+ this._super(ids);
+ this.dataset.set_ids(ids);
} else {
this._super(value);
this.dataset.reset_ids(value);
},
get_value: function() {
var self = this;
- var val = _.map(this.dataset.ids, function(id) {
+ if (!this.dataset)
+ return [];
+ var val = this.dataset.delete_all ? [commands.delete_all()] : [];
+ val = val.concat(_.map(this.dataset.ids, function(id) {
var alter_order = _.detect(self.dataset.to_create, function(x) {return x.id === id;});
if (alter_order) {
return commands.create(alter_order.values);
return commands.update(alter_order.id, alter_order.values);
}
return commands.link_to(id);
- });
+ }));
return val.concat(_.map(
this.dataset.to_delete, function(x) {
return commands['delete'](x.id);}));
}
});
+openerp.base.form.One2ManyDataSet = openerp.base.BufferedDataSet.extend({
+ get_context: function() {
+ this.context = this.o2m.build_context();
+ return this.context;
+ }
+});
+
openerp.base.form.One2ManyListView = openerp.base.ListView.extend({
do_add_record: function () {
- var self = this;
- var pop = new openerp.base.form.SelectCreatePopup(null, self.o2m.view.session);
- pop.select_element(self.o2m.field.relation,{
- initial_view: "form",
- alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
- auto_create: false
- });
- pop.on_create.add(function(data) {
- self.o2m.dataset.create(data, function(r) {
- self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r.result]));
- pop.stop();
- self.o2m.reload_current_view();
+ if (this.options.editable) {
+ this._super.apply(this, arguments);
+ } else {
+ var self = this;
+ var pop = new openerp.base.form.SelectCreatePopup(null, self.o2m.view.session);
+ pop.select_element(self.o2m.field.relation,{
+ initial_view: "form",
+ alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
+ auto_create: false,
+ parent_view: self.o2m.view
+ }, self.o2m.build_domain(), self.o2m.build_context());
+ pop.on_create.add(function(data) {
+ self.o2m.dataset.create(data, function(r) {
+ self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r.result]));
+ self.o2m.dataset.on_change();
+ pop.stop();
+ self.o2m.reload_current_view();
+ });
});
- });
+ }
}
});
openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
+ multi_selection: false,
init: function(view, node) {
this._super(view, node);
this.template = "FieldMany2Many";
var self = this;
- this.dataset = new openerp.base.DataSetStatic(
+ this.dataset = new openerp.base.form.Many2ManyDataSet(
this.session, this.field.relation);
+ this.dataset.m2m = this;
this.dataset.on_unlink.add_last(function(ids) {
- //TODO niv: should check this for other cases
self.on_ui_change();
});
this.list_view = new openerp.base.form.Many2ManyListView(
null, this.view.session, this.list_id, this.dataset, false, {
- 'addable': 'Add'
+ 'addable': 'Add',
+ 'selectable': self.multi_selection
});
this.list_view.m2m_field = this;
this.list_view.on_loaded.add_last(function() {
self.is_started.resolve();
});
- this.list_view.start();
+ setTimeout(function () {
+ self.list_view.start();
+ }, 0);
},
set_value: function(value) {
value = value || [];
},
get_value: function() {
return [commands.replace_with(this.dataset.ids)];
+ },
+ set_value_from_ui: function() {},
+ validate: function() {
+ this.invalid = false;
+ // TODO niv
+ }
+});
+
+openerp.base.form.Many2ManyDataSet = openerp.base.DataSetStatic.extend({
+ get_context: function() {
+ this.context = this.m2m.build_context();
+ return this.context;
}
});
do_add_record: function () {
var pop = new openerp.base.form.SelectCreatePopup(
null, this.m2m_field.view.session);
- pop.select_element(this.model);
+ pop.select_element(this.model, {},
+ new openerp.base.CompoundDomain(this.m2m_field.build_domain(), ["!", ["id", "in", this.m2m_field.dataset.ids]]),
+ this.m2m_field.build_context());
var self = this;
pop.on_select_elements.add(function(element_ids) {
_.each(element_ids, function(element_id) {
if(! _.detect(self.dataset.ids, function(x) {return x == element_id;})) {
self.dataset.set_ids([].concat(self.dataset.ids, [element_id]));
+ self.m2m_field.on_ui_change();
self.reload_content();
}
});
do_activate_record: function(index, id) {
this.m2m_field.view.session.action_manager.do_action({
"res_model": this.dataset.model,
- "views":[[false,"form"]],
+ "views": [[false,"form"]],
"res_id": id,
- "type":"ir.actions.act_window",
- "view_type":"form",
- "view_mode":"form",
- "target":"new"
+ "type": "ir.actions.act_window",
+ "view_type": "form",
+ "view_mode": "form",
+ "target": "new",
+ "context": this.m2m_field.build_context()
});
}
});
* - disable_multiple_selection
* - alternative_form_view
* - auto_create (default true)
+ * - parent_view
*/
select_element: function(model, options, domain, context) {
this.model = model;
this.initial_ids = this.options.initial_ids;
jQuery(this.render()).dialog({title: '',
modal: true,
- minWidth: 800});
+ width: 960,
+ height: 600});
this.start();
},
start: function() {
this._super();
this.dataset = new openerp.base.ReadOnlyDataSetSearch(this.session, this.model,
- this.context, this.domain);
+ this.context);
+ this.dataset.parent_view = this.options.parent_view;
if (this.options.initial_view == "search") {
this.setup_search_view();
} else { // "form"
});
this.searchview.on_search.add(function(domains, contexts, groupbys) {
if (self.initial_ids) {
- self.view_list.do_search.call(self, domains.concat([[["id", "in", self.initial_ids]]]),
+ self.view_list.do_search.call(self, domains.concat([[["id", "in", self.initial_ids]], self.domain]),
contexts, groupbys);
self.initial_ids = undefined;
} else {
- self.view_list.do_search.call(self, domains, contexts, groupbys);
+ self.view_list.do_search.call(self, domains.concat([self.domain]), contexts, groupbys);
}
});
this.searchview.on_loaded.add_last(function () {
return;
var self = this;
var wdataset = new openerp.base.DataSetSearch(this.session, this.model, this.context, this.domain);
+ wdataset.parent_view = this.options.parent_view;
wdataset.create(data, function(r) {
self.on_select_elements([r.result]);
});
}
});
+openerp.base.form.FormOpenPopup = openerp.base.BaseWidget.extend({
+ identifier_prefix: "formopenpopup",
+ template: "FormOpenPopup",
+ /**
+ * options:
+ * - alternative_form_view
+ * - auto_write (default true)
+ * - parent_view
+ */
+ 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});
+ jQuery(this.render()).dialog({title: '',
+ modal: true,
+ width: 960,
+ height: 600});
+ this.start();
+ },
+ start: function() {
+ this._super();
+ this.dataset = new openerp.base.ReadOnlyDataSetSearch(this.session, this.model,
+ this.context);
+ this.dataset.ids = [this.row_id];
+ this.dataset.index = 0;
+ this.dataset.parent_view = this.options.parent_view;
+ this.setup_form_view();
+ },
+ on_write: function(id, data) {
+ if (!this.options.auto_write)
+ return;
+ var self = this;
+ var wdataset = new openerp.base.DataSetSearch(this.session, this.model, this.context, this.domain);
+ wdataset.parent_view = this.options.parent_view;
+ wdataset.write(id, data, function(r) {
+ self.stop();
+ self.on_write_completed();
+ });
+ },
+ on_write_completed: function() {},
+ setup_form_view: function() {
+ var self = this;
+ this.view_form = new openerp.base.FormView(null, this.session,
+ this.element_id + "_view_form", this.dataset, false);
+ if (this.options.alternative_form_view) {
+ this.view_form.set_embedded_view(this.options.alternative_form_view);
+ }
+ this.view_form.start();
+ 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();
+ });
+ var $cbutton = $buttons.find(".oe_formopenpopup-form-close");
+ $cbutton.click(function() {
+ self.stop();
+ });
+ self.view_form.do_show();
+ });
+ this.dataset.on_write.add(this.on_write);
+ }
+});
+
openerp.base.form.FieldReference = openerp.base.form.Field.extend({
init: function(view, node) {
this._super(view, node);
'reference' : 'openerp.base.form.FieldReference',
'boolean' : 'openerp.base.form.FieldBoolean',
'float' : 'openerp.base.form.FieldFloat',
- 'integer': 'openerp.base.form.FieldFloat',
+ 'integer': 'openerp.base.form.FieldInteger',
'progressbar': 'openerp.base.form.FieldProgressBar',
'float_time': 'openerp.base.form.FieldFloatTime',
'image': 'openerp.base.form.FieldBinaryImage',