PDA

View Full Version : json-p request into local storage



borden0108
26 Oct 2011, 5:39 PM
hi everyone,

i have tried multiple ways to try to first get my json file and then add it to localstorage. i was wondering if anyone knew i would do this. i have been working on this for 2 weeks and have search tirelessly for a solution.

Please DON'T refer me to the Taking Sencha Touch Apps Offline as i have tried this and have not got it to work.

Here is my json file



[{"DayNumber":1,"PeriodNumber":1,"PeriodNumberSeq":1,"DefinitionPeriodNumber":1,"DefinitionTimeFrom":"8:50:00 AM","DefinitionTimeTo":"9:45:00 AM","ClassCode":"10EWB2","ClassDescription":"Writing Workshop 1","StaffID":619597,"Room":"T22"},{"DayNumber":1,"PeriodNumber":3,"PeriodNumberSeq":1,"DefinitionPeriodNumber":3,"DefinitionTimeFrom":"10:55:00 AM","DefinitionTimeTo":"11:50:00 AM","ClassCode":"10CBP1","ClassDescription":"Programming ","StaffID":607388,"Room":"CY17"},{"DayNumber":1,"PeriodNumber":4,"PeriodNumberSeq":1,"DefinitionPeriodNumber":4,"DefinitionTimeFrom":"11:50:00 AM","DefinitionTimeTo":"12:40:00 PM","ClassCode":"10CWA1","ClassDescription":"Web Authoring","StaffID":607388,"Room":"CY34"},{"DayNumber":1,"PeriodNumber":5,"PeriodNumberSeq":1,"DefinitionPeriodNumber":5,"DefinitionTimeFrom":"1:30:00 PM","DefinitionTimeTo":"2:25:00 PM","ClassCode":"10M9B5","ClassDescription":"Mainstream Mathematics 2","StaffID":625461,"Room":"A4"},{"DayNumber":1,"PeriodNumber":6,"PeriodNumberSeq":1,"DefinitionPeriodNumber":6,"DefinitionTimeFrom":"2:25:00 PM","DefinitionTimeTo":"3:15:00 PM","ClassCode":"10APX4","ClassDescription":"Photography","StaffID":620143,"Room":"CY14"},{"DayNumber":2,"PeriodNumber":1,"PeriodNumberSeq":1,"DefinitionPeriodNumber":1,"DefinitionTimeFrom":"8:50:00 AM","DefinitionTimeTo":"9:45:00 AM","ClassCode":"10GHZ6","ClassDescription":"Hazard Geography","StaffID":608055,"Room":"S22"},{"DayNumber":2,"PeriodNumber":2,"PeriodNumberSeq":1,"DefinitionPeriodNumber":2,"DefinitionTimeFrom":"9:45:00 AM","DefinitionTimeTo":"10:35:00 AM","ClassCode":"10GHZ6","ClassDescription":"Hazard Geography","StaffID":608055,"Room":"S22"},{"DayNumber":2,"PeriodNumber":3,"PeriodNumberSeq":1,"DefinitionPeriodNumber":3,"DefinitionTimeFrom":"10:55:00 AM","DefinitionTimeTo":"11:50:00 AM","ClassCode":"10M9B5","ClassDescription":"Mainstream Mathematics 2","StaffID":625461,"Room":"A4"},{"DayNumber":2,"PeriodNumber":4,"PeriodNumberSeq":1,"DefinitionPeriodNumber":4,"DefinitionTimeFrom":"11:50:00 AM","DefinitionTimeTo":"12:40:00 PM","ClassCode":"10M9B5","ClassDescription":"Mainstream Mathematics 2","StaffID":625461,"Room":"A4"},{"DayNumber":2,"PeriodNumber":5,"PeriodNumberSeq":1,"DefinitionPeriodNumber":5,"DefinitionTimeFrom":"1:30:00 PM","DefinitionTimeTo":"2:25:00 PM","ClassCode":"10AMS2","ClassDescription":"Media Studies","StaffID":622915,"Room":"CY14"},{"DayNumber":2,"PeriodNumber":6,"PeriodNumberSeq":1,"DefinitionPeriodNumber":6,"DefinitionTimeFrom":"2:25:00 PM","DefinitionTimeTo":"3:15:00 PM","ClassCode":"10P9D6","ClassDescription":"Physical Development","StaffID":83,"Room":"G3"},{"DayNumber":3,"PeriodNumber":1,"PeriodNumberSeq":1,"DefinitionPeriodNumber":1,"DefinitionTimeFrom":"8:30:00 AM","DefinitionTimeTo":"9:25:00 AM","ClassCode":"10P9D6","ClassDescription":"Physical Development","StaffID":1455,"Room":"G3"},{"DayNumber":3,"PeriodNumber":2,"PeriodNumberSeq":1,"DefinitionPeriodNumber":2,"DefinitionTimeFrom":"9:25:00 AM","DefinitionTimeTo":"10:15:00 AM","ClassCode":"10EWB2","ClassDescription":"Writing Workshop 1","StaffID":619597,"Room":"T22"},{"DayNumber":3,"PeriodNumber":3,"PeriodNumberSeq":1,"DefinitionPeriodNumber":3,"DefinitionTimeFrom":"10:35:00 AM","DefinitionTimeTo":"11:30:00 AM","ClassCode":"10APX4","ClassDescription":"Photography","StaffID":620143,"Room":"CY14"},{"DayNumber":3,"PeriodNumber":4,"PeriodNumberSeq":1,"DefinitionPeriodNumber":4,"DefinitionTimeFrom":"11:30:00 AM","DefinitionTimeTo":"12:15:00 PM","ClassCode":"10CBP1","ClassDescription":"Programming ","StaffID":607388,"Room":"CY17"},{"DayNumber":3,"PeriodNumber":5,"PeriodNumberSeq":1,"DefinitionPeriodNumber":5,"DefinitionTimeFrom":"1:30:00 PM","DefinitionTimeTo":"2:25:00 PM","ClassCode":"10C9H1","ClassDescription":"Chapel","StaffID":1071,"Room":"C1"},{"DayNumber":3,"PeriodNumber":6,"PeriodNumberSeq":1,"DefinitionPeriodNumber":6,"DefinitionTimeFrom":"2:25:00 PM","DefinitionTimeTo":"3:15:00 PM","ClassCode":"10EWB2","ClassDescription":"Writing Workshop 1","StaffID":619597,"Room":"A3"},{"DayNumber":4,"PeriodNumber":1,"PeriodNumberSeq":1,"DefinitionPeriodNumber":1,"DefinitionTimeFrom":"8:50:00 AM","DefinitionTimeTo":"9:45:00 AM","ClassCode":"10QCS5","ClassDescription":"Literacy - Curriculum Support2","StaffID":601807,"Room":"A1"},{"DayNumber":4,"PeriodNumber":2,"PeriodNumberSeq":1,"DefinitionPeriodNumber":2,"DefinitionTimeFrom":"9:45:00 AM","DefinitionTimeTo":"10:35:00 AM","ClassCode":"10QCS5","ClassDescription":"Literacy - Curriculum Support2","StaffID":601807,"Room":"A1"},{"DayNumber":4,"PeriodNumber":3,"PeriodNumberSeq":1,"DefinitionPeriodNumber":3,"DefinitionTimeFrom":"10:55:00 AM","DefinitionTimeTo":"11:50:00 AM","ClassCode":"10AMS2","ClassDescription":"Media Studies","StaffID":622915,"Room":"CY14"},{"DayNumber":4,"PeriodNumber":4,"PeriodNumberSeq":1,"DefinitionPeriodNumber":4,"DefinitionTimeFrom":"11:50:00 AM","DefinitionTimeTo":"12:40:00 PM","ClassCode":"10AMS2","ClassDescription":"Media Studies","StaffID":622915,"Room":"CY14"},{"DayNumber":4,"PeriodNumber":6,"PeriodNumberSeq":1,"DefinitionPeriodNumber":6,"DefinitionTimeFrom":"2:25:00 PM","DefinitionTimeTo":"3:15:00 PM","ClassCode":"10M9B5","ClassDescription":"Mainstream Mathematics 2","StaffID":625461,"Room":"A4"},{"DayNumber":5,"PeriodNumber":1,"PeriodNumberSeq":1,"DefinitionPeriodNumber":1,"DefinitionTimeFrom":"8:50:00 AM","DefinitionTimeTo":"9:45:00 AM","ClassCode":"10M9B5","ClassDescription":"Mainstream Mathematics 2","StaffID":625461,"Room":"A4"},{"DayNumber":5,"PeriodNumber":2,"PeriodNumberSeq":1,"DefinitionPeriodNumber":2,"DefinitionTimeFrom":"9:45:00 AM","DefinitionTimeTo":"10:35:00 AM","ClassCode":"10CWA1","ClassDescription":"Web Authoring","StaffID":607388,"Room":"CY34"},{"DayNumber":5,"PeriodNumber":4,"PeriodNumberSeq":1,"DefinitionPeriodNumber":4,"DefinitionTimeFrom":"11:50:00 AM","DefinitionTimeTo":"12:40:00 PM","ClassCode":"10GHZ6","ClassDescription":"Hazard Geography","StaffID":608055,"Room":"S22"},{"DayNumber":5,"PeriodNumber":5,"PeriodNumberSeq":1,"DefinitionPeriodNumber":5,"DefinitionTimeFrom":"1:30:00 PM","DefinitionTimeTo":"2:25:00 PM","ClassCode":"10EWB2","ClassDescription":"Writing Workshop 1","StaffID":619597,"Room":"T22"},{"DayNumber":5,"PeriodNumber":6,"PeriodNumberSeq":1,"DefinitionPeriodNumber":6,"DefinitionTimeFrom":"2:25:00 PM","DefinitionTimeTo":"3:15:00 PM","ClassCode":"10QCS5","ClassDescription":"Literacy - Curriculum Support2","StaffID":601807,"Room":"A1"},{"DayNumber":6,"PeriodNumber":1,"PeriodNumberSeq":1,"DefinitionPeriodNumber":1,"DefinitionTimeFrom":"8:50:00 AM","DefinitionTimeTo":"9:45:00 AM","ClassCode":"10M9B5","ClassDescription":"Mainstream Mathematics 2","StaffID":625461,"Room":"A4"},{"DayNumber":6,"PeriodNumber":2,"PeriodNumberSeq":1,"DefinitionPeriodNumber":2,"DefinitionTimeFrom":"9:45:00 AM","DefinitionTimeTo":"10:35:00 AM","ClassCode":"10CBP1","ClassDescription":"Programming ","StaffID":607388,"Room":"CY17"},{"DayNumber":6,"PeriodNumber":3,"PeriodNumberSeq":1,"DefinitionPeriodNumber":3,"DefinitionTimeFrom":"10:55:00 AM","DefinitionTimeTo":"11:50:00 AM","ClassCode":"10C9H1","ClassDescription":"Chapel","StaffID":1071,"Room":"C1"},{"DayNumber":6,"PeriodNumber":4,"PeriodNumberSeq":1,"DefinitionPeriodNumber":4,"DefinitionTimeFrom":"11:50:00 AM","DefinitionTimeTo":"12:40:00 PM","ClassCode":"10CWA1","ClassDescription":"Web Authoring","StaffID":607388,"Room":"CY34"},{"DayNumber":6,"PeriodNumber":5,"PeriodNumberSeq":1,"DefinitionPeriodNumber":5,"DefinitionTimeFrom":"1:30:00 PM","DefinitionTimeTo":"2:25:00 PM","ClassCode":"10APX4","ClassDescription":"Photography","StaffID":620143,"Room":"CY14"},{"DayNumber":6,"PeriodNumber":6,"PeriodNumberSeq":1,"DefinitionPeriodNumber":6,"DefinitionTimeFrom":"2:25:00 PM","DefinitionTimeTo":"3:15:00 PM","ClassCode":"10EWB2","ClassDescription":"Writing Workshop 1","StaffID":619597,"Room":"T22"},{"DayNumber":7,"PeriodNumber":3,"PeriodNumberSeq":1,"DefinitionPeriodNumber":3,"DefinitionTimeFrom":"10:55:00 AM","DefinitionTimeTo":"11:50:00 AM","ClassCode":"10CWA1","ClassDescription":"Web Authoring","StaffID":607388,"Room":"CY34"},{"DayNumber":7,"PeriodNumber":4,"PeriodNumberSeq":1,"DefinitionPeriodNumber":4,"DefinitionTimeFrom":"11:50:00 AM","DefinitionTimeTo":"12:40:00 PM","ClassCode":"10CWA1","ClassDescription":"Web Authoring","StaffID":607388,"Room":"CY34"},{"DayNumber":7,"PeriodNumber":5,"PeriodNumberSeq":1,"DefinitionPeriodNumber":5,"DefinitionTimeFrom":"1:30:00 PM","DefinitionTimeTo":"2:25:00 PM","ClassCode":"10P9D6","ClassDescription":"Physical Development","StaffID":1455,"Room":"G3"},{"DayNumber":7,"PeriodNumber":6,"PeriodNumberSeq":1,"DefinitionPeriodNumber":6,"DefinitionTimeFrom":"2:25:00 PM","DefinitionTimeTo":"3:15:00 PM","ClassCode":"10GHZ6","ClassDescription":"Hazard Geography","StaffID":608055,"Room":"S22"},{"DayNumber":8,"PeriodNumber":1,"PeriodNumberSeq":1,"DefinitionPeriodNumber":1,"DefinitionTimeFrom":"8:30:00 AM","DefinitionTimeTo":"9:25:00 AM","ClassCode":"10M9B5","ClassDescription":"Mainstream Mathematics 2","StaffID":625461,"Room":"S21"},{"DayNumber":8,"PeriodNumber":2,"PeriodNumberSeq":1,"DefinitionPeriodNumber":2,"DefinitionTimeFrom":"9:25:00 AM","DefinitionTimeTo":"10:15:00 AM","ClassCode":"10M9B5","ClassDescription":"Mainstream Mathematics 2","StaffID":625461,"Room":"S21"},{"DayNumber":8,"PeriodNumber":3,"PeriodNumberSeq":1,"DefinitionPeriodNumber":3,"DefinitionTimeFrom":"10:35:00 AM","DefinitionTimeTo":"11:30:00 AM","ClassCode":"10APX4","ClassDescription":"Photography","StaffID":620143,"Room":"CY14"},{"DayNumber":8,"PeriodNumber":4,"PeriodNumberSeq":1,"DefinitionPeriodNumber":4,"DefinitionTimeFrom":"11:30:00 AM","DefinitionTimeTo":"12:15:00 PM","ClassCode":"10APX4","ClassDescription":"Photography","StaffID":620143,"Room":"CY14"},{"DayNumber":8,"PeriodNumber":5,"PeriodNumberSeq":1,"DefinitionPeriodNumber":5,"DefinitionTimeFrom":"1:30:00 PM","DefinitionTimeTo":"2:25:00 PM","ClassCode":"10QCS5","ClassDescription":"Literacy - Curriculum Support2","StaffID":601807,"Room":"A1"},{"DayNumber":8,"PeriodNumber":6,"PeriodNumberSeq":1,"DefinitionPeriodNumber":6,"DefinitionTimeFrom":"2:25:00 PM","DefinitionTimeTo":"3:15:00 PM","ClassCode":"10AMS2","ClassDescription":"Media Studies","StaffID":622915,"Room":"CY14"},{"DayNumber":9,"PeriodNumber":1,"PeriodNumberSeq":1,"DefinitionPeriodNumber":1,"DefinitionTimeFrom":"8:50:00 AM","DefinitionTimeTo":"9:45:00 AM","ClassCode":"10P9D6","ClassDescription":"Physical Development","StaffID":83,"Room":"G3"},{"DayNumber":9,"PeriodNumber":2,"PeriodNumberSeq":1,"DefinitionPeriodNumber":2,"DefinitionTimeFrom":"9:45:00 AM","DefinitionTimeTo":"10:35:00 AM","ClassCode":"10EWB2","ClassDescription":"Writing Workshop 1","StaffID":619597,"Room":"T22"},{"DayNumber":9,"PeriodNumber":3,"PeriodNumberSeq":1,"DefinitionPeriodNumber":3,"DefinitionTimeFrom":"10:55:00 AM","DefinitionTimeTo":"11:50:00 AM","ClassCode":"10CBP1","ClassDescription":"Programming ","StaffID":607388,"Room":"CY17"},{"DayNumber":9,"PeriodNumber":4,"PeriodNumberSeq":1,"DefinitionPeriodNumber":4,"DefinitionTimeFrom":"11:50:00 AM","DefinitionTimeTo":"12:40:00 PM","ClassCode":"10CBP1","ClassDescription":"Programming ","StaffID":607388,"Room":"CY17"},{"DayNumber":9,"PeriodNumber":5,"PeriodNumberSeq":1,"DefinitionPeriodNumber":5,"DefinitionTimeFrom":"1:30:00 PM","DefinitionTimeTo":"2:25:00 PM","ClassCode":"10M9B5","ClassDescription":"Mainstream Mathematics 2","StaffID":625461,"Room":"A4"},{"DayNumber":9,"PeriodNumber":6,"PeriodNumberSeq":1,"DefinitionPeriodNumber":6,"DefinitionTimeFrom":"2:25:00 PM","DefinitionTimeTo":"3:15:00 PM","ClassCode":"10EWB2","ClassDescription":"Writing Workshop 1","StaffID":619597,"Room":"S23"},{"DayNumber":10,"PeriodNumber":1,"PeriodNumberSeq":1,"DefinitionPeriodNumber":1,"DefinitionTimeFrom":"8:50:00 AM","DefinitionTimeTo":"9:45:00 AM","ClassCode":"10GHZ6","ClassDescription":"Hazard Geography","StaffID":608055,"Room":"S22"},{"DayNumber":10,"PeriodNumber":2,"PeriodNumberSeq":1,"DefinitionPeriodNumber":2,"DefinitionTimeFrom":"9:45:00 AM","DefinitionTimeTo":"10:35:00 AM","ClassCode":"10F9M1","ClassDescription":"Form Period","StaffID":615792,"Room":"T11"},{"DayNumber":10,"PeriodNumber":3,"PeriodNumberSeq":1,"DefinitionPeriodNumber":3,"DefinitionTimeFrom":"10:55:00 AM","DefinitionTimeTo":"11:50:00 AM","ClassCode":"10M9B5","ClassDescription":"Mainstream Mathematics 2","StaffID":625461,"Room":"A4"},{"DayNumber":10,"PeriodNumber":4,"PeriodNumberSeq":1,"DefinitionPeriodNumber":4,"DefinitionTimeFrom":"11:50:00 AM","DefinitionTimeTo":"12:40:00 PM","ClassCode":"10AMS2","ClassDescription":"Media Studies","StaffID":622915,"Room":"CY14"},{"DayNumber":10,"PeriodNumber":5,"PeriodNumberSeq":1,"DefinitionPeriodNumber":5,"DefinitionTimeFrom":"1:30:00 PM","DefinitionTimeTo":"2:25:00 PM","ClassCode":"10QCS5","ClassDescription":"Literacy - Curriculum Support2","StaffID":601807,"Room":"A1"},{"DayNumber":10,"PeriodNumber":6,"PeriodNumberSeq":1,"DefinitionPeriodNumber":6,"DefinitionTimeFrom":"2:25:00 PM","DefinitionTimeTo":"3:15:00 PM","ClassCode":"10EWB2","ClassDescription":"Writing Workshop 1","StaffID":619597,"Room":"T22"}]




and here is my attempt at it






Ext.setup({
// When the program has rendered the above code it will now start the code below.
onReady: function() {

Ext.define("timetable", {extend: "Ext.data.Model", fields: [
{name: 'DayNumber', type: 'string'},
{name: 'PeriodNumber', type: 'string'},
{name: 'PeriodNumberSeq', type: 'string'},
{name: 'DefinitionPeriodNumber', type: 'string'},
{name: 'DefinitionTimeFrom', type: 'string'},
{name: 'DefinitionTimeTo', type: 'string'},
{name: 'ClassCode', type: 'string'},
{name: 'ClassDescription', type: 'string'},
{name: 'StaffID', type: 'string'},
{name: 'Room', type: 'string'},
],
proxy: {
type: 'localstorage',
id: 'modelproxy',
}
});


var calculateDesiredWidth = function() {
var viewWidth = Ext.Element.getViewportWidth(),
desiredWidth = Math.min(viewWidth, 400) - 10;
return desiredWidth;
};




authform = Ext.create(Ext.form.FormPanel,{
id: 'infomation',
layout: 'fit',
method:'post',
centered:true,
url:'https://intranet.trinity.vic.edu.au/CookieAuth.dll?Logon',
width: 400,
standardSubmit : true,
scroll:'vertical',
floating: true,
modal: true,
height:300,
items:[{
xtype: 'fieldset',
width: calculateDesiredWidth,
title: 'Login',
instructions: 'Please complete the information.',
items: [{
name: 'username',
label: 'username',
xtype: 'textfield',
cls:'form-height',
},{
name: 'password',
label: 'password',
xtype: 'passwordfield',
cls:'form-height',
},{
xtype: 'hiddenfield',
name:'curl',
value:'Z2Fdefault.asp',
}],
}],
dockedItems: [{
dock: 'top',
xtype: 'toolbar',
title: 'Intranet Login'
},{
dock: 'bottom',
xtype: 'toolbar',
items: [{
text: 'Cancel',
handler: function() {
authform.hide();
}
},{
xtype: 'spacer'
},{
text: 'Submit',
ui:'confirm',
handler: function() {
authform.submit ({
waitMsg:'Submitting',
success: function(e) {
authform.hide();
window.stop();
}


});
},
}],
}]
});




var editBtn = Ext.create(Ext.Button,{
text: 'Settings',
handler: function() {
authform.show();
}
});
var spinner = Ext.create(Ext.form.Spinner,{
minValue: 0,
maxValue: 100,
incrementValue: 2,
cycle: true
});


var spinnerBtn = Ext.create(Ext.Button,{
text: 'Select Day',
handler: function() {
spinner.show();
}
});
var onlineStore = Ext.create(Ext.data.Store,{
model: 'timetable',
method:'GET',
autoLoad: true,
proxy: {
type: 'jsonp',
url : 'https://intranet.trinity.vic.edu.au/timetable/getTimetable.asp',
extraParams: {
synID:300068,
room:0,
year:YearNumber(),
term:TermNumber(),
day:DayNumber(),
callType:'student'
},
reader: {
type: 'json',
root: 'items'
},
exception: function(data) {
data = data.result;
console.log(data);
}
}
});





/*var offlineStore = Ext.create(Ext.data.Store,{
autoLoad:false,
model: 'timetable',
proxy: {
type: 'localstorage',
id: 'helloworld'
}
});
var onlineStore = Ext.create(Ext.data.Store,{
model: 'timetable',
method:'GET',
autoLoad: true,
proxy: {
type: 'jsonp',
url : 'https://intranet.trinity.vic.edu.au/timetable/getTimetable.asp',
extraParams: {
synID:300068,
room:0,
year:YearNumber(),
term:TermNumber(),
day:DayNumber(),
callType:'student'
},
exception: function(data) {
data = data.result;
}
}
});


var onlineStore = Ext.create(Ext.data.Store,{
model: 'timetable',
method:'GET',
autoLoad: true,
});
var jsonreq = Ext.util.JSONP.request({
url: 'http://tgs3865/cbp/300068/json/jsonfile.json',
callbackKey: 'callback',
params: {
synID:300068,
room:0,
year:YearNumber(),
term:TermNumber(),
day:DayNumber(),
callType:'student'
},
reader: {
type: 'json',
root: 'items'
},
callback: function(data) {
data = data.result;
}
});
*/
var list = Ext.create('Ext.List', {
store:onlineStore,
model:'timetable',
itemSelector:'list',
itemTpl: '<tpl>'+'Period {ClassDescription}: {ClassCode}' + '<div id="room">{Room}</div>' + '</tpl>' ,
});

Ext.create('Ext.Panel', {
fullscreen: true,
title:'Timetable',
dockedItems:[
{
xtype: 'toolbar',
docked: 'top',
scrollable: {
direction: 'horizontal',
indicators: false
},
items: [
{ ui: 'round', text: 'Load' },
{ xtype: 'spacer' }
]
}
],
layout: {
type: 'fit',
align: 'stretch'
},
defaults: {
flex: 1
},
items:
[list]
});
},
});

mitchellsimoens
29 Oct 2011, 6:30 AM
Looks like you are trying to assign a proxy in both your Model and your Store. You cannot do this.