Permalink
Browse files

Removing deprecated FileIFrameField, use UploadField instead

  • Loading branch information...
1 parent 5a98cdd commit 594faf71b2de1881dfaf06bfd2cbf605cb983f9c @halkyon halkyon committed Nov 14, 2012
Showing with 0 additions and 583 deletions.
  1. +0 −58 css/FileIFrameField.css
  2. +0 −277 forms/FileIFrameField.php
  3. +0 −47 javascript/FileIFrameField.js
  4. +0 −175 scss/FileIFrameField.scss
  5. +0 −26 templates/FileIFrameField_iframe.ss
View
@@ -1,58 +0,0 @@
-/*
-typography.css has been removed from framework, why shall we still has this? a dynamic typographp.css should be used by
-server side call, like Requirements::css();
-@import url("typography.css");
-*/
-html, body { padding: 0; margin: 0; border-style: none; height: 100%; overflow: hidden; }
-
-form { margin: 0; padding: 0; }
-
-h2 { margin: 0; font-size: 1.4em; }
-
-/** Selection Groups */
-.SelectionGroup { padding: 0; margin: 10px 0 0 0; }
-
-.SelectionGroup li { list-style-type: none; margin: 0 0 4px; }
-
-.SelectionGroup li label { font-size: 11px; }
-
-.SelectionGroup li input.selector { width: 20px; margin-top: 0; }
-
-.SelectionGroup li div.field { display: none; }
-
-.SelectionGroup li.selected div.field { display: block; margin-left: 30px; margin-bottom: 1em; margin-top: 4px; }
-
-.mainblock .SelectionGroup li.selected div.field { margin-left: 27px; margin-bottom: 4px; }
-
-.SelectionGroup li.selected label.selector { font-weight: bold; }
-
-/** TreeDropdownField stying */
-.SelectionGroup div.TreeDropdownField { width: 241px; padding: 0; }
-
-html > body div.TreeDropdownField { position: relative; }
-
-.SelectionGroup div.TreeDropdownField span.items { display: block; height: 100%; border: 1px #7f9db9 solid; cursor: pointer; width: 214px; float: left; padding-top: 2px; padding-bottom: 2px; background-color: white; }
-
-.SelectionGroup div.TreeDropdownField div.tree_holder { clear: left; cursor: default; border: 1px black solid; margin: 0; height: 180px; overflow: auto; background-color: white; /** HACK IE6, see http://www.hedgerwow.com/360/bugs/css-select-free.html */ position: absolute; z-index: 10; width: 238px; /*must have for any value*/ }
-
-html > body div.TreeDropdownField div.tree_holder { top: 20px; left: 0px; z-index: 1000; }
-
-/** HACK IE6, see http://www.hedgerwow.com/360/bugs/css-select-free.html */
-.SelectionGroup div.TreeDropdownField div.tree_holder iframe { display: none; /* IE5*/ display/**/: block; /* IE5*/ position: absolute; top: 0; left: 0; z-index: -1; filter: mask(); width: 180px; /*must have for any big value*/ height: 200px; border: 0; }
-
-div.TreeDropdownField a.editLink { border-width: 1px 1px 1px 0; background: url(../images/TreeDropdownField_button.gif) left top no-repeat; width: 19px; height: 21px; margin: 0; padding: 0; float: left; clear: right; z-index: 0; overflow: hidden; }
-
-/* added block/width so tree values don't disappear in ie7 */
-.SelectionGroup div.TreeDropdownField ul.tree li { display: block; width: 100%; }
-
-.Actions { text-align: right; margin: 0; position: absolute; right: 5px; bottom: 5px; }
-
-.mainblock { float: left; border: 1px solid #ccc; padding: 5px; margin-right: 5px; height: 140px; position: relative; }
-
-.mainblock.editform { width: 275px; }
-
-.mainblock.attached { position: absolute; left: 270px; width: 100px; }
-
-.mainblock form fieldset { border: none; }
-
-.mainblock form div.Actions input { font-size: 11px; }
View
@@ -1,277 +0,0 @@
-<?php
-/**
- * A field that allows you to attach a file to a DataObject without submitting the form it is part of, through the use
- * of an iframe.
- *
- * If all you need is a simple file upload, it is reccomended you use {@link FileField}
- *
- * @deprecated 3.0 Use UploadField
- *
- * @package forms
- * @subpackage fields-files
- */
-class FileIFrameField extends FileField {
-
- public static $allowed_actions = array (
- 'iframe',
- 'EditFileForm',
- 'DeleteFileForm'
- );
-
- /**
- * Flag that controls whether or not new files
- * can be uploaded by the user from their local computer.
- *
- * @var boolean
- */
- protected $canUploadNewFile = true;
-
- /**
- * Sets whether or not files can be uploaded into the CMS from the user's local computer
- *
- * @param boolean
- */
- public function setCanUploadNewFile($can) {
- $this->canUploadNewFile = $can;
- }
-
- /**
- * @return boolean
- */
- public function getCanUploadNewFile() {
- return $this->canUploadNewFile;
- }
-
- /**
- * The data class that this field is editing.
- * @return string Class name
- */
- public function dataClass() {
- if($this->form && $this->form->getRecord()) {
- $class = $this->form->getRecord()->has_one($this->getName());
- return ($class) ? $class : 'File';
- } else {
- return 'File';
- }
- }
-
- /**
- * @return string
- */
- public function Field($properties = array()) {
- Deprecation::notice('3.0', 'Use UploadField');
-
- Requirements::css(FRAMEWORK_DIR . '/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css');
- Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang');
- Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js');
- Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-ui/jquery-ui.js');
-
-
- if($this->form->getRecord() && $this->form->getRecord()->exists()) {
- $record = $this->form->getRecord();
- if(class_exists('Translatable') && SiteTree::has_extension('Translatable') && $record->Locale){
- $iframe = "iframe?locale=".$record->Locale;
- }else{
- $iframe = "iframe";
- }
-
- return $this->createTag (
- 'iframe',
- array (
- 'name' => $this->getName() . '_iframe',
- 'src' => Controller::join_links($this->Link(), $iframe),
- 'style' => 'height: 152px; width: 100%; border: none;'
- )
- ) . $this->createTag (
- 'input',
- array (
- 'type' => 'hidden',
- 'id' => $this->ID(),
- 'name' => $this->getName() . 'ID',
- 'value' => $this->attrValue()
- )
- );
- } else {
- return _t(
- 'FileIFrameField.ATTACHONCESAVED',
- '{type}s can be attached once you have saved the record for the first time.',
- array('type' => $this->FileTypeName())
- );
- }
- }
-
- /**
- * Attempt to retreive a File object that has already been attached to this forms data record
- *
- * @return File|null
- */
- public function AttachedFile() {
- return $this->form->getRecord() ? $this->form->getRecord()->{$this->getName()}() : null;
- }
-
- /**
- * @return string
- */
- public function iframe() {
- // clear the requirements added by any parent controllers
- Requirements::clear();
- Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang');
- Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
- Requirements::javascript(FRAMEWORK_DIR . '/javascript/FileIFrameField.js');
-
- Requirements::css(FRAMEWORK_DIR . '/css/FileIFrameField.css');
-
- return $this->renderWith('FileIframeField_iframe');
- }
-
- /**
- * @return Form
- */
- public function EditFileForm() {
- $uploadFile = _t('FileIFrameField.FROMCOMPUTER', 'From your Computer');
- $selectFile = _t('FileIFrameField.FROMFILESTORE', 'From the File Store');
-
- if($this->AttachedFile() && $this->AttachedFile()->ID) {
- $title = _t('FileIFrameField.REPLACE', 'Replace {type}', array('type' => $this->FileTypeName()));
- } else {
- $title = _t('FileIFrameField.ATTACH', 'Attach {type}', array('type' => $this->FileTypeName()));
- }
-
- $fileSources = array();
-
- if(singleton($this->dataClass())->canCreate()) {
- if($this->canUploadNewFile) {
- $fileSources["new//$uploadFile"] = new FileField('Upload', '');
- }
- }
-
- $fileSources["existing//$selectFile"] = new TreeDropdownField('ExistingFile', '', 'File');
-
- $fields = new FieldList (
- new HeaderField('EditFileHeader', $title),
- new SelectionGroup('FileSource', $fileSources)
- );
-
- // locale needs to be passed through from the iframe source
- if(isset($_GET['locale'])) {
- $fields->push(new HiddenField('locale', '', $_GET['locale']));
- }
-
- return new Form (
- $this,
- 'EditFileForm',
- $fields,
- new FieldList(
- new FormAction('save', $title)
- )
- );
- }
-
- public function save($data, $form) {
- // check the user has entered all the required information
- if (
- !isset($data['FileSource'])
- || ($data['FileSource'] == 'new' && (!isset($_FILES['Upload']) || !$_FILES['Upload']))
- || ($data['FileSource'] == 'existing' && (!isset($data['ExistingFile']) || !$data['ExistingFile']))
- ) {
- $form->sessionMessage(_t('FileIFrameField.NOSOURCE', 'Please select a source file to attach'), 'required');
- $form->getController()->redirectBack();
- return;
- }
-
- $desiredClass = $this->dataClass();
- $controller = $this->form->getController();
-
- // upload a new file
- if($data['FileSource'] == 'new') {
- $fileObject = Object::create($desiredClass);
-
- try {
- $this->upload->loadIntoFile($_FILES['Upload'], $fileObject, $this->folderName);
- } catch (Exception $e){
- $form->sessionMessage(_t('FileIFrameField.DISALLOWEDFILETYPE',
- 'This filetype is not allowed to be uploaded'), 'bad');
- $controller->redirectBack();
- return;
- }
-
- if($this->upload->isError()) {
- $controller->redirectBack();
- return;
- }
-
- $this->form->getRecord()->{$this->getName() . 'ID'} = $fileObject->ID;
-
- $fileObject->write();
- }
-
- // attach an existing file from the assets store
- if($data['FileSource'] == 'existing') {
- $fileObject = DataObject::get_by_id('File', $data['ExistingFile']);
-
- // dont allow the user to attach a folder by default
- if(!$fileObject || ($fileObject instanceof Folder && $desiredClass != 'Folder')) {
- $controller->redirectBack();
- return;
- }
-
- $this->form->getRecord()->{$this->getName() . 'ID'} = $fileObject->ID;
-
- if(!$fileObject instanceof $desiredClass) {
- $fileObject->ClassName = $desiredClass;
- $fileObject->write();
- }
- }
-
- $this->form->getRecord()->write();
- $controller->redirectBack();
- }
-
- /**
- * @return Form
- */
- public function DeleteFileForm() {
- $form = new Form (
- $this,
- 'DeleteFileForm',
- new FieldList (
- new HiddenField('DeleteFile', null, false)
- ),
- new FieldList (
- $deleteButton = new FormAction (
- 'delete', _t('FileIFrameField.DELETE', 'Delete {type}', array('type' => $this->FileTypeName()))
- )
- )
- );
-
- $deleteButton->addExtraClass('delete');
- return $form;
- }
-
- public function delete($data, $form) {
- // delete the actual file, or just un-attach it?
- if(isset($data['DeleteFile']) && $data['DeleteFile']) {
- $file = DataObject::get_by_id('File', $this->form->getRecord()->{$this->getName() . 'ID'});
-
- if($file) {
- $file->delete();
- }
- }
-
- // then un-attach file from this record
- $this->form->getRecord()->{$this->getName() . 'ID'} = 0;
- $this->form->getRecord()->write();
-
- $this->form->getController()->redirectBack();
- }
-
- /**
- * Get the type of file this field is used to attach (e.g. File, Image)
- *
- * @return string
- */
- public function FileTypeName() {
- return _t('FileIFrameField.FILE', 'File');
- }
-
-}
@@ -1,47 +0,0 @@
-(function($) {
-
- $('#Form_DeleteFileForm_action_delete').click(function(e) {
- var deleteMessage = ss.i18n._t('FILEIFRAMEFIELD.CONFIRMDELETE', 'Are you sure you want to delete this file?');
-
- if(typeof(parent.jQuery.fn.dialog) != 'undefined') {
- var buttons = {};
- var $dialog = undefined;
- var $deleteForm = $('#Form_DeleteFileForm');
- var $deleteFile = $('#Form_DeleteFileForm_DeleteFile');
-
- buttons[ss.i18n._t('FILEIFRAMEFIELD.DELETEFILE', 'Delete File')] = function() {
- $deleteFile.attr('value', 'true');
- $deleteForm.submit();
-
- $dialog.dialog('close');
- };
-
- buttons[ss.i18n._t('FILEIFRAMEFIELD.UNATTACHFILE', 'Un-Attach File')] = function() {
- $deleteForm.submit();
- $dialog.dialog('close');
- };
-
- buttons[ss.i18n._t('CANCEL', 'Cancel')] = function() {
- $dialog.dialog('close');
- };
-
- $dialog = parent.jQuery('<p><span class="ui-icon ui-icon-alert" style="float:left;margin-right:5px;"></span>' + deleteMessage + '</p>').dialog({
- bgiframe: true,
- resizable: false,
- modal: true,
- height: 140,
- overlay: {
- backgroundColor: '#000',
- opacity: 0.5
- },
- title: ss.i18n._t('FILEIFRAMEFIELD.DELETEIMAGE', 'Delete Image'),
- buttons: buttons
- });
-
- e.preventDefault();
- } else if(!confirm(deleteMessage)) {
- e.preventDefault();
- }
- });
-
-})(jQuery);
Oops, something went wrong.

0 comments on commit 594faf7

Please sign in to comment.