From 93b3fe8a234982afd37d2c4f4b6e43670af83ffb Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 14 Feb 2012 22:03:09 +0100 Subject: [PATCH 01/15] API CHANGE Removed unused AssetTableField, handled by GridField now --- code/forms/AssetTableField.php | 363 --------------------- code/forms/FolderUnusedAssetsField.php | 17 +- templates/Includes/AssetTableField.ss | 42 --- templates/Includes/AssetTableField_Item.ss | 23 -- 4 files changed, 4 insertions(+), 441 deletions(-) delete mode 100644 code/forms/AssetTableField.php delete mode 100644 templates/Includes/AssetTableField.ss delete mode 100644 templates/Includes/AssetTableField_Item.ss diff --git a/code/forms/AssetTableField.php b/code/forms/AssetTableField.php deleted file mode 100644 index 6856d70a..00000000 --- a/code/forms/AssetTableField.php +++ /dev/null @@ -1,363 +0,0 @@ -searchableFields() as $fieldName => $fieldSpec) { - if(strpos($fieldName, '.') === false) $searchFilters[] = "\"$fieldName\" LIKE '%{$SQL_search}%'"; - } - $this->sourceFilter = '(' . implode(' OR ', $searchFilters) . ')'; - $this->searchingFor = $_REQUEST['FileSearch']; - - // @todo Integrate search form more closely and don't rely on deprecated - // $extraLinkParams. - $this->extraLinkParams = array( - 'FileSearch' => $SQL_search - ); - } - - $this->sourceSort = 'Title'; - $this->Markable = true; - } - - /** - * Creates the link to this form, including the search pattern - * - * @return string - */ - function CurrentLink() { - $link = parent::CurrentLink(); - - if(isset($_REQUEST['FileSearch']) ) { - if ( strpos($link, '?')!==false ) - $link .= "&"; - else - $link .= "/?"; - - $link .= "FileSearch=".urlencode($_REQUEST['FileSearch']); - } - - return $link; - } - - function FieldHolder() { - $ret = parent::FieldHolder(); - - Requirements::javascript(CMS_DIR . '/javascript/AssetTableField.js'); - - return $ret; - } - - function FirstLink() { - $link = parent::FirstLink(); - if($link && isset($_REQUEST['FileSearch'])) { - return $link . '&FileSearch=' . $_REQUEST['FileSearch']; - } - return $link; - } - - function PrevLink() { - $link = parent::PrevLink(); - if($link && isset($_REQUEST['FileSearch'])) { - return $link . '&FileSearch=' . $_REQUEST['FileSearch']; - } - return $link; - } - - function NextLink() { - $link = parent::NextLink(); - if($link && isset($_REQUEST['FileSearch'])) { - return $link . '&FileSearch=' . $_REQUEST['FileSearch']; - } - return $link; - } - - function LastLink() { - $link = parent::LastLink(); - if($link && isset($_REQUEST['FileSearch'])) { - return $link . '&FileSearch=' . $_REQUEST['FileSearch']; - } - return $link; - } - - function setFolder($folder) { - $this->folder = $folder; - $this->sourceFilter .= ($this->sourceFilter) ? " AND " : ""; - - // If you are searching for files then show all those from subfolders - if($this->searchingFor) { - $folderIDs = $nextIDSet = array($folder->ID); - $folderClasses = "'" . implode("','", ClassInfo::subclassesFor("Folder")) . "'"; - - while($nextIDSet) { - // TO DO: In 2.4 this should be refactored to use the new data mapper. - $nextIDSet = DB::query("SELECT \"ID\" FROM \"File\" WHERE \"ParentID\" IN (" - . implode(", " , $nextIDSet) . ") AND \"ClassName\" IN ($folderClasses)")->column(); - if($nextIDSet) $folderIDs = array_merge($folderIDs, $nextIDSet); - } - - $this->sourceFilter .= " \"ParentID\" IN (" . implode(", ", $folderIDs) . ") AND \"ClassName\" <> 'Folder'"; - - // Otherwise just show the direct contents - } else { - $this->sourceFilter .= " \"ParentID\" = '" . $folder->ID . "' AND \"ClassName\" <> 'Folder'"; - } - } - - function Folder() { - return $this->folder; - } - - function sourceID() { - if($this->folder) return $this->folder->ID; - } - - /** - * Get the pop-up fields for the given record. - */ - function getCustomFieldsFor($childData) { - if(!$childData) { - user_error("AssetTableField::DetailForm No record found"); - return null; - } - - if(!$childData instanceof File) { - throw new InvalidArgumentException(sprintf('$childData is of class "%s", subclass of "File" expected', get_class($childData))); - } - - if($childData->ParentID) { - $folder = DataObject::get_by_id('File', $childData->ParentID ); - } else { - $folder = singleton('Folder'); - } - - $urlLink = "
"; - $urlLink .= ""; - $urlLink .= "{$childData->RelativeLink()}"; - $urlLink .= "
"; - - $detailFormFields = new FieldList( - new TabSet("BottomRoot", - $mainTab = new Tab('Main', - new TextField("Title", _t('AssetTableField.TITLE','Title')), - new TextField("Name", _t('AssetTableField.FILENAME','Filename')), - new LiteralField("AbsoluteURL", $urlLink), - new ReadonlyField("FileType", _t('AssetTableField.TYPE','Type')), - new ReadonlyField("Size", _t('AssetTableField.SIZE','Size'), $childData->getSize()), - new DropdownField("OwnerID", _t('AssetTableField.OWNER','Owner'), Member::mapInCMSGroups()), - new DateField_Disabled("Created", _t('AssetTableField.CREATED','First uploaded')), - new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT','Last changed')) - ) - ) - ); - $mainTab->setTitle(_t('AssetTableField.MAIN', 'Main')); - - if(is_a($childData, 'Image')) { - $tab = $detailFormFields->findOrMakeTab("BottomRoot.Image", _t('AssetTableField.IMAGE', 'Image')); - - $big = $childData->URL; - $formattedImage = $childData->getFormattedImage('AssetLibraryPreview'); - $thumbnail = $formattedImage ? $formattedImage->URL : ''; - - // Hmm this required the translated string to be appended to BottomRoot to add this to the Main tab - $detailFormFields->addFieldToTab('BottomRoot.Main', - new ReadonlyField("Dimensions", _t('AssetTableField.DIM','Dimensions')) - ); - - $tab->push( - new LiteralField("ImageFull", - "{$childData->Name}" - ) - ); - } - - if(!($childData instanceof Folder)) { - $mainTab->push(new CheckboxField("ShowInSearch", $childData->fieldLabel('ShowInSearch'))); - } - - if($childData && $childData->hasMethod('BackLinkTracking')) { - if(class_exists('Subsite')) Subsite::disable_subsite_filter(true); - $links = $childData->BackLinkTracking(); - if(class_exists('Subsite')) Subsite::disable_subsite_filter(false); - - $linkArray = array(); - if($links && $links->exists()) { - $backlinks = array(); - foreach($links as $link) { - // Avoid duplicates - if (!in_array($link->ID, $linkArray)) { - $backlinks[] = "
  • ID\">" . $link->Breadcrumbs(null,true). "
  • "; - $linkArray[] = $link->ID; - } - } - $backlinks = "
    ". _t('AssetTableField.PAGESLINKING','The following pages link to this file:') ."
    "; - } - if(!isset($backlinks)) $backlinks = "

    ". _t('AssetTableField.NOLINKS',"This file hasn't been linked to from any pages.") ."

    "; - $detailFormFields->addFieldToTab("BottomRoot.Links", new LiteralField("Backlinks", $backlinks)); - } - - // the ID field confuses the Controller-logic in finding the right view for ReferencedField - $detailFormFields->removeByName('ID'); - - if($childData) $childData->extend('updateCMSFields', $detailFormFields); - - return $detailFormFields; - } - - /** - * Provide some HTML for a search form, to be - * added above the AssetTable field, allowing - * a user to filter the current table's files - * by their filename. - * - * @return string HTML for search form - */ - function SearchForm() { - $fieldContainer = new FieldGroup( - new FieldGroup( - new TextField( - 'FileSearch', - _t('MemberTableField.SEARCH', 'Search'), - $this->searchingFor - ) - ), - new FieldGroup( - $btnFilter = new InlineFormAction( - 'FileFilterButton', - _t('MemberTableField.FILTER', 'Filter') - ), - $btnClear = new InlineFormAction( - 'FileFilterClearButton', - _t('AssetTableField.CLEAR', 'Clear') - ) - ) - ); - $btnFilter->includeDefaultJS(false); - $btnClear->includeDefaultJS(false); - - return $fieldContainer->FieldHolder(); - } - - /** - * @return FormField|null - */ - function DeleteMarkedButton() { - if(!$this->isReadonly() ) { - $deleteButton = new InlineFormAction( - 'deletemarked', - _t('Folder.DELSELECTED','Delete selected files'), - 'delete' - ); - $deleteButton->includeDefaultJS(false); - return $deleteButton; - } - } - - /** - * @return string HTML - */ - public function deletemarked($request) { - $fileIDs = $request->requestVar($this->getName()); - $numFiles = 0; - $brokenPageList = ''; - - if($fileIDs && count($fileIDs)) { - $files = DataObject::get( - "File", - sprintf("\"File\".\"ID\" IN (%s)", Convert::raw2sql(implode(',', $fileIDs))) - ); - if($files) { - $brokenPages = array(); - foreach($files as $file) { - $brokenPages = array_merge($brokenPages, $file->BackLinkTracking()->toArray()); - $file->delete(); - $numFiles++; - } - if($brokenPages) { - $brokenPageList = " ". _t('AssetAdmin.NOWBROKEN', 'These pages now have broken links:') . ''; - Notifications::notifyByEmail("BrokenLink", "Page_BrokenLinkEmail"); - } else { - $brokenPageList = ''; - } - - } - } - - $response = $this->form->Controller()->getResponse(); - $response->addHeader( - 'X-Status', - sprintf( - _t('AssetAdmin.DELETEDX',"Deleted %s file(s) %s"), - $numFiles, - $brokenPageList - ) - ); - } - - public function movemarked($request) { - $fileIDs = $request->requestVar($this->getName()); - $folderId = $request->requestVar('DestFolderID'); - $numFiles = 0; - - if($folderId && (is_numeric($folderId) || ($folderId) == 'root')) { - if($folderId == 'root') $folderId = 0; - - if($fileIDs && count($fileIDs)) { - $files = DataObject::get( - "File", - sprintf("\"File\".\"ID\" IN (%s)", Convert::raw2sql(implode(',', $fileIDs))) - ); - if($files) { - foreach($files as $file) { - $file->ParentID = $folderId; - $file->write(); - $numFiles++; - } - } - } - - $response = $this->form->Controller()->getResponse(); - $response->addHeader( - 'X-Status', - sprintf( - sprintf(_t('AssetAdmin.MOVEDX','Moved %s files'),$numFiles), - $numFiles - ) - ); - } - } -} - - diff --git a/code/forms/FolderUnusedAssetsField.php b/code/forms/FolderUnusedAssetsField.php index c88ec7da..36dd1153 100644 --- a/code/forms/FolderUnusedAssetsField.php +++ b/code/forms/FolderUnusedAssetsField.php @@ -41,21 +41,12 @@ class Folder_UnusedAssetsField extends CompositeField { /** * Creates table for displaying unused files. * - * @returns AssetTableField + * @return GridField */ protected function getAssetList() { $where = $this->folder->getUnusedFilesListFilter(); - $assetList = new AssetTableField( - $this->folder, - "AssetList", - "File", - array("Title" => _t('Folder.TITLE', "Title"), "LinkedURL" => _t('Folder.FILENAME', "Filename")), - "", - $where - ); - $assetList->setPopupCaption(_t('Folder.VIEWASSET', "View Asset")); - $assetList->setPermissions(array("show","delete")); - $assetList->Markable = false; - return $assetList; + $files = DataList::create('File')->where($where); + $field = new GridField('AssetList', false, $files); + return $field; } } \ No newline at end of file diff --git a/templates/Includes/AssetTableField.ss b/templates/Includes/AssetTableField.ss deleted file mode 100644 index 200e6628..00000000 --- a/templates/Includes/AssetTableField.ss +++ /dev/null @@ -1,42 +0,0 @@ -
    -
    - $SearchForm -
    - <% if Markable %> - <% include TableListField_SelectOptions %> - <% end_if %> - <% include TableListField_PageControls %> - - - - - <% if Markable %><% end_if %> - <% control Headings %> - - <% end_control %> - - <% if Can(delete) %><% end_if %> - - - - <% if Items %> - <% control Items %> - <% include AssetTableField_Item %> - <% end_control %> - <% else %> - - - <% if Markable %><% end_if %> - - <% if Can(delete) %><% end_if %> - - <% end_if %> - -
      $Title  
     <% sprintf(_t('AssetTableField.NODATAFOUND', 'No %s found'),$NamePlural) %> 
    -
    - $DeleteMarkedButton - <% control Utility %> - $Title - <% end_control %> -
    -
    \ No newline at end of file diff --git a/templates/Includes/AssetTableField_Item.ss b/templates/Includes/AssetTableField_Item.ss deleted file mode 100644 index f7b942d1..00000000 --- a/templates/Includes/AssetTableField_Item.ss +++ /dev/null @@ -1,23 +0,0 @@ - class="$HighlightClasses"<% end_if %>> - - Drag - - - <% if Markable %>$MarkingCheckbox<% end_if %> - <% control Fields %> - $Value - <% end_control %> - <% control Actions %> - - <% if IsAllowed %> - - <% if Icon %>$Label<% else %>$Label<% end_if %> - - <% else %> - - <% if IconDisabled %>$Label<% else %>$Label<% end_if %> - - <% end_if %> - - <% end_control %> - \ No newline at end of file From 68e9e91a78227f5a011240b0e5c5bac3e0b9ea5c Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 15 Feb 2012 19:35:11 +0100 Subject: [PATCH 02/15] ENHANCEMENT New panel styling for AssetAdmin and CMSFileAddController (SSF-24) --- code/controllers/AssetAdmin.php | 30 +++++++++++ code/controllers/CMSFileAddController.php | 5 +- templates/Includes/AssetAdmin_Content.ss | 51 ------------------- templates/Includes/AssetAdmin_EditForm.ss | 1 - ...n_EditFormTools.ss => AssetAdmin_Tools.ss} | 0 .../Includes/CMSFileAddController_Content.ss | 37 -------------- 6 files changed, 34 insertions(+), 90 deletions(-) delete mode 100644 templates/Includes/AssetAdmin_Content.ss delete mode 100644 templates/Includes/AssetAdmin_EditForm.ss rename templates/Includes/{AssetAdmin_EditFormTools.ss => AssetAdmin_Tools.ss} (100%) delete mode 100644 templates/Includes/CMSFileAddController_Content.ss diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php index 7d4ef041..9b88a028 100644 --- a/code/controllers/AssetAdmin.php +++ b/code/controllers/AssetAdmin.php @@ -72,6 +72,36 @@ JS CMSBatchActionHandler::register('delete', 'AssetAdmin_DeleteBatchAction', 'Folder'); } + + public function getEditForm($id = null, $fields = null) { + $form = parent::getEditForm($id, $fields); + + $fields = $form->Fields(); + $fields->findOrMakeTab('Root.TreeView', _t('AssetAdmin.TreeView', 'Tree View')); + $fields->addFieldToTab('Root.TreeView', + // TODO Replace with lazy loading on client to avoid performance hit of rendering potentially unused views + new LiteralField( + 'Tree', + FormField::createTag( + 'div', + array( + 'class' => 'cms-tree', + 'data-url' => $this->Link('getsubtree'), + 'data-url-savetreenode' => $this->Link('savetreenode') + ), + $this->SiteTreeAsUL() + ) + ) + ); + + $form->addExtraClass('cms-edit-form'); + $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); + // TODO Can't merge $FormAttributes in template at the moment + $form->addExtraClass('center ss-tabset ' . $this->BaseCSSClasses()); + if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); + + return $form; + } public function AddForm() { $form = parent::AddForm(); diff --git a/code/controllers/CMSFileAddController.php b/code/controllers/CMSFileAddController.php index e282a10c..44b4d2ff 100644 --- a/code/controllers/CMSFileAddController.php +++ b/code/controllers/CMSFileAddController.php @@ -35,11 +35,14 @@ class CMSFileAddController extends AssetAdmin { } $form = new Form($this, 'getEditForm', new FieldList($uploadField), new FieldList()); - $form->addExtraClass('cms-content center cms-edit-form ' . $this->BaseCSSClasses()); + $form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses()); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); return $form; } + function Tools() { + return false; + } } \ No newline at end of file diff --git a/templates/Includes/AssetAdmin_Content.ss b/templates/Includes/AssetAdmin_Content.ss deleted file mode 100644 index c647b543..00000000 --- a/templates/Includes/AssetAdmin_Content.ss +++ /dev/null @@ -1,51 +0,0 @@ -
    - - - - -
    -
    -

    - -
    - $AddForm -
    -
    - $SiteTreeAsUL -
    -
    - -
    - -
    -
    - $EditForm -
    -
    - Not implemented yet -
    -
    - Not implemented yet -
    -
    - -
    \ No newline at end of file diff --git a/templates/Includes/AssetAdmin_EditForm.ss b/templates/Includes/AssetAdmin_EditForm.ss deleted file mode 100644 index 45fe1125..00000000 --- a/templates/Includes/AssetAdmin_EditForm.ss +++ /dev/null @@ -1 +0,0 @@ -<% include Form %> \ No newline at end of file diff --git a/templates/Includes/AssetAdmin_EditFormTools.ss b/templates/Includes/AssetAdmin_Tools.ss similarity index 100% rename from templates/Includes/AssetAdmin_EditFormTools.ss rename to templates/Includes/AssetAdmin_Tools.ss diff --git a/templates/Includes/CMSFileAddController_Content.ss b/templates/Includes/CMSFileAddController_Content.ss deleted file mode 100644 index 29a6dbf6..00000000 --- a/templates/Includes/CMSFileAddController_Content.ss +++ /dev/null @@ -1,37 +0,0 @@ -<% with EditForm %> -
    - -
    -
    -

    <% _t('CMSAddPageController.Title','Add pages') %>

    -
    -
    - -
    - - <% if Message %> -

    $Message

    - <% else %> - - <% end_if %> - -
    - <% if Legend %>$Legend<% end_if %> - <% control Fields %> - $FieldHolder - <% end_control %> -
    -
    - -
    - <% if Actions %> -
    - <% control Actions %> - $Field - <% end_control %> -
    - <% end_if %> -
    - -
    -<% end_with %> From 8c503069b8b4c1de414de1b161c058e1c0b596f7 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 16 Feb 2012 18:06:48 +0100 Subject: [PATCH 03/15] MINOR Removed jQuery.metadata usage in CMS, use jQuery.data() and HTML5 data attributes instead. Also fixes errors where jQuery.metadata tries to eval() HTML5 data attrs, which isn't always applicable --- code/controllers/CMSPageHistoryController.php | 9 ++++----- javascript/CMSPageHistoryController.js | 7 +++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/code/controllers/CMSPageHistoryController.php b/code/controllers/CMSPageHistoryController.php index 137765af..e18e9c9a 100644 --- a/code/controllers/CMSPageHistoryController.php +++ b/code/controllers/CMSPageHistoryController.php @@ -221,11 +221,10 @@ class CMSPageHistoryController extends CMSMain { $hiddenID->setValue($id); $form->unsetValidator(); - $form->addExtraClass('cms-versions-form'); // placeholder, necessary for $.metadata() to work - $form->addExtraClass(Convert::raw2json(array( - 'link-tmpl-compare' => Controller::join_links($this->Link('compare'), '%s', '%s', '%s'), - 'link-tmpl-show' => Controller::join_links($this->Link('show'), '%s', '%s'), - ))); + $form + ->addExtraClass('cms-versions-form') // placeholder, necessary for $.metadata() to work + ->setAttribute('data-link-tmpl-compare', Controller::join_links($this->Link('compare'), '%s', '%s', '%s')) + ->setAttribute('data-link-tmpl-show', Controller::join_links($this->Link('show'), '%s', '%s')); return $form; } diff --git a/javascript/CMSPageHistoryController.js b/javascript/CMSPageHistoryController.js index b5e486fd..ab6a0bc2 100644 --- a/javascript/CMSPageHistoryController.js +++ b/javascript/CMSPageHistoryController.js @@ -57,9 +57,8 @@ if(!id) return false; - var button, url, selected, to, from, compare, data, metadata; + var button, url, selected, to, from, compare, data; - metadata = this.metadata({type: 'class'}); compare = (this.find(":input[name=CompareMode]").is(":checked")); selected = this.find("table input[type=checkbox]").filter(":checked"); @@ -69,12 +68,12 @@ to = selected.eq(0).val(); from = selected.eq(1).val(); button = this.find(':submit[name=action_doCompare]'); - url = ss.i18n.sprintf(metadata['link-tmpl-compare'], id,from,to); + url = ss.i18n.sprintf(this.data('linkTmplCompare'), id,from,to); } else { to = selected.eq(0).val(); button = this.find(':submit[name=action_doShowVersion]'); - url = ss.i18n.sprintf(metadata['link-tmpl-show'], id,to); + url = ss.i18n.sprintf(this.data('linkTmplShow'), id,to); } $('.cms-container').loadPanel(url, '', {selector: '.cms-edit-form'}); From 88952c0ac79a32fba3880290075c75dc8a3c8ad5 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 16 Feb 2012 17:36:45 +0100 Subject: [PATCH 04/15] MINOR Using HTML5 data attributes for denoting layout in templates --- templates/CMSPageEditController_Tools.ss | 2 +- templates/Includes/AssetAdmin_Tools.ss | 2 +- templates/Includes/AssetAdmin_UploadContent.ss | 2 +- templates/Includes/CMSPageAddController_Content.ss | 2 +- templates/Includes/CMSPageHistoryController_Tools.ss | 2 +- templates/Includes/CMSPagesController_Content.ss | 2 +- templates/Includes/CMSPagesController_ContentToolbar.ss | 4 ++-- templates/Includes/CMSPagesController_Tools.ss | 2 +- templates/Includes/ReportAdmin_Content.ss | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/templates/CMSPageEditController_Tools.ss b/templates/CMSPageEditController_Tools.ss index 030d1cf2..b3ed137a 100644 --- a/templates/CMSPageEditController_Tools.ss +++ b/templates/CMSPageEditController_Tools.ss @@ -1,4 +1,4 @@ -
    +

    <% _t('CMSPageEditController.Title','Pages') %>

    diff --git a/templates/Includes/AssetAdmin_Tools.ss b/templates/Includes/AssetAdmin_Tools.ss index df026e13..6431b873 100644 --- a/templates/Includes/AssetAdmin_Tools.ss +++ b/templates/Includes/AssetAdmin_Tools.ss @@ -1,4 +1,4 @@ -