Results 1 to 3 of 3

Thread: Global variables

  1. #1

    Default Global variables

    Hi,
    Anyone have idea how to create and manage global variables in SA3 ?,
    I'm trying to handle an array where I want to go keeping the names of some buttons that is clicked.
    Thank you for your help

  2. #2
    Sencha Premium Member
    Join Date
    May 2010
    Location
    Guatemala, Central America
    Posts
    1,501
    Answers
    13

    Default

    Not quite sure what you want to accomplish but for constants you have at least two options:

    1. Add a JS resource and create your constants there.l
    2. Add a new class and make it singleton. Then add properties to it.

    In the 2n case you will have to prefix your values with <app>.<kind>.<ClassName>.

    In both cases you can reference your variables in code.
    If you want to use some variable to set a component property you have to to that in "process config" function, for example:

    Code:
    processConfig: function(config) {
      config.title = MyApp.view.Constants.WIN_TITLE;
    }
    Hope this helps.

    Regards.

  3. #3
    Sencha Premium Member
    Join Date
    Jul 2014
    Location
    Bakersfield CA
    Posts
    81
    Answers
    3

    Default

    Here is my example...

    Code:
    Ext.define('shared.constants.Config',{
        singleton: true,
        alias: 'config',
        itemId: '#config',
        config:{
            //Counts - latest
            localDBWellBoreCount: 0-0,
            localDBWellTestCount:0,
            remoteDBWellTestCount: 0,
            remoteDBWellBoreCount: 0,
    
    
            //Control Variables
            refreshIncremental: false,
            isOffline: true,
            isLocalReplicating: false,
            isRemoteReplicating: false,
            loadFromOfflineResource: false,
            isGettingLocalModifiedRecords: false,
    
    
            //testing mode either local or remote
            testingMode: 'remote',
    
    
            // Used for replication
            eventArgs : {"store":null,"records":null,"successful":null,"operation":null,"eOpts":null},
    
    
            //URL Prefixes
            localServer: 'http://services:8080/',
            remoteServer: 'http://54.173.155.87:8080/',
            targetServer: null
        },
    
    
        constructor: function (config){
            //Ext.Logger.log('The Class '+this.self.getName()+'::constructor method has been executed');
            this.setLocalDBWellBoreCount = 0;
            this.localDBWellTestCount = 0;
            this.remoteDBWellTestCount = 0;
            this.remoteDBWellBoreCount = 0;
            this.refreshIncremental = false;
            this.isOffline = false;
            this.isLocalReplicating = false;
            this.isRemoteReplicating = false;
            this.loadFromOfflineResource = false;
            this.isGettingLocalModifiedRecords = false;
            this.testingMode = 'remote';
            this.localServer = 'http://services:8080/';
            this.remoteServer = 'http://54.173.155.87:8080/';
            this.eventArgs = {"store":null,"records":null,"successful":null,"operation":null,"eOpts":null};
    
    
            switch (this.testingMode) {
                case 'local': 
                    this.targetServer = this.localServer;
                    break;
                case 'remote':
                    this.targetServer = this.remoteServer;
            }
    
    
    
    
        },
    
    
        toString: function() {
            this.callParent();
            return '\n|| localDBWellBoreCount = '+this.localDBWellBoreCount+ '\n|| localDBWellTestCount = '+this.localDBWellTestCount+'\n|| remoteDBWellTestCount = '+this.remoteDBWellTestCount+
                '\n|| remoteDBWellBoreCount = '+this.remoteDBWellBoreCount+'\n|| refreshIncremental = '+this.refreshIncremental+
                '\n|| isOffline = '+this.isOffline + '\n|| isLocalReplicating = '+this.isLocalReplicating+ 
                '\n|| isRemoteReplicating = '+this.isRemoteReplicating+'\n|| loadFromOfflineResource = '+this.loadFromOfflineResource+
                '\n|| isGettingLocalModifiedRecords = '+this.isGettingLocalModifiedRecords+'\n|| testingMode = '+this.testingMode+
                '\n|| localServer = '+this.localServer+'\n|| testingMode = '+this.testingMode+'\n|| remoteServer = '+this.remoteServer+
                '\n|| targetServer = '+this.targetServer;
        }
    
    
    });
    Make sure you add this to your app.requires collection in the Application Config, like this...

    Code:
    / @require @packageOverrides
    Ext.Loader.setConfig({
        paths: {
            storage: './storage',
            config: './shared/constants',
            proxy: './proxy',
            custom: './custom'
        }
    });
    
    
    Ext.application({
    
    
        requires: [
            'Ext.Loader',
            'shared.constants.Config',
            'Ext.device.Connection',
            'proxy.OfflineProxy',
            'storage.WebSQL',
            'Ext.Label',
            'Ext.Date',
            'Ext.DateExtras'
        ],
        models: [
            'WellTestModel',
            'WellModel',
            'ServiceModel',
            'CriteriaModel'
        ],
        stores: [
            'WellListStore',
            'WellTestJSONStore',
            'ServiceStore',
            'CriteriaStore'
        ],
        views: [
            'WellNavigation',
            'WellListContainer',
            'WellTestPanel'
        ],
        controllers: [
            'WellController',
            'WellTestController',
            'ReplicationController'
        ],
        name: 'AEGMobile',
    
    
        launch: function() {
            shared.constants.Config.isOffline = !Ext.device.Connection.isOnline();
            shared.constants.Config.isLocalReplicating = false;
            shared.constants.Config.isRemoteReplicating = false;
            shared.constants.Config.loadFromOfflineResource = false;
            shared.constants.Config.isGettingLocalModifiedRecords = false;
    
    
            //Ext.Logger.log('************************* CONTROL VALUES STATE BELOW **********************************************');
            //Ext.Logger.log(this.self.getName()+'::launch is TESTING the values of shared.constants.Config = '+shared.constants.Config.toString());
            //Ext.Logger.log('************************* CONTROL VALUES STATE ABOVE **********************************************');
    
    
            storage.WebSQL.setListener();
            Ext.Viewport.setMasked(false);
            Ext.Viewport.setMasked({ xtype: 'loadmask', message: 'AEGMobile Starting...' });
            Ext.create('AEGMobile.view.WellNavigation', {fullscreen: true});
        }
    
    
    });
    Notice how I use the Ext.Logger Class instead of console.log. I don't have an observer pattern applied to my design to control the replication process back to the server, so I use the logging like this to tell me what's happening with my Globals (which are STATE variables). If you do the same then you will have to explicitly comment them out for a production build to work.

    Hope this helps...

    Curtis

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
  •