Newer
Older

Henning Leutz
committed
* @module package/quiqqer/cron/bin/Manager

Henning Leutz
committed
*
* @require qui/QUI
* @require qui/controls/desktop/Panel
* @require qui/controls/windows/Confirm
* @require qui/controls/buttons/Button
* @require qui/controls/buttons/Seperator
* @require controls/grid/Grid
* @require Ajax
* @require Locale

Henning Leutz
committed
define('package/quiqqer/cron/bin/Manager', [
'qui/QUI',
'qui/controls/windows/Confirm',
'Ajax',
'Locale'
],function(QUI, QUIPanel, QUIConfirm, QUIButton, QUIButtonSeperator, Grid, Ajax, QUILocale)

Henning Leutz
committed
Type : 'package/quiqqer/cron/bin/Manager',
initialize : function(options)
{
this.parent( options );
this.addEvents({
onCreate : this.$onCreate,
onResize : this.$onResize
});
},
/**
* Load the crons into the grid
*
* @return {self}
*/
loadCrons : function()
{
var self = this;
Ajax.get('package_quiqqer_cron_ajax_getList', function(result)
{
if ( !self.$Grid ) {
return;
}

Henning Leutz
committed
var execCron = function(Btn)
{
self.execCron(
Btn.getAttribute( 'cronId' )
);
};
var toggleCron = function(Btn)
{
self.toggleStatusOfCron(
Btn.getAttribute( 'cronId' )
);
};

Henning Leutz
committed
for ( var i = 0, len = result.length; i < len; i++ )
title : QUILocale.get( lg, 'cron.panel.manager.btn.toggle' ),
icon : result[ i ].active == 1 ? 'icon-ok' : 'icon-remove',

Henning Leutz
committed
events : {
onClick : toggleCron
result[ i ].play = {
name : 'cron-play-button-'+ result[ i ].id,
title : QUILocale.get( lg, 'cron.panel.manager.btn.execute' ),
icon : 'icon-play',
cronId : result[ i ].id,

Henning Leutz
committed
events : {
onClick : execCron
}
};
self.$Grid.setData({
data : result
});
},
/**
* event : on Create
*/
$onCreate : function()
{
name : 'add',
text : QUILocale.get( lg, 'cron.panel.manager.btn.add' ),
onClick : function() {
self.openAddCronWindow();
}
}
})
);
this.addButton( new QUIButtonSeperator() );
this.addButton(
new QUIButton({
name : 'edit',
text : QUILocale.get( lg, 'cron.panel.manager.btn.edit' ),
textimage : 'icon-pencil',
events :
{
onClick : function() {
self.editMarkedCron();
}
}
})
);
name : 'delete',
text : QUILocale.get( lg, 'cron.panel.manager.btn.delete' ),
textimage : 'icon-trash',
events :
{
onClick : function() {
self.deleteMarkedCrons();
this.addButton( new QUIButtonSeperator() );
this.addButton(
new QUIButton({
name : 'history',
text : QUILocale.get( lg, 'cron.panel.manager.btn.history' ),
textimage : 'icon-long-arrow-right',
events :
{
onClick : function() {
self.showHistory();
}
}
})
);
this.getButtons( 'delete' ).disable();

Henning Leutz
committed
var Content = this.getContent(),
Container = new Element('div', {
'class' : 'box',
styles : {
width : '100%',
height : '100%'
}
}).inject( Content );
this.$Grid = new Grid(Container, {
columnModel : [{
header : QUILocale.get( 'quiqqer/system', 'status' ),

Henning Leutz
committed
width : 60
}, {
header : ' ',
dataIndex : 'play',
dataType : 'button',

Henning Leutz
committed
width : 60
header : QUILocale.get( 'quiqqer/system', 'id' ),
dataIndex : 'id',
dataType : 'string',
width : 50
dataIndex : 'min',
dataType : 'string',
width : 50
}, {
dataIndex : 'hour',
dataType : 'string',
width : 50
}, {
dataIndex : 'day',
dataType : 'string',
width : 50
}, {
dataIndex : 'month',
dataType : 'string',
width : 50
}, {
dataIndex : 'exec',
dataType : 'string',
width : 150
dataIndex : 'params',
dataType : 'string',
width : 150
dataIndex : 'desc',
dataType : 'string',
width : 200
}],
multipleSelection : true,
pagination : true
});
this.$Grid.addEvents({
onRefresh : function() {
self.loadCrons();
},
onClick : function()
{
var delButton = self.getButtons( 'delete' ),
editButton = self.getButtons( 'edit' ),
selected = self.$Grid.getSelectedIndices().length;
if ( selected == 1 )
{
editButton.enable();
} else
{
editButton.disable();
}
{
delButton.enable();
} else
{

Henning Leutz
committed
delButton.disable();
}
},
onDblClick : function(data)
{
var rowData = self.$Grid.getDataByRow( data.row );
self.editCron( rowData.id );
}
});
this.loadCrons();
},
/**
* event : on resize
*/
$onResize : function()
{
if ( !this.$Grid ) {
return;
}
var Content = this.getContent(),
size = Content.getSize();
this.$Grid.setHeight( size.y - 40 );
this.$Grid.setWidth( size.x - 40 );
},
/**
* Open the delete marked cron windows and delete all marked crons
*
* @return {self}
*/
deleteMarkedCrons : function()
{
if ( !this.$Grid ) {
return this;
}
var self = this,
data = this.$Grid.getSelectedData();
if ( !data.length ) {
return this;
}
var ids = data.map(function(o) {
return o.id;
});
new QUIConfirm({
icon : 'icon-remove',
title : QUILocale.get( lg, 'cron.window.delete.cron.title' ),
text : QUILocale.get( lg, 'cron.window.delete.cron.text' ),
information : QUILocale.get( lg, 'cron.window.delete.cron.information', {
ids : ids.join(',')
}),
events :
{
onSubmit : function(Win)
{
Win.Loader.show();
Ajax.post('package_quiqqer_cron_ajax_delete', function()
{
Win.close();
self.loadCrons();
}, {
'package' : 'quiqqer/cron',
ids : JSON.encode( ids )
});
}
}
}).open();
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
* Edit a cron, opens the cron Edit-Window
*
* @param {String} cronId - ID of the Cron
*/
editCron : function(cronId)
{
var self = this;
require(['package/quiqqer/cron/bin/CronWindow'], function(Window)
{
new Window({
cronId : cronId,
events :
{
onSubmit : function() {
self.loadCrons();
}
}
}).open();
});
return this;
},
/**
* Opens the Edit-Window for the marked cron
*/
editMarkedCron : function()
{
if ( !this.$Grid ) {
return this;
}

Henning Leutz
committed
var data = this.$Grid.getSelectedData();
if ( !data.length ) {
return this;
}
this.editCron( data[ 0 ].id );
},
/**
* Open the add Cron-Window
*
* @return {self}
*/
openAddCronWindow : function()
{
var self = this;
require(['package/quiqqer/cron/bin/CronWindow'], function(Window)
{
new Window({

Henning Leutz
committed
events : {
onSubmit : function() {
self.loadCrons();
}
}
}).open();
});
return this;
},
/**
* Change the cron status
* If the cron is active to deactive
* If the cron is deactive to active
*

Henning Leutz
committed
* @param {Number} cronId - ID of the Cron
* @return {self}
*/
toggleStatusOfCron : function(cronId)
{
var self = this;

Henning Leutz
committed
Ajax.post('package_quiqqer_cron_ajax_cron_toggle', function()
self.loadCrons();
}, {
'package' : 'quiqqer/cron',
cronId : cronId
});
return this;
},
/**
* Execute the cron
*

Henning Leutz
committed
* @param {Number} cronId - ID of the Cron
* @return {self}
*/
execCron : function(cronId)
{
var i, len;
var buttons = [];
if ( this.$Grid ) {
buttons = QUI.Controls.get( 'cron-play-button-'+ cronId );
}
for ( i = 0, len = buttons.length; i < len; i++ ) {
buttons[ i ].setAttribute('icon', 'icon-refresh icon-spin');
}

Henning Leutz
committed
Ajax.post('package_quiqqer_cron_ajax_cron_executeCron', function()
{
for ( i = 0, len = buttons.length; i < len; i++ ) {
buttons[ i ].setAttribute('icon', 'icon-play');
}
}, {
'package' : 'quiqqer/cron',
cronId : cronId
});
},
/**
* Show the Cron-History Panel
*/
showHistory : function()
{
var self = this;
require(['package/quiqqer/cron/bin/History'], function(Panel) {
new Panel().inject( self.getParent() );
});
}