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

bricks -> project multilingual

Übergeordneter 03dd614d
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -15,7 +15,12 @@ function package_quiqqer_bricks_ajax_getBrick($brickId)
$BrickManager = new \QUI\Bricks\Manager();
$Brick = $BrickManager->getBrickById( $brickId );
return $Brick->getAttributes();
return array(
'attributes' => $Brick->getAttributes(),
'settings' => $BrickManager->getAvailableBrickSettingsByBrickType(
$Brick->getAttribute( 'type' )
)
);
}
\QUI::$Ajax->register(
......
......@@ -32,7 +32,8 @@ define('package/quiqqer/bricks/bin/AreaWindow', [
options : {
title : 'Projekt Brickbereiche',
project : false,
projectName : false,
projectLang : false,
maxHeight : 500,
maxWidth : 400
},
......@@ -86,7 +87,8 @@ define('package/quiqqer/bricks/bin/AreaWindow', [
Ajax.get('package_quiqqer_bricks_ajax_project_getAreas', callback, {
'package' : 'quiqqer/brick',
project : JSON.encode({
name : this.getAttribute( 'project' )
name : this.getAttribute( 'projectName' ),
lang : this.getAttribute( 'projectLang' )
})
});
},
......
......@@ -36,7 +36,8 @@ define('package/quiqqer/bricks/bin/BrickAreas', [
options : {
brickId : false, // brickId
styles : false,
project : false,
projectName : false,
projectLang : false,
areas : false
},
......@@ -79,7 +80,8 @@ define('package/quiqqer/bricks/bin/BrickAreas', [
onClick : function()
{
new AreaWindow({
project : self.getAttribute( 'project' ),
projectName : self.getAttribute( 'projectName' ),
projectLang : self.getAttribute( 'projectLang' ),
events :
{
onSubmit : function(Win, areas)
......
......@@ -34,15 +34,17 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
],
options : {
id : false,
project : false
id : false,
projectName : false,
projectLang : false
},
initialize : function(options)
{
this.parent( options );
this.$availableBricks = [];
this.$availableBricks = [];
this.$availableSettings = [];
this.$Editor = false;
this.$Areas = false;
......@@ -79,9 +81,10 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
'package_quiqqer_bricks_ajax_getAvailableBricks'
], function(data, bricks)
{
self.$availableBricks = bricks;
self.$availableBricks = bricks;
self.$availableSettings = data.settings;
self.setAttributes( data );
self.setAttributes( data.attributes );
self.$createData(function() {
self.fireEvent( 'loaded', [ self ] );
});
......@@ -111,7 +114,7 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
{
var self = this;
new Element('div', {
var Container = new Element('div', {
'html' : '<label>' +
' <span class="quiqqer-bricks-brickedit-label-text">' +
' Title' +
......@@ -133,6 +136,21 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
var i, len, title, group, val;
if ( this.$availableSettings )
{
console.log( this.$availableSettings );
var Setting;
for ( i = 0, len = this.$availableSettings.length; i < len; i++ )
{
Setting = this.$availableSettings[ i ];
console.log( Setting );
}
}
var Type = this.$Elm.getElement( '[name="type"]'),
Title = this.$Elm.getElement( '[name="title"]' );
......@@ -173,9 +191,10 @@ define('package/quiqqer/bricks/bin/BrickEdit', [
// areas
this.$Areas = new BrickAreas({
brickId : this.getAttribute( 'id' ),
project : this.getAttribute( 'project' ),
areas : areas,
styles : {
projectName : this.getAttribute( 'projectName' ),
projectLang : this.getAttribute( 'projectLang' ),
areas : areas,
styles : {
height : 120
}
}).inject( this.$Elm.getElement( '.quiqqer-bricks-areas' ), 'after' );
......
......@@ -35,6 +35,7 @@ define('package/quiqqer/bricks/bin/Manager', [
Binds : [
'loadBricksFromProject',
'refresh',
'$refreshProjectLanguages',
'$onCreate',
'$onResize',
'$openCreateDialog',
......@@ -51,7 +52,9 @@ define('package/quiqqer/bricks/bin/Manager', [
{
this.parent( options );
this.$Grid = false;
this.$Grid = false;
this.$ProjectSelect = false;
this.$ProjectLangs = false;
this.addEvents({
onCreate : this.$onCreate,
......@@ -70,11 +73,13 @@ define('package/quiqqer/bricks/bin/Manager', [
return;
}
var self = this;
var self = this,
project = this.$ProjectSelect.getValue(),
lang = this.$ProjectLangs.getValue();
this.Loader.show();
this.getBricksFromProject(this.$ProjectSelect.getValue(), function(result)
this.getBricksFromProject( project, lang, function(result)
{
if ( typeof callback === 'function' ) {
callback();
......@@ -85,7 +90,6 @@ define('package/quiqqer/bricks/bin/Manager', [
});
self.refreshButtons();
self.Loader.hide();
});
},
......@@ -123,13 +127,24 @@ define('package/quiqqer/bricks/bin/Manager', [
// Buttons
this.$ProjectSelect = new QUISelect({
name : 'projects',
name : 'projects-name',
events : {
onChange : this.$refreshProjectLanguages
}
});
this.$ProjectLangs = new QUISelect({
name : 'projects-langs',
events : {
onChange : this.refresh
},
styles : {
width : 80
}
});
this.addButton( this.$ProjectSelect );
this.addButton( this.$ProjectLangs );
this.addButton( new QUISeperator() );
this.addButton(
......@@ -251,6 +266,45 @@ define('package/quiqqer/bricks/bin/Manager', [
this.refreshButtons();
},
/**
* Refresh the project language dropdown
*/
$refreshProjectLanguages : function()
{
var self = this,
activeProject = this.$ProjectSelect.getValue();
Projects.getList(function(projects)
{
for ( var project in projects )
{
if ( !projects.hasOwnProperty( project ) ) {
continue;
}
if ( activeProject != project ) {
continue;
}
var langs = projects[ project ].langs;
langs = langs.split( ',' );
self.$ProjectLangs.clear();
for ( var i = 0, len = langs.length; i < len; i++ )
{
self.$ProjectLangs.appendChild(
langs[ i ], langs[ i ], 'icon-home'
);
}
self.$ProjectLangs.setValue(
self.$ProjectLangs.firstChild().getAttribute( 'value' )
);
}
});
},
/**
*
*/
......@@ -338,14 +392,16 @@ define('package/quiqqer/bricks/bin/Manager', [
return;
}
self.createBrick(self.$ProjectSelect.getValue(), {
var project = self.$ProjectSelect.getValue(),
lang = self.$ProjectLangs.getValue();
self.createBrick(project, lang, {
title : Title.value,
type : Type.value
}, function(brickId)
{
Win.close();
self.refresh(function() {
self.editBrick( brickId );
});
......@@ -484,14 +540,16 @@ define('package/quiqqer/bricks/bin/Manager', [
* 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
*/
getBricksFromProject : function(project, callback)
getBricksFromProject : function(project, lang, callback)
{
Ajax.get('package_quiqqer_bricks_ajax_project_getBricks', callback, {
'package' : 'quiqqer/bricks',
project : JSON.encode({
name : project
name : project,
lang : lang
})
});
},
......@@ -500,15 +558,17 @@ define('package/quiqqer/bricks/bin/Manager', [
* Create a new brick
*
* @param {String} project
* @param {String} lang
* @param {Object} data
* @param {Function} callback
*/
createBrick : function(project, data, callback)
createBrick : function(project, lang, data, callback)
{
Ajax.post('package_quiqqer_bricks_ajax_project_createBrick', callback, {
'package' : 'quiqqer/bricks',
project : JSON.encode({
name : project
name : project,
lang : lang
}),
data : JSON.encode( data )
});
......
......@@ -5,6 +5,7 @@
<table name="bricks">
<field type="INT( 3 ) NOT NULL AUTO_INCREMENT PRIMARY KEY">id</field>
<field type="VARCHAR( 255 )">project</field>
<field type="VARCHAR( 2 )">lang</field>
<field type="VARCHAR( 255 ) NOT NULL">title</field>
<field type="TEXT NOT NULL">description</field>
<field type="TEXT">settings</field>
......
......@@ -41,6 +41,7 @@ public function createBrickForProject(Project $Project, Brick $Brick)
$this->_getTable(),
array(
'project' => $Project->getName(),
'lang' => $Project->getLang(),
'title' => $Brick->getAttribute('title'),
'description' => $Brick->getAttribute('description'),
'type' => $Brick->getAttribute('type')
......@@ -52,6 +53,14 @@ public function createBrickForProject(Project $Project, Brick $Brick)
return $lastId;
}
/**
* CLears the bricks cache
*/
public function clearCache()
{
QUI\Cache\Manager::clear( 'quiqqer/bricks' );
}
/**
* Delete the brick
*
......@@ -133,8 +142,7 @@ public function getAvailableBricks()
}
$PKM = QUI::getPackageManager();
$packages = $PKM->getInstalled();
$xmlFiles = $this->_getBricksXMLFiles();
$result = array();
$result[] = array(
......@@ -143,14 +151,7 @@ public function getAvailableBricks()
'control' => 'content'
);
foreach ( $packages as $package )
{
$bricksXML = OPT_DIR . $package['name'] .'/bricks.xml';
if ( !file_exists( $bricksXML ) ) {
continue;
}
foreach ( $xmlFiles as $bricksXML ) {
$result = array_merge( $result, Utils::getBricksFromXML( $bricksXML ) );
}
......@@ -190,6 +191,61 @@ public function getBrickById($id)
return $this->_bricks[ $id ];
}
/**
* Return the available brick settings by the brick type
*
* @param $brickType
* @return array
*/
public function getAvailableBrickSettingsByBrickType($brickType)
{
if ( $brickType == 'content' ) {
return array();
}
$cache = 'quiqqer/bricks/brickType/'. md5($brickType);
try
{
return QUI\Cache\Manager::get( $cache );
} catch ( QUI\Exception $Exception )
{
}
$settings = array();
$xmlFiles = $this->_getBricksXMLFiles();
foreach ( $xmlFiles as $brickXML )
{
$Dom = QUI\Utils\XML::getDomFromXml( $brickXML );
$Path = new \DOMXPath( $Dom );
$Settings = $Path->query(
"//quiqqer/bricks/brick[@control='{$brickType}']/settings/setting"
);
if ( !$Settings->length ) {
continue;
}
foreach ( $Settings as $Setting )
{
$settings[] = array(
'name' => $Setting->getAttribute( 'name' )
);
}
break;
}
QUI\Cache\Manager::set( $cache, $settings );
return $settings;
}
/**
* Return the bricks from the area
*
......@@ -244,7 +300,8 @@ public function getBricksFromProject(Project $Project)
$list = QUI::getDataBase()->fetch(array(
'from' => $this->_getTable(),
'where' => array(
'project' => $Project->getName()
'project' => $Project->getName(),
'lang' => $Project->getLang()
)
));
......@@ -327,4 +384,41 @@ protected function _getTable()
{
return QUI::getDBTableName( self::TABLE );
}
/**
* List of available bricks.xml files
* @return array
*/
protected function _getBricksXMLFiles()
{
$cache = 'quiqqer/bricks/availableBrickFiles';
try
{
return QUI\Cache\Manager::get( $cache );
} catch ( QUI\Exception $Exception )
{
}
$PKM = QUI::getPackageManager();
$packages = $PKM->getInstalled();
$result = array();
foreach ( $packages as $package )
{
$bricksXML = OPT_DIR . $package['name'] .'/bricks.xml';
if ( !file_exists( $bricksXML ) ) {
continue;
}
$result[] = $bricksXML;
}
QUI\Cache\Manager::set( $cache, $result );
return $result;
}
}
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