Skip to content

Commit

Permalink
Now weekends:false works with resourceMonth and ResourceNextWeeks views.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarno Kurlin committed Oct 4, 2012
1 parent 009395e commit db0b9e6
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 23 deletions.
34 changes: 32 additions & 2 deletions src/common/DayEventRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function DayEventRenderer() {
var skinCss;
var html = '';
var viewName = getViewName();
var weekends = opt('weekends'), weekendTestDate, weekendSumColStart, weekendSumColEnd;

// calculate desired position/dimensions, create html
for (i=0; i<segCnt; i++) {
Expand Down Expand Up @@ -164,19 +165,48 @@ function DayEventRenderer() {
}

if (viewName == 'resourceMonth') {
// hack for resourceMonth view
// What is we have view which lists 4 week from now on, how can we get right columns?
// for resourceMonth view
leftCol = seg.start.getDate()-1;
rightCol = seg.end.getDate()-2;

if(!weekends) {
// Drop out weekends
weekendSumColStart=0
weekendSumColEnd=0

for(j=0; j<=leftCol; j++) {
weekendTestDate = addDays(cloneDate(t.visStart), j);

if(weekendTestDate.getDay() == 0 || weekendTestDate.getDay() == 6) {
weekendSumColStart++;
}
}
leftCol -= weekendSumColStart;

for(j=0; j<=rightCol; j++) {
weekendTestDate = addDays(cloneDate(t.visStart), j);

if(weekendTestDate.getDay() == 0 || weekendTestDate.getDay() == 6) {
weekendSumColEnd++;
}
}
rightCol -= weekendSumColEnd;
}

if(rightCol < 0) {
// end is in the next month so rightCol is the last column
rightCol = getColCnt()-1;
}
}
else if (viewName == 'resourceNextWeeks') {

leftCol = dateCell(seg.start).col;
rightCol = dateCell(seg.end).col-1;
if(!weekends) {
leftCol = dateCell(seg.start).col;
rightCol = dateCell(addDays(cloneDate(seg.end),-1)).col;
}

}
else if (viewName == 'resourceDay') {
// hack for resourceDay view
Expand Down
2 changes: 1 addition & 1 deletion src/common/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function View(element, calendar, viewName) {
allDay,
function() {
// TODO: investigate cases where this inverse technique might not work
moveEvents(eventsByID[eventId], -dayDelta, -minuteDelta, oldAllDay);
moveEvents(eventsByID[eventId], -dayDelta, -minuteDelta, oldAllDay,resource.oldId);
reportEventChange(eventId);
},
ev,
Expand Down
121 changes: 109 additions & 12 deletions src/resource/ResourceEventRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@ function ResourceEventRenderer() {
colCnt = getColCnt(),
resources = t.getResources,
d1 = cloneDate(t.visStart),
d2 = addDays(cloneDate(d1), colCnt),
d2 = cloneDate(t.visEnd),
visEventsEnds = $.map(events, exclEndDay),
i, row,
j, level,
k, seg, currentResource, viewName = getViewName(),
l, segs=[];

if (viewName == 'resourceDay') {
d2 = cloneDate(t.visEnd);


if (viewName == 'resourceDay') {
visEventsEnds = $.map(events, function(event) {
return event.end || addDays(event.start, 1);
});
Expand Down Expand Up @@ -124,7 +122,7 @@ function ResourceEventRenderer() {

function draggableResourceEvent(event, eventElement) {
var hoverListener = getHoverListener();
var dayDelta, minuteDelta, resourceDelta, newResourceId, resources, viewName = getViewName();
var dayDelta, minuteDelta, resourceDelta, newResourceId, resources, viewName = getViewName(), weekendTestDate, daysToAdd, daysToDel, dayDeltaStart, dayDeltaEnd;
eventElement.draggable({
zIndex: 9,
delay: 50,
Expand All @@ -138,7 +136,7 @@ function ResourceEventRenderer() {
clearOverlays();
if (cell) {
//setOverflowHidden(true);
resourceDelta = rowDelta * (opt('isRTL') ? -1 : 1);
resourceDelta = rowDelta;
resources = t.getResources;
newResourceId = resources[cell.row].id;

Expand All @@ -152,10 +150,37 @@ function ResourceEventRenderer() {
);
}
else {
dayDelta = colDelta * (opt('isRTL') ? -1 : 1);
dayDelta = dayDeltaStart = dayDeltaEnd = colDelta * (opt('isRTL') ? -1 : 1);

// If weekends are not within, add or remove days from dayDelta. Is there a better way?
if (!opt('weekends') && (dayDelta > 0 || dayDelta < 0)) {
if (dayDelta > 0) {
for(i=1; i<=dayDeltaStart; i++) {
weekendTestDate = addDays(cloneDate(event.start), i);
if (weekendTestDate.getDay() == 6 || weekendTestDate.getDay() == 0) dayDeltaStart++;
}

for(i=1; i<=dayDeltaEnd; i++) {
weekendTestDate = addDays(cloneDate(event.end), i);
if (weekendTestDate.getDay() == 6 || weekendTestDate.getDay() == 0) dayDeltaEnd++;
}
}
else {
for(i=-1; i>=dayDeltaStart; i--) {
weekendTestDate = addDays(cloneDate(event.start), i);
if (weekendTestDate.getDay() == 6 || weekendTestDate.getDay() == 0) dayDeltaStart--;
}

for(i=-1; i>=dayDeltaEnd; i--) {
weekendTestDate = addDays(cloneDate(event.end), i);
if (weekendTestDate.getDay() == 6 || weekendTestDate.getDay() == 0) dayDeltaEnd--;
}
}
}

renderDayOverlay(
addDays(cloneDate(event.start), dayDelta),
addDays(exclEndDay(event), dayDelta),
addDays(cloneDate(event.start), dayDeltaStart),
addDays(exclEndDay(event), dayDeltaEnd),
false,
cell.row
);
Expand All @@ -176,6 +201,39 @@ function ResourceEventRenderer() {
eventDrop(this, event, 0, minuteDelta, event.allDay, ev, ui, newResourceId);
}
else if (dayDelta || resourceDelta) {
if (!opt('weekends')) {
// We have to add or remove days from event.start and event.end. Is there a better way?
if (dayDelta > 0) {
daysToAdd = 0;
for(i=1; i<=dayDelta+daysToAdd; i++) {
weekendTestDate = addDays(cloneDate(event.start), i);
if (weekendTestDate.getDay() == 6 || weekendTestDate.getDay() == 0) daysToAdd++;
}
if (daysToAdd > 0) event.start = addDays(cloneDate(event.start), daysToAdd, true);

daysToAdd = 0;
for(i=1; i<=dayDelta+daysToAdd; i++) {
weekendTestDate = addDays(cloneDate(event.end), i);
if (weekendTestDate.getDay() == 6 || weekendTestDate.getDay() == 0) daysToAdd++;
}
if (daysToAdd > 0) event.end = addDays(cloneDate(event.end), daysToAdd, true);
}
else {
daysToDel = 0;
for(i=-1; i>=dayDelta+daysToDel; i--) {
weekendTestDate = addDays(cloneDate(event.start), i);
if (weekendTestDate.getDay() == 6 || weekendTestDate.getDay() == 0) daysToDel--;
}
if (daysToDel < 0) event.start = addDays(cloneDate(event.start), daysToDel, true);

daysToDel = 0;
for(i=-1; i>=dayDelta+daysToDel; i--) {
weekendTestDate = addDays(cloneDate(event.end), i);
if (weekendTestDate.getDay() == 6 || weekendTestDate.getDay() == 0) daysToDel--;
}
if (daysToDel < 0) event.end = addDays(cloneDate(event.end), daysToDel, true);
}
}
eventDrop(this, event, dayDelta, 0, event.allDay, ev, ui, newResourceId);
} else{
eventElement.css('filter', ''); // clear IE opacity side-effects
Expand Down Expand Up @@ -229,6 +287,7 @@ function ResourceEventRenderer() {
var helpers;
var eventCopy = $.extend({}, event);
var minCell = dateCell(event.start);
var newEnd;
clearSelection();
$('body')
.css('cursor', direction + '-resize')
Expand All @@ -244,8 +303,25 @@ function ResourceEventRenderer() {
var newEnd = addMinutes(eventEnd(event), minuteDelta, true);
}
else {
dayDelta = (7 + c*dis+dit) - (7 + origCell.col*dis+dit);
var newEnd = addDays(eventEnd(event), dayDelta, true);
dayDelta = dayDeltaStart = dayDeltaEnd = (7 + c*dis+dit) - (7 + origCell.col*dis+dit);

// If weekends is set to false, add or remove days from dayDelta
if (!opt('weekends') && (dayDelta > 0 || dayDelta < 0)) {
if (dayDelta > 0) {
for(i=1; i<=dayDeltaEnd; i++) {
weekendTestDate = addDays(cloneDate(event.end), i);
if (weekendTestDate.getDay() == 6 || weekendTestDate.getDay() == 0) dayDeltaEnd++;
}
}
else {
for(i=-1; i>=dayDeltaEnd; i--) {
weekendTestDate = addDays(cloneDate(event.end), i);
if (weekendTestDate.getDay() == 6 || weekendTestDate.getDay() == 0) dayDeltaEnd--;
}
}
}
newEnd = addDays(eventEnd(event), dayDeltaEnd, true);

}

if (dayDelta || minuteDelta) {
Expand Down Expand Up @@ -280,7 +356,28 @@ function ResourceEventRenderer() {
$('body').css('cursor', '');
hoverListener.stop();
clearOverlays();

if (dayDelta) {
if (!opt('weekends')) {
// We have to add or remove days from event.end. Is there a better way?
if (dayDelta > 0) {
daysToAdd = 0;
for(i=1; i<=dayDelta+daysToAdd; i++) {
weekendTestDate = addDays(cloneDate(event.end), i);
if (weekendTestDate.getDay() == 6 || weekendTestDate.getDay() == 0) daysToAdd++;
}
if (daysToAdd > 0) event.end = addDays(cloneDate(event.end), daysToAdd, true);
}
else {
daysToDel = 0;
for(i=-1; i>=dayDelta+daysToDel; i--) {
weekendTestDate = addDays(cloneDate(event.end), i);
if (weekendTestDate.getDay() == 6 || weekendTestDate.getDay() == 0) daysToDel--;
}
if (daysToDel < 0) event.end = addDays(cloneDate(event.end), daysToDel, true);
}
}

eventResize(this, event, dayDelta, 0, ev);
// event redraw will clear helpers
}
Expand Down
14 changes: 14 additions & 0 deletions src/resource/ResourceMonthView.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function ResourceMonthView(element, calendar) {
skipWeekend(visStart);
skipWeekend(visEnd, -1, true);
}

t.title = formatDates(
visStart,
addDays(cloneDate(visEnd), -1),
Expand All @@ -42,6 +43,19 @@ function ResourceMonthView(element, calendar) {
t.visStart = visStart;
t.visEnd = visEnd;
var cols = Math.round((visEnd - visStart) / (DAY_MS));
var weekendTestDate;
if(!weekends) {
// Drop out weekends from cols
var weekendCnt = 0;
for(i=1; i<=cols; i++) {
weekendTestDate = addDays(cloneDate(visStart), i);
if(weekendTestDate.getDay() == 0 || weekendTestDate.getDay() == 6) {
weekendCnt++;
}
}
cols -= weekendCnt;
}

renderBasic(getResources.length, getResources.length, cols, false);
}

Expand Down
7 changes: 4 additions & 3 deletions src/resource/ResourceNextWeeksView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ function ResourceNextWeeksView(element, calendar) {


function render(date, delta) {
var weekends = opt('weekends');
if (delta) {
addDays(date, delta * opt('numberOfWeeks') * 7);
addDays(date, delta * opt('numberOfWeeks') * weekends ? 7 : 5);
}
var start = addDays(cloneDate(date), -((date.getDay() - opt('firstDay') + 7) % 7));
var start = addDays(cloneDate(date), -((date.getDay() - opt('firstDay') + weekends ? 7 : 5) % weekends ? 7 : 5));
var end = addWeeks(cloneDate(start), opt('numberOfWeeks'));
var visStart = cloneDate(start);
var visEnd = cloneDate(end);
var weekends = opt('weekends');

if (!weekends) {
skipWeekend(visStart);
Expand All @@ -38,6 +38,7 @@ function ResourceNextWeeksView(element, calendar) {
addDays(cloneDate(visEnd), -1),
opt('titleFormat')
);

t.start = start;
t.end = end;
t.visStart = visStart;
Expand Down
Loading

0 comments on commit db0b9e6

Please sign in to comment.