12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- /**
- * Created by robin on 12/12/16.
- */
-
- (function () {
- 'use strict';
-
- angular.module('appSdk')
- .factory('articlesDataAccess', ['luWebApiCrudDataAccess', 'luDataInitializer',
- function (luWebApiCrudDataAccess, luDataInitializer) {
-
- var DataAccess = luWebApiCrudDataAccess.create('/api/articles');
-
- DataAccess.defaultDbo = {
- id: null,
- title: null,
- type: null,
- text: null,
- pictureUrl: null,
- pictureCaption: null,
- fields: [],
- createdAt: null,
- updatedAt: null,
- _itemType: 'articles',
- toString: function () {
- return this.title == null ? this.id : this.title;
- }
- };
-
- DataAccess.defaultFieldDbo = {
- value: null,
- property: null,
- type: null
- };
-
- DataAccess.initFieldDbo = function (dbo, type) {
- if (dbo == null) {
- return null;
- }
- var dboInit = DataAccess.extendDeep({}, DataAccess.defaultFieldDbo, dbo);
- return dboInit;
- };
-
- DataAccess.initFieldModel = function (model, op) {
- if (model == null) {
- return null;
- }
- var modelInit = angular.copy(model);
- return modelInit;
- };
-
- DataAccess.articleFieldModelInitializer = luDataInitializer.create(DataAccess.initFieldModel);
-
- DataAccess.articleFieldDboInitializer = luDataInitializer.create(DataAccess.initFieldDbo);
-
- DataAccess.initDbo = function (dbo, type) {
- if (dbo == null) {
- return null;
- }
- var dboInit = DataAccess._initDbo(dbo);
- dboInit.fields = DataAccess.articleFieldDboInitializer.initListData(dboInit.fields, type);
- if (type == DataAccess.TYPE_MODEL)
- {
- dboInit.title = dboInit.id.replace(new RegExp('_', 'g'), ' ');
- }
- return dboInit;
- };
-
- DataAccess.initModel = function (model, op) {
- if (model == null) {
- return null;
- }
- var modelInit = DataAccess._initModel(model, op);
- modelInit.fields = DataAccess.articleFieldModelInitializer.initListData(modelInit.fields, op);
- modelInit.id = modelInit.title.replace(new RegExp(' ', 'g'), '_');
- delete modelInit.title;
- return modelInit;
- };
-
- return DataAccess;
- }]);
- })();
|