PDA

View Full Version : Editing Items in a datastore.



Devon_Britton
24 Jul 2012, 3:23 AM
Hi everyone.

I'm trying to take a record pulled form a nested JSON document, edit it and then save the changes back to my ravenDB store.

So I've managed to pull all the data that I need and iterate through each record to change the status.

The problem is that I'm getting the following error when I try sync to update the store.:
Uncaught Error: [ERROR][Ext.data.proxy.Server#create] JsonP proxies can only be used to read data.

Here's the code for the "Save" button controller. The Store, Model and Proxy Code is below that, along with the JSON document.

Your help is greatly appreciated!!!


var me = this, list = me.getPackageList(), store = me.getDataList().getStore(), details = me.getDetails();

var customer = details.getData();
var cId = customer.ID;
var i = store.findExact('ID', cId);
var packages = store.getAt(i).get('Packages');
for (var a = 0; a < packages.length; a++) {
id = packages[a].ID;
var select = Ext.get('option'+id).dom;
if (select) {
for (var j = 0; j < select.options.length; j++) {
if (select.options[j].selected) {
packages[a].set('Status', select.options[j].value);
}
}
}
}
store.sync();


Model:


Ext.define('Deliveries.model.Shipment', {
extend: 'Ext.data.Model',
uses: [
'Deliveries.model.Package'
],
config: {
fields: [
{
name: 'ID',
type: 'int'
},
{
name: 'Name',
type: 'string'
},
{
name: 'Telephone',
type: 'string'
},
{
name: 'Address',
type: 'string'
},
{
name: 'Suburb',
type: 'string'
},
{
name: 'City',
type: 'string'
},
{
name: 'Province',
type: 'string'
},
{
name: 'Country',
type: 'string'
},
{
name: 'PostalCode',
type: 'string'
},
{
name: 'DeliveryStatus',
type: 'string'
},
{
name: 'Packages',
type: 'auto'
}
],
hasMany: {
associationKey: 'Packages',
model: 'Deliveries.model.Package'
}
}
});

Store:


Ext.define('Deliveries.store.RavenDBStore', {
extend: 'Ext.data.Store',
alias: 'store.ravendb',
requires: [
'Deliveries.model.Shipment'
],


config: {
autoLoad: true,
model: 'Deliveries.model.Shipment',
storeId: 'RavenDBStore',
proxy: {
type: 'jsonp',
url: 'http://localhost:8080/databases/Shipping/docs',
callbackKey: 'jsonp',
reader: {
type: 'json',
rootProperty: 'Shipments'
}
}
}
});


JSON:

{
"ID": 3,
"Name": "Sarah Carlson",
"Telephone": "(011) 123 4567",
"Address": "1 Test ave",
"Suburb": "Test",
"City": "Testville",
"Province": "Gauteng",
"Country": "South Africa",
"PostalCode": "0001",
"DeliveryStatus": "Pending",
"Packages": [
{
"ID": 1,
"Name": "Package 1",
"Status": "Pending"
},
{
"ID": 2,
"Name": "Package 2",
"Status": "Pending"
}
]
}

fousheezy
24 Jul 2012, 6:38 AM
Is there a need for you to use the jsonp proxy rather than json? You can pull data via jsonp from another domain, but I haven't seen an attempt to write data back. You might try defining the 'writer' configuration in the jsonp proxy and tweaking some settings in there to make it write back your updates.

http://docs.sencha.com/touch/2-0/#!/api/Ext.data.writer.Writer

Devon_Britton
25 Jul 2012, 2:04 AM
I have tried doing this with an AJAX proxy but unfortunately that gives me the following errors:

Failed to load resource: the server responded with a status of 401 (Unauthorized) http://10.0.0.3:8080/databases/Shipping/docs?_dc=1343210580700&page=1&start=0&limit=25
XMLHttpRequest cannot load http://10.0.0.3:8080/databases/Shipping/docs?_dc=1343210580700&page=1&start=0&limit=25. Origin http://localhost (http://localhost/) is not allowed by Access-Control-Allow-Origin.

How is it that one proxy won't allow you to write data and another won't allow you to read data??

It seems needlessly complicated to me.