2011-03-30 14:35:56 +00:00
|
|
|
|
openerp.base.form = function (openerp) {
|
2011-03-30 14:00:48 +00:00
|
|
|
|
|
2011-03-31 14:54:32 +00:00
|
|
|
|
openerp.base.views.add('form', 'openerp.base.FormView');
|
2011-05-11 14:49:10 +00:00
|
|
|
|
openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormView# */{
|
2011-04-01 10:45:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* Indicates that this view is not searchable, and thus that no search
|
|
|
|
|
* view should be displayed (if there is one active).
|
|
|
|
|
*/
|
|
|
|
|
searchable: false,
|
2011-06-01 12:49:54 +00:00
|
|
|
|
template: "FormView",
|
2011-04-01 10:45:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* @constructs
|
|
|
|
|
* @param {openerp.base.Session} session the current openerp session
|
|
|
|
|
* @param {String} element_id this view's root element id
|
|
|
|
|
* @param {openerp.base.DataSet} dataset the dataset this view will work with
|
|
|
|
|
* @param {String} view_id the identifier of the OpenERP view object
|
2011-06-03 09:43:02 +00:00
|
|
|
|
*
|
|
|
|
|
* @property {openerp.base.Registry} registry=openerp.base.form.widgets widgets registry for this form view instance
|
2011-04-01 10:45:00 +00:00
|
|
|
|
*/
|
2011-04-04 13:47:05 +00:00
|
|
|
|
init: function(view_manager, session, element_id, dataset, view_id) {
|
2011-03-30 14:00:48 +00:00
|
|
|
|
this._super(session, element_id);
|
2011-05-24 11:30:13 +00:00
|
|
|
|
this.view_manager = view_manager || new openerp.base.NullViewManager();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
this.dataset = dataset;
|
|
|
|
|
this.model = dataset.model;
|
|
|
|
|
this.view_id = view_id;
|
2011-04-04 15:06:19 +00:00
|
|
|
|
this.fields_view = {};
|
2011-03-30 14:00:48 +00:00
|
|
|
|
this.widgets = {};
|
|
|
|
|
this.widgets_counter = 0;
|
|
|
|
|
this.fields = {};
|
2011-04-05 15:14:40 +00:00
|
|
|
|
this.datarecord = {};
|
2011-03-30 14:00:48 +00:00
|
|
|
|
this.ready = false;
|
2011-04-11 11:35:16 +00:00
|
|
|
|
this.show_invalid = true;
|
2011-04-12 20:38:20 +00:00
|
|
|
|
this.touched = false;
|
2011-06-16 14:25:30 +00:00
|
|
|
|
this.flags = this.view_manager.flags || {};
|
2011-06-20 18:25:49 +00:00
|
|
|
|
this.default_focus_field = null;
|
|
|
|
|
this.default_focus_button = null;
|
2011-06-03 09:43:02 +00:00
|
|
|
|
this.registry = openerp.base.form.widgets;
|
2011-06-17 14:19:45 +00:00
|
|
|
|
this.has_been_loaded = $.Deferred();
|
2011-06-23 15:55:09 +00:00
|
|
|
|
this.$form_header = null;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-06-06 07:04:51 +00:00
|
|
|
|
start: function() {
|
2011-03-30 14:00:48 +00:00
|
|
|
|
//this.log('Starting FormView '+this.model+this.view_id)
|
2011-06-06 07:04:51 +00:00
|
|
|
|
if (this.embedded_view) {
|
|
|
|
|
return $.Deferred().then(this.on_loaded).resolve({fields_view: this.embedded_view});
|
2011-06-01 08:23:58 +00:00
|
|
|
|
} else {
|
2011-06-21 14:38:04 +00:00
|
|
|
|
var context = new openerp.base.CompoundContext(this.dataset.context);
|
|
|
|
|
if (this.view_manager.action && this.view_manager.action.context) {
|
|
|
|
|
context.add(this.view_manager.action.context);
|
|
|
|
|
}
|
2011-06-01 08:23:58 +00:00
|
|
|
|
return this.rpc("/base/formview/load", {"model": this.model, "view_id": this.view_id,
|
2011-06-21 14:38:04 +00:00
|
|
|
|
toolbar:!!this.flags.sidebar, context: context}, this.on_loaded);
|
2011-06-01 08:23:58 +00:00
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
|
|
|
|
on_loaded: function(data) {
|
|
|
|
|
var self = this;
|
|
|
|
|
this.fields_view = data.fields_view;
|
2011-06-03 09:43:02 +00:00
|
|
|
|
var frame = new (this.registry.get_object('frame'))(this, this.fields_view.arch);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
|
2011-06-01 12:49:54 +00:00
|
|
|
|
this.$element.html(QWeb.render(this.template, { 'frame': frame, 'view': this }));
|
2011-03-30 14:00:48 +00:00
|
|
|
|
_.each(this.widgets, function(w) {
|
|
|
|
|
w.start();
|
|
|
|
|
});
|
2011-06-23 15:55:09 +00:00
|
|
|
|
this.$form_header = this.$element.find('#' + this.element_id + '_header');
|
|
|
|
|
this.$form_header.find('div.oe_form_pager button[data-pager-action]').click(function() {
|
2011-04-05 08:57:50 +00:00
|
|
|
|
var action = $(this).data('pager-action');
|
|
|
|
|
self.on_pager_action(action);
|
|
|
|
|
});
|
2011-04-05 14:34:25 +00:00
|
|
|
|
|
2011-06-23 15:55:09 +00:00
|
|
|
|
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);
|
2011-04-05 14:34:25 +00:00
|
|
|
|
|
2011-05-24 11:30:13 +00:00
|
|
|
|
this.view_manager.sidebar.set_toolbar(data.fields_view.toolbar);
|
2011-06-17 14:19:45 +00:00
|
|
|
|
this.has_been_loaded.resolve();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-04-06 21:10:37 +00:00
|
|
|
|
do_show: function () {
|
2011-04-12 13:15:22 +00:00
|
|
|
|
var self = this;
|
2011-06-23 15:55:09 +00:00
|
|
|
|
if (this.dataset.index === null) {
|
2011-04-12 13:15:22 +00:00
|
|
|
|
// null index means we should start a new record
|
|
|
|
|
this.on_button_new();
|
|
|
|
|
} else {
|
|
|
|
|
this.dataset.read_index(_.keys(this.fields_view.fields), this.on_record_loaded);
|
|
|
|
|
}
|
2011-06-23 15:55:09 +00:00
|
|
|
|
self.$element.show();
|
2011-05-24 16:42:33 +00:00
|
|
|
|
this.view_manager.sidebar.do_refresh(true);
|
2011-04-06 21:10:37 +00:00
|
|
|
|
},
|
|
|
|
|
do_hide: function () {
|
|
|
|
|
this.$element.hide();
|
|
|
|
|
},
|
2011-03-30 14:00:48 +00:00
|
|
|
|
on_record_loaded: function(record) {
|
2011-06-23 15:55:09 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
2011-04-12 20:38:20 +00:00
|
|
|
|
this.touched = false;
|
2011-06-23 15:55:09 +00:00
|
|
|
|
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) {
|
2011-04-12 20:38:20 +00:00
|
|
|
|
var field = this.fields[f];
|
2011-06-23 15:55:09 +00:00
|
|
|
|
if (field) {
|
|
|
|
|
field.touched = true;
|
|
|
|
|
this.do_onchange(field);
|
2011-04-07 13:07:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
2011-06-23 15:55:09 +00:00
|
|
|
|
this.on_form_changed();
|
|
|
|
|
this.show_invalid = this.ready = true;
|
2011-04-11 11:55:07 +00:00
|
|
|
|
this.do_update_pager(record.id == null);
|
2011-05-26 21:38:11 +00:00
|
|
|
|
this.do_update_sidebar();
|
2011-06-20 18:25:49 +00:00
|
|
|
|
if (this.default_focus_field) {
|
|
|
|
|
this.default_focus_field.focus();
|
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-06-23 15:55:09 +00:00
|
|
|
|
on_form_changed: function() {
|
|
|
|
|
for (var w in this.widgets) {
|
|
|
|
|
w = this.widgets[w];
|
|
|
|
|
w.process_attrs();
|
|
|
|
|
w.update_dom();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2011-04-06 21:10:37 +00:00
|
|
|
|
on_pager_action: function(action) {
|
|
|
|
|
switch (action) {
|
|
|
|
|
case 'first':
|
|
|
|
|
this.dataset.index = 0;
|
|
|
|
|
break;
|
|
|
|
|
case 'previous':
|
|
|
|
|
this.dataset.previous();
|
|
|
|
|
break;
|
|
|
|
|
case 'next':
|
|
|
|
|
this.dataset.next();
|
|
|
|
|
break;
|
|
|
|
|
case 'last':
|
|
|
|
|
this.dataset.index = this.dataset.ids.length - 1;
|
|
|
|
|
break;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
2011-04-11 15:59:46 +00:00
|
|
|
|
this.reload();
|
2011-04-06 21:10:37 +00:00
|
|
|
|
},
|
2011-04-11 11:55:07 +00:00
|
|
|
|
do_update_pager: function(hide_index) {
|
2011-04-12 20:38:20 +00:00
|
|
|
|
var $pager = this.$element.find('#' + this.element_id + '_header div.oe_form_pager');
|
2011-04-11 11:55:07 +00:00
|
|
|
|
var index = hide_index ? '-' : this.dataset.index + 1;
|
2011-04-11 12:32:07 +00:00
|
|
|
|
$pager.find('span.oe_pager_index').html(index);
|
|
|
|
|
$pager.find('span.oe_pager_count').html(this.dataset.count);
|
2011-04-06 21:10:37 +00:00
|
|
|
|
},
|
2011-04-07 17:09:29 +00:00
|
|
|
|
do_onchange: function(widget, processed) {
|
|
|
|
|
processed = processed || [];
|
2011-04-07 13:07:25 +00:00
|
|
|
|
if (widget.node.attrs.on_change) {
|
|
|
|
|
var self = this;
|
|
|
|
|
this.ready = false;
|
|
|
|
|
var onchange = _.trim(widget.node.attrs.on_change);
|
|
|
|
|
var call = onchange.match(/^\s?(.*?)\((.*?)\)\s?$/);
|
2011-06-23 15:55:09 +00:00
|
|
|
|
console.log("Onchange triggered for field '%s' -> %s", widget.name, onchange);
|
2011-04-07 13:07:25 +00:00
|
|
|
|
if (call) {
|
|
|
|
|
var method = call[1], args = [];
|
2011-05-12 14:48:35 +00:00
|
|
|
|
var argument_replacement = {
|
|
|
|
|
'False' : false,
|
|
|
|
|
'True' : true,
|
|
|
|
|
'None' : null
|
|
|
|
|
}
|
2011-04-07 13:07:25 +00:00
|
|
|
|
_.each(call[2].split(','), function(a) {
|
|
|
|
|
var field = _.trim(a);
|
2011-05-12 14:48:35 +00:00
|
|
|
|
if (field in argument_replacement) {
|
|
|
|
|
args.push(argument_replacement[field]);
|
|
|
|
|
} else if (self.fields[field]) {
|
2011-06-20 14:43:48 +00:00
|
|
|
|
var value = self.fields[field].get_value();
|
2011-04-07 13:07:25 +00:00
|
|
|
|
args.push(value == null ? false : value);
|
|
|
|
|
} else {
|
|
|
|
|
args.push(false);
|
2011-05-12 14:32:22 +00:00
|
|
|
|
self.log("warning : on_change can't find field " + field, onchange);
|
2011-04-07 13:07:25 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2011-04-07 17:09:29 +00:00
|
|
|
|
var ajax = {
|
|
|
|
|
url: '/base/dataset/call',
|
|
|
|
|
async: false
|
2011-04-08 10:37:36 +00:00
|
|
|
|
};
|
2011-04-07 17:09:29 +00:00
|
|
|
|
return this.rpc(ajax, {
|
|
|
|
|
model: this.dataset.model,
|
|
|
|
|
method: method,
|
2011-06-16 07:43:00 +00:00
|
|
|
|
args: [(this.datarecord.id == null ? [] : [this.datarecord.id])].concat(args)
|
2011-04-07 17:09:29 +00:00
|
|
|
|
}, function(response) {
|
|
|
|
|
self.on_processed_onchange(response, processed);
|
2011-04-07 15:59:36 +00:00
|
|
|
|
});
|
2011-04-07 13:07:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
this.log("Wrong on_change format", on_change);
|
|
|
|
|
}
|
2011-04-06 14:51:13 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2011-04-07 17:09:29 +00:00
|
|
|
|
on_processed_onchange: function(response, processed) {
|
2011-04-06 14:51:13 +00:00
|
|
|
|
var result = response.result;
|
|
|
|
|
if (result.value) {
|
2011-06-23 15:55:09 +00:00
|
|
|
|
console.log(" |-> Onchange Response :", result.value);
|
2011-04-06 14:51:13 +00:00
|
|
|
|
for (var f in result.value) {
|
|
|
|
|
var field = this.fields[f];
|
|
|
|
|
if (field) {
|
|
|
|
|
var value = result.value[f];
|
2011-04-07 17:09:29 +00:00
|
|
|
|
processed.push(field.name);
|
2011-06-20 14:43:48 +00:00
|
|
|
|
if (field.get_value() != value) {
|
2011-06-23 15:55:09 +00:00
|
|
|
|
console.log(" |-> Onchange Action : change '%s' value from '%s' to '%s'", field.name, field.get_value(), value);
|
2011-04-06 14:51:13 +00:00
|
|
|
|
field.set_value(value);
|
2011-04-07 17:09:29 +00:00
|
|
|
|
if (_.indexOf(processed, field.name) < 0) {
|
|
|
|
|
this.do_onchange(field, processed);
|
|
|
|
|
}
|
2011-04-06 14:51:13 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.log("warning : on_processed_onchange can't find field " + field, result);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-07 17:09:29 +00:00
|
|
|
|
this.on_form_changed();
|
2011-04-06 14:51:13 +00:00
|
|
|
|
}
|
|
|
|
|
if (result.warning) {
|
|
|
|
|
$(QWeb.render("DialogWarning", result.warning)).dialog({
|
|
|
|
|
modal: true,
|
|
|
|
|
buttons: {
|
|
|
|
|
Ok: function() {
|
|
|
|
|
$(this).dialog("close");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (result.domain) {
|
|
|
|
|
// Will be removed ?
|
|
|
|
|
}
|
|
|
|
|
this.ready = true;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-04-07 13:07:25 +00:00
|
|
|
|
on_button_new: function() {
|
|
|
|
|
var self = this;
|
2011-06-21 14:38:04 +00:00
|
|
|
|
var context = new openerp.base.CompoundContext(this.dataset.context);
|
|
|
|
|
if (this.view_manager.action && this.view_manager.action.context) {
|
|
|
|
|
context.add(this.view_manager.action.context);
|
|
|
|
|
}
|
2011-06-17 14:19:45 +00:00
|
|
|
|
$.when(this.has_been_loaded).then(function() {
|
2011-06-21 14:38:04 +00:00
|
|
|
|
self.dataset.default_get(_.keys(self.fields_view.fields), context, function(result) {
|
2011-06-17 14:19:45 +00:00
|
|
|
|
self.on_record_loaded(result.result);
|
|
|
|
|
});
|
2011-04-07 13:07:25 +00:00
|
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-06-06 13:11:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Triggers saving the form's record. Chooses between creating a new
|
|
|
|
|
* record or saving an existing one depending on whether the record
|
|
|
|
|
* already has an id property.
|
|
|
|
|
*
|
|
|
|
|
* @param {Function} success callback on save success
|
|
|
|
|
* @param {Boolean} [prepend_on_create=false] if ``do_save`` creates a new record, should that record be inserted at the start of the dataset (by default, records are added at the end)
|
|
|
|
|
*/
|
|
|
|
|
do_save: function(success, prepend_on_create) {
|
2011-04-11 11:35:16 +00:00
|
|
|
|
var self = this;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
if (!this.ready) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-06-22 12:25:42 +00:00
|
|
|
|
var invalid = false,
|
|
|
|
|
values = {},
|
|
|
|
|
first_invalid_field = null;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
for (var f in this.fields) {
|
|
|
|
|
f = this.fields[f];
|
|
|
|
|
if (f.invalid) {
|
|
|
|
|
invalid = true;
|
2011-04-11 11:35:16 +00:00
|
|
|
|
f.update_dom();
|
2011-06-22 12:25:42 +00:00
|
|
|
|
if (!first_invalid_field) {
|
|
|
|
|
first_invalid_field = f;
|
|
|
|
|
}
|
2011-04-05 14:34:25 +00:00
|
|
|
|
} else if (f.touched) {
|
2011-04-05 15:14:40 +00:00
|
|
|
|
values[f.name] = f.get_value();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (invalid) {
|
2011-06-22 12:25:42 +00:00
|
|
|
|
first_invalid_field.focus();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
this.on_invalid();
|
2011-04-11 15:59:46 +00:00
|
|
|
|
return false;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
} else {
|
2011-04-08 10:37:36 +00:00
|
|
|
|
this.log("About to save", values);
|
2011-04-11 11:35:16 +00:00
|
|
|
|
if (!this.datarecord.id) {
|
2011-04-11 15:59:46 +00:00
|
|
|
|
this.dataset.create(values, function(r) {
|
2011-06-06 13:11:08 +00:00
|
|
|
|
self.on_created(r, success, prepend_on_create);
|
2011-04-11 11:35:16 +00:00
|
|
|
|
});
|
|
|
|
|
} else {
|
2011-04-11 15:59:46 +00:00
|
|
|
|
this.dataset.write(this.datarecord.id, values, function(r) {
|
|
|
|
|
self.on_saved(r, success);
|
|
|
|
|
});
|
2011-04-11 11:35:16 +00:00
|
|
|
|
}
|
2011-04-11 15:59:46 +00:00
|
|
|
|
return true;
|
2011-04-05 14:34:25 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
do_save_edit: function() {
|
2011-04-11 11:35:16 +00:00
|
|
|
|
this.do_save();
|
|
|
|
|
//this.switch_readonly(); Use promises
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-04-05 14:34:25 +00:00
|
|
|
|
switch_readonly: function() {
|
|
|
|
|
},
|
|
|
|
|
switch_editable: function() {
|
|
|
|
|
},
|
2011-03-30 14:00:48 +00:00
|
|
|
|
on_invalid: function() {
|
2011-04-05 17:35:12 +00:00
|
|
|
|
var msg = "<ul>";
|
|
|
|
|
_.each(this.fields, function(f) {
|
|
|
|
|
if (f.invalid) {
|
|
|
|
|
msg += "<li>" + f.string + "</li>";
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
msg += "</ul>";
|
2011-04-11 08:30:32 +00:00
|
|
|
|
this.notification.warn("The following fields are invalid :", msg);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-04-11 15:59:46 +00:00
|
|
|
|
on_saved: function(r, success) {
|
2011-04-05 15:14:40 +00:00
|
|
|
|
if (!r.result) {
|
2011-04-11 15:59:46 +00:00
|
|
|
|
this.notification.warn("Record not saved", "Problem while saving record.");
|
2011-04-05 15:53:48 +00:00
|
|
|
|
} else {
|
2011-04-11 08:30:32 +00:00
|
|
|
|
this.notification.notify("Record saved", "The record #" + this.datarecord.id + " has been saved.");
|
2011-04-11 15:59:46 +00:00
|
|
|
|
if (success) {
|
|
|
|
|
success(r);
|
|
|
|
|
}
|
2011-06-21 10:22:46 +00:00
|
|
|
|
this.reload();
|
2011-04-11 15:59:46 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2011-06-06 13:11:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Updates the form' dataset to contain the new record:
|
|
|
|
|
*
|
|
|
|
|
* * Adds the newly created record to the current dataset (at the end by
|
|
|
|
|
* default)
|
|
|
|
|
* * Selects that record (sets the dataset's index to point to the new
|
|
|
|
|
* record's id).
|
|
|
|
|
* * Updates the pager and sidebar displays
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} r
|
|
|
|
|
* @param {Function} success callback to execute after having updated the dataset
|
|
|
|
|
* @param {Boolean} [prepend_on_create=false] adds the newly created record at the beginning of the dataset instead of the end
|
|
|
|
|
*/
|
|
|
|
|
on_created: function(r, success, prepend_on_create) {
|
2011-04-11 15:59:46 +00:00
|
|
|
|
if (!r.result) {
|
|
|
|
|
this.notification.warn("Record not created", "Problem while creating record.");
|
|
|
|
|
} else {
|
2011-06-06 13:11:08 +00:00
|
|
|
|
this.datarecord.id = r.result;
|
|
|
|
|
if (!prepend_on_create) {
|
|
|
|
|
this.dataset.ids.push(this.datarecord.id);
|
|
|
|
|
this.dataset.index = this.dataset.ids.length - 1;
|
|
|
|
|
} else {
|
|
|
|
|
this.dataset.ids.unshift(this.datarecord.id);
|
|
|
|
|
this.dataset.index = 0;
|
|
|
|
|
}
|
2011-04-11 15:59:46 +00:00
|
|
|
|
this.dataset.count++;
|
|
|
|
|
this.do_update_pager();
|
2011-05-26 21:38:11 +00:00
|
|
|
|
this.do_update_sidebar();
|
2011-04-11 15:59:46 +00:00
|
|
|
|
this.notification.notify("Record created", "The record has been created with id #" + this.datarecord.id);
|
|
|
|
|
if (success) {
|
2011-06-06 13:11:08 +00:00
|
|
|
|
success(_.extend(r, {created: true}));
|
2011-04-11 15:59:46 +00:00
|
|
|
|
}
|
2011-06-21 10:22:46 +00:00
|
|
|
|
this.reload();
|
2011-04-05 15:14:40 +00:00
|
|
|
|
}
|
2011-03-31 14:44:22 +00:00
|
|
|
|
},
|
2011-04-04 15:06:19 +00:00
|
|
|
|
do_search: function (domains, contexts, groupbys) {
|
2011-04-11 08:30:32 +00:00
|
|
|
|
this.notification.notify("Searching form");
|
2011-04-04 15:06:19 +00:00
|
|
|
|
},
|
2011-04-01 10:44:54 +00:00
|
|
|
|
on_action: function (action) {
|
2011-04-11 08:30:32 +00:00
|
|
|
|
this.notification.notify('Executing action ' + action);
|
2011-04-08 10:37:36 +00:00
|
|
|
|
},
|
|
|
|
|
do_cancel: function () {
|
2011-04-11 08:30:32 +00:00
|
|
|
|
this.notification.notify("Cancelling form");
|
2011-04-11 15:59:46 +00:00
|
|
|
|
},
|
2011-05-26 21:38:11 +00:00
|
|
|
|
do_update_sidebar: function() {
|
2011-05-31 14:11:19 +00:00
|
|
|
|
if (this.flags.sidebar === false) {
|
2011-05-26 21:38:11 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!this.datarecord.id) {
|
|
|
|
|
this.on_attachments_loaded([]);
|
|
|
|
|
} else {
|
2011-06-23 10:42:22 +00:00
|
|
|
|
// TODO fme: modify this so it doesn't try to load attachments when there is not sidebar
|
|
|
|
|
/*this.rpc('/base/dataset/search_read', {
|
2011-05-26 21:38:11 +00:00
|
|
|
|
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
|
2011-06-23 10:42:22 +00:00
|
|
|
|
}, this.on_attachments_loaded);*/
|
2011-05-26 21:38:11 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
on_attachments_loaded: function(attachments) {
|
|
|
|
|
this.$sidebar = this.view_manager.sidebar.$element.find('.sidebar-attachments');
|
|
|
|
|
this.attachments = attachments;
|
|
|
|
|
this.$sidebar.html(QWeb.render('FormView.sidebar.attachments', this));
|
|
|
|
|
this.$sidebar.find('.oe-sidebar-attachment-delete').click(this.on_attachment_delete);
|
|
|
|
|
this.$sidebar.find('.oe-binary-file').change(this.on_attachment_changed);
|
|
|
|
|
},
|
|
|
|
|
on_attachment_changed: function(e) {
|
|
|
|
|
window[this.element_id + '_iframe'] = this.do_update_sidebar;
|
|
|
|
|
var $e = $(e.target);
|
|
|
|
|
if ($e.val() != '') {
|
|
|
|
|
this.$sidebar.find('form.oe-binary-form').submit();
|
|
|
|
|
$e.parent().find('input[type=file]').attr('disabled', 'true');
|
|
|
|
|
$e.parent().find('button').attr('disabled', 'true').find('img, span').toggle();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
on_attachment_delete: function(e) {
|
|
|
|
|
var self = this, $e = $(e.currentTarget);
|
|
|
|
|
var name = _.trim($e.parent().find('a.oe-sidebar-attachments-link').text());
|
|
|
|
|
if (confirm("Do you really want to delete the attachment " + name + " ?")) {
|
|
|
|
|
this.rpc('/base/dataset/unlink', {
|
|
|
|
|
model: 'ir.attachment',
|
|
|
|
|
ids: [parseInt($e.attr('data-id'))]
|
|
|
|
|
}, function(r) {
|
|
|
|
|
$e.parent().remove();
|
|
|
|
|
self.notification.notify("Delete an attachment", "The attachment '" + name + "' has been deleted");
|
|
|
|
|
});
|
|
|
|
|
}
|
2011-05-24 16:42:33 +00:00
|
|
|
|
},
|
2011-04-11 15:59:46 +00:00
|
|
|
|
reload: function() {
|
|
|
|
|
if (this.datarecord.id) {
|
|
|
|
|
this.dataset.read_index(_.keys(this.fields_view.fields), this.on_record_loaded);
|
|
|
|
|
} else {
|
2011-04-12 13:15:22 +00:00
|
|
|
|
this.on_button_new();
|
2011-04-11 15:59:46 +00:00
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 10:57:51 +00:00
|
|
|
|
/** @namespace */
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form = {};
|
|
|
|
|
|
2011-04-11 17:36:43 +00:00
|
|
|
|
openerp.base.form.compute_domain = function(expr, fields) {
|
|
|
|
|
var stack = [];
|
2011-04-11 17:50:25 +00:00
|
|
|
|
for (var i = expr.length - 1; i >= 0; i--) {
|
2011-04-11 17:36:43 +00:00
|
|
|
|
var ex = expr[i];
|
|
|
|
|
if (ex.length == 1) {
|
2011-04-11 17:50:25 +00:00
|
|
|
|
var top = stack.pop();
|
2011-05-17 09:35:03 +00:00
|
|
|
|
switch (ex) {
|
2011-04-11 17:50:25 +00:00
|
|
|
|
case '|':
|
|
|
|
|
stack.push(stack.pop() || top);
|
|
|
|
|
continue;
|
|
|
|
|
case '&':
|
|
|
|
|
stack.push(stack.pop() && top);
|
|
|
|
|
continue;
|
|
|
|
|
case '!':
|
|
|
|
|
stack.push(!top);
|
|
|
|
|
continue;
|
|
|
|
|
default:
|
2011-05-17 09:35:03 +00:00
|
|
|
|
throw new Error('Unknown domain operator ' + ex);
|
2011-04-11 17:50:25 +00:00
|
|
|
|
}
|
2011-04-11 17:36:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var field = fields[ex[0]].value;
|
|
|
|
|
var op = ex[1];
|
|
|
|
|
var val = ex[2];
|
|
|
|
|
|
|
|
|
|
switch (op.toLowerCase()) {
|
|
|
|
|
case '=':
|
|
|
|
|
case '==':
|
|
|
|
|
stack.push(field == val);
|
|
|
|
|
break;
|
|
|
|
|
case '!=':
|
|
|
|
|
case '<>':
|
|
|
|
|
stack.push(field != val);
|
|
|
|
|
break;
|
|
|
|
|
case '<':
|
|
|
|
|
stack.push(field < val);
|
|
|
|
|
break;
|
|
|
|
|
case '>':
|
|
|
|
|
stack.push(field > val);
|
|
|
|
|
break;
|
|
|
|
|
case '<=':
|
|
|
|
|
stack.push(field <= val);
|
|
|
|
|
break;
|
|
|
|
|
case '>=':
|
|
|
|
|
stack.push(field >= val);
|
|
|
|
|
break;
|
|
|
|
|
case 'in':
|
2011-05-17 09:35:03 +00:00
|
|
|
|
stack.push(_(val).contains(field));
|
2011-04-11 17:36:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'not in':
|
2011-05-17 09:35:03 +00:00
|
|
|
|
stack.push(!_(val).contains(field));
|
2011-04-11 17:36:43 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
this.log("Unsupported operator in attrs :", op);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-17 09:35:03 +00:00
|
|
|
|
return _.all(stack);
|
|
|
|
|
};
|
2011-05-11 14:49:10 +00:00
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.Widget = openerp.base.Controller.extend({
|
2011-06-03 10:31:00 +00:00
|
|
|
|
template: 'Widget',
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this.view = view;
|
|
|
|
|
this.node = node;
|
2011-05-25 09:04:35 +00:00
|
|
|
|
this.attrs = JSON.parse(this.node.attrs.attrs || '{}');
|
2011-03-30 14:00:48 +00:00
|
|
|
|
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._super(this.view.session, this.element_id);
|
|
|
|
|
|
|
|
|
|
this.view.widgets[this.element_id] = this;
|
|
|
|
|
this.children = node.children;
|
|
|
|
|
this.colspan = parseInt(node.attrs.colspan || 1);
|
|
|
|
|
|
|
|
|
|
this.string = this.string || node.attrs.string;
|
|
|
|
|
this.help = this.help || node.attrs.help;
|
|
|
|
|
this.invisible = (node.attrs.invisible == '1');
|
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this.$element = $('#' + this.element_id);
|
|
|
|
|
},
|
|
|
|
|
process_attrs: function() {
|
2011-04-11 17:36:43 +00:00
|
|
|
|
var compute_domain = openerp.base.form.compute_domain;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
for (var a in this.attrs) {
|
2011-04-11 17:36:43 +00:00
|
|
|
|
this[a] = compute_domain(this.attrs[a], this.view.fields);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
update_dom: function() {
|
|
|
|
|
this.$element.toggle(!this.invisible);
|
|
|
|
|
},
|
|
|
|
|
render: function() {
|
|
|
|
|
var template = this.template;
|
|
|
|
|
return QWeb.render(template, { "widget": this });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.WidgetFrame = openerp.base.form.Widget.extend({
|
2011-06-03 10:31:00 +00:00
|
|
|
|
template: 'WidgetFrame',
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.columns = node.attrs.col || 4;
|
|
|
|
|
this.x = 0;
|
|
|
|
|
this.y = 0;
|
|
|
|
|
this.table = [];
|
|
|
|
|
this.add_row();
|
|
|
|
|
for (var i = 0; i < node.children.length; i++) {
|
|
|
|
|
var n = node.children[i];
|
|
|
|
|
if (n.tag == "newline") {
|
|
|
|
|
this.add_row();
|
|
|
|
|
} else {
|
|
|
|
|
this.handle_node(n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.set_row_cells_with(this.table[this.table.length - 1]);
|
|
|
|
|
},
|
|
|
|
|
add_row: function(){
|
|
|
|
|
if (this.table.length) {
|
|
|
|
|
this.set_row_cells_with(this.table[this.table.length - 1]);
|
|
|
|
|
}
|
|
|
|
|
var row = [];
|
|
|
|
|
this.table.push(row);
|
|
|
|
|
this.x = 0;
|
|
|
|
|
this.y += 1;
|
|
|
|
|
return row;
|
|
|
|
|
},
|
|
|
|
|
set_row_cells_with: function(row) {
|
|
|
|
|
for (var i = 0; i < row.length; i++) {
|
|
|
|
|
var w = row[i];
|
|
|
|
|
if (w.is_field_label) {
|
|
|
|
|
w.width = "1%";
|
|
|
|
|
if (row[i + 1]) {
|
|
|
|
|
row[i + 1].width = Math.round((100 / this.columns) * (w.colspan + 1) - 1) + '%';
|
|
|
|
|
}
|
|
|
|
|
} else if (w.width === undefined) {
|
|
|
|
|
w.width = Math.round((100 / this.columns) * w.colspan) + '%';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2011-04-12 08:38:31 +00:00
|
|
|
|
handle_node: function(node) {
|
|
|
|
|
var type = this.view.fields_view.fields[node.attrs.name] || {};
|
|
|
|
|
var widget_type = node.attrs.widget || type.type || node.tag;
|
2011-06-03 09:43:02 +00:00
|
|
|
|
var widget = new (this.view.registry.get_object(widget_type)) (this.view, node);
|
2011-06-20 18:25:49 +00:00
|
|
|
|
if (node.tag == 'field') {
|
2011-06-22 12:25:42 +00:00
|
|
|
|
if (!this.view.default_focus_field || node.attrs.default_focus == '1') {
|
2011-06-20 18:25:49 +00:00
|
|
|
|
this.view.default_focus_field = widget;
|
|
|
|
|
}
|
|
|
|
|
if (node.attrs.nolabel != '1') {
|
|
|
|
|
var label = new (this.view.registry.get_object('label')) (this.view, node);
|
|
|
|
|
label["for"] = widget;
|
|
|
|
|
this.add_widget(label);
|
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
2011-04-04 20:08:29 +00:00
|
|
|
|
this.add_widget(widget);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-04-21 08:53:18 +00:00
|
|
|
|
add_widget: function(widget) {
|
|
|
|
|
var current_row = this.table[this.table.length - 1];
|
|
|
|
|
if (current_row.length && (this.x + widget.colspan) > this.columns) {
|
|
|
|
|
current_row = this.add_row();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
2011-04-21 08:53:18 +00:00
|
|
|
|
current_row.push(widget);
|
|
|
|
|
this.x += widget.colspan;
|
|
|
|
|
return widget;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.WidgetNotebook = openerp.base.form.Widget.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
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") {
|
2011-03-31 08:28:38 +00:00
|
|
|
|
var page = new openerp.base.form.WidgetFrame(this.view, n);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
this.pages.push(page);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$element.tabs();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.WidgetSeparator = openerp.base.form.Widget.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.template = "WidgetSeparator";
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.WidgetButton = openerp.base.form.Widget.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.template = "WidgetButton";
|
2011-06-20 18:25:49 +00:00
|
|
|
|
if (node.attrs.default_focus == '1') {
|
|
|
|
|
// TODO fme: provide enter key binding to widgets
|
|
|
|
|
this.view.default_focus_button = this;
|
|
|
|
|
}
|
2011-04-11 15:59:46 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$element.click(this.on_click);
|
|
|
|
|
},
|
|
|
|
|
on_click: function(saved) {
|
|
|
|
|
var self = this;
|
2011-04-12 20:38:20 +00:00
|
|
|
|
if (!this.node.attrs.special && this.view.touched && saved !== true) {
|
2011-04-11 15:59:46 +00:00
|
|
|
|
this.view.do_save(function() {
|
|
|
|
|
self.on_click(true);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
if (this.node.attrs.confirm) {
|
|
|
|
|
var dialog = $('<div>' + this.node.attrs.confirm + '</div>').dialog({
|
|
|
|
|
title: 'Confirm',
|
|
|
|
|
modal: true,
|
|
|
|
|
buttons: {
|
|
|
|
|
Ok: function() {
|
|
|
|
|
self.on_confirmed();
|
|
|
|
|
$(this).dialog("close");
|
|
|
|
|
},
|
|
|
|
|
Cancel: function() {
|
|
|
|
|
$(this).dialog("close");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.on_confirmed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
on_confirmed: function() {
|
2011-05-04 09:12:33 +00:00
|
|
|
|
var self = this;
|
|
|
|
|
|
2011-05-11 14:49:10 +00:00
|
|
|
|
this.view.execute_action(
|
2011-05-04 09:12:33 +00:00
|
|
|
|
this.node.attrs, this.view.dataset, this.session.action_manager,
|
|
|
|
|
this.view.datarecord.id, function (result) {
|
|
|
|
|
self.log("Button returned", result);
|
|
|
|
|
self.view.reload();
|
2011-04-12 15:09:55 +00:00
|
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.WidgetLabel = openerp.base.form.Widget.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this.is_field_label = true;
|
|
|
|
|
this.element_name = 'label_' + node.attrs.name;
|
|
|
|
|
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
|
|
|
|
|
this.template = "WidgetLabel";
|
|
|
|
|
this.colspan = 1;
|
|
|
|
|
},
|
|
|
|
|
render: function () {
|
|
|
|
|
if (this['for'] && this.type !== 'label') {
|
|
|
|
|
return QWeb.render(this.template, {widget: this['for']});
|
|
|
|
|
}
|
|
|
|
|
// Actual label widgets should not have a false and have type label
|
|
|
|
|
return QWeb.render(this.template, {widget: this});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.Field = openerp.base.form.Widget.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this.name = node.attrs.name;
|
|
|
|
|
this.value = undefined;
|
|
|
|
|
view.fields[this.name] = this;
|
|
|
|
|
this.type = node.attrs.widget || view.fields_view.fields[node.attrs.name].type;
|
|
|
|
|
this.element_name = "field_" + this.name + "_" + this.type;
|
|
|
|
|
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
|
|
|
|
|
if (node.attrs.nolabel != '1' && this.colspan > 1) {
|
|
|
|
|
this.colspan--;
|
|
|
|
|
}
|
2011-04-12 08:38:31 +00:00
|
|
|
|
this.field = view.fields_view.fields[node.attrs.name] || {};
|
2011-03-30 14:00:48 +00:00
|
|
|
|
this.string = node.attrs.string || this.field.string;
|
|
|
|
|
this.help = node.attrs.help || this.field.help;
|
2011-04-12 08:38:31 +00:00
|
|
|
|
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';
|
2011-03-30 14:00:48 +00:00
|
|
|
|
this.invalid = false;
|
2011-04-05 14:34:25 +00:00
|
|
|
|
this.touched = false;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
|
|
|
|
set_value: function(value) {
|
|
|
|
|
this.value = value;
|
2011-04-05 18:57:04 +00:00
|
|
|
|
this.invalid = false;
|
2011-04-07 13:07:25 +00:00
|
|
|
|
this.update_dom();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-04-11 11:35:16 +00:00
|
|
|
|
set_value_from_ui: function() {
|
|
|
|
|
this.value = undefined;
|
|
|
|
|
},
|
2011-04-05 14:34:25 +00:00
|
|
|
|
get_value: function() {
|
|
|
|
|
return this.value;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
|
|
|
|
update_dom: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$element.toggleClass('disabled', this.readonly);
|
|
|
|
|
this.$element.toggleClass('required', this.required);
|
2011-04-11 11:35:16 +00:00
|
|
|
|
if (this.view.show_invalid) {
|
|
|
|
|
this.$element.toggleClass('invalid', this.invalid);
|
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
|
|
|
|
on_ui_change: function() {
|
2011-04-12 20:38:20 +00:00
|
|
|
|
this.touched = this.view.touched = true;
|
2011-04-11 11:35:16 +00:00
|
|
|
|
this.validate();
|
2011-06-20 14:43:48 +00:00
|
|
|
|
if (!this.invalid) {
|
|
|
|
|
this.set_value_from_ui();
|
2011-06-23 15:55:09 +00:00
|
|
|
|
this.view.do_onchange(this);
|
|
|
|
|
this.view.on_form_changed();
|
2011-06-20 14:43:48 +00:00
|
|
|
|
} else {
|
|
|
|
|
this.update_dom();
|
|
|
|
|
}
|
2011-04-11 11:35:16 +00:00
|
|
|
|
},
|
|
|
|
|
validate: function() {
|
2011-06-20 14:43:48 +00:00
|
|
|
|
this.invalid = false;
|
2011-06-20 18:25:49 +00:00
|
|
|
|
},
|
|
|
|
|
focus: function() {
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.FieldChar = openerp.base.form.Field.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.template = "FieldChar";
|
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$element.find('input').change(this.on_ui_change);
|
|
|
|
|
},
|
|
|
|
|
set_value: function(value) {
|
|
|
|
|
this._super.apply(this, arguments);
|
2011-04-05 09:20:50 +00:00
|
|
|
|
var show_value = (value != null && value !== false) ? value : '';
|
|
|
|
|
this.$element.find('input').val(show_value);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
|
|
|
|
update_dom: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2011-04-05 14:34:25 +00:00
|
|
|
|
this.$element.find('input').attr('disabled', this.readonly);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-04-11 11:35:16 +00:00
|
|
|
|
set_value_from_ui: function() {
|
2011-03-30 14:00:48 +00:00
|
|
|
|
this.value = this.$element.find('input').val();
|
2011-04-11 11:35:16 +00:00
|
|
|
|
},
|
|
|
|
|
validate: function() {
|
|
|
|
|
this.invalid = false;
|
2011-06-20 14:43:48 +00:00
|
|
|
|
var value = this.$element.find('input').val();
|
|
|
|
|
if (value === "") {
|
2011-04-11 11:35:16 +00:00
|
|
|
|
this.invalid = this.required;
|
|
|
|
|
} else if (this.validation_regex) {
|
2011-06-20 14:43:48 +00:00
|
|
|
|
this.invalid = !this.validation_regex.test(value);
|
2011-04-11 11:35:16 +00:00
|
|
|
|
}
|
2011-06-20 18:25:49 +00:00
|
|
|
|
},
|
|
|
|
|
focus: function() {
|
|
|
|
|
this.$element.find('input').focus();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.FieldEmail = openerp.base.form.FieldChar.extend({
|
2011-04-11 11:35:16 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
2011-05-12 16:25:50 +00:00
|
|
|
|
this.template = "FieldEmail";
|
2011-04-11 11:35:16 +00:00
|
|
|
|
this.validation_regex = /@/;
|
2011-05-12 16:25:50 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$element.find('button').click(this.on_button_clicked);
|
|
|
|
|
},
|
|
|
|
|
on_button_clicked: function() {
|
|
|
|
|
if (!this.value || this.invalid) {
|
|
|
|
|
this.notification.warn("E-mail error", "Can't send email to invalid e-mail address");
|
|
|
|
|
} else {
|
|
|
|
|
location.href = 'mailto:' + this.value;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
set_value: function(value) {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
var show_value = (value != null && value !== false) ? value : '';
|
|
|
|
|
this.$element.find('a').attr('href', 'mailto:' + show_value);
|
2011-04-11 11:35:16 +00:00
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.FieldUrl = openerp.base.form.FieldChar.extend({
|
2011-05-19 13:55:22 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.template = "FieldUrl";
|
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$element.find('button').click(this.on_button_clicked);
|
|
|
|
|
},
|
|
|
|
|
on_button_clicked: function() {
|
|
|
|
|
if (!this.value) {
|
|
|
|
|
this.notification.warn("Resource error", "This resource is empty");
|
|
|
|
|
} else {
|
|
|
|
|
window.open(this.value);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-04-05 14:34:25 +00:00
|
|
|
|
openerp.base.form.FieldFloat = openerp.base.form.FieldChar.extend({
|
2011-04-11 11:35:16 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
2011-05-09 15:19:23 +00:00
|
|
|
|
this.validation_regex = /^-?\d+(\.\d+)?$/;
|
2011-04-11 11:35:16 +00:00
|
|
|
|
},
|
2011-03-30 14:00:48 +00:00
|
|
|
|
set_value: function(value) {
|
2011-06-20 14:43:48 +00:00
|
|
|
|
this._super.apply(this, [value]);
|
|
|
|
|
if (value === false || value === undefined) {
|
2011-05-09 15:19:23 +00:00
|
|
|
|
// As in GTK client, floats default to 0
|
|
|
|
|
value = 0;
|
|
|
|
|
}
|
|
|
|
|
var show_value = value.toFixed(2);
|
2011-04-11 11:35:16 +00:00
|
|
|
|
this.$element.find('input').val(show_value);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-04-11 11:35:16 +00:00
|
|
|
|
set_value_from_ui: function() {
|
2011-06-20 14:43:48 +00:00
|
|
|
|
this.value = Number(this.$element.find('input').val().replace(/,/g, '.'));
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-05-12 10:36:01 +00:00
|
|
|
|
openerp.base.form.FieldDatetime = openerp.base.form.Field.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
2011-04-05 14:34:25 +00:00
|
|
|
|
this.template = "FieldDate";
|
2011-05-12 10:36:01 +00:00
|
|
|
|
this.jqueryui_object = 'datetimepicker';
|
2011-04-05 14:34:25 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2011-05-12 10:36:01 +00:00
|
|
|
|
this.$element.find('input').change(this.on_ui_change)[this.jqueryui_object]({
|
|
|
|
|
dateFormat: 'yy-mm-dd',
|
|
|
|
|
timeFormat: 'hh:mm:ss'
|
2011-04-05 14:34:25 +00:00
|
|
|
|
});
|
2011-05-12 10:36:01 +00:00
|
|
|
|
},
|
|
|
|
|
set_value: function(value) {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
if (value == null || value == false) {
|
|
|
|
|
this.$element.find('input').val('');
|
|
|
|
|
} else {
|
2011-06-20 14:43:48 +00:00
|
|
|
|
this.$element.find('input').unbind('change');
|
|
|
|
|
// jQuery UI date picker wrongly call on_change event herebelow
|
|
|
|
|
this.$element.find('input')[this.jqueryui_object]('setDate', this.parse(value));
|
|
|
|
|
this.$element.find('input').change(this.on_ui_change);
|
2011-05-12 10:36:01 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
set_value_from_ui: function() {
|
|
|
|
|
this.value = this.$element.find('input')[this.jqueryui_object]('getDate') || false;
|
2011-05-12 14:43:55 +00:00
|
|
|
|
if (this.value) {
|
|
|
|
|
this.value = this.format(this.value);
|
|
|
|
|
}
|
2011-05-12 10:36:01 +00:00
|
|
|
|
},
|
|
|
|
|
validate: function() {
|
2011-06-23 17:20:50 +00:00
|
|
|
|
this.invalid = this.required && !this.$element.find('input')[this.jqueryui_object]('getDate');
|
2011-05-12 10:36:01 +00:00
|
|
|
|
},
|
2011-06-20 18:25:49 +00:00
|
|
|
|
focus: function() {
|
|
|
|
|
this.$element.find('input').focus();
|
|
|
|
|
},
|
2011-05-12 14:43:55 +00:00
|
|
|
|
parse: openerp.base.parse_datetime,
|
|
|
|
|
format: openerp.base.format_datetime
|
2011-03-30 14:00:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-12 10:36:01 +00:00
|
|
|
|
openerp.base.form.FieldDate = openerp.base.form.FieldDatetime.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
2011-05-12 10:36:01 +00:00
|
|
|
|
this.jqueryui_object = 'datepicker';
|
2011-04-05 14:34:25 +00:00
|
|
|
|
},
|
2011-05-12 14:43:55 +00:00
|
|
|
|
parse: openerp.base.parse_date,
|
|
|
|
|
format: openerp.base.format_date
|
2011-03-30 14:00:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-05-12 14:32:22 +00:00
|
|
|
|
openerp.base.form.FieldFloatTime = openerp.base.form.FieldChar.extend({
|
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.validation_regex = /^\d+:\d+$/;
|
|
|
|
|
},
|
|
|
|
|
set_value: function(value) {
|
|
|
|
|
this._super.apply(this, [value]);
|
2011-06-20 14:43:48 +00:00
|
|
|
|
if (value === false || value === undefined) {
|
|
|
|
|
// As in GTK client, floats default to 0
|
|
|
|
|
value = 0;
|
|
|
|
|
}
|
2011-05-12 14:32:22 +00:00
|
|
|
|
var show_value = _.sprintf("%02d:%02d", Math.floor(value), Math.round((value % 1) * 60));
|
|
|
|
|
this.$element.find('input').val(show_value);
|
|
|
|
|
},
|
2011-06-20 14:43:48 +00:00
|
|
|
|
set_value_from_ui: function() {
|
|
|
|
|
var time = this.$element.find('input').val().split(':');
|
|
|
|
|
this.set_value(parseInt(time[0], 10) + parseInt(time[1], 10) / 60);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-04-05 14:34:25 +00:00
|
|
|
|
openerp.base.form.FieldText = openerp.base.form.Field.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
2011-04-05 14:34:25 +00:00
|
|
|
|
this.template = "FieldText";
|
2011-04-11 11:35:16 +00:00
|
|
|
|
this.validation_regex = null;
|
2011-03-31 16:03:23 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2011-04-05 14:34:25 +00:00
|
|
|
|
this.$element.find('textarea').change(this.on_ui_change);
|
2011-04-05 09:55:49 +00:00
|
|
|
|
},
|
|
|
|
|
set_value: function(value) {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
var show_value = (value != null && value !== false) ? value : '';
|
2011-04-05 14:34:25 +00:00
|
|
|
|
this.$element.find('textarea').val(show_value);
|
2011-04-05 09:55:49 +00:00
|
|
|
|
},
|
2011-04-05 14:34:25 +00:00
|
|
|
|
update_dom: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$element.find('textarea').attr('disabled', this.readonly);
|
|
|
|
|
},
|
2011-04-11 11:35:16 +00:00
|
|
|
|
set_value_from_ui: function() {
|
2011-04-05 14:34:25 +00:00
|
|
|
|
this.value = this.$element.find('textarea').val();
|
2011-04-11 11:35:16 +00:00
|
|
|
|
},
|
|
|
|
|
validate: function() {
|
|
|
|
|
this.invalid = false;
|
2011-06-20 14:43:48 +00:00
|
|
|
|
var value = this.$element.find('textarea').val();
|
|
|
|
|
if (value === "") {
|
2011-04-11 11:35:16 +00:00
|
|
|
|
this.invalid = this.required;
|
|
|
|
|
} else if (this.validation_regex) {
|
2011-06-20 14:43:48 +00:00
|
|
|
|
this.invalid = !this.validation_regex.test(value);
|
2011-04-11 11:35:16 +00:00
|
|
|
|
}
|
2011-06-20 18:25:49 +00:00
|
|
|
|
},
|
|
|
|
|
focus: function() {
|
|
|
|
|
this.$element.find('textarea').focus();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-04-05 14:34:25 +00:00
|
|
|
|
openerp.base.form.FieldBoolean = openerp.base.form.Field.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
2011-04-05 14:34:25 +00:00
|
|
|
|
this.template = "FieldBoolean";
|
2011-04-05 09:55:49 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
2011-04-05 14:34:25 +00:00
|
|
|
|
var self = this;
|
2011-04-05 09:55:49 +00:00
|
|
|
|
this._super.apply(this, arguments);
|
2011-04-05 14:34:25 +00:00
|
|
|
|
this.$element.find('input').click(function() {
|
2011-04-06 14:51:13 +00:00
|
|
|
|
if ($(this).is(':checked') != self.value) {
|
2011-04-05 14:34:25 +00:00
|
|
|
|
self.on_ui_change();
|
|
|
|
|
}
|
2011-04-05 09:55:49 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
set_value: function(value) {
|
|
|
|
|
this._super.apply(this, arguments);
|
2011-04-05 14:34:25 +00:00
|
|
|
|
this.$element.find('input')[0].checked = value;
|
2011-04-05 09:55:49 +00:00
|
|
|
|
},
|
2011-04-11 11:35:16 +00:00
|
|
|
|
set_value_from_ui: function() {
|
|
|
|
|
this.value = this.$element.find('input').is(':checked');
|
|
|
|
|
},
|
2011-04-05 14:34:25 +00:00
|
|
|
|
update_dom: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2011-04-11 11:35:16 +00:00
|
|
|
|
this.$element.find('input').attr('disabled', this.readonly);
|
2011-04-05 14:34:25 +00:00
|
|
|
|
},
|
2011-04-11 11:35:16 +00:00
|
|
|
|
validate: function() {
|
2011-06-20 14:43:48 +00:00
|
|
|
|
this.invalid = this.required && !this.$element.find('input').is(':checked');
|
2011-06-20 18:25:49 +00:00
|
|
|
|
},
|
|
|
|
|
focus: function() {
|
|
|
|
|
this.$element.find('input').focus();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-04-12 09:26:31 +00:00
|
|
|
|
openerp.base.form.FieldProgressBar = openerp.base.form.Field.extend({
|
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.template = "FieldProgressBar";
|
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$element.find('div').progressbar({
|
|
|
|
|
value: this.value,
|
|
|
|
|
disabled: this.readonly
|
|
|
|
|
});
|
2011-05-09 14:10:01 +00:00
|
|
|
|
},
|
|
|
|
|
set_value: function(value) {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
var show_value = Number(value);
|
|
|
|
|
if (show_value === NaN) {
|
|
|
|
|
show_value = 0;
|
|
|
|
|
}
|
|
|
|
|
this.$element.find('div').progressbar('option', 'value', show_value).find('span').html(show_value + '%');
|
2011-04-12 09:26:31 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.FieldTextXml = openerp.base.form.Field.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
// to replace view editor
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.FieldSelection = openerp.base.form.Field.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.template = "FieldSelection";
|
|
|
|
|
},
|
2011-04-05 14:34:25 +00:00
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$element.find('select').change(this.on_ui_change);
|
|
|
|
|
},
|
2011-03-30 14:00:48 +00:00
|
|
|
|
set_value: function(value) {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
if (value != null && value !== false) {
|
|
|
|
|
this.$element.find('select').val(value);
|
2011-04-05 09:20:50 +00:00
|
|
|
|
} else {
|
2011-06-21 12:41:16 +00:00
|
|
|
|
this.$element.find('select').val('false');
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2011-04-11 11:35:16 +00:00
|
|
|
|
set_value_from_ui: function() {
|
|
|
|
|
this.value = this.$element.find('select').val();
|
|
|
|
|
},
|
2011-04-05 14:34:25 +00:00
|
|
|
|
update_dom: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$element.find('select').attr('disabled', this.readonly);
|
|
|
|
|
},
|
2011-04-11 11:35:16 +00:00
|
|
|
|
validate: function() {
|
2011-06-20 14:43:48 +00:00
|
|
|
|
this.invalid = this.required && this.$element.find('select').val() === "";
|
2011-06-20 18:25:49 +00:00
|
|
|
|
},
|
|
|
|
|
focus: function() {
|
|
|
|
|
this.$element.find('select').focus();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-06-10 13:22:37 +00:00
|
|
|
|
// jquery autocomplete tweak to allow html
|
2011-06-20 14:43:48 +00:00
|
|
|
|
(function() {
|
2011-06-10 13:22:37 +00:00
|
|
|
|
var proto = $.ui.autocomplete.prototype,
|
|
|
|
|
initSource = proto._initSource;
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-10 13:22:37 +00:00
|
|
|
|
function filter( array, term ) {
|
|
|
|
|
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
|
|
|
|
|
return $.grep( array, function(value) {
|
|
|
|
|
return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() );
|
|
|
|
|
});
|
2011-06-10 10:31:55 +00:00
|
|
|
|
}
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-10 13:22:37 +00:00
|
|
|
|
$.extend( proto, {
|
|
|
|
|
_initSource: function() {
|
|
|
|
|
if ( this.options.html && $.isArray(this.options.source) ) {
|
|
|
|
|
this.source = function( request, response ) {
|
|
|
|
|
response( filter( this.options.source, request.term ) );
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
initSource.call( this );
|
|
|
|
|
}
|
|
|
|
|
},
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-10 13:22:37 +00:00
|
|
|
|
_renderItem: function( ul, item) {
|
|
|
|
|
return $( "<li></li>" )
|
|
|
|
|
.data( "item.autocomplete", item )
|
|
|
|
|
.append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) )
|
|
|
|
|
.appendTo( ul );
|
|
|
|
|
}
|
|
|
|
|
});
|
2011-06-20 14:43:48 +00:00
|
|
|
|
})();
|
2011-06-10 10:31:55 +00:00
|
|
|
|
|
2011-06-15 09:54:07 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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 action = relation_field.view.view_manager.action || {};
|
|
|
|
|
var a_context = action.context || {};
|
|
|
|
|
var f_context = relation_field.field.context || {};
|
2011-06-17 12:08:34 +00:00
|
|
|
|
var ctx = new openerp.base.CompoundContext(a_context).add(f_context);
|
|
|
|
|
return ctx;
|
2011-06-15 09:54:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.template = "FieldMany2One";
|
2011-06-06 16:50:43 +00:00
|
|
|
|
this.limit = 7;
|
2011-06-08 15:29:44 +00:00
|
|
|
|
this.value = null;
|
2011-06-09 17:08:51 +00:00
|
|
|
|
this.cm_id = _.uniqueId('m2o_cm_');
|
2011-06-10 13:22:37 +00:00
|
|
|
|
this.last_search = [];
|
2011-06-23 12:57:25 +00:00
|
|
|
|
this.tmp_value = undefined;
|
2011-04-27 12:20:51 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
2011-06-06 16:50:43 +00:00
|
|
|
|
this._super();
|
|
|
|
|
var self = this;
|
|
|
|
|
this.$input = this.$element.find("input");
|
2011-06-10 14:58:01 +00:00
|
|
|
|
this.$drop_down = this.$element.find(".oe-m2o-drop-down-button");
|
|
|
|
|
this.$menu_btn = this.$element.find(".oe-m2o-cm-button");
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-10 10:31:55 +00:00
|
|
|
|
// context menu
|
2011-06-09 17:08:51 +00:00
|
|
|
|
var bindings = {};
|
|
|
|
|
bindings[this.cm_id + "_search"] = function() {
|
|
|
|
|
self._search_create_popup("search");
|
|
|
|
|
};
|
|
|
|
|
bindings[this.cm_id + "_create"] = function() {
|
|
|
|
|
self._search_create_popup("form");
|
|
|
|
|
};
|
|
|
|
|
bindings[this.cm_id + "_open"] = function() {
|
|
|
|
|
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",
|
2011-06-15 09:54:07 +00:00
|
|
|
|
"target":"new",
|
|
|
|
|
"context": build_relation_context(self)
|
2011-06-09 17:08:51 +00:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
var cmenu = this.$menu_btn.contextMenu(this.cm_id, {'leftClickToo': true,
|
2011-06-10 13:22:37 +00:00
|
|
|
|
bindings: bindings, itemStyle: {"color": ""},
|
|
|
|
|
onContextMenu: function() {
|
|
|
|
|
if(self.value) {
|
2011-06-10 14:58:01 +00:00
|
|
|
|
$("#" + self.cm_id + "_open").removeClass("oe-m2o-disabled-cm");
|
2011-06-10 13:22:37 +00:00
|
|
|
|
} else {
|
2011-06-10 14:58:01 +00:00
|
|
|
|
$("#" + self.cm_id + "_open").addClass("oe-m2o-disabled-cm");
|
2011-06-10 13:22:37 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-10 10:31:55 +00:00
|
|
|
|
// some behavior for input
|
|
|
|
|
this.$input.keyup(function() {
|
2011-06-08 15:29:44 +00:00
|
|
|
|
if (self.$input.val() === "") {
|
2011-06-10 14:58:01 +00:00
|
|
|
|
self._change_int_value(null);
|
2011-06-10 10:31:55 +00:00
|
|
|
|
} else if (self.value === null || (self.value && self.$input.val() !== self.value[1])) {
|
2011-06-10 14:58:01 +00:00
|
|
|
|
self._change_int_value(undefined);
|
2011-06-08 15:29:44 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2011-06-09 17:36:44 +00:00
|
|
|
|
this.$drop_down.click(function() {
|
2011-06-08 15:47:44 +00:00
|
|
|
|
if (self.$input.autocomplete("widget").is(":visible")) {
|
2011-06-08 15:29:44 +00:00
|
|
|
|
self.$input.autocomplete("close");
|
|
|
|
|
} else {
|
2011-06-10 13:55:26 +00:00
|
|
|
|
if (self.value) {
|
|
|
|
|
self.$input.autocomplete("search", "");
|
|
|
|
|
} else {
|
|
|
|
|
self.$input.autocomplete("search");
|
|
|
|
|
}
|
2011-06-08 15:47:44 +00:00
|
|
|
|
self.$input.focus();
|
2011-06-08 15:29:44 +00:00
|
|
|
|
}
|
2011-06-06 16:50:43 +00:00
|
|
|
|
});
|
2011-06-10 13:22:37 +00:00
|
|
|
|
var anyoneLoosesFocus = function() {
|
|
|
|
|
if (!self.$input.is(":focus") &&
|
|
|
|
|
!self.$input.autocomplete("widget").is(":visible") &&
|
|
|
|
|
!self.value) {
|
|
|
|
|
if(self.value === undefined && self.last_search.length > 0) {
|
2011-06-10 14:58:01 +00:00
|
|
|
|
self._change_int_ext_value(self.last_search[0]);
|
2011-06-10 13:22:37 +00:00
|
|
|
|
} else {
|
2011-06-10 14:58:01 +00:00
|
|
|
|
self._change_int_ext_value(null);
|
2011-06-10 13:22:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.$input.focusout(anyoneLoosesFocus);
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-10 10:31:55 +00:00
|
|
|
|
// autocomplete
|
2011-06-06 16:50:43 +00:00
|
|
|
|
this.$input.autocomplete({
|
2011-06-08 15:29:44 +00:00
|
|
|
|
source: function(req, resp) { self.get_search_result(req, resp); },
|
2011-06-09 13:20:04 +00:00
|
|
|
|
select: function(event, ui) {
|
2011-06-08 15:29:44 +00:00
|
|
|
|
var item = ui.item;
|
|
|
|
|
if (item.id) {
|
2011-06-10 14:58:01 +00:00
|
|
|
|
self._change_int_value([item.id, item.name]);
|
2011-06-08 15:29:44 +00:00
|
|
|
|
} else if (item.action) {
|
2011-06-10 14:58:01 +00:00
|
|
|
|
self._change_int_value(undefined);
|
2011-06-08 15:29:44 +00:00
|
|
|
|
item.action();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-06-10 10:31:55 +00:00
|
|
|
|
},
|
2011-06-10 12:15:45 +00:00
|
|
|
|
focus: function(e, ui) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
},
|
2011-06-10 13:22:37 +00:00
|
|
|
|
html: true,
|
2011-06-10 13:55:26 +00:00
|
|
|
|
close: anyoneLoosesFocus,
|
2011-06-10 13:58:35 +00:00
|
|
|
|
minLength: 0,
|
|
|
|
|
delay: 0
|
2011-06-06 16:50:43 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2011-06-10 10:31:55 +00:00
|
|
|
|
// autocomplete component content handling
|
2011-06-06 16:50:43 +00:00
|
|
|
|
get_search_result: function(request, response) {
|
|
|
|
|
var search_val = request.term;
|
|
|
|
|
var self = this;
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-06 16:50:43 +00:00
|
|
|
|
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, []);
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-17 08:41:33 +00:00
|
|
|
|
dataset.name_search([search_val, self.field.domain || [], 'ilike',
|
2011-06-15 09:54:07 +00:00
|
|
|
|
build_relation_context(self), this.limit + 1], function(data) {
|
2011-06-10 13:22:37 +00:00
|
|
|
|
self.last_search = data.result;
|
2011-06-10 10:31:55 +00:00
|
|
|
|
// possible selections for the m2o
|
2011-06-08 15:29:44 +00:00
|
|
|
|
var values = _.map(data.result, function(x) {
|
2011-06-10 13:22:37 +00:00
|
|
|
|
return {label: $('<span />').text(x[1]).html(), name:x[1], id:x[0]};
|
2011-06-06 16:50:43 +00:00
|
|
|
|
});
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-15 09:54:07 +00:00
|
|
|
|
// search more... if more results that max
|
2011-06-09 13:20:04 +00:00
|
|
|
|
if (values.length > self.limit) {
|
|
|
|
|
values = values.slice(0, self.limit);
|
2011-06-10 12:15:45 +00:00
|
|
|
|
values.push({label: "<em> Search More...</em>", action: function() {
|
2011-06-17 08:41:33 +00:00
|
|
|
|
dataset.name_search([search_val, self.field.domain || [], 'ilike',
|
2011-06-15 09:54:07 +00:00
|
|
|
|
build_relation_context(self), false], function(data) {
|
2011-06-10 14:58:01 +00:00
|
|
|
|
self._change_int_value(null);
|
2011-06-09 17:08:51 +00:00
|
|
|
|
self._search_create_popup("search", data.result);
|
2011-06-09 13:20:04 +00:00
|
|
|
|
});
|
|
|
|
|
}});
|
2011-06-06 16:50:43 +00:00
|
|
|
|
}
|
2011-06-15 09:54:07 +00:00
|
|
|
|
// quick create
|
2011-06-14 08:10:46 +00:00
|
|
|
|
var raw_result = _(data.result).map(function(x) {return x[1];})
|
|
|
|
|
if (search_val.length > 0 &&
|
|
|
|
|
!_.include(raw_result, search_val) &&
|
|
|
|
|
(!self.value || search_val !== self.value[1])) {
|
2011-06-10 10:31:55 +00:00
|
|
|
|
values.push({label: '<em> Create "<strong>' +
|
|
|
|
|
$('<span />').text(search_val).html() + '</strong>"</em>', action: function() {
|
2011-06-10 16:16:29 +00:00
|
|
|
|
self._quick_create(search_val);
|
2011-06-10 10:31:55 +00:00
|
|
|
|
}});
|
|
|
|
|
}
|
2011-06-15 09:54:07 +00:00
|
|
|
|
// create...
|
2011-06-10 12:15:45 +00:00
|
|
|
|
values.push({label: "<em> Create and Edit...</em>", action: function() {
|
2011-06-10 15:24:13 +00:00
|
|
|
|
self._change_int_value(null);
|
2011-06-09 17:08:51 +00:00
|
|
|
|
self._search_create_popup("form");
|
2011-06-09 13:20:04 +00:00
|
|
|
|
}});
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-06 16:50:43 +00:00
|
|
|
|
response(values);
|
|
|
|
|
});
|
2011-04-05 09:20:50 +00:00
|
|
|
|
},
|
2011-06-10 16:16:29 +00:00
|
|
|
|
_quick_create: function(name) {
|
|
|
|
|
var self = this;
|
|
|
|
|
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, []);
|
2011-06-15 09:54:07 +00:00
|
|
|
|
dataset.call("name_create", [name, build_relation_context(self)], function(data) {
|
2011-06-10 16:16:29 +00:00
|
|
|
|
self._change_int_ext_value(data.result);
|
|
|
|
|
}, function(a, b) {
|
|
|
|
|
self._change_int_value(null);
|
2011-06-17 14:19:45 +00:00
|
|
|
|
self._search_create_popup("form", undefined, {"default_name": name});
|
2011-06-10 16:16:29 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2011-06-10 10:31:55 +00:00
|
|
|
|
// all search/create popup handling
|
2011-06-17 14:19:45 +00:00
|
|
|
|
_search_create_popup: function(view, ids, context) {
|
2011-06-09 17:08:51 +00:00
|
|
|
|
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, []);
|
|
|
|
|
var self = this;
|
2011-06-16 15:17:22 +00:00
|
|
|
|
var pop = new openerp.base.form.SelectCreatePopup(null, self.view.session);
|
2011-06-15 15:04:40 +00:00
|
|
|
|
pop.select_element(self.field.relation,{
|
|
|
|
|
initial_ids: ids ? _.map(ids, function(x) {return x[0]}) : undefined,
|
|
|
|
|
initial_view: view,
|
|
|
|
|
disable_multiple_selection: true
|
2011-06-17 14:19:45 +00:00
|
|
|
|
}, self.view.domain || [],
|
|
|
|
|
new openerp.base.CompoundContext(build_relation_context(self)).add(context || {}));
|
2011-06-15 15:04:40 +00:00
|
|
|
|
pop.on_select_elements.add(function(element_ids) {
|
|
|
|
|
dataset.call("name_get", [element_ids[0]], function(data) {
|
2011-06-10 15:24:13 +00:00
|
|
|
|
self._change_int_ext_value(data.result[0]);
|
2011-06-09 17:08:51 +00:00
|
|
|
|
pop.stop();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
2011-06-10 14:58:01 +00:00
|
|
|
|
_change_int_ext_value: function(value) {
|
|
|
|
|
this._change_int_value(value);
|
|
|
|
|
this.$input.val(this.value ? this.value[1] : "");
|
|
|
|
|
},
|
|
|
|
|
_change_int_value: function(value) {
|
|
|
|
|
this.value = value;
|
2011-06-10 15:07:33 +00:00
|
|
|
|
if (this.original_value === undefined || (this.value !== undefined &&
|
|
|
|
|
((this.original_value ? this.original_value[0] : null) !== (this.value ? this.value[0] : null)))) {
|
|
|
|
|
this.original_value = undefined;
|
2011-06-10 14:58:01 +00:00
|
|
|
|
this.on_ui_change();
|
2011-04-05 14:34:25 +00:00
|
|
|
|
}
|
2011-05-03 08:50:44 +00:00
|
|
|
|
},
|
2011-06-10 14:58:01 +00:00
|
|
|
|
set_value_from_ui: function() {},
|
|
|
|
|
set_value: function(value) {
|
2011-06-23 10:42:22 +00:00
|
|
|
|
value = value || null;
|
2011-06-23 12:40:16 +00:00
|
|
|
|
var self = this;
|
|
|
|
|
var _super = this._super;
|
2011-06-23 12:57:25 +00:00
|
|
|
|
this.tmp_value = value;
|
2011-06-23 12:40:16 +00:00
|
|
|
|
var real_set_value = function(rval) {
|
2011-06-23 12:57:25 +00:00
|
|
|
|
this.tmp_value = undefined;
|
2011-06-23 12:40:16 +00:00
|
|
|
|
_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, []);
|
2011-06-23 12:57:25 +00:00
|
|
|
|
dataset.call("name_get", [value], function(data) {
|
2011-06-23 12:40:16 +00:00
|
|
|
|
real_set_value(data.result[0]);
|
2011-06-23 13:51:24 +00:00
|
|
|
|
}).fail(function() {self.tmp_value = undefined;});
|
2011-06-23 12:40:16 +00:00
|
|
|
|
} else {
|
|
|
|
|
setTimeout(function() {real_set_value(value);}, 0);
|
|
|
|
|
}
|
2011-06-10 14:58:01 +00:00
|
|
|
|
},
|
2011-05-03 08:50:44 +00:00
|
|
|
|
get_value: function() {
|
2011-06-23 12:57:25 +00:00
|
|
|
|
if (this.tmp_value !== undefined) {
|
|
|
|
|
if (this.tmp_value instanceof Array) {
|
|
|
|
|
return this.tmp_value[0];
|
|
|
|
|
}
|
|
|
|
|
return this.tmp_value;
|
|
|
|
|
}
|
2011-06-10 13:29:26 +00:00
|
|
|
|
if (this.value === undefined)
|
|
|
|
|
throw "theorically unreachable state";
|
2011-06-10 14:58:01 +00:00
|
|
|
|
return this.value ? this.value[0] : false;
|
|
|
|
|
},
|
|
|
|
|
validate: function() {
|
|
|
|
|
this.invalid = false;
|
|
|
|
|
if (this.value === null) {
|
|
|
|
|
this.invalid = this.required;
|
|
|
|
|
}
|
2011-06-10 13:29:26 +00:00
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-06-21 12:12:22 +00:00
|
|
|
|
/*
|
|
|
|
|
# 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)
|
|
|
|
|
*/
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.template = "FieldOne2Many";
|
2011-05-31 15:28:07 +00:00
|
|
|
|
this.is_started = $.Deferred();
|
2011-04-05 10:04:50 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-05-31 14:11:19 +00:00
|
|
|
|
var self = this;
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-23 16:57:17 +00:00
|
|
|
|
this.dataset = new openerp.base.BufferedDataSet(this.session, this.field.relation);
|
2011-06-21 12:12:22 +00:00
|
|
|
|
this.dataset.on_change.add_last(function() {
|
2011-05-31 14:11:19 +00:00
|
|
|
|
self.on_ui_change();
|
|
|
|
|
});
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-06 07:04:51 +00:00
|
|
|
|
var modes = this.node.attrs.mode;
|
|
|
|
|
modes = !!modes ? modes.split(",") : ["tree", "form"];
|
|
|
|
|
var views = [];
|
|
|
|
|
_.each(modes, function(mode) {
|
2011-06-16 14:25:30 +00:00
|
|
|
|
var view = {view_id: false, view_type: mode == "tree" ? "list" : mode};
|
2011-06-06 07:04:51 +00:00
|
|
|
|
if (self.field.views && self.field.views[mode]) {
|
2011-06-16 14:25:30 +00:00
|
|
|
|
view.embedded_view = self.field.views[mode];
|
|
|
|
|
}
|
|
|
|
|
if(view.view_type === "list") {
|
|
|
|
|
view.options = {
|
|
|
|
|
};
|
2011-06-06 07:04:51 +00:00
|
|
|
|
}
|
|
|
|
|
views.push(view);
|
|
|
|
|
});
|
2011-06-16 16:37:09 +00:00
|
|
|
|
this.views = views;
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-05-31 14:11:19 +00:00
|
|
|
|
this.viewmanager = new openerp.base.ViewManager(this.view.session,
|
2011-05-31 13:01:54 +00:00
|
|
|
|
this.element_id, this.dataset, views);
|
2011-06-16 16:37:09 +00:00
|
|
|
|
var reg = new openerp.base.Registry();
|
|
|
|
|
reg.add("form", openerp.base.views.map["form"]);
|
|
|
|
|
reg.add("graph", openerp.base.views.map["graph"]);
|
|
|
|
|
reg.add("list", "openerp.base.form.One2ManyListView");
|
|
|
|
|
this.viewmanager.registry = reg;
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-01 08:23:58 +00:00
|
|
|
|
this.viewmanager.on_controller_inited.add_last(function(view_type, controller) {
|
2011-05-31 15:28:07 +00:00
|
|
|
|
if (view_type == "list") {
|
2011-06-16 16:37:09 +00:00
|
|
|
|
controller.o2m = self;
|
2011-06-01 08:23:58 +00:00
|
|
|
|
} else if (view_type == "form") {
|
2011-05-31 15:28:07 +00:00
|
|
|
|
// TODO niv
|
2011-05-31 13:01:54 +00:00
|
|
|
|
}
|
2011-06-01 08:23:58 +00:00
|
|
|
|
self.is_started.resolve();
|
2011-05-31 13:01:54 +00:00
|
|
|
|
});
|
2011-06-06 07:39:35 +00:00
|
|
|
|
this.viewmanager.start();
|
2011-04-04 15:52:09 +00:00
|
|
|
|
},
|
2011-06-16 16:37:09 +00:00
|
|
|
|
reload_current_view: function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
var view = self.viewmanager.views[self.viewmanager.active_view].controller;
|
|
|
|
|
if(self.viewmanager.active_view === "list") {
|
|
|
|
|
view.reload_content();
|
|
|
|
|
} else if (self.viewmanager.active_view === "form") {
|
2011-06-23 10:42:22 +00:00
|
|
|
|
// TODO niv: implement
|
2011-06-16 16:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2011-06-21 12:12:22 +00:00
|
|
|
|
set_value_from_ui: function() {},
|
2011-04-11 11:35:16 +00:00
|
|
|
|
set_value: function(value) {
|
2011-06-23 10:42:22 +00:00
|
|
|
|
value = value || []
|
|
|
|
|
this._super(value);
|
|
|
|
|
this.dataset.reset_ids(value);
|
|
|
|
|
var self = this;
|
|
|
|
|
$.when(this.is_started).then(function() {
|
|
|
|
|
self.reload_current_view();
|
|
|
|
|
});
|
2011-05-31 13:38:17 +00:00
|
|
|
|
},
|
2011-06-21 12:12:22 +00:00
|
|
|
|
get_value: function() {
|
|
|
|
|
var val = _.map(this.dataset.to_delete, function(v, k) {return [2, parseInt(k, 10)];});
|
|
|
|
|
var val = val.concat(_.map(this.dataset.to_create, function(x) {return [0, 0, x];}));
|
|
|
|
|
return val;
|
|
|
|
|
},
|
|
|
|
|
validate: function() {
|
|
|
|
|
this.invalid = false;
|
|
|
|
|
// TODO niv
|
2011-05-31 13:38:17 +00:00
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-06-16 16:37:09 +00:00
|
|
|
|
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",
|
2011-06-23 17:07:34 +00:00
|
|
|
|
alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
|
|
|
|
|
auto_create: false
|
2011-06-16 16:37:09 +00:00
|
|
|
|
});
|
2011-06-23 17:07:34 +00:00
|
|
|
|
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();
|
|
|
|
|
});
|
2011-06-16 16:37:09 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.template = "FieldMany2Many";
|
2011-04-22 15:54:52 +00:00
|
|
|
|
this.list_id = _.uniqueId("many2many");
|
2011-05-31 15:28:07 +00:00
|
|
|
|
this.is_started = $.Deferred();
|
2011-04-22 15:54:52 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-05-31 14:11:19 +00:00
|
|
|
|
var self = this;
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-05-27 15:10:00 +00:00
|
|
|
|
this.dataset = new openerp.base.DataSetStatic(
|
|
|
|
|
this.session, this.field.relation);
|
2011-05-31 14:11:19 +00:00
|
|
|
|
this.dataset.on_unlink.add_last(function(ids) {
|
2011-06-23 10:42:22 +00:00
|
|
|
|
//TODO niv: should check this for other cases
|
2011-05-31 14:11:19 +00:00
|
|
|
|
self.on_ui_change();
|
|
|
|
|
});
|
2011-05-27 15:10:00 +00:00
|
|
|
|
|
|
|
|
|
this.list_view = new openerp.base.form.Many2ManyListView(
|
|
|
|
|
null, this.view.session, this.list_id, this.dataset, false, {
|
|
|
|
|
'addable': 'Add'
|
|
|
|
|
});
|
2011-04-26 14:13:34 +00:00
|
|
|
|
this.list_view.m2m_field = this;
|
2011-05-10 12:15:51 +00:00
|
|
|
|
this.list_view.on_loaded.add_last(function() {
|
2011-05-31 15:28:07 +00:00
|
|
|
|
self.is_started.resolve();
|
|
|
|
|
});
|
2011-06-15 15:40:15 +00:00
|
|
|
|
this.list_view.start();
|
2011-04-22 15:54:52 +00:00
|
|
|
|
},
|
|
|
|
|
set_value: function(value) {
|
2011-06-23 10:42:22 +00:00
|
|
|
|
value = value || [];
|
|
|
|
|
this._super(value);
|
|
|
|
|
this.dataset.set_ids(value);
|
|
|
|
|
var self = this;
|
|
|
|
|
$.when(this.is_started).then(function() {
|
|
|
|
|
self.list_view.reload_content();
|
|
|
|
|
});
|
2011-04-26 12:11:46 +00:00
|
|
|
|
},
|
|
|
|
|
get_value: function() {
|
|
|
|
|
return [[6,false,this.dataset.ids]];
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-04-26 11:24:13 +00:00
|
|
|
|
openerp.base.form.Many2ManyListView = openerp.base.ListView.extend({
|
2011-05-27 15:10:00 +00:00
|
|
|
|
do_add_record: function () {
|
2011-06-16 15:17:22 +00:00
|
|
|
|
var pop = new openerp.base.form.SelectCreatePopup(
|
2011-05-27 15:10:00 +00:00
|
|
|
|
null, this.m2m_field.view.session);
|
2011-05-09 10:05:41 +00:00
|
|
|
|
pop.select_element(this.model);
|
2011-05-09 11:52:33 +00:00
|
|
|
|
var self = this;
|
2011-06-15 15:04:40 +00:00
|
|
|
|
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.reload_content();
|
|
|
|
|
}
|
|
|
|
|
});
|
2011-05-09 11:52:33 +00:00
|
|
|
|
pop.stop();
|
|
|
|
|
});
|
2011-04-26 14:13:34 +00:00
|
|
|
|
},
|
2011-05-27 15:10:00 +00:00
|
|
|
|
do_activate_record: function(index, id) {
|
|
|
|
|
this.m2m_field.view.session.action_manager.do_action({
|
2011-04-26 14:13:34 +00:00
|
|
|
|
"res_model": this.dataset.model,
|
|
|
|
|
"views":[[false,"form"]],
|
|
|
|
|
"res_id": id,
|
|
|
|
|
"type":"ir.actions.act_window",
|
|
|
|
|
"view_type":"form",
|
|
|
|
|
"view_mode":"form",
|
|
|
|
|
"target":"new"
|
|
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-06-16 15:17:22 +00:00
|
|
|
|
openerp.base.form.SelectCreatePopup = openerp.base.BaseWidget.extend({
|
|
|
|
|
identifier_prefix: "selectcreatepopup",
|
|
|
|
|
template: "SelectCreatePopup",
|
2011-06-15 15:04:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* options:
|
|
|
|
|
* - initial_ids
|
|
|
|
|
* - initial_view: form or search (default search)
|
|
|
|
|
* - disable_multiple_selection
|
2011-06-16 16:37:09 +00:00
|
|
|
|
* - alternative_form_view
|
2011-06-23 16:57:17 +00:00
|
|
|
|
* - auto_create (default true)
|
2011-06-15 15:04:40 +00:00
|
|
|
|
*/
|
2011-06-17 08:41:33 +00:00
|
|
|
|
select_element: function(model, options, domain, context) {
|
2011-05-03 16:17:25 +00:00
|
|
|
|
this.model = model;
|
2011-06-17 12:08:34 +00:00
|
|
|
|
this.domain = domain || [];
|
|
|
|
|
this.context = context || {};
|
2011-06-23 16:57:17 +00:00
|
|
|
|
this.options = _.defaults(options || {}, {"initial_view": "search", "auto_create": true});
|
2011-06-15 15:04:40 +00:00
|
|
|
|
this.initial_ids = this.options.initial_ids;
|
2011-05-27 15:10:00 +00:00
|
|
|
|
jQuery(this.render()).dialog({title: '',
|
2011-05-03 16:17:25 +00:00
|
|
|
|
modal: true,
|
|
|
|
|
minWidth: 800});
|
|
|
|
|
this.start();
|
2011-05-09 10:05:41 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
2011-05-09 11:52:33 +00:00
|
|
|
|
this._super();
|
2011-06-23 16:57:17 +00:00
|
|
|
|
this.dataset = new openerp.base.ReadOnlyDataSetSearch(this.session, this.model,
|
2011-06-17 14:19:45 +00:00
|
|
|
|
this.context, this.domain);
|
2011-06-23 16:57:17 +00:00
|
|
|
|
if (this.options.initial_view == "search") {
|
2011-06-09 13:20:04 +00:00
|
|
|
|
this.setup_search_view();
|
|
|
|
|
} else { // "form"
|
|
|
|
|
this.new_object();
|
2011-05-16 11:02:42 +00:00
|
|
|
|
}
|
2011-05-09 10:05:41 +00:00
|
|
|
|
},
|
|
|
|
|
setup_search_view: function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
if (this.searchview) {
|
|
|
|
|
this.searchview.stop();
|
|
|
|
|
}
|
2011-05-24 11:30:13 +00:00
|
|
|
|
this.searchview = new openerp.base.SearchView(null, this.session,
|
2011-06-15 15:04:40 +00:00
|
|
|
|
this.element_id + "_search", this.dataset, false, {
|
2011-06-15 15:40:15 +00:00
|
|
|
|
"selectable": !this.options.disable_multiple_selection,
|
|
|
|
|
"deletable": false
|
2011-06-15 15:04:40 +00:00
|
|
|
|
});
|
2011-05-09 11:52:33 +00:00
|
|
|
|
this.searchview.on_search.add(function(domains, contexts, groupbys) {
|
2011-06-09 13:20:04 +00:00
|
|
|
|
if (self.initial_ids) {
|
2011-06-17 14:19:45 +00:00
|
|
|
|
self.view_list.do_search.call(self,[[["id", "in", self.initial_ids]]],
|
|
|
|
|
contexts, groupbys);
|
2011-06-09 13:20:04 +00:00
|
|
|
|
self.initial_ids = undefined;
|
|
|
|
|
} else {
|
|
|
|
|
self.view_list.do_search.call(self, domains, contexts, groupbys);
|
|
|
|
|
}
|
2011-05-09 11:52:33 +00:00
|
|
|
|
});
|
2011-05-10 10:30:46 +00:00
|
|
|
|
this.searchview.on_loaded.add_last(function () {
|
|
|
|
|
var $buttons = self.searchview.$element.find(".oe_search-view-buttons");
|
2011-06-16 15:17:22 +00:00
|
|
|
|
$buttons.append(QWeb.render("SelectCreatePopup.search.buttons"));
|
|
|
|
|
var $cbutton = $buttons.find(".oe_selectcreatepopup-search-close");
|
2011-05-10 10:30:46 +00:00
|
|
|
|
$cbutton.click(function() {
|
|
|
|
|
self.stop();
|
|
|
|
|
});
|
2011-06-16 15:17:22 +00:00
|
|
|
|
var $sbutton = $buttons.find(".oe_selectcreatepopup-search-select");
|
2011-06-15 15:04:40 +00:00
|
|
|
|
if(self.options.disable_multiple_selection) {
|
|
|
|
|
$sbutton.hide();
|
|
|
|
|
}
|
|
|
|
|
$sbutton.click(function() {
|
|
|
|
|
self.on_select_elements(self.selected_ids);
|
|
|
|
|
});
|
2011-06-21 12:12:22 +00:00
|
|
|
|
self.view_list = new openerp.base.form.SelectCreateListView( null, self.session,
|
2011-05-24 11:30:13 +00:00
|
|
|
|
self.element_id + "_view_list", self.dataset, false,
|
|
|
|
|
{'deletable': false});
|
2011-05-10 12:15:51 +00:00
|
|
|
|
self.view_list.popup = self;
|
|
|
|
|
self.view_list.do_show();
|
2011-06-09 13:20:04 +00:00
|
|
|
|
self.view_list.start().then(function() {
|
|
|
|
|
self.searchview.do_search();
|
2011-05-10 12:15:51 +00:00
|
|
|
|
});
|
2011-05-10 10:30:46 +00:00
|
|
|
|
});
|
|
|
|
|
this.searchview.start();
|
2011-05-09 10:05:41 +00:00
|
|
|
|
},
|
2011-06-23 16:57:17 +00:00
|
|
|
|
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]);
|
|
|
|
|
});
|
|
|
|
|
},
|
2011-06-15 15:04:40 +00:00
|
|
|
|
on_select_elements: function(element_ids) {
|
|
|
|
|
},
|
|
|
|
|
on_click_element: function(ids) {
|
|
|
|
|
this.selected_ids = ids || [];
|
|
|
|
|
if(this.selected_ids.length > 0) {
|
2011-06-16 15:17:22 +00:00
|
|
|
|
this.$element.find(".oe_selectcreatepopup-search-select").removeAttr('disabled');
|
2011-06-15 15:04:40 +00:00
|
|
|
|
} else {
|
2011-06-16 15:17:22 +00:00
|
|
|
|
this.$element.find(".oe_selectcreatepopup-search-select").attr('disabled', "disabled");
|
2011-06-15 15:04:40 +00:00
|
|
|
|
}
|
2011-05-10 10:30:46 +00:00
|
|
|
|
},
|
|
|
|
|
new_object: function() {
|
|
|
|
|
var self = this;
|
2011-06-09 13:20:04 +00:00
|
|
|
|
if (this.searchview) {
|
|
|
|
|
this.searchview.hide();
|
|
|
|
|
}
|
|
|
|
|
if (this.view_list) {
|
|
|
|
|
this.view_list.$element.hide();
|
|
|
|
|
}
|
2011-05-10 10:30:46 +00:00
|
|
|
|
this.dataset.index = null;
|
2011-05-24 11:30:13 +00:00
|
|
|
|
this.view_form = new openerp.base.FormView(null, this.session,
|
2011-05-10 10:30:46 +00:00
|
|
|
|
this.element_id + "_view_form", this.dataset, false);
|
2011-06-16 16:37:09 +00:00
|
|
|
|
if (this.options.alternative_form_view) {
|
|
|
|
|
this.view_form.set_embedded_view(this.options.alternative_form_view);
|
|
|
|
|
}
|
2011-05-10 10:30:46 +00:00
|
|
|
|
this.view_form.start();
|
|
|
|
|
this.view_form.on_loaded.add_last(function() {
|
|
|
|
|
var $buttons = self.view_form.$element.find(".oe_form_buttons");
|
2011-06-16 15:17:22 +00:00
|
|
|
|
$buttons.html(QWeb.render("SelectCreatePopup.form.buttons"));
|
|
|
|
|
var $nbutton = $buttons.find(".oe_selectcreatepopup-form-save");
|
2011-05-10 10:30:46 +00:00
|
|
|
|
$nbutton.click(function() {
|
|
|
|
|
self.view_form.do_save();
|
|
|
|
|
});
|
2011-06-16 15:17:22 +00:00
|
|
|
|
var $cbutton = $buttons.find(".oe_selectcreatepopup-form-close");
|
2011-05-10 10:30:46 +00:00
|
|
|
|
$cbutton.click(function() {
|
|
|
|
|
self.stop();
|
|
|
|
|
});
|
|
|
|
|
});
|
2011-06-23 16:57:17 +00:00
|
|
|
|
this.dataset.on_create.add(this.on_create);
|
2011-05-10 10:30:46 +00:00
|
|
|
|
this.view_form.do_show();
|
2011-05-03 16:17:25 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-06-21 12:12:22 +00:00
|
|
|
|
openerp.base.form.SelectCreateListView = openerp.base.ListView.extend({
|
2011-06-15 15:06:58 +00:00
|
|
|
|
do_add_record: function () {
|
|
|
|
|
this.popup.new_object();
|
|
|
|
|
},
|
2011-05-24 08:35:58 +00:00
|
|
|
|
select_record: function(index) {
|
2011-06-15 15:04:40 +00:00
|
|
|
|
this.popup.on_select_elements([this.dataset.ids[index]]);
|
|
|
|
|
},
|
|
|
|
|
do_select: function(ids, records) {
|
|
|
|
|
this._super(ids, records);
|
|
|
|
|
this.popup.on_click_element(ids);
|
2011-05-09 11:52:33 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 08:28:38 +00:00
|
|
|
|
openerp.base.form.FieldReference = openerp.base.form.Field.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.template = "FieldReference";
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-05-19 12:58:45 +00:00
|
|
|
|
openerp.base.form.FieldBinary = openerp.base.form.Field.extend({
|
2011-05-12 15:22:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
2011-05-18 22:36:16 +00:00
|
|
|
|
this.iframe = this.element_id + '_iframe';
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.binary_value = false;
|
2011-05-12 15:22:48 +00:00
|
|
|
|
},
|
2011-05-18 15:33:56 +00:00
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2011-05-18 22:36:16 +00:00
|
|
|
|
this.$element.find('input.oe-binary-file').change(this.on_file_change);
|
2011-05-23 13:38:40 +00:00
|
|
|
|
this.$element.find('button.oe-binary-file-save').click(this.on_save_as);
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.$element.find('.oe-binary-file-clear').click(this.on_clear);
|
2011-05-18 15:33:56 +00:00
|
|
|
|
},
|
|
|
|
|
set_value_from_ui: function() {
|
|
|
|
|
},
|
2011-05-19 12:58:45 +00:00
|
|
|
|
human_filesize : function(size) {
|
|
|
|
|
var units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
|
|
|
var i = 0;
|
|
|
|
|
while (size >= 1024) {
|
|
|
|
|
size /= 1024;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return size.toFixed(2) + ' ' + units[i];
|
2011-05-19 10:17:26 +00:00
|
|
|
|
},
|
2011-05-23 13:38:40 +00:00
|
|
|
|
on_file_change: function(e) {
|
2011-05-19 10:17:26 +00:00
|
|
|
|
// 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
|
2011-05-18 22:36:16 +00:00
|
|
|
|
window[this.iframe] = this.on_file_uploaded;
|
2011-05-23 13:38:40 +00:00
|
|
|
|
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.toggle_progress();
|
|
|
|
|
}
|
2011-05-18 22:36:16 +00:00
|
|
|
|
},
|
2011-05-19 11:12:37 +00:00
|
|
|
|
toggle_progress: function() {
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.$element.find('.oe-binary-progress, .oe-binary').toggle();
|
2011-05-18 22:36:16 +00:00
|
|
|
|
},
|
2011-05-19 12:58:45 +00:00
|
|
|
|
on_file_uploaded: function(size, name, content_type, file_base64) {
|
2011-05-18 22:36:16 +00:00
|
|
|
|
delete(window[this.iframe]);
|
|
|
|
|
if (size === false) {
|
|
|
|
|
this.notification.warn("File Upload", "There was a problem while uploading your file");
|
|
|
|
|
// TODO: use openerp web exception handler
|
|
|
|
|
console.log("Error while uploading file : ", name);
|
|
|
|
|
} else {
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.on_file_uploaded_and_valid.apply(this, arguments);
|
2011-05-19 10:17:26 +00:00
|
|
|
|
this.on_ui_change();
|
2011-05-18 22:36:16 +00:00
|
|
|
|
}
|
2011-05-19 11:12:37 +00:00
|
|
|
|
this.toggle_progress();
|
2011-05-18 22:36:16 +00:00
|
|
|
|
},
|
2011-05-19 12:58:45 +00:00
|
|
|
|
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
|
|
|
|
|
},
|
2011-05-23 13:38:40 +00:00
|
|
|
|
on_save_as: function() {
|
2011-05-26 21:38:11 +00:00
|
|
|
|
if (!this.view.datarecord.id) {
|
|
|
|
|
this.notification.warn("Can't save file", "The record has not yet been saved");
|
|
|
|
|
} else {
|
|
|
|
|
var url = '/base/binary/saveas?session_id=' + this.session.session_id + '&model=' +
|
|
|
|
|
this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name +
|
|
|
|
|
'&fieldname=' + (this.node.attrs.filename || '') + '&t=' + (new Date().getTime())
|
|
|
|
|
window.open(url);
|
|
|
|
|
}
|
2011-05-23 13:38:40 +00:00
|
|
|
|
},
|
2011-05-18 15:33:56 +00:00
|
|
|
|
on_clear: function() {
|
|
|
|
|
if (this.value !== false) {
|
|
|
|
|
this.value = false;
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.binary_value = false;
|
2011-05-18 15:33:56 +00:00
|
|
|
|
this.on_ui_change();
|
|
|
|
|
}
|
2011-05-19 10:17:26 +00:00
|
|
|
|
return false;
|
2011-05-19 12:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
openerp.base.form.FieldBinaryFile = openerp.base.form.FieldBinary.extend({
|
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.template = "FieldBinaryFile";
|
|
|
|
|
},
|
|
|
|
|
set_value: function(value) {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
var show_value = (value != null && value !== false) ? value : '';
|
|
|
|
|
this.$element.find('input').eq(0).val(show_value);
|
|
|
|
|
},
|
|
|
|
|
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
|
|
|
|
|
this.value = file_base64;
|
|
|
|
|
this.binary_value = true;
|
|
|
|
|
var show_value = this.human_filesize(size);
|
|
|
|
|
this.$element.find('input').eq(0).val(show_value);
|
|
|
|
|
this.set_filename(name);
|
|
|
|
|
},
|
|
|
|
|
set_filename: function(value) {
|
|
|
|
|
var filename = this.node.attrs.filename;
|
|
|
|
|
if (this.view.fields[filename]) {
|
|
|
|
|
this.view.fields[filename].set_value(value);
|
2011-05-19 13:45:35 +00:00
|
|
|
|
this.view.fields[filename].on_ui_change();
|
2011-05-19 12:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
on_clear: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$element.find('input').eq(0).val('');
|
|
|
|
|
this.set_filename('');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
openerp.base.form.FieldBinaryImage = openerp.base.form.FieldBinary.extend({
|
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
|
|
|
|
this.template = "FieldBinaryImage";
|
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$image = this.$element.find('img.oe-binary-image');
|
|
|
|
|
},
|
|
|
|
|
set_image_maxwidth: function() {
|
|
|
|
|
this.$image.css('max-width', this.$element.width());
|
|
|
|
|
},
|
|
|
|
|
on_file_change: function() {
|
|
|
|
|
this.set_image_maxwidth();
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
},
|
|
|
|
|
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
|
|
|
|
|
this.value = file_base64;
|
|
|
|
|
this.binary_value = true;
|
|
|
|
|
this.$image.attr('src', 'data:' + (content_type || 'image/png') + ';base64,' + file_base64);
|
|
|
|
|
},
|
|
|
|
|
on_clear: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$image.attr('src', '/base/static/src/img/placeholder.png');
|
2011-05-18 15:33:56 +00:00
|
|
|
|
},
|
2011-05-12 15:22:48 +00:00
|
|
|
|
set_value: function(value) {
|
|
|
|
|
this._super.apply(this, arguments);
|
2011-05-19 10:17:26 +00:00
|
|
|
|
this.set_image_maxwidth();
|
2011-05-23 14:52:19 +00:00
|
|
|
|
var url = '/base/binary/image?session_id=' + this.session.session_id + '&model=' +
|
2011-05-18 15:33:56 +00:00
|
|
|
|
this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name + '&t=' + (new Date().getTime())
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.$image.attr('src', url);
|
2011-05-12 15:22:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 10:57:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* Registry of form widgets, called by :js:`openerp.base.FormView`
|
|
|
|
|
*/
|
|
|
|
|
openerp.base.form.widgets = new openerp.base.Registry({
|
2011-06-03 09:43:02 +00:00
|
|
|
|
'frame' : 'openerp.base.form.WidgetFrame',
|
2011-03-31 10:57:51 +00:00
|
|
|
|
'group' : 'openerp.base.form.WidgetFrame',
|
|
|
|
|
'notebook' : 'openerp.base.form.WidgetNotebook',
|
|
|
|
|
'separator' : 'openerp.base.form.WidgetSeparator',
|
|
|
|
|
'label' : 'openerp.base.form.WidgetLabel',
|
|
|
|
|
'button' : 'openerp.base.form.WidgetButton',
|
|
|
|
|
'char' : 'openerp.base.form.FieldChar',
|
|
|
|
|
'email' : 'openerp.base.form.FieldEmail',
|
|
|
|
|
'url' : 'openerp.base.form.FieldUrl',
|
|
|
|
|
'text' : 'openerp.base.form.FieldText',
|
2011-04-12 12:02:58 +00:00
|
|
|
|
'text_wiki' : 'openerp.base.form.FieldText',
|
2011-03-31 10:57:51 +00:00
|
|
|
|
'date' : 'openerp.base.form.FieldDate',
|
|
|
|
|
'datetime' : 'openerp.base.form.FieldDatetime',
|
|
|
|
|
'selection' : 'openerp.base.form.FieldSelection',
|
|
|
|
|
'many2one' : 'openerp.base.form.FieldMany2One',
|
|
|
|
|
'many2many' : 'openerp.base.form.FieldMany2Many',
|
|
|
|
|
'one2many' : 'openerp.base.form.FieldOne2Many',
|
|
|
|
|
'one2many_list' : 'openerp.base.form.FieldOne2Many',
|
|
|
|
|
'reference' : 'openerp.base.form.FieldReference',
|
|
|
|
|
'boolean' : 'openerp.base.form.FieldBoolean',
|
2011-04-07 06:07:07 +00:00
|
|
|
|
'float' : 'openerp.base.form.FieldFloat',
|
|
|
|
|
'integer': 'openerp.base.form.FieldFloat',
|
2011-04-12 09:26:31 +00:00
|
|
|
|
'progressbar': 'openerp.base.form.FieldProgressBar',
|
2011-05-12 15:22:48 +00:00
|
|
|
|
'float_time': 'openerp.base.form.FieldFloatTime',
|
2011-05-19 12:58:45 +00:00
|
|
|
|
'image': 'openerp.base.form.FieldBinaryImage',
|
|
|
|
|
'binary': 'openerp.base.form.FieldBinaryFile'
|
2011-03-31 10:57:51 +00:00
|
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|