Ext.define('Compass.ErpApp.Mobile.JobTracker.Application', { extend: 'Ext.Carousel', xtype: 'compass-erpapp-mobile-jobtracker-application', selectedJob: null, config: { layout: 'card', listeners: { activate: function () { this.setActiveItem(0); } } }, scheduleJob: function () { var me = this; this.setMasked({xtype: 'loadmask', message: 'scheduling job...'}); Ext.Ajax.request({ url: '/erp_app/desktop/job_tracker/schedule', method: 'POST', params: { id: this.selectedJob.get('id'), authenticity_token:Compass.ErpApp.AuthentictyToken }, success: function (response) { me.setMasked(false); var obj = Ext.decode(response.responseText); if (obj.success) { me.store.load(); me.setActiveItem(0); } else { Ext.Msg.alert('Error', 'Error scheduling job.'); } }, failure: function (response) { me.setMasked(false); Ext.Msg.alert('Error', 'Error scheduling job.'); } }); }, unScheduleJob: function () { var me = this; this.setMasked({xtype: 'loadmask', message: 'Unscheduling job...'}); Ext.Ajax.request({ url: '/erp_app/desktop/job_tracker/unschedule', method: 'POST', params: { id: this.selectedJob.get('id'), authenticity_token:Compass.ErpApp.AuthentictyToken }, success: function (response) { me.setMasked(false); var obj = Ext.decode(response.responseText); if (obj.success) { me.store.load(); me.setActiveItem(0); } else { Ext.Msg.alert('Error', 'Error unscheduling job.'); } }, failure: function (response) { me.setMasked(false); Ext.Msg.alert('Error', 'Error unscheduling job.'); } }); }, constructor: function (config) { this.store = Ext.create('Compass.ErpApp.Mobile.JobTracker.Store.Jobs', { storeId: 'jobtracker-jobstore' }); this.store.load(); config['items'] = [ { xtype: 'toolbar', ui: 'light', iconMask:true, docked: 'top', items: [ { text: 'Home', ui: 'back', handler: function (btn) { btn.up('#mainContainer').setActiveItem('#home'); } }, { iconCls: 'refresh', iconMask: true, handler: function (btn) { btn.up('compass-erpapp-mobile-jobtracker-application').store.load(); } } ] }, { xtype: 'list', store: 'jobtracker-jobstore', onItemDisclosure: true, itemTpl: [ '', '
', '', '
', '', '
', '
', '
{job_name}
', '', '
Last run: N/A
', '', '
Last run: {last_run_at:date("m/d/Y g:i:s")}
', '
', '', '
Next run: N/A
', '', '
Next run: {next_run_at:date("m/d/Y g:i:s")}
', '
'], listeners: { disclose: function (me, record, target, e, eOpts) { var app = me.up('compass-erpapp-mobile-jobtracker-application'), details = app.down('#details'); details.setHtml(Compass.ErpApp.Mobile.JobTracker.Templates.jobDetails.apply(record.getData())); app.setActiveItem(details); app.selectedJob = record; } } }, { itemId: 'details', items: [ { xtype: 'toolbar', docked: 'top', items: [ { text: 'Schedule', handler: function (btn) { var app = btn.up('compass-erpapp-mobile-jobtracker-application'); if(Ext.isEmpty(app.selectedJob)){ Ext.Msg.alert('Error', 'No job selected'); } else{ app.scheduleJob(); } } }, { text: 'UnSchedule', handler: function (btn) { var app = btn.up('compass-erpapp-mobile-jobtracker-application'); if(Ext.isEmpty(app.selectedJob)){ Ext.Msg.alert('Error', 'No job selected'); } else{ app.unScheduleJob(); } } } ] } ], layout: 'fit', autoScroll: true } ]; this.callParent([config]); } });