@dhyasama/totem-models 6.11.7 → 6.11.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Deal.js +6 -6
- package/lib/Organization.js +197 -17
- package/package.json +1 -1
package/lib/Deal.js
CHANGED
|
@@ -148,8 +148,8 @@ module.exports = function(mongoose, config) {
|
|
|
148
148
|
})
|
|
149
149
|
.populate('organization', 'name logoUrl website websiteAliases')
|
|
150
150
|
.populate('messages')
|
|
151
|
-
.populate('
|
|
152
|
-
.populate('
|
|
151
|
+
.populate('source.person', 'name avatarUrl title')
|
|
152
|
+
.populate('referrer.person', 'name avatarUrl title')
|
|
153
153
|
.populate({
|
|
154
154
|
path: 'documents',
|
|
155
155
|
match: { customer: config.CUSTOMER_ID }
|
|
@@ -177,8 +177,8 @@ module.exports = function(mongoose, config) {
|
|
|
177
177
|
.find(terms)
|
|
178
178
|
.populate('organization', 'name description logoUrl website websiteAliases chairs')
|
|
179
179
|
.populate('messages')
|
|
180
|
-
.populate('
|
|
181
|
-
.populate('
|
|
180
|
+
.populate('source.person', 'name avatarUrl title')
|
|
181
|
+
.populate('referrer.person', 'name avatarUrl title')
|
|
182
182
|
.populate({
|
|
183
183
|
path: 'documents',
|
|
184
184
|
match: { customer: customerId }
|
|
@@ -224,8 +224,8 @@ module.exports = function(mongoose, config) {
|
|
|
224
224
|
})
|
|
225
225
|
.populate('organization', 'name logoUrl website websiteAliases')
|
|
226
226
|
.populate('messages')
|
|
227
|
-
.populate('
|
|
228
|
-
.populate('
|
|
227
|
+
.populate('source.person', 'name avatarUrl title')
|
|
228
|
+
.populate('referrer.person', 'name avatarUrl title')
|
|
229
229
|
.populate({
|
|
230
230
|
path: 'documents',
|
|
231
231
|
match: { customer: config.CUSTOMER_ID }
|
package/lib/Organization.js
CHANGED
|
@@ -206,14 +206,69 @@ module.exports = function(mongoose, config) {
|
|
|
206
206
|
|
|
207
207
|
active: { type: Boolean, default: false },
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
statuses: [{
|
|
210
210
|
name: { type: String, trim: true },
|
|
211
211
|
order: { type: Number },
|
|
212
212
|
active: { type: Boolean, default: true },
|
|
213
213
|
color: { type: String, trim: true }
|
|
214
214
|
}],
|
|
215
215
|
|
|
216
|
-
|
|
216
|
+
standardFields: {
|
|
217
|
+
|
|
218
|
+
// Standard fields are always "on" in the system
|
|
219
|
+
// They can be configured in how they work on the deal list page
|
|
220
|
+
// order for standard fields only sets the order on the list page. their position is fixed on the org page deal section and edit form.
|
|
221
|
+
// order is co-mingled with order for custom fields
|
|
222
|
+
// colspan is for the number of columns the field should take up on the list page
|
|
223
|
+
// showOnFilter controls whether values are extracted and used in filtering options on list page
|
|
224
|
+
// showOnList controls if the field will be on deal list page
|
|
225
|
+
|
|
226
|
+
action: {
|
|
227
|
+
order: { type: Number, default: 99 },
|
|
228
|
+
colspan: { type: Number, default: 1 },
|
|
229
|
+
showOnFilter: { type: Boolean, default: true },
|
|
230
|
+
showOnList: { type: Boolean, default: true }
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
raise: {
|
|
234
|
+
order: { type: Number, default: 99 },
|
|
235
|
+
colspan: { type: Number, default: 1 },
|
|
236
|
+
showOnFilter: { type: Boolean, default: true },
|
|
237
|
+
showOnList: { type: Boolean, default: true }
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
valuation: {
|
|
241
|
+
order: { type: Number, default: 99 },
|
|
242
|
+
colspan: { type: Number, default: 1 },
|
|
243
|
+
showOnFilter: { type: Boolean, default: true },
|
|
244
|
+
showOnList: { type: Boolean, default: true }
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
sources: {
|
|
248
|
+
types: [ { type: String, trim: true } ],
|
|
249
|
+
order: { type: Number, default: 99 },
|
|
250
|
+
colspan: { type: Number, default: 1 },
|
|
251
|
+
showOnFilter: { type: Boolean, default: true },
|
|
252
|
+
showOnList: { type: Boolean, default: true }
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
referrers: {
|
|
256
|
+
order: { type: Number, default: 99 },
|
|
257
|
+
colspan: { type: Number, default: 1 },
|
|
258
|
+
showOnFilter: { type: Boolean, default: true },
|
|
259
|
+
showOnList: { type: Boolean, default: true }
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
chairs: {
|
|
263
|
+
order: { type: Number, default: 99 },
|
|
264
|
+
colspan: { type: Number, default: 1 },
|
|
265
|
+
showOnFilter: { type: Boolean, default: true },
|
|
266
|
+
showOnList: { type: Boolean, default: true }
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
customFields: [{
|
|
217
272
|
|
|
218
273
|
// Data stored on deals will be accessed with this key
|
|
219
274
|
// It must follow standard js variable naming rules
|
|
@@ -222,9 +277,6 @@ module.exports = function(mongoose, config) {
|
|
|
222
277
|
// Changing it after data is in the system will make data on deal inaccessible
|
|
223
278
|
key: { type: String, trim: true },
|
|
224
279
|
|
|
225
|
-
// this sets whether the field is a custom field
|
|
226
|
-
isStandard: false,
|
|
227
|
-
|
|
228
280
|
// User friendly text, will be displayed
|
|
229
281
|
label: { type: String, trim: true },
|
|
230
282
|
|
|
@@ -256,12 +308,13 @@ module.exports = function(mongoose, config) {
|
|
|
256
308
|
// colspan is for the number of columns the field should take up on the list page
|
|
257
309
|
colspan: { type: Number, default: 1 },
|
|
258
310
|
|
|
259
|
-
// showOnList controls if the field will be on deal list page
|
|
260
|
-
showOnList: { type: Boolean, default: true },
|
|
261
|
-
|
|
262
311
|
// showOnFilter controls whether values are extracted and used in filtering options on list page
|
|
263
312
|
showOnFilter: { type: Boolean, default: true },
|
|
264
313
|
|
|
314
|
+
// showOnList controls if the field will be on deal list page
|
|
315
|
+
// fields are always shown on org pages and in edit forms
|
|
316
|
+
showOnList: { type: Boolean, default: true }
|
|
317
|
+
|
|
265
318
|
}
|
|
266
319
|
|
|
267
320
|
}]
|
|
@@ -450,12 +503,139 @@ module.exports = function(mongoose, config) {
|
|
|
450
503
|
// Deals aren't on for customer
|
|
451
504
|
else if (!self.customer.deals.active) return [];
|
|
452
505
|
|
|
453
|
-
// Get active
|
|
454
|
-
var
|
|
455
|
-
|
|
456
|
-
|
|
506
|
+
// Get active status names and sort them
|
|
507
|
+
var statuses = _.filter(self.customer.deals.statuses, function(s) { return s.active; });
|
|
508
|
+
statuses = _.sortBy(statuses, 'order');
|
|
509
|
+
statuses = _.pluck(statuses, 'name');
|
|
510
|
+
|
|
511
|
+
return statuses;
|
|
512
|
+
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
Organization.virtual('customer.deals.fields').get(function () {
|
|
516
|
+
|
|
517
|
+
// Combine standard fields and custom fields into a single list and sort by column order
|
|
518
|
+
// Fundraise is actually two fields, so multiply the order by ten to make room for the extra field
|
|
519
|
+
|
|
520
|
+
var self = this;
|
|
457
521
|
|
|
458
|
-
|
|
522
|
+
var standardFields = self.customer.deals.standardFields;
|
|
523
|
+
|
|
524
|
+
// Defaulting to off so it will be immediately apparent the customer hasn't been properly configured
|
|
525
|
+
standardFields = standardFields || {
|
|
526
|
+
fundraise: {
|
|
527
|
+
showOnList: false
|
|
528
|
+
},
|
|
529
|
+
sources: {
|
|
530
|
+
showOnList: false
|
|
531
|
+
},
|
|
532
|
+
referrers: {
|
|
533
|
+
showOnList: false
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
var customFields = self.customer.deals.customFields;
|
|
538
|
+
var result = [];
|
|
539
|
+
|
|
540
|
+
// Add standard fields
|
|
541
|
+
if (standardFields.action.showOnList) {
|
|
542
|
+
result.push({
|
|
543
|
+
name: 'Next Steps',
|
|
544
|
+
type: 'Text',
|
|
545
|
+
key: 'action',
|
|
546
|
+
isStandard: true,
|
|
547
|
+
order: standardFields.action.order * 10,
|
|
548
|
+
colspan: standardFields.action.colspan || 1,
|
|
549
|
+
showOnFilter: standardFields.action.showOnFilter === true ? true : false
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if (standardFields.raise.showOnList) {
|
|
554
|
+
result.push({
|
|
555
|
+
name: 'Raise',
|
|
556
|
+
type: 'Money',
|
|
557
|
+
key: 'fundraise.amount',
|
|
558
|
+
isStandard: true,
|
|
559
|
+
order: standardFields.raise.order * 10,
|
|
560
|
+
colspan: standardFields.raise.colspan || 1,
|
|
561
|
+
showOnFilter: standardFields.raise.showOnFilter === true ? true : false
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
if(standardFields.valuation.showOnList) {
|
|
566
|
+
result.push({
|
|
567
|
+
name: 'Valuation',
|
|
568
|
+
type: 'Money',
|
|
569
|
+
key: 'fundraise.valuation',
|
|
570
|
+
isStandard: true,
|
|
571
|
+
order: standardFields.valuation.order * 10 + 1,
|
|
572
|
+
colspan: standardFields.valuation.colspan || 1,
|
|
573
|
+
showOnFilter: standardFields.valuation.showOnFilter === true ? true : false
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (standardFields.sources.showOnList) {
|
|
578
|
+
result.push({
|
|
579
|
+
name: 'Sources',
|
|
580
|
+
type: 'Reference',
|
|
581
|
+
key: 'sources',
|
|
582
|
+
isStandard: true,
|
|
583
|
+
order: standardFields.sources.order * 10,
|
|
584
|
+
colspan: standardFields.sources.colspan || 1,
|
|
585
|
+
showOnFilter: standardFields.sources.showOnFilter === true ? true : false
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
if (standardFields.referrers.showOnList) {
|
|
590
|
+
result.push({
|
|
591
|
+
name: 'Referrers',
|
|
592
|
+
type: 'Reference',
|
|
593
|
+
key: 'referrers',
|
|
594
|
+
isStandard: true,
|
|
595
|
+
order: standardFields.referrers.order * 10,
|
|
596
|
+
colspan: standardFields.referrers.colspan || 1,
|
|
597
|
+
showOnFilter: standardFields.referrers.showOnFilter === true ? true : false
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
if (standardFields.chairs.showOnList) {
|
|
602
|
+
result.push({
|
|
603
|
+
name: 'Leads',
|
|
604
|
+
type: 'Reference',
|
|
605
|
+
key: 'organization.chairs',
|
|
606
|
+
isStandard: true,
|
|
607
|
+
order: standardFields.chairs.order * 10,
|
|
608
|
+
colspan: standardFields.chairs.colspan || 1,
|
|
609
|
+
showOnFilter: standardFields.chairs.showOnFilter === true ? true : false
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// Add custom fields
|
|
614
|
+
_.each(customFields, function(field) {
|
|
615
|
+
if (field.display.showOnList) {
|
|
616
|
+
result.push({
|
|
617
|
+
name: field.label,
|
|
618
|
+
type: field.type,
|
|
619
|
+
isStandard: false,
|
|
620
|
+
key: field.key,
|
|
621
|
+
options: field.options,
|
|
622
|
+
order: field.display.order * 10,
|
|
623
|
+
colspan: field.display.colspan || 1,
|
|
624
|
+
showOnFilter: field.display.showOnFilter === true ? true : false
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
// Sort the combined standard and custom fields
|
|
630
|
+
result = _.sortBy(result, function(item) { return item.order; });
|
|
631
|
+
|
|
632
|
+
// Now that we have all fields combined and ordered, make column order zero-indexed and gap-free
|
|
633
|
+
result = _.map(result, function(item, index) {
|
|
634
|
+
item.order = index;
|
|
635
|
+
return item;
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
return result;
|
|
459
639
|
|
|
460
640
|
});
|
|
461
641
|
|
|
@@ -755,10 +935,10 @@ module.exports = function(mongoose, config) {
|
|
|
755
935
|
if (err) return callback(err, null);
|
|
756
936
|
else if (!org) return callback(new Error('Customer not found'), null);
|
|
757
937
|
|
|
758
|
-
var
|
|
938
|
+
var statuses = org.customer.deals.activeStatuses;
|
|
759
939
|
|
|
760
|
-
var match = _.find(
|
|
761
|
-
return
|
|
940
|
+
var match = _.find(statuses, function(status) {
|
|
941
|
+
return status == previous.deal.stage;
|
|
762
942
|
});
|
|
763
943
|
|
|
764
944
|
if (!match) return callback(new Error('This stage is not valid for this customer'), null);
|
|
@@ -1823,4 +2003,4 @@ module.exports = function(mongoose, config) {
|
|
|
1823
2003
|
|
|
1824
2004
|
mongoose.model('Organization', Organization, 'organizations');
|
|
1825
2005
|
|
|
1826
|
-
};
|
|
2006
|
+
};
|