Posts Tagged ‘dataview’

Manipulating datastore data after loading

by on Wednesday, December 26th, 2012

var restaurantsStore = this.getStore();
var avg_rating;
restaurantsStore.clearFilter();
if ( restaurantsStore !== undefined )
{
restaurantsStore.load({
callback: function(records, operation, success) {
var proxy = restaurantsStore.getProxy(),
message = proxy.getReader().rawData.message;

if( success === false ){
Ext.Msg.alert('Operation Failed', message);
}
else{
var vendor = records[0].get('vendor');
Ext.getCmp('poweredByContainer').setVendor( vendor );

if( vendor === 'O' ){
for ( var index = 0; index < records.length; index++)
{
var phone = records[index].get('phone');
var recordR = restaurantsStore.getAt(index);
Ext.Ajax.request({
modelInstance: recordR,
url: 'restaurants/call_yelp_api/'+phone,
success: function(response, context){
var text = Ext.decode(response.responseText);
if( text.businesses[0] !== undefined )
avg_rating = text.businesses[0].avg_rating;
context.modelInstance.set('overall_rating', (avg_rating/5)*100);

},
failure: function(response){
var textF = response.responseText;
}
});

}
}

}
},
params: params,
scope: this
});