Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

articles.dataaccess.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.title == null ? this.id : this.title;
  23. }
  24. };
  25. DataAccess.defaultFieldDbo = {
  26. value: null,
  27. property: null,
  28. type: null
  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. if (type == DataAccess.TYPE_MODEL)
  53. {
  54. dboInit.title = dboInit.id.replace(new RegExp('_', 'g'), ' ');
  55. }
  56. return dboInit;
  57. };
  58. DataAccess.initModel = function (model, op) {
  59. if (model == null) {
  60. return null;
  61. }
  62. var modelInit = DataAccess._initModel(model, op);
  63. modelInit.fields = DataAccess.articleFieldModelInitializer.initListData(modelInit.fields, op);
  64. modelInit.id = modelInit.title.replace(new RegExp(' ', 'g'), '_');
  65. delete modelInit.title;
  66. return modelInit;
  67. };
  68. return DataAccess;
  69. }]);
  70. })();