var accounting_file_form = {
    settings: {
        file_type_autocomplete_url: '',
        tmpFileProcessRemoveUrl: null,
        tmpFileProcessUrl: null,
    },
    init: function() {
        this.initAutocomplete();
        this.uploadFile();
    },
    initAutocomplete: function() {
        global.autocomplete.bind(this.settings.file_type_autocomplete_url, '#accountingFile_fileType_desc', '#accountingFile_fileType');
    },
    uploadFile: function () {
        if(jQ('#accounting-file-dropzone').length > 0) {
            Dropzone.autoDiscover = false;

            let uploadZone = new Dropzone('#accounting-file-dropzone', {
                url: accounting_file_form.settings.tmpFileProcessUrl,
                acceptedFiles: 'image/*,application/pdf,.docx,.xls,.xlsx',
                maxFiles: null,
                dictDefaultMessage: 'Drop image file here or click to upload.',
                addRemoveLinks: true,
            });
            uploadZone.on('sending', function (file, xhr, formData) {
                formData.append('tmpFileName', jQ('#accountingFile_file_temp_name').val())
            });
            uploadZone.on("removedfile", function (file) {
                let fileName = file.name,
                    file_temp_name = jQ('#accountingFile_file_temp_name').val(),
                    settings = {
                        url: accounting_file_form.settings.tmpFileProcessRemoveUrl,
                        data: {
                            fileName,
                            file_temp_name
                        }
                    };
                global.ajax(settings, 'removeTmpFile');
            });
        }
    },
};