summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@openerp.com>2012-11-15 13:28:34 +0100
committerChristophe Matthieu <chm@openerp.com>2012-11-15 13:28:34 +0100
commit64e46a1e0ed5091f41fe7f332d905e7bd2ef00dc (patch)
tree72902c29c8411256b0565bc958cefa476d4b3027 /addons/web/static/src
parent739775253f2d0f9e4fc9bdfd197369a14d72223a (diff)
[IMP] web form: one2many_binary accept all values one2any and default values
bzr revid: chm@openerp.com-20121115122834-5vo00jagzvysti1a
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/view_form.js89
1 files changed, 71 insertions, 18 deletions
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 1be42849a96..e9f87e2ee26 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -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 );
},
set_value: function(value_) {
+ var value_ = value_ || [];
var self = this;
- if (value_ && typeof value_[0] != 'object') {
- this.ds_file.call('read', [value_, ['name', 'datas_fname']]).done(function(data) {
- _.each(data, function (val) {
- val.no_unlink = true;
- });
- self.set_value(data);
- });
- } else {
- this._super(value_);
- }
+ var ids = [];
+ _.each(value_, function(command) {
+ if (isNaN(command) && command.id == undefined) {
+ switch (command[0]) {
+ case commands.CREATE:
+ ids = ids.concat(command[2]);
+ return;
+ case commands.REPLACE_WITH:
+ 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() {
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) {
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 () {
- var render = $(instance.web.qweb.render('FieldBinaryFileUploader.files', {'widget': this}));
- render.on('click', '.oe_delete', _.bind(this.on_file_delete, this));
- this.$('.oe_placeholder_files, .oe_attachments').replaceWith( render );
-
- // reinit input type file
- var $input = this.$('input.oe_form_binary_file');
- $input.after($input.clone(true)).remove();
- this.$(".oe_fileupload").show();
+ var self = this;
+ this.read_name_values().then(function (datas) {
+
+ var render = $(instance.web.qweb.render('FieldBinaryFileUploader.files', {'widget': self}));
+ render.on('click', '.oe_delete', _.bind(self.on_file_delete, self));
+ self.$('.oe_placeholder_files, .oe_attachments').replaceWith( render );
+
+ // 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) {
event.stopPropagation();