1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 09:44:38 +02:00
This commit is contained in:
Ryan Cramer
2019-12-03 11:55:49 -05:00
parent a6e3626992
commit 987d23154d
5 changed files with 45 additions and 8 deletions

View File

@@ -397,18 +397,34 @@ $(document).ready(function() {
'<span class="InputfieldFileStats"> &bull; ' + message + '</span></p></li>';
}
var errorMsg = '';
if(typeof files !== "undefined") {
for(var i=0, l=files.length; i<l; i++) {
var extension = files[i].name.split('.').pop().toLowerCase();
if(extensions.indexOf(extension) == -1) {
$fileList.append(errorItem(files[i].name, extension + ' is a invalid file extension, please use one of: ' + extensions));
if(typeof ProcessWire.config.InputfieldFile.labels['bad-ext'] != "undefined") {
errorMsg = ProcessWire.config.InputfieldFile.labels['bad-ext'];
errorMsg = errorMsg.replace('EXTENSIONS', extensions);
} else {
errorMsg = extension + ' is a invalid file extension, please use one of: ' + extensions;
}
$fileList.append(errorItem(files[i].name, errorMsg));
} else if(files[i].size > maxFilesize && maxFilesize > 2000000) {
// I do this test only if maxFilesize is at least 2M (php default).
// There might (not sure though) be some issues to get that value so don't want to overvalidate here -apeisa
$fileList.append(errorItem(files[i].name, 'Filesize ' + parseInt(files[i].size / 1024, 10) +' kb is too big. Maximum allowed is ' + parseInt(maxFilesize / 1024, 10) + ' kb'));
var maxKB = parseInt(maxFilesize / 1024, 10);
if(typeof ProcessWire.config.InputfieldFile.labels['too-big'] != "undefined") {
errorMsg = ProcessWire.config.InputfieldFile.labels['too-big'];
errorMsg = errorMsg.replace('MAX_KB', maxKB);
} else {
var fileSize = parseInt(files[i].size / 1024, 10);
errorMsg = 'Filesize ' + fileSize +' kb is too big. Maximum allowed is ' + maxKB + ' kb';
}
$fileList.append(errorItem(files[i].name, errorMsg));
} else {
uploadFile(files[i]);

File diff suppressed because one or more lines are too long

View File

@@ -636,6 +636,10 @@ class InputfieldFile extends Inputfield implements InputfieldItemList, Inputfiel
}
public function renderReady(Inputfield $parent = null, $renderValueMode = false) {
/** @var Config $config */
$config = $this->wire('config');
$this->addClass('InputfieldNoFocus', 'wrapClass');
if(!$renderValueMode) $this->addClass('InputfieldHasUpload', 'wrapClass');
@@ -644,7 +648,6 @@ class InputfieldFile extends Inputfield implements InputfieldItemList, Inputfiel
$this->addClass('InputfieldFileHasTags', 'wrapClass');
if($this->useTags >= FieldtypeFile::useTagsPredefined && $this->hasField) {
// predefined tags
$config = $this->wire('config');
$fieldName = $this->hasField->name;
$jsName = "InputfieldFileTags_$fieldName";
$allowUserTags = $this->useTags & FieldtypeFile::useTagsNormal;
@@ -674,6 +677,15 @@ class InputfieldFile extends Inputfield implements InputfieldItemList, Inputfiel
}
}
$data = $config->js('InputfieldFile');
if(!is_array($data)) $data = array();
if(empty($data['labels'])) $data['labels'] = array();
if(empty($data['labels']['bad-ext'])) {
$data['labels']['bad-ext'] = $this->_('Unsupported file extension, please use only: EXTENSIONS');
$data['labels']['too-big'] = $this->_('File is too big - maximum allowed size is MAX_KB kb');
$config->js('InputfieldFile', $data);
}
$this->getItemInputfields(); // custom fields ready
return parent::renderReady($parent, $renderValueMode);

View File

@@ -2192,7 +2192,12 @@ function InputfieldImage($) {
var message;
if(extensions.indexOf(extension) == -1) {
if(typeof ProcessWire.config.InputfieldFile.labels['bad-ext'] != "undefined") {
message = ProcessWire.config.InputfieldFile.labels['bad-ext'];
message = message.replace('EXTENSIONS', extensions);
} else {
message = extension + ' is a invalid file extension, please use one of: ' + extensions;
}
$errorParent.append(errorItem(message, files[i].name));
} else if(!useClientResize && files[i].size > maxFilesize && maxFilesize > 2000000) {
@@ -2200,8 +2205,12 @@ function InputfieldImage($) {
// There might (not sure though) be some issues to get that value so don't want to overvalidate here -apeisa
var filesizeKB = toKilobyte(files[i].size),
maxFilesizeKB = toKilobyte(maxFilesize);
if(typeof ProcessWire.config.InputfieldFile.labels['too-big'] != "undefined") {
message = ProcessWire.config.InputfieldFile.labels['too-big'];
message = message.replace('MAX_KB', maxFilesizeKB);
} else {
message = 'Filesize ' + filesizeKB + ' kb is too big. Maximum allowed is ' + maxFilesizeKB + ' kb';
}
$errorParent.append(errorItem(message, files[i].name));
} else if(typeof xhr != "undefined") {

File diff suppressed because one or more lines are too long