proxy.offline¶
webix.proxy.
offline
¶webix.proxy.offline helper.
Please look into the linked official documentation.
External references¶
Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | webix.proxy.offline = {
$proxy:true,
storage: webix.storage.local,
cache:false,
data:"",
_is_offline : function(){
if (!this.cache && !webix.env.offline){
webix.callEvent("onOfflineMode",[]);
webix.env.offline = true;
}
},
_is_online : function(){
if (!this.cache && webix.env.offline){
webix.env.offline = false;
webix.callEvent("onOnlineMode", []);
}
},
load:function(view, callback){
var mycallback = {
error:function(){
//assuming offline mode
var text = this.getCache() || this.data;
var loader = { responseText: text };
var data = webix.ajax.prototype._data(loader);
this._is_offline();
webix.ajax.$callback(view, callback, text, data, loader);
},
success:function(text, data, loader){
this._is_online();
webix.ajax.$callback(view, callback, text, data, loader);
this.setCache(text);
}
};
//in cache mode - always load data from cache
if (this.cache && this.getCache())
mycallback.error.call(this);
else {
//else try to load actual data first
if (this.source.$proxy)
this.source.load(this, mycallback);
else
webix.ajax(this.source, mycallback, this);
}
},
getCache:function(){
return this.storage.get(this._data_name());
},
clearCache:function(){
this.storage.remove(this._data_name());
},
setCache:function(text){
this.storage.put(this._data_name(), text);
},
_data_name:function(){
if (this.source.$proxy)
return this.source.source + "_$proxy$_data";
else
return this.source + "_$proxy$_data";
},
saveAll:function(view, update, dp, callback){
this.setCache(view.serialize());
webix.ajax.$callback(view, callback, "", update);
},
result:function(id, master, dp, text, data){
for (var i = 0; i < data.length; i++)
dp.processResult({ id: data[i].id, status: data[i].operation }, {}, {});
}
};
|