diff options
author | Georg Ehrke <georg.stefan.germany@googlemail.com> | 2011-10-01 22:27:30 +0400 |
---|---|---|
committer | Georg Ehrke <georg.stefan.germany@googlemail.com> | 2011-10-01 22:27:30 +0400 |
commit | 43a3e46369723d1f00ecc3048e3c88177995ab14 (patch) | |
tree | 3cf9436ca58da006f8f072096f369c6b7fd2ba5d /apps | |
parent | bf6414d3ad2a19bc9bf5174abd82d8ffaee02ef4 (diff) |
added drag and drop function for events in calendar app
Diffstat (limited to 'apps')
-rw-r--r-- | apps/calendar/ajax/moveevent.php | 98 | ||||
-rw-r--r-- | apps/calendar/js/calendar.js | 35 |
2 files changed, 133 insertions, 0 deletions
diff --git a/apps/calendar/ajax/moveevent.php b/apps/calendar/ajax/moveevent.php new file mode 100644 index 00000000000..d18c25eb517 --- /dev/null +++ b/apps/calendar/ajax/moveevent.php @@ -0,0 +1,98 @@ +<?php +/** + * Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +error_reporting(E_ALL); +require_once('../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +$data = OC_Calendar_Object::find($_POST["id"]); +$calendarid = $data["calendarid"]; +$cal = $calendarid; +$id = $_POST["id"]; +$calendar = OC_Calendar_Calendar::findCalendar($calendarid); +if(OC_User::getUser() != $calendar["userid"]){ + OC_JSON::error(); + exit; +} +$newdate = $_POST["newdate"]; +$caldata = array(); +//modified part of editeventform.php +$object = Sabre_VObject_Reader::read($data['calendardata']); +$vevent = $object->VEVENT; +$dtstart = $vevent->DTSTART; +$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); +switch($dtstart->getDateType()) { + case Sabre_VObject_Element_DateTime::LOCALTZ: + case Sabre_VObject_Element_DateTime::LOCAL: + $startdate = $dtstart->getDateTime()->format('d-m-Y'); + $starttime = $dtstart->getDateTime()->format('H:i'); + $enddate = $dtend->getDateTime()->format('d-m-Y'); + $endtime = $dtend->getDateTime()->format('H:i'); + $allday = false; + break; + case Sabre_VObject_Element_DateTime::DATE: + $startdate = $dtstart->getDateTime()->format('d-m-Y'); + $starttime = '00:00'; + $dtend->getDateTime()->modify('-1 day'); + $enddate = $dtend->getDateTime()->format('d-m-Y'); + $endtime = '23:59'; + $allday = true; + break; +} +$caldata["title"] = isset($vevent->SUMMARY) ? $vevent->SUMMARY->value : ''; +$caldata["location"] = isset($vevent->LOCATION) ? $vevent->LOCATION->value : ''; +$caldata["categories"] = array(); +if (isset($vevent->CATEGORIES)){ + $caldata["categories"] = explode(',', $vevent->CATEGORIES->value); + $caldata["categories"] = array_map('trim', $categories); +} +foreach($caldata["categories"] as $category){ + if (!in_array($category, $category_options)){ + array_unshift($category_options, $category); + } +} +$caldata["repeat"] = isset($vevent->CATEGORY) ? $vevent->CATEGORY->value : ''; +$caldata["description"] = isset($vevent->DESCRIPTION) ? $vevent->DESCRIPTION->value : ''; +//end part of editeventform.php +$startdatearray = explode("-", $startdate); +$starttimearray = explode(":", $starttime); +$startunix = mktime($starttimearray[0], $starttimearray[1], 0, $startdatearray[1], $startdatearray[0], $startdatearray[2]); +$enddatearray = explode("-", $enddate); +$endtimearray = explode(":", $endtime); +$endunix = mktime($endtimearray[0], $endtimearray[1], 0, $enddatearray[1], $enddatearray[0], $enddatearray[2]); +$difference = $endunix - $startunix;echo $difference . "\n"; +if(strlen($newdate) > 10){ + $newdatestringarray = explode("-", $newdate); + if($newdatestringarray[1] == "allday"){ + $allday = true; + $newdatestringarray[1] = "00:00"; + } +}else{ + $newdatestringarray = array(); + $newdatestringarray[0] = $newdate; + $newdatestringarray[1] = $starttime; +} +$newdatearray = explode(".", $newdatestringarray[0]); +$newtimearray = explode(":", $newdatestringarray[1]); +$newstartunix = mktime($newtimearray[0], $newtimearray[1], 0, $newdatearray[1], $newdatearray[0], $newdatearray[2]); +$newendunix = $newstartunix + $difference; +if($allday == true){ + $caldata["allday"] = true; +}else{ + unset($caldata["allday"]); +} +$caldata["from"] = date("d-m-Y", $newstartunix); +$caldata["fromtime"] = date("H:i", $newstartunix); echo $caldata["fromtime"]; +$caldata["to"] = date("d-m-Y", $newendunix); +$caldata["totime"] = date("H:i", $newendunix); echo $caldata["totime"]; +//modified part of editevent.php +$vcalendar = Sabre_VObject_Reader::read($data["calendardata"]); +OC_Calendar_Object::updateVCalendarFromRequest($caldata, $vcalendar); + +$result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); +OC_JSON::success(); +//end part of editevent.php +?>
\ No newline at end of file diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index 554d1f1b0a4..79689fbf859 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -155,6 +155,7 @@ Calendar={ Calendar.UI.updateView() }); }, + drageventid: '', updateDate:function(direction){ if(direction == 'forward' && this.current.forward) { this.current.forward(); @@ -247,6 +248,11 @@ Calendar={ .data('event_info', event) .hover(this.createEventPopup, this.hideEventPopup) + .draggable({ + drag: function() { + Calendar.UI.drageventid = event.id; + } + }) .click(this.editEvent); var color = this.calendars[event['calendarid']]['color']; if (color){ @@ -360,6 +366,12 @@ Calendar={ } },"json"); }, + moveevent:function(eventid, newstartdate){ + $.post(OC.filePath('calendar', 'ajax', 'moveevent.php'), { id: eventid, newdate: newstartdate}, + function(data) { + console.log("Event moved successfully"); + }); + }, showadvancedoptions:function(){ $("#advanced_options").css("display", "block"); $("#advanced_options_button").css("display", "none"); @@ -548,6 +560,22 @@ Calendar={ var today = new Date(); for(var i = 0; i <= 6; i++){ $("#oneweekview th." + Calendar.UI.weekdays[i]).html(Calendar.UI.formatDayShort((i+Calendar.firstdayofweek)%7) + Calendar.space + dates[i].getDate() + Calendar.space + Calendar.UI.formatMonthShort(dates[i].getMonth())); + $("#oneweekview td." + Calendar.UI.weekdays[i] + ".allday").attr('title', dates[i].getDate() + "." + String(parseInt(dates[i].getMonth()) + 1) + "." + dates[i].getFullYear() + "-" + "allday"); + $("#oneweekview td." + Calendar.UI.weekdays[i] + ".allday").droppable({ + drop: function() { + Calendar.UI.moveevent(Calendar.UI.drageventid, this.title); + Calendar.UI.loadEvents(); + } + }); + for(var ii = 0;ii <= 23; ii++){ + $("#oneweekview td." + Calendar.UI.weekdays[i] + "." + String(ii)).attr('title', dates[i].getDate() + "." + String(parseInt(dates[i].getMonth()) + 1) + "." + dates[i].getFullYear() + "-" + String(ii) + ":00"); + $("#oneweekview td." + Calendar.UI.weekdays[i] + "." + String(ii)).droppable({ + drop: function() { + Calendar.UI.moveevent(Calendar.UI.drageventid, this.title); + Calendar.UI.loadEvents(); + } + }); + } if(dates[i].getDate() == today.getDate() && dates[i].getMonth() == today.getMonth() && dates[i].getFullYear() == today.getFullYear()){ $("#oneweekview ." + Calendar.UI.weekdays[i]).addClass("thisday"); } @@ -724,6 +752,13 @@ Calendar={ var month = dates[i].getMonth(); var year = dates[i].getFullYear(); $("#onemonthview .week_" + week + " ." + Calendar.UI.weekdays[weekday] + " .dateinfo").html(dayofmonth + Calendar.space + Calendar.UI.formatMonthShort(month)); + $("#onemonthview .week_" + week + " ." + Calendar.UI.weekdays[weekday]).attr('title', dayofmonth + "." + String(parseInt(month) + 1) + "." + year); + $("#onemonthview .week_" + week + " ." + Calendar.UI.weekdays[weekday]).droppable({ + drop: function() { + Calendar.UI.moveevent(Calendar.UI.drageventid, this.title); + Calendar.UI.loadEvents(); + } + }); if(dayofmonth == today.getDate() && month == today.getMonth() && year == today.getFullYear()){ $("#onemonthview .week_" + week + " ." + Calendar.UI.weekdays[weekday]).addClass('thisday'); } |