Created
August 17, 2012 12:30
-
-
Save DimitarChristoff/3378472 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request.checkSomething = new Class({ | |
// override Request.JSON and overload results into storage. | |
Extends: Request.JSON, | |
Implements: Storage, | |
options: { | |
secure: true | |
}, | |
initialize: function(options) { | |
this.storageMethod = 'localStorage'; | |
this.setupStorage(); | |
this.parent(options); | |
}, | |
send: function(options) { | |
options = options || this.options; | |
// check if they are cached. if so, use them instead. | |
this.key = options.key; | |
var data = this.getItem(this.key); | |
if (data) { | |
// compat. | |
this.onSuccess(data, data); | |
this.fireEvent("retrieve", this.key, data); | |
return; | |
} | |
this.parent(options); | |
}, | |
success: function(text, xml){ | |
// override the success so we can store the result into storage. | |
var json; | |
try { | |
json = this.response.json = JSON.decode(text, this.options.secure); | |
} catch (error){ | |
this.fireEvent('error', [text, error]); | |
return; | |
} | |
if (json == null) | |
this.onFailure(); | |
else { | |
// store it. | |
this.setItem(this.key, json); | |
this.onSuccess(json, text); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment