Hi all,
I am having some trouble conceptualizing how to configure my REST api with my store, view, and controller.
How can I autoload a function from my controller to make an API call before my view is loaded, and then have the response be parsed and sent to my store? Is this best practice?
Thanks in advance!
Here is some of my code:
StatusController.js
Code:
/**
* This class is the controller for the main view for the application. It is specified as
* the "controller" of the Main view class.
*
* TODO - Replace this content of this view to suite the needs of your application.
*/
Ext.define('CPT.view.status.StatusController', {
extend: 'Ext.app.ViewController',
alias: 'controller.status',
name: 'StatusController',
// THIS FUNCTION NEEDS TO BE RAN BEFORE THE VIEW IS LOADED
onLoad: function() {
var sessionId = localStorage.getItem("SessionId");
var sharedFn = CPT.app.getController('CPT.shared.Shared');
sharedFn.rpc({
url: 'user/session/',
params: {
email: '****',
password: '****'
},
headers: {
'X-Application-Name' : 'CPT'
}
});
}
});
TicketStatus.js
Code:
Ext.define('CPT.store.TicketStatus', {
extend: 'Ext.data.Store',
xtype: 'ticketstatus',
alias: 'store.ticketstatus',
fields: [
'event_date', 'event_name', 'request', 'status', 'purpose_of_request', 'comp_requested', 'paid_requested', 'comp_approved', 'paid_approved', 'comp_approved', 'paid_approved', 'comp_fulfilled', 'paid_fulfilled', 'edit_cancel_resubmit'
],
data: { items: [
/* DATA WILL NEED TO BE HERE*/
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty: 'items'
}
}
});
Status.js
Code:
Ext.define('CPT.view.status.Status', {
extend: 'Ext.panel.Panel',
xtype: 'status',
requires: [
'CPT.view.status.TabPanel',
'CPT.view.status.StatusController'
],
height: 800,
scrollable: true,
layout: {
type: 'fit'
},
dockedItems: [{
dock: 'top',
xtype: 'statustabpanel' //TicketList.js and other tabs are nested in this tab panel
}]
});
TicketList.js
Code:
Ext.define('CPT.view.status.TicketList', {
extend: 'Ext.grid.Panel',
xtype: 'ticketlist',
requires: [
'CPT.store.TicketStatus'
],
title: '',
store: {
type: 'ticketstatus'
},
columns: [
{ text: 'Event Date', dataIndex: 'event_date' },
{ text: 'Event Name', dataIndex: 'event_name' },
{ text: 'Request # [Holder]', dataIndex: 'request' },
{ text: 'Status', dataIndex: 'status' },
{ text: 'Purpose Of Request', dataIndex: 'purpose_of_request' },
{ text: 'Comp Tix Requested', dataIndex: 'comp_requested' },
{ text: 'Paid Tix Requested', dataIndex: 'paid_requested' },
{ text: 'Comp Tix Approved', dataIndex: 'comp_approved' },
{ text: 'Paid Tix Approved', dataIndex: 'paid_approved' },
{ text: 'Comp Tix Fulfilled', dataIndex: 'comp_fulfilled' },
{ text: 'Paid Tix Fulfilled', dataIndex: 'paid_fulfilled' },
{ text: 'Edit/Cancel/Resubmit', dataIndex: 'edit_cancel_resubmit' }
],
listeners: {
select: 'onItemSelected'
},
});