PDA

View Full Version : MVC, Ext.direct & "the Tools"



sysrun
30 Jan 2012, 5:44 AM
Hi,

im not getting it:

If i use this code, all my App-Files where packed in the app-all.js BUT the Ext.direct-Calls in my stores throwing errors "Undefined" direct-functions.


Ext.require(['Ext.direct.Manager',"Bonusserver.REMOTING_API"],function(){
Ext.direct.Manager.addProvider(Bonusserver.REMOTING_API);
},this);
Ext.application({
name: 'Bonus',

appFolder: 'extapp',


requires:[
'Ext.direct.*',
'Bonus.*',
'Ext.view.*'
],


controllers: [
'XXX'
],


autoCreateViewport: true

}
});


If i use this code, the Ext.direct part is ok BUT none of my App-Files would be included in the app-all.js:


Ext.require(['Ext.direct.Manager',"Bonusserver.REMOTING_API","Ext.app.Application"],function(){
Ext.direct.Manager.addProvider(Bonusserver.REMOTING_API);
Ext.application({
name: 'Bonus',

appFolder: 'extapp',


requires:[
'Ext.direct.*',
'Bonus.*',
'Ext.view.*'
],


controllers: [
'XXX'
],


autoCreateViewport: true

}
});

},this);


So, how to use ExtMVC together with Ext.direct and the Sencha-Tools?

mitchellsimoens
30 Jan 2012, 8:40 AM
What happens if you use addProvider within the Ext.application's launch method? This will need to be reworked as you are using autoCreateViewport though.

sysrun
31 Jan 2012, 7:41 AM
Like this code?


Ext.application({
...

autoCreateViewport: true,
launch: function() {
Ext.direct.Manager.addProvider(Bonusserver.REMOTING_API);
}
}
});


This will need to be reworked as you are using autoCreateViewport though.

So i cant use autoCreateViewport?

sysrun
31 Jan 2012, 8:53 AM
Tried this Code in my app.js:



Ext.require('Ext.direct.Manager',function(){
Ext.direct.Manager.addProvider(Bonusserver.REMOTING_API);
});

Ext.application({
name: 'Bonus',

appFolder: 'extapp',

paths:{
"Ext": "ext-4.0.7/src",
"Bonus":"extapp",
"Ext.ux":"ux"
},



controllers: [
xxx
],


autoCreateViewport: false,


launch:function(){
Ext.direct.Manager.addProvider(Bonusserver.REMOTING_API);
Ext.create('Ext.container.Viewport', {
items: {
html: 'My App'
}
});
}
});

autoCreateViewport off and addProvider in launch-function. Same Error:

After async-load of the Model i get an error in Firebug:
Bonusserver.Mitarbeiter is undefined

Here is my Model:

Ext.define('Bonus.model.Mitarbeiter', {
extend: 'Ext.data.Model',

fields: [
'id',
{name: 'name', type: 'string'},
{name: 'email', type: 'string'}
],

proxy:{
type:'direct',
directFn:Bonusserver.Mitarbeiter.getSelect
}

});

bsbal
20 Mar 2012, 6:24 AM
I'm at the moment at the same point. When I include my user classes in app-all.js then my extDirect functions are broken, if I exclude my user classes from app-all.js, extDirect functions are working fine.

Is there no solution for this problem arround?

bsbal
21 Mar 2012, 3:53 AM
I've managed it to get it working with 4.1 RC2 setting all directFn definitions (in models) in quotes and resetting directFn in controller code.

Only problem is, that proxy config has to be set in controller logic! :(

mitchellsimoens
21 Mar 2012, 4:07 AM
You could set it in the constructor.

bsbal
21 Mar 2012, 4:47 AM
Question 1: How
Question 2: Why is this necessary? Isn't it a Bug?

mitchellsimoens
21 Mar 2012, 4:57 AM
It's not a bug. The reason is the directFn is trying to look for a JS namespaced function which until the provider returns doesn't exist. I wish there was a way to work around it which you could define as a string and then in a constructor handle that, either way there isn't an elegant solution.


Ext.define('MyApp.store.Direct', {
extend : 'Ext.data.Store',

....

constructor : function(config) {
config = config || {};

config.proxy = {
...
directFn : Some.direct.Function
};

this.callParent([config]);
}
});

bsbal
21 Mar 2012, 5:39 AM
I've tried your suggestion but had no luck.

Store:


Ext.define('Iks.store.UserKontrolle', {
extend: 'Ext.data.DirectStore',
storeId: 'UserKontrolle',


model: 'Iks.model.UserKontrolle',
autoLoad: false,

sorters: ['themengebietPos', 'themaPos'],


constructor: function (config) {
config = config || {};


config.proxy = {
type: 'direct',
batchActions: false,
paramOrder: 'id',
api: {
read: MyExt.IksService.readUserKontrolle,
update: MyExt.IksService.updateUserKontrolle
},
reader: {
type: 'json',
root: 'result',
idProperty: 'id'
}


};


this.callParent(config);
}

});


Model:


Ext.define('Iks.model.UserKontrolle', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'titel', type: 'string' },
{ name: 'beschrieb', type: 'string' },
{ name: 'verantwortlicherUser', type: 'string' },
{ name: 'reqFile', type: 'bool' },
{ name: 'bisDatum', type: 'date', dateFormat: 'MS' },
{ name: 'ergebnisText', type: 'string' },
{ name: 'status', type: 'int' },
{ name: 'modDatum', type: 'date', dateFormat: 'MS' },
{ name: 'modUser', type: 'string' },
{ name: 'thema', type: 'string' },
{ name: 'themaPos', type: 'int' },
{ name: 'themengebiet', type: 'string' },
{ name: 'themengebietPos', type: 'int' },
{ name: 'kombiPos', type: 'string' }
]



});


Without doing that in Controller,


onLaunch: function () {


//Config Stores
var UserKontrolleStore = Ext.getStore('UserKontrolle');
UserKontrolleStore.proxy.api.read = MyExt.IksService.readUserKontrolle;
UserKontrolleStore.proxy.api.update = MyExt.IksService.updateUserKontrolle;
...




it comes with following error:
'No direct function specified for this proxy' when calling method: [nsIDOMEventListener::handleEvent]

bsbal
21 Mar 2012, 5:42 AM
And sice [4.1RC1] you can define a directFn as a string, what is really helping when using SDK Tools.

Lukappa
27 Nov 2012, 11:49 PM
Hello,
I just want to share my experience about this issue.

After compiling my MVC (extjs-4.1.3) project with sencha cmd 3, Ext.direct was broken.

The main problem was inside my models because I placed the proxy inside some model (tried even with constructor, but no changes).

I solved the problem moving every "proxy" from every "model" to related "store" and wrapping every directFn / api.read between quotes.

​I hope it could help you. Bye

catalinux1907
28 Nov 2012, 12:19 AM
Ext.define('MyApp.store.NewsletterListStore', {
extend:'Ext.data.Store',
model:'MyApp.model.NewsletterCampaign',


storeId:'NewsletterListStore',
autoLoad:true,


proxy:{
type:'direct',
directFn:'App.io.Module1.getCampaignList',
reader:{
type:'json',
root:'data',
successProperty:'success',
totalProperty:'total'
}
}
});


This works great

jgroth
30 Nov 2012, 7:17 AM
After hours of debugging I finally got this to work. This is what I had to do to get it working:


Using String definitions for directFn in my stores
Defining a constructor in my Ext.application object
Loading my direct functions in the application constructor through Ext.direct.Manager.addProvider (it did not work loading them in the launch method, since the stores got loaded before that and it seemed like the directFn got set to null if the functions had not been loaded)