mwaylabs/The-M-Project — pull request #46 by pbetancor (2012-05-31 07:56:05+00:00)
Title: Extended model

Added a new data provider 'M.DataProviderRemoteStoragePaginated' for remote paginated filtered searchs.

Added a 'count' function to the model.

Example of M.DataProviderRemoteStoragePaginated:
Declaring the provider:
```javascript
M.MetroMixProvider = M.DataProviderRemoteStoragePaginated.configure({
'NotaCreditoDetail': {
url: '/metroMixServer/notasCredito',
read: {
url: {
all: function() {
return '';
},
paginated: function(firstResult, maxNumberResults, filter) {
return "/" + filter + "/amount/" + firstResult + "/" + maxNumberResults;
}
},

// mapeo necesario para devolver un objeto que pueda ser manejado por createRecord
map: function(obj) {

return {
fechaEmision: M.Date.create(obj.fechaEmision),
valor: obj.valor
};

}
},
count: {
url: {
all: function() {
return '/count';
},
filter: function(filter) {
return '/' + filter + '/count';
}
}
},
beforeSend : function(xhr) {
var config = M.Application.getConfig('authorization');
var encodedUserPass = M.Base64.encode(config.username + ':' + config.password);
xhr.setRequestHeader('Authorization', config.type + ' ' + encodedUserPass);
}
}
});
```
Using the provider:

```javascript
M.LoaderView.show(M.I18N.l('loading_list') + '...');
var obj = {
firstResult: 0,
maxNumberResults: 20,
filter: 'typeA',
onSuccess: function(model) {

var controller = MmxMobile.NotasCreditoDetailController;
controller.set('results', model);
M.LoaderView.hide();
},
onError: function(error) {
M.LoaderView.hide();
alert(M.I18N.l('connection_problem') + ": " + error.xhr.status + " (" + error.xhr.statusText + "). " + error.xhr.responseText);
}
};
MmxMobile.NotaCreditoDetail.find(obj); // a request is sent to: /metroMixServer/notasCredito/typeA/amount/0/20
```

Spanish wiki: https://github.com/avantic/The-M-Docs/wiki/DataProviderRemoteStorage

As soon as we can, we'll translate the wiki to english, and we'll add it to the 'GitHub' pages of The-M-Docs.