PageRenderTime 40ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): BSD-3-Clause, 0BSD, Apache-2.0, MIT, BSD-2-Clause, GPL-2.0, LGPL-2.0, JSON
  1. Vivi.module("Entities", function (Entities, App, Backbone, Marionette, $, _) {
  2. Entities.Collection = Backbone.Collection.extend({
  3. constructor: function () {
  4. // Check for store name which is required for local storage.
  5. if (!this.entityName) {
  6. throw "Entity collection has no 'entityName' which is required for local storage.";
  7. }
  8. Backbone.Collection.apply(this, arguments);
  9. },
  10. sync: function (method, model, options) {
  11. var localStorageEnabled = App.localStorageEnabled;
  12. if (method === "read") {
  13. if (localStorageEnabled) {
  14. var besoegArray = amplify.store(this.entityName) || [];
  15. options.success(besoegArray);
  16. //amplify.store(this.name, null); // Delete store
  17. } else {
  18. App.Services.Request(this.entityName)
  19. .done(function (result) {
  20. options.success(result);
  21. });
  22. }
  23. }
  24. },
  25. }
  26. );
  27. });