mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 17:54:44 +02:00
Fix issue processwire/processwire-issues#774
This commit is contained in:
@@ -396,6 +396,8 @@ $(document).ready(function() {
|
||||
'<p class="InputfieldFileInfo ui-widget ui-widget-header InputfieldItemHeader ui-state-error"> ' + filename + ' ' +
|
||||
'<span class="InputfieldFileStats"> • ' + message + '</span></p></li>';
|
||||
}
|
||||
|
||||
var errorMsg = '';
|
||||
|
||||
if(typeof files !== "undefined") {
|
||||
for(var i=0, l=files.length; i<l; i++) {
|
||||
@@ -403,12 +405,26 @@ $(document).ready(function() {
|
||||
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
@@ -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);
|
||||
|
@@ -2192,7 +2192,12 @@ function InputfieldImage($) {
|
||||
var message;
|
||||
|
||||
if(extensions.indexOf(extension) == -1) {
|
||||
message = extension + ' is a invalid file extension, please use one of: ' + extensions;
|
||||
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);
|
||||
|
||||
message = 'Filesize ' + filesizeKB + ' kb is too big. Maximum allowed is ' + maxFilesizeKB + ' kb';
|
||||
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
Reference in New Issue
Block a user