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');
if ( !selected.length )
{
AddButton.enable();
DelButton.disable();
return;
}
AddButton.enable();
DelButton.enable();
if ( selected.length > 1 ) {
AddButton.disable();
}
},
/**
* 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( new QUISeperator() );
this.addButton(
new QUIButton({
text : QUILocale.get( lg, 'manager.button.delete' ),
disabled : true,
events : {
onClick : this.$openDeleteDialog
}
})
);
// Grid
var Container = new Element('div').inject(
this.getContent()
);
this.$Grid = new Grid( Container, {
columnModel : [{
header : QUILocale.get( 'quiqqer/system', 'id' ),
dataIndex : 'id',
dataType : 'integer',
width : 40
}, {
header : QUILocale.get( 'quiqqer/system', 'title' ),
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
this.Loader.show();
Projects.getList(function(projects)
{
for ( var project in projects )
{
if ( !projects.hasOwnProperty( project ) ) {
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();
if ( !Body ) {
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()
})
);
}.bind(this));
*
* @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
return new Promise(function(resolve, reject) {
Ajax.post('package_quiqqer_bricks_ajax_brick_delete', function() {
if (typeof callback === 'function') {
callback();
}
resolve();
}, {
'package' : 'quiqqer/bricks',
brickIds : JSON.encode(brickIds),
onError : reject
});