diff --git a/bin/Site/Area.js b/bin/Site/Area.js index fdf99c2d902516538ed7da95ffca0ce3ccace3c2..242c0c58b731c6761ace49fa1e6e5de0528c8d56 100644 --- a/bin/Site/Area.js +++ b/bin/Site/Area.js @@ -135,7 +135,7 @@ define('package/quiqqer/bricks/bin/Site/Area', [ icon : 'fa fa-caret-left', events: { onClick: function (Btn) { - if (Btn.getAttribute('icon') == 'fa fa-caret-left') { + if (Btn.getAttribute('icon') === 'fa fa-caret-left') { self.openButtons(); return; } @@ -248,9 +248,7 @@ define('package/quiqqer/bricks/bin/Site/Area', [ }); if (promises.length) { - Promise.resolve(promises).then(function () { - self.refresh(); Loader.destroy(); }); @@ -513,7 +511,7 @@ define('package/quiqqer/bricks/bin/Site/Area', [ clone : function (event) { var Target = event.target; - if (Target.nodeName != 'LI') { + if (Target.nodeName !== 'LI') { Target = Target.getParent('li'); } diff --git a/bin/Site/Category.css b/bin/Site/Category.css index 5237bc614b1db7c9304a1e27db1709236dde6ad5..136254b822c6cd9179a224882327fd2b08531570 100644 --- a/bin/Site/Category.css +++ b/bin/Site/Category.css @@ -1,7 +1,22 @@ -.quiqqer-bricks-site-category { +.quiqqer-bricks-site-category, +.quiqqer-bricks-site-category-image { float: left; - height: 100%; position: relative; width: 100%; } + +.quiqqer-bricks-site-category-areas { + float: left; + width: 60%; +} + +.quiqqer-bricks-site-category-image { + float: left; + padding-left: 20px; + width: 40%; +} + +.quiqqer-bricks-site-category-image img { + max-width: 100%; +} \ No newline at end of file diff --git a/bin/Site/Category.js b/bin/Site/Category.js index 3bc90d3f2c51f67d4c6620f8b468614d6147bac6..62eb46ac7c8370067ff16152f8c2a8148cec4737 100644 --- a/bin/Site/Category.js +++ b/bin/Site/Category.js @@ -44,6 +44,8 @@ define('package/quiqqer/bricks/bin/Site/Category', [ this.Loader = new QUILoader(); this.areas = []; + this.$Areas = null; + this.addEvents({ onInject : this.$onInject, onDestroy: this.$onDestroy @@ -56,11 +58,15 @@ define('package/quiqqer/bricks/bin/Site/Category', [ */ create: function () { this.$Elm = new Element('div', { - 'class': 'quiqqer-bricks-site-category' + 'class': 'quiqqer-bricks-site-category', + 'html' : '<div class="quiqqer-bricks-site-category-areas"></div>' + + '<div class="quiqqer-bricks-site-category-image"></div>' }); this.Loader.inject(this.$Elm); + this.$Areas = this.$Elm.getElement('.quiqqer-bricks-site-category-areas'); + this.$Image = this.$Elm.getElement('.quiqqer-bricks-site-category-image'); return this.$Elm; }, @@ -69,17 +75,32 @@ define('package/quiqqer/bricks/bin/Site/Category', [ * event : on inject */ $onInject: function () { - var self = this; - this.Loader.show(); - this.getBrickAreas(function (bricks) { + var self = this, + Site = this.getAttribute('Site'), + Project = Site.getProject(), + layout = Site.getAttribute('layout'); + + Project.getLayouts().then(function (layouts) { + layout = layouts.find(function (entry) { + return entry.type === layout; + }); + + if (layout.image && layout.image !== '') { + new Element('img', { + src: layout.image + }).inject(self.$Image); + } + + return self.getBrickAreas(); + + }).then(function (bricks) { if (!bricks.length) { - self.$Elm.set( + self.$Areas.set( 'html', QUILocale.get('quiqqer/bricks', 'bricks.message.no.areas.found') ); - return; } @@ -138,24 +159,35 @@ define('package/quiqqer/bricks/bin/Site/Category', [ /** * Return the available areas for the site - * @param {Function} callback - callback function + * + * @param {Function} [callback] - callback function + * @return {Promise} */ getBrickAreas: function (callback) { var Site = this.getAttribute('Site'), Project = Site.getProject(); - Project.getConfig(function (layout) { - if (Site.getAttribute('layout')) { - layout = Site.getAttribute('layout'); - } + return new Promise(function (resolve, reject) { + Project.getConfig(function (layout) { + if (Site.getAttribute('layout')) { + layout = Site.getAttribute('layout'); + } - QUIAjax.get('package_quiqqer_bricks_ajax_project_getAreas', callback, { - 'package': 'quiqqer/bricks', - project : Project.encode(), - layout : layout - }); + QUIAjax.get('package_quiqqer_bricks_ajax_project_getAreas', function (result) { + if (typeof callback === 'function') { + callback(result); + } + + resolve(result); + }, { + 'package': 'quiqqer/bricks', + project : Project.encode(), + layout : layout, + onError : reject + }); - }, 'layout'); + }, 'layout'); + }); }, /** @@ -173,7 +205,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [ Control.setAttribute('Site', Site); Control.setAttributes(area); - Control.inject(this.$Elm); + Control.inject(this.$Areas); this.areas.push(Control); diff --git a/src/QUI/Bricks/Manager.php b/src/QUI/Bricks/Manager.php index ee73b57b111f0727ad254460f2e420343708cb5e..09827d6af1637451ea576589ac0d5896ad98c42c 100644 --- a/src/QUI/Bricks/Manager.php +++ b/src/QUI/Bricks/Manager.php @@ -174,7 +174,7 @@ public function getAreasByProject(Project $Project, $layoutType = false) // get bricks foreach ($templates as $template) { - $brickXML = realpath(OPT_DIR . $template . '/bricks.xml'); + $brickXML = realpath(OPT_DIR.$template.'/bricks.xml'); if (!$brickXML) { continue; @@ -186,7 +186,7 @@ public function getAreasByProject(Project $Project, $layoutType = false) ); } - // unque values + // unique values $cleaned = array(); foreach ($bricks as $val) { if (!isset($cleaned[$val['name']])) { @@ -198,6 +198,13 @@ public function getAreasByProject(Project $Project, $layoutType = false) // use @ because: https://bugs.php.net/bug.php?id=50688 @usort($bricks, function ($a, $b) { + if (isset($a['priority']) && isset($b['priority'])) { + if ($a['priority'] == $b['priority']) { + return 0; + } + + return ($a['priority'] < $b['priority']) ? -1 : 1; + } $transA = QUI::getLocale()->get( $a['title']['group'], @@ -344,7 +351,7 @@ public function getBrickByUID($uid) */ public function getAvailableBrickSettingsByBrickType($brickType) { - $cache = 'quiqqer/bricks/brickType/' . md5($brickType); + $cache = 'quiqqer/bricks/brickType/'.md5($brickType); try { return QUI\Cache\Manager::get($cache); @@ -496,7 +503,7 @@ public function getBricksByArea($brickArea, Site $Site) $result[] = $Clone->check(); } catch (QUI\Exception $Exception) { QUI\System\Log::addWarning( - $Exception->getMessage() . ' Brick-ID:' . $brickId + $Exception->getMessage().' Brick-ID:'.$brickId ); } } @@ -578,7 +585,7 @@ public function saveBrick($brickId, array $brickData) } if (!empty($areas)) { - $areaString = ',' . implode(',', $areas) . ','; + $areaString = ','.implode(',', $areas).','; } $Brick->setAttributes($brickData); @@ -679,7 +686,7 @@ protected function getBricksXMLFiles() // package bricks foreach ($packages as $package) { - $bricksXML = OPT_DIR . $package['name'] . '/bricks.xml'; + $bricksXML = OPT_DIR.$package['name'].'/bricks.xml'; if (file_exists($bricksXML)) { $result[] = $bricksXML; @@ -690,7 +697,7 @@ protected function getBricksXMLFiles() $projects = $Projects->getProjects(); foreach ($projects as $project) { - $bricksXML = USR_DIR . $project . '/bricks.xml'; + $bricksXML = USR_DIR.$project.'/bricks.xml'; if (file_exists($bricksXML)) { $result[] = $bricksXML; diff --git a/src/QUI/Bricks/Utils.php b/src/QUI/Bricks/Utils.php index 121659a9892cfe238e62e7788b0153a1d8812773..a026be586aa3c3199b26527704ed905388fbf55c 100644 --- a/src/QUI/Bricks/Utils.php +++ b/src/QUI/Bricks/Utils.php @@ -148,7 +148,8 @@ public static function parseAreaToArray(\DOMElement $Brick, \DOMXPath $Path) 'name' => $name, 'title' => $title, 'description' => $description, - 'inheritance' => $Brick->getAttribute('inheritance') + 'inheritance' => $Brick->getAttribute('inheritance'), + 'priority' => $Brick->getAttribute('priority') ); } @@ -164,7 +165,7 @@ public static function hasInheritance(Project $Project, $areaName) $template = $Project->getAttribute('template'); // getAreasByProject - $brickXML = realpath(OPT_DIR . $template . '/bricks.xml'); + $brickXML = realpath(OPT_DIR.$template.'/bricks.xml'); $bricks = self::getTemplateAreasFromXML($brickXML); foreach ($bricks as $brickData) {