Skip to content

Commit

Permalink
Move system calendars to dedicated section.
Browse files Browse the repository at this point in the history
Still need to implement adding new system calendars from ajax
view.
  • Loading branch information
mrubinsk committed Apr 21, 2015
1 parent a9a6e4b commit 91b901e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
19 changes: 18 additions & 1 deletion kronolith/js/kronolith.js
Expand Up @@ -944,6 +944,12 @@ KronolithCore = {
if (!div) {
div = this.getCalendarList(type, cal.owner);
}

// System calendars are still internal for purposes of the backend.
if (type == 'system') {
type = 'internal';
}

noItems = div.previous();
if (noItems &&
noItems.tagName == 'DIV' &&
Expand Down Expand Up @@ -1005,7 +1011,7 @@ KronolithCore = {
extContainer = $('kronolithExternalCalendars');

$H(Kronolith.conf.calendars.internal).each(function(cal) {
this.insertCalendarInList('internal', cal.key, cal.value);
this.insertCalendarInList(cal.value.system ? 'system' : 'internal', cal.key, cal.value);
}, this);

if (Kronolith.conf.tasks) {
Expand Down Expand Up @@ -1073,6 +1079,8 @@ KronolithCore = {
getCalendarList: function(type, personal)
{
switch (type) {
case 'system':
return $('kronolithSystemCalendars');
case 'internal':
return personal
? $('kronolithMyCalendars')
Expand Down Expand Up @@ -3223,10 +3231,12 @@ KronolithCore = {
if (newCalendar || info.owner) {
if (info.system) {
$('kronolithPOwnerInput').hide();
$('kronolithCalendarSystem').setValue(1);
$('kronolithSystemOwner').show();
} else {
$('kronolithPOwnerInput').show();
$('kronolithSystemOwner').hide();
$('kronolithCalendarSystem').setValue(0);
}
if (type == 'internal' || type == 'tasklists' || type == 'resource') {
this.updateGroupDropDown([['kronolithC' + type + 'PGList', this.updateGroupPerms.bind(this, type)],
Expand Down Expand Up @@ -3744,8 +3754,15 @@ KronolithCore = {
if (this.colorPicker) {
this.colorPicker.hide();
}

var data = form.serialize({ hash: true });

// Ensure we keep null owner for system calendars. Do this here instead
// of in the editCalendarCallback so we don't wipe out the default
// value for other calendars.
if (data.system == 1) {
data.owner_input = null;
}
if (data.type == 'holiday') {
this.insertCalendarInList('holiday', data.driver, Kronolith.conf.calendars.holiday[data.driver]);
this.toggleCalendar('holiday', data.driver);
Expand Down
4 changes: 2 additions & 2 deletions kronolith/lib/Ajax/Application/Handler.php
Expand Up @@ -889,7 +889,7 @@ public function saveCalendar()
switch ($this->vars->type) {
case 'internal':
$info = array();
foreach (array('name', 'color', 'description', 'tags') as $key) {
foreach (array('name', 'color', 'description', 'tags', 'system') as $key) {
$info[$key] = $this->vars->$key;
}

Expand Down Expand Up @@ -923,7 +923,7 @@ public function saveCalendar()
$original_owner = $calendar->get('owner');
Kronolith::updateShare($calendar, $info);
Kronolith::readPermsForm($calendar);
if ($calendar->get('owner') != $original_owner) {
if (!$info['system'] && $calendar->get('owner') != $original_owner) {
$result->deleted = true;
}
if ($calendar->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::SHOW)) {
Expand Down
15 changes: 12 additions & 3 deletions kronolith/lib/Calendar/Internal.php
Expand Up @@ -131,6 +131,16 @@ public function caldavUrl()
return $this->_caldavUrl($this->_share->getName(), 'calendar');
}

/**
* Returns if this is a system calendar.
*
* @return boolean True if system calendar, otherwise false.
*/
public function isSystem()
{
return empty($this->owner()) && ($this->_share->get('type') == Kronolith::SHARE_TYPE_USER);
}

/**
* Returns a hash representing this calendar.
*
Expand All @@ -141,15 +151,14 @@ public function toHash()
global $calendar_manager, $conf, $injector, $registry;

$id = $this->_share->getName();
$is_system = empty($this->owner()) && $this->_share->get('type') == Kronolith::SHARE_TYPE_USER;
$owner = $registry->getAuth() &&
($this->owner() == $registry->getAuth() ||
$is_system && $registry->isAdmin());
$this->isSystem() && $registry->isAdmin());

$hash = parent::toHash();
$hash['name'] = $this->name();
$hash['owner'] = $owner;
$hash['system'] = $is_system;
$hash['system'] = $this->isSystem();
$hash['users'] = Kronolith::listShareUsers($this->_share);
$hash['show'] = in_array(
$id,
Expand Down
3 changes: 1 addition & 2 deletions kronolith/lib/Kronolith.php
Expand Up @@ -1322,8 +1322,7 @@ public static function updateShare(&$calendar, $info)
$calendar->set('name', $info['name']);
$calendar->set('color', $info['color']);
$calendar->set('desc', $info['description']);
$calendar->set('owner', empty($info['system']) ? $GLOBALS['registry']->getAuth() : null);

$calendar->set('owner', ($info['system'] == 0) ? $GLOBALS['registry']->getAuth() : null);
try {
$calendar->save();
} catch (Horde_Share_Exception $e) {
Expand Down
1 change: 1 addition & 0 deletions kronolith/templates/chunks/calendar.php
Expand Up @@ -57,6 +57,7 @@
<input type="hidden" name="import_step" value="1" />
<input type="hidden" name="import_format" value="icalendar" />
<input type="hidden" name="import_ajax" value="1" />
<input type="hidden" name="system" id="kronolithCalendarSystem" value="0" />
<?php Horde_Util::pformInput() ?>
<?php endif; ?>

Expand Down
12 changes: 12 additions & 0 deletions kronolith/templates/dynamic/sidebar.html.php
Expand Up @@ -51,6 +51,18 @@
</div>
<?php endif; ?>

<div class="horde-sidebar-split"></div>
<div>
<h3>
<span class="horde-expand" title="<?php echo _("Expand") ?>"><?php echo _("System Calendars") ?></span>
</h3>

<div style="display:none">
<div class="horde-info"><?php echo _("No items to display") ?></div>
<div id="kronolithSystemCalendars" class="horde-resources"></div>
</div>
</div>

<div class="horde-sidebar-split"></div>
<div>
<h3>
Expand Down

0 comments on commit 91b901e

Please sign in to comment.