[FIX] Solve Internal error during Upload/Add image in form view

This commit is contained in:
chintan-ambaliya 2018-01-22 14:43:10 +05:30
parent 32d5a77281
commit 31f5af381e
3 changed files with 27 additions and 22 deletions

View File

@ -16,10 +16,10 @@ var FormRenderer = BasicRenderer.extend({
events: _.extend({}, BasicRenderer.prototype.events, { events: _.extend({}, BasicRenderer.prototype.events, {
'click .o_notification_box .oe_field_translate': '_onTranslate', 'click .o_notification_box .oe_field_translate': '_onTranslate',
'click .oe_title, .o_inner_group': '_onClick', 'click .oe_title, .o_inner_group': '_onClick',
'change .o_input_file': '_onChangeInputFile', 'change #multi_attachment .o_input_file': '_onChangeInputFile',
'dragover .o_form_sheet_bg': '_onDragEnterForm', 'dragover .o_form_sheet_bg': '_onDragEnterForm',
'dragleave .o_input_file': '_onDragLeaveForm', 'dragleave #multi_attachment .o_input_file': '_onDragLeaveForm',
'drop .o_input_file': '_onDropFile', 'drop #multi_attachment .o_input_file': '_onDropFile',
}), }),
/** /**
* @override * @override
@ -27,7 +27,8 @@ var FormRenderer = BasicRenderer.extend({
init: function (parent, state, params) { init: function (parent, state, params) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.idsForLabels = {}; this.idsForLabels = {};
if (this.activeActions && this.activeActions.edit) { this.is_editable = params.editable;
if (this.is_editable) {
this.fileuploadId = _.uniqueId('oe_fileupload'); this.fileuploadId = _.uniqueId('oe_fileupload');
$(window).on(this.fileuploadId, this._onFileUploaded.bind(this)); $(window).on(this.fileuploadId, this._onFileUploaded.bind(this));
} }
@ -850,38 +851,38 @@ var FormRenderer = BasicRenderer.extend({
}); });
this.$el.find('.o_notebook ul.nav-tabs').tabCollapse(); this.$el.find('.o_notebook ul.nav-tabs').tabCollapse();
// for Drag and Drop Attachment(s) // for Drag and Drop Attachment(s)
if (this.activeActions.edit) { if (this.is_editable) {
this.$attach_form = $(qweb.render('DragAndDropAttachment', {widget: this})); this.$attach_form = $(qweb.render('DragAndDropAttachment', {widget: this}));
this.$el.find('.o_form_sheet_bg').prepend(this.$attach_form); this.$el.find('.o_form_sheet_bg').prepend(this.$attach_form);
this.$el.find('.o_form_sheet_bg .o_input_file').addClass('hide'); this.$el.find('.o_form_sheet_bg #multi_attachment .o_input_file').addClass('hide');
} }
}, },
_onChangeInputFile: function (event) { _onChangeInputFile: function (event) {
if (!this.activeActions.edit) return; if (!this.is_editable) return;
var $event = $(event.target); var $event = $(event.target);
if ($event.val() !== '') { if ($event.val() !== '') {
var $binaryForm = this.$el.find('.o_form_sheet_bg form.o_form_binary_form'); var $binaryForm = this.$el.find('.o_form_sheet_bg #multi_attachment form.o_form_binary_form');
$binaryForm.submit(); $binaryForm.submit();
framework.blockUI(); framework.blockUI();
} }
}, },
_onDragEnterForm: function (e) { _onDragEnterForm: function (e) {
if (!this.activeActions.edit) return; if (!this.is_editable) return;
var $input = this.$el.find('.o_form_sheet_bg .o_input_file'); var $input = this.$el.find('.o_form_sheet_bg #multi_attachment .o_input_file');
$input.removeClass('hide').addClass('f_attachment_input'); $input.removeClass('hide').addClass('f_attachment_input');
$input.parent().parent().addClass('f_attachment') $input.parent().parent().addClass('f_attachment')
}, },
_onDragLeaveForm: function (e) { _onDragLeaveForm: function (e) {
if (!this.activeActions.edit) return; if (!this.is_editable) return;
var $input = this.$el.find('.o_form_sheet_bg .o_input_file'); var $input = this.$el.find('.o_form_sheet_bg #multi_attachment .o_input_file');
$input.addClass('hide').removeClass('f_attachment_input'); $input.addClass('hide').removeClass('f_attachment_input');
$input.parent().parent().removeClass('f_attachment') $input.parent().parent().removeClass('f_attachment')
}, },
_onDropFile: function (event) { _onDropFile: function (event) {
if (!this.activeActions.edit) return; if (!this.is_editable) return;
var $event = $(event.target); var $event = $(event.target);
if ($event.val() !== '') { if ($event.val() !== '') {
var $binaryForm = this.$el.find('.o_form_sheet_bg form.o_form_binary_form'); var $binaryForm = this.$el.find('.o_form_sheet_bg #multi_attachment form.o_form_binary_form');
$binaryForm.submit(); $binaryForm.submit();
framework.blockUI(); framework.blockUI();
} }
@ -898,7 +899,7 @@ var FormRenderer = BasicRenderer.extend({
framework.unblockUI(); framework.unblockUI();
this._getAttachments().then(function (attachments) { this._getAttachments().then(function (attachments) {
self.trigger_up('update_sidebar_attachments', {files: attachments}); self.trigger_up('update_sidebar_attachments', {files: attachments});
var $input = self.$el.find('.o_form_sheet_bg .o_input_file'); var $input = self.$el.find('.o_form_sheet_bg #multi_attachment .o_input_file');
$input.addClass('hide').removeClass('f_attachment_input'); $input.addClass('hide').removeClass('f_attachment_input');
$input.parent().parent().removeClass('f_attachment') $input.parent().parent().removeClass('f_attachment')
}); });

View File

@ -40,6 +40,8 @@ var FormView = BasicView.extend({
this.controllerParams.mode = mode; this.controllerParams.mode = mode;
this.rendererParams.mode = mode; this.rendererParams.mode = mode;
this.rendererParams.editable = this.controllerParams.activeActions.edit;
}, },
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------

View File

@ -37,6 +37,7 @@
</t> </t>
<t t-name="DragAndDropAttachment"> <t t-name="DragAndDropAttachment">
<div id="multi_attachment">
<t t-call="HiddenInputFile"> <t t-call="HiddenInputFile">
<t t-set="fileupload_id" t-value="widget.fileuploadId"/> <t t-set="fileupload_id" t-value="widget.fileuploadId"/>
<t t-set="fileupload_action" t-translation="off">/web/binary/upload_attachment</t> <t t-set="fileupload_action" t-translation="off">/web/binary/upload_attachment</t>
@ -44,5 +45,6 @@
<input type="hidden" name="model" t-att-value="widget.state.model"/> <input type="hidden" name="model" t-att-value="widget.state.model"/>
<input type="hidden" name="id" t-att-value="widget.state.res_id"/> <input type="hidden" name="id" t-att-value="widget.state.res_id"/>
</t> </t>
</div>
</t> </t>
</templates> </templates>