PDA

View Full Version : Designer 2 - Quick question



martinrame
3 Feb 2012, 2:16 AM
I'm testing Designer 2 and have two questions.

1 - In my application.js I have a singleton that stores application configuration, like this:


Ext.define('Globals',{
singleton: true,
loggedIn: false
});

So far, I'm starting my app with a custom "app.js", because Designer overwrites my file removing my Ext.define. How/where can I add this code to my app in Designer?.

2 - In my app, I only want to declare Controllers in the main app file, but Designer adds Stores, Views and Models automatically. How can I force Designer to only add Controllers?.

Thanks in advance,
Leonardo.

aconran
3 Feb 2012, 6:12 AM
1) You can put this inside your launch method of the application. Double click on the Application node (or click on the application and go to the code view). Then use the drop down in the top left to switch to the launch method.

2) This is currently by design. Are you putting the stores/views/models on a different controller other than the application controller? If so the designer should prompt you to remove it from Application when you add it to the controller.

martinrame
3 Feb 2012, 12:53 PM
Thanks aconran, I solved question #2.

Regarding #1, I added a model named "User" and created an instance in app launch as follows:


launch: function() {
var userInstance = Ext.create('MyApp.model.User', {loggedIn: false});
}

The problem is that I need to access this instance from a controller (also defined in app.js). In the controller's init function I added this:


userInstance.set('loggedIn', false);

But I get "Uncaught ReferenceError: userInstance is not defined" in my browser javascript debug window.

Leonardo.

ssamayoa
3 Feb 2012, 1:06 PM
Put the value in your singleton:



Ext.define('Globals',{ singleton: true, loggedIn: false });
var Globals = MyApp.Globals;




launch: function() {
Globals.user = Ext.create('MyApp.model.User', {loggedIn: false});
}


Then access the object using Globals.user

martinrame
3 Feb 2012, 1:44 PM
ssamayoa, this is my app.js, where should I add my singleton?


Ext.Loader.setConfig({
enabled: true
});


Ext.application({
autoCreateViewport: true,


name: 'MyApp',


controllers: [
'MyForm',
'MyGridPanel',
'ViewportController'
],


launch: function() {
}
});

ssamayoa
3 Feb 2012, 1:57 PM
I just check designer and doesnt have a "requires" property.

I use that technique with hand chafted app.js, something like:



Ext.application({
autoCreateViewport: true,
name: 'MyApp',
requires : [ 'Globals'], // <<<--here
launch: function() {
Globals.user...
}
});