Newer
Older
* @author www.pcsg.de (Henning Leutz)
*
* @event onLoaded [ this ]
*/
], function(QUI, QUIControl, QUIFormUtils, BrickAreas, Ajax, QUILocale, ControlUtils)
{
"use strict";
return new Class({
Extends : QUIControl,
Binds : [
'$onInject',
'$onDestroy'
],
options : {
id : false,
projectName : false,
projectLang : false
},
initialize : function(options)
{
this.parent( options );
this.$availableBricks = [];
this.$availableSettings = [];
this.$Editor = false;
this.$Areas = false;
this.addEvents({
onInject : this.$onInject,
onDestroy : this.$onDestroy
});
},
/**
* Return the HTML Node Element
*
* @return {HTMLElement}
*/
create : function()
{
this.$Elm = new Element('div', {
});
return this.$Elm;
},
/**
* event : on inject
*/
$onInject : function()
{
var self = this;
Ajax.get([
'package_quiqqer_bricks_ajax_getBrick',
'package_quiqqer_bricks_ajax_getAvailableBricks'
], function(data, bricks)
/**
* @param {{availableSettings:object}} data
* @param {{attributes:object}} data
* @param {{settings:object}} data
*/
self.$createData(function() {
self.fireEvent( 'loaded', [ self ] );
});
}, {
'package' : 'quiqqer/brick',
brickId : this.getAttribute( 'id' )
});
},
/**
* event : on destroy
*/
$onDestroy : function()
{
if ( this.$Editor ) {
this.$Editor.destroy();
}
},
/**
* Create the html for the control
*
* @param {Function} [callback]
*/
$createData : function(callback)
{
var self = this;
' <span class="quiqqer-bricks-brickedit-label-text">' +
' </span>' +
' <input type="text" name="title" />' +
'</label>' +
'<label>' +
' <span class="quiqqer-bricks-brickedit-label-text">' +
QUILocale.get( 'quiqqer/bricks', 'brick.edit.description' ) +
' </span>' +
' <textarea name="description"></textarea>' +
'</label>'+
'<label>' +
' <span class="quiqqer-bricks-brickedit-label-text">' +
QUILocale.get( 'quiqqer/bricks', 'brick.edit.type' ) +
' </span>' +
' <select name="type"></select>' +
'</label>'+
'<label class="quiqqer-bricks-areas">' +
' <span class="quiqqer-bricks-brickedit-label-text">' +
QUILocale.get( 'quiqqer/bricks', 'brick.edit.allowed.areas' ) +
var i, len, title, group, val;
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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 );
}
// set data
QUIFormUtils.setDataToForm(
this.getAttribute( 'settings' ),
SettingsElement
);
// parse controls
ControlUtils.parse( SettingsElement );
QUI.parse(SettingsElement, function()
// set project to the controls
SettingsElement.getElements( '[data-quiid]' ).each(function(Elm)
{
var Control = QUI.Controls.getById(
Elm.get('data-quiid')
);
if ( 'setProject' in Control )
{
Control.setProject(
self.getAttribute( 'projectName' ),
self.getAttribute( 'projectLang' )
);
}
});
});
var Type = this.$Elm.getElement( '[name="type"]' ),
Title = this.$Elm.getElement( '[name="title"]' ),
Desc = this.$Elm.getElement( '[name="description"]' );
for ( i = 0, len = this.$availableBricks.length; i < len; i++ )
if ( 'group' in title )
{
group = title.group;
val = title.var;
} else
{
group = title[ 0 ];
val = title[ 1 ];
}
html : QUILocale.get( group, val )
}).inject( Type );
}
Title.value = this.getAttribute( 'title' );
Type.value = this.getAttribute( 'type' );
var areas = [];
if ( this.getAttribute( 'areas' ) )
{
areas = this.getAttribute('areas')
.replace(/^,*/, '')
.replace(/,*$/, '')
.split(',');
}
projectName : this.getAttribute( 'projectName' ),
projectLang : this.getAttribute( 'projectLang' ),
areas : areas,
styles : {
}).inject( this.$Elm.getElement( '.quiqqer-bricks-areas' ), 'after' );
if ( this.getAttribute( 'type' ) == 'content' )
{
new Element('label', {
html : '<span class="quiqqer-bricks-brickedit-label-editor">' +
QUILocale.get( 'quiqqer/bricks', 'brick.edit.content' ) +
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
'</span>'
}).inject( this.$Elm );
// load ckeditor
require(['classes/editor/Manager'], function(EditorManager)
{
new EditorManager().getEditor(null, function(Editor)
{
self.$Editor = Editor;
var EditorContainer = new Element('div', {
styles : {
clear : 'both',
height : 300,
width : '100%'
}
}).inject( self.$Elm );
self.$Editor.addEvent('onLoaded', function()
{
if ( typeof callback === 'function' ) {
callback();
}
});
self.$Editor.inject( EditorContainer );
self.$Editor.setHeight( 300 );
self.$Editor.setContent( self.getAttribute( 'content' ) );
});
});
return;
}
if ( typeof callback === 'function' ) {
callback();
}
Title = this.$Elm.getElement( '[name="title"]'),
Desc = this.$Elm.getElement( '[name="description"]' );
title : Title.value,
description : Desc.value,
type : Type.value,
content : '',
areas : this.$Areas.getAreas().join(',')
};
if ( this.$Editor ) {
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' ) {
callback();
}
}, {
'package' : 'quiqqer/brick',
brickId : this.getAttribute( 'id' ),