Newer
Older
/**
* Block manager
*
* @module package/quiqqer/blocks/bin/Manager
* @author www.pcsg.de (Henning Leutz)
*/
define('package/quiqqer/blocks/bin/Manager', [
'qui/QUI',
'qui/controls/desktop/Panel',
'qui/controls/buttons/Select',
'qui/controls/buttons/Button',
'qui/controls/buttons/Seperator',
'controls/grid/Grid',
'Locale',
'Projects',
'css!package/quiqqer/blocks/bin/Manager.css'
], function(QUI, QUIPanel, QUISelect, QUIButton, QUISeperator, QUIConfirm, Grid, QUILocale, Projects, Ajax)
{
"use strict";
var lg = 'quiqqer/blocks';
return new Class({
Extends : QUIPanel,
Type : 'package/quiqqer/blocks/bin/Manager',
Binds : [
'loadBlocksFromProject',
'refresh',
'$onCreate',
],
options : {
title : QUILocale.get( lg, 'menu.blocks.text' )
},
initialize : function(options)
{
this.parent( options );
onCreate : this.$onCreate,
onResize : this.$onResize
{
if ( !this.$Elm ) {
return;
}
var self = this;
this.Loader.show();
this.getBlocksFromProject(this.$ProjectSelect.getValue(), function(result)
{
/**
* Refresh the buttons status
*/
refreshButtons : function()
{
var selected = this.$Grid.getSelectedData(),
AddButton = this.getButtons('block-add'),
DelButton = this.getButtons('block-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',
events : {
onChange : this.refresh
}
});
this.addButton( this.$ProjectSelect );
this.addButton( new QUISeperator() );
this.addButton(
new QUIButton({
text : 'Block hinzufügen',
name : 'block-add',
disabled : true,
events : {
this.addButton(
new QUIButton({
text : 'Markierte Blöcke löschen',
name : 'block-delete',
disabled : true,
events : {
onClick : this.$openDeleteDialog
}
})
);
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
// 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
}, {
header : QUILocale.get( lg, 'block.type' ),
dataIndex : 'type',
dataType : 'string',
width : 200
onDblClick : this.$onDblClick,
onClick : this.$onClick
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
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()
{
this.editBlock(
this.$Grid.getSelectedData()[0].id
);
},
/**
* event : click
*/
$onClick : function()
{
this.refreshButtons();
},
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
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
/**
*
*/
$openCreateDialog : function()
{
var self = this;
new QUIConfirm({
title : 'Neuen Block hinzufügen',
icon : 'icon-th',
maxHeight : 300,
maxWidth : 400,
autoclose : false,
events :
{
onOpen : function(Win)
{
var Body = Win.getContent();
Win.Loader.show();
Body.addClass( 'quiqqer-blocks-create' );
Body.set(
'html',
'<label>' +
' <span class="quiqqer-blocks-create-label-text">' +
' Title' +
' </span>' +
' <input type="text" name="title" />' +
'</label>' +
'<label>' +
' <span class="quiqqer-blocks-create-label-text">' +
' Block Typ' +
' </span>' +
' <select name="type"></select>' +
'</label>'
);
self.getAvailableBlocks(function(blocklist)
{
if ( !Body ) {
return;
}
var i, len, group, title, val;
var Select = Body.getElement( 'select'),
Title = Body.getElement( '[name="title"]');
for ( i = 0, len = blocklist.length; i < len; i++ )
{
title = blocklist[ i ].title;
if ( 'group' in title )
{
group = title.group;
val = title.var;
} else
{
group = title[ 0 ];
val = title[ 1 ];
}
html : QUILocale.get( group, val )
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
}).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"]' );
if ( Title.value === '' ) {
return;
}
self.createBlock(self.$ProjectSelect.getValue(), {
title : Title.value,
type : Type.value
}, function(blockId)
{
Win.close();
self.refresh(function() {
self.editBlock( blockId );
});
});
}
}
}).open();
},
/**
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
* Opens the delete block dialog
*/
$openDeleteDialog : function()
{
var self = this,
blockIds = this.$Grid.getSelectedData().map(function(block) {
return block.id;
});
new QUIConfirm({
maxHeight : 300,
maxWidth : 600,
autoclose : false,
events :
{
onOpen : function(Win)
{
var Content = Win.getContent(),
lists = '<ul>';
self.$Grid.getSelectedData().each(function(block) {
lists = lists +'<li>'+ block.id +' - '+ block.title +'</li>';
});
lists = lists +'</ul>';
Content.set(
'html',
'<h1>Möchten Sie folgende Block-IDs wirklich löschen</h1>' +
lists
);
},
onSubmit : function(Win)
{
Win.Loader.show();
self.deleteBlocks(blockIds, function()
{
Win.close();
self.refresh();
});
}
}
}).open();
},
/**
* Opens the edit sheet of a Block
*
* @param {integer} blockId
*/
editBlock : function(blockId)
{
this.Loader.show();
var Block;
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
var self = this,
Sheet = this.createSheet({
title : 'Block editieren'
});
Sheet.addEvents({
onOpen : function(Sheet)
{
require(['package/quiqqer/blocks/bin/BlockEdit'], function(BlockEdit)
{
Block = new BlockEdit({
id : blockId,
project : self.$ProjectSelect.getValue(),
events :
{
onLoaded : function() {
self.Loader.hide();
}
}
}).inject( Sheet.getContent() );
});
Sheet.getContent().setStyle( 'overflow', 'auto' );
}
});
Sheet.addButton({
textimage : 'icon-save',
text : 'Speichern',
styles : {
width : 200
},
events :
{
onClick : function()
{
self.Loader.show();
Block.save(function()
{
self.Loader.hide();
Sheet.hide();
});
}
}
});
Sheet.show();
},
/**
* Methods / Model
*/
/**
* Return the available blocks
* @param callback
*/
getAvailableBlocks : function(callback)
{
Ajax.get('package_quiqqer_blocks_ajax_getAvailableBlocks', callback, {
'package' : 'quiqqer/blocks'
});
},
/**
* Return the blocksf from a project
*
* @param {String} project - name of the project
* @param {Function} callback - callback function
*/
getBlocksFromProject : function(project, callback)
{
Ajax.get('package_quiqqer_blocks_ajax_project_getBlocks', callback, {
'package' : 'quiqqer/blocks',
project : JSON.encode({
name : project
})
});
},
/**
* Create a new block
*
* @param {String} project
* @param {Object} data
* @param {Function} callback
*/
createBlock : function(project, data, callback)
{
Ajax.post('package_quiqqer_blocks_ajax_project_createBlock', callback, {
'package' : 'quiqqer/blocks',
project : JSON.encode({
name : project
}),
data : JSON.encode( data )
});
},
/**
* Delete the Block-Ids
*
* @param {array} blockIds - Block IDs which should be deleted
* @param {Function} callback
*/
deleteBlocks : function(blockIds, callback)
{
Ajax.post('package_quiqqer_blocks_ajax_block_delete', callback, {
'package' : 'quiqqer/blocks',
blockIds : JSON.encode( blockIds )
});