app/assets/javascripts/activeadmin/trumbowyg/plugins/upload/trumbowyg.upload.js in activeadmin_trumbowyg-0.2.10 vs app/assets/javascripts/activeadmin/trumbowyg/plugins/upload/trumbowyg.upload.js in activeadmin_trumbowyg-0.2.12
- old
+ new
@@ -19,11 +19,11 @@
fileFieldName: 'fileToUpload',
data: [], // Additional data for ajax [{name: 'key', value: 'value'}]
headers: {}, // Additional headers
xhrFields: {}, // Additional fields
urlPropertyName: 'file', // How to get url from the json response (for instance 'url' for {url: ....})
- statusPropertyName: 'success', // How to get status from the json response
+ statusPropertyName: 'success', // How to get status from the json response
success: undefined, // Success callback: function (data, trumbowyg, $modal, values) {}
error: undefined, // Error callback: function () {}
imageWidthModalEdit: false // Add ability to edit image width
};
@@ -51,70 +51,75 @@
en: {
upload: 'Upload',
file: 'File',
uploadError: 'Error'
},
+ cs: {
+ upload: 'Nahrát obrázek',
+ file: 'Soubor',
+ uploadError: 'Chyba'
+ },
da: {
upload: 'Upload',
file: 'Fil',
uploadError: 'Fejl'
},
de: {
upload: 'Hochladen',
file: 'Datei',
uploadError: 'Fehler'
},
- sk: {
- upload: 'Nahrať',
- file: 'Súbor',
- uploadError: 'Chyba'
- },
fr: {
upload: 'Envoi',
file: 'Fichier',
uploadError: 'Erreur'
},
- cs: {
- upload: 'Nahrát obrázek',
- file: 'Soubor',
- uploadError: 'Chyba'
+ hu: {
+ upload: 'Feltöltés',
+ file: 'Fájl',
+ uploadError: 'Hiba'
},
- zh_cn: {
- upload: '上传',
- file: '文件',
- uploadError: '错误'
- },
- zh_tw: {
- upload: '上傳',
- file: '文件',
- uploadError: '錯誤'
- },
- ru: {
- upload: 'Загрузка',
- file: 'Файл',
- uploadError: 'Ошибка'
- },
ja: {
upload: 'アップロード',
file: 'ファイル',
uploadError: 'エラー'
},
+ ko: {
+ upload: '그림 올리기',
+ file: '파일',
+ uploadError: '에러'
+ },
pt_br: {
upload: 'Enviar do local',
file: 'Arquivo',
uploadError: 'Erro'
},
+ ru: {
+ upload: 'Загрузка',
+ file: 'Файл',
+ uploadError: 'Ошибка'
+ },
+ sk: {
+ upload: 'Nahrať',
+ file: 'Súbor',
+ uploadError: 'Chyba'
+ },
tr: {
upload: 'Yükle',
file: 'Dosya',
uploadError: 'Hata'
},
- ko: {
- upload: '그림 올리기',
- file: '파일',
- uploadError: '에러'
+ zh_cn: {
+ upload: '上传',
+ file: '文件',
+ uploadError: '错误'
},
+ zh_tw: {
+ upload: '上傳',
+ file: '文件',
+ uploadError: '錯誤'
+ },
},
// jshint camelcase:true
plugins: {
upload: {
@@ -145,19 +150,27 @@
fields.width = {
value: ''
};
}
+ // Prevent multiple submissions while uploading
+ var isUploading = false;
+
var $modal = trumbowyg.openModalInsert(
// Title
trumbowyg.lang.upload,
// Fields
fields,
// Callback
function (values) {
+ if (isUploading) {
+ return;
+ }
+ isUploading = true;
+
var data = new FormData();
data.append(trumbowyg.o.plugins.upload.fileFieldName, file);
trumbowyg.o.plugins.upload.data.map(function (cur) {
data.append(cur.name, cur.value);
@@ -204,11 +217,11 @@
if (!!getDeep(data, trumbowyg.o.plugins.upload.statusPropertyName.split('.'))) {
var url = getDeep(data, trumbowyg.o.plugins.upload.urlPropertyName.split('.'));
trumbowyg.execCmd('insertImage', url, false, true);
var $img = $('img[src="' + url + '"]:not([alt])', trumbowyg.$box);
$img.attr('alt', values.alt);
- if (trumbowyg.o.imageWidthModalEdit && parseInt(values.width) > 0) {
+ if (trumbowyg.o.plugins.upload.imageWidthModalEdit && parseInt(values.width) > 0) {
$img.attr({
width: values.width
});
}
setTimeout(function () {
@@ -221,17 +234,21 @@
trumbowyg.lang[data.message]
);
trumbowyg.$c.trigger('tbwuploaderror', [trumbowyg, data]);
}
}
+
+ isUploading = false;
},
error: trumbowyg.o.plugins.upload.error || function () {
trumbowyg.addErrorOnModalField(
$('input[type=file]', $modal),
trumbowyg.lang.uploadError
);
trumbowyg.$c.trigger('tbwuploaderror', [trumbowyg]);
+
+ isUploading = false;
}
});
}
);