Skip to content
This repository has been archived by the owner on Oct 31, 2018. It is now read-only.

Commit

Permalink
Let users set a default calendar for new events
Browse files Browse the repository at this point in the history
This should fix: #348

Users can set one calendar default by clicking on the star.
New events will be created in the default calendar.
  • Loading branch information
vgezer committed Nov 20, 2014
1 parent 4c06265 commit 5521ed2
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 3 deletions.
3 changes: 1 addition & 2 deletions ajax/calendar/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -22,5 +22,4 @@
}
} catch(Exception $e) {
OCP\JSON::error(array('message'=>$e->getMessage()));
exit;
}
25 changes: 25 additions & 0 deletions ajax/calendar/makedefault.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright (c) 2014 Volkan Gezer <volkangezer at gmail dot com>
* 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()));
}
10 changes: 10 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Binary file added img/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions js/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions js/on-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
Expand Down
22 changes: 22 additions & 0 deletions lib/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions templates/part.choosecalendar.rowfields.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@

</span>

<span class="action">
<?php if ($_['calendar']['permissions'] & OCP\PERMISSION_CREATE) { ?>
<a href="#" id="chooseCalendar-make-def" data-id="<?php p($_['calendar']['id']) ?>" title="<?php p($l->t('Set as Default Calendar')) ?>" <?php OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'defaultcalendar')==$_['calendar']['id']? print_unescaped('class="icon-default"') : print_unescaped('class="icon-default not-set"')?>></a>
<?php } ?>

</span>

<span class="action">
<?php if ($_['calendar']['permissions'] & OCP\PERMISSION_DELETE) { ?>
<a href="#" id="chooseCalendar-delete" data-id="<?php p($_['calendar']['id']) ?>" title="<?php p($l->t('Delete')) ?>" class="icon-delete"></a>
Expand Down
2 changes: 1 addition & 1 deletion templates/part.eventform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))); ?>
</select>
<?php } else { ?>
<input style="display:none;" type="hidden" name="calendar" value="<?php p($_['calendar_options'][0]['id']); ?>">
Expand Down

0 comments on commit 5521ed2

Please sign in to comment.