示例#1
0
 public function Field($properties = array())
 {
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
     Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/ssui.core.js');
     Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang');
     Requirements::combine_files('uploadfield.js', array(THIRDPARTY_DIR . '/javascript-templates/tmpl.js', THIRDPARTY_DIR . '/javascript-loadimage/load-image.js', THIRDPARTY_DIR . '/jquery-fileupload/jquery.iframe-transport.js', THIRDPARTY_DIR . '/jquery-fileupload/cors/jquery.xdr-transport.js', THIRDPARTY_DIR . '/jquery-fileupload/jquery.fileupload.js', THIRDPARTY_DIR . '/jquery-fileupload/jquery.fileupload-ui.js', FRAMEWORK_DIR . '/javascript/UploadField_uploadtemplate.js', FRAMEWORK_DIR . '/javascript/UploadField_downloadtemplate.js', FRAMEWORK_DIR . '/javascript/UploadField.js'));
     Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
     // TODO hmmm, remove it?
     Requirements::css(FRAMEWORK_DIR . '/css/UploadField.css');
     // Calculated config as per jquery.fileupload-ui.js
     $allowedMaxFileNumber = $this->getAllowedMaxFileNumber();
     $config = array('url' => $this->Link('upload'), 'urlSelectDialog' => $this->Link('select'), 'urlAttach' => $this->Link('attach'), 'urlFileExists' => $this->link('fileexists'), 'acceptFileTypes' => '.+$', 'maxNumberOfFiles' => $allowedMaxFileNumber ? $allowedMaxFileNumber - count($this->getItemIDs()) : null, 'replaceFile' => $this->getUpload()->getReplaceFile());
     // Validation: File extensions
     if ($allowedExtensions = $this->getAllowedExtensions()) {
         $config['acceptFileTypes'] = '(\\.|\\/)(' . implode('|', $allowedExtensions) . ')$';
         $config['errorMessages']['acceptFileTypes'] = _t('File.INVALIDEXTENSIONSHORT', 'Extension is not allowed');
     }
     // Validation: File size
     if ($allowedMaxFileSize = $this->getValidator()->getAllowedMaxFileSize()) {
         $config['maxFileSize'] = $allowedMaxFileSize;
         $config['errorMessages']['maxFileSize'] = _t('File.TOOLARGESHORT', 'File size exceeds {size}', array('size' => File::format_size($config['maxFileSize'])));
     }
     // Validation: Number of files
     if ($allowedMaxFileNumber) {
         if ($allowedMaxFileNumber > 1) {
             $config['errorMessages']['maxNumberOfFiles'] = _t('UploadField.MAXNUMBEROFFILESSHORT', 'Can only upload {count} files', array('count' => $allowedMaxFileNumber));
         } else {
             $config['errorMessages']['maxNumberOfFiles'] = _t('UploadField.MAXNUMBEROFFILESONE', 'Can only upload one file');
         }
     }
     // add overwrite warning error message to the config object sent to Javascript
     if ($this->getOverwriteWarning()) {
         $config['errorMessages']['overwriteWarning'] = _t('UploadField.OVERWRITEWARNING', 'File with the same name already exists');
     }
     $mergedConfig = array_merge($config, $this->ufConfig);
     return parent::Field(array('configString' => str_replace('"', """, Convert::raw2json($mergedConfig)), 'config' => new ArrayData($mergedConfig), 'multiple' => $allowedMaxFileNumber !== 1));
 }
 public function Field($properties = array())
 {
     $this->setAttribute('data-icon', $this->getConfig('dataIcon'));
     $this->setAttribute('data-input', $this->getConfig('dataInput'));
     $this->setAttribute('data-ButtonName', $this->getConfig('dataButtonName'));
     $this->setAttribute('data-size', $this->getConfig('dataSize'));
     $this->setAttribute('data-IconName', $this->getConfig('dataIconName'));
     // Set Button Title
     $this->setAttribute('data-buttonText', _t('BootstrapFileField.CHOOSEFILE', 'BootstrapFileField.CHOOSEFILE'));
     // Overwrite Button Title
     if ($this->button_title) {
         $this->setAttribute('data-buttonText', $this->button_title);
     }
     Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.min.js');
     Requirements::javascript('bootstrap_extra_fields/javascript/bootstrap-filestyle.min.js');
     // Fetch the Field Record
     if ($this->form) {
         $record = $this->form->getRecord();
     }
     $fieldName = $this->name;
     if (isset($record) && $record) {
         $fileField = $record->{$fieldName}();
         if ($fileField && $fileField->exists()) {
             if ($fileField->hasMethod('Thumbnail') && $fileField->Thumbnail()) {
                 $Image = $fileField->Thumbnail()->getTag();
             } else {
                 if ($fileField->CMSThumbnail()) {
                     $Image = $fileField->CMSThumbnail();
                 } else {
                     $Image = false;
                 }
             }
         } else {
             $Image = false;
         }
     } else {
         $Image = false;
     }
     $properties = array_merge($properties, array('MaxFileSize' => $this->getValidator()->getAllowedMaxFileSize(), 'Image' => $Image));
     return parent::Field($properties);
 }
 public function Field($properties = array())
 {
     return parent::Field($properties);
 }
 public function Field($properties = array())
 {
     // Fetch the Field Record
     if ($this->form) {
         $record = $this->form->getRecord();
     }
     $fieldName = $this->name;
     if (isset($record) && $record) {
         $imageField = $record->{$fieldName}();
         if ($imageField && $imageField->exists()) {
             if ($imageField->hasMethod('Thumbnail') && $imageField->Thumbnail()) {
                 $Image = $imageField->Thumbnail()->getURL();
             } else {
                 if ($imageField->CMSThumbnail()) {
                     $Image = $imageField->CMSThumbnail()->getURL();
                 } else {
                     $Image = false;
                 }
             }
         } else {
             $Image = false;
         }
     } else {
         $Image = false;
     }
     $properties = array_merge($properties, array('MaxFileSize' => $this->getValidator()->getAllowedMaxFileSize(), 'Image' => $Image));
     return parent::Field($properties);
 }