Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for tracking categories but tracking options is not cur…
…rently working
- Loading branch information
Jordan Walsh
committed
Feb 23, 2017
1 parent
882fedf
commit 34ab49d
Showing
3 changed files
with
116 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,68 @@ | ||
var _ = require('lodash') | ||
, Entity = require('./entity') | ||
, logger = require('../logger') | ||
var _ = require('lodash'), | ||
Entity = require('./entity'), | ||
logger = require('../logger') | ||
|
||
var TrackingOptionSchema = new Entity.SchemaObject({ | ||
TrackingOptionID: {type: String}, | ||
Name: {type: String}, | ||
Status: {type: String} | ||
TrackingOptionID: { type: String, toObject: 'always' }, | ||
Name: { type: String, toObject: 'always' }, | ||
Status: { type: String, toObject: 'always' } | ||
}); | ||
|
||
var TrackingCategorySchema = new Entity.SchemaObject({ | ||
TrackingCategoryID: {type: String}, | ||
Name: {type: String}, | ||
Status: {type: String}, | ||
Options: {type: Array, arrayType: TrackingOptionSchema, toObject: 'always'} | ||
TrackingCategoryID: { type: String, toObject: 'always' }, | ||
Name: { type: String, toObject: 'always' }, | ||
Status: { type: String, toObject: 'always' }, | ||
Options: { type: Array, arrayType: TrackingOptionSchema, toObject: 'always' } | ||
}); | ||
|
||
|
||
var TrackingCategory = Entity.extend(TrackingCategorySchema, { | ||
constructor: function (application, data, options) | ||
{ | ||
constructor: function(application, data, options) { | ||
logger.debug('TrackingCategory::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function (data, options) | ||
{ | ||
}, | ||
changes: function (options) | ||
{ | ||
initialize: function(data, options) {}, | ||
changes: function(options) { | ||
return this._super(options); | ||
}, | ||
_toObject: function (options) | ||
{ | ||
_toObject: function(options) { | ||
return this._super(options); | ||
}, | ||
fromXmlObj: function (obj) | ||
{ | ||
fromXmlObj: function(obj) { | ||
var self = this; | ||
_.extend(self, _.omit(obj, 'Options')); | ||
if (obj.Options) { | ||
_.each(this.application.asArray(obj.Options.Option), function (option) | ||
{ | ||
_.each(this.application.asArray(obj.Options.Option), function(option) { | ||
self.Options.push(option); | ||
}) | ||
} | ||
|
||
return this; | ||
}, | ||
toXml: function () | ||
{ | ||
toXml: function() { | ||
var trackingCategory = _.omit(this.toObject(), 'Options'); | ||
_.extend(trackingCategory, { Options: []}); | ||
_.forEach(this.Options, function(option) | ||
{ | ||
trackingCategory.Options.push({ Option: option.toObject()}) | ||
_.extend(trackingCategory, { Options: [] }); | ||
_.forEach(this.Options, function(option) { | ||
trackingCategory.Options.push({ Option: option.toObject() }) | ||
}) | ||
|
||
return this.application.js2xml(trackingCategory, 'TrackingCategory'); | ||
}, | ||
save: function(options) { | ||
var self = this; | ||
var xml = '<TrackingCategories>' + this.toXml() + '</TrackingCategories>'; | ||
var path, method; | ||
if (this.TrackingCategoryID) { | ||
path = 'TrackingCategories/' + this.TrackingCategoryID; | ||
method = 'post' | ||
} else { | ||
path = 'TrackingCategories'; | ||
method = 'put' | ||
} | ||
return this.application.putOrPostEntity(method, path, xml, { entityPath: 'TrackingCategories.TrackingCategory', entityConstructor: function(data) { return self.application.core.trackingCategories.newTrackingCategory(data) } }); | ||
} | ||
}); | ||
|
||
|
||
module.exports = TrackingCategory; | ||
module.exports.TrackingCategorySchema = TrackingCategorySchema; | ||
module.exports.TrackingCategorySchema = TrackingCategorySchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,30 @@ | ||
var _ = require('lodash') | ||
, logger = require('../logger') | ||
, EntityHelper = require('./entity_helper') | ||
, TrackingCategory = require('../entities/trackingcategory') | ||
, p = require('../misc/promise') | ||
, util = require('util') | ||
var _ = require('lodash'), | ||
logger = require('../logger'), | ||
EntityHelper = require('./entity_helper'), | ||
TrackingCategory = require('../entities/trackingcategory'), | ||
p = require('../misc/promise'), | ||
util = require('util') | ||
|
||
var TrackingCategorys = EntityHelper.extend({ | ||
constructor: function (application, options) | ||
{ | ||
EntityHelper.call(this, application, _.extend({ entityName:'TrackingCategory', entityPlural:'TrackingCategories'}, options)); | ||
var TrackingCategories = EntityHelper.extend({ | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, _.extend({ entityName: 'TrackingCategory', entityPlural: 'TrackingCategories' }, options)); | ||
}, | ||
newTrackingCategory: function (data, options) | ||
{ | ||
newTrackingCategory: function(data, options) { | ||
return new TrackingCategory(this.application, data, options) | ||
}, | ||
getTrackingCategory: function (id, where, order, includeArchived) | ||
{ | ||
return this.getTrackingCategories({id: id, other: {includeArchived: includeArchived}, where: where, order: order}) | ||
.then(function (timesheets) | ||
{ | ||
return _.first(timesheets); | ||
getTrackingCategory: function(id, where, order, includeArchived) { | ||
return this.getTrackingCategories({ id: id, other: { includeArchived: includeArchived }, where: where, order: order }) | ||
.then(function(trackingCategories) { | ||
return _.first(trackingCategories); | ||
}) | ||
}, | ||
getTrackingCategories: function (options) | ||
{ | ||
getTrackingCategories: function(options) { | ||
var self = this; | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityConstructor = function(data) { return self.newTrackingCategory(data)}; | ||
return this.getEntities(clonedOptions) | ||
clonedOptions.entityPath = 'TrackingCategories.TrackingCategory'; | ||
clonedOptions.entityConstructor = function(data) { return self.newTrackingCategory(data) }; | ||
return this.getEntities(clonedOptions); | ||
} | ||
}) | ||
|
||
module.exports = TrackingCategorys; | ||
|
||
module.exports = TrackingCategories; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters