ExtJs model proxy versus proxy server

Well, I am fixated on what should be the main task in ExtJs. I am writing a simple login script that sends a username / password combination to a RESTful web service and gets a GUID if the credentials are correct.

My question is: do I use a model proxy or a store proxy?

As far as I understand, models are one record, while stores are designed to process datasets containing more than one record. If this is correct, then the Model proxy seems to be the way to go.

After Sencha's documentation at http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Model, the code will look something like this:

Ext.define('AuthenticationModel', { extend: 'Ext.data.Model', fields: ['username', 'password'], proxy: { type: 'rest', url : '/authentication' } }); //get a reference to the authentication model class var AuthenticationModel = Ext.ModelManager.getModel('AuthenticationModel'); 

So far, everything is in order, until the next step:

 //Use the configured RestProxy to make a GET request AuthenticationModel.load('???', { success: function(session) { console.log('Login successful'); } }); 

The load () method for the Model class is a static call waiting for a single unique identifier. Logins usually depend on two factors: username and password.

Thus, this means that the store proxy is the only way to verify the account name of the username and password in ExtJS. Can anyone check and explain? Any help to figure this out would be greatly appreciated.

+7
restful-authentication extjs extjs4 model store
source share
2 answers

You just need to know the following:

The store will use its own proxy server, if you configured it for this instance, and if not, it takes proxies from the model.

Thus, you can easily use two proxy configurations to include operations with several CRUDs in the repository and operations with one CRUD in the models. Please note that the static load method of the model expects the id model, because it is supposed to load the model with only one identifier (yes, composite keys are not supported). You will also need to get the model instance in the callback (as you did).

Back to your username / password issue

You can apply your session model with a custom loadSession method

 loadSession: function(username,password, config) { config = Ext.apply({}, config); config = Ext.applyIf(config, { action: 'read', username: username, password: password }); var operation = new Ext.data.Operation(config), scope = config.scope || this, callback; callback = function(operation) { var record = null, success = operation.wasSuccessful(); if (success) { record = operation.getRecords()[0]; // If the server didn't set the id, do it here if (!record.hasId()) { record.setId(username); // take care to apply the write ID here!!! } Ext.callback(config.success, scope, [record, operation]); } else { Ext.callback(config.failure, scope, [record, operation]); } Ext.callback(config.callback, scope, [record, operation, success]); }; this.getProxy().read(operation, callback, this); } 

Now call this instead of loading.

+7
source share

I found it in the App Store Part 2 app architecture documentation

Use proxies for models:

This is usually a good practice, as it allows you to load and save instances of this model without having to store it. In addition, when several stores use the same model, you do not need to redefine proxies on each of them.

Use proxies for stores:

In Ext JS 4, several stores can use the same data model, even if stores will download their data from different sources. In our example, the station model will be used by search services and stations to store, as loading data from another place. One returns search results, the other returns favorite user stations. To do this, one of our stores will need to redefine the proxy server defined on the model.

+2
source share

All Articles