$vars->set('name', $calendar->get('name'));
$vars->set('description', $calendar->get('desc'));
+$tags = new Kronolith_Tagger();
+$vars->set('tags', implode(',', array_values($tags->getTags($calendar->getName(), 'calendar'))));
$title = $form->getTitle();
require KRONOLITH_TEMPLATES . '/common-header.inc';
require KRONOLITH_TEMPLATES . '/menu.inc';
if (!$imple) {
exit;
}
-
$args = array();
foreach ($path as $pair) {
if (strpos($pair, '=') === false) {
new Ajax.Request(KronolithVar.pref_api_url, { parameters: { app: 'kronolith', pref: 'show_panel', value: pref_value } });
}
+function removeTag(tagid)
+{
+
+}
document.observe('dom:loaded', function() {
$$('#pageControlsInner .checkbox').invoke('observe', 'click', function() {
Views.invalidate();
--- /dev/null
+function addTag()
+{
+ if (!$('addtag').value.blank()) {
+ var params = new Object();
+ params.requestType="TagActions/action=add/gallery=" + tagActions.gallery + "/tags=" + $('addtag').value;
+ new Ajax.Updater({success:'tags'},
+ tagActions.url,
+ {
+ method: 'post',
+ parameters: params,
+ onComplete: function() {$('addtag').value = "";}
+ }
+ );
+ }
+
+ return true;
+}
+
+function removeTag(resource, type, tagid, endpoint)
+{
+ var params = new Object();
+ params.imple = "TagActions/action=remove/resource=" + resource + "/type=" + type + "/tags=" + tagid;
+ new Ajax.Updater({success:'tags-' + resource},
+ endpoint,
+ {
+ method: 'post',
+ parameters: params
+ }
+ );
+ return true;
+}
+
+// Since onsubmit is never called when submitting programatically we
+// can use this function to add tags when we press enter on the tag form.
+function submitcheck()
+{
+ return !addTag();
+}
\ No newline at end of file
$this->addVariable(_("Name"), 'name', 'text', true);
$this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
-
+ $this->addVariable(_("Tags"), 'tags', 'text', false);
$this->setButtons(array(_("Create")));
}
}
$calendar->set('name', $this->_vars->get('name'));
$calendar->set('desc', $this->_vars->get('description'));
+ $tagger = new Kronolith_Tagger();
+ $tagger->tag($calendar->getName(), explode(',', $this->_vars->get('tags')), 'calendar');
return $GLOBALS['kronolith_shares']->addShare($calendar);
}
$this->addHidden('', 'c', 'text', true);
$this->addVariable(_("Name"), 'name', 'text', true);
$this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
-
+ $this->addVariable(_("Tags"), 'tags', 'text', false);
$this->setButtons(array(_("Save")));
}
$new_name = $this->_vars->get('name');
$this->_calendar->set('name', $new_name);
$this->_calendar->set('desc', $this->_vars->get('description'));
-
+ $tagger = new Kronolith_Tagger();
+ $tagger->tag($this->_calendar->getName(), explode(',', $this->_vars->get('tags')), 'calendar');
if ($original_name != $new_name) {
$result = $GLOBALS['kronolith_driver']->rename($original_name, $new_name);
if (is_a($result, 'PEAR_Error')) {
--- /dev/null
+<?php
+/**
+ *
+ */
+class Kronolith_Imple_TagActions extends Kronolith_Imple
+{
+ public function attach()
+ {
+ // TODO: HACK! attach is called in the contructor which means that even
+ // if we are only handling the request, we try to attach().
+ if (count($this->_params) == 0) {
+ return;
+ }
+ Horde::addScriptFile('tagactions.js');
+ $dom_id = $this->_params['triggerId'];
+ $action = $this->_params['action'];
+ $content_id = $this->_params['resource'];
+ $content_type = $this->_params['type'];
+ $tag_id = $this->_params['tagId'];
+ $endpoint = Horde::url('imple.php', true);
+
+ if ($action == 'add') {
+ $js = "Event.observe('" . $dom_id . "', 'click', function(event) {addTag(); Event.stop(event)});";
+ } elseif ($action == 'delete') {
+ $js = "Event.observe('" . $dom_id . "', 'click', function(event) {removeTag('" . $content_id . "', '" . $content_type . "', " . $tag_id . ", '" . $endpoint . "'); Event.stop(event)});";
+ }
+ Kronolith::addInlineScript($js, 'window');
+ }
+
+ public function handle($args)
+ {
+ global $ansel_storage;
+
+ $request = $args['action'];
+ $content = array('id' => $args['resource'], 'type' => $args['type']);
+ $tags = $args['tags'];
+
+ /* Get the resource owner */
+ /* Perms checks */
+
+ switch ($request) {
+ case 'add':
+ break;
+ case 'remove':
+ $tagger = new Kronolith_Tagger();
+ //$tagger->
+
+
+ break;
+ }
+ }
+
+ private function _getTagHtml($tags, $hasEdit)
+ {
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Kronolith interface to the Horde_Content tagger
+ *
+ *
+ */
+
+// Note:: Autoloading depends on there being a registry entry for content
+Horde_Autoloader::addClassPattern('/^Content_/',
+ $GLOBALS['registry']->get('fileroot', 'content') . '/lib/');
+
+class Kronolith_Tagger {
+
+ protected static $_type_ids = array();
+ protected static $_tagger;
+
+ public function __construct()
+ {
+ if (is_null(self::$_tagger)) {
+ // Set up the context for the tagger and related content classes
+ $GLOBALS['conf']['sql']['adapter'] = $GLOBALS['conf']['sql']['phptype'] == 'mysqli' ?
+ 'mysqli' :
+ 'pdo_' . $GLOBALS['conf']['sql']['phptype'];
+
+ Horde_Db::setAdapter(Horde_Db_Adapter::factory($GLOBALS['conf']['sql']));
+
+ $context = array('dbAdapter' => Horde_Db::getAdapter());
+ $user_mgr = new Content_Users_Manager($context);
+ $type_mgr = new Content_Types_Manager($context);
+
+ // Objects_Manager requires a Types_Manager
+ $context['typeManager'] = $type_mgr;
+ $object_mgr = new Content_Objects_Manager($context);
+
+ // Create the Content_Tagger
+ $context['userManager'] = $user_mgr;
+ $context['objectManager'] = $object_mgr;
+
+ self::$_tagger = new Content_Tagger($context);
+ $types = $type_mgr->ensureTypes(array('calendar', 'event'));
+ self::$_type_ids = array('calendar' => $types[0], 'event' => $types[1]);
+ }
+ }
+
+ /**
+ * Tag a kronolith object with any number of tags.
+ *
+ * @param string $localId The identifier of the kronolith object.
+ * @param mixed $tags Either a single tag string or an array of tags.
+ * @param string $content_type The type of object we are tagging (event/calendar).
+ *
+ * @return void
+ */
+ public function tag($localId, $tags, $content_type = 'event')
+ {
+ self::$_tagger->tag(Auth::getAuth(),
+ array('object' => $localId,
+ 'type' => self::$_type_ids[$content_type]),
+ $tags);
+ }
+
+ /**
+ * Retrieve the tags on a given object(s)
+ */
+ public function getTags($localId, $type = 'event')
+ {
+ if (!is_array($localId)) {
+ $localId = array($localId);
+ }
+ $tags = array();
+ foreach ($localId as $id) {
+ $tags = $tags + self::$_tagger->getTags(array('objectId' => array('object' => $id, 'type' => $type)));
+ }
+var_dump($tags);
+ return $tags;
+ }
+
+ public function untag($localId, $tag, $content_type = 'event')
+ {
+ //self::$_tagger->
+ }
+
+ /**
+ * tag search - return all types of content we care about tagged with
+ * the passed in tags
+ *
+ * @param array $tags An array of tag ids.
+ */
+ public function search($tags, $content_type = null)
+ {
+ $this->getObjects(array('tagId' => $tags, ''));
+ }
+
+}
$shared_calendars[$id] = $cal;
}
}
+
+$tagger = new Kronolith_Tagger();
?>
<div id="pageControls">
<h4><?php echo _("My Calendars:") ?></h4>
<ul id="mycalendars">
<?php foreach ($my_calendars as $id => $cal): ?>
- <li><label><input type="checkbox" class="checkbox" name="display_cal[]" value="<?php echo htmlspecialchars($id) ?>"<?php echo (in_array($id, $display_calendars) ? ' checked="checked"' : '') . ' /> ' . htmlspecialchars($cal->get('name')) ?></label> <?php echo $info_img ?></li>
+ <li><label><input type="checkbox" class="checkbox" name="display_cal[]" value="<?php echo htmlspecialchars($id) ?>"<?php echo (in_array($id, $display_calendars) ? ' checked="checked"' : '') . ' /> ' . htmlspecialchars($cal->get('name')) ?></label> <?php echo $info_img ?>
+ <ul class="panel-tags" id="tags-<?php echo $id?>" style="margin-left: 10px;">
+ <?php $tags = $tagger->getTags($id, 'calendar'); ?>
+ <?php foreach ($tags as $tag_id => $tag): ?>
+ <li><?php echo $tag . ($cal->hasPermission(Auth::getAuth(), PERMS_EDIT) ? '<a href="#" id="remove' . md5($id . $tag_id) . '">' . Horde::img('delete-small.png', _("Remove Tag"), '', $registry->getImageDir('horde')) . '</a>' : '') . '</li>'?>
+ <?php
+ Kronolith_Imple::factory('TagActions', array('triggerId' => 'remove' . md5($id . $tag_id),
+ 'action' => 'delete',
+ 'resource' => $id,
+ 'type' => 'calendar',
+ 'tagId' => $tag_id));
+ ?>
+ <?php endforeach;?>
+ </ul>
+ </li>
<?php endforeach; ?>
</ul>
<?php endif; ?>