Skip to content
Code-Schnipsel Gruppen Projekte
Commit e4393e38 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

brick settings

Übergeordneter 0a47b872
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
...@@ -17,7 +17,8 @@ function package_quiqqer_bricks_ajax_getBrick($brickId) ...@@ -17,7 +17,8 @@ function package_quiqqer_bricks_ajax_getBrick($brickId)
return array( return array(
'attributes' => $Brick->getAttributes(), 'attributes' => $Brick->getAttributes(),
'settings' => $BrickManager->getAvailableBrickSettingsByBrickType( 'settings' => $Brick->getSettings(),
'availableSettings' => $BrickManager->getAvailableBrickSettingsByBrickType(
$Brick->getAttribute( 'type' ) $Brick->getAttribute( 'type' )
) )
); );
......
...@@ -5,12 +5,13 @@ ...@@ -5,12 +5,13 @@
*/ */
/** /**
* Returns the feed list * Returns the bricks of the project area
* *
* @param string $project - json array, Project Data * @param string $project - json array, Project Data
* @param string|bool $area - (optional), Area name
* @return array * @return array
*/ */
function package_quiqqer_bricks_ajax_project_getBricks($project) function package_quiqqer_bricks_ajax_project_getBricks($project, $area=false)
{ {
$Project = QUI::getProjectManager()->decode( $project ); $Project = QUI::getProjectManager()->decode( $project );
$BrickManager = new QUI\Bricks\Manager(); $BrickManager = new QUI\Bricks\Manager();
...@@ -18,8 +19,20 @@ function package_quiqqer_bricks_ajax_project_getBricks($project) ...@@ -18,8 +19,20 @@ function package_quiqqer_bricks_ajax_project_getBricks($project)
$bricks = $BrickManager->getBricksFromProject( $Project ); $bricks = $BrickManager->getBricksFromProject( $Project );
$result = array(); $result = array();
foreach ( $bricks as $Brick ) { foreach ( $bricks as $Brick )
$result[] = $Brick->getAttributes(); {
/* @var $Brick QUI\Bricks\Brick */
if ( !$area )
{
$result[] = $Brick->getAttributes();
continue;
}
$areas = $Brick->getAttribute('areas');
if ( strpos( $areas, ','.$area.',' ) !== false ) {
$result[] = $Brick->getAttributes();
}
} }
return $result; return $result;
...@@ -27,6 +40,6 @@ function package_quiqqer_bricks_ajax_project_getBricks($project) ...@@ -27,6 +40,6 @@ function package_quiqqer_bricks_ajax_project_getBricks($project)
QUI::$Ajax->register( QUI::$Ajax->register(
'package_quiqqer_bricks_ajax_project_getBricks', 'package_quiqqer_bricks_ajax_project_getBricks',
array( 'project' ), array( 'project', 'area' ),
'Permission::checkAdminUser' 'Permission::checkAdminUser'
); );
...@@ -13,13 +13,15 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ ...@@ -13,13 +13,15 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
'qui/QUI', 'qui/QUI',
'qui/controls/Control', 'qui/controls/Control',
'qui/utils/Form',
'package/quiqqer/bricks/bin/BrickAreas', 'package/quiqqer/bricks/bin/BrickAreas',
'Ajax', 'Ajax',
'Locale', 'Locale',
'utils/Controls',
'css!package/quiqqer/bricks/bin/BrickEdit.css' 'css!package/quiqqer/bricks/bin/BrickEdit.css'
], function(QUI, QUIControl, BrickAreas, Ajax, QUILocale) ], function(QUI, QUIControl, QUIFormUtils, BrickAreas, Ajax, QUILocale, ControlUtils)
{ {
"use strict"; "use strict";
...@@ -81,10 +83,17 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ ...@@ -81,10 +83,17 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
'package_quiqqer_bricks_ajax_getAvailableBricks' 'package_quiqqer_bricks_ajax_getAvailableBricks'
], function(data, bricks) ], function(data, bricks)
{ {
/**
* @param {{availableSettings:object}} data
* @param {{attributes:object}} data
* @param {{settings:object}} data
*/
self.$availableBricks = bricks; self.$availableBricks = bricks;
self.$availableSettings = data.settings; self.$availableSettings = data.availableSettings;
self.setAttributes( data.attributes ); self.setAttributes( data.attributes );
self.setAttribute( 'settings', data.settings );
self.$createData(function() { self.$createData(function() {
self.fireEvent( 'loaded', [ self ] ); self.fireEvent( 'loaded', [ self ] );
}); });
...@@ -134,21 +143,68 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ ...@@ -134,21 +143,68 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
'</label>' '</label>'
}).inject( this.$Elm ); }).inject( this.$Elm );
var i, len, title, group, val; var i, len, title, group, val;
if ( this.$availableSettings ) if ( this.$availableSettings )
{ {
console.log( this.$availableSettings ); var setting, dataQui;
var SettingsElement = new Element('form', {
'class' : 'quiqqer-bricks-brickedit-settings'
});
for ( i = 0, len = this.$availableSettings.length; i < len; i++ )
{
setting = this.$availableSettings[ i ];
dataQui = '';
if ( setting['data-qui'] !== '' ) {
dataQui = ' data-qui="'+ setting['data-qui'] +'" ';
}
new Element('div', {
html : '<label class="quiqqer-bricks-areas">' +
' <span class="quiqqer-bricks-brickedit-label-text">' +
setting.text +
' </span>' +
'</label>' +
'<input type="'+ setting.type +'" ' +
' name="'+ setting.name +'" ' +
' class="'+ setting.class +'" ' +
dataQui +
'/>'
}).inject( SettingsElement );
}
SettingsElement.inject( Container );
var Setting; // set data
QUIFormUtils.setDataToForm(
this.getAttribute( 'settings' ),
SettingsElement
);
for ( i = 0, len = this.$availableSettings.length; i < len; i++ ) // parse controls
ControlUtils.parse( SettingsElement );
QUI.parse(SettingsElement, function()
{ {
Setting = this.$availableSettings[ i ]; // set project to the controls
SettingsElement.getElements( '[data-quiid]' ).each(function(Elm)
{
var Control = QUI.Controls.getById(
Elm.get('data-quiid')
);
console.log( Setting ); if ( 'setProject' in Control )
} {
Control.setProject(
self.getAttribute( 'projectName' ),
self.getAttribute( 'projectLang' )
);
}
});
});
} }
var Type = this.$Elm.getElement( '[name="type"]'), var Type = this.$Elm.getElement( '[name="type"]'),
...@@ -190,7 +246,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ ...@@ -190,7 +246,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
// areas // areas
this.$Areas = new BrickAreas({ this.$Areas = new BrickAreas({
brickId : this.getAttribute( 'id' ), brickId : this.getAttribute( 'id' ),
projectName : this.getAttribute( 'projectName' ), projectName : this.getAttribute( 'projectName' ),
projectLang : this.getAttribute( 'projectLang' ), projectLang : this.getAttribute( 'projectLang' ),
areas : areas, areas : areas,
...@@ -254,7 +310,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ ...@@ -254,7 +310,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
*/ */
save : function(callback) save : function(callback)
{ {
var Type = this.$Elm.getElement( '[name="type"]'), var Type = this.$Elm.getElement( '[name="type"]' ),
Title = this.$Elm.getElement( '[name="title"]' ); Title = this.$Elm.getElement( '[name="title"]' );
var data = { var data = {
...@@ -268,6 +324,16 @@ define('package/quiqqer/bricks/bin/BrickEdit', [ ...@@ -268,6 +324,16 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
data.content = this.$Editor.getContent(); data.content = this.$Editor.getContent();
} }
// settings
var SettingsForm = this.$Elm.getElement(
'.quiqqer-bricks-brickedit-settings'
);
if ( SettingsForm ) {
data.settings = QUIFormUtils.getFormData( SettingsForm );
}
Ajax.post('package_quiqqer_bricks_ajax_brick_save', function() Ajax.post('package_quiqqer_bricks_ajax_brick_save', function()
{ {
if ( typeof callback === 'function' ) { if ( typeof callback === 'function' ) {
......
...@@ -306,7 +306,7 @@ define('package/quiqqer/bricks/bin/Manager', [ ...@@ -306,7 +306,7 @@ define('package/quiqqer/bricks/bin/Manager', [
}, },
/** /**
* * Opens the brick creation dialog
*/ */
$openCreateDialog : function() $openCreateDialog : function()
{ {
...@@ -482,9 +482,10 @@ define('package/quiqqer/bricks/bin/Manager', [ ...@@ -482,9 +482,10 @@ define('package/quiqqer/bricks/bin/Manager', [
require(['package/quiqqer/bricks/bin/BrickEdit'], function(BrickEdit) require(['package/quiqqer/bricks/bin/BrickEdit'], function(BrickEdit)
{ {
Brick = new BrickEdit({ Brick = new BrickEdit({
id : brickId, id : brickId,
project : self.$ProjectSelect.getValue(), projectName : self.$ProjectSelect.getValue(),
events : projectLang : self.$ProjectLangs.getValue(),
events :
{ {
onLoaded : function() { onLoaded : function() {
self.Loader.hide(); self.Loader.hide();
......
...@@ -105,7 +105,8 @@ define('package/quiqqer/bricks/bin/Site/Area', [ ...@@ -105,7 +105,8 @@ define('package/quiqqer/bricks/bin/Site/Area', [
}, { }, {
'package' : 'quiqqer/bricks', 'package' : 'quiqqer/bricks',
project : Project.encode() project : Project.encode(),
area : this.getAttribute( 'name' )
}); });
}, },
......
...@@ -35,7 +35,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [ ...@@ -35,7 +35,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [
initialize: function (options) initialize: function (options)
{ {
this.parent(options); this.parent( options );
this.Loader = new QUILoader(); this.Loader = new QUILoader();
this.areas = []; this.areas = [];
...@@ -75,11 +75,11 @@ define('package/quiqqer/bricks/bin/Site/Category', [ ...@@ -75,11 +75,11 @@ define('package/quiqqer/bricks/bin/Site/Category', [
{ {
var i, len, data, AC; var i, len, data, AC;
var Site = self.getAttribute( 'Site'), var Site = self.getAttribute( 'Site' ),
areas = Site.getAttribute( 'quiqqer.bricks.areas' ); areas = Site.getAttribute( 'quiqqer.bricks.areas' );
if ( areas ) { if ( areas ) {
areas = JSON.decode(areas); areas = JSON.decode( areas );
} }
for ( i = 0, len = bricks.length; i < len; i++ ) for ( i = 0, len = bricks.length; i < len; i++ )
...@@ -109,7 +109,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [ ...@@ -109,7 +109,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [
{ {
var i, len, AC; var i, len, AC;
var Site = this.getAttribute( 'Site'), var Site = this.getAttribute( 'Site' ),
areas = {}; areas = {};
for ( i = 0, len = this.areas.length; i < len; i++ ) for ( i = 0, len = this.areas.length; i < len; i++ )
...@@ -128,7 +128,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [ ...@@ -128,7 +128,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [
*/ */
getBrickAreas : function(callback) getBrickAreas : function(callback)
{ {
var Site = this.getAttribute( 'Site'), var Site = this.getAttribute( 'Site' ),
Project = Site.getProject(); Project = Site.getProject();
QUIAjax.get('package_quiqqer_bricks_ajax_project_getAreas', callback, { QUIAjax.get('package_quiqqer_bricks_ajax_project_getAreas', callback, {
...@@ -146,7 +146,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [ ...@@ -146,7 +146,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [
*/ */
$insertBrickAreaEdit : function(area) $insertBrickAreaEdit : function(area)
{ {
var Site = this.getAttribute( 'Site'), var Site = this.getAttribute( 'Site' ),
Project = Site.getProject(), Project = Site.getProject(),
Control = new Area(); Control = new Area();
...@@ -161,5 +161,4 @@ define('package/quiqqer/bricks/bin/Site/Category', [ ...@@ -161,5 +161,4 @@ define('package/quiqqer/bricks/bin/Site/Category', [
return Control; return Control;
} }
}); });
});
});
\ No newline at end of file
...@@ -41,6 +41,40 @@ public function __construct($params=array()) ...@@ -41,6 +41,40 @@ public function __construct($params=array())
$this->setAttributes( $default ); $this->setAttributes( $default );
foreach ( $default as $key => $value )
{
if ( isset( $params[ $key ] ) ) {
$this->setAttribute( $key, $params[ $key ] );
}
}
// default settings from control
$Control = $this->_getControl();
$Manager = new Manager();
$availableSettings = $Manager->getAvailableBrickSettingsByBrickType(
$this->getAttribute( 'type' )
);
foreach ( $availableSettings as $entry ) {
$this->_settings[ $entry['name'] ] = false;
}
// control default settings
if ( $Control )
{
$controlSettings = $Control->getAttributes();
foreach ( $this->_settings as $key => $value )
{
if ( isset( $controlSettings[ $key ] ) ) {
$this->_settings[ $key ] = $controlSettings[ $key ];
}
}
}
// settings from database
if ( isset( $params['settings'] ) ) if ( isset( $params['settings'] ) )
{ {
$settings = $params['settings']; $settings = $params['settings'];
...@@ -49,13 +83,15 @@ public function __construct($params=array()) ...@@ -49,13 +83,15 @@ public function __construct($params=array())
$settings = json_decode( $settings, true ); $settings = json_decode( $settings, true );
} }
$this->_settings = $settings; if ( !is_array( $settings ) ) {
} return;
}
foreach ( $default as $key => $value ) foreach ( $this->_settings as $key => $value )
{ {
if ( isset( $params[ $key ] ) ) { if ( isset( $settings[ $key ] ) ) {
$this->setAttribute( $key, $params[ $key ] ); $this->_settings[ $key ] = $settings[ $key ];
}
} }
} }
} }
...@@ -71,31 +107,86 @@ public function create() ...@@ -71,31 +107,86 @@ public function create()
return $this->getAttribute( 'content' ); return $this->getAttribute( 'content' );
} }
$Control = $this->_getControl();
if ( !$Control ) {
throw new QUI\Exception( 'Control not found. Brick could not be create' );
}
$Control->setAttributes( $this->getSettings() );
return $Control->create();
}
/**
* Return the internal control
* @return QUI\Control|Bool
*/
protected function _getControl()
{
$Ctrl = $this->getAttribute( 'type' ); $Ctrl = $this->getAttribute( 'type' );
if ( !is_callable( $Ctrl ) && !class_exists( $Ctrl ) ) { if ( !is_callable( $Ctrl ) && !class_exists( $Ctrl ) ) {
throw new QUI\Exception( 'Control not found. Brick could not be create' ); return false;
} }
/* @var $Control \QUI\Control */ /* @var $Control \QUI\Control */
$Control = new $Ctrl(); $Control = new $Ctrl();
if ( !($Control instanceof QUI\Control) ) { if ( !($Control instanceof QUI\Control) ) {
throw new QUI\Exception( 'Control not found. Brick could not be create' ); return false;
} }
$Control->setAttributes( $this->getSettings() ); return $Control;
return $Control->create();
} }
/** /**
* Return the brick settings * Return the brick settings
* @return array *
* @return Array
*/ */
public function getSettings() public function getSettings()
{ {
return $this->_settings; return $this->_settings;
} }
}
\ No newline at end of file /**
* Set brick settings
*
* @param Array $settings
*/
public function setSettings($settings)
{
foreach ( $settings as $key => $value ) {
$this->setSetting( $key, $value );
}
}
/**
* Return the setting of the brick
*
* @param String $name - Name of the setting
* @return Bool|String
*/
public function getSetting($name)
{
if ( isset( $this->_settings[ $name ] ) ) {
return $this->_settings[ $name ];
}
return false;
}
/**
* Set a brick setting
*
* @param String $name - name of the setting
* @param String $value - value of the setting
*/
public function setSetting($name, $value)
{
if ( isset( $this->_settings[ $name ] ) ) {
$this->_settings[ $name ] = $value;
}
}
}
...@@ -233,8 +233,13 @@ public function getAvailableBrickSettingsByBrickType($brickType) ...@@ -233,8 +233,13 @@ public function getAvailableBrickSettingsByBrickType($brickType)
foreach ( $Settings as $Setting ) foreach ( $Settings as $Setting )
{ {
/* @var $Setting \DOMElement */
$settings[] = array( $settings[] = array(
'name' => $Setting->getAttribute( 'name' ) 'name' => $Setting->getAttribute( 'name' ),
'text' => QUI\Utils\DOM::getTextFromNode( $Setting ),
'type' => $Setting->getAttribute( 'type' ),
'class' => $Setting->getAttribute( 'class' ),
'data-qui' => $Setting->getAttribute( 'data-qui' )
); );
} }
...@@ -364,12 +369,16 @@ public function saveBrick($brickId, array $brickData) ...@@ -364,12 +369,16 @@ public function saveBrick($brickId, array $brickData)
$Brick->setAttributes( $brickData ); $Brick->setAttributes( $brickData );
if ( isset( $brickData['settings'] ) ) {
$Brick->setSettings( $brickData['settings'] );
}
QUI::getDataBase()->update($this->_getTable(), array( QUI::getDataBase()->update($this->_getTable(), array(
'title' => $Brick->getAttribute( 'title' ), 'title' => $Brick->getAttribute( 'title' ),
'description' => $Brick->getAttribute( 'description' ), 'description' => $Brick->getAttribute( 'description' ),
'content' => $Brick->getAttribute( 'content' ), 'content' => $Brick->getAttribute( 'content' ),
'type' => $Brick->getAttribute( 'type' ), 'type' => $Brick->getAttribute( 'type' ),
'settings' => json_encode( $Brick->getAttribute( 'settings' ) ), 'settings' => json_encode( $Brick->getSettings() ),
'areas' => $areaString 'areas' => $areaString
), array( ), array(
'id' => (int)$brickId 'id' => (int)$brickId
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren