[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, {
'click .o_notification_box .oe_field_translate': '_onTranslate',
'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',
'dragleave .o_input_file': '_onDragLeaveForm',
'drop .o_input_file': '_onDropFile',
'dragleave #multi_attachment .o_input_file': '_onDragLeaveForm',
'drop #multi_attachment .o_input_file': '_onDropFile',
}),
/**
* @override
@ -27,7 +27,8 @@ var FormRenderer = BasicRenderer.extend({
init: function (parent, state, params) {
this._super.apply(this, arguments);
this.idsForLabels = {};
if (this.activeActions && this.activeActions.edit) {
this.is_editable = params.editable;
if (this.is_editable) {
this.fileuploadId = _.uniqueId('oe_fileupload');
$(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();
// for Drag and Drop Attachment(s)
if (this.activeActions.edit) {
if (this.is_editable) {
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 .o_input_file').addClass('hide');
this.$el.find('.o_form_sheet_bg #multi_attachment .o_input_file').addClass('hide');
}
},
_onChangeInputFile: function (event) {
if (!this.activeActions.edit) return;
if (!this.is_editable) return;
var $event = $(event.target);
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();
framework.blockUI();
}
},
_onDragEnterForm: function (e) {
if (!this.activeActions.edit) return;
var $input = this.$el.find('.o_form_sheet_bg .o_input_file');
if (!this.is_editable) return;
var $input = this.$el.find('.o_form_sheet_bg #multi_attachment .o_input_file');
$input.removeClass('hide').addClass('f_attachment_input');
$input.parent().parent().addClass('f_attachment')
},
_onDragLeaveForm: function (e) {
if (!this.activeActions.edit) return;
var $input = this.$el.find('.o_form_sheet_bg .o_input_file');
if (!this.is_editable) return;
var $input = this.$el.find('.o_form_sheet_bg #multi_attachment .o_input_file');
$input.addClass('hide').removeClass('f_attachment_input');
$input.parent().parent().removeClass('f_attachment')
},
_onDropFile: function (event) {
if (!this.activeActions.edit) return;
if (!this.is_editable) return;
var $event = $(event.target);
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();
framework.blockUI();
}
@ -898,7 +899,7 @@ var FormRenderer = BasicRenderer.extend({
framework.unblockUI();
this._getAttachments().then(function (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.parent().parent().removeClass('f_attachment')
});

View File

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

View File

@ -37,12 +37,14 @@
</t>
<t t-name="DragAndDropAttachment">
<t t-call="HiddenInputFile">
<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="multi_upload" t-value="true"/>
<input type="hidden" name="model" t-att-value="widget.state.model"/>
<input type="hidden" name="id" t-att-value="widget.state.res_id"/>
</t>
<div id="multi_attachment">
<t t-call="HiddenInputFile">
<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="multi_upload" t-value="true"/>
<input type="hidden" name="model" t-att-value="widget.state.model"/>
<input type="hidden" name="id" t-att-value="widget.state.res_id"/>
</t>
</div>
</t>
</templates>