/OfflinePOC/Scripts/App/entities/base/collection.js
JavaScript | 38 lines | 25 code | 11 blank | 2 comment | 5 complexity | a6a31583d1fe18335fb1e678cc935a19 MD5 | raw file
Possible License(s): BSD-3-Clause, 0BSD, Apache-2.0, MIT, BSD-2-Clause, GPL-2.0, LGPL-2.0, JSON
- 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);
- });
- }
- }
- },
- }
- );
- });