Implement select event creation

This commit is contained in:
Bart Visscher 2011-10-25 19:57:20 +02:00
Родитель 950018b5c3
Коммит 50649ad0d1
2 изменённых файлов: 31 добавлений и 52 удалений

Просмотреть файл

@ -15,39 +15,35 @@ if(!OC_USER::isLoggedIn()) {
} }
OC_JSON::checkAppEnabled('calendar'); OC_JSON::checkAppEnabled('calendar');
if (!isset($_POST['start'])){
OC_JSON::error();
die;
}
$start = $_POST['start'];
$end = $_POST['end'];
$allday = $_POST['allday'];
if (!$end){
$duration = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'duration', '60');
$end = $start + ($duration * 60);
}
$start = new DateTime('@'.$start);
$end = new DateTime('@'.$end);
$timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', 'Europe/London');
$start->setTimezone(new DateTimeZone($timezone));
$end->setTimezone(new DateTimeZone($timezone));
$calendar_options = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); $calendar_options = OC_Calendar_Calendar::allCalendars(OC_User::getUser());
$category_options = OC_Calendar_Object::getCategoryOptions($l10n); $category_options = OC_Calendar_Object::getCategoryOptions($l10n);
$repeat_options = OC_Calendar_Object::getRepeatOptions($l10n); $repeat_options = OC_Calendar_Object::getRepeatOptions($l10n);
$startday = substr($_GET['d'], 0, 2);
$startmonth = substr($_GET['d'], 2, 2);
$startyear = substr($_GET['d'], 4, 4);
$allday = $_GET['t'] == 'allday';
if(!$allday){
$starthour = substr($_GET['t'], 0, 2);
$startminutes = substr($_GET['t'], 2, 2);
}else{
$starthour = '00';
$startminutes = '00';
}
$datetimestamp = mktime($starthour, $startminutes, 0, $startmonth, $startday, $startyear);
$duration = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'duration', "60");
$datetimestamp = $datetimestamp + ($duration * 60);
$endmonth = date("m", $datetimestamp);
$endday = date("d", $datetimestamp);
$endyear = date("Y", $datetimestamp);
$endtime = date("G", $datetimestamp);
$endminutes = date("i", $datetimestamp);
$tmpl = new OC_Template('calendar', 'part.newevent'); $tmpl = new OC_Template('calendar', 'part.newevent');
$tmpl->assign('calendar_options', $calendar_options); $tmpl->assign('calendar_options', $calendar_options);
$tmpl->assign('category_options', $category_options); $tmpl->assign('category_options', $category_options);
$tmpl->assign('startdate', $startday . '-' . $startmonth . '-' . $startyear); $tmpl->assign('startdate', $start->format('d-m-Y'));
$tmpl->assign('starttime', $starthour . ':' . $startminutes); $tmpl->assign('starttime', $start->format('H:i'));
$tmpl->assign('enddate', $endday . '-' . $endmonth . '-' . $endyear); $tmpl->assign('enddate', $end->format('d-m-Y'));
$tmpl->assign('endtime', ($endtime <= 9 ? '0' : '') . $endtime . ':' . $endminutes); $tmpl->assign('endtime', $end->format('H:i'));
$tmpl->assign('allday', $allday); $tmpl->assign('allday', $allday);
$tmpl->printpage(); $tmpl->printpage();
?> ?>

Просмотреть файл

@ -31,36 +31,17 @@ Calendar={
} }
}); });
}, },
newEvent:function(date, allDay, jsEvent, view){ newEvent:function(start, end, allday){
var dayofmonth = date.getDate(); start = Math.round(start.getTime()/1000);
var month = date.getMonth(); if (end){
var year = date.getFullYear(); end = Math.round(end.getTime()/1000);
var hour = date.getHours();
var min = date.getMinutes();
if(dayofmonth <= 9){
dayofmonth = '0' + dayofmonth;
}
month++;
if(month <= 9){
month = '0' + month;
}
if(hour <= 9){
hour = '0' + hour;
}
if(min <= 9){
min = '0' + min;
}
var date = String(dayofmonth) + String(month) + String(year);
if (allDay){
var time = 'allday';
}else{
var time = String(hour) + String(min);
} }
$('#calendar_holder').fullCalendar('unselect');
if($('#event').dialog('isOpen') == true){ if($('#event').dialog('isOpen') == true){
// TODO: save event // TODO: save event
$('#event').dialog('destroy').remove(); $('#event').dialog('destroy').remove();
}else{ }else{
$('#dialog_holder').load(OC.filePath('calendar', 'ajax', 'neweventform.php') + '?d=' + date + '&t=' + time, Calendar.UI.startEventDialog); $('#dialog_holder').load(OC.filePath('calendar', 'ajax', 'neweventform.php'), {start:start, end:end, allday:allday?1:0}, Calendar.UI.startEventDialog);
} }
}, },
editEvent:function(calEvent, jsEvent, view){ editEvent:function(calEvent, jsEvent, view){
@ -509,7 +490,9 @@ $(document).ready(function(){
$('#datecontrol_date').html(view.title); $('#datecontrol_date').html(view.title);
$.get(OC.filePath('calendar', 'ajax', 'changeview.php') + "?v="+view.name); $.get(OC.filePath('calendar', 'ajax', 'changeview.php') + "?v="+view.name);
}, },
dayClick: Calendar.UI.newEvent, selectable: true,
selectHelper: true,
select: Calendar.UI.newEvent,
eventClick: Calendar.UI.editEvent, eventClick: Calendar.UI.editEvent,
eventDrop: Calendar.UI.moveEvent, eventDrop: Calendar.UI.moveEvent,
eventResize: Calendar.UI.resizeEvent, eventResize: Calendar.UI.resizeEvent,