Allow to edit calendar comments
authorJoey Schulze <joey@infodrom.org>
Thu, 11 Jul 2019 19:51:42 +0000 (21:51 +0200)
committerJoey Schulze <joey@infodrom.org>
Thu, 11 Jul 2019 19:53:26 +0000 (21:53 +0200)
class/calendar_item.class.php
class/calendar_item_log.class.php [new file with mode: 0644]
src/Infodrom/calendar/index.wml

index b8fb50d..08c656d 100644 (file)
@@ -108,26 +108,33 @@ class Calendar_Item extends DatabaseTable {
 
     $items = array();
     $items[] = array('dt' => substr($this->data->created,0,16),
+                    'edit' => false,
                     'log' => 'Item created');
 
-    $sql = sprintf("SELECT name,url,comment,sys_edit,sys_user " .
+    $sql = sprintf("SELECT id,name,url,comment,sys_edit,sys_user " .
                   "FROM calendar_item_log WHERE dav_id = %d ORDER BY sys_edit", $this->id);
     foreach ($this->fetchObjectList($sql) as $row) {
       if (strlen($row->url))
          $items[] = array('dt' => substr($row->sys_edit,0,16),
+                          'edit' => false,
                           'log' => sprintf('<a href="%s" target="_blank">%s</a>',
                                           $row->url,
                                           $row->name ? $row->name : 'Link'));
       if (strlen($row->comment))
          $items[] = array('dt' => substr($row->sys_edit,0,16),
+                          'id' => $row->id,
+                          'edit' => true,
                           'log' => $row->comment);
     }
 
     foreach ($items as $item) {
        $color = !$color;
-       $out .= sprintf('<div class="row%d"><div class="logl">%s</div><div class="logr">%s</div><div class="clear"></div></div>',
+       $out .= sprintf('<div class="row%d"><div class="logl">%s</div><div class="logr%s"%s>%s</div><div class="clear"></div></div>',
                        $color,
-                       $item['dt'], $item['log']);
+                       $item['dt'],
+                       $item['edit'] ? ' editable' : '',
+                       $item['edit'] ? sprintf(' route="Calendar_Item_Log/EditComment" item_id="%d"', $item['id']) : '',
+                       $item['log']);
     }
 
     return array('html' => array('log' => $out));
diff --git a/class/calendar_item_log.class.php b/class/calendar_item_log.class.php
new file mode 100644 (file)
index 0000000..4d361b2
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+class Calendar_Item_Log extends DatabaseTable {
+
+  public function __construct($id=false)
+  {
+    $db = new Database(DBDRIVER, DBHOST, DAV_DBNAME, DBUSER, DBPASS);
+
+    parent::__construct('calendar_item_log', $id, $db);
+  }
+
+  public function ajaxEditComment(Array $data)
+  {
+      return $this->modify('comment', utf8_decode($data['content']));
+  }
+}
index 558e86c..7c63676 100644 (file)
@@ -2,6 +2,7 @@
 
 <future>
 <page func="Infodrom Oldenburg" title="Termine">
+<script type="text/javascript" src="<root_prefix>jquery.editable.js"></script>
 
 <style type="text/css">
 @media only screen and (max-device-width: 400px) {
@@ -296,7 +297,10 @@ function show_log()
        logwindow.openPopup();
     }
 
-    $.invoke('Calendar_Item/Log', {id: $('div#menu').attr('dav_id')});
+    $.invoke('Calendar_Item/Log', {id: $('div#menu').attr('dav_id')}, function(data){
+       if (!is_mobile())
+           make_editable('div#log div.editable');
+    });
 }
 
 var commentwindow = false;