/OfflinePOC/Scripts/App/entities/base/collection.js
https://gitlab.com/galtrold/offlinestorage · JavaScript · 38 lines · 25 code · 11 blank · 2 comment · 5 complexity · a6a31583d1fe18335fb1e678cc935a19 MD5 · raw file
- Vivi.module("Entities", function (Entities, App, Backbone, Marionette, $, _) {
- Entities.Collection = Backbone.Collection.extend({
- constructor: function () {
- // Check for store name which is required for local storage.
- if (!this.entityName) {
- throw "Entity collection has no 'entityName' which is required for local storage.";
- }
- Backbone.Collection.apply(this, arguments);
- },
- sync: function (method, model, options) {
- var localStorageEnabled = App.localStorageEnabled;
- if (method === "read") {
- if (localStorageEnabled) {
-
- var besoegArray = amplify.store(this.entityName) || [];
- options.success(besoegArray);
- //amplify.store(this.name, null); // Delete store
- } else {
- App.Services.Request(this.entityName)
- .done(function (result) {
- options.success(result);
- });
- }
- }
- },
- }
- );
- });