Results 1 to 4 of 4

Thread: Store, View, Controller - API Configuration

  1. #1
    Sencha User
    Join Date
    Jun 2015
    Posts
    13
    Answers
    3

    Default Answered: Store, View, Controller - API Configuration

    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'
        },
    
    
    
    
    
    
    });

  2. Quote Originally Posted by adossaji View Post
    I am more concerned with how to run the onLoad function in my controller that calls my API. Once I have the object with data in it, it will be queried and will populate the grid in my TicketList and ParkingList.
    Going back to my first response, you could add a render event listener to your view, and have it call a handler method that lives in your view controller.

    Thanks!
    Joel

  3. #2
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Hi--

    You don't necessarily need to have the data ready *before* the view is created. For example, you could hook into an event like "render" on the view, and load the grid's store at this time. You could also add the autoLoad config in your store config of your grid, and this will load the store once the view is created.

    Either way, though, the grid will render the data once the remote request completes.

    Thanks!
    Joel

  4. #3
    Sencha User
    Join Date
    Jun 2015
    Posts
    13
    Answers
    3

    Default

    I am more concerned with how to run the onLoad function in my controller that calls my API. Once I have the object with data in it, it will be queried and will populate the grid in my TicketList and ParkingList.

    Quote Originally Posted by joel.watson View Post
    Hi--

    You don't necessarily need to have the data ready *before* the view is created. For example, you could hook into an event like "render" on the view, and load the grid's store at this time. You could also add the autoLoad config in your store config of your grid, and this will load the store once the view is created.

    Either way, though, the grid will render the data once the remote request completes.

    Thanks!
    Joel

  5. #4
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Quote Originally Posted by adossaji View Post
    I am more concerned with how to run the onLoad function in my controller that calls my API. Once I have the object with data in it, it will be queried and will populate the grid in my TicketList and ParkingList.
    Going back to my first response, you could add a render event listener to your view, and have it call a handler method that lives in your view controller.

    Thanks!
    Joel

Similar Threads

  1. Adding controller, model; store and view dynamically
    By ALWA in forum Sencha Touch 2.x: Q&A
    Replies: 1
    Last Post: 30 Apr 2012, 3:59 AM
  2. How to pass store to a view and set itemtpl from a controller
    By sajan in forum Sencha Architect 2.x: Help & Discussions
    Replies: 0
    Last Post: 12 Apr 2012, 2:51 PM
  3. mvc communiction between controller view and store
    By thele in forum Sencha Touch 1.x: Discussion
    Replies: 0
    Last Post: 21 Jul 2011, 1:40 PM
  4. Load Store from Controller to XTemplate in View
    By qlpage in forum Ext: Discussion
    Replies: 0
    Last Post: 1 Jul 2011, 5:47 AM
  5. model, view, store,controller should have same file name ?
    By rmdismail in forum Ext: Discussion
    Replies: 1
    Last Post: 11 Jun 2011, 6:36 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •