Fix changing calendar data

This commit is contained in:
Bart Visscher 2011-10-19 19:07:56 +02:00
parent 3d8a1ccb3f
commit 2269f74c27
7 changed files with 72 additions and 51 deletions

View File

@ -13,5 +13,8 @@ if(!OC_USER::isLoggedIn()) {
OC_JSON::checkAppEnabled('calendar');
$calendarid = $_POST['calendarid'];
OC_Calendar_Calendar::setCalendarActive($calendarid, $_POST['active']);
$cal = OC_Calendar_Calendar::findCalendar($calendarid);
echo $cal['active'];
$calendar = OC_Calendar_Calendar::findCalendar($calendarid);
OC_JSON::success(array(
'active' => $calendar['active'],
'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar),
));

View File

@ -20,4 +20,7 @@ OC_Calendar_Calendar::setCalendarActive($calendarid, 1);
$calendar = OC_Calendar_Calendar::findCalendar($calendarid);
$tmpl = new OC_Template('calendar', 'part.choosecalendar.rowfields');
$tmpl->assign('calendar', $calendar);
OC_JSON::success(array('data' => $tmpl->fetchPage()));
OC_JSON::success(array(
'page' => $tmpl->fetchPage(),
'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar),
));

View File

@ -20,4 +20,7 @@ OC_Calendar_Calendar::setCalendarActive($calendarid, $_POST['active']);
$calendar = OC_Calendar_Calendar::findCalendar($calendarid);
$tmpl = new OC_Template('calendar', 'part.choosecalendar.rowfields');
$tmpl->assign('calendar', $calendar);
OC_JSON::success(array('data' => $tmpl->fetchPage()));
OC_JSON::success(array(
'page' => $tmpl->fetchPage(),
'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar),
));

View File

@ -17,12 +17,7 @@ if( count($calendars) == 0){
}
$eventSources = array();
foreach($calendars as $calendar){
$eventSources[] = array(
'url' => 'ajax/events.php?calendar_id='.$calendar['id'],
'backgroundColor' => '#'.$calendar['calendarcolor'],
'borderColor' => '#888',
'textColor' => 'black',
);
$eventSources[] = OC_Calendar_Calendar::getEventSourceInfo($calendar);
}
OC_Util::addScript('calendar', 'calendar');
OC_Util::addStyle('calendar', 'style');

View File

@ -259,19 +259,6 @@ Calendar={
$('#caldav_url').show();
$("#caldav_url_close").show();
},
deleteCalendar:function(calid){
var check = confirm("Do you really want to delete this calendar?");
if(check == false){
return false;
}else{
$.post(OC.filePath('calendar', 'ajax', 'deletecalendar.php'), { calendarid: calid},
function(data) {
Calendar.UI.refetchEvents();
$('#choosecalendar_dialog').dialog('destroy').remove();
Calendar.UI.Calendar.overview();
});
}
},
initscroll:function(){
if(window.addEventListener)
document.addEventListener('DOMMouseScroll', Calendar.UI.scrollcalendar);
@ -328,8 +315,14 @@ Calendar={
{
$.post(OC.filePath('calendar', 'ajax', 'activation.php'), { calendarid: calendarid, active: checkbox.checked?1:0 },
function(data) {
checkbox.checked = data == 1;
Calendar.UI.refetchEvents();
if (data.status == 'success'){
checkbox.checked = data.active == 1;
if (data.active == 1){
$('#calendar_holder').fullCalendar('addEventSource', data.eventSource);
}else{
$('#calendar_holder').fullCalendar('removeEventSource', data.eventSource.url);
}
}
});
},
newCalendar:function(object){
@ -344,6 +337,46 @@ Calendar={
function(){Calendar.UI.Calendar.colorPicker(this)});
$(object).closest('tr').after(tr).hide();
},
deleteCalendar:function(calid){
var check = confirm("Do you really want to delete this calendar?");
if(check == false){
return false;
}else{
$.post(OC.filePath('calendar', 'ajax', 'deletecalendar.php'), { calendarid: calid},
function(data) {
if (data.status == 'success'){
var url = 'ajax/events.php?calendar_id='+calid;
$('#calendar_holder').fullCalendar('removeEventSource', url);
$('#choosecalendar_dialog').dialog('destroy').remove();
Calendar.UI.Calendar.overview();
}
});
}
},
submit:function(button, calendarid){
var displayname = $("#displayname_"+calendarid).val();
var active = $("#edit_active_"+calendarid+":checked").length;
var description = $("#description_"+calendarid).val();
var calendarcolor = $("#calendarcolor_"+calendarid).val();
var url;
if (calendarid == 'new'){
url = "ajax/createcalendar.php";
}else{
url = "ajax/updatecalendar.php";
}
$.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor },
function(data){
if(data.status == 'success'){
$(button).closest('tr').prev().html(data.page).show().next().remove();
$('#calendar_holder').fullCalendar('removeEventSource', data.eventSource.url);
$('#calendar_holder').fullCalendar('addEventSource', data.eventSource);
}
}, 'json');
},
cancel:function(button, calendarid){
$(button).closest('tr').prev().show().next().remove();
},
colorPicker:function(container){
// based on jquery-colorpicker at jquery.webspirited.com
var obj = $('.colorpicker', container);
@ -369,31 +402,7 @@ Calendar={
position: 'absolute',
left: -10000
});
},
submit:function(button, calendarid){
var displayname = $("#displayname_"+calendarid).val();
var active = $("#edit_active_"+calendarid+":checked").length;
var description = $("#description_"+calendarid).val();
var calendarcolor = $("#calendarcolor_"+calendarid).val();
var url;
if (calendarid == 'new'){
url = "ajax/createcalendar.php";
}else{
url = "ajax/updatecalendar.php";
}
$.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor },
function(data){
if(data.error == "true"){
}else{
$(button).closest('tr').prev().html(data.data).show().next().remove();
Calendar.UI.refetchEvents();
}
}, 'json');
},
cancel:function(button, calendarid){
$(button).closest('tr').prev().show().next().remove();
},
}
},
List:{
removeEvents:function(){

View File

@ -240,4 +240,12 @@ class OC_Calendar_Calendar{
'ecc255', // dark yellow
);
}
public static function getEventSourceInfo($calendar){
return array(
'url' => 'ajax/events.php?calendar_id='.$calendar['id'],
'backgroundColor' => '#'.$calendar['calendarcolor'],
'borderColor' => '#888',
'textColor' => 'black',
);
}
}

View File

@ -1,4 +1,4 @@
<?php
echo "<td width=\"20px\"><input id=\"active_" . $_['calendar']["id"] . "\" type=\"checkbox\" onClick=\"Calendar.UI.Calendar.activation(this, " . $_['calendar']["id"] . ")\"" . ($_['calendar']["active"] ? ' checked="checked"' : '') . "></td>";
echo "<td><label for=\"active_" . $_['calendar']["id"] . "\">" . $_['calendar']["displayname"] . "</label></td>";
echo "<td width=\"20px\"><a href=\"#\" onclick=\"Calendar.UI.showCalDAVUrl('" . OC_User::getUser() . "', '" . $_['calendar']["uri"] . "');\" title=\"" . $l->t("CalDav Link") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/public.svg\"></a></td><td width=\"20px\"><a href=\"export.php?calid=" . $_['calendar']["id"] . "\" title=\"" . $l->t("Download") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/download.svg\"></a></td><td width=\"20px\"><a href=\"#\" title=\"" . $l->t("Edit") . "\" class=\"action\" onclick=\"Calendar.UI.Calendar.edit(this, " . $_['calendar']["id"] . ");\"><img class=\"svg action\" src=\"../../core/img/actions/rename.svg\"></a></td><td width=\"20px\"><a href=\"#\" onclick=\"Calendar.UI.deleteCalendar('" . $_['calendar']["id"] . "');\" title=\"" . $l->t("Delete") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/delete.svg\"></a></td>";
echo "<td width=\"20px\"><a href=\"#\" onclick=\"Calendar.UI.showCalDAVUrl('" . OC_User::getUser() . "', '" . $_['calendar']["uri"] . "');\" title=\"" . $l->t("CalDav Link") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/public.svg\"></a></td><td width=\"20px\"><a href=\"export.php?calid=" . $_['calendar']["id"] . "\" title=\"" . $l->t("Download") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/download.svg\"></a></td><td width=\"20px\"><a href=\"#\" title=\"" . $l->t("Edit") . "\" class=\"action\" onclick=\"Calendar.UI.Calendar.edit(this, " . $_['calendar']["id"] . ");\"><img class=\"svg action\" src=\"../../core/img/actions/rename.svg\"></a></td><td width=\"20px\"><a href=\"#\" onclick=\"Calendar.UI.Calendar.deleteCalendar('" . $_['calendar']["id"] . "');\" title=\"" . $l->t("Delete") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/delete.svg\"></a></td>";