|
1185 | 1185 | self.initCaption();
|
1186 | 1186 | }
|
1187 | 1187 | },
|
| 1188 | + resetPreviewThumbs: function (isAjax) { |
| 1189 | + var self = this, out; |
| 1190 | + if (isAjax) { |
| 1191 | + self.clearPreview(); |
| 1192 | + self.filestack = []; |
| 1193 | + return; |
| 1194 | + } |
| 1195 | + if (self.hasInitialPreview()) { |
| 1196 | + out = previewCache.out(self.id); |
| 1197 | + self.$preview.html(out.content); |
| 1198 | + self.setCaption(out.caption); |
| 1199 | + self.initPreviewDeletes(); |
| 1200 | + } else { |
| 1201 | + self.clearPreview(); |
| 1202 | + } |
| 1203 | + }, |
1188 | 1204 | reset: function () {
|
1189 | 1205 | var self = this;
|
1190 | 1206 | self.resetPreview();
|
|
1205 | 1221 | self.raise('filedisabled');
|
1206 | 1222 | self.$element.attr('disabled', 'disabled');
|
1207 | 1223 | self.$container.find(".kv-fileinput-caption").addClass("file-caption-disabled");
|
1208 |
| - self.$container.find(".btn-file, .fileinput-remove, .kv-fileinput-upload, .file-preview-frame button").attr("disabled", true); |
| 1224 | + self.$container.find(".btn-file, .fileinput-remove, .kv-fileinput-upload, .file-preview-frame button").attr("disabled", |
| 1225 | + true); |
1209 | 1226 | self.initDragDrop();
|
1210 | 1227 | },
|
1211 | 1228 | enable: function () {
|
|
1907 | 1924 | self.fileInputCleared = false;
|
1908 | 1925 | var tfiles, msg, total, $preview = self.$preview, isDragDrop = arguments.length > 1,
|
1909 | 1926 | files = isDragDrop ? e.originalEvent.dataTransfer.files : $el.get(0).files,
|
1910 |
| - isSingleUpload = isEmpty($el.attr('multiple')), i = 0, f, m, folders = 0, |
1911 |
| - ctr = self.filestack.length, isAjaxUpload = self.isUploadable, |
| 1927 | + isSingleUpload = isEmpty($el.attr('multiple')), i = 0, f, n, folders = 0, |
| 1928 | + ctr = self.filestack.length, isAjaxUpload = self.isUploadable, len, |
| 1929 | + flagSingle = (isSingleUpload && ctr > 0), |
1912 | 1930 | throwError = function (mesg, file, previewId, index) {
|
1913 | 1931 | var p1 = $.extend(self.getOutData({}, {}, files), {id: previewId, index: index}),
|
1914 | 1932 | p2 = {id: previewId, index: index, file: file, files: files};
|
|
1949 | 1967 | return;
|
1950 | 1968 | }
|
1951 | 1969 | self.resetErrors();
|
1952 |
| - total = self.isUploadable ? self.getFileStack().length + tfiles.length : tfiles.length; |
| 1970 | + len = tfiles.length; |
| 1971 | + total = self.isUploadable ? self.getFileStack().length + len : len; |
1953 | 1972 | if (self.maxFileCount > 0 && total > self.maxFileCount) {
|
1954 |
| - msg = self.msgFilesTooMany.replace('{m}', self.maxFileCount).replace('{n}', total); |
1955 |
| - self.isError = throwError(msg, null, null, null); |
1956 |
| - self.$captionContainer.find('.kv-caption-icon').hide(); |
1957 |
| - self.setCaption('', true); |
1958 |
| - self.setEllipsis(); |
1959 |
| - self.$container.removeClass('file-input-new file-input-ajax-new'); |
1960 |
| - return; |
1961 |
| - } |
1962 |
| - if (!isAjaxUpload || (isSingleUpload && ctr > 0)) { |
1963 |
| - if (self.hasInitialPreview()) { |
1964 |
| - var out = previewCache.out(self.id); |
1965 |
| - $preview.html(out.content); |
1966 |
| - self.setCaption(out.caption); |
1967 |
| - self.initPreviewDeletes(); |
1968 |
| - } else { |
1969 |
| - self.clearPreview(); |
| 1973 | + if (!self.autoReplace || len > self.maxFileCount) { |
| 1974 | + n = (self.autoReplace && len > self.maxFileCount) ? len : total; |
| 1975 | + msg = self.msgFilesTooMany.replace('{m}', self.maxFileCount).replace('{n}', n); |
| 1976 | + self.isError = throwError(msg, null, null, null); |
| 1977 | + self.$captionContainer.find('.kv-caption-icon').hide(); |
| 1978 | + self.setCaption('', true); |
| 1979 | + self.setEllipsis(); |
| 1980 | + self.$container.removeClass('file-input-new file-input-ajax-new'); |
| 1981 | + return; |
1970 | 1982 | }
|
1971 |
| - if (isSingleUpload && ctr > 0) { |
1972 |
| - self.filestack = []; |
| 1983 | + if (total > self.maxFileCount) { |
| 1984 | + self.resetPreviewThumbs(isAjaxUpload); |
1973 | 1985 | }
|
1974 | 1986 | } else {
|
1975 |
| - if (isAjaxUpload && ctr === 0 && (!previewCache.count(self.id) || self.overwriteInitial)) { |
1976 |
| - self.clearPreview(); |
1977 |
| - self.filestack = []; |
| 1987 | + if (!isAjaxUpload || flagSingle) { |
| 1988 | + self.resetPreviewThumbs(false); |
| 1989 | + if (flagSingle) { |
| 1990 | + self.filestack = []; |
| 1991 | + } |
| 1992 | + } else { |
| 1993 | + if (isAjaxUpload && ctr === 0 && (!previewCache.count(self.id) || self.overwriteInitial)) { |
| 1994 | + self.resetPreviewThumbs(true); |
| 1995 | + } |
1978 | 1996 | }
|
1979 | 1997 | }
|
1980 | 1998 | if (self.isPreviewable) {
|
|
2168 | 2186 | showUpload: true,
|
2169 | 2187 | showCancel: true,
|
2170 | 2188 | showUploadedThumbs: true,
|
| 2189 | + autoReplace: false, |
2171 | 2190 | mainClass: '',
|
2172 | 2191 | previewClass: '',
|
2173 | 2192 | captionClass: '',
|
|
0 commit comments