Merge pull request #1887 from gpasztor87/ui

Update AssetList + Clean up
This commit is contained in:
Samuel Georges 2016-03-31 07:41:05 +11:00
commit ea5193e4c8
9 changed files with 26 additions and 60 deletions

View File

@ -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.
*/

View File

@ -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();

View File

@ -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)
{

View File

@ -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)

View File

@ -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
*/
@ -139,7 +139,9 @@ class ComponentPartial extends Extendable implements CmsObjectContract
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))) {

View File

@ -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)
{

View File

@ -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;

View File

@ -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')) {

View File

@ -42,7 +42,7 @@
id="<?= $cbId ?>"
type="checkbox"
name="file[<?= e($item->path) ?>]"
<?= $this->isFileSelected($item) ? 'checked' : null ?>
<?= $this->isItemSelected($item->path) ? 'checked' : null ?>
data-request="<?= $this->getEventHandler('onSelect') ?>"
value="1">
<label for="<?= $cbId ?>"><?= e(trans('cms::lang.asset.select')) ?></label>