aboutsummaryrefslogtreecommitdiffstats
path: root/src/services.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/services.js')
-rw-r--r--src/services.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/services.js b/src/services.js
index 19375f39..41f179e9 100644
--- a/src/services.js
+++ b/src/services.js
@@ -392,3 +392,67 @@ angularService('$resource', function($xhr){
var resource = new ResourceFactory($xhr);
return bind(resource, resource.route);
}, {inject: ['$xhr.cache']});
+
+
+angularService('$cookies', function($browser) {
+ var cookies = {}, rootScope = this;
+ $browser.watchCookies(function(newCookies){
+ copy(newCookies, cookies);
+ rootScope.$eval();
+ });
+ this.$onEval(PRIORITY_FIRST, update);
+ this.$onEval(PRIORITY_LAST, update);
+ return cookies;
+
+ function update(){
+ var name, browserCookies = $browser.cookies();
+ for(name in cookies) {
+ if (browserCookies[name] !== cookies[name]) {
+ $browser.cookies(name, browserCookies[name] = cookies[name]);
+ }
+ }
+ for(name in browserCookies) {
+ if (browserCookies[name] !== cookies[name]) {
+ $browser.cookies(name, _undefined);
+ //TODO: write test for this delete
+ //delete cookies[name];
+ }
+ }
+ };
+}, {inject: ['$browser']});
+
+
+angularService('$sessionStore', function($store) {
+
+ function SessionStore() {}
+
+ SessionStore.prototype.get = function(key) {
+ return fromJson($store[key]);
+ };
+
+ SessionStore.prototype.getAll = function() {
+ var all = {},
+ key;
+
+ for (key in $store) {
+ if (!$store.hasOwnProperty(key)) continue;
+ all[key] = fromJson($store[key]);
+ }
+
+ return all;
+ };
+
+
+ SessionStore.prototype.put = function(key, value) {
+ $store[key] = toJson(value);
+ };
+
+
+ SessionStore.prototype.remove = function(key) {
+ delete $store[key];
+ };
+
+
+ return new SessionStore();
+
+}, {inject: ['$cookies']}); \ No newline at end of file