mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-04-08 06:48:51 +00:00
creating and dragNDrop between calendars in multicolumndayview
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#import <Foundation/NSCalendarDate.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSArray.h>
|
||||
|
||||
#import <NGObjWeb/NSException+HTTP.h>
|
||||
#import <NGObjWeb/SoPermissions.h>
|
||||
@@ -52,19 +53,25 @@
|
||||
WOResponse *response;
|
||||
WORequest *rq;
|
||||
SOGoAppointmentObject *co;
|
||||
SoSecurityManager *sm;
|
||||
iCalEvent *event;
|
||||
NSCalendarDate *start, *newStart, *end, *newEnd;
|
||||
NSTimeInterval newDuration;
|
||||
SOGoUserDefaults *ud;
|
||||
NSString *daysDelta, *startDelta, *durationDelta;
|
||||
NSString *daysDelta, *startDelta, *durationDelta, *calendarID;
|
||||
NSArray *calendarsID;
|
||||
NSTimeZone *tz;
|
||||
NSException *ex;
|
||||
SOGoAppointmentFolder *componentCalendar, *previousCalendar;
|
||||
SOGoAppointmentFolders *user;
|
||||
|
||||
rq = [context request];
|
||||
|
||||
daysDelta = [rq formValueForKey: @"days"];
|
||||
startDelta = [rq formValueForKey: @"start"];
|
||||
durationDelta = [rq formValueForKey: @"duration"];
|
||||
calendarID = [rq formValueForKey: @"calendarID"];
|
||||
|
||||
if ([daysDelta length] > 0
|
||||
|| [startDelta length] > 0 || [durationDelta length] > 0)
|
||||
{
|
||||
@@ -105,10 +112,31 @@
|
||||
}
|
||||
|
||||
if ([event hasRecurrenceRules])
|
||||
[event updateRecurrenceRulesUntilDate: end];
|
||||
[event updateRecurrenceRulesUntilDate: end];
|
||||
|
||||
[event setLastModified: [NSCalendarDate calendarDate]];
|
||||
ex = [co saveComponent: event];
|
||||
/***************************** TODO ******************/
|
||||
if (![calendarID isEqualToString:@"0"]) {
|
||||
user = [[self->context activeUser] calendarsFolderInContext: self->context];
|
||||
calendarsID = [calendarID componentsSeparatedByString:@","];
|
||||
previousCalendar = [user lookupName:[[calendarsID objectAtIndex:0] stringValue] inContext: self->context acquire: 0];
|
||||
componentCalendar = [user lookupName:[[calendarsID objectAtIndex:1] stringValue] inContext: self->context acquire: 0];
|
||||
// The event was moved to a different calendar.
|
||||
sm = [SoSecurityManager sharedSecurityManager];
|
||||
if (![sm validatePermission: SoPerm_DeleteObjects
|
||||
onObject: previousCalendar
|
||||
inContext: context])
|
||||
{
|
||||
if (![sm validatePermission: SoPerm_AddDocumentsImagesAndFiles
|
||||
onObject: componentCalendar
|
||||
inContext: context])
|
||||
ex = [co moveToFolder: componentCalendar];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/********************************************************/
|
||||
if (ex)
|
||||
{
|
||||
NSDictionary *jsonResponse;
|
||||
|
||||
@@ -191,7 +191,7 @@
|
||||
NSMutableDictionary *calendar;
|
||||
unsigned int count, foldersCount;
|
||||
NSString *folderName, *fDisplayName;
|
||||
NSNumber *isActive;
|
||||
BOOL *isActive;
|
||||
|
||||
co = [self clientObject];
|
||||
folders = [co subFolders];
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<div class="days">
|
||||
<var:foreach list="calendarsToDisplay" item="currentCalendar">
|
||||
<var:foreach list="daysToDisplay" item="currentTableDay">
|
||||
<div var:class="dayClasses" var:day="currentTableDay.shortDateString" var:id="currentAllDayId" hour="allday"><!-- space --></div>
|
||||
<div var:class="dayClasses" var:day="currentTableDay.shortDateString" var:id="currentAllDayId" var:calendar="currentCalendar.folder" hour="allday"><!-- space --></div>
|
||||
</var:foreach>
|
||||
</var:foreach>
|
||||
</div>
|
||||
@@ -75,7 +75,7 @@
|
||||
<var:if condition="isMultiColumnView">
|
||||
<var:foreach list="calendarsToDisplay" item="currentCalendar">
|
||||
<var:foreach list="daysToDisplay" item="currentTableDay">
|
||||
<div var:class="dayClasses" var:id="currentDayId" var:day-number="currentDayNumber" var:day="currentTableDay.shortDateString">
|
||||
<div var:class="dayClasses" var:id="currentDayId" var:day-number="currentDayNumber" var:calendar="currentCalendar.folder" var:day="currentTableDay.shortDateString">
|
||||
<div class="hourCells">
|
||||
<var:foreach list="hoursToDisplay" item="currentTableHour">
|
||||
<div var:class="clickableHourCellClass" var:day="currentTableDay.shortDateString" var:hour="currentAppointmentHour">
|
||||
|
||||
@@ -123,28 +123,34 @@ function newEventFromDragging(controller, day, coordinates) {
|
||||
newEvent("event", day, startHm, lengthHm);
|
||||
}
|
||||
|
||||
function updateEventFromDragging(controller, eventCells, eventDelta) {
|
||||
if (eventDelta.dayNumber || eventDelta.start || eventDelta.duration) {
|
||||
var params = ("days=" + eventDelta.dayNumber
|
||||
+ "&start=" + eventDelta.start * 15
|
||||
+ "&duration=" + eventDelta.duration * 15);
|
||||
// log("eventCells: " + eventCells.length);
|
||||
var eventCell = eventCells[0];
|
||||
// log(" time: " + eventCell.recurrenceTime);
|
||||
// log(" exception: " + eventCell.isException);
|
||||
|
||||
if (eventCell.recurrenceTime && !eventCell.isException)
|
||||
_editRecurrenceDialog(eventCell, "confirmAdjustment", params);
|
||||
else {
|
||||
var urlstr = (ApplicationBaseURL
|
||||
+ "/" + eventCell.calendar + "/" + eventCell.cname);
|
||||
if (eventCell.recurrenceTime)
|
||||
urlstr += "/occurence" + eventCell.recurrenceTime;
|
||||
urlstr += ("/adjust?" + params);
|
||||
// log(" urlstr: " + urlstr);
|
||||
triggerAjaxRequest(urlstr, updateEventFromDraggingCallback);
|
||||
}
|
||||
function updateEventFromDragging(controller, eventCells, eventDelta, calendarID) {
|
||||
if (eventDelta.dayNumber || eventDelta.start || eventDelta.duration) {
|
||||
if (calendarID != 0)
|
||||
var params = ("calendarID=" + calendarID
|
||||
+ "&days=" + 0
|
||||
+ "&start=" + eventDelta.start * 15
|
||||
+ "&duration=" + eventDelta.duration * 15);
|
||||
else
|
||||
var params = ("calendarID=" + calendarID
|
||||
+ "&days=" + eventDelta.dayNumber
|
||||
+ "&start=" + eventDelta.start * 15
|
||||
+ "&duration=" + eventDelta.duration * 15);
|
||||
// log("eventCells: " + eventCells.length);
|
||||
var eventCell = eventCells[0];
|
||||
// log(" time: " + eventCell.recurrenceTime);
|
||||
// log(" exception: " + eventCell.isException);
|
||||
|
||||
if (eventCell.recurrenceTime && !eventCell.isException)
|
||||
_editRecurrenceDialog(eventCell, "confirmAdjustment", params);
|
||||
else {
|
||||
var urlstr = (ApplicationBaseURL + "/" + eventCell.calendar + "/" + eventCell.cname);
|
||||
if (eventCell.recurrenceTime)
|
||||
urlstr += "/occurence" + eventCell.recurrenceTime;
|
||||
urlstr += ("/adjust?" + params);
|
||||
// log(" urlstr: " + urlstr);
|
||||
triggerAjaxRequest(urlstr, updateEventFromDraggingCallback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function performEventAdjustment(folder, event, recurrence, params) {
|
||||
@@ -2293,6 +2299,22 @@ function calendarDisplayCallback(http) {
|
||||
if (currentView == "monthview")
|
||||
days[i].observe("scroll", onBodyClickHandler);
|
||||
}
|
||||
else if (currentView == "multicolumndayview") {
|
||||
var calendarHeader = $("calendarHeader");
|
||||
var headerCalendarsLabels = calendarHeader.select("DIV.calendarLabels DIV.calendarsToDisplay");
|
||||
var headerDays = calendarHeader.select("DIV.days DIV.day");
|
||||
for (var i = 0; i < days.length; i++) {
|
||||
headerDays[i].hour = "allday";
|
||||
headerCalendarsLabels[i].observe("mousedown", listRowMouseDownHandler);
|
||||
headerDays[i].observe("click", onCalendarSelectDay);
|
||||
headerDays[i].observe("dblclick", onClickableCellsDblClick);
|
||||
days[i].observe("click", onCalendarSelectDay);
|
||||
|
||||
var clickableCells = days[i].select("DIV.clickableHourCell");
|
||||
for (var j = 0; j < clickableCells.length; j++)
|
||||
clickableCells[j].observe("dblclick", onClickableCellsDblClick);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var calendarHeader = $("calendarHeader");
|
||||
var headerDaysLabels = calendarHeader.select("DIV.dayLabels DIV.day");
|
||||
@@ -2706,6 +2728,19 @@ function onCalendarSelectDay(event) {
|
||||
|
||||
var target = Event.findElement(event);
|
||||
var div = target.up('div');
|
||||
|
||||
// Select the calendar associated with the day clicked
|
||||
if (currentView == "multicolumndayview") {
|
||||
if (target.getAttribute("calendar"))
|
||||
var calendar = "[id='/" + target.getAttribute("calendar") + "']";
|
||||
else
|
||||
var calendar = "[id='/" + target.up("[calendar]").getAttribute("calendar") + "']";
|
||||
var list = $("calendarList");
|
||||
var selectedCalendar = list.down(calendar);
|
||||
|
||||
onRowClick(event, selectedCalendar);
|
||||
}
|
||||
|
||||
if (div && !div.hasClassName('event') && !div.hasClassName('eventInside') && !div.hasClassName('text') && !div.hasClassName('gradient')) {
|
||||
// Target is not an event -- unselect all events.
|
||||
listOfSelection = $("eventsList");
|
||||
|
||||
@@ -8,6 +8,7 @@ var SOGoEventDragDayLength = 24 * 4; /* quarters */
|
||||
var SOGoEventDragHandleSize = 8; /* handles for dragging mode */
|
||||
var SOGoEventDragHorizontalOffset = 3;
|
||||
var SOGoEventDragVerticalOffset = 3;
|
||||
var calendarID = [], activeCalendars = [];;
|
||||
|
||||
/* singleton */
|
||||
var _sogoEventDragUtilities = null;
|
||||
@@ -217,27 +218,31 @@ SOGoEventDragEventCoordinates.prototype = {
|
||||
},
|
||||
|
||||
initFromEventCellMultiDay: function(eventCell) {
|
||||
var classNames = eventCell.className.split(" ");
|
||||
for (var i = 0;
|
||||
(this.start == -1 || this.duration == -1)
|
||||
&& i < classNames.length;
|
||||
i++) {
|
||||
var className = classNames[i];
|
||||
var classNames = eventCell.className.split(" ");
|
||||
for (var i = 0; (this.start == -1 || this.duration == -1) && i < classNames.length; i++) {
|
||||
var className = classNames[i];
|
||||
if (className.startsWith("starts")) {
|
||||
this.start = parseInt(className.substr(6));
|
||||
this.start = parseInt(className.substr(6));
|
||||
}
|
||||
else if (className.startsWith("lasts")) {
|
||||
this.duration = parseInt(className.substr(5));
|
||||
}
|
||||
}
|
||||
var dayNumber = -1;
|
||||
|
||||
var dayNode = eventCell.parentNode.parentNode;
|
||||
var classNames = dayNode.className.split(" ");
|
||||
for (var i = 0; dayNumber == -1 && i < classNames.length; i++) {
|
||||
if (currentView == "multicolumndayview") {
|
||||
calendarID[0] = dayNode.getAttribute("calendar");
|
||||
var dayNumber = this._updateMulticolumnViewDayNumber(calendarID);
|
||||
}
|
||||
else {
|
||||
var classNames = dayNode.className.split(" ");
|
||||
for (var i = 0; dayNumber == -1 && i < classNames.length; i++) {
|
||||
var className = classNames[i];
|
||||
if (className.startsWith("day") && className.length > 3) {
|
||||
dayNumber = parseInt(className.substr(3));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.dayNumber = dayNumber;
|
||||
},
|
||||
@@ -246,13 +251,19 @@ SOGoEventDragEventCoordinates.prototype = {
|
||||
this.duration = SOGoEventDragDayLength;
|
||||
|
||||
var dayNode = eventCell.parentNode;
|
||||
var classNames = dayNode.className.split(" ");
|
||||
var dayNumber = -1;
|
||||
for (var i = 0; dayNumber == -1 && i < classNames.length; i++) {
|
||||
if (currentView == "multicolumndayview") {
|
||||
calendarID[0] = dayNode.getAttribute("calendar");
|
||||
var dayNumber = this._updateMulticolumnViewDayNumber(calendarID);
|
||||
}
|
||||
else {
|
||||
var classNames = dayNode.className.split(" ");
|
||||
var dayNumber = -1;
|
||||
for (var i = 0; dayNumber == -1 && i < classNames.length; i++) {
|
||||
var className = classNames[i];
|
||||
if (className.startsWith("day") && className.length > 3) {
|
||||
dayNumber = parseInt(className.substr(3));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.dayNumber = dayNumber;
|
||||
},
|
||||
@@ -294,8 +305,8 @@ SOGoEventDragEventCoordinates.prototype = {
|
||||
current.setEventType(this.eventType);
|
||||
current.initFromEventCell(eventCells[i]);
|
||||
if (this.dayNumber == -1 || current.dayNumber < this.dayNumber) {
|
||||
this.dayNumber = current.dayNumber;
|
||||
this.start = current.start;
|
||||
this.dayNumber = current.dayNumber;
|
||||
this.start = current.start;
|
||||
}
|
||||
this.duration += current.duration;
|
||||
}
|
||||
@@ -321,6 +332,20 @@ SOGoEventDragEventCoordinates.prototype = {
|
||||
|
||||
return "" + hours + ":" + mins;
|
||||
},
|
||||
|
||||
_updateMulticolumnViewDayNumber: function(calendarID) {
|
||||
var calendarList = $("calendarList").getElementsByTagName("li");
|
||||
for (var j = 0; j < calendarList.length ; j++) {
|
||||
if ($("calendarList").getElementsByTagName("li")[j].down().checked) {
|
||||
activeCalendars.push($("calendarList").getElementsByTagName("li")[j].getAttribute("id").substr(1));
|
||||
}
|
||||
}
|
||||
for (var k = 0; k < activeCalendars.length; k++) {
|
||||
if (activeCalendars[k] == calendarID[0]) {
|
||||
return k;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
getStartTime: function() {
|
||||
return this._quartersToHM(this.start);
|
||||
@@ -515,12 +540,32 @@ SOGoEventDragGhostController.prototype = {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
_updateMulticolumnViewDayNumber_SEDGC: function() {
|
||||
var calendarID_SEDGC = this.folderClass.substr(14);
|
||||
var calendarList = $("calendarList").getElementsByTagName("li");
|
||||
var activeCalendars = [];
|
||||
for (var j = 0; j < calendarList.length ; j++) {
|
||||
if ($("calendarList").getElementsByTagName("li")[j].down().checked) {
|
||||
activeCalendars.push($("calendarList").getElementsByTagName("li")[j].getAttribute("id").substr(1));
|
||||
}
|
||||
}
|
||||
for (var k = 0; k < activeCalendars.length; k++) {
|
||||
if (activeCalendars[k] == calendarID_SEDGC) {
|
||||
this.currentCoordinates.dayNumber = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_updateCoordinates: function SEDGC__updateCoordinates() {
|
||||
var delta = this.currentPointerCoordinates
|
||||
.getDelta(this.originalPointerCoordinates);
|
||||
var deltaQuarters = delta.x * SOGoEventDragDayLength + delta.y;
|
||||
this.currentCoordinates.dayNumber = this.originalCoordinates.dayNumber;
|
||||
if (currentView == "multicolumndayview")
|
||||
this._updateMulticolumnViewDayNumber_SEDGC();
|
||||
else
|
||||
this.currentCoordinates.dayNumber = this.originalCoordinates.dayNumber;
|
||||
|
||||
// log("dragMode: " + this.dragMode);
|
||||
if (this.dragMode == "move-event") {
|
||||
@@ -565,6 +610,10 @@ SOGoEventDragGhostController.prototype = {
|
||||
var deltaDays = Math.floor(this.currentCoordinates.start
|
||||
/ SOGoEventDragDayLength);
|
||||
this.currentCoordinates.start -= deltaDays * SOGoEventDragDayLength;
|
||||
|
||||
// This dayNumber needs to be updated with the calendar number.
|
||||
if (currentView == "multicolumndayview")
|
||||
this._updateMulticolumnViewDayNumber_SEDGC();
|
||||
this.currentCoordinates.dayNumber += deltaDays;
|
||||
}
|
||||
},
|
||||
@@ -1036,9 +1085,17 @@ SOGoEventDragController.prototype = {
|
||||
this.ghostController.initWithCoordinates(coordinates);
|
||||
|
||||
if (!this.eventCells) {
|
||||
if (currentView == "multicolumndayview") {
|
||||
if (target.getAttribute("calendar"))
|
||||
var folderID = target.getAttribute("calendar");
|
||||
else
|
||||
var folderID = target.up("[calendar]").getAttribute("calendar");
|
||||
}
|
||||
else {
|
||||
var folder = getSelectedFolder();
|
||||
var folderID = folder.readAttribute("id").substr(1);
|
||||
this.ghostController.setFolderClass("calendarFolder" + folderID);
|
||||
}
|
||||
this.ghostController.setFolderClass("calendarFolder" + folderID);
|
||||
}
|
||||
this.ghostController.setDragMode(this._determineDragMode());
|
||||
this.ghostController.setPointerHandler(this.pointerHandler);
|
||||
@@ -1311,7 +1368,14 @@ SOGoEventDragController.prototype = {
|
||||
.currentCoordinates
|
||||
.getDelta(this.ghostController
|
||||
.originalCoordinates);
|
||||
this.updateDropCallback(this, this.eventCells, delta);
|
||||
if (currentView == "multicolumndayview" && delta.dayNumber != 0) {
|
||||
var position = activeCalendars.indexOf(calendarID[0]);
|
||||
position += delta.dayNumber;
|
||||
calendarID[1] = activeCalendars[position];
|
||||
this.updateDropCallback(this, this.eventCells, delta, calendarID);
|
||||
}
|
||||
else
|
||||
this.updateDropCallback(this, this.eventCells, delta, 0);
|
||||
} else {
|
||||
var eventContainerNodes = utilities.getEventContainerNodes();
|
||||
var dayNode = eventContainerNodes[this.ghostController
|
||||
|
||||
Reference in New Issue
Block a user