@@ -383,11 +383,6 @@ class DataSet(openerpweb.Controller):
|
||||
reads = Model.read(ids, fields or False, context)
|
||||
reads.sort(key=lambda obj: ids.index(obj['id']))
|
||||
return reads
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def read(self, request, model, ids, fields=False):
|
||||
return self.do_search_read(request, model, ids, fields,
|
||||
request.session.eval_context(request.context))
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def get(self, request, model, ids, fields=False):
|
||||
|
||||
@@ -474,9 +474,10 @@ background: linear-gradient(top, #ffffff 0%,#d8d8d8 11%,#afafaf 86%,#333333 91%,
|
||||
background: #AAAAAA;
|
||||
}
|
||||
.openerp .filter_icon {
|
||||
height: 22px;
|
||||
padding: 1px 2px 0 2px;
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
margin: 0;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
.openerp .filter_label {
|
||||
font-weight: bold;
|
||||
@@ -537,14 +538,6 @@ background: linear-gradient(top, #ffffff 0%,#d8d8d8 11%,#afafaf 86%,#333333 91%,
|
||||
.openerp .searchview_group_content {
|
||||
padding-left: 10px;
|
||||
}
|
||||
.openerp .searchview_group_content .oe-searchview-render-line {
|
||||
width:0;
|
||||
}
|
||||
|
||||
|
||||
.openerp .oe-searchview-render-line {
|
||||
width:100%;
|
||||
}
|
||||
|
||||
.openerp .searchview_extended_group {
|
||||
padding: 3px;
|
||||
@@ -1055,6 +1048,7 @@ background: linear-gradient(top, #ffffff 0%,#ebe9e9 100%); /* W3C */
|
||||
.openerp .oe-m2o-drop-down-button img,
|
||||
.openerp .oe-m2o-cm-button img {
|
||||
margin-bottom: -4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.openerp .oe-m2o-disabled-cm {
|
||||
color: grey;
|
||||
|
||||
@@ -137,6 +137,29 @@ openerp.base.Registry = Class.extend( /** @lends openerp.base.Registry# */ {
|
||||
}
|
||||
return object_match;
|
||||
},
|
||||
/**
|
||||
* Tries a number of keys, and returns the first object matching one of
|
||||
* the keys.
|
||||
*
|
||||
* @param {Array} keys a sequence of keys to fetch the object for
|
||||
* @returns {Class} the first class found matching an object
|
||||
*
|
||||
* @throws {openerp.base.KeyNotFound} if none of the keys was in the mapping
|
||||
* @trows {openerp.base.ObjectNotFound} if a found object path was invalid
|
||||
*/
|
||||
get_any: function (keys) {
|
||||
for (var i=0; i<keys.length; ++i) {
|
||||
try {
|
||||
return this.get_object(keys[i]);
|
||||
} catch (e) {
|
||||
if (e instanceof openerp.base.KeyNotFound) {
|
||||
continue;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
throw new openerp.base.KeyNotFound(keys.join(','));
|
||||
},
|
||||
/**
|
||||
* Adds a new key and value to the registry.
|
||||
*
|
||||
|
||||
@@ -235,7 +235,7 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
|
||||
this._super(session);
|
||||
this.model = model;
|
||||
this.context = context || {};
|
||||
this.index = 0;
|
||||
this.index = null;
|
||||
this.count = 0;
|
||||
},
|
||||
start: function() {
|
||||
@@ -357,6 +357,8 @@ openerp.base.DataSetStatic = openerp.base.DataSet.extend({
|
||||
this.count = this.ids.length;
|
||||
},
|
||||
read_slice: function (fields, offset, limit, callback) {
|
||||
var self = this;
|
||||
offset = offset || 0;
|
||||
var end_pos = limit && limit !== -1 ? offset + limit : undefined;
|
||||
this.read_ids(this.ids.slice(offset, end_pos), fields, callback);
|
||||
},
|
||||
@@ -456,6 +458,135 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({
|
||||
}
|
||||
});
|
||||
|
||||
openerp.base.BufferedDataSet = openerp.base.DataSetStatic.extend({
|
||||
virtual_id_prefix: "one2many_v_id_",
|
||||
virtual_id_regex: /one2many_v_id_.*/,
|
||||
debug_mode: true,
|
||||
init: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.reset_ids([]);
|
||||
},
|
||||
create: function(data, callback, error_callback) {
|
||||
var cached = {id:_.uniqueId(this.virtual_id_prefix), values: data};
|
||||
this.to_create.push(cached);
|
||||
this.cache.push(cached);
|
||||
this.on_change();
|
||||
var to_return = $.Deferred().then(callback);
|
||||
setTimeout(function() {to_return.resolve({result: cached.id});}, 0);
|
||||
return to_return.promise();
|
||||
},
|
||||
write: function (id, data, callback) {
|
||||
var self = this;
|
||||
var record = _.detect(this.to_create, function(x) {return x.id === id;});
|
||||
record = record || _.detect(this.to_write, function(x) {return x.id === id;});
|
||||
if (record) {
|
||||
$.extend(record.values, data);
|
||||
} else {
|
||||
record = {id: id, values: data};
|
||||
self.to_write.push(record);
|
||||
}
|
||||
var cached = _.detect(this.cache, function(x) {return x.id === id;});
|
||||
$.extend(cached.values, record.values);
|
||||
this.on_change();
|
||||
var to_return = $.Deferred().then(callback);
|
||||
setTimeout(function () {to_return.resolve({result: true});}, 0);
|
||||
return to_return.promise();
|
||||
},
|
||||
unlink: function(ids, callback, error_callback) {
|
||||
var self = this;
|
||||
_.each(ids, function(id) {
|
||||
if (! _.detect(self.to_create, function(x) { return x.id === id; })) {
|
||||
self.to_delete.push({id: id})
|
||||
}
|
||||
});
|
||||
this.to_create = _.reject(this.to_create, function(x) { return _.include(ids, x.id);});
|
||||
this.to_write = _.reject(this.to_write, function(x) { return _.include(ids, x.id);});
|
||||
this.cache = _.reject(this.cache, function(x) { return _.include(ids, x.id);});
|
||||
this.set_ids(_.without.apply(_, [this.ids].concat(ids)));
|
||||
this.on_change();
|
||||
var to_return = $.Deferred().then(callback);
|
||||
setTimeout(function () {to_return.resolve({result: true});}, 0);
|
||||
return to_return.promise();
|
||||
},
|
||||
reset_ids: function(ids) {
|
||||
this.set_ids(ids);
|
||||
this.to_delete = [];
|
||||
this.to_create = [];
|
||||
this.to_write = [];
|
||||
this.cache = [];
|
||||
},
|
||||
on_change: function() {},
|
||||
read_ids: function (ids, fields, callback) {
|
||||
var self = this;
|
||||
var to_get = [];
|
||||
_.each(ids, function(id) {
|
||||
var cached = _.detect(self.cache, function(x) {return x.id === id;});
|
||||
var created = _.detect(self.to_create, function(x) {return x.id === id;});
|
||||
if (created) {
|
||||
_.each(fields, function(x) {if (cached.values[x] === undefined) cached.values[x] = false;});
|
||||
} else {
|
||||
if (!cached || !_.all(fields, function(x) {return cached.values[x] !== undefined}))
|
||||
to_get.push(id);
|
||||
}
|
||||
});
|
||||
var completion = $.Deferred().then(callback);
|
||||
var return_records = function() {
|
||||
var records = _.map(ids, function(id) {
|
||||
return _.extend({}, _.detect(self.cache, function(c) {return c.id === id;}).values, {"id": id});
|
||||
});
|
||||
if (self.debug_mode) {
|
||||
if (_.include(records, undefined)) {
|
||||
throw "Record not correctly loaded";
|
||||
}
|
||||
}
|
||||
setTimeout(function () {completion.resolve(records);}, 0);
|
||||
}
|
||||
if(to_get.length > 0) {
|
||||
var rpc_promise = this._super(to_get, fields, function(records) {
|
||||
_.each(records, function(record, index) {
|
||||
var id = to_get[index];
|
||||
var cached = _.detect(self.cache, function(x) {return x.id === id;});
|
||||
if (!cached) {
|
||||
self.cache.push({id: id, values: record});
|
||||
} else {
|
||||
// I assume cache value is prioritary
|
||||
_.defaults(cached.values, record);
|
||||
}
|
||||
});
|
||||
return_records();
|
||||
});
|
||||
$.when(rpc_promise).fail(function() {completion.reject();});
|
||||
} else {
|
||||
return_records();
|
||||
}
|
||||
return completion.promise();
|
||||
},
|
||||
});
|
||||
|
||||
openerp.base.ReadOnlyDataSetSearch = openerp.base.DataSetSearch.extend({
|
||||
create: function(data, callback, error_callback) {
|
||||
this.on_create(data);
|
||||
var to_return = $.Deferred().then(callback);
|
||||
setTimeout(function () {to_return.resolve({"result": undefined});}, 0);
|
||||
return to_return.promise();
|
||||
},
|
||||
on_create: function(data) {},
|
||||
write: function (id, data, callback) {
|
||||
this.on_write(id);
|
||||
var to_return = $.Deferred().then(callback);
|
||||
setTimeout(function () {to_return.resolve({"result": true});}, 0);
|
||||
return to_return.promise();
|
||||
},
|
||||
on_write: function(id) {},
|
||||
unlink: function(ids, callback, error_callback) {
|
||||
this.on_unlink(ids);
|
||||
var to_return = $.Deferred().then(callback);
|
||||
setTimeout(function () {to_return.resolve({"result": true});}, 0);
|
||||
return to_return.promise();
|
||||
},
|
||||
on_unlink: function(ids) {}
|
||||
});
|
||||
|
||||
openerp.base.CompoundContext = function() {
|
||||
this.__ref = "compound_context";
|
||||
this.__contexts = [];
|
||||
|
||||
@@ -36,6 +36,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
|
||||
this.default_focus_button = null;
|
||||
this.registry = openerp.base.form.widgets;
|
||||
this.has_been_loaded = $.Deferred();
|
||||
this.$form_header = null;
|
||||
},
|
||||
start: function() {
|
||||
//this.log('Starting FormView '+this.model+this.view_id)
|
||||
@@ -59,76 +60,80 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
|
||||
_.each(this.widgets, function(w) {
|
||||
w.start();
|
||||
});
|
||||
this.$element.find('div.oe_form_pager button[data-pager-action]').click(function() {
|
||||
this.$form_header = this.$element.find('#' + this.element_id + '_header');
|
||||
this.$form_header.find('div.oe_form_pager button[data-pager-action]').click(function() {
|
||||
var action = $(this).data('pager-action');
|
||||
self.on_pager_action(action);
|
||||
});
|
||||
|
||||
this.$element.find('#' + this.element_id + '_header button.oe_form_button_save').click(this.do_save);
|
||||
this.$element.find('#' + this.element_id + '_header button.oe_form_button_save_edit').click(this.do_save_edit);
|
||||
this.$element.find('#' + this.element_id + '_header button.oe_form_button_cancel').click(this.do_cancel);
|
||||
this.$element.find('#' + this.element_id + '_header button.oe_form_button_new').click(this.on_button_new);
|
||||
this.$form_header.find('button.oe_form_button_save').click(this.do_save);
|
||||
this.$form_header.find('button.oe_form_button_save_edit').click(this.do_save_edit);
|
||||
this.$form_header.find('button.oe_form_button_cancel').click(this.do_cancel);
|
||||
this.$form_header.find('button.oe_form_button_new').click(this.on_button_new);
|
||||
|
||||
this.view_manager.sidebar.set_toolbar(data.fields_view.toolbar);
|
||||
this.has_been_loaded.resolve();
|
||||
},
|
||||
do_show: function () {
|
||||
var self = this;
|
||||
self.$element.show();
|
||||
if (this.dataset.index === null || (this.dataset.index === 0 && this.dataset.ids.length == 0)) {
|
||||
if (this.dataset.index === null) {
|
||||
// null index means we should start a new record
|
||||
// 0 index with empty ids means we called the form with empty dataset (wizards, switched to form from empty list, ...)
|
||||
this.on_button_new();
|
||||
} else {
|
||||
this.dataset.read_index(_.keys(this.fields_view.fields), this.on_record_loaded);
|
||||
}
|
||||
self.$element.show();
|
||||
this.view_manager.sidebar.do_refresh(true);
|
||||
},
|
||||
do_hide: function () {
|
||||
this.$element.hide();
|
||||
},
|
||||
on_record_loaded: function(record) {
|
||||
if (!record) {
|
||||
throw("Form: No record received");
|
||||
}
|
||||
if (!record.id) {
|
||||
this.$form_header.find('.oe_form_on_create').show();
|
||||
this.$form_header.find('.oe_form_on_update').hide();
|
||||
this.$form_header.find('button.oe_form_button_new').hide();
|
||||
} else {
|
||||
this.$form_header.find('.oe_form_on_create').hide();
|
||||
this.$form_header.find('.oe_form_on_update').show();
|
||||
this.$form_header.find('button.oe_form_button_new').show();
|
||||
}
|
||||
this.touched = false;
|
||||
if (record) {
|
||||
this.datarecord = record;
|
||||
for (var f in this.fields) {
|
||||
this.datarecord = record;
|
||||
for (var f in this.fields) {
|
||||
var field = this.fields[f];
|
||||
field.touched = false;
|
||||
field.set_value(this.datarecord[f] || false);
|
||||
field.validate();
|
||||
}
|
||||
if (!record.id) {
|
||||
// New record: Second pass in order to trigger the onchanges
|
||||
this.touched = true;
|
||||
this.show_invalid = false;
|
||||
for (var f in record) {
|
||||
var field = this.fields[f];
|
||||
field.touched = false;
|
||||
field.set_value(this.datarecord[f] || false);
|
||||
field.validate();
|
||||
}
|
||||
if (!record.id) {
|
||||
// New record: Second pass in order to trigger the onchanges
|
||||
this.touched = true;
|
||||
this.show_invalid = false;
|
||||
for (var f in record) {
|
||||
var field = this.fields[f];
|
||||
if (field) {
|
||||
field.touched = true;
|
||||
this.on_form_changed(field);
|
||||
}
|
||||
if (field) {
|
||||
field.touched = true;
|
||||
this.do_onchange(field);
|
||||
}
|
||||
}
|
||||
this.on_form_changed();
|
||||
this.show_invalid = this.ready = true;
|
||||
} else {
|
||||
this.log("No record received");
|
||||
}
|
||||
this.on_form_changed();
|
||||
this.show_invalid = this.ready = true;
|
||||
this.do_update_pager(record.id == null);
|
||||
this.do_update_sidebar();
|
||||
if (this.default_focus_field) {
|
||||
this.default_focus_field.focus();
|
||||
}
|
||||
},
|
||||
on_form_changed: function(widget) {
|
||||
if (widget && widget.node.attrs.on_change) {
|
||||
this.do_onchange(widget);
|
||||
} else {
|
||||
for (var w in this.widgets) {
|
||||
w = this.widgets[w];
|
||||
w.process_attrs();
|
||||
w.update_dom();
|
||||
}
|
||||
on_form_changed: function() {
|
||||
for (var w in this.widgets) {
|
||||
w = this.widgets[w];
|
||||
w.process_attrs();
|
||||
w.update_dom();
|
||||
}
|
||||
},
|
||||
on_pager_action: function(action) {
|
||||
@@ -161,6 +166,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
|
||||
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 argument_replacement = {
|
||||
@@ -199,12 +205,14 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
|
||||
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);
|
||||
if (_.indexOf(processed, field.name) < 0) {
|
||||
this.do_onchange(field, processed);
|
||||
@@ -369,12 +377,13 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
|
||||
if (!this.datarecord.id) {
|
||||
this.on_attachments_loaded([]);
|
||||
} else {
|
||||
this.rpc('/base/dataset/search_read', {
|
||||
// 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);
|
||||
}, this.on_attachments_loaded);*/
|
||||
}
|
||||
},
|
||||
on_attachments_loaded: function(attachments) {
|
||||
@@ -439,7 +448,7 @@ openerp.base.form.compute_domain = function(expr, fields) {
|
||||
}
|
||||
}
|
||||
|
||||
var field = fields[ex[0]].value;
|
||||
var field = fields[ex[0]].get_value ? fields[ex[0]].get_value() : fields[ex[0]].value;
|
||||
var op = ex[1];
|
||||
var val = ex[2];
|
||||
|
||||
@@ -559,8 +568,8 @@ openerp.base.form.WidgetFrame = openerp.base.form.Widget.extend({
|
||||
},
|
||||
handle_node: function(node) {
|
||||
var type = this.view.fields_view.fields[node.attrs.name] || {};
|
||||
var widget_type = node.attrs.widget || type.type || node.tag;
|
||||
var widget = new (this.view.registry.get_object(widget_type)) (this.view, node);
|
||||
var widget = new (this.view.registry.get_any(
|
||||
[node.attrs.widget, type.type, node.tag])) (this.view, node);
|
||||
if (node.tag == 'field') {
|
||||
if (!this.view.default_focus_field || node.attrs.default_focus == '1') {
|
||||
this.view.default_focus_field = widget;
|
||||
@@ -727,7 +736,8 @@ openerp.base.form.Field = openerp.base.form.Widget.extend({
|
||||
this.validate();
|
||||
if (!this.invalid) {
|
||||
this.set_value_from_ui();
|
||||
this.view.on_form_changed(this);
|
||||
this.view.do_onchange(this);
|
||||
this.view.on_form_changed();
|
||||
} else {
|
||||
this.update_dom();
|
||||
}
|
||||
@@ -866,7 +876,7 @@ openerp.base.form.FieldDatetime = openerp.base.form.Field.extend({
|
||||
}
|
||||
},
|
||||
validate: function() {
|
||||
this.invalid = this.required && this.$element.find('input')[this.jqueryui_object]('getDate') === '';
|
||||
this.invalid = this.required && !this.$element.find('input')[this.jqueryui_object]('getDate');
|
||||
},
|
||||
focus: function() {
|
||||
this.$element.find('input').focus();
|
||||
@@ -1083,6 +1093,7 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||
this.value = null;
|
||||
this.cm_id = _.uniqueId('m2o_cm_');
|
||||
this.last_search = [];
|
||||
this.tmp_value = undefined;
|
||||
},
|
||||
start: function() {
|
||||
this._super();
|
||||
@@ -1248,7 +1259,7 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||
}, self.view.domain || [],
|
||||
new openerp.base.CompoundContext(build_relation_context(self)).add(context || {}));
|
||||
pop.on_select_elements.add(function(element_ids) {
|
||||
dataset.call("name_get", [element_ids[0]], function(data) {
|
||||
dataset.call("name_get", [[element_ids[0]]], function(data) {
|
||||
self._change_int_ext_value(data.result[0]);
|
||||
pop.stop();
|
||||
});
|
||||
@@ -1268,11 +1279,32 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||
},
|
||||
set_value_from_ui: function() {},
|
||||
set_value: function(value) {
|
||||
this._super(value);
|
||||
this.original_value = value;
|
||||
this._change_int_ext_value(value);
|
||||
value = value || null;
|
||||
var self = this;
|
||||
var _super = this._super;
|
||||
this.tmp_value = value;
|
||||
var real_set_value = function(rval) {
|
||||
self.tmp_value = undefined;
|
||||
_super.apply(self, rval);
|
||||
self.original_value = rval;
|
||||
self._change_int_ext_value(rval);
|
||||
};
|
||||
if(typeof(value) === "number") {
|
||||
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, []);
|
||||
dataset.call("name_get", [[value]], function(data) {
|
||||
real_set_value(data.result[0]);
|
||||
}).fail(function() {self.tmp_value = undefined;});
|
||||
} else {
|
||||
setTimeout(function() {real_set_value(value);}, 0);
|
||||
}
|
||||
},
|
||||
get_value: function() {
|
||||
if (this.tmp_value !== undefined) {
|
||||
if (this.tmp_value instanceof Array) {
|
||||
return this.tmp_value[0];
|
||||
}
|
||||
return this.tmp_value === null ? false : this.tmp_value;
|
||||
}
|
||||
if (this.value === undefined)
|
||||
throw "theorically unreachable state";
|
||||
return this.value ? this.value[0] : false;
|
||||
@@ -1285,23 +1317,29 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
# Values: (0, 0, { fields }) create
|
||||
# (1, ID, { fields }) update
|
||||
# (2, ID) remove (delete)
|
||||
# (3, ID) unlink one (target id or target of relation)
|
||||
# (4, ID) link
|
||||
# (5) unlink all (only valid for one2many)
|
||||
*/
|
||||
|
||||
openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
||||
init: function(view, node) {
|
||||
this._super(view, node);
|
||||
this.template = "FieldOne2Many";
|
||||
this.is_started = $.Deferred();
|
||||
this.is_setted = $.Deferred();
|
||||
},
|
||||
start: function() {
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
var self = this;
|
||||
|
||||
this.dataset = new openerp.base.DataSetStatic(this.session, this.field.relation);
|
||||
this.dataset.on_unlink.add_last(function(ids) {
|
||||
self.dataset.set_ids(_.without.apply(_, [self.dataset.ids].concat(ids)));
|
||||
this.dataset = new openerp.base.BufferedDataSet(this.session, this.field.relation);
|
||||
this.dataset.on_change.add_last(function() {
|
||||
self.on_ui_change();
|
||||
self.reload_current_view();
|
||||
});
|
||||
|
||||
var modes = this.node.attrs.mode;
|
||||
@@ -1337,14 +1375,6 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
||||
self.is_started.resolve();
|
||||
});
|
||||
this.viewmanager.start();
|
||||
|
||||
$.when(this.is_started, this.is_setted).then(function() {
|
||||
if (modes[0] == "tree") {
|
||||
var view = self.viewmanager.views[self.viewmanager.active_view].controller;
|
||||
view.reload_content();
|
||||
}
|
||||
// TODO niv: handle other types of views
|
||||
});
|
||||
},
|
||||
reload_current_view: function() {
|
||||
var self = this;
|
||||
@@ -1352,18 +1382,61 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
||||
if(self.viewmanager.active_view === "list") {
|
||||
view.reload_content();
|
||||
} else if (self.viewmanager.active_view === "form") {
|
||||
// TODO niv: but fme did not implemented delete in form view anyway
|
||||
// TODO niv: implement
|
||||
}
|
||||
},
|
||||
set_value_from_ui: function() {},
|
||||
set_value: function(value) {
|
||||
if(value != false) {
|
||||
this.dataset.set_ids(value);
|
||||
this.is_setted.resolve();
|
||||
value = value || [];
|
||||
var self = this;
|
||||
if(value.length >= 1 && value[0] instanceof Array) {
|
||||
var ids = [];
|
||||
_each(value, function(command) {
|
||||
if(command[0] == 0) {
|
||||
var obj = {id: _.uniqueId(self.dataset.virtual_id_prefix), values: command[2]};
|
||||
self.dataset.to_create.push(obj);
|
||||
self.dataset.cache.push(_.clone(obj));
|
||||
ids.push(obj.id);
|
||||
} else if(command[0] == 1) {
|
||||
var obj = {id: command[1], values: command[2]};
|
||||
self.dataset.to_write.push(obj);
|
||||
self.dataset.cache.push(_.clone(obj));
|
||||
ids.push(obj.id);
|
||||
} else if(command[0] == 2) {
|
||||
self.dataset.to_delete.push({id: command[1]});
|
||||
} else if(command[0] == 4) {
|
||||
ids.push(command[1]);
|
||||
}
|
||||
});
|
||||
this._super(ids);
|
||||
this.dataset.set_ids(ids);
|
||||
} else {
|
||||
this._super(value);
|
||||
this.dataset.reset_ids(value);
|
||||
}
|
||||
$.when(this.is_started).then(function() {
|
||||
self.reload_current_view();
|
||||
});
|
||||
},
|
||||
get_value: function(value) {
|
||||
//TODO niv
|
||||
return [];
|
||||
get_value: function() {
|
||||
var self = this;
|
||||
var val = _.map(this.dataset.ids, function(id) {
|
||||
var alter_order = _.detect(self.dataset.to_create, function(x) {return x.id === id;});
|
||||
if (alter_order) {
|
||||
return [0, 0, alter_order.values];
|
||||
}
|
||||
alter_order = _.detect(self.dataset.to_write, function(x) {return x.id === id;});
|
||||
if (alter_order) {
|
||||
return [1, alter_order.id, alter_order.values];
|
||||
}
|
||||
return [4, id];
|
||||
});
|
||||
val = val.concat(_.map(this.dataset.to_delete, function(v, k) {return [2, x.id];}));
|
||||
return val;
|
||||
},
|
||||
validate: function() {
|
||||
this.invalid = false;
|
||||
// TODO niv
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1373,14 +1446,15 @@ openerp.base.form.One2ManyListView = openerp.base.ListView.extend({
|
||||
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
|
||||
alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
|
||||
auto_create: false
|
||||
});
|
||||
pop.on_select_elements.add(function(element_ids) {
|
||||
var ids = self.o2m.dataset.ids;
|
||||
_.each(element_ids, function(x) {if (!_.include(ids, x)) ids.push(x);});
|
||||
self.o2m.dataset.set_ids(ids);
|
||||
self.o2m.on_ui_change();
|
||||
self.o2m.reload_current_view();
|
||||
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();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1391,7 +1465,6 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
|
||||
this.template = "FieldMany2Many";
|
||||
this.list_id = _.uniqueId("many2many");
|
||||
this.is_started = $.Deferred();
|
||||
this.is_setted = $.Deferred();
|
||||
},
|
||||
start: function() {
|
||||
this._super.apply(this, arguments);
|
||||
@@ -1401,8 +1474,7 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
|
||||
this.dataset = new openerp.base.DataSetStatic(
|
||||
this.session, this.field.relation);
|
||||
this.dataset.on_unlink.add_last(function(ids) {
|
||||
self.list_view.reload_content();
|
||||
|
||||
//TODO niv: should check this for other cases
|
||||
self.on_ui_change();
|
||||
});
|
||||
|
||||
@@ -1415,15 +1487,18 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
|
||||
self.is_started.resolve();
|
||||
});
|
||||
this.list_view.start();
|
||||
$.when(this.is_started, this.is_setted).then(function() {
|
||||
self.list_view.reload_content();
|
||||
});
|
||||
},
|
||||
set_value: function(value) {
|
||||
if (value != false) {
|
||||
this.dataset.set_ids(value);
|
||||
this.is_setted.resolve();
|
||||
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;
|
||||
$.when(this.is_started).then(function() {
|
||||
self.list_view.reload_content();
|
||||
});
|
||||
},
|
||||
get_value: function() {
|
||||
return [[6,false,this.dataset.ids]];
|
||||
@@ -1468,12 +1543,13 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
|
||||
* - initial_view: form or search (default search)
|
||||
* - disable_multiple_selection
|
||||
* - alternative_form_view
|
||||
* - auto_create (default true)
|
||||
*/
|
||||
select_element: function(model, options, domain, context) {
|
||||
this.model = model;
|
||||
this.domain = domain || [];
|
||||
this.context = context || {};
|
||||
this.options = options || {};
|
||||
this.options = _.defaults(options || {}, {"initial_view": "search", "auto_create": true});
|
||||
this.initial_ids = this.options.initial_ids;
|
||||
jQuery(this.render()).dialog({title: '',
|
||||
modal: true,
|
||||
@@ -1482,9 +1558,9 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
|
||||
},
|
||||
start: function() {
|
||||
this._super();
|
||||
this.dataset = new openerp.base.DataSetSearch(this.session, this.model,
|
||||
this.dataset = new openerp.base.ReadOnlyDataSetSearch(this.session, this.model,
|
||||
this.context, this.domain);
|
||||
if ((this.options.initial_view || "search") == "search") {
|
||||
if (this.options.initial_view == "search") {
|
||||
this.setup_search_view();
|
||||
} else { // "form"
|
||||
this.new_object();
|
||||
@@ -1523,7 +1599,7 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
|
||||
$sbutton.click(function() {
|
||||
self.on_select_elements(self.selected_ids);
|
||||
});
|
||||
self.view_list = new openerp.base.form.Many2XPopupListView( null, self.session,
|
||||
self.view_list = new openerp.base.form.SelectCreateListView( null, self.session,
|
||||
self.element_id + "_view_list", self.dataset, false,
|
||||
{'deletable': false});
|
||||
self.view_list.popup = self;
|
||||
@@ -1534,6 +1610,15 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
|
||||
});
|
||||
this.searchview.start();
|
||||
},
|
||||
on_create: function(data) {
|
||||
if (!this.options.auto_create)
|
||||
return;
|
||||
var self = this;
|
||||
var wdataset = new openerp.base.DataSetSearch(this.session, this.model, this.context, this.domain);
|
||||
wdataset.create(data, function(r) {
|
||||
self.on_select_elements([r.result]);
|
||||
});
|
||||
},
|
||||
on_select_elements: function(element_ids) {
|
||||
},
|
||||
on_click_element: function(ids) {
|
||||
@@ -1571,17 +1656,12 @@ openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
|
||||
self.stop();
|
||||
});
|
||||
});
|
||||
this.view_form.on_created.add_last(function(r, success) {
|
||||
if (r.result) {
|
||||
var id = arguments[0].result;
|
||||
self.on_select_elements([id]);
|
||||
}
|
||||
});
|
||||
this.dataset.on_create.add(this.on_create);
|
||||
this.view_form.do_show();
|
||||
}
|
||||
});
|
||||
|
||||
openerp.base.form.Many2XPopupListView = openerp.base.ListView.extend({
|
||||
openerp.base.form.SelectCreateListView = openerp.base.ListView.extend({
|
||||
do_add_record: function () {
|
||||
this.popup.new_object();
|
||||
},
|
||||
|
||||
@@ -877,7 +877,7 @@ openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Gr
|
||||
|
||||
var d = new $.Deferred();
|
||||
dataset.read_slice(
|
||||
_.filter(_.pluck(this.columns, 'name'), _.identity),
|
||||
_.filter(_.pluck(_.select(this.columns, function(x) {return x.tag == "field";}), 'name'), _.identity),
|
||||
0, false,
|
||||
function (records) {
|
||||
var form_records = _(records).map(
|
||||
|
||||
@@ -377,6 +377,7 @@ openerp.base.search.FilterGroup = openerp.base.search.Widget.extend({
|
||||
init: function (filters, view) {
|
||||
this._super(view);
|
||||
this.filters = filters;
|
||||
this.length = filters.length;
|
||||
},
|
||||
start: function () {
|
||||
this._super();
|
||||
|
||||
@@ -244,6 +244,7 @@ openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
|
||||
dataset = new openerp.base.DataSetStatic(session, action.res_model);
|
||||
dataset.ids = [action.res_id];
|
||||
dataset.count = 1;
|
||||
dataset.index = 0;
|
||||
}
|
||||
this._super(session, element_id, dataset, action.views);
|
||||
this.action = action;
|
||||
@@ -417,6 +418,7 @@ openerp.base.View = openerp.base.Controller.extend({
|
||||
action.context['active_id'] = dataset.ids[dataset.index];
|
||||
action.context['active_ids'] = [dataset.ids[dataset.index]];
|
||||
action.context['active_model'] = dataset.model;
|
||||
_.extend(action.context, dataset.context);
|
||||
action.flags = {
|
||||
sidebar : false,
|
||||
search_view : false,
|
||||
|
||||
@@ -360,8 +360,14 @@
|
||||
<h2 class="oe_view_title"><t t-esc="view.fields_view.arch.attrs.string"/></h2>
|
||||
<div class="oe_form_header" t-att-id="view.element_id + '_header'">
|
||||
<div class="oe_form_buttons" t-if="view.flags.action_buttons !== false">
|
||||
<!--<button type="button" class="oe_form_button_save">Save</button>-->
|
||||
<button type="button" class="oe_form_button_save_edit">Save & Edit</button>
|
||||
<!--<button type="button" class="oe_form_button_save">
|
||||
<span class="oe_form_on_update">Save</span>
|
||||
<span class="oe_form_on_create">Create</span>
|
||||
</button>-->
|
||||
<button type="button" class="oe_form_button_save_edit">
|
||||
<span class="oe_form_on_update">Save & Edit</span>
|
||||
<span class="oe_form_on_create">Create & Edit</span>
|
||||
</button>
|
||||
<!--<button type="button" class="oe_form_button_cancel">Cancel</button>-->
|
||||
<button type="button" class="oe_form_button_new">New</button>
|
||||
</div>
|
||||
|
||||
@@ -180,9 +180,9 @@ class CompoundDomain(BaseDomain):
|
||||
final_domain = []
|
||||
for domain in self.domains:
|
||||
if not isinstance(domain, (list, BaseDomain)):
|
||||
raise TypeError("Domain %r is not a list or a nonliteral Domain",
|
||||
domain)
|
||||
|
||||
raise TypeError(
|
||||
"Domain %r is not a list or a nonliteral Domain" % domain)
|
||||
|
||||
if isinstance(domain, list):
|
||||
final_domain.extend(domain)
|
||||
continue
|
||||
@@ -210,9 +210,9 @@ class CompoundContext(BaseContext):
|
||||
final_context = {}
|
||||
for context_to_eval in self.contexts:
|
||||
if not isinstance(context_to_eval, (dict, BaseContext)):
|
||||
raise TypeError("Context %r is not a dict or a nonliteral Context",
|
||||
context_to_eval)
|
||||
|
||||
raise TypeError(
|
||||
"Context %r is not a dict or a nonliteral Context" % context_to_eval)
|
||||
|
||||
if isinstance(context_to_eval, dict):
|
||||
final_context.update(context_to_eval)
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user