2015-05-22 23:30:15 +02:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-day-view
|
2016-07-15 23:02:24 +02:00
|
|
|
* @requires phuix-icon-view
|
2015-05-22 23:30:15 +02:00
|
|
|
*/
|
|
|
|
JX.behavior('day-view', function(config) {
|
2015-05-22 23:46:48 +02:00
|
|
|
|
2015-05-22 23:30:15 +02:00
|
|
|
function findTodayClusters() {
|
|
|
|
var events = today_events.sort(function(x, y){
|
|
|
|
return (x.eventStartEpoch - y.eventStartEpoch);
|
|
|
|
});
|
|
|
|
|
|
|
|
var clusters = [];
|
|
|
|
|
2015-05-22 23:46:48 +02:00
|
|
|
for (var i=0; i < events.length; i++) {
|
|
|
|
var today_event = events[i];
|
|
|
|
|
2015-05-22 23:30:15 +02:00
|
|
|
var destination_cluster_index = null;
|
2015-05-24 04:47:23 +02:00
|
|
|
var event_start = today_event.eventStartEpoch - (60);
|
|
|
|
var event_end = today_event.eventEndEpoch + (60);
|
2015-05-22 23:30:15 +02:00
|
|
|
|
2015-05-22 23:46:48 +02:00
|
|
|
for (var j=0; j < clusters.length; j++) {
|
|
|
|
var cluster = clusters[j];
|
|
|
|
|
|
|
|
for(var k=0; k < cluster.length; k++) {
|
|
|
|
var clustered_event = cluster[k];
|
2015-05-22 23:30:15 +02:00
|
|
|
var compare_event_start = clustered_event.eventStartEpoch;
|
|
|
|
var compare_event_end = clustered_event.eventEndEpoch;
|
|
|
|
|
|
|
|
if (event_start < compare_event_end &&
|
|
|
|
event_end > compare_event_start) {
|
2015-05-22 23:46:48 +02:00
|
|
|
destination_cluster_index = j;
|
2015-05-22 23:30:15 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-05-22 23:46:48 +02:00
|
|
|
|
|
|
|
if (destination_cluster_index !== null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-05-22 23:30:15 +02:00
|
|
|
|
|
|
|
if (destination_cluster_index !== null) {
|
2015-05-22 23:46:48 +02:00
|
|
|
clusters[destination_cluster_index].push(today_event);
|
2015-05-22 23:30:15 +02:00
|
|
|
destination_cluster_index = null;
|
|
|
|
} else {
|
|
|
|
var next_cluster = [];
|
2015-05-22 23:46:48 +02:00
|
|
|
next_cluster.push(today_event);
|
2015-05-22 23:30:15 +02:00
|
|
|
clusters.push(next_cluster);
|
|
|
|
}
|
2015-05-22 23:46:48 +02:00
|
|
|
}
|
2015-05-22 23:30:15 +02:00
|
|
|
|
|
|
|
return clusters;
|
|
|
|
}
|
|
|
|
|
2015-05-24 04:47:23 +02:00
|
|
|
function updateEventsFromCluster(cluster) {
|
2015-05-23 00:30:17 +02:00
|
|
|
var cluster_size = cluster.length;
|
|
|
|
var n = 0;
|
|
|
|
for(var i=0; i < cluster.length; i++) {
|
|
|
|
var cluster_member = cluster[i];
|
|
|
|
|
|
|
|
var event_id = cluster_member.eventID;
|
|
|
|
var offset = ((n / cluster_size) * 100) + '%';
|
|
|
|
var width = ((1 / cluster_size) * 100) + '%';
|
|
|
|
|
2015-05-24 04:47:23 +02:00
|
|
|
for (var j=0; j < today_events.length; j++) {
|
|
|
|
if (today_events[j].eventID == event_id) {
|
2015-05-23 00:30:17 +02:00
|
|
|
|
2015-05-24 04:47:23 +02:00
|
|
|
today_events[j]['offset'] = offset;
|
|
|
|
today_events[j]['width'] = width;
|
2015-05-23 00:30:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2015-05-24 04:47:23 +02:00
|
|
|
return today_events;
|
2015-05-23 00:30:17 +02:00
|
|
|
}
|
|
|
|
|
2015-05-24 04:47:23 +02:00
|
|
|
function drawEvent(e) {
|
|
|
|
var name = e['eventName'];
|
|
|
|
var eventID = e['eventID'];
|
|
|
|
var viewerIsInvited = e['viewerIsInvited'];
|
|
|
|
var offset = e['offset'];
|
|
|
|
var width = e['width'];
|
|
|
|
var top = e['top'];
|
|
|
|
var height = e['height'];
|
|
|
|
var uri = e['uri'];
|
|
|
|
|
|
|
|
var sigil = 'phui-calendar-day-event';
|
2015-05-23 01:26:48 +02:00
|
|
|
var link_class = 'phui-calendar-day-event-link';
|
2015-05-23 02:50:23 +02:00
|
|
|
|
2015-05-23 01:26:48 +02:00
|
|
|
if (viewerIsInvited) {
|
|
|
|
link_class = link_class + ' viewer-invited-day-event';
|
|
|
|
}
|
|
|
|
|
2016-07-15 23:02:24 +02:00
|
|
|
var icon = new JX.PHUIXIconView()
|
|
|
|
.setIcon(e.displayIcon)
|
|
|
|
.setColor(e.displayIconColor)
|
|
|
|
.getNode();
|
|
|
|
|
|
|
|
var content = [icon, ' ', name];
|
|
|
|
|
2015-05-23 01:26:48 +02:00
|
|
|
var name_link = JX.$N(
|
|
|
|
'a',
|
|
|
|
{
|
|
|
|
className : link_class,
|
|
|
|
href: uri
|
|
|
|
},
|
2016-07-15 23:02:24 +02:00
|
|
|
content);
|
2015-05-23 01:26:48 +02:00
|
|
|
|
2015-05-24 20:22:33 +02:00
|
|
|
var class_name = 'phui-calendar-day-event';
|
|
|
|
if (e.canEdit) {
|
|
|
|
class_name = class_name + ' can-drag';
|
|
|
|
}
|
|
|
|
|
2015-05-23 01:26:48 +02:00
|
|
|
var div = JX.$N(
|
|
|
|
'div',
|
|
|
|
{
|
2015-05-24 20:22:33 +02:00
|
|
|
className: class_name,
|
2015-05-24 04:47:23 +02:00
|
|
|
sigil: sigil,
|
|
|
|
meta: {eventID: eventID, record: e, uri: uri},
|
2015-05-23 01:26:48 +02:00
|
|
|
style: {
|
|
|
|
left: offset,
|
|
|
|
width: width,
|
|
|
|
top: top,
|
|
|
|
height: height
|
|
|
|
}
|
|
|
|
},
|
|
|
|
name_link);
|
|
|
|
|
|
|
|
return div;
|
|
|
|
}
|
|
|
|
|
2016-07-15 23:02:24 +02:00
|
|
|
function drawAllDayEvent(e) {
|
2015-05-23 02:50:23 +02:00
|
|
|
var class_name = 'day-view-all-day';
|
|
|
|
|
2016-07-15 23:02:24 +02:00
|
|
|
var icon = new JX.PHUIXIconView()
|
|
|
|
.setIcon(e.displayIcon)
|
|
|
|
.setColor(e.displayIconColor)
|
|
|
|
.getNode();
|
|
|
|
var content = [icon, ' ', e.name];
|
|
|
|
|
|
|
|
var name = JX.$N(
|
2015-05-23 02:50:23 +02:00
|
|
|
'a',
|
|
|
|
{
|
|
|
|
className: class_name,
|
2016-07-15 23:02:24 +02:00
|
|
|
href: e.uri
|
2015-05-23 02:50:23 +02:00
|
|
|
},
|
2016-07-15 23:02:24 +02:00
|
|
|
content);
|
2015-05-23 02:50:23 +02:00
|
|
|
|
|
|
|
var all_day_label = JX.$N(
|
|
|
|
'span',
|
|
|
|
{className: 'phui-calendar-all-day-label'},
|
|
|
|
'All Day');
|
|
|
|
|
|
|
|
var div_all_day = JX.$N(
|
|
|
|
'div',
|
2015-05-24 04:47:23 +02:00
|
|
|
{className: 'phui-calendar-day-event all-day'},
|
2015-05-23 02:50:23 +02:00
|
|
|
[all_day_label, name]);
|
|
|
|
|
|
|
|
return div_all_day;
|
|
|
|
}
|
|
|
|
|
2015-05-23 01:26:48 +02:00
|
|
|
function drawRows() {
|
|
|
|
var rows = [];
|
|
|
|
var early_hours = [8];
|
|
|
|
if (first_event_hour) {
|
|
|
|
early_hours.push(first_event_hour);
|
|
|
|
}
|
|
|
|
var min_early_hour = Math.min(early_hours[0], early_hours[1]);
|
|
|
|
|
|
|
|
|
|
|
|
for(var i=0; i < hours.length; i++) {
|
|
|
|
if (hours[i]['hour'] < min_early_hour) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var cell_time = JX.$N(
|
|
|
|
'td',
|
|
|
|
{className: 'phui-calendar-day-hour'},
|
2016-07-13 19:26:18 +02:00
|
|
|
hours[i].displayTime);
|
2015-05-23 01:26:48 +02:00
|
|
|
|
|
|
|
var cell_event = JX.$N(
|
|
|
|
'td',
|
|
|
|
{
|
2015-05-24 20:22:33 +02:00
|
|
|
meta: {
|
2016-07-13 19:26:18 +02:00
|
|
|
time: hours[i].displayTime
|
2015-05-24 20:22:33 +02:00
|
|
|
},
|
|
|
|
className: 'phui-calendar-day-events',
|
|
|
|
sigil: 'phui-calendar-day-event-cell'
|
2015-05-24 04:47:23 +02:00
|
|
|
});
|
|
|
|
|
2015-05-23 01:26:48 +02:00
|
|
|
var row = JX.$N(
|
|
|
|
'tr',
|
|
|
|
{},
|
|
|
|
[cell_time, cell_event]);
|
|
|
|
rows.push(row);
|
|
|
|
}
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
|
2015-05-24 04:47:23 +02:00
|
|
|
function clusterAndDrawEvents() {
|
|
|
|
var today_clusters = findTodayClusters();
|
|
|
|
for(var i=0; i < today_clusters.length; i++) {
|
|
|
|
today_events = updateEventsFromCluster(today_clusters[i]);
|
|
|
|
}
|
|
|
|
var drawn_hourly_events = [];
|
|
|
|
for (i=0; i < today_events.length; i++) {
|
|
|
|
drawn_hourly_events.push(drawEvent(today_events[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
JX.DOM.setContent(hourly_events_wrapper, drawn_hourly_events);
|
|
|
|
|
2015-05-23 00:30:17 +02:00
|
|
|
}
|
2015-05-24 04:47:23 +02:00
|
|
|
|
2015-05-24 20:22:33 +02:00
|
|
|
var year = config.year;
|
|
|
|
var month = config.month;
|
|
|
|
var day = config.day;
|
|
|
|
var query = config.query;
|
|
|
|
|
2015-05-24 04:47:23 +02:00
|
|
|
var hours = config.hours;
|
|
|
|
var first_event_hour = config.firstEventHour;
|
|
|
|
var first_event_hour_epoch = parseInt(config.firstEventHourEpoch, 10);
|
|
|
|
var today_events = config.todayEvents;
|
|
|
|
var today_all_day_events = config.allDayEvents;
|
|
|
|
var table_wrapper = JX.$(config.tableID);
|
2015-05-23 01:26:48 +02:00
|
|
|
var rows = drawRows();
|
2015-05-23 02:50:23 +02:00
|
|
|
|
|
|
|
var all_day_events = [];
|
|
|
|
for(i=0; i < today_all_day_events.length; i++) {
|
|
|
|
var all_day_event = today_all_day_events[i];
|
2016-07-15 23:02:24 +02:00
|
|
|
all_day_events.push(drawAllDayEvent(all_day_event));
|
2015-05-23 02:50:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var table = JX.$N(
|
|
|
|
'table',
|
|
|
|
{className: 'phui-calendar-day-view'},
|
|
|
|
rows);
|
|
|
|
|
2015-05-24 04:47:23 +02:00
|
|
|
var dragging = false;
|
|
|
|
var origin = null;
|
|
|
|
|
|
|
|
var offset_top = null;
|
|
|
|
var new_top = null;
|
|
|
|
|
|
|
|
var click_time = null;
|
|
|
|
|
|
|
|
JX.DOM.listen(
|
|
|
|
table_wrapper,
|
|
|
|
'mousedown',
|
|
|
|
'phui-calendar-day-event',
|
|
|
|
function(e){
|
|
|
|
|
|
|
|
if (!e.isNormalMouseEvent()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-24 20:22:33 +02:00
|
|
|
var data = e.getNodeData('phui-calendar-day-event');
|
|
|
|
if (!data.record.canEdit) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-24 04:47:23 +02:00
|
|
|
e.kill();
|
|
|
|
dragging = e.getNode('phui-calendar-day-event');
|
|
|
|
JX.DOM.alterClass(dragging, 'phui-drag', true);
|
|
|
|
|
|
|
|
click_time = new Date();
|
|
|
|
|
|
|
|
origin = JX.$V(e);
|
|
|
|
|
|
|
|
var outer = JX.Vector.getPos(table);
|
|
|
|
var inner = JX.Vector.getPos(dragging);
|
|
|
|
|
|
|
|
offset_top = inner.y - outer.y;
|
|
|
|
new_top = offset_top;
|
|
|
|
|
|
|
|
dragging.style.top = offset_top + 'px';
|
|
|
|
});
|
|
|
|
JX.Stratcom.listen('mousemove', null, function(e){
|
|
|
|
if (!dragging) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var cursor = JX.$V(e);
|
|
|
|
|
|
|
|
new_top = cursor.y - origin.y + offset_top;
|
|
|
|
new_top = Math.min(new_top, 1320);
|
|
|
|
new_top = Math.max(new_top, 0);
|
|
|
|
new_top = Math.floor(new_top/15) * 15;
|
|
|
|
|
|
|
|
dragging.style.top = new_top + 'px';
|
|
|
|
});
|
|
|
|
JX.Stratcom.listen('mouseup', null, function(){
|
|
|
|
if (!dragging) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-24 20:22:33 +02:00
|
|
|
|
|
|
|
var data = JX.Stratcom.getData(dragging);
|
|
|
|
var record = data.record;
|
|
|
|
|
2015-05-24 04:47:23 +02:00
|
|
|
if (new_top == offset_top) {
|
|
|
|
var now = new Date();
|
|
|
|
if (now.getTime() - click_time.getTime() < 250) {
|
|
|
|
JX.$U(record.uri).go();
|
|
|
|
}
|
|
|
|
|
|
|
|
JX.DOM.alterClass(dragging, 'phui-drag', false);
|
|
|
|
dragging = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var new_time = first_event_hour_epoch + (new_top * 60);
|
|
|
|
var id = data.eventID;
|
|
|
|
var duration = record.eventEndEpoch - record.eventStartEpoch;
|
|
|
|
record.eventStartEpoch = new_time;
|
|
|
|
record.eventEndEpoch = new_time + duration;
|
|
|
|
record.top = new_top + 'px';
|
|
|
|
|
|
|
|
new JX.Workflow(
|
|
|
|
'/calendar/event/drag/' + id + '/',
|
|
|
|
{start: new_time})
|
|
|
|
.start();
|
|
|
|
|
|
|
|
JX.DOM.alterClass(dragging, 'phui-drag', false);
|
|
|
|
dragging = false;
|
|
|
|
|
|
|
|
clusterAndDrawEvents();
|
|
|
|
});
|
|
|
|
|
|
|
|
JX.DOM.listen(table_wrapper, 'click', 'phui-calendar-day-event', function(e){
|
|
|
|
if (e.isNormalClick()) {
|
|
|
|
e.kill();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-24 20:22:33 +02:00
|
|
|
JX.DOM.listen(table, 'click', 'phui-calendar-day-event-cell', function(e){
|
|
|
|
if (!e.isNormalClick()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var data = e.getNodeData('phui-calendar-day-event-cell');
|
|
|
|
var time = data.time;
|
2016-07-15 23:02:24 +02:00
|
|
|
|
2015-05-24 20:22:33 +02:00
|
|
|
new JX.Workflow(
|
2016-07-15 23:02:24 +02:00
|
|
|
'/calendar/event/edit/',
|
2015-05-24 20:22:33 +02:00
|
|
|
{
|
2016-07-15 23:02:24 +02:00
|
|
|
start_d: year + '-' + month + '-' + day,
|
|
|
|
start_t: time,
|
|
|
|
end_d: year + '-' + month + '-' + day,
|
|
|
|
end_t: time + ' +1 hour'
|
2015-05-24 20:22:33 +02:00
|
|
|
})
|
|
|
|
.start();
|
|
|
|
});
|
|
|
|
|
2015-05-24 04:47:23 +02:00
|
|
|
var hourly_events_wrapper = JX.$N(
|
|
|
|
'div',
|
|
|
|
{style: {
|
|
|
|
position: 'absolute',
|
|
|
|
left: '69px',
|
|
|
|
right: 0
|
|
|
|
}});
|
|
|
|
|
|
|
|
clusterAndDrawEvents();
|
|
|
|
|
|
|
|
var daily_wrapper = JX.$N(
|
|
|
|
'div',
|
|
|
|
{style: {position: 'relative'}},
|
|
|
|
[hourly_events_wrapper, table]);
|
|
|
|
|
|
|
|
JX.DOM.setContent(table_wrapper, [all_day_events, daily_wrapper]);
|
|
|
|
|
2015-05-22 23:30:15 +02:00
|
|
|
});
|