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)
return array(
'attributes' => $Brick->getAttributes(),
'settings' => $BrickManager->getAvailableBrickSettingsByBrickType(
'settings' => $Brick->getSettings(),
'availableSettings' => $BrickManager->getAvailableBrickSettingsByBrickType(
$Brick->getAttribute( 'type' )
)
);
......
......@@ -5,12 +5,13 @@
*/
/**
* Returns the feed list
* Returns the bricks of the project area
*
* @param string $project - json array, Project Data
* @param string|bool $area - (optional), Area name
* @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 );
$BrickManager = new QUI\Bricks\Manager();
......@@ -18,8 +19,20 @@ function package_quiqqer_bricks_ajax_project_getBricks($project)
$bricks = $BrickManager->getBricksFromProject( $Project );
$result = array();
foreach ( $bricks as $Brick ) {
$result[] = $Brick->getAttributes();
foreach ( $bricks as $Brick )
{
/* @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;
......@@ -27,6 +40,6 @@ function package_quiqqer_bricks_ajax_project_getBricks($project)
QUI::$Ajax->register(
'package_quiqqer_bricks_ajax_project_getBricks',
array( 'project' ),
array( 'project', 'area' ),
'Permission::checkAdminUser'
);
......@@ -13,13 +13,15 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
'qui/QUI',
'qui/controls/Control',
'qui/utils/Form',
'package/quiqqer/bricks/bin/BrickAreas',
'Ajax',
'Locale',
'utils/Controls',
'css!package/quiqqer/bricks/bin/BrickEdit.css'
], function(QUI, QUIControl, BrickAreas, Ajax, QUILocale)
], function(QUI, QUIControl, QUIFormUtils, BrickAreas, Ajax, QUILocale, ControlUtils)
{
"use strict";
......@@ -81,10 +83,17 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
'package_quiqqer_bricks_ajax_getAvailableBricks'
], function(data, bricks)
{
/**
* @param {{availableSettings:object}} data
* @param {{attributes:object}} data
* @param {{settings:object}} data
*/
self.$availableBricks = bricks;
self.$availableSettings = data.settings;
self.$availableSettings = data.availableSettings;
self.setAttributes( data.attributes );
self.setAttribute( 'settings', data.settings );
self.$createData(function() {
self.fireEvent( 'loaded', [ self ] );
});
......@@ -134,21 +143,68 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
'</label>'
}).inject( this.$Elm );
var i, len, title, group, val;
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"]'),
......@@ -190,7 +246,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
// areas
this.$Areas = new BrickAreas({
brickId : this.getAttribute( 'id' ),
brickId : this.getAttribute( 'id' ),
projectName : this.getAttribute( 'projectName' ),
projectLang : this.getAttribute( 'projectLang' ),
areas : areas,
......@@ -254,7 +310,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
*/
save : function(callback)
{
var Type = this.$Elm.getElement( '[name="type"]'),
var Type = this.$Elm.getElement( '[name="type"]' ),
Title = this.$Elm.getElement( '[name="title"]' );
var data = {
......@@ -268,6 +324,16 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
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()
{
if ( typeof callback === 'function' ) {
......
......@@ -306,7 +306,7 @@ define('package/quiqqer/bricks/bin/Manager', [
},
/**
*
* Opens the brick creation dialog
*/
$openCreateDialog : function()
{
......@@ -482,9 +482,10 @@ define('package/quiqqer/bricks/bin/Manager', [
require(['package/quiqqer/bricks/bin/BrickEdit'], function(BrickEdit)
{
Brick = new BrickEdit({
id : brickId,
project : self.$ProjectSelect.getValue(),
events :
id : brickId,
projectName : self.$ProjectSelect.getValue(),
projectLang : self.$ProjectLangs.getValue(),
events :
{
onLoaded : function() {
self.Loader.hide();
......
......@@ -105,7 +105,8 @@ define('package/quiqqer/bricks/bin/Site/Area', [
}, {
'package' : 'quiqqer/bricks',
project : Project.encode()
project : Project.encode(),
area : this.getAttribute( 'name' )
});
},
......
......@@ -35,7 +35,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [
initialize: function (options)
{
this.parent(options);
this.parent( options );
this.Loader = new QUILoader();
this.areas = [];
......@@ -75,11 +75,11 @@ define('package/quiqqer/bricks/bin/Site/Category', [
{
var i, len, data, AC;
var Site = self.getAttribute( 'Site'),
var Site = self.getAttribute( 'Site' ),
areas = Site.getAttribute( 'quiqqer.bricks.areas' );
if ( areas ) {
areas = JSON.decode(areas);
areas = JSON.decode( areas );
}
for ( i = 0, len = bricks.length; i < len; i++ )
......@@ -109,7 +109,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [
{
var i, len, AC;
var Site = this.getAttribute( 'Site'),
var Site = this.getAttribute( 'Site' ),
areas = {};
for ( i = 0, len = this.areas.length; i < len; i++ )
......@@ -128,7 +128,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [
*/
getBrickAreas : function(callback)
{
var Site = this.getAttribute( 'Site'),
var Site = this.getAttribute( 'Site' ),
Project = Site.getProject();
QUIAjax.get('package_quiqqer_bricks_ajax_project_getAreas', callback, {
......@@ -146,7 +146,7 @@ define('package/quiqqer/bricks/bin/Site/Category', [
*/
$insertBrickAreaEdit : function(area)
{
var Site = this.getAttribute( 'Site'),
var Site = this.getAttribute( 'Site' ),
Project = Site.getProject(),
Control = new Area();
......@@ -161,5 +161,4 @@ define('package/quiqqer/bricks/bin/Site/Category', [
return Control;
}
});
});
\ No newline at end of file
});
......@@ -41,6 +41,40 @@ public function __construct($params=array())
$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'] ) )
{
$settings = $params['settings'];
......@@ -49,13 +83,15 @@ public function __construct($params=array())
$settings = json_decode( $settings, true );
}
$this->_settings = $settings;
}
if ( !is_array( $settings ) ) {
return;
}
foreach ( $default as $key => $value )
{
if ( isset( $params[ $key ] ) ) {
$this->setAttribute( $key, $params[ $key ] );
foreach ( $this->_settings as $key => $value )
{
if ( isset( $settings[ $key ] ) ) {
$this->_settings[ $key ] = $settings[ $key ];
}
}
}
}
......@@ -71,31 +107,86 @@ public function create()
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' );
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 */
$Control = new $Ctrl();
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->create();
return $Control;
}
/**
* Return the brick settings
* @return array
*
* @return Array
*/
public function getSettings()
{
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)
foreach ( $Settings as $Setting )
{
/* @var $Setting \DOMElement */
$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)
$Brick->setAttributes( $brickData );
if ( isset( $brickData['settings'] ) ) {
$Brick->setSettings( $brickData['settings'] );
}
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->getAttribute( 'settings' ) ),
'settings' => json_encode( $Brick->getSettings() ),
'areas' => $areaString
), array(
'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