Newer
Older
/**
* Area manager for the site object
*
* @author www.pcsg.de (Henning Leutz)
*
* @event onLoaded
*/
'qui/QUI',
'qui/controls/Control',
'qui/controls/loader/Loader',
'Ajax',
'Locale',
], function (QUI, QUIControl, QUILoader, QUIAjax, QUILocale, Area)
{
"use strict";
return new Class({
Extends : QUIControl,
Binds : [
'$onInject',
'$onDestroy'
],
this.Loader = new QUILoader();
this.areas = [];
this.addEvents({
onInject : this.$onInject,
onDestroy : this.$onDestroy
});
},
/**
* Return the domnode element
* @return {HTMLElement}
*/
create: function ()
{
this.$Elm = new Element('div', {
});
this.Loader.inject( this.$Elm );
return this.$Elm;
},
/**
* event : on inject
*/
$onInject : function()
{
var self = this;
this.Loader.show();
if ( !bricks.length )
{
self.$Elm.set(
'html',
QUILocale.get( 'quiqqer/bricks', 'bricks.message.no.areas.found' )
);
return;
}
var i, len, data, AC;
if ( areas ) {
if ( typeof areas[ AC.getAttribute('name') ] === 'undefined' ) {
continue;
}
data = areas[ AC.getAttribute('name') ];
data.each(function(brickData) {
AC.addBrick( brickData );
});
}
self.Loader.hide();
self.fireEvent( 'loaded' );
});
},
/**
* event : on destroy
*/
$onDestroy : function()
{
this.updateSite();
},
/**
* Update the internal site object
*/
updateSite : function()
{
var i, len, AC;
areas = {};
for ( i = 0, len = this.areas.length; i < len; i++ )
{
AC = this.areas[ i ];
areas[ AC.getAttribute( 'name' ) ] = AC.getData();
}
Site.setAttribute( 'quiqqer.bricks.areas', JSON.encode( areas ) );
},
/**
* @param {Function} callback - callback function
*/
Project = Site.getProject();
QUIAjax.get('package_quiqqer_bricks_ajax_project_getAreas', callback, {
'package' : 'quiqqer/bricks',
project : Project.encode(),
});
},
/**
*
* @param {Object} area - Data of the area
* @return Area
*/
Project = Site.getProject(),
Control = new Area();
Control.setAttribute( 'Project', Project );
Control.setAttribute( 'Site', Site );
Control.setAttributes( area );
Control.inject( this.$Elm );
this.areas.push( Control );
return Control;
}
});