forked from damiengarbarino/dojo-calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoreBase.js
205 lines (174 loc) · 5.7 KB
/
StoreBase.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
define([
"dcl/dcl",
"delite/Widget",
"delite/StoreMap"
], function (dcl, Widget, StoreMap) {
return dcl([Widget, StoreMap], {
// summary:
// This mixin contains the store management, and is mixed into both CalendarBase and ViewBase.
// startTimeAttr: String
// The attribute of the store item that contains the start time of
// the events represented by this item. Default is "startTime".
startTimeAttr: "startTime",
// endTimeAttr: String
// The attribute of the store item that contains the end time of
// the events represented by this item. Default is "endTime".
endTimeAttr: "endTime",
// summaryAttr: String
// The attribute of the store item that contains the summary of
// the events represented by this item. Default is "summary".
summaryAttr: "summary",
// allDayAttr: String
// The attribute of the store item that contains the all day state of
// the events represented by this item. Default is "allDay".
allDayAttr: "allDay",
// subColumnAttr: String
// The attribute of the store item that contains the sub column name of
// the events represented by this item. Default is "calendar".
subColumnAttr: "calendar",
// cssClassFunc: Function
// Optional function that returns a css class name to apply to item renderers
// that are displaying the specified item in parameter.
cssClassFunc: null,
// decodeDate: Function?
// An optional function to transform store date into DateTime objects. Default is null.
decodeDate: null,
// encodeDate: Function?
// An optional function to transform DateTime objects into store date. Default is null.
encodeDate: null,
itemToRenderItem: dcl.superCall(function (sup) {
return function (storeItem) {
// Override to use decodeDate() method.
var ri = sup.apply(this, arguments);
ri.startTime = this.decodeDate ? this.decodeDate(ri.startTime) : ri.startTime;
ri.endTime = this.decodeDate ? this.decodeDate(ri.endTime) : ri.endTime;
// Also, some of the code depends on renderItem._item pointing back to the original store item.
ri._item = storeItem;
return ri;
};
}),
renderItemToItem: dcl.superCall(function (sup) {
return function () {
// Override to use encodeDate() method
var ri = sup.apply(this, arguments);
if (this.encodeDate) {
ri.startTime = this.encodeDate(ri.startTime);
ri.endTime = this.encodeDate(ri.endTime);
}
return ri;
};
}),
computeProperties: function (oldVals) {
if ("renderItems" in oldVals) {
// renderItems can be set due to a result from querying the store, or alternately set
// directly (in the case when ColumnView sets renderItems in ColumnViewSecondarySheet).
// In either case, split into this.visibleItems and this.visibleDecorationItems,
// since that's what the rest of the code wants.
var data = this.visibleItems = [];
var decorations = this.visibleDecorationItems = [];
if (this.renderItems) {
this.renderItems.forEach(function (ri) {
if (ri.type === "decoration") {
decorations.push(ri);
} else {
data.push(ri);
}
});
}
}
},
_removeItemWithId: function (items, id) {
var l = items.length;
for (var i = l - 1; i >= 0; i--) {
if (items[i].id == id) {
items.splice(i, 1);
this._cleanItemStoreState(id);
return true;
}
}
},
_getItemStoreStateObj: function (/*Object*/ item) {
// tags
// private
var owner = this.owner;
if (owner) {
return owner._getItemStoreStateObj(item);
}
var store = this.source;
if (store != null && this._itemStoreState != null) {
var id = item.id === undefined ? store.getIdentity(item) : item.id;
return this._itemStoreState[id];
}
return null;
},
getItemStoreState: function (item) {
// summary:
// Returns the creation state of an item.
// This state is changing during the interactive creation of an item.
// Valid values are:
// - "unstored": The event is being interactively created. It is not in the store yet.
// - "storing": The creation gesture has ended, the event is being added to the store.
// - "stored": The event is not in the two previous states, and is assumed to be in the store
// (not checking because of performance reasons, use store API for testing existence in store).
// item: Object
// The item.
// returns: String
var owner = this.owner;
if (owner) {
return owner.getItemStoreState(item);
}
if (this._itemStoreState == null) {
return "stored";
}
var store = this.source;
var id = item.id === undefined ? store.getIdentity(item) : item.id;
var s = this._itemStoreState[id];
if (store != null && s !== undefined) {
return s.state;
}
return "stored";
},
_cleanItemStoreState: function (id) {
var owner = this.owner;
if (owner) {
return owner._cleanItemStoreState(id);
}
if (!this._itemStoreState) {
return;
}
var s = this._itemStoreState[id];
if (s) {
delete this._itemStoreState[id];
return true;
}
return false;
},
_setItemStoreState: function (/*Object*/item, /*String*/state) {
var owner = this.owner;
if (owner) {
owner._setItemStoreState(item, state);
return;
}
if (this._itemStoreState === undefined) {
this._itemStoreState = {};
}
var store = this.source;
var id = item.id === undefined ? store.getIdentity(item) : item.id;
var s = this._itemStoreState[id];
if (state === "stored" || state == null) {
if (s !== undefined) {
delete this._itemStoreState[id];
}
return;
}
if (store) {
this._itemStoreState[id] = {
id: id,
item: item,
renderItem: this.itemToRenderItem(item),
state: state
};
}
}
});
});