diff --git a/ajax/calendar/delete.php b/ajax/calendar/delete.php index f3924bbfe..834b026ad 100644 --- a/ajax/calendar/delete.php +++ b/ajax/calendar/delete.php @@ -11,7 +11,7 @@ OCP\JSON::checkAppEnabled('calendar'); OCP\JSON::callCheck(); -$cal = $_POST["calendarid"]; +$cal = isset($_POST["calendarid"]) ? $_POST["calendarid"] : null; try { $del = OC_Calendar_Calendar::deleteCalendar($cal); @@ -22,5 +22,4 @@ } } catch(Exception $e) { OCP\JSON::error(array('message'=>$e->getMessage())); - exit; } diff --git a/ajax/calendar/makedefault.php b/ajax/calendar/makedefault.php new file mode 100644 index 000000000..42a7f29c4 --- /dev/null +++ b/ajax/calendar/makedefault.php @@ -0,0 +1,25 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + + +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('calendar'); +OCP\JSON::callCheck(); + +$cal = isset($_POST["calendarid"]) ? $_POST["calendarid"] : null; + +try { + $def = OC_Calendar_Calendar::makeDefault($cal); + if($def === true) { + OCP\JSON::success(); + }else{ + OCP\JSON::error(array('error'=>'dberror')); + } +} catch(Exception $e) { + OCP\JSON::error(array('message'=>$e->getMessage())); +} diff --git a/css/style.css b/css/style.css index 9244f4552..b62a7c726 100644 --- a/css/style.css +++ b/css/style.css @@ -551,6 +551,16 @@ button.category{margin:0 3px;} top: 44px; } +.icon-default { + background-image: url('../img/star.png'); +} + +.not-set { + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=10)"; + filter: alpha(opacity = 10); + opacity: 0.1; +} + #navigation-list #caldav_url_entry { min-height: 0; } diff --git a/img/star.png b/img/star.png new file mode 100644 index 000000000..2fe31d944 Binary files /dev/null and b/img/star.png differ diff --git a/js/calendar.js b/js/calendar.js index 9e70618ef..47c3eccf1 100644 --- a/js/calendar.js +++ b/js/calendar.js @@ -628,6 +628,20 @@ Calendar={ }); } }, + makeDefault:function(calid){ + + $.post(OC.filePath('calendar', 'ajax/calendar', 'makedefault.php'), { calendarid: calid}, + function(data) { + if (data.status == 'success'){ + var url = 'ajax/events.php?calendar_id='+calid; + if($('#navigation-list li[data-id="'+calid+'"] span a').hasClass( "icon-default" )) + { + $('#navigation-list li span a[id="chooseCalendar-make-def"]').addClass("not-set"); + $('#navigation-list li[data-id="'+calid+'"] span a[id="chooseCalendar-make-def"]').removeClass("not-set"); + } + } + }); + }, submit:function(button, calendarid){ var displayname = $.trim($("#displayname_"+calendarid).val()); var active = $("#active_"+calendarid).attr("checked") ? 1 : 0; diff --git a/js/on-event.js b/js/on-event.js index accb0e11e..e7dc1f683 100644 --- a/js/on-event.js +++ b/js/on-event.js @@ -59,6 +59,9 @@ $(document).on('click', '#chooseCalendar-edit', function () { $(document).on('click', '#chooseCalendar-delete', function () { Calendar.UI.Calendar.deleteCalendar($(this).data('id')); }); +$(document).on('click','#chooseCalendar-make-def', function () { + Calendar.UI.Calendar.makeDefault($(this).data('id')); +}); $(document).on('click', '#editCalendar-submit', function () { Calendar.UI.Calendar.submit($(this), $(this).data('id')); }); diff --git a/lib/calendar.php b/lib/calendar.php index f2dc4b446..59e4390bf 100644 --- a/lib/calendar.php +++ b/lib/calendar.php @@ -280,6 +280,28 @@ public static function deleteCalendar($id) { return true; } + /** + * @brief Sets a calendar default and new events are created in it by default + * @param integer $id + * @return boolean + */ + public static function makeDefault($id) { + $calendar = self::find($id); + if ($calendar['userid'] != OCP\User::getUser()) { + $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id); + if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_CREATE)) { + throw new Exception( + OC_Calendar_App::$l10n->t( + 'You do not have the permissions to update this calendar.' + ) + ); + } + } + OCP\Config::setUserValue(OCP\User::getUser(), "calendar", "defaultcalendar", $id); + + return true; + } + /** * @brief merges two calendars * @param integer $id1 diff --git a/templates/part.choosecalendar.rowfields.php b/templates/part.choosecalendar.rowfields.php index 37b93c883..b5d596e23 100644 --- a/templates/part.choosecalendar.rowfields.php +++ b/templates/part.choosecalendar.rowfields.php @@ -40,6 +40,13 @@ + + + > + + + + diff --git a/templates/part.eventform.php b/templates/part.eventform.php index 82d7fc1b4..798e38b60 100644 --- a/templates/part.eventform.php +++ b/templates/part.eventform.php @@ -30,7 +30,7 @@ } } $sortedCalendars = array_merge($enabledCalendars, $disabledCalendars); - print_unescaped(OCP\html_select_options($sortedCalendars, $_['calendar'], array('value'=>'id', 'label'=>'displayname'))); ?> + print_unescaped(OCP\html_select_options($sortedCalendars, OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'defaultcalendar', $_['calendar']), array('value'=>'id', 'label'=>'displayname'))); ?>