forked from Meteor-Community-Packages/meteor-tabular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
56 lines (41 loc) · 1.51 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* global Tabular:true, Mongo, _, Meteor, Template */
Tabular = {}; //exported
Tabular.tablesByName = {};
if (Meteor.isClient) {
Template.registerHelper('TabularTables', Tabular.tablesByName);
}
Tabular.Table = function (options) {
var self = this;
if (!options) {
throw new Error('Tabular.Table options argument is required');
}
if (!options.name) {
throw new Error('Tabular.Table options must specify name');
}
self.name = options.name;
if (!(options.collection instanceof Mongo.Collection)) {
throw new Error('Tabular.Table options must specify collection');
}
self.collection = options.collection;
self.pub = options.pub || 'tabular_genericPub';
// By default we use core `Meteor.subscribe`, but you can pass
// a subscription manager like `sub: new SubsManager({cacheLimit: 20, expireIn: 3})`
self.sub = options.sub || Meteor;
self.onUnload = options.onUnload;
self.allow = options.allow;
self.allowFields = options.allowFields;
self.changeSelector = options.changeSelector;
if (_.isArray(options.extraFields)) {
var fields = {};
_.each(options.extraFields, function (fieldName) {
fields[fieldName] = 1;
});
self.extraFields = fields;
}
self.selector = options.selector;
if (!options.columns) {
throw new Error('Tabular.Table options must specify columns');
}
self.options = _.omit(options, 'collection', 'pub', 'sub', 'onUnload', 'allow', 'allowFields', 'extraFields', 'name', 'selector');
Tabular.tablesByName[self.name] = self;
};