HI all,
I am trying to build and odata hybrid offline based application using kapsel odata offline Plugin.
The below code is how I create an offline store and open store.
var properties = { "name": "EquipmentStoreOffline", "host": smphost, "port": smpport, "https": smphttps, "serviceRoot": appId, "streamParams": "custom_header=Authorization:" + authStr + ";", "definingRequests": { "eqheaderDR": definingrequests.EquipmentListDR } }; store_EQ = sap.OData.createOfflineStore(properties); store_EQ.onrequesterror = onRequestError; store_EQ.open(openStoreSuccessCallback_EQ, unRegisterErrorCallback);
//open store success for equipment header function openStoreSuccessCallback_EQ() { if (!store_EQ) { console.log("The store must be open before it can be refreshed"); Ext.Msg.alert("Offline Store does not contain data !!"); return; } if (navigator.onLine) { clearData(); store.refresh(read_EQ, unRegisterErrorCallback); flushStore(); } else { Ext.Msg.alert("You have gone Offline .Please verify your network connectivity."); sap.OData.applyHttpClient(); var readlocal = "yes"; read_EQ(readlocal); } }
function read_EQ(islocal) { var oHeaders = {}; oHeaders['Authorization'] = authStr; oHeaders['Content-Type'] = "application/atom+xml"; var serviceUri = basesmpUrl + "/EQUIPMENT_MASTER_SET/?" + "$format=xml"; console.log(serviceUri); if (islocal == "yes") { //displays entities that have been created or updated but have not yet been flushed. if (store_EQ && store_EQ.getRequestQueueStatus) { //filter is a new features in SP06 of the SDK. getRequestQueueStatus was added in the same SP. serviceUri = serviceUri + " and sap.islocal()"; } else { alert("Displaying changed records that have not yet been flushed requires the offline store to be open and is a new feature in SP06 of the SDK"); } } var eqstore = Ext.getStore("EquipmentStore"), localStore = Ext.getStore("EquipmentStoreOffline"), me = this; localStore.load(); eqstore.removeAll(); var request = { headers: oHeaders, requestUri: serviceUri, method: "GET" }; OData.read( request, function (data, response) { for (var i = 0; i < data.results.length; i++) { var rec = { Aufnr: data.results[i].Aufnr, Equnr: data.results[i].Equnr, BarcodeNo: data.results[i].BarcodeNo, Eqktx: data.results[i].Eqktx, Eqart: data.results[i].Eqart, Completion: data.results[i].Completion, Status: data.results[i].Status, Header: data.results[i].Header, Location: data.results[i].Location, SubLocation: data.results[i].SubLocation }; localStore.add(rec); localStore.sync(); } var record = localStore.filter('BarcodeNo', FilterEQ); Ext.getCmp("eqgridpanel").setStore(localStore); }, function (err) { console.log(err); } ); }
This is my code. I have a few questions on this.
1) I am not sure as of where to give flushstore() , clearstore() and closestore() as given in the example Getting Started with Kapsel - Part 15 -- Offline OData (New in SP05) Right now I have given in " if(navigator.isOnline) " function. is this the right way?
2) There is a read_EQ function being called on refreshing the store (the read function in the example from the above link). The check for (isLocal) is always called even if i dont pass any parameter in the read function(Passing parameter "yes" if offline to check if the queue is present.). When i gave alerts, it seems to be value "OK" and hence the url which has sap.islocal appended in it is throwing error 400. To prevent this, I have right now checked if the value is "yes", the one i am passing when offline and proceeded .Is this the correct way of calling the read function??
3) currently out of the 2 stores equipmentstore and equipment store offline, only one store is being used via this offline method. When online, i clear and reload this and when offline I read from it. Is there a need of 2 seperate stores for online and offline?
4) when should i use closestore and clearstore?
Almost all links i get online is based on Native development. I am using sencha touch with kapsel plugins for hybrid app development.
Kindly reply.