-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCubes.js
More file actions
145 lines (105 loc) · 4.31 KB
/
Copy pathCubes.js
File metadata and controls
145 lines (105 loc) · 4.31 KB
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
define(["dojo", "put-selector/put", "dojo/date", "dojo/date/locale"],
function(dojo, put, DD, DF) {
var genId = 1;
function nextId() {
return "lineup_cubes_" + genId++;
}
var timeIncrements = function(startTime, endTime) {
var t = dojo.isString(startTime) ? (new Date(startTime)) : startTime;
var e = dojo.isString(endTime) ? (new Date(endTime)) : endTime;
var incs = [];
while(t <= e) {
incs.push( DF.format(t, {selector: 'time'}) );
t = dojo.date.add(t, 'minute', 15);
}
return incs;
};
return dojo.declare([], {
showDay: null,
// constructor: function(opts, srcNodeRef) {
// console.debug("CTOR");
// },
postscript: function(opts, srcNodeRef) {
//console.debug("POSTSCRIPT");
if (srcNodeRef) {
// normalize srcNodeRef and store on instance during create process.
this.srcNodeRef = srcNodeRef = srcNodeRef.nodeType ? srcNodeRef : dojo.byId(srcNodeRef);
}
this.create(opts, srcNodeRef)
this.inherited(arguments);
},
// preamble: function() {
// this.inherited(arguments);
// console.debug("PREAMBLE");
// },
// =====
create: function(opts, srcNodeRef) {
if ('showDay' in opts) {
this.showDay = opts.showDay;
this._delayRender = false;
} else {
this._delayRender = true;
}
var domNode = srcNodeRef || put("div");
this.domNode = domNode;
// apply id to widget and domNode. From incoming node, widget params, or autogenerated.
this.id = domNode.id = domNode.id || this.id || nextId();
put(domNode, '.lineup-cubes');
if (!this._delayRender) {
this.render();
}
},
render: function() {
this.domNode.innerHTML = '<br/>';
this.headerNode = put(this.domNode, 'div.cubes-header');
this.bodyNode = put(this.domNode, 'div.cubes-body');
var table = put(this.domNode, 'table tbody');
this.headerNode = put(table, 'tr.cubes-header');
this.bodyNode = put(table, 'tr.cubes-body');
this.footerNode = put(table, 'tr.cubes-footer');
this.renderHeader();
this.renderBody();
},
renderHeader: function() {
console.debug("renderHeader; this=%o", this);
put(this.headerNode, 'th.time'); // no header content for times column
dojo.forEach(this.showDay.venues, function(showsInfo) {
//console.debug("showsInfo = %o", showsInfo);
put(this.headerNode, 'th $', showsInfo.venue.name);
}, this);
},
renderBody: function() {
var ul = put(this.bodyNode, 'th.times ul.schedule-times');
console.debug("renderBody; this = %o", this);
dojo.forEach( timeIncrements(this.showDay.schedule_start, this.showDay.schedule_end), function(time) {
put(ul, 'li $', time);
});
var PX_PER_MIN = 2;
var startOfDay = new Date(this.showDay.schedule_start);
var venueLineupNodes = [];
dojo.forEach(this.showDay.venues, function(venueLineup) {
// create a single column for all the shows
var venueLineupNode = put(this.bodyNode, 'td.venue div.artist-lineup');
dojo.forEach(venueLineup.shows, function(setInfo ) {
var showBox = put(venueLineupNode, 'div.show-box');
// the show box is sized and placed based on the time information
//console.debug("calculating info from setInfo=%o", setInfo)
var startTime = new Date(setInfo.start);
var startOffset = (DD.difference(startOfDay, startTime, 'minute') * PX_PER_MIN);
var height = (parseInt(setInfo.length || this.showDay.default_show_length || 15) * PX_PER_MIN) - 1; // shave a pixel off
//console.debug("math... startOffset = %o; height = %o", startOffset, height);
dojo.style(showBox, {
height: height+'px', // calculate from show length or end time
top: startOffset+'px'
});
put(showBox, 'div.show-container strong.show-title $ +span.show-time $', setInfo.name, DF.format(startTime, {selector: 'time'}))
}, this);
venueLineupNodes.push(venueLineupNode);
}, this);
},
// =====
setShowDayData: function(data) {
this.showDay = data;
}
});
});