PDA

View Full Version : Defining a custom proxy with MVC architecture



quaidbrown
10 Jan 2012, 1:54 PM
The problem seems to be with using type: 'myajax' in my store. Is my syntax correct here?
I get a typerror cannot call method substring of undefined...

I started this thread before but now I have a new problem:
http://www.sencha.com/forum/showthread.php?173179-Proxy-as-its-own-class-doesn-t-work-with-api-property

/app/controller/AppointmentController.js

Ext.define('AM.controller.AppointmentController', {
extend: 'Ext.app.Controller',
stores: ['AppointmentStore'],
models: ['AppointmentModel'],
views: [
'appointment.AppointmentListView',
'appointment.AppointmentEditView'
],

init: function(){
console.log('Entering Appointment Controller init');
this.control({
'appointmentlistview' : {
itemdblclick: this.editAppointment
},
'appointmenteditview button[action=save]': {
click: this.updateAppointment
}
});



console.log('Leaving Appointment Controller init');
},
editAppointment: function(grid, record){
console.log('Double clicked on ' + record.get('PatientName'));
var view = Ext.widget('appointmenteditview');
view.down('form').loadRecord(record);
},
updateAppointment: function(button){
var win = button.up('window');
var form = win.down('form');
var record = form.getRecord();
var values = form.getValues();

record.set(values);
win.close();
this.getAppointmentStoreStore().sync();
}


});



app/model/AppointmentModel.js

Ext.define('AM.model.AppointmentModel', {
extend: 'Ext.data.Model',
fields: ['Id', 'PatientName', 'Start', 'End']
});


app/proxy/AppointmentAjaxRemoteProxy.js

Ext.define('AM.proxy.AppointmentAjaxRemoteProxy',{
extend: 'Ext.data.proxy.Ajax',
alias : 'proxy.myajax',

api: {
create : '/SchedulingService/Appointment/SetAppointment/SetAppointment',
read : '/SchedulingService/Appointment/Appointments',
update : '/SchedulingService/Appointment/SetAppointment/SetAppointment',
destroy : '/SchedulingService/Appointment/SetAppointment/SetAppointment'
},
reader: {
type: 'json',
root: 'GetAppointmentsResult',
successProperty: 'success'
}
});

app/store/AppointmentStore.js:

Ext.define('AM.store.AppointmentStore',{
extend: 'Ext.data.Store',
model: 'AM.model.AppointmentModel',
autoLoad: true,

proxy:{
type: 'myajax'
}
//Ext.create('AM.proxy.AppointmentAjaxRemoteProxy')

});

quaidbrown
11 Jan 2012, 7:35 AM
I fixed the substring error with:

requires : ['AM.proxy.AppointmentAjaxRemoteProxy'] in the AppointmentStore.

However, the api{} block isn't used. I think this might be a bug. Has anybody tried this?