forked from damiengarbarino/dojo-calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColumnView.js
executable file
·170 lines (147 loc) · 5.04 KB
/
ColumnView.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
define([
"dcl/dcl",
"delite/register",
"dojo/dom-class",
"dojo/dom-geometry",
"dojo/dom-style",
"./SimpleColumnView",
"delite/handlebars!./templates/ColumnView.html",
"./ColumnViewSecondarySheet",
"./metrics"
], function (
dcl,
register,
domClass,
domGeometry,
domStyle,
SimpleColumnView,
template,
ColumnViewSecondarySheet,
metrics
) {
return register("d-calendar-column-view", [SimpleColumnView], {
// summary:
// This class extends SimpleColumnView by adding a secondary
// sheet to display long or all day events.
// By default a dcalendar/ColumnViewSecondarySheet instance is created.
// Set the secondarySheetClass property to define the class to instantiate,
// for example to mix the default class with Mouse, Keyboard or Touch plugins.
template: template,
baseClass: "d-calendar-column-view",
// secondarySheetClass: Class
// The secondary sheet class, by default dcalendar/ColumnViewSecondarySheet.
secondarySheetClass: ColumnViewSecondarySheet,
// secondarySheetProps: Object
// Secondary sheet constructor parameters.
secondarySheetProps: null,
// headerPadding: Integer
// Padding between the header (composed of the secondary sheet and the column header)
// and the primary sheet.
headerPadding: 3,
_showSecondarySheet: true,
// List of properties to forward to secondary sheet.
forwardProperties: [
// These are the main properties; they control which date range is shown and which events are shown.
// Whenever the user goes forwards or backwards in the SimpleColumnView, it
// reruns the query, which in turn resets renderItems[].
"renderItems", "startDate", "columnCount",
// These properties will likely never change but they need to at least be passed once.
"editable", "moveEnabled", "resizeEnabled",
"createOnGridClick",
"horizontalRenderer", "labelRenderer"
],
initializeRendering: dcl.superCall(function (sup) {
return function () {
sup.apply(this, arguments);
if (this.secondarySheetPlaceholder) {
var args = {owner: this};
this.forwardProperties.forEach(function (prop) {
if (this[prop] !== null && this[prop] !== undefined) {
var value = typeof prop === "function" ? this[prop].bind(this) : this[prop];
args[prop] = value;
}
}, this);
for (var key in this.secondarySheetProps) {
args[key] = this.secondarySheetProps[key];
}
this.secondarySheet = new this.secondarySheetClass(args);
this.secondarySheet.placeAt(this.secondarySheetPlaceholder, "replace");
}
};
}),
destroy: function () {
if (this.secondarySheet) {
this.secondarySheet.destroy();
}
},
_setVisibility: dcl.superCall(function (sup) {
return function (value) {
sup.apply(this, arguments);
if (this.secondarySheet) {
this.secondarySheet._setVisibility(value);
}
};
}),
resize: dcl.superCall(function (sup) {
return function () {
sup.apply(this, arguments);
if (this.secondarySheet) {
// secondary sheet is sized by CSS
this.secondarySheet.resize();
}
};
}),
refreshRendering: function (props) {
if (this.secondarySheet) {
// Forward property changes to second sheet
this.forwardProperties.forEach(function (prop) {
if (prop in props && this[prop] !== null && this[prop] !== undefined) {
var value = typeof prop === "function" ? this[prop].bind(this) : this[prop];
this.secondarySheet[prop] = value;
}
}, this);
this.secondarySheet.deliver();
}
},
_buildRowHeader: dcl.superCall(function (sup) {
return function () {
sup.apply(this, arguments);
// The width of the first column in the secondary sheet must have the same width as the row header.
if (this.secondarySheet) {
var width = domGeometry.getMarginBox(this.rowHeader).w;
domGeometry.setMarginBox(this.secondarySheet.rowHeaderTable, {w: width});
// Hack until MatrixView gets flex sizing.
var prop = (this.effectiveDir === "ltr") ? "left" : "right";
this.secondarySheet.grid.style[prop] = width + "px";
this.secondarySheet.itemContainer.style[prop] = width + "px";
}
};
}),
updateRenderers: dcl.superCall(function (sup) {
return function (obj, stateOnly) {
sup.apply(this, arguments);
if (this.secondarySheet) {
this.secondarySheet.updateRenderers(obj, stateOnly);
}
};
}),
_defaultItemToRendererKindFunc: function (item) {
return item.allDay ? null : "vertical"; // String
},
// TODO: combine to use pointer events?
_onGridTouchStart: dcl.after(function () {
this._doEndItemEditing(this.secondarySheet, "touch");
}),
_onGridMouseDown: dcl.after(function () {
this._doEndItemEditing(this.secondarySheet, "mouse");
}),
_configureScrollBar: dcl.superCall(function (sup) {
return function () {
sup.apply(this, arguments);
// Compensate for scrollbar on main grid, to make secondary sheet columns align with main columns
this.secondarySheet.style[this.effectiveDir == "ltr" ? "marginRight" : "marginLeft"] =
metrics.getScrollbar().w + "px";
};
})
});
});