From 9f3fcf27edc29706bed8bb364b3a310ce771e573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20G=C3=A1bor?= Date: Wed, 30 Mar 2016 18:17:18 +0200 Subject: [PATCH] Update AssetsList --- modules/backend/classes/FormWidgetBase.php | 3 +- modules/backend/traits/SelectableWidget.php | 9 ++++ modules/cms/classes/CmsException.php | 4 +- modules/cms/classes/CmsObject.php | 1 + modules/cms/classes/ComponentPartial.php | 10 ++-- modules/cms/classes/Content.php | 2 +- modules/cms/classes/Controller.php | 2 +- modules/cms/widgets/AssetList.php | 53 ++----------------- .../cms/widgets/assetlist/partials/_items.htm | 2 +- 9 files changed, 26 insertions(+), 60 deletions(-) diff --git a/modules/backend/classes/FormWidgetBase.php b/modules/backend/classes/FormWidgetBase.php index c335c791a..c2e3052da 100644 --- a/modules/backend/classes/FormWidgetBase.php +++ b/modules/backend/classes/FormWidgetBase.php @@ -17,7 +17,7 @@ abstract class FormWidgetBase extends WidgetBase // /** - * @var Model Form model object. + * @var \October\Rain\Database\Model Form model object. */ public $model; @@ -63,7 +63,6 @@ abstract class FormWidgetBase extends WidgetBase /** * Constructor * @param $controller Controller Active controller object. - * @param $model Model The relevant model to reference. * @param $formField FormField Object containing general form field information. * @param $configuration array Configuration the relates to this widget. */ diff --git a/modules/backend/traits/SelectableWidget.php b/modules/backend/traits/SelectableWidget.php index 93fe23779..f3d41caee 100644 --- a/modules/backend/traits/SelectableWidget.php +++ b/modules/backend/traits/SelectableWidget.php @@ -48,6 +48,15 @@ trait SelectableWidget $this->putSession('selected', []); } + protected function removeSelection($itemId) + { + $currentSelection = $this->getSelectedItems(); + + unset($currentSelection[$itemId]); + $this->putSession('selected', $currentSelection); + $this->selectedItemsCache = $currentSelection; + } + protected function isItemSelected($itemId) { $selectedItems = $this->getSelectedItems(); diff --git a/modules/cms/classes/CmsException.php b/modules/cms/classes/CmsException.php index ded3dc01b..379ac5717 100644 --- a/modules/cms/classes/CmsException.php +++ b/modules/cms/classes/CmsException.php @@ -95,7 +95,7 @@ class CmsException extends ApplicationException * Override properties of an exception specific to the INI section * of a CMS object. * @param \Exception $exception The exception to modify. - * @return void + * @return bool */ protected function processIni(Exception $exception) { @@ -138,7 +138,7 @@ class CmsException extends ApplicationException * Override properties of an exception specific to the PHP section * of a CMS object. * @param \Exception $exception The exception to modify. - * @return void + * @return bool */ protected function processPhp(Exception $exception) { diff --git a/modules/cms/classes/CmsObject.php b/modules/cms/classes/CmsObject.php index 1b645d2ff..61179dc47 100644 --- a/modules/cms/classes/CmsObject.php +++ b/modules/cms/classes/CmsObject.php @@ -162,6 +162,7 @@ class CmsObject extends HalcyonModel implements CmsObjectContract /** * Returns the full path to the template file corresponding to this object. + * @param string $fileName * @return string */ public function getFilePath($fileName = null) diff --git a/modules/cms/classes/ComponentPartial.php b/modules/cms/classes/ComponentPartial.php index 9457ef8ab..83c254fcc 100644 --- a/modules/cms/classes/ComponentPartial.php +++ b/modules/cms/classes/ComponentPartial.php @@ -66,7 +66,7 @@ class ComponentPartial extends Extendable implements CmsObjectContract /** * Loads the object from a file. * This method is used in the CMS back-end. It doesn't use any caching. - * @param Cms\Classes\ComponentBase $component Specifies the component the object belongs to. + * @param \Cms\Classes\ComponentBase $component Specifies the component the object belongs to. * @param string $fileName Specifies the file name, with the extension. * The file name can contain only alphanumeric symbols, dashes and dots. * @return mixed Returns a CMS object instance or null if the object wasn't found. @@ -79,7 +79,7 @@ class ComponentPartial extends Extendable implements CmsObjectContract /** * There is not much point caching a component partial, so this behavior * reverts to a regular load call. - * @param Cms\Classes\ComponentBase $component + * @param \Cms\Classes\ComponentBase $component * @param string $fileName * @return mixed */ @@ -133,13 +133,15 @@ class ComponentPartial extends Extendable implements CmsObjectContract /** * Checks the supplied file name for validity. - * @param string $fileName + * @param string $fileName * @return string */ protected function validateFileName($fileName) { if (!FileHelper::validatePath($fileName, $this->maxNesting)) { - throw new ApplicationException(Lang::get('cms::lang.cms_object.invalid_file', ['name'=>$fileName])); + throw new ApplicationException(Lang::get('cms::lang.cms_object.invalid_file', [ + 'name' => $fileName + ])); } if (!strlen(File::extension($fileName))) { diff --git a/modules/cms/classes/Content.php b/modules/cms/classes/Content.php index 7a115bf3e..220da6907 100644 --- a/modules/cms/classes/Content.php +++ b/modules/cms/classes/Content.php @@ -29,7 +29,7 @@ class Content extends CmsCompoundObject /** * Initializes the object properties from the cached data. The extra data * set here becomes available as attributes set on the model after fetch. - * @param array $cached The cached data array. + * @param array $item The cached data array. */ public static function initCacheItem(&$item) { diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 855407ef3..1d1fa59c8 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -103,7 +103,7 @@ class Controller protected static $instance = null; /** - * @var Cms\Classes\ComponentBase Object of the active component, used internally. + * @var \Cms\Classes\ComponentBase Object of the active component, used internally. */ protected $componentContext = null; diff --git a/modules/cms/widgets/AssetList.php b/modules/cms/widgets/AssetList.php index 5ab05e998..ac202959c 100644 --- a/modules/cms/widgets/AssetList.php +++ b/modules/cms/widgets/AssetList.php @@ -31,14 +31,14 @@ use Exception; */ class AssetList extends WidgetBase { + use \Backend\Traits\SelectableWidget; + protected $searchTerm = false; protected $theme; protected $groupStatusCache = false; - protected $selectedFilesCache = false; - /** * @var string Message to display when there are no records in the list. */ @@ -53,6 +53,7 @@ class AssetList extends WidgetBase { $this->alias = $alias; $this->theme = Theme::getEditTheme(); + $this->selectionInputName = 'file'; parent::__construct($controller, []); $this->bindToController(); @@ -89,11 +90,6 @@ class AssetList extends WidgetBase $this->setGroupStatus(Input::get('group'), Input::get('status')); } - public function onSelect() - { - $this->extendSelection(); - } - public function onOpenDirectory() { $path = Input::get('path'); @@ -369,7 +365,7 @@ class AssetList extends WidgetBase )); } - if (!@File::deleteDirectory($originalFullPath, $directory)) { + if (!@File::deleteDirectory($originalFullPath)) { throw new ApplicationException(Lang::get( 'cms::lang.asset.error_deleting_directory', ['dir'=>$basename] @@ -580,30 +576,6 @@ class AssetList extends WidgetBase return $prefix.$this->theme->getDirName(); } - protected function getSelectedFiles() - { - if ($this->selectedFilesCache !== false) { - return $this->selectedFilesCache; - } - - $files = $this->getSession($this->getThemeSessionKey('selected'), []); - if (!is_array($files)) { - return $this->selectedFilesCache = []; - } - - return $this->selectedFilesCache = $files; - } - - protected function isFileSelected($item) - { - $selectedFiles = $this->getSelectedFiles(); - if (!is_array($selectedFiles) || !isset($selectedFiles[$item->path])) { - return false; - } - - return $selectedFiles[$item->path]; - } - protected function getUpPath() { $path = $this->getCurrentRelativePath(); @@ -614,23 +586,6 @@ class AssetList extends WidgetBase return dirname($path); } - protected function extendSelection() - { - $items = Input::get('file', []); - $currentSelection = $this->getSelectedFiles(); - - $this->putSession($this->getThemeSessionKey('selected'), array_merge($currentSelection, $items)); - } - - protected function removeSelection($path) - { - $currentSelection = $this->getSelectedFiles(); - - unset($currentSelection[$path]); - $this->putSession($this->getThemeSessionKey('selected'), $currentSelection); - $this->selectedFilesCache = $currentSelection; - } - protected function validateRequestTheme() { if ($this->theme->getDirName() != Request::input('theme')) { diff --git a/modules/cms/widgets/assetlist/partials/_items.htm b/modules/cms/widgets/assetlist/partials/_items.htm index 68d426b9c..3d1a5a41f 100644 --- a/modules/cms/widgets/assetlist/partials/_items.htm +++ b/modules/cms/widgets/assetlist/partials/_items.htm @@ -42,7 +42,7 @@ id="" type="checkbox" name="file[path) ?>]" - isFileSelected($item) ? 'checked' : null ?> + isItemSelected($item->path) ? 'checked' : null ?> data-request="getEventHandler('onSelect') ?>" value="1">