[IMP] web form: one2many_binary accept all values one2any and default values
bzr revid: chm@openerp.com-20121115122834-5vo00jagzvysti1a
This commit is contained in:
parent
739775253f
commit
64e46a1e0e
|
@ -5018,17 +5018,38 @@ instance.web.form.FieldOne2ManyBinaryMultiFiles = instance.web.form.AbstractFiel
|
||||||
this.$el.on('change', 'input.oe_form_binary_file', this.on_file_change );
|
this.$el.on('change', 'input.oe_form_binary_file', this.on_file_change );
|
||||||
},
|
},
|
||||||
set_value: function(value_) {
|
set_value: function(value_) {
|
||||||
|
var value_ = value_ || [];
|
||||||
var self = this;
|
var self = this;
|
||||||
if (value_ && typeof value_[0] != 'object') {
|
var ids = [];
|
||||||
this.ds_file.call('read', [value_, ['name', 'datas_fname']]).done(function(data) {
|
_.each(value_, function(command) {
|
||||||
_.each(data, function (val) {
|
if (isNaN(command) && command.id == undefined) {
|
||||||
val.no_unlink = true;
|
switch (command[0]) {
|
||||||
});
|
case commands.CREATE:
|
||||||
self.set_value(data);
|
ids = ids.concat(command[2]);
|
||||||
});
|
return;
|
||||||
} else {
|
case commands.REPLACE_WITH:
|
||||||
this._super(value_);
|
ids = ids.concat(command[2]);
|
||||||
}
|
return;
|
||||||
|
case commands.UPDATE:
|
||||||
|
ids = ids.concat(command[2]);
|
||||||
|
return;
|
||||||
|
case commands.LINK_TO:
|
||||||
|
ids = ids.concat(command[1]);
|
||||||
|
return;
|
||||||
|
case commands.DELETE:
|
||||||
|
ids = _.filter(ids, function (id) { return id != command[1];});
|
||||||
|
self.ds_file.unlink(command[1]);
|
||||||
|
return;
|
||||||
|
case commands.DELETE_ALL:
|
||||||
|
self.ds_file.unlink(ids);
|
||||||
|
ids = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ids.push(command);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this._super( ids );
|
||||||
},
|
},
|
||||||
get_value: function() {
|
get_value: function() {
|
||||||
return _.map(this.get('value'), function (value) { return commands.link_to( value.id ); });
|
return _.map(this.get('value'), function (value) { return commands.link_to( value.id ); });
|
||||||
|
@ -5036,15 +5057,47 @@ instance.web.form.FieldOne2ManyBinaryMultiFiles = instance.web.form.AbstractFiel
|
||||||
get_file_url: function (attachment) {
|
get_file_url: function (attachment) {
|
||||||
return this.session.url('/web/binary/saveas', {model: 'ir.attachment', field: 'datas', filename_field: 'datas_fname', id: attachment['id']});
|
return this.session.url('/web/binary/saveas', {model: 'ir.attachment', field: 'datas', filename_field: 'datas_fname', id: attachment['id']});
|
||||||
},
|
},
|
||||||
|
read_name_values : function () {
|
||||||
|
var self = this;
|
||||||
|
// select the list of id for a get_name
|
||||||
|
var values = [];
|
||||||
|
_.each(this.get('value'), function (val) {
|
||||||
|
if (typeof val != 'object') {
|
||||||
|
values.push(val);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// send request for get_name
|
||||||
|
if (values.length) {
|
||||||
|
return this.ds_file.call('read', [values, ['id', 'name', 'datas_fname']]).done(function (datas) {
|
||||||
|
_.each(datas, function (data) {
|
||||||
|
data.no_unlink = true;
|
||||||
|
data.url = self.session.url('/web/binary/saveas', {model: 'ir.attachment', field: 'datas', filename_field: 'datas_fname', id: data.id});
|
||||||
|
|
||||||
|
_.each(self.get('value'), function (val, key) {
|
||||||
|
if(val == data.id) {
|
||||||
|
self.get('value')[key] = data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return $.when(this.get('value'));
|
||||||
|
}
|
||||||
|
},
|
||||||
render_value: function () {
|
render_value: function () {
|
||||||
var render = $(instance.web.qweb.render('FieldBinaryFileUploader.files', {'widget': this}));
|
var self = this;
|
||||||
render.on('click', '.oe_delete', _.bind(this.on_file_delete, this));
|
this.read_name_values().then(function (datas) {
|
||||||
this.$('.oe_placeholder_files, .oe_attachments').replaceWith( render );
|
|
||||||
|
|
||||||
// reinit input type file
|
var render = $(instance.web.qweb.render('FieldBinaryFileUploader.files', {'widget': self}));
|
||||||
var $input = this.$('input.oe_form_binary_file');
|
render.on('click', '.oe_delete', _.bind(self.on_file_delete, self));
|
||||||
$input.after($input.clone(true)).remove();
|
self.$('.oe_placeholder_files, .oe_attachments').replaceWith( render );
|
||||||
this.$(".oe_fileupload").show();
|
|
||||||
|
// reinit input type file
|
||||||
|
var $input = self.$('input.oe_form_binary_file');
|
||||||
|
$input.after($input.clone(true)).remove();
|
||||||
|
self.$(".oe_fileupload").show();
|
||||||
|
|
||||||
|
});
|
||||||
},
|
},
|
||||||
on_file_change: function (event) {
|
on_file_change: function (event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
Loading…
Reference in New Issue