diff --git a/ajax/getBrick.php b/ajax/getBrick.php index 745ca27c53798f6bbb818bea950d2a8071833ad0..36113b6f5a1833a264e61e610ccf9e7918b224e4 100644 --- a/ajax/getBrick.php +++ b/ajax/getBrick.php @@ -18,9 +18,9 @@ function ($brickId) { $Brick = $BrickManager->getBrickById($brickId); return array( - 'attributes' => $Brick->getAttributes(), - 'settings' => $Brick->getSettings(), - 'customfields' => $Brick->getCustomFields(), + 'attributes' => $Brick->getAttributes(), + 'settings' => $Brick->getSettings(), + 'customfields' => $Brick->getCustomFields(), 'availableSettings' => $BrickManager->getAvailableBrickSettingsByBrickType( $Brick->getAttribute('type') ) diff --git a/ajax/getPanelCategories.php b/ajax/getPanelCategories.php new file mode 100644 index 0000000000000000000000000000000000000000..89aa1a84be5b483bdb470174d3eb990d019218aa --- /dev/null +++ b/ajax/getPanelCategories.php @@ -0,0 +1,26 @@ +<?php + +/** + * This file contains package_quiqqer_bricks_ajax_getPanelCategories + */ + +/** + * Returns the Brick categories for a brick panel + * + * @param {String|Integer} $brickId - Brick-ID + * @return array + */ +QUI::$Ajax->registerFunction( + 'package_quiqqer_bricks_ajax_getPanelCategories', + function ($brickId) { + $categories = QUI\Bricks\Panel::getInstance()->getCategoriesFromBrick($brickId); + + foreach ($categories as $key => $category) { + unset($categories[$key]['items']); + } + + return $categories; + }, + array('brickId'), + 'Permission::checkAdminUser' +); diff --git a/ajax/getPanelCategory.php b/ajax/getPanelCategory.php new file mode 100644 index 0000000000000000000000000000000000000000..79425fc844f932e188df5f0399fd8662980ea273 --- /dev/null +++ b/ajax/getPanelCategory.php @@ -0,0 +1,17 @@ +<?php + +/** + * Return a xml category + * + * @param array $file - list of xml files + * @param $category + * @return String + */ +QUI::$Ajax->registerFunction( + 'package_quiqqer_bricks_ajax_getPanelCategory', + function ($brickId, $category) { + return QUI\Bricks\Panel::getInstance()->getCategoryFromBrick($brickId, $category); + }, + array('brickId', 'category'), + 'Permission::checkAdminUser' +); diff --git a/bin/BrickEdit.css b/bin/BrickEdit.css index f3f022599bfe76c315c173e902fd4d895432f6a1..76d576ec0baf4d2982a926314a8557f9b1f4ea09 100644 --- a/bin/BrickEdit.css +++ b/bin/BrickEdit.css @@ -5,6 +5,16 @@ width: 100%; } +.quiqqer-bricks-container { + float: left; + position: relative; + width: 100%; +} + +.brick-edit-content { + margin-bottom: 0; +} + .quiqqer-bricks-brickedit label { clear: both; float: left; diff --git a/bin/BrickEdit.js b/bin/BrickEdit.js index 6047e60e664ed403e40abef97b99844a182ab562..af23a4728c393d3d8329e6f41b7eb44f966c8ee1 100644 --- a/bin/BrickEdit.js +++ b/bin/BrickEdit.js @@ -21,10 +21,12 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ 'qui/utils/Form', 'utils/Controls', 'utils/Template', + 'package/quiqqer/bricks/bin/Bricks', 'css!package/quiqqer/bricks/bin/BrickEdit.css' -], function (QUI, QUIPanel, QUIConfirm, BrickAreas, QUIAjax, QUILocale, Projects, QUIFormUtils, ControlUtils, Template) { +], function (QUI, QUIPanel, QUIConfirm, BrickAreas, QUIAjax, QUILocale, + Projects, QUIFormUtils, ControlUtils, Template, Bricks) { "use strict"; var lg = 'quiqqer/bricks'; @@ -38,10 +40,18 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ '$onInject', '$onCreate', '$onDestroy', + + 'showInformation', + 'showSettings', + 'showExtras', + 'showContent', + '$load', '$unload', 'save', - 'del' + 'del', + '$onCategoryEnter', + '$onCategoryLeave' ], options: { @@ -56,23 +66,27 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ this.$availableBricks = []; this.$availableSettings = []; this.$customfields = []; + this.$loaded = false; - this.$Editor = false; - this.$Areas = false; - this.$Active = false; + this.$Container = null; + this.$Editor = false; + this.$Areas = false; this.addEvents({ - onInject : this.$onInject, - onCreate : this.$onCreate, - onDestroy: this.$onDestroy, - onResize : function () { + onInject : this.$onInject, + onCreate : this.$onCreate, + onDestroy : this.$onDestroy, + onResize : function () { var controls = QUI.Controls.getControlsInElement(this.getContent()); + controls.each(function (Control) { if ("resize" in Control) { Control.resize(); } }); - }.bind(this) + }.bind(this), + onCategoryEnter: this.$onCategoryEnter, + onCategoryLeave: this.$onCategoryLeave }); }, @@ -111,7 +125,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ icon : 'fa fa-file-o', text : QUILocale.get('quiqqer/system', 'information'), events: { - onActive: this.$load + onClick: this.showInformation } }); @@ -120,7 +134,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ icon : 'fa fa-magic', text : QUILocale.get('quiqqer/system', 'properties'), events: { - onActive: this.$load + onClick: this.showSettings } }); @@ -129,7 +143,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ icon : 'fa fa-gears', text : QUILocale.get('quiqqer/system', 'settings'), events: { - onActive: this.$load + onClick: this.showExtras } }); @@ -138,7 +152,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ icon : 'fa fa-file-text-o', text : QUILocale.get('quiqqer/system', 'content'), events: { - onActive: this.$load + onClick: this.showContent } }); }, @@ -151,8 +165,9 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ QUIAjax.get([ 'package_quiqqer_bricks_ajax_getBrick', - 'package_quiqqer_bricks_ajax_getAvailableBricks' - ], function (brick, bricks) { + 'package_quiqqer_bricks_ajax_getAvailableBricks', + 'package_quiqqer_bricks_ajax_getPanelCategories' + ], function (brick, bricks, categories) { /** * @param {{availableSettings:object}} data * @param {{attributes:object}} data @@ -172,11 +187,33 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ }) }); + this.getContent().setStyles({ + position: 'relative' + }); + + this.$Container = new Element('div', { + 'class': 'quiqqer-bricks-container' + }).inject(this.getContent()); + + // brick xml settings + var type = brick.attributes.type; + var data = bricks.filter(function (entry) { + return entry.control === type; + }); + + if (data.length && data[0].hasContent === 0) { + this.getCategory('content').hide(); + } + + for (var i = 0, len = categories.length; i < len; i++) { + this.addCategory(categories[i]); + } + this.refresh(); this.fireEvent('loaded', [this]); this.getCategory('information').click(); - + this.$loaded = true; }.bind(this), { 'package': 'quiqqer/brick', brickId : this.getAttribute('id') @@ -201,57 +238,43 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ * * @return Promise */ - save: function (callback) { - var Active = this.$Active; - + save: function () { this.Loader.show(); this.$unload(); - return this.$load(Active).then(function () { - - return new Promise(function (resolve, reject) { - var data = this.getAttribute('data'); - - data.customfields = this.$customfields; - - QUIAjax.post('package_quiqqer_bricks_ajax_brick_save', function () { - if (typeof callback === 'function') { - callback(); - } - - resolve(); - - QUI.getMessageHandler().then(function (MH) { - MH.addSuccess( - QUILocale.get(lg, 'message.brick.save.success') - ); - }); + var self = this, + data = self.getAttribute('data'); - this.fireEvent('save', [this]); - this.Loader.hide(); + data.customfields = self.$customfields; - }.bind(this), { - 'package': 'quiqqer/brick', - brickId : this.getAttribute('id'), - data : JSON.encode(data), - onError : reject - }); - - }.bind(this)); + return Bricks.saveBrick(self.getAttribute('id'), data).then(function () { + QUI.getMessageHandler().then(function (MH) { + MH.addSuccess( + QUILocale.get(lg, 'message.brick.save.success') + ); + }); - }.bind(this)); + self.fireEvent('save', [self]); + self.Loader.hide(); + }); }, /** * Delete the brick */ del: function () { - var self = this; + var self = this, + data = this.getAttribute('data'); new QUIConfirm({ title : QUILocale.get(lg, 'window.brick.delete.title'), - text : QUILocale.get(lg, 'window.brick.delete.text'), + text : QUILocale.get(lg, 'window.brick.delete.text', { + brickId : self.getAttribute('id'), + brickTitle: data.attributes.title + }), information: QUILocale.get(lg, 'window.brick.delete.information'), + icon : 'fa fa-trash', + texticon : 'fa fa-trash', maxHeight : 300, maxWidth : 600, autoclose : false, @@ -259,14 +282,9 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ onSubmit: function (Win) { Win.Loader.show(); - QUIAjax.post('package_quiqqer_bricks_ajax_brick_delete', function () { + Bricks.deleteBricks([self.getAttribute('id')]).then(function () { Win.close(); - self.fireEvent('delete'); - self.destroy(); - }, { - 'package': 'quiqqer/bricks', - brickIds : JSON.encode([self.getAttribute('id')]) }); } } @@ -276,100 +294,55 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ /** * event on button active * - * @param {Object} Button - qui/controls/buttons/Button - * * @return Promise */ - $load: function (Button) { - this.Loader.show(); - - return new Promise(function (resolve, reject) { - - var Prom = false, - self = this; - - if (Button === this.$Active) { - reject(); - self.Loader.hide(); - return; - } - - var data = this.getAttribute('data'); - - this.$unload(); - - this.setAttribute('data', data); - this.$Active = Button; - - switch (Button.getAttribute('name')) { - case 'information': - Prom = this.$showInformation(); - break; - - case 'settings': - Prom = this.$showSettings(); - break; - - case 'extra': - Prom = this.$showExtras(); - break; - - case 'content': - Prom = this.$showContent(); - break; - - default: - reject(); - return; - } - - if (!Prom) { - reject(); - self.Loader.hide(); - return; - } - - Prom.then(function () { - - resolve(); - self.Loader.hide(); - - }).catch(function () { - reject(); - self.Loader.hide(); - }); - - }.bind(this)); + $load: function () { + QUIFormUtils.setDataToForm( + this.getAttribute('data').attributes, + this.$Container.getElement('form') + ); + + QUIFormUtils.setDataToForm( + this.getAttribute('data').settings, + this.$Container.getElement('form') + ); }, /** * event unload category */ $unload: function () { - if (!this.$Active) { + if (!this.$loaded) { + return; + } + + if (!this.getActiveCategory()) { return; } var Form = this.getContent().getElement('form'), - unload = this.$Active.getAttribute('name'), + unload = this.getActiveCategory().getAttribute('name'), data = this.getAttribute('data'); - if (unload === 'information') { - data.attributes = Object.merge( - data.attributes, - QUIFormUtils.getFormData(Form) - ); + switch (unload) { + case 'extra': + case 'settings': + case 'content': + break; + + default: + data.attributes = Object.merge( + data.attributes, + QUIFormUtils.getFormData(Form) + ); } - if (Form.getElement('[name="frontendTitle"]')) { + if (Form && Form.getElement('[name="frontendTitle"]')) { data.attributes.frontendTitle = Form.getElement('[name="frontendTitle"]').value; } - if (unload === 'settings') { + if (unload === 'settings' && this.$Areas) { data.attributes.areas = this.$Areas.getAreas().join(','); - //data.attributes.width = Form.elements.width.value; - //data.attributes.height = Form.elements.height.value; - //data.attributes.classes = Form.elements.classes.value; var flexibleList = [], fieldData = QUIFormUtils.getFormData(Form); @@ -390,9 +363,6 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ } this.$customfields = flexibleList; - - this.$Areas.destroy(); - this.$Areas = false; } if (unload === 'extra') { @@ -402,15 +372,13 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ ); } - if (unload === 'content') { + if (unload === 'content' && this.$Editor) { data.attributes.content = this.$Editor.getContent(); this.$Editor.destroy(); this.$Editor = false; } - this.$Active = null; - this.setAttribute('data', data); }, @@ -419,25 +387,21 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ * * @returns {Promise} */ - $showInformation: function () { - return new Promise(function (resolve, reject) { - - Template.get('ajax/brick/templates/information', function (result) { - this.setContent(result); - - QUIFormUtils.setDataToForm( - this.getAttribute('data').attributes, - this.getContent().getElement('form') - ); - - resolve(); + showInformation: function () { + var self = this; - }.bind(this), { - 'package': 'quiqqer/bricks', - onError : reject + return this.$hideCategory().then(function () { + return Template.get('ajax/brick/templates/information', false, { + 'package': 'quiqqer/bricks' }); - - }.bind(this)); + }).then(function (html) { + self.$Container.set('html', html); + self.$load(); + }).then(function () { + return self.$showCategory(); + }).then(function () { + self.Loader.hide(); + }); }, /** @@ -445,83 +409,88 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ * * @returns {Promise} */ - $showSettings: function () { - return new Promise(function (resolve, reject) { - - Template.get('ajax/brick/templates/settings', function (result) { - this.setContent(result); - - // areas - var Content = this.getContent(), - areas = [], - attributes = this.getAttribute('data').attributes, - customfields = this.$customfields; - - if (attributes.areas) { - areas = attributes.areas - .replace(/^,*/, '') - .replace(/,*$/, '') - .split(','); - } + showSettings: function () { + var self = this; - // areas - this.$Areas = new BrickAreas({ - brickId : this.getAttribute('id'), - projectName: this.getAttribute('projectName'), - projectLang: this.getAttribute('projectLang'), - areas : areas, - styles : { - height: 120 + return this.$hideCategory().then(function () { + return new Promise(function (resolve, reject) { + Template.get('ajax/brick/templates/settings', function (result) { + self.$Container.set('html', result); + + // areas + var Content = self.getContent(), + areas = [], + attributes = self.getAttribute('data').attributes, + customfields = self.$customfields; + + if (attributes.areas) { + areas = attributes.areas + .replace(/^,*/, '') + .replace(/,*$/, '') + .split(','); } - }).inject(Content.getElement('.quiqqer-bricks-areas')); - - // flexble settings - var i, len, data; - var TBody = Content.getElement('.brick-table-flexible tbody'); - - for (i = 0, len = this.$availableSettings.length; i < len; i++) { + // areas + self.$Areas = new BrickAreas({ + brickId : self.getAttribute('id'), + projectName: self.getAttribute('projectName'), + projectLang: self.getAttribute('projectLang'), + areas : areas, + styles : { + height: 120 + } + }).inject(Content.getElement('.quiqqer-bricks-areas')); - data = this.$availableSettings[i]; - new Element('tr', { - 'class': i % 2 ? 'odd' : 'even', - html : '<td>' + - '<label>' + - '<input type="checkbox" name="flexible-' + data.name + '" />' + - '<span>' + QUILocale.get(data.text[0], data.text[1]) + '</span>' + - '</label>' + - '</td>' - }).inject(TBody); - } + // flexble settings + var i, len, data; + var TBody = Content.getElement('.brick-table-flexible tbody'); - if (customfields) { + for (i = 0, len = self.$availableSettings.length; i < len; i++) { + data = self.$availableSettings[i]; - var name; - var Form = Content.getElement('form'); + new Element('tr', { + 'class': i % 2 ? 'odd' : 'even', + html : '<td>' + + '<label>' + + '<input type="checkbox" name="flexible-' + data.name + '" />' + + '<span>' + QUILocale.get(data.text[0], data.text[1]) + '</span>' + + '</label>' + + '</td>' + }).inject(TBody); + } - for (i = 0, len = customfields.length; i < len; i++) { + if (customfields) { + var name; + var Form = Content.getElement('form'); - name = customfields[i]; + for (i = 0, len = customfields.length; i < len; i++) { + name = customfields[i]; - if (typeof Form.elements[name] !== 'undefined') { - Form.elements[name].checked = true; - } + if (typeof Form.elements[name] !== 'undefined') { + Form.elements[name].checked = true; + } - if (typeof Form.elements['flexible-' + name] !== 'undefined') { - Form.elements['flexible-' + name].checked = true; + if (typeof Form.elements['flexible-' + name] !== 'undefined') { + Form.elements['flexible-' + name].checked = true; + } } } - } - resolve(); - - }.bind(this), { - 'package': 'quiqqer/bricks', - onError : reject + resolve(); + }, { + 'package': 'quiqqer/bricks', + onError : reject + }); }); - - }.bind(this)); + }).then(function () { + return self.$showCategory(); + }).then(function () { + self.Loader.hide(); + }).catch(function (err) { + console.error(err); + self.Loader.hide(); + }); }, /** @@ -529,22 +498,23 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ * * @returns {Promise} */ - $showExtras: function () { - return new Promise(function (resolve, reject) { - - Template.get('ajax/brick/templates/extras', function (result) { - this.setContent(result); - - this.$createExtraData().then(function () { - resolve(); - }); + showExtras: function () { + var self = this; - }.bind(this), { - 'package': 'quiqqer/bricks', - onError : reject + return this.$hideCategory().then(function () { + return Template.get('ajax/brick/templates/extras', false, { + 'package': 'quiqqer/bricks' }); - - }.bind(this)); + }).then(function (html) { + self.$Container.set('html', html); + self.$load(); + + return self.$createExtraData(); + }).then(function () { + return self.$showCategory(); + }).then(function () { + self.Loader.hide(); + }); }, /** @@ -552,34 +522,36 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ * * @returns {Promise} */ - $showContent: function () { - return new Promise(function (resolve, reject) { - - Template.get('ajax/brick/templates/content', function (result) { - this.setContent(result); - - this.$createContentEditor().then(function () { - resolve(); - }); + showContent: function () { + var self = this; - }.bind(this), { - 'package': 'quiqqer/bricks', - onError : reject + return this.$hideCategory().then(function () { + return Template.get('ajax/brick/templates/content', false, { + 'package': 'quiqqer/bricks' }); - - }.bind(this)); + }).then(function (html) { + self.$Container.set('html', html); + return self.$createContentEditor(); + }).then(function () { + return self.$showCategory(); + }).then(function () { + self.Loader.hide(); + }).catch(function (err) { + console.error(err); + self.Loader.hide(); + }); }, /** * Create the editor, if the brick type is a content type * - * @param {Function} [callback] * @return Promise */ - $createContentEditor: function (callback) { - return new Promise(function (resolve) { + $createContentEditor: function () { + var self = this; - var TableBody = this.$Elm.getElement('table.brick-edit-content tbody'), + return new Promise(function (resolve) { + var TableBody = self.$Container.getElement('table.brick-edit-content tbody'), TD = new Element('td'), TR = new Element('tr', { 'class': 'odd' @@ -588,25 +560,25 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ TD.inject(TR); TR.inject(TableBody); - var contenSize = this.getContent().getSize(); + var contentSize = self.getContent().getSize(); // load ckeditor require(['classes/editor/Manager'], function (EditorManager) { new EditorManager().getEditor(null, function (Editor) { - this.$Editor = Editor; - this.$Editor.setAttribute('showLoader', false); + self.$Editor = Editor; + self.$Editor.setAttribute('showLoader', false); var Project = Projects.get( - this.getAttribute('projectName'), - this.getAttribute('projectLang') + self.getAttribute('projectName'), + self.getAttribute('projectLang') ); - this.$Editor.setProject(Project); + self.$Editor.setProject(Project); var height = 300; - if ((contenSize.y - 100) > height) { - height = contenSize.y - 100; + if ((contentSize.y - 100) > height) { + height = contentSize.y - 100; } @@ -619,24 +591,16 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ } }).inject(TD); - this.$Editor.addEvent('onLoaded', function () { - if (typeof callback === 'function') { - callback(); - } - - resolve(); - }); - - this.$Editor.inject(EditorContainer); - this.$Editor.setHeight(EditorContainer.getSize().y); - this.$Editor.setWidth(EditorContainer.getSize().x); - this.$Editor.setContent( - this.getAttribute('data').attributes.content + self.$Editor.addEvent('onLoaded', resolve); + self.$Editor.inject(EditorContainer); + self.$Editor.setHeight(EditorContainer.getSize().y); + self.$Editor.setWidth(EditorContainer.getSize().x); + self.$Editor.setContent( + self.getAttribute('data').attributes.content ); - - }.bind(this)); - }.bind(this)); - }.bind(this)); + }); + }); + }); }, /** @@ -649,8 +613,8 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ var TableExtra = this.$Elm.getElement('table.brick-edit-extra-header'), TableBody = TableExtra.getElement('tbody'); - TableBody.getElement('[name="frontendTitle"]').value = this.getAttribute( - 'data').attributes.frontendTitle; + TableBody.getElement('[name="frontendTitle"]').value = + this.getAttribute('data').attributes.frontendTitle; if (!this.$availableSettings || !this.$availableSettings.length) { TableExtra.setStyle('display', 'none'); @@ -665,12 +629,11 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ TableExtra.setStyle('display', null); - var Form = this.getContent().getElement('form'); - var i, len, Row, text, Value, setting, extraFieldId; var self = this, - id = this.getId(); + id = this.getId(), + Form = this.getContent().getElement('form'); // extra settings for (i = 0, len = this.$availableSettings.length; i < len; i++) { @@ -744,7 +707,6 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ // parse controls QUI.parse(TableExtra).then(function () { return ControlUtils.parse(TableExtra); - }).then(function () { // set project to the controls TableExtra.getElements('[data-quiid]').each(function (Elm) { @@ -765,6 +727,115 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ }).catch(reject); }.bind(this)); + }, + + /** + * event: on category enter + * + * @return Promise + */ + $onCategoryEnter: function (Panel, Category) { + if (this.$loaded === false) { + return Promise.resolve(); + } + + switch (Category.getAttribute('name')) { + case 'information': + case 'extra': + case 'settings': + case 'content': + return Promise.resolve(); + } + + var self = this; + + this.Loader.show(); + + return this.$hideCategory().then(function () { + return new Promise(function (resolve, reject) { + QUIAjax.get('package_quiqqer_bricks_ajax_getPanelCategory', function (result) { + self.$Container.set('html', '<form>' + result + '</form>'); + self.$load(); + resolve(); + }, { + 'package': 'quiqqer/bricks', + brickId : self.getAttribute('id'), + category : Category.getAttribute('name'), + onError : reject + }); + }); + }).then(function () { + return QUI.parse(); + }).then(function () { + return self.$showCategory(); + }).then(function () { + self.Loader.hide(); + + }).catch(function (err) { + console.error(err); + self.Loader.hide(); + }); + }, + + /** + * event: on category leave + */ + $onCategoryLeave: function () { + this.$unload(); + + if (this.$Areas) { + this.$Areas.destroy(); + this.$Areas = false; + } + + if (this.$Editor) { + this.$Editor.destroy(); + this.$Editor = false; + } + }, + + /** + * show the container + * + * @return Promise + */ + $showCategory: function () { + var self = this; + + return new Promise(function (resolve) { + moofx(self.$Container).animate({ + opacity: 1, + top : 0 + }, { + duration: 250, + callback: resolve + }); + }); + }, + + /** + * hide the container + * + * @return Promise + */ + $hideCategory: function () { + var self = this; + + // unload + this.$unload(); + + return new Promise(function (resolve) { + moofx(self.$Container).animate({ + opacity: 0, + top : -20 + }, { + duration: 250, + callback: function () { + self.$Container.set('html', ''); + resolve(); + } + }); + }); } }); }); diff --git a/bin/Bricks.js b/bin/Bricks.js new file mode 100644 index 0000000000000000000000000000000000000000..206e41353e7206858c4c0e523cb4f7184dc29d97 --- /dev/null +++ b/bin/Bricks.js @@ -0,0 +1,9 @@ +/** + * Main bricks handler + */ +define('package/quiqqer/bricks/bin/Bricks', [ + 'package/quiqqer/bricks/bin/classes/Bricks' +], function (Bricks) { + "use strict"; + return new Bricks(); +}); \ No newline at end of file diff --git a/bin/Controls/ContentSwitcher.js b/bin/Controls/ContentSwitcher.js index af76bb6930b857d7b49632c9c16bda452732bc56..68551ec9dd35a7a241b417561072c88b5e6d3430 100644 --- a/bin/Controls/ContentSwitcher.js +++ b/bin/Controls/ContentSwitcher.js @@ -1,46 +1,76 @@ - /** - * * @module package/quiqqer/bricks/bin/Controls/ContentSwitcher - * - * @require qui/controls/elements/FormList - * @require css!package/quiqqer/bricks/bin/Controls/ContentSwitcher.css + * @author www.pcsg.de (Henning Leutz) */ define('package/quiqqer/bricks/bin/Controls/ContentSwitcher', [ 'qui/controls/elements/FormList', + 'utils/Controls', + 'Locale', 'css!package/quiqqer/bricks/bin/Controls/ContentSwitcher.css' -], function (QUIFormList) { +], function (QUIFormList, QUIControls, QUILocale) { "use strict"; + var lg = 'quiqqer/bricks'; + return new Class({ - Extends : QUIFormList, - Type : 'package/quiqqer/bricks/bin/Controls/ContentSwitcher', + Extends: QUIFormList, + Type : 'package/quiqqer/bricks/bin/Controls/ContentSwitcher', + + Binds: [ + '$onParsed' + ], - initialize : function (options) { + initialize: function (options) { this.parent(options); - this.setAttribute( - 'entry', - - '<div class="quiqqer-bricks-ContentSwitcher-entry">' + - '<label>' + - '<span class="entry-title">Bild</span>' + - '<input type="text" class="media-image" name="img" />' + - '</label>' + - '<label>' + - '<span class="entry-title">Ãœberschrift</span>' + - '<input type="text" name="title" />' + - '</label>' + - '<label>' + - '<span class="entry-title">Text</span>' + - '<textarea name="content" rows="10"></textarea>' + - '</label>' + - '</div>' - ); + this.addEvents({ + onParsed : this.$onParsed + }); + + this.setAttributes({ + buttonText: QUILocale.get(lg, 'contentSwitcher.entries.button.text'), + entry: '<div class="quiqqer-bricks-ContentSwitcher-entry" style="display: none;">' + + '<label class="entry-image">' + + '<span class="entry-title">' + + QUILocale.get(lg, 'contentSwitcher.entries.entry.picture') + + '</span>' + + '<input class="media-image" data-qui-options-selectable_types="image" name="img"/>' + + '</label>' + + '<label>' + + '<span class="entry-title">' + + QUILocale.get(lg, 'contentSwitcher.entries.entry.title') + + '</span>' + + '<input type="text" name="title" />' + + '</label>' + + '<label>' + + '<span class="entry-title">' + + QUILocale.get(lg, 'contentSwitcher.entries.entry.content') + + '</span>' + + '<textarea name="content" rows="10"></textarea>' + + '</label>' + + '</div>' + }); + }, + + /** + * Parses QUI controls when a new entry is created + * + * Fired after (inherited) FormList has parsed the content + * + * @param event + * @param Element - The element that was previously parsed by (inherited) FormList + */ + $onParsed: function (event, Element) { + Element.getElement('.quiqqer-bricks-ContentSwitcher-entry').show(); + // + // QUIControls.parse(Element).then(function () { + // // Element is fully parsed so we can finally show it + // Element.getElement('.quiqqer-bricks-ContentSwitcher-entry').show(); + // }); } }); }); diff --git a/bin/Controls/Slider/Promoslider.js b/bin/Controls/Slider/Promoslider.js index c1b7b2b0be283e93fe57ea779532f555bc08339e..bafd9618845a1aeb6f3fff891d029e65117e3572 100644 --- a/bin/Controls/Slider/Promoslider.js +++ b/bin/Controls/Slider/Promoslider.js @@ -3,10 +3,6 @@ * @author www.pcsg.de (Henning Leutz) * * Promo Slider - Slider für eye catching Sachen - * - * @require qui/QUI - * @require qui/controls/Control - * @require URL_OPT_DIR + bin/hammerjs/hammer.min.js */ define('package/quiqqer/bricks/bin/Controls/Slider/Promoslider', [ @@ -95,7 +91,7 @@ define('package/quiqqer/bricks/bin/Controls/Slider/Promoslider', [ self.show(event.target.get('data-no')); }; - + var i, len, Dot; for (i = 0, len = desktopSlides.length; i < len; i++) { @@ -110,6 +106,10 @@ define('package/quiqqer/bricks/bin/Controls/Slider/Promoslider', [ Dot.inject(this.$DotsDesktop); this.$desktopdots.push(Dot); + + if (desktopSlides[i].get('data-href') && desktopSlides[i].get('data-href') !== '') { + desktopSlides[i].setStyle('cursor', 'pointer'); + } } if (typeof this.$desktopdots[0] !== 'undefined') { @@ -130,6 +130,10 @@ define('package/quiqqer/bricks/bin/Controls/Slider/Promoslider', [ Dot.inject(this.$DotsMobile); this.$mobiledots.push(Dot); + + if (mobileSlides[i].get('data-href') && mobileSlides[i].get('data-href') !== '') { + mobileSlides[i].setStyle('cursor', 'pointer'); + } } if (typeof this.$mobiledots[0] !== 'undefined') { @@ -141,7 +145,7 @@ define('package/quiqqer/bricks/bin/Controls/Slider/Promoslider', [ // keyboard events document.addEvent('keyup', function (event) { - if (event.key == 'left') { + if (event.key === 'left') { self.prev(); return; } @@ -149,18 +153,28 @@ define('package/quiqqer/bricks/bin/Controls/Slider/Promoslider', [ self.next(); }); + // slide clicks + var slideClick = function () { + if (this.get('data-href') && this.get('data-href') !== '') { + window.location = this.get('data-href'); + } + }; + + desktopSlides.addEvent('click', slideClick); + mobileSlides.addEvent('click', slideClick); + // touch events if (this.getAttribute('touch')) { this.$Touch = new Hammer(this.getElm()); this.$Touch.on('swipe', function (ev) { - if (ev.offsetDirection == 4) { + if (ev.offsetDirection === 4) { self.prev(); return; } - if (ev.offsetDirection == 2) { + if (ev.offsetDirection === 2) { self.next(); } }); @@ -283,8 +297,8 @@ define('package/quiqqer/bricks/bin/Controls/Slider/Promoslider', [ if (slideNo < 0) { slideNo = Elm.getElements( - '.quiqqer-bricks-promoslider-slide' - ).length - 1; + '.quiqqer-bricks-promoslider-slide' + ).length - 1; } return this.show(slideNo); @@ -409,11 +423,9 @@ define('package/quiqqer/bricks/bin/Controls/Slider/Promoslider', [ this.$hideSheetToLeft(Current).then(function () { return this.$showSheetFromRight(Slide); - }.bind(this)).then(function () { resolve(); this.$running = false; - }.bind(this)); }.bind(this)); @@ -530,7 +542,7 @@ define('package/quiqqer/bricks/bin/Controls/Slider/Promoslider', [ return new Promise(function (resolve) { (function () { - if (Node.getStyle('position') == 'absolute') { + if (Node.getStyle('position') === 'absolute') { var oldPos = Node.getStyle('left').toInt(); moofx(Node).animate({ @@ -580,7 +592,7 @@ define('package/quiqqer/bricks/bin/Controls/Slider/Promoslider', [ return new Promise(function (resolve) { (function () { - if (Node.getStyle('position') == 'absolute') { + if (Node.getStyle('position') === 'absolute') { var origLeft = Node.getStyle('left').toInt(); Node.setStyle('left', origLeft + 50); diff --git a/bin/Manager.js b/bin/Manager.js index 7979104592168d98f03660351ede2d67a21e63ef..45a51b6a9866b53f975a3f4cd54556bd8021de75 100644 --- a/bin/Manager.js +++ b/bin/Manager.js @@ -16,6 +16,7 @@ define('package/quiqqer/bricks/bin/Manager', [ 'Locale', 'Projects', 'Ajax', + 'package/quiqqer/bricks/bin/Bricks', 'Mustache', 'text!package/quiqqer/bricks/bin/Manager.Copy.html', @@ -23,7 +24,7 @@ define('package/quiqqer/bricks/bin/Manager', [ 'css!package/quiqqer/bricks/bin/Manager.css' ], function (QUI, QUIPanel, QUISelect, QUIButton, QUISeparator, QUIConfirm, Grid, QUILocale, Projects, Ajax, - Mustache, templateCopy) { + Bricks, Mustache, templateCopy) { "use strict"; var lg = 'quiqqer/bricks'; @@ -43,7 +44,9 @@ define('package/quiqqer/bricks/bin/Manager', [ '$openCopyDialog', '$openDeleteDialog', '$onDblClick', - '$onClick' + '$onClick', + '$onInject', + '$onDestroy' ], options: { @@ -58,8 +61,10 @@ define('package/quiqqer/bricks/bin/Manager', [ this.$ProjectLangs = false; this.addEvents({ - onCreate: this.$onCreate, - onResize: this.$onResize + onCreate : this.$onCreate, + onResize : this.$onResize, + onInject : this.$onInject, + onDestroy: this.$onDestroy }); }, @@ -79,7 +84,7 @@ define('package/quiqqer/bricks/bin/Manager', [ this.Loader.show(); - this.getBricksFromProject(project, lang, function (result) { + Bricks.getBricksFromProject(project, lang).then(function (result) { if (typeof callback === 'function') { callback(); } @@ -282,6 +287,30 @@ define('package/quiqqer/bricks/bin/Manager', [ }); }, + /** + * event: on inject + */ + $onInject: function () { + Bricks.addEvents({ + onBrickDelete: this.refresh, + onBrickSave : this.refresh, + onBrickCopy : this.refresh, + onBrickCreate: this.refresh + }); + }, + + /** + * event: on destroy + */ + $onDestroy: function () { + Bricks.removeEvents({ + onBrickDelete: this.refresh, + onBrickSave : this.refresh, + onBrickCopy : this.refresh, + onBrickCreate: this.refresh + }); + }, + /** * event : on resize */ @@ -390,7 +419,7 @@ define('package/quiqqer/bricks/bin/Manager', [ '</label>' ); - self.getAvailableBricks(function (bricklist) { + Bricks.getAvailableBricks().then(function (bricklist) { if (!Body) { return; } @@ -444,17 +473,15 @@ define('package/quiqqer/bricks/bin/Manager', [ } var project = self.$ProjectSelect.getValue(), - lang = self.$ProjectLangs.getValue(); + lang = self.$ProjectLangs.getValue(), + data = { + title: Title.value, + type : Type.value + }; - self.createBrick(project, lang, { - title: Title.value, - type : Type.value - }, function (brickId) { + Bricks.createBrick(project, lang, data).then(function (brickId) { Win.close(); - - self.refresh(function () { - self.editBrick(brickId); - }); + self.editBrick(brickId); }); } } @@ -497,9 +524,8 @@ define('package/quiqqer/bricks/bin/Manager', [ onSubmit: function (Win) { Win.Loader.show(); - self.deleteBricks(brickIds, function () { + Bricks.deleteBricks(brickIds).then(function () { Win.close(); - self.refresh(); }); } } @@ -555,16 +581,13 @@ define('package/quiqqer/bricks/bin/Manager', [ Select.setValue(lang); - Ajax.get('package_quiqqer_bricks_ajax_getBrick', function (data) { + Bricks.getBrick(brickId).then(function (data) { var Form = Content.getElement('form'); Form.elements.title.value = data.attributes.title; Form.elements.description.value = data.attributes.description; Win.Loader.hide(); - }, { - 'package': 'quiqqer/bricks', - brickId : brickId }); }); }, @@ -578,19 +601,13 @@ define('package/quiqqer/bricks/bin/Manager', [ var Select = Content.getElement('.dialog-bricks-copy-languages [data-quiid]'); var Language = QUI.Controls.getById(Select.get('data-quiid')); - Ajax.post('package_quiqqer_bricks_ajax_brick_copy', function (data) { - self.refresh(); + Bricks.copyBrick(brickId, { + 'lang' : Language.getValue(), + 'title' : Form.elements.title.value, + 'description': Form.elements.description.value + }).then(function (data) { Win.close(); - - self.editBrick(data['id']); - }, { - 'package': 'quiqqer/bricks', - brickId : brickId, - params : JSON.encode({ - 'lang' : Language.getValue(), - 'title' : Form.elements.title.value, - 'description': Form.elements.description.value - }) + self.editBrick(data.id); }); } } @@ -612,151 +629,10 @@ define('package/quiqqer/bricks/bin/Manager', [ '#id' : 'brick-edit-' + brickId, id : brickId, projectName: this.$ProjectSelect.getValue(), - projectLang: this.$ProjectLangs.getValue(), - events : { - onDelete: this.refresh - } + projectLang: this.$ProjectLangs.getValue() }) ); }.bind(this)); - }, - - /** - * Methods / Model - */ - - /** - * Return the available bricks - * - * @param {Function} [callback] - callback function - * - * @return Promise - */ - getAvailableBricks: function (callback) { - return new Promise(function (resolve, reject) { - - Ajax.get('package_quiqqer_bricks_ajax_getAvailableBricks', function (result) { - - if (typeof callback === 'function') { - callback(result); - } - - resolve(result); - }, { - 'package': 'quiqqer/bricks', - onError : reject - }); - - }); - }, - - /** - * Return the bricksf from a project - * - * @param {String} project - name of the project - * @param {String} lang - Language of the project - * @param {Function} [callback] - callback function - * - * @return Promise - */ - getBricksFromProject: function (project, lang, callback) { - return new Promise(function (resolve, reject) { - - Ajax.get('package_quiqqer_bricks_ajax_project_getBricks', function (result) { - - if (typeof callback === 'function') { - callback(result); - } - - resolve(result); - }, { - 'package': 'quiqqer/bricks', - project : JSON.encode({ - name: project, - lang: lang - }), - onError : reject - }); - - }); - }, - - /** - * Create a new brick - * - * @param {String} project - name of the project - * @param {String} lang - Language of the project - * @param {Object} data - Data of the brick - * @param {Function} [callback] - callback function - * - * @return Promise - */ - createBrick: function (project, lang, data, callback) { - return new Promise(function (resolve, reject) { - - Ajax.post('package_quiqqer_bricks_ajax_project_createBrick', function (brickId) { - - if (typeof callback === 'function') { - callback(brickId); - } - - resolve(brickId); - }, { - 'package': 'quiqqer/bricks', - project : JSON.encode({ - name: project, - lang: lang - }), - data : JSON.encode(data), - onError : reject - }); - - }); - }, - - /** - * Delete the Brick-Ids - * - * @param {Array} brickIds - Brick IDs which should be deleted - * @param {Function} [callback] - callback function - * - * @return Promise - */ - deleteBricks: function (brickIds, callback) { - var panels = QUI.Controls.getByType( - 'package/quiqqer/bricks/bin/BrickEdit' - ); - - return new Promise(function (resolve, reject) { - - Ajax.post('package_quiqqer_bricks_ajax_brick_delete', function () { - - if (typeof callback === 'function') { - callback(); - } - - resolve(); - - // exist brick panels? - var c, i, len, clen, brickId; - - for (i = 0, len = brickIds.length; i < len; i++) { - brickId = brickIds[i]; - - for (c = 0, clen = panels.length; c < clen; c++) { - if (panels[c].getAttribute('id') === brickId) { - panels[c].destroy(); - } - } - } - - }, { - 'package': 'quiqqer/bricks', - brickIds : JSON.encode(brickIds), - onError : reject - }); - - }); } }); }); diff --git a/bin/Site/Area.js b/bin/Site/Area.js index 91d41a6ca84e5184e2deb52588bdba040ef34f5a..f5e6b0f1f0d5fe44ed8e88f9eac8ebf485fc0f05 100644 --- a/bin/Site/Area.js +++ b/bin/Site/Area.js @@ -3,17 +3,6 @@ * * @module package/quiqqer/bricks/bin/Site/Area * @author www.pcsg.de (Henning Leutz) - * - * @require qui/QUI - * @require qui/controls/Control - * @require qui/controls/buttons/Button - * @require qui/controls/windows/Popup - * @require qui/controls/windows/Confirm - * @require qui/controls/elements/List - * @require Locale - * @require Ajax - * @require package/quiqqer/bricks/bin/Sortables - * @require css!package/quiqqer/bricks/bin/Site/Area.css */ define('package/quiqqer/bricks/bin/Site/Area', [ @@ -24,18 +13,18 @@ define('package/quiqqer/bricks/bin/Site/Area', [ 'qui/controls/windows/Alert', 'qui/controls/windows/Confirm', 'qui/controls/elements/List', + 'package/quiqqer/bricks/bin/Bricks', 'Locale', 'Ajax', 'package/quiqqer/bricks/bin/Sortables', 'css!package/quiqqer/bricks/bin/Site/Area.css' -], function (QUI, QUIControl, QUIButton, QUIPopup, QUIAlert, QUIConfirm, QUIList, QUILocale, QUIAjax, Sortables) { +], function (QUI, QUIControl, QUIButton, QUIPopup, QUIAlert, QUIConfirm, QUIList, Bricks, QUILocale, QUIAjax, Sortables) { "use strict"; var lg = 'quiqqer/bricks'; - return new Class({ Extends: QUIControl, @@ -46,7 +35,9 @@ define('package/quiqqer/bricks/bin/Site/Area', [ 'openBrickSettingDialog', 'openSettingsDialog', 'createNewBrick', - '$onInject' + '$onInject', + '$onDestroy', + '$onBrickRefresh' ], options: { @@ -78,12 +69,33 @@ define('package/quiqqer/bricks/bin/Site/Area', [ this.$ExtraBtns = false; this.addEvents({ - onInject: this.$onInject + onInject : this.$onInject, + onDestroy: this.$onDestroy + }); + + Bricks.addEvents({ + onBrickDelete: this.$onBrickRefresh, + onBrickSave : this.$onBrickRefresh, + onBrickCopy : this.$onBrickRefresh, + onBrickCreate: this.$onBrickRefresh }); }, /** - * Return the domnode element + * event: on destroy + */ + $onDestroy: function () { + Bricks.removeEvents({ + onBrickDelete: this.$onBrickRefresh, + onBrickSave : this.$onBrickRefresh, + onBrickCopy : this.$onBrickRefresh, + onBrickCreate: this.$onBrickRefresh + }); + }, + + /** + * Return the DOMNode element + * * @return {HTMLElement} */ create: function () { @@ -214,9 +226,7 @@ define('package/quiqqer/bricks/bin/Site/Area', [ * event : on inject */ $onInject: function () { - var self = this, - Site = this.getAttribute('Site'), - Project = Site.getProject(); + var self = this; var Loader = new Element('div', { 'class': 'quiqqer-bricks-site-category-area-loader', @@ -231,11 +241,9 @@ define('package/quiqqer/bricks/bin/Site/Area', [ opacity : 0 }); - QUIAjax.get('package_quiqqer_bricks_ajax_project_getBricks', function (bricks) { + this.$refreshAvailableBricks().then(function () { self.$AddButton.enable(); - - self.$availableBricks = bricks; - self.$loaded = true; + self.$loaded = true; self.$brickIds.each(function (brickId) { self.addBrickById(brickId); @@ -257,11 +265,35 @@ define('package/quiqqer/bricks/bin/Site/Area', [ } Loader.destroy(); + }); + }, - }, { - 'package': 'quiqqer/bricks', - project : Project.encode(), - area : this.getAttribute('name') + /** + * event : on brick changes + */ + $onBrickRefresh: function () { + this.$refreshAvailableBricks(); + }, + + /** + * Refresh the available bricks + * + * @return {*|Promise} + */ + $refreshAvailableBricks: function () { + var self = this, + Site = this.getAttribute('Site'), + Project = Site.getProject(); + console.warn('refresh'); + return new Promise(function (resolve) { + QUIAjax.get('package_quiqqer_bricks_ajax_project_getBricks', function (bricks) { + self.$availableBricks = bricks; + resolve(bricks); + }, { + 'package': 'quiqqer/bricks', + project : Project.encode(), + area : self.getAttribute('name') + }); }); }, diff --git a/bin/Site/BrickEdit.js b/bin/Site/BrickEdit.js index 1395ff6bc21ec86856569b6bb6acc80699542165..c3b9b8f672b66a5e4a655e8c8d06c2c15932005e 100644 --- a/bin/Site/BrickEdit.js +++ b/bin/Site/BrickEdit.js @@ -3,15 +3,6 @@ * * @module package/quiqqer/bricks/bin/Site/Area * @author www.pcsg.de (Henning Leutz) - * - * @require qui/QUI - * @require qui/controls/Control - * @require qui/controls/loader/Loader - * @require qui/utils/Form - * @require utils/Template - * @require utils/Controls - * @require Ajax - * @require css!package/quiqqer/bricks/bin/Site/BrickEdit.css */ define('package/quiqqer/bricks/bin/Site/BrickEdit', [ diff --git a/bin/Site/Category.js b/bin/Site/Category.js index 4f2d0892372e160737d51a17d1247b02015231eb..664576756a3922ddea1feb38cfb83e617a8f2b37 100644 --- a/bin/Site/Category.js +++ b/bin/Site/Category.js @@ -4,14 +4,6 @@ * @module package/quiqqer/bricks/bin/Site/Category * @author www.pcsg.de (Henning Leutz) * - * @require qui/QUI - * @require qui/controls/Control - * @require qui/controls/loader/Loader - * @require Ajax - * @require Locale - * @require package/quiqqer/bricks/bin/Site/Area - * @require css!package/quiqqer/bricks/bin/Site/Category.css - * * @event onLoaded */ define('package/quiqqer/bricks/bin/Site/Category', [ @@ -141,6 +133,11 @@ define('package/quiqqer/bricks/bin/Site/Category', [ */ $onDestroy: function () { this.updateSite(); + + // destroy areas + this.areas.each(function (Area) { + Area.destroy(); + }); }, /** diff --git a/bin/classes/Areas.js b/bin/classes/Areas.js index 280cfb3dc5e3bf653f17d9b52e5069a5159dd2c0..32af44a1b24dd203049a05406300e5f354b9688c 100644 --- a/bin/classes/Areas.js +++ b/bin/classes/Areas.js @@ -1,3 +1,8 @@ +/** + * Main area handler + * + * @author www.pcsg.de (Henning Leutz) + */ define('package/quiqqer/bricks/bin/classes/Areas', [ 'qui/QUI', @@ -10,7 +15,7 @@ define('package/quiqqer/bricks/bin/classes/Areas', [ return new Class({ Extends: QDOM, - Type : 'classes/editor/Manager', + Type : 'package/quiqqer/bricks/bin/classes/Areas', initialize: function (options) { this.parent(options); diff --git a/bin/classes/Bricks.js b/bin/classes/Bricks.js new file mode 100644 index 0000000000000000000000000000000000000000..609c61fd2a22c07e3e2154d8358ae82c136628a2 --- /dev/null +++ b/bin/classes/Bricks.js @@ -0,0 +1,192 @@ +/** + * Main Brick Handler + * + * @author www.pcsg.de (Henning Leutz) + * + * @event onBrickSave [brickId, data, result] + * @event onBrickCopy [brickId, params, result] + * @event onBrickCreate [brick, project, lang, data] + * @event onBrickDelete [brickIds] + */ +define('package/quiqqer/bricks/bin/classes/Bricks', [ + + 'qui/QUI', + 'qui/classes/DOM', + 'Ajax' + +], function (QUI, QDOM, QUIAjax) { + "use strict"; + + return new Class({ + Extends: QDOM, + Type : 'package/quiqqer/bricks/bin/classes/Bricks', + + initialize: function (options) { + this.parent(options); + }, + + /** + * Return the data of a brick + * + * @param {Number|String} brickId + * @return Promise + */ + getBrick: function (brickId) { + return new Promise(function (resolve, reject) { + QUIAjax.get('package_quiqqer_bricks_ajax_getBrick', resolve, { + 'package': 'quiqqer/bricks', + brickId : brickId, + onError : reject + }); + }); + }, + + /** + * Return the data of a brick + * + * @param {Number|String} brickId + * @param {Object} data - Brick data + * @return Promise + */ + saveBrick: function (brickId, data) { + var self = this; + return new Promise(function (resolve, reject) { + QUIAjax.get('package_quiqqer_bricks_ajax_brick_save', function (result) { + self.fireEvent('brickSave', [brickId, data, result]); + resolve(result); + }, { + 'package': 'quiqqer/bricks', + brickId : brickId, + data : JSON.encode(data), + onError : reject + }); + }); + }, + + /** + * Return the data of a brick + * + * @param {Number|String} brickId + * @param {Object} params + * @return Promise + */ + copyBrick: function (brickId, params) { + var self = this; + + params = params || {}; + + return new Promise(function (resolve, reject) { + QUIAjax.get('package_quiqqer_bricks_ajax_brick_copy', function (result) { + self.fireEvent('brickCopy', [brickId, params, result]); + resolve(result); + }, { + 'package': 'quiqqer/bricks', + brickId : brickId, + params : JSON.encode(params), + onError : reject + }); + }); + }, + + /** + * Return the bricks from a project + * + * @param {String} project - name of the project + * @param {String} lang - Language of the project + * @return Promise + */ + getBricksFromProject: function (project, lang) { + return new Promise(function (resolve, reject) { + QUIAjax.get('package_quiqqer_bricks_ajax_project_getBricks', resolve, { + 'package': 'quiqqer/bricks', + project : JSON.encode({ + name: project, + lang: lang + }), + onError : reject + }); + }); + }, + + /** + * Return all available bricks + * + * @return Promise + */ + getAvailableBricks: function () { + return new Promise(function (resolve, reject) { + QUIAjax.get('package_quiqqer_bricks_ajax_getAvailableBricks', resolve, { + 'package': 'quiqqer/bricks', + onError : reject + }); + }); + }, + + + /** + * Create a new brick + * + * @param {String} project - name of the project + * @param {String} lang - Language of the project + * @param {Object} data - Data of the brick + * + * @return Promise + */ + createBrick: function (project, lang, data) { + var self = this; + + return new Promise(function (resolve, reject) { + QUIAjax.post('package_quiqqer_bricks_ajax_project_createBrick', function (brick) { + self.fireEvent('brickCreate', [brick, project, lang, data]); + resolve(brick); + }, { + 'package': 'quiqqer/bricks', + project : JSON.encode({ + name: project, + lang: lang + }), + data : JSON.encode(data), + onError : reject + }); + }); + }, + + /** + * Delete the Brick-Ids + * + * @param {Array} brickIds - Brick IDs which should be deleted + * @return Promise + */ + deleteBricks: function (brickIds) { + var self = this; + + var panels = QUI.Controls.getByType( + 'package/quiqqer/bricks/bin/BrickEdit' + ); + + return new Promise(function (resolve, reject) { + QUIAjax.post('package_quiqqer_bricks_ajax_brick_delete', function () { + // exist brick panels? + var c, i, len, clen, brickId; + + for (i = 0, len = brickIds.length; i < len; i++) { + brickId = brickIds[i]; + + for (c = 0, clen = panels.length; c < clen; c++) { + if (panels[c].getAttribute('id') === brickId) { + panels[c].destroy(); + } + } + } + + self.fireEvent('brickDelete', [brickIds]); + resolve(); + }, { + 'package': 'quiqqer/bricks', + brickIds : JSON.encode(brickIds), + onError : reject + }); + }); + } + }); +}); diff --git a/bricks.xml b/bricks.xml index b8f59a7d497c5bfe92f900a110a3475a83f6fbc2..4da1eeadf0d31568e830a1b00d23a363cd3b052a 100644 --- a/bricks.xml +++ b/bricks.xml @@ -2,7 +2,7 @@ <quiqqer> <bricks> <!-- available standard bricks --> - <brick control="\QUI\Controls\Breadcrumb"> + <brick control="\QUI\Controls\Breadcrumb" hasContent="0"> <title> <locale group="quiqqer/bricks" var="brick.control.breadcrumb.title"/> </title> @@ -582,7 +582,7 @@ </settings> </brick> - <brick control="\QUI\Bricks\Controls\SideBox1"> + <brick control="\QUI\Bricks\Controls\SideBox1" deprecated="1"> <title> <locale group="quiqqer/bricks" var="brick.control.sidebox1.title"/> </title> @@ -643,7 +643,7 @@ </settings> </brick> - <brick control="\QUI\Bricks\Controls\SideBox2"> + <brick control="\QUI\Bricks\Controls\SideBox2" deprecated="1"> <title> <locale group="quiqqer/bricks" var="brick.control.sidebox2.title"/> </title> @@ -701,7 +701,7 @@ </settings> </brick> - <brick control="\QUI\Bricks\Controls\SideBox3"> + <brick control="\QUI\Bricks\Controls\SideBox3" deprecated="1"> <title> <locale group="quiqqer/bricks" var="brick.control.sidebox3.title"/> </title> @@ -820,7 +820,7 @@ </settings> </brick> - <brick control="\QUI\Bricks\Controls\SideBox4"> + <brick control="\QUI\Bricks\Controls\SideBox4" deprecated="1"> <title> <locale group="quiqqer/bricks" var="brick.control.sidebox4.title"/> </title> diff --git a/locale.xml b/locale.xml index 956c49956e7e318fdf9aedd405a14d6db0b7c5c6..386b36fc4c1ca2becd8a33743db9161e9acbde39 100644 --- a/locale.xml +++ b/locale.xml @@ -726,6 +726,26 @@ Möchten Sie die Bausteine aus der Bausteinzone entfernen?</p>]]></de> <en><![CDATA[Edit Slide]]></en> </locale> + <locale name="contentSwitcher.entries.button.text"> + <de><![CDATA[Eintrag hinzufügen]]></de> + <en><![CDATA[Add entry]]></en> + </locale> + + <locale name="contentSwitcher.entries.entry.picture"> + <de><![CDATA[Bild]]></de> + <en><![CDATA[Picture]]></en> + </locale> + + <locale name="contentSwitcher.entries.entry.title"> + <de><![CDATA[Ãœberschrift]]></de> + <en><![CDATA[Title]]></en> + </locale> + + <locale name="contentSwitcher.entries.entry.content"> + <de><![CDATA[Text]]></de> + <en><![CDATA[Content]]></en> + </locale> + <locale name="dialog.copy.title"> <de><![CDATA[Baustein #[id] kopieren]]></de> <en><![CDATA[Copy brick #[id]]]></en> @@ -802,7 +822,7 @@ Möchten Sie die Bausteine aus der Bausteinzone entfernen?</p>]]></de> <!-- Content Switcher --> <locale name="bricks.ContentSwitcher.title"> <de><![CDATA[Bausteine: Inhalt-Wechsel]]></de> - <en><![CDATA[Bricks Content with image]]></en> + <en><![CDATA[Bricks Content Switcher]]></en> <pl><![CDATA[Bricks: Content Switcher: treść i zdjÄ™cie]]></pl> </locale> <locale name="bricks.ContentSwitcher.description"> diff --git a/menu.xml b/menu.xml index d4808cca61fee646f7313a2f34cde5a2ef89c980..014b7a0e9f75b150952f87e78eb6785013cca0e1 100644 --- a/menu.xml +++ b/menu.xml @@ -4,6 +4,7 @@ name="bricks" icon="fa fa-th" require="package/quiqqer/bricks/bin/Manager" + permission="quiqqer.bricks.edit" > <locale group="quiqqer/bricks" var="menu.bricks.text" /> </item> diff --git a/package.xml b/package.xml index 761d594b10cddc19ce42bdf45c55a4df4a12fdd5..c9cdaf85cb0ce1c268b3d10c78fbc02f4e23d289 100644 --- a/package.xml +++ b/package.xml @@ -16,7 +16,7 @@ <wiki><![CDATA[https://dev.quiqqer.com/quiqqer/package-bricks/wikis/home]]></wiki> </support> - <image src="URL_OPT_DIR/quiqqer/package-bricks/bin/images/Logo.jpg"/> + <image src="URL_OPT_DIR/quiqqer/bricks/bin/images/Logo.jpg"/> <copyright> <name><![CDATA[PCSG - Computer & Internet Service OHG]]></name> diff --git a/src/QUI/Bricks/Brick.php b/src/QUI/Bricks/Brick.php index 6c8b0b61fc7beb034c624ef1d2e82c9acf99a105..17ec43ab3e2e94ed26c6e58066ac42193459678d 100644 --- a/src/QUI/Bricks/Brick.php +++ b/src/QUI/Bricks/Brick.php @@ -79,7 +79,8 @@ public function __construct($params = array()) 'height' => '', 'width' => '', 'classes' => '', - 'frontendTitle' => '' + 'frontendTitle' => '', + 'hasContent' => 1 ); $this->setAttributes($default); @@ -124,6 +125,13 @@ public function __construct($params = array()) $this->settings[$entry['name']] = false; } + $availableAttributes = Utils::getAttributesForBrick($this); + + foreach ($availableAttributes as $attribute) { + $this->settings[$attribute] = false; + } + + // control default settings if (is_object($Control)) { $controlSettings = $Control->getAttributes(); diff --git a/src/QUI/Bricks/Controls/Slider/Promoslider.css b/src/QUI/Bricks/Controls/Slider/Promoslider.css index a8ed18b036fc0b94e8266f1746a0c800a8752409..f67b437120741321f57940d34618a89dfa7d7f14 100644 --- a/src/QUI/Bricks/Controls/Slider/Promoslider.css +++ b/src/QUI/Bricks/Controls/Slider/Promoslider.css @@ -47,6 +47,7 @@ .quiqqer-bricks-promoslider__nav_inner .quiqqer-bricks-promoslider-slide-image { height: 100%; + padding: 0; } .quiqqer-bricks-promoslider-slide-image img { diff --git a/src/QUI/Bricks/Controls/Slider/Promoslider.html b/src/QUI/Bricks/Controls/Slider/Promoslider.html index 17085860b96abca599dd9d4613b4a3d02234ae32..5154d22476ddc7ca97e1216f863fe976be3d1219 100644 --- a/src/QUI/Bricks/Controls/Slider/Promoslider.html +++ b/src/QUI/Bricks/Controls/Slider/Promoslider.html @@ -18,7 +18,8 @@ style="display: none" {/if} data-no="{$key}" - role=option + role="option" + data-href="{$slide.url}" > {if $slide.image && $this->getAttribute('image-as-wallpaper')} <div class="quiqqer-bricks-promoslider-slide-image quiqqer-bricks-promoslider-slide-image__cover" @@ -63,7 +64,8 @@ style="display: none" {/if} data-no="{$key}" - role=option + data-href="{$slide.url}" + role="option" > {if $slide.image && $this->getAttribute('image-as-wallpaper')} <div class="quiqqer-bricks-promoslider-slide-mobile-image quiqqer-bricks-promoslider-slide-image__cover" diff --git a/src/QUI/Bricks/Events.php b/src/QUI/Bricks/Events.php index f09520db89fa486da65d1321a806d5c743d9dac9..751ea05270f8a13f7a36f134a7abf889fa3a25ed 100644 --- a/src/QUI/Bricks/Events.php +++ b/src/QUI/Bricks/Events.php @@ -219,7 +219,17 @@ public static function onPackageSetup(QUI\Package\Package $Package) if ($Package->getName() !== 'quiqqer/bricks') { return; } + + $php = 'php'; - shell_exec('php '.OPT_DIR.'quiqqer/bricks/patches/uniqueIds.php'); + if (defined('PHP_BINARY')) { + $php = PHP_BINARY; + } + + try { + shell_exec($php.' '.OPT_DIR.'quiqqer/bricks/patches/uniqueIds.php'); + } catch (\Exception $Exception) { + QUI\System\Log::writeException($Exception); + } } } diff --git a/src/QUI/Bricks/Manager.php b/src/QUI/Bricks/Manager.php index 5daf2a018b34134c5481cfc65bd341775b1a1ffd..be5fc547f9817c2fc4f26073984dcdb4979df3ae 100644 --- a/src/QUI/Bricks/Manager.php +++ b/src/QUI/Bricks/Manager.php @@ -629,11 +629,11 @@ protected function parseSettingToBrickArray(\DOMElement $Setting) * Return the bricks from the area * * @param string $brickArea - Name of the area - * @param Site $Site + * @param QUI\Interfaces\Projects\Site $Site * * @return array */ - public function getBricksByArea($brickArea, Site $Site) + public function getBricksByArea($brickArea, QUI\Interfaces\Projects\Site $Site) { if (empty($brickArea)) { return array(); @@ -755,7 +755,6 @@ public function saveBrick($brickId, array $brickData) $brickData['areas'] = $brickData['attributes']['areas']; } - if (isset($brickData['areas'])) { $parts = explode(',', $brickData['areas']); @@ -788,6 +787,13 @@ public function saveBrick($brickId, array $brickData) $Brick->setSettings($brickData['settings']); } + $brickAttributes = Utils::getAttributesForBrick($Brick); + + foreach ($brickAttributes as $attribute) { + if (isset($brickData['attributes'][$attribute])) { + $Brick->setSetting($attribute, $brickData['attributes'][$attribute]); + } + } // custom fields $customfields = array(); @@ -811,6 +817,9 @@ public function saveBrick($brickId, array $brickData) } } + QUI\System\Log::writeRecursive($brickData); + QUI\System\Log::writeRecursive($Brick->getSettings()); + // update QUI::getDataBase()->update($this->getTable(), array( 'title' => $Brick->getAttribute('title'), @@ -915,53 +924,18 @@ public function copyBrick($brickId, $params = array()) */ protected function getBricksXMLFiles() { - $cache = 'quiqqer/bricks/availableBrickFiles'; - - try { - return QUI\Cache\Manager::get($cache); - } catch (QUI\Exception $Exception) { - } - - $PKM = QUI::getPackageManager(); - $Projects = QUI::getProjectManager(); - $packages = $PKM->getInstalled(); - $result = array(); - - // package bricks - foreach ($packages as $package) { - $bricksXML = OPT_DIR.$package['name'].'/bricks.xml'; - - if (file_exists($bricksXML)) { - $result[] = $bricksXML; - } - } - - // project bricks - $projects = $Projects->getProjects(); - - foreach ($projects as $project) { - $bricksXML = USR_DIR.$project.'/bricks.xml'; - - if (file_exists($bricksXML)) { - $result[] = $bricksXML; - } - } - - - QUI\Cache\Manager::set($cache, $result); - - return $result; + return Utils::getBricksXMLFiles(); } /** * Return the bricks from an area which are inherited from its parents * * @param string $brickArea - Name of the area - * @param Site $Site - Site object + * @param QUI\Interfaces\Projects\Site $Site - Site object * * @return array */ - protected function getInheritedBricks($brickArea, Site $Site) + protected function getInheritedBricks($brickArea, QUI\Interfaces\Projects\Site $Site) { // inheritance ( vererbung ) $Project = $Site->getProject(); diff --git a/src/QUI/Bricks/Panel.php b/src/QUI/Bricks/Panel.php new file mode 100644 index 0000000000000000000000000000000000000000..cc547c9a600c27a65d17874f470dca551dc973d2 --- /dev/null +++ b/src/QUI/Bricks/Panel.php @@ -0,0 +1,146 @@ +<?php + +/** + * This file contains QUI\Bricks\Panel + */ + +namespace QUI\Bricks; + +use QUI; + +/** + * Class Panel + * - Helper class for the brick panel in the administration + * + * @package QUI\Bricks + */ +class Panel extends QUI\Utils\Singleton +{ + /** + * @param integer $brickId + * @param string $category + * + * @return string + */ + public function getCategoryFromBrick($brickId, $category) + { + $BrickManager = QUI\Bricks\Manager::init(); + $Brick = $BrickManager->getBrickById($brickId); + $type = $Brick->getAttribute('type'); + + $cacheName = 'quiqqer/bricks/categories/category/'.$type.'/'.$category; + + try { + return QUI\Cache\Manager::get($cacheName); + } catch (QUI\Exception $Exception) { + } + + + $files = Utils::getBricksXMLFiles(); + $path = $this->getPath($Brick); + $path = $path.'/window'; + + $Settings = QUI\Utils\XML\Settings::getInstance(); + $Settings->setXMLPath($path); + + $result = ''; + + try { + $result = $Settings->getCategoriesHtml($files, $category); + QUI\Cache\Manager::set($cacheName, $result); + } catch (\Exception $Exception) { + QUI\System\Log::writeException($Exception); + } + + return $result; + } + + /** + * @param string|integer $brickId + * @return array + */ + public function getCategoriesFromBrick($brickId) + { + $BrickManager = QUI\Bricks\Manager::init(); + $Brick = $BrickManager->getBrickById($brickId); + + $xmlFiles = $this->getXMLFilesForBricks($Brick); + $path = $this->getPath($Brick); + $path = $path.'/window'; + + $Settings = QUI\Utils\XML\Settings::getInstance(); + $Settings->setXMLPath($path); + + $categories = array(); + + foreach ($xmlFiles as $file) { + $panel = $Settings->getPanel($file); + $categories = array_merge( + $categories, + $panel['categories']->toArray() + ); + } + + // locale + foreach ($categories as $key => $category) { + if (isset($category['title']) && is_array($category['title'])) { + $categories[$key]['text'] = QUI::getLocale()->get( + $category['title'][0], + $category['title'][1] + ); + + $categories[$key]['title'] = QUI::getLocale()->get( + $category['title'][0], + $category['title'][1] + ); + } + + if (empty($category['text']) && !empty($category['title'])) { + $categories[$key]['text'] = $category['title']; + } + } + + return $categories; + } + + /** + * @param Brick $Brick + * @return array + */ + public function getXMLFilesForBricks(Brick $Brick) + { + $path = $this->getPath($Brick); + + $xmlFiles = Utils::getBricksXMLFiles(); + $result = array(); + + foreach ($xmlFiles as $xmlFile) { + try { + $Dom = QUI\Utils\Text\XML::getDomFromXml($xmlFile); + $Path = new \DOMXPath($Dom); + $bricks = $Path->query($path); + + if ($bricks->length) { + $result[] = $xmlFile; + } + } catch (QUI\Exception $Exception) { + continue; + } + } + + return $result; + } + + /** + * @param Brick $Brick + * @return string + */ + protected function getPath(Brick $Brick) + { + $type = $Brick->getAttribute('type'); + $type = '\\'.trim($type, '\\'); + $path = '//quiqqer/bricks/brick[@control="'.$type.'"]'; + + return $path; + } +} diff --git a/src/QUI/Bricks/Utils.php b/src/QUI/Bricks/Utils.php index a026be586aa3c3199b26527704ed905388fbf55c..fd253025676302bd03b2db15c8081afa9e25aa27 100644 --- a/src/QUI/Bricks/Utils.php +++ b/src/QUI/Bricks/Utils.php @@ -121,8 +121,16 @@ public static function getTypeTemplateAreasFromXML($file, $siteType) */ public static function parseAreaToArray(\DOMElement $Brick, \DOMXPath $Path) { - $control = $Brick->getAttribute('control'); - $name = $Brick->getAttribute('name'); + $control = $Brick->getAttribute('control'); + $name = $Brick->getAttribute('name'); + + $hasContent = 1; + + if ($Brick->hasAttribute('hasContent') + && (int)$Brick->getAttribute('hasContent') === 0) { + $hasContent = 0; + } + $title = array(); $description = array(); @@ -145,6 +153,7 @@ public static function parseAreaToArray(\DOMElement $Brick, \DOMXPath $Path) return array( 'control' => $control, + 'hasContent' => $hasContent, 'name' => $name, 'title' => $title, 'description' => $description, @@ -182,4 +191,112 @@ public static function hasInheritance(Project $Project, $areaName) return true; } + + /** + * List of available bricks.xml files + * + * @return array + */ + public static function getBricksXMLFiles() + { + $cache = 'quiqqer/bricks/availableBrickFiles'; + + try { + return QUI\Cache\Manager::get($cache); + } catch (QUI\Exception $Exception) { + } + + $PKM = QUI::getPackageManager(); + $Projects = QUI::getProjectManager(); + $packages = $PKM->getInstalled(); + $result = array(); + + // package bricks + foreach ($packages as $package) { + $bricksXML = OPT_DIR.$package['name'].'/bricks.xml'; + + if (file_exists($bricksXML)) { + $result[] = $bricksXML; + } + } + + // project bricks + $projects = $Projects->getProjects(); + + foreach ($projects as $project) { + $bricksXML = USR_DIR.$project.'/bricks.xml'; + + if (file_exists($bricksXML)) { + $result[] = $bricksXML; + } + } + + + QUI\Cache\Manager::set($cache, $result); + + return $result; + } + + /** + * Return all available attributes for a brick + * + * @param Brick $Brick + * @return array + */ + public static function getAttributesForBrick(Brick $Brick) + { + $attributes = array(); + $files = Panel::getInstance()->getXMLFilesForBricks($Brick); + + // main path + $type = $Brick->getAttribute('type'); + $type = '\\'.trim($type, '\\'); + + $path = '//quiqqer/bricks/brick[@control="'.$type.'"]'; + $cache = 'quiqqer/bricks/'.md5($type).'/attributes'; + + try { + return QUI\Cache\Manager::get($cache); + } catch (QUI\Exception $Exception) { + } + + + $settingsPath = $path.'/settings/setting'; + $categoriesPath = $path.'/window/categories/category/settings'; + + foreach ($files as $file) { + $Dom = QUI\Utils\Text\XML::getDomFromXml($file); + $Path = new \DOMXPath($Dom); + + // settings + $settings = $Path->query($settingsPath); + + /* @var $Setting \DOMElement */ + foreach ($settings as $Setting) { + $attributes[] = $Setting->getAttribute('name'); + } + + // categories + $categories = $Path->query($categoriesPath); + + /* @var $Settings \DOMElement */ + foreach ($categories as $Settings) { + $children = $Settings->childNodes; + + /* @var $Child \DOMElement */ + foreach ($children as $Child) { + switch ($Child->nodeName) { + case 'input': + case 'textarea': + $attributes[] = $Child->getAttribute('conf'); + break; + } + } + } + } + + QUI\Cache\Manager::set($cache, $attributes); + + return $attributes; + } }