From 64a1ff4bb0abcf18e99ca80f7ef56565098895a3 Mon Sep 17 00:00:00 2001 From: Henning Leutz <leutz@pcsg.de> Date: Wed, 24 Jun 2015 11:11:59 +0200 Subject: [PATCH] =?UTF-8?q?Flexible=20Eigenschaften=20k=C3=B6nnen=20gesetz?= =?UTF-8?q?t=20werden=20und=20eingestellt=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ajax/brick/templates/settings.html | 33 +++++++++++ ajax/getBrick.php | 1 + bin/BrickEdit.css | 5 ++ bin/BrickEdit.js | 93 +++++++++++++++++++++++++----- database.xml | 1 + lib/QUI/Bricks/Brick.php | 40 +++++++++++-- lib/QUI/Bricks/Manager.php | 41 +++++++++---- locale.xml | 9 +++ 8 files changed, 194 insertions(+), 29 deletions(-) diff --git a/ajax/brick/templates/settings.html b/ajax/brick/templates/settings.html index 18cbf7d..a769c35 100644 --- a/ajax/brick/templates/settings.html +++ b/ajax/brick/templates/settings.html @@ -49,4 +49,37 @@ </tr> </tbody> </table> + + + <table class="data-table brick-table-flexible"> + <thead> + <tr> + <th> + {locale group="quiqqer/bricks" var="brick.edit.settings.flexible.header"} + <div class="description"> + {locale group="quiqqer/bricks" var="brick.edit.settings.flexible.header.description"} + </div> + </th> + </tr> + </thead> + <tbody> + <tr class="{cycle values="odd,even" reset=true}"> + <td> + <label> + <input type="checkbox" name="flexible-height"> + <span>{locale group="quiqqer/bricks" var="brick.edit.height"}</span> + </label> + </td> + </tr> + <tr class="{cycle values="odd,even"}"> + <td> + <label> + <input type="checkbox" name="flexible-width"> + <span>{locale group="quiqqer/bricks" var="brick.edit.width"}</span> + </label> + </td> + </tr> + </tbody> + </table> + </form> \ No newline at end of file diff --git a/ajax/getBrick.php b/ajax/getBrick.php index a3c123e..b79b523 100644 --- a/ajax/getBrick.php +++ b/ajax/getBrick.php @@ -19,6 +19,7 @@ function package_quiqqer_bricks_ajax_getBrick($brickId) return array( 'attributes' => $Brick->getAttributes(), 'settings' => $Brick->getSettings(), + 'customfields' => $Brick->getCustomFields(), 'availableSettings' => $BrickManager->getAvailableBrickSettingsByBrickType( $Brick->getAttribute('type') ) diff --git a/bin/BrickEdit.css b/bin/BrickEdit.css index ae9582e..8ff07a3 100644 --- a/bin/BrickEdit.css +++ b/bin/BrickEdit.css @@ -38,4 +38,9 @@ .brick-edit-extra-header tbody tr td:first-child, .quiqqer-bricks-brickedit .data-table tbody tr td:first-child { width: 200px; +} + +.brick-table-flexible label { + margin-bottom: 0; + width: 100% !important; } \ No newline at end of file diff --git a/bin/BrickEdit.js b/bin/BrickEdit.js index 8f9ec99..992405b 100644 --- a/bin/BrickEdit.js +++ b/bin/BrickEdit.js @@ -68,6 +68,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ this.$availableBricks = []; this.$availableSettings = []; + this.$customfields = []; this.$Editor = false; this.$Areas = false; @@ -120,15 +121,6 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ } }); - this.addCategory({ - name : 'content', - icon : 'icon-file-text-alt', - text : QUILocale.get('quiqqer/system', 'content'), - events : { - onActive : this.$load - } - }); - this.addCategory({ name : 'settings', icon : 'icon-magic', @@ -146,6 +138,15 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ onActive : this.$load } }); + + this.addCategory({ + name : 'content', + icon : 'icon-file-text-alt', + text : QUILocale.get('quiqqer/system', 'content'), + events : { + onActive : this.$load + } + }); }, /** @@ -167,6 +168,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ */ this.$availableBricks = bricks; this.$availableSettings = brick.availableSettings; + this.$customfields = brick.customfields; this.setAttribute('data', brick); @@ -219,6 +221,10 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ return new Promise(function(resolve, reject) { + var data = this.getAttribute('data').attributes; + + data.customfields = this.$customfields; + QUIAjax.post('package_quiqqer_bricks_ajax_brick_save', function () { if (typeof callback === 'function') { @@ -233,7 +239,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ }.bind(this), { 'package': 'quiqqer/brick', brickId : this.getAttribute('id'), - data : JSON.encode(this.getAttribute('data').attributes), + data : JSON.encode(data), onError : reject }); @@ -360,7 +366,6 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ data = this.getAttribute('data'); if (unload == 'information') { - data.attributes = Object.merge( data.attributes, QUIFormUtils.getFormData(Form) @@ -372,12 +377,35 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ data.attributes.width = Form.elements.width.value; data.attributes.height = Form.elements.height.value; + var flexibleList = [], + fieldData = QUIFormUtils.getFormData(Form); + + for (var key in fieldData) { + + if (!fieldData.hasOwnProperty(key)) { + continue; + } + + if (!key.match('flexible')) { + continue; + } + + if (fieldData[key]) { + flexibleList.push(key); + } + } + + this.$customfields = flexibleList; + this.$Areas.destroy(); this.$Areas = false; } if (unload == 'extra') { - data.settings = QUIFormUtils.getFormData(Form); + data.settings = Object.merge( + data.settings, + QUIFormUtils.getFormData(Form) + ); } if (unload == 'content') { @@ -436,7 +464,8 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ // areas var Content = this.getContent(), areas = [], - attributes = this.getAttribute('data').attributes; + attributes = this.getAttribute('data').attributes, + customfields = this.$customfields; if (attributes.areas) { @@ -465,6 +494,44 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ Content.getElement('[name="height"]').value = attributes.height; } + // flexble settings + var i, len, data; + var TBody = Content.getElement('.brick-table-flexible tbody'); + + for (i = 0, len = this.$availableSettings.length; i < len; i++) { + + data = this.$availableSettings[i]; + + new Element('tr', { + 'class' : i % 2 ? 'even' : 'odd', + html : '<td>' + + '<label>'+ + '<input type="checkbox" name="flexible-'+ data.name +'" />'+ + '<span>'+ QUILocale.get(data.text[0], data.text[1]) +'</span>'+ + '</label>'+ + '</td>' + }).inject(TBody); + } + + if (customfields) { + + var name; + var Form = Content.getElement('form'); + + 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['flexible-'+name] !== 'undefined') { + Form.elements['flexible-'+name].checked = true; + } + } + } + resolve(); }.bind(this), { diff --git a/database.xml b/database.xml index 29ec143..a706dc6 100644 --- a/database.xml +++ b/database.xml @@ -9,6 +9,7 @@ <field type="VARCHAR( 255 ) NOT NULL">title</field> <field type="TEXT NOT NULL">description</field> <field type="TEXT">settings</field> + <field type="TEXT">customfields</field> <field type="VARCHAR( 255 )">type</field> <field type="TEXT">content</field> <field type="TEXT">areas</field> diff --git a/lib/QUI/Bricks/Brick.php b/lib/QUI/Bricks/Brick.php index e6c7a41..6102a47 100644 --- a/lib/QUI/Bricks/Brick.php +++ b/lib/QUI/Bricks/Brick.php @@ -31,6 +31,13 @@ class Brick extends QUI\QDOM */ protected $_settings = array(); + /** + * Fields can be overwritten by another user + * + * @var array + */ + protected $_customfields = array(); + /** * Constructor * @@ -93,14 +100,25 @@ public function __construct($params = array()) $settings = json_decode($settings, true); } - if (!is_array($settings)) { - return; + if (is_array($settings)) { + foreach ($this->_settings as $key => $value) { + if (isset($settings[$key])) { + $this->_settings[$key] = $settings[$key]; + } + } } + } - foreach ($this->_settings as $key => $value) { - if (isset($settings[$key])) { - $this->_settings[$key] = $settings[$key]; - } + // customfields + if (isset($params['customfields'])) { + $customfields = $params['customfields']; + + if (is_string($customfields)) { + $customfields = json_decode($customfields, true); + } + + if (is_array($customfields)) { + $this->_customfields = $customfields; } } } @@ -235,4 +253,14 @@ public function setSetting($name, $value) $this->_settings[$name] = $value; } } + + /** + * This fields can be overwritten by another user + * + * @return array + */ + public function getCustomFields() + { + return $this->_customfields; + } } diff --git a/lib/QUI/Bricks/Manager.php b/lib/QUI/Bricks/Manager.php index 4748e36..bdeb4b0 100644 --- a/lib/QUI/Bricks/Manager.php +++ b/lib/QUI/Bricks/Manager.php @@ -407,7 +407,6 @@ public function saveBrick($brickId, array $brickData) return ''; }, $this->getAreasByProject($Project)); - if (isset($brickData['areas'])) { $parts = explode(',', $brickData['areas']); @@ -422,22 +421,44 @@ public function saveBrick($brickId, array $brickData) $areaString = ','.implode(',', $areas).','; } - $Brick->setAttributes($brickData); + + // brick settings if (isset($brickData['settings'])) { $Brick->setSettings($brickData['settings']); } + + // custom fields + $customfields = array(); + + if (isset($brickData['customfields'])) { + $availableSettings = $Brick->getSettings(); + $availableSettings['width'] = true; + $availableSettings['height'] = true; + + foreach ($brickData['customfields'] as $customfield) { + $customfield = str_replace('flexible-', '', $customfield); + + if (isset($availableSettings[$customfield])) { + $customfields[] = $customfield; + } + } + } + + + // update QUI::getDataBase()->update($this->_getTable(), array( - 'title' => $Brick->getAttribute('title'), - 'description' => $Brick->getAttribute('description'), - 'content' => $Brick->getAttribute('content'), - 'type' => $Brick->getAttribute('type'), - 'settings' => json_encode($Brick->getSettings()), - 'areas' => $areaString, - 'height' => $Brick->getAttribute('height'), - 'width' => $Brick->getAttribute('width') + 'title' => $Brick->getAttribute('title'), + 'description' => $Brick->getAttribute('description'), + 'content' => $Brick->getAttribute('content'), + 'type' => $Brick->getAttribute('type'), + 'settings' => json_encode($Brick->getSettings()), + 'customfields' => json_encode($customfields), + 'areas' => $areaString, + 'height' => $Brick->getAttribute('height'), + 'width' => $Brick->getAttribute('width') ), array( 'id' => (int)$brickId )); diff --git a/locale.xml b/locale.xml index 6072e57..06112f3 100644 --- a/locale.xml +++ b/locale.xml @@ -180,6 +180,15 @@ <de><![CDATA[Baustein Breite]]></de> <en><![CDATA[Brick width]]></en> </locale> + <locale name="brick.edit.settings.flexible.header"> + <de><![CDATA[Flexible Einstellungen]]></de> + <en><![CDATA[Flexible settings]]></en> + </locale> + <locale name="brick.edit.settings.flexible.header.description"> + <de><![CDATA[Bestimmen Sie welche Einstellung flexibel von anderen Benutzern verändert werden können.]]></de> + <en><![CDATA[Determine which setting can be flexibly changed by others.]]></en> + </locale> + </groups> <groups name="quiqqer/bricks" datatype="js"> <locale name="brick.type"> -- GitLab