Newer
Older
* @author www.pcsg.de (Henning Leutz)

Henning Leutz
committed
*
* @require qui/QUI
* @require qui/controls/desktop/Panel
* @require qui/controls/buttons/Select
* @require qui/controls/buttons/Button
* @require qui/controls/buttons/Seperator
* @require qui/controls/windows/Confirm
* @require controls/grid/Grid
* @require Locale
* @require Projects
* @require Ajax
* @require css!package/quiqqer/bricks/bin/Manager.css
'qui/QUI',
'qui/controls/desktop/Panel',
'qui/controls/buttons/Select',
'qui/controls/buttons/Button',
'qui/controls/buttons/Seperator',
'controls/grid/Grid',
'Locale',
'Projects',
], function(QUI, QUIPanel, QUISelect, QUIButton, QUISeperator, QUIConfirm, Grid, QUILocale, Projects, Ajax)
return new Class({
Extends : QUIPanel,
},
initialize : function(options)
{
this.parent( options );
this.$Grid = false;
this.$ProjectSelect = false;
this.$ProjectLangs = false;
onCreate : this.$onCreate,
onResize : this.$onResize
var self = this,
project = this.$ProjectSelect.getValue(),
lang = this.$ProjectLangs.getValue();
this.getBricksFromProject(project, lang, function(result)
/**
* Refresh the buttons status
*/
refreshButtons : function()
{
var selected = this.$Grid.getSelectedData(),
AddButton = this.getButtons('brick-add'),
DelButton = this.getButtons('brick-delete');
{
AddButton.enable();
DelButton.disable();
return;
}
AddButton.enable();
DelButton.enable();
/**
* event : on create
*/
$onCreate : function()
{
var self = this;
// Buttons
this.$ProjectSelect = new QUISelect({
name : 'projects-name',
events : {
onChange : this.$refreshProjectLanguages
}
});
this.$ProjectLangs = new QUISelect({
name : 'projects-langs',
this.addButton(this.$ProjectSelect);
this.addButton(this.$ProjectLangs);
this.addButton(new QUISeperator());
disabled : true,
events : {
onClick : this.$openDeleteDialog
}
})
);
// Grid
var Container = new Element('div').inject(
this.getContent()
);
this.$Grid = new Grid( Container, {
columnModel : [{
dataIndex : 'id',
dataType : 'integer',
width : 40
}, {
dataIndex : 'title',
dataType : 'string',
width : 140
}, {
header : QUILocale.get('quiqqer/system', 'description'),
dataIndex : 'description',
dataType : 'string',
width : 300
}, {
dataIndex : 'type',
dataType : 'string',
width : 200
onDblClick : this.$onDblClick,
onClick : this.$onClick
this.Loader.show();
Projects.getList(function(projects)
{
continue;
}
self.$ProjectSelect.appendChild(
project, project, 'icon-home'
);
}
self.$ProjectSelect.setValue(
self.$ProjectSelect.firstChild().getAttribute( 'value' )
);
});
},
/**
* event : on resize
*/
$onResize : function()
{
if ( !this.$Grid ) {
return;
}
var Body = this.getContent();
return;
}
var size = Body.getSize();
this.$Grid.setHeight(size.y - 40);
this.$Grid.setWidth(size.x - 40);
/**
* event : dbl click
*/
$onDblClick : function()
{
/**
* event : click
*/
$onClick : function()
{
this.refreshButtons();
},
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
308
309
310
311
312
313
314
315
316
317
318
319
/**
* 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' )
);
}
});
},
*/
$openCreateDialog : function()
{
var self = this;
new QUIConfirm({
title : QUILocale.get( lg, 'manager.window.create.title' ),
icon : 'icon-th',
maxHeight : 300,
maxWidth : 400,
autoclose : false,
events :
{
onOpen : function(Win)
{
var Body = Win.getContent();
Win.Loader.show();
QUILocale.get( lg, 'manager.window.create.label.title' ) +

Henning Leutz
committed
' <input type="text" name="title" required="required" />' +
QUILocale.get( lg, 'manager.window.create.label.type' ) +
' </span>' +
' <select name="type"></select>' +
'</label>'
);
var i, len, group, title, val;
var Select = Body.getElement( 'select'),
Title = Body.getElement( '[name="title"]');
if ( 'group' in title )
{
group = title.group;
val = title.var;
} else
{
group = title[ 0 ];
val = title[ 1 ];
}
html : QUILocale.get( group, val )
}).inject( Select );
}
Title.focus.delay( 500, Title );
Win.Loader.hide();
});
},
onSubmit : function(Win)
{
Win.Loader.show();
var Body = Win.getContent(),
Title = Body.getElement( '[name="title"]' ),
Type = Body.getElement( '[name="type"]' );

Henning Leutz
committed
if ( Title.value === '' )
{
QUI.getMessageHandler(function(MH)
{
MH.addError(
QUILocale.get( lg, 'exception.brick.has.no.title' ),
Title
);
});
Title.focus();
Win.Loader.hide();
var project = self.$ProjectSelect.getValue(),
lang = self.$ProjectLangs.getValue();
self.createBrick(project, lang, {
*/
$openDeleteDialog : function()
{
var self = this,
brickIds = this.$Grid.getSelectedData().map(function(brick) {
return brick.id;
});
new QUIConfirm({
maxHeight : 300,
maxWidth : 600,
autoclose : false,
title : QUILocale.get( lg, 'manager.window.delete.title' ),
events :
{
onOpen : function(Win)
{
var Content = Win.getContent(),
lists = '<ul>';
self.$Grid.getSelectedData().each(function(brick) {
lists = lists +'<li>'+ brick.id +' - '+ brick.title +'</li>';
});
lists = lists +'</ul>';
Content.set(
'html',
QUILocale.get( lg, 'manager.window.delete.information', {
list : lists
})
);
},
onSubmit : function(Win)
{
Win.Loader.show();
{
Win.close();
self.refresh();
});
}
}
}).open();
},
/**
require([
'package/quiqqer/bricks/bin/BrickEdit',
'utils/Panels'
], function(BrickEdit, PanelUtils)
{
PanelUtils.openPanelInTasks(
new BrickEdit({
id : brickId,
projectName : this.$ProjectSelect.getValue(),
projectLang : this.$ProjectLangs.getValue(),
events : {
onDelete : this.refresh
}
*
* @param {Function} [callback] - callback function
*
* @return Promise
return new Promise(function(resolve, reject) {
Ajax.get('package_quiqqer_bricks_ajax_getAvailableBricks', function(result) {
if (typeof callback === 'function') {
callback(result);
}
resolve(result);
}, {
'package' : 'quiqqer/bricks',
onError : reject
});
*
* @param {String} project - name of the project
* @param {String} lang - Language of the project
* @param {Function} [callback] - callback function
*
* @return Promise
getBricksFromProject : function(project, lang, callback)
return new Promise(function(resolve, reject) {
Ajax.get('package_quiqqer_bricks_ajax_project_getBricks', function(result) {
if (typeof callback === 'function') {
callback(result);
}
resolve(result);
}, {
'package' : 'quiqqer/bricks',
project : JSON.encode({
name : project,
lang : lang
}),
onError : reject
});
* @param {String} project - name of the project
* @param {String} lang - Language of the project
* @param {Object} data - Data of the brick
* @param {Function} [callback] - callback function
*
* @return Promise
createBrick : function(project, lang, data, callback)
return new Promise(function(resolve, reject) {
Ajax.post('package_quiqqer_bricks_ajax_project_createBrick', function(brickId) {
if (typeof callback === 'function') {
callback(brickId);
}
resolve(brickId);
}, {
'package' : 'quiqqer/bricks',
project : JSON.encode({
name : project,
lang : lang
}),
data : JSON.encode(data),
onError : reject
});
* @param {Array} brickIds - Brick IDs which should be deleted
* @param {Function} [callback] - callback function
*
* @return Promise
var panels = QUI.Controls.getByType(
'package/quiqqer/bricks/bin/BrickEdit'
);
return new Promise(function(resolve, reject) {
Ajax.post('package_quiqqer_bricks_ajax_brick_delete', function() {
if (typeof callback === 'function') {
callback();
}
resolve();
// exist brick panels?
var c, i, len, clen, brickId;
for (i = 0, len = brickIds.length; i < len; i++) {
brickId = brickIds[i];
for (c = 0, clen = panels.length; c < clen; c++) {
if (panels[c].getAttribute('id') == brickId) {
panels[c].destroy();
}
}
}
}, {
'package' : 'quiqqer/bricks',
brickIds : JSON.encode(brickIds),
onError : reject
});