This repository has been archived by the owner on Jun 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Configs.js
240 lines (229 loc) · 4.92 KB
/
Configs.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
var DEFAULT_CONFIG = {
system: {
useProfileConfig: 0,
startProfile: "",
showEmptyView: 1,
show: ["daily"],
fullDayEventLocalize: 1,
redrawInterval: 30*60*1000, //minimum 60000
locale: null,
},
views: {
daily: {
direction: "row",
counts: 5,
titleFormat: "D",
overTitleFormat: "MMM D",
subtitleFormat: "ddd",
},
weekly: {
direction: "row",
counts: 4,
titleFormat: "wo",
overTitleFormat: "gggg wo",
subtitleFormat: "MMM Do",
},
monthly: {
direction: "row",
counts: 3,
titleFormat: "MMMM",
overTitleFormat: "YYYY MMM",
subtitleFormat: "YYYY",
},
upcoming: {
title: "Upcoming",
useRelative: 1
},
current: {
title: "Current",
useRelative: 1
},
month: {
titleFormat : "D",
overTitleFormat : "MMM D",
monthTitleFormat: "MMMM",
weekdayFormat: "ddd",
showWeeks: 1,
weeksTitle: "weeks",
weeksFormat: "wo",
},
weeks: {
showWeeks: 1,
weeksTitle: "weeks",
weeksFormat: "wo",
weekdayFormat: "ddd",
titleFormat: "MMM D",
overTitleFormat: "MMM D",
counts: 4,
},
},
calendars: [],
defaultView: {
position: "bottom_bar",
positionOrder: -1,
overflowRolling: 0,
overflowHeight: 0,
overflowDuration: 2,
onlyStartingTime: 0,
timeFormat: "HH:mm",
dateFormat: "MMM Do",
fullDayEventDateFormat: "MMM Do",
ellipsis: 0,
limit:0,
oneLineEvent:0,
replaceTitle: [],
classPattern: [],
classPatternWhere: ["title"],
symbolPattern: [],
symbolPatternWhere: ["title"],
},
defaultCalendar: {
name: null,
profiles: [],
views: [],
styleName: "",
replaceTitle: [],
classPattern: [],
classPatternWhere: ["title"],
symbolPattern: [],
symbolPatternWhere: ["title"],
ellipsis: 0,
symbol: "",
maxEntries:50,
maxDays:180,
interval: 30*60*1000,
url: null,
auth: {
user:"",
pass:"",
method:""
}
}
}
function Configs(
systemConfig={},
viewsConfig={},
calendarsConfig={},
profileConfigs={},
defaultViewConfig={},
defaultCalendarConfig={}
) {
this.system = systemConfig
this.views = viewsConfig
this.calendars = calendarsConfig
this.profileConfigs = profileConfigs
this.defaultView = defaultViewConfig
this.defaultCalendar = defaultCalendarConfig
return this;
}
Configs.prototype.mix = function(tmpl, ncfg, includeCalendars=1) {
var cfg = {}
//system
var tcfg = (typeof ncfg.system !== "undefined") ? ncfg.system : {}
cfg.system = this.assignment({}, tmpl.system, tcfg)
if(!cfg.system.locale) {
cfg.system.locale = moment.locale()
}
//views
if(ncfg.views !== "undefined") {
cfg.views = this.assignment({}, tmpl.views, ncfg.views)
}
//defaultView
if(ncfg.defaultView !== "undefined") {
cfg.defaultView = this.assignment({}, tmpl.defaultView, ncfg.defaultView)
}
//defaultCalendar
if(ncfg.defaultCalendar !== "undefined") {
cfg.defaultCalendar = this.assignment(
{},
tmpl.defaultCalendar,
ncfg.defaultCalendar
)
}
//profileConfig
if (ncfg.profileConfigs !== "undefined") {
cfg.profileConfigs = this.assignment({}, ncfg.profileConfigs)
}
//calendars
if (!includeCalendars || typeof ncfg.calendars == "undefined") {
cfg.calendars = this.assignment({}, tmpl.calendars)
} else {
cfg.calendars = this.assignment({}, ncfg.calendars)
}
return cfg
}
Configs.prototype.getCalConfig = function(idx) {
return this.assignment(
{},
DEFAULT_CONFIG.defaultCalendar,
this.defaultCalendar,
this.calendars[idx]
)
}
Configs.prototype.getViewConfig = function (idx) {
var ret = this.assignment(
{},
DEFAULT_CONFIG.defaultView,
this.defaultView,
this.views[idx]
)
if (idx == "upcoming" || idx == "current" || idx == "month") {
ret.counts = 1
}
if (typeof ret.locale == "undefined") {
ret.locale = this.system.locale
} else {
if (ret.locale == "") {
ret.locale = this.system.locale
}
}
ret.mode = idx
return ret
}
Configs.prototype.make = function(newCfg) {
var ret = this.mix(DEFAULT_CONFIG, newCfg)
return new Configs(
ret.system,
ret.views,
ret.calendars,
ret.profileConfigs,
ret.defaultView,
ret.defaultCalendar
)
}
Configs.prototype.modify = function(newCfg) {
var ret = this.mix(this, newCfg)
this.system = ret.system
this.views = ret.views
this.calendars = ret.calendars
this.defaultView = ret.defaultView
this.defaultCalendar = ret.defaultCalendar
this.profileConfigs = ret.profileConfigs
return this;
}
Configs.prototype.assignment = function (result) {
var stack = Array.prototype.slice.call(arguments, 1);
var item;
var key;
while (stack.length) {
item = stack.shift();
for (key in item) {
if (item.hasOwnProperty(key)) {
if (
typeof result[key] === "object"
&& result[key]
&& Object.prototype.toString.call(result[key]) !== "[object Array]"
) {
if (typeof item[key] === "object" && item[key] !== null) {
result[key] = this.assignment({}, result[key], item[key]);
} else {
result[key] = item[key];
}
} else {
result[key] = item[key];
}
}
}
}
return result;
}