Browse Source

Fix #258: Enhance messages to include file plural and single

Kartik Visweswaran 10 years ago
parent
commit
195e929546

+ 1 - 0
CHANGE.md

@@ -17,6 +17,7 @@ version 4.1.9
 13. (enh #252): Enhance async batch completion.
 14. (bug #253): Fix initial preview delete cache initialization.
 15. (bug #257): Fix upload single to replace thumbs correctly.
+16. (enh #258): Enhance messages to include file plural and single.
 
 version 4.1.8
 =============

+ 1 - 1
README.md

@@ -118,7 +118,7 @@ Step 1: Load the following assets in your header.
 ```html
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
 <link href="path/to/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" />
-<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
+<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
 <script src="path/to/js/fileinput.min.js"></script>
 <!-- bootstrap.js below is only needed if you wish to the feature of viewing details
      of text file preview via modal dialog -->

+ 1 - 1
examples/index.html

@@ -6,7 +6,7 @@
         <title>Krajee JQuery Plugins - &copy; Kartik</title>
         <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
         <link href="../css/fileinput.css" media="all" rel="stylesheet" type="text/css" />
-        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
+        <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
         <script src="../js/fileinput.js" type="text/javascript"></script>
         <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" type="text/javascript"></script>
     </head>

+ 1 - 1
examples/index_de.html

@@ -6,7 +6,7 @@
         <title>Krajee JQuery Plugins - &copy; Kartik</title>
         <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
         <link href="../css/fileinput.css" media="all" rel="stylesheet" type="text/css" />
-        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
+        <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
         <script src="../js/fileinput.js" type="text/javascript"></script>
         <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" type="text/javascript"></script>
     </head>

+ 24 - 11
js/fileinput.js

@@ -41,7 +41,9 @@
                     tags: obj.initialPreviewThumbTags,
                     delimiter: obj.initialPreviewDelimiter,
                     template: obj.previewGenericTemplate,
-                    msg: obj.msgSelected,
+                    msg: function(n) {
+                        return obj.getMsgSelected(n);
+                    },
                     initId: obj.previewInitId,
                     footer: obj.getLayoutTemplate('footer'),
                     isDelete: obj.initialPreviewShowDelete,
@@ -53,11 +55,12 @@
             },
             fetch: function (id) {
                 return previewCache.data[id].content.filter(function (n) {
-                    return n !== undefined;
+                    return n !== null;
                 });
             },
-            count: function (id) {
-                return !!previewCache.data[id] && !!previewCache.data[id].content ? previewCache.fetch(id).length : 0;
+            count: function (id, all) {
+                return !!previewCache.data[id] && !!previewCache.data[id].content ? 
+                    (all ? previewCache.data[id].content.length : previewCache.fetch(id).length): 0;
             },
             get: function (id, i, isDisabled) {
                 var ind = 'init_' + i, data = previewCache.data[id],
@@ -131,14 +134,14 @@
                 previewCache.data[id].config[index] = null;
             },
             out: function (id) {
-                var html = '', data = previewCache.data[id], caption, len = previewCache.count(id);
+                var html = '', data = previewCache.data[id], caption, len = previewCache.count(id, true);
                 if (len === 0) {
                     return {content: '', caption: ''};
                 }
                 for (var i = 0; i < len; i++) {
                     html += previewCache.get(id, i);
                 }
-                caption = data.msg.repl('{n}', len);
+                caption = data.msg(previewCache.count(id));
                 return {content: html, caption: caption};
             },
             footer: function (id, i, isDisabled) {
@@ -822,7 +825,7 @@
                             self.reset();
                         } else {
                             n = chk + len;
-                            cap = n > 1 ? self.msgSelected.repl('{n}', n) : filestack[0].name;
+                            cap = n > 1 ? self.getMsgSelected(n) : filestack[0].name;
                             self.setCaption(cap);
                         }
                     });
@@ -837,6 +840,10 @@
                 });
             });
         },
+        getMsgSelected: function(n) {
+            var self = this, strFiles = n === 1 ? self.fileSingle : self.filePlural;
+            return self.msgSelected.repl('{n}', n).repl('{files}', strFiles);
+        },
         renderFileFooter: function (caption, width) {
             var self = this, config = self.fileActionSettings, footer, out,
                 template = self.getLayoutTemplate('footer');
@@ -944,9 +951,13 @@
                         }                            
                     },
                     success: function (data, textStatus, jqXHR) {
+                        var n, cap;
                         if (data === undefined || data.error === undefined) {
                             previewCache.unset(self.id, index);
+                            n = previewCache.count(self.id),
+                            cap = n > 0? self.getMsgSelected(n) : '';
                             self.raise('filedeleted', [vKey, jqXHR, extraData]);
+                            self.setCaption(cap);
                         } else {
                             params.jqXHR = jqXHR;
                             params.response = data;
@@ -961,7 +972,8 @@
                             self.clearObjects($frame);
                             $frame.remove();
                             resetProgress();
-                            if (!previewCache.count(self.id) && self.getFileStack().length === 0) {
+                            if (!n && self.getFileStack().length === 0) {
+                                self.setCaption('');
                                 self.reset();
                             }
                         });
@@ -1194,6 +1206,7 @@
                     $thumb.after($newThumb).fadeOut('slow', function () {
                         $newThumb.fadeIn('slow').css('display:inline-block');
                         self.initPreviewDeletes();
+                        self.clearFileInput();
                     });
                 } else {
                     if (allFiles) {
@@ -1771,11 +1784,11 @@
             self.updateFileDetails(numFiles, false);
         },
         updateFileDetails: function (numFiles) {
-            var self = this, msgSelected = self.msgSelected, $el = self.$element, fileStack = self.getFileStack(),
+            var self = this, $el = self.$element, fileStack = self.getFileStack(),
                 name = $el.val() || (fileStack.length && fileStack[0].name) || '', label = self.slug(name),
                 n = self.isUploadable ? fileStack.length : numFiles,
                 nFiles = previewCache.count(self.id) + n,
-                log = n > 1 ? msgSelected.repl('{n}', nFiles) : label;
+                log = n > 1 ? self.getMsgSelected(nFiles) : label;
             if (self.isError) {
                 self.$previewContainer.removeClass('loading');
                 self.$previewStatus.html('');
@@ -2118,7 +2131,7 @@
         msgValidationError: 'File Upload Error',
         msgLoading: 'Loading file {index} of {files} &hellip;',
         msgProgress: 'Loading file {index} of {files} - {name} - {percent}% completed.',
-        msgSelected: '{n} files selected',
+        msgSelected: '{n} {files} selected',
         msgFoldersNotAllowed: 'Drag & drop files only! {n} folder(s) dropped were skipped.',
         dropZoneTitle: 'Drag & drop files here &hellip;'
     };

File diff suppressed because it is too large
+ 0 - 0
js/fileinput.min.js


+ 1 - 1
js/fileinput_locale_LANG.js

@@ -34,7 +34,7 @@
         msgValidationError: 'File Upload Error',
         msgLoading: 'Loading file {index} of {files} &hellip;',
         msgProgress: 'Loading file {index} of {files} - {name} - {percent}% completed.',
-        msgSelected: '{n} files selected',
+        msgSelected: '{n} {files} selected',
         msgFoldersNotAllowed: 'Drag & drop files only! Skipped {n} dropped folder(s).',
         dropZoneTitle: 'Drag & drop files here &hellip;'
     };

+ 1 - 1
js/fileinput_locale_de.js

@@ -32,7 +32,7 @@
         msgValidationError: 'Fehler beim Hochladen',
         msgLoading: 'Lade Datei {index} von {files} hoch&hellip;',
         msgProgress: 'Datei {index} von {files} - {name} - zu {percent}% fertiggestellt.',
-        msgSelected: '{n} Dateien ausgewählt',
+        msgSelected: '{n} {files} ausgewählt',
         msgFoldersNotAllowed: 'Drag & Drop funktioniert nur bei Dateien! {n} Ordner übersprungen.',
         dropZoneTitle: 'Dateien hierher ziehen &hellip;'
     };

+ 1 - 1
js/fileinput_locale_es.js

@@ -34,7 +34,7 @@
         msgValidationError: 'Error Cargando Archivo',
         msgLoading: 'Cargando archivo {index} of {files} &hellip;',
         msgProgress: 'Cargando archivo {index} of {files} - {name} - {percent}% completado.',
-        msgSelected: '{n} archivos seleccionados',
+        msgSelected: '{n} {files} seleccionados',
         msgFoldersNotAllowed: 'Arrastre y suelte únicamente archivos! Se omite {n} carpeta(s).',
         dropZoneTitle: 'Arrastre y suelte los archivos aquí &hellip;'
     };

+ 1 - 1
js/fileinput_locale_fr.js

@@ -34,7 +34,7 @@
         msgValidationError: 'Erreur lors de la transmission du fichier',
         msgLoading: 'Transmission du fichier {index} sur {files}&hellip;',
         msgProgress: 'Transmission du fichier {index} sur {files} - {name} - {percent}% faits.',
-        msgSelected: '{n} fichier(s) sélectionné(s)',
+        msgSelected: '{n} {files} sélectionné(s)',
         msgFoldersNotAllowed: 'Glissez et déposez uniquement des fichiers ! {n} répertoire(s) exclu(s).',
         dropZoneTitle: 'Glissez et déposez les fichiers ici&hellip;'
     };

+ 1 - 1
js/fileinput_locale_hu.js

@@ -34,7 +34,7 @@
         msgValidationError: 'Fájl ellenörzési hiba.',
         msgLoading: '{index} / {files} töltése &hellip;',
         msgProgress: 'Feltöltés: {index} / {files} - {name} - {percent}% kész.',
-        msgSelected: '{n} fájl kiválasztva.',
+        msgSelected: '{n} {files} kiválasztva.',
         msgFoldersNotAllowed: 'Csak fájlokat húzzon ide! Kihagyva {n} könyvtár.',
         dropZoneTitle: 'Fájlok húzása ide &hellip;'
     };

+ 1 - 1
js/fileinput_locale_it.js

@@ -36,7 +36,7 @@
         msgValidationError: 'Errore caricamento file',
         msgLoading: 'Caricamento file {index} di {files}&hellip;',
         msgProgress: 'Caricamento file {index} di {files} - {name} - {percent}% completato.',
-        msgSelected: '{n} file selezionati',
+        msgSelected: '{n} {files} selezionati',
         msgFoldersNotAllowed: 'Trascina solo file! Ignorata/e {n} cartella/e.',
         dropZoneTitle: 'Trascina i file qui&hellip;'
     };

+ 1 - 1
js/fileinput_locale_ru.js

@@ -35,7 +35,7 @@
         msgValidationError: 'Ошибка при загрузке файла',
         msgLoading: 'Загрузка файла {index} из {files} &hellip;',
         msgProgress: 'Загрузка файла {index} из {files} - {name} - {percent}% завершено.',
-        msgSelected: '{n} файл(ов) выбрано',
+        msgSelected: '{n} {files} выбрано',
         msgFoldersNotAllowed: 'Разрешено только перетаскивание файлов! Пропущено {n} папок.',
         dropZoneTitle: 'Перетащите файлы сюда &hellip;'
     };

+ 1 - 1
js/fileinput_locale_sr.js

@@ -35,7 +35,7 @@
         msgValidationError: 'Greška prilikom otpremanja fajla',
         msgLoading: 'Učitavanje datoteke {index} od {files} &hellip;',
         msgProgress: 'Učitavanje datoteke {index} od {files} - {name} - {percent}% završeno.',
-        msgSelected: '{n} datoteka je označeno',
+        msgSelected: '{n} {files} je označeno',
         msgFoldersNotAllowed: 'Moguće je prevlačiti samo datoteke! Preskočeno je {n} fascikla.',
         dropZoneTitle: 'Prevucite datoteke ovde &hellip;'
     };

+ 1 - 1
js/fileinput_locale_th.js

@@ -34,7 +34,7 @@
         msgValidationError: 'อัพโหลดไฟล์มีปัญหา',
         msgLoading: 'กำลังโหลดไฟล์ {index} จาก {files} &hellip;',
         msgProgress: 'กำลังโหลดไฟล์ {index} จาก {files} - {name} - {percent}%',
-        msgSelected: '{n} ถูกเลือกไฟล์',
+        msgSelected: '{n} {files} ถูกเลือก',
         msgFoldersNotAllowed: 'Drag & drop เฉพาะไฟล์เท่านั้น! ข้าม dropped folder จำนวน {n}',
         dropZoneTitle: 'Drag & drop ไฟล์ตรงนี้ &hellip;'
     };

+ 1 - 1
js/fileinput_locale_uk.js

@@ -35,7 +35,7 @@
         msgValidationError: 'Помилка під час загрузки файла',
         msgLoading: 'Загрузка файла {index} із {files} &hellip;',
         msgProgress: 'Загрузка файла {index} із {files} - {name} - {percent}% завершено.',
-        msgSelected: '{n} файл(ів) вибрано',
+        msgSelected: '{n} {files} вибрано',
         msgFoldersNotAllowed: 'Дозволено перетягувати тільки файли! Пропущено {n} папок.',
         dropZoneTitle: 'Перетяніть файли сюди &hellip;'
     };

+ 1 - 1
js/fileinput_locale_zh.js

@@ -35,7 +35,7 @@
         msgValidationError: '文件上传错误',
         msgLoading: '加载第 {index} 文件 共 {files} &hellip;',
         msgProgress: '加载第 {index} 文件 共 {files} - {name} - {percent}% 完成.',
-        msgSelected: '{n} 个文件选中',
+        msgSelected: '{n} {files} 选中',
         msgFoldersNotAllowed: '只支持拖拽文件! 跳过 {n} 拖拽的文件夹.',
         dropZoneTitle: '拖拽文件到这里 &hellip;',
         slugCallback: function(text) {

Some files were not shown because too many files changed in this diff