Created
November 18, 2015 07:36
-
-
Save jkdeveyra/5eb1c68a0a5bcfef76e1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Campaign Templates collection. | |
*/ | |
CampaignTemplates = new Meteor.Collection('campaign_templates'); | |
var CategorySchema = new SimpleSchema({ | |
"name": { type: String }, | |
"code": { type: String }, | |
"type": { type: String }, | |
"values": { type: [String] } | |
}); | |
var DriverSchema = new SimpleSchema({ | |
"name": { type: String }, | |
"code": { type: String }, | |
"categories": { type: [CategorySchema] } | |
}); | |
CampaignTemplatesSchema = new SimpleSchema({ | |
user_id: { | |
type: String, | |
index: true, | |
autoValue: function() { | |
return Meteor.userId(); | |
} | |
}, | |
company_id: { | |
type: String, | |
index: true | |
}, | |
campaign_id: { | |
type: String, | |
index: true | |
}, | |
title: { | |
type: String, | |
label: "Campaign Template", | |
index: true, | |
custom: function () { | |
if (this.isSet) { | |
if (Meteor.isServer && this.userId) { | |
if (!Meteor.call('isCampaignTemplateNameAvailable', this.value)) { | |
return 'notUnique'; | |
} | |
} | |
if (Meteor.isClient) { | |
Meteor.call('isCampaignTemplateNameAvailable', this.value, function (event, result) { | |
if (!result) { | |
CampaignTemplates.simpleSchema().namedContext().addInvalidKeys([{name: "title", type: "notUnique"}]); | |
} | |
}); | |
} | |
} | |
} | |
}, | |
overview: { | |
type: String, | |
label: "Overview", | |
optional: true | |
}, | |
approved: { | |
type: Boolean, | |
defaultValue: false | |
}, | |
startDate: { | |
type: Date, | |
label: "Start Date" | |
}, | |
endDate: { | |
type: Date, | |
label: "End Date" | |
}, | |
"values": { type: [DriverSchema] }, | |
"benchmarkValues": { type: Array, optional: true }, | |
"benchmarkValues.$": { type: Object }, | |
"benchmarkValues.$.category_id": { type: String }, | |
"benchmarkValues.$.benchmark_id": { type: String }, | |
"benchmarkValues.$.tag_id": { type: String }, | |
"benchmarkValues.$.value": { type: String }, | |
"benchmarkValues.$.affix": { type: String }, | |
"search_index": { | |
type: String, | |
index: true, | |
autoValue: function() { return ""; } | |
}, | |
createdAt: { | |
type: Date, | |
autoValue: function() { | |
if (this.isInsert) { | |
return new Date; | |
} else if (this.isUpsert) { | |
return {$setOnInsert: new Date}; | |
} else { | |
this.unset(); | |
} | |
} | |
}, | |
modifiedAt: { | |
type: Date, | |
autoValue: function() { | |
return new Date(); | |
} | |
} | |
}); | |
CampaignTemplates.attachSchema(CampaignTemplatesSchema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can we add tagName to benchmarkValues?. It will be use in campaign template preview.