You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

articles.dataaccess.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Created by robin on 12/12/16.
  3. */
  4. (function () {
  5. 'use strict';
  6. angular.module('appSdk')
  7. .factory('articlesDataAccess', ['luWebApiCrudDataAccess', 'luDataInitializer',
  8. function (luWebApiCrudDataAccess, luDataInitializer) {
  9. var DataAccess = luWebApiCrudDataAccess.create('/api/articles');
  10. DataAccess.defaultDbo = {
  11. id: null,
  12. title: null,
  13. type: null,
  14. text: null,
  15. pictureUrl: null,
  16. pictureCaption: null,
  17. fields: [],
  18. createdAt: null,
  19. updatedAt: null,
  20. _itemType: 'articles',
  21. toString: function () {
  22. return this.id;
  23. }
  24. };
  25. DataAccess.defaultFieldDbo = {
  26. value: null,
  27. property: null,
  28. type: 20.0
  29. };
  30. DataAccess.initFieldDbo = function (dbo, type) {
  31. if (dbo == null) {
  32. return null;
  33. }
  34. var dboInit = DataAccess.extendDeep({}, DataAccess.defaultFieldDbo, dbo);
  35. return dboInit;
  36. };
  37. DataAccess.initFieldModel = function (model, op) {
  38. if (model == null) {
  39. return null;
  40. }
  41. var modelInit = angular.copy(model);
  42. return modelInit;
  43. };
  44. DataAccess.articleFieldModelInitializer = luDataInitializer.create(DataAccess.initFieldModel);
  45. DataAccess.articleFieldDboInitializer = luDataInitializer.create(DataAccess.initFieldDbo);
  46. DataAccess.initDbo = function (dbo, type) {
  47. if (dbo == null) {
  48. return null;
  49. }
  50. var dboInit = DataAccess._initDbo(dbo);
  51. dboInit.fields = DataAccess.articleFieldDboInitializer.initListData(dboInit.fields, type);
  52. dboInit.title = dboInit.id;
  53. return dboInit;
  54. };
  55. DataAccess.initModel = function (model, op) {
  56. if (model == null) {
  57. return null;
  58. }
  59. var modelInit = DataAccess._initModel(model, op);
  60. modelInit.fields = DataAccess.articleFieldModelInitializer.initListData(modelInit.fields, op);
  61. modelInit.id = modelInit.title;
  62. delete modelInit.title;
  63. return modelInit;
  64. };
  65. return DataAccess;
  66. }]);
  67. })();