diff --git a/modules/cms/controllers/index/config_page_list.yaml b/modules/cms/controllers/index/config_page_list.yaml index c2205e19b..b28e06ec0 100644 --- a/modules/cms/controllers/index/config_page_list.yaml +++ b/modules/cms/controllers/index/config_page_list.yaml @@ -9,3 +9,7 @@ descriptionProperties: noRecordsMessage: 'cms::lang.page.no_list_records' deleteConfirmation: 'cms::lang.page.delete_confirm_multiple' itemType: page +sortingProperties: + url: 'cms::lang.page.url' + title: 'cms::lang.page.title' + fileName: 'cms::lang.page.file_name' \ No newline at end of file diff --git a/modules/cms/lang/en/lang.php b/modules/cms/lang/en/lang.php index 5d9aee367..3bbcf122b 100644 --- a/modules/cms/lang/en/lang.php +++ b/modules/cms/lang/en/lang.php @@ -115,7 +115,10 @@ return [ 'delete_confirm_multiple' => 'Delete selected pages?', 'delete_confirm_single' => 'Delete this page?', 'no_layout' => '-- no layout --', - 'cms_page' => 'CMS page' + 'cms_page' => 'CMS page', + 'title' => 'Page title', + 'url' => 'Page URL', + 'file_name' => 'Page file name' ], 'layout' => [ 'not_found_name' => "The layout ':name' is not found", @@ -241,7 +244,8 @@ return [ 'not_found' => 'Template not found.', 'saved' => 'Template saved.', 'no_list_records' => 'No records found', - 'delete_confirm' => 'Delete selected templates?' + 'delete_confirm' => 'Delete selected templates?', + 'order_by' =>'Order by' ], 'permissions' => [ 'name' => 'CMS', diff --git a/modules/cms/widgets/TemplateList.php b/modules/cms/widgets/TemplateList.php index 3c230a121..593db8146 100644 --- a/modules/cms/widgets/TemplateList.php +++ b/modules/cms/widgets/TemplateList.php @@ -17,6 +17,8 @@ use Backend\Classes\WidgetBase; */ class TemplateList extends WidgetBase { + const SORTING_FILENAME = 'fileName'; + use \Backend\Traits\SelectableWidget; protected $searchTerm = false; @@ -69,6 +71,12 @@ class TemplateList extends WidgetBase */ public $ignoreDirectories = []; + /** + * @var boolean Defines sorting properties. + * The sorting feature is disabled if there are no sorting properties defined. + */ + public $sortingProperties = []; + /* * Public methods */ @@ -137,6 +145,16 @@ class TemplateList extends WidgetBase return $this->updateList(); } + public function onApplySorting() + { + $this->setSortingProperty(Input::get('sortProperty')); + + $result = $this->updateList(); + $result['#'.$this->getId('sorting-options')] = $this->makePartial('sorting-options'); + + return $result; + } + // // Methods for the internal use // @@ -156,9 +174,7 @@ class TemplateList extends WidgetBase $items = array_map([$this, 'normalizeItem'], $items); - usort($items, function ($a, $b) { - return strcmp($a->fileName, $b->fileName); - }); + $this->sortItems($items); /* * Apply the search @@ -217,6 +233,10 @@ class TemplateList extends WidgetBase } } + // Sort folders by name regardless of the + // selected sorting options. + ksort($foundGroups); + foreach ($foundGroups as $group) { $result[] = $group; } @@ -224,6 +244,15 @@ class TemplateList extends WidgetBase return $result; } + protected function sortItems(&$items) + { + $sortingProperty = $this->getSortingProperty(); + + usort($items, function ($a, $b) use ($sortingProperty) { + return strcmp($a->$sortingProperty, $b->$sortingProperty); + }); + } + protected function removeIgnoredDirectories($items) { if (!$this->ignoreDirectories) { @@ -274,6 +303,10 @@ class TemplateList extends WidgetBase 'descriptions' => $descriptions ]; + foreach ($this->sortingProperties as $property=>$name) { + $result[$property] = $item->$property; + } + return (object) $result; } @@ -385,4 +418,20 @@ class TemplateList extends WidgetBase $this->groupStatusCache = $statuses; $this->putSession($this->getThemeSessionKey('groups'), $statuses); } + + protected function getSortingProperty() + { + $property = $this->getSession($this->getThemeSessionKey('sorting_property'), self::SORTING_FILENAME); + + if (!array_key_exists($property, $this->sortingProperties)) { + return self::SORTING_FILENAME; + } + + return $property; + } + + protected function setSortingProperty($property) + { + $this->putSession($this->getThemeSessionKey('sorting_property'), $property); + } } diff --git a/modules/cms/widgets/templatelist/partials/_sorting-options.htm b/modules/cms/widgets/templatelist/partials/_sorting-options.htm new file mode 100644 index 000000000..da02a5b92 --- /dev/null +++ b/modules/cms/widgets/templatelist/partials/_sorting-options.htm @@ -0,0 +1,7 @@ +sortingProperties as $propertyName=>$propertyTitle): ?> +
  • getSortingProperty() == $propertyName): ?>class="active"> + + + +
  • + \ No newline at end of file diff --git a/modules/cms/widgets/templatelist/partials/_toolbar.htm b/modules/cms/widgets/templatelist/partials/_toolbar.htm index 6f2814b1f..cbdd7253e 100644 --- a/modules/cms/widgets/templatelist/partials/_toolbar.htm +++ b/modules/cms/widgets/templatelist/partials/_toolbar.htm @@ -4,16 +4,35 @@
    - - + + + sortingProperties): ?> + + + + +
    diff --git a/modules/system/assets/ui/less/dropdown.less b/modules/system/assets/ui/less/dropdown.less index 4d0093d55..6dc18264f 100644 --- a/modules/system/assets/ui/less/dropdown.less +++ b/modules/system/assets/ui/less/dropdown.less @@ -122,6 +122,10 @@ &.dropdown-title { display: none; } &.divider { margin: 0; } + + &.active > a { + font-weight: bold; + } } } } diff --git a/modules/system/assets/ui/storm.css b/modules/system/assets/ui/storm.css index 09f32dbb1..4a69feef7 100644 --- a/modules/system/assets/ui/storm.css +++ b/modules/system/assets/ui/storm.css @@ -1360,6 +1360,7 @@ button.close{padding:0;cursor:pointer;background:transparent;border:0;-webkit-ap .dropdown-menu .dropdown-container > ul li.first-item a:active:after{content:'';display:block;width:0;height:0;border-left:7.5px solid transparent;border-right:7.5px solid transparent;border-bottom:8px solid #3498db} .dropdown-menu .dropdown-container > ul li.dropdown-title{display:none} .dropdown-menu .dropdown-container > ul li.divider{margin:0} +.dropdown-menu .dropdown-container > ul li.active > a{font-weight:bold} .dropdown-menu.pull-right .dropdown-container > ul:after{left:auto;right:15px} .dropdown-menu.pull-right .dropdown-container > ul:before{left:auto;right:14px} .dropdown-menu.pull-right .dropdown-container > ul li.first-item a:hover:after,.dropdown-menu.pull-right .dropdown-container > ul li.first-item a:focus:after{left:auto;right:15px}