$result->task = $task->toJson(true, $prefs->getValue('twentyFour') ? 'H:i' : 'h:i A');
break;
+ case 'DeleteTask':
+ if (!$registry->hasMethod('tasks/deleteTask')) {
+ break;
+ }
+ if (is_null($id = Horde_Util::getFormData('id')) ||
+ is_null($list = Horde_Util::getFormData('list'))) {
+ break;
+ }
+ $result = $registry->tasks->deleteTask($list, $id);
+ if (is_a($result, 'PEAR_Error')) {
+ $notification->push($result, 'horde.error');
+ break;
+ }
+ $result = new stdClass;
+ $result->deleted = true;
+ break;
+
case 'ToggleCompletion':
if (!$registry->hasMethod('tasks/toggleCompletion')) {
break;
this.doAction('GetTask', { 'list': tasklist, 'id': id }, this._editTask.bind(this));
} else {
$('kronolithTaskId').clear();
+ $('kronolithTaskOldList').clear();
$('kronolithTaskList').setValue(Kronolith.conf.default_tasklist);
$('kronolithTaskDelete').hide();
$('kronolithTaskDueDate').setValue(d.toString(Kronolith.conf.date_format));
/* Basic information */
$('kronolithTaskId').setValue(task.id);
+ $('kronolithTaskOldList').setValue(task.l);
$('kronolithTaskList').setValue(task.l);
$('kronolithTaskTitle').setValue(task.n);
//$('kronolithTaskLocation').setValue(task.l);
},
/**
+ * Finally removes a task from the DOM and the cache.
+ *
+ * @param string task A task id.
+ * @param string list A task list name.
+ */
+ _removeTask: function(task, list)
+ {
+ this._deleteTasksCache(task, list);
+ $('kronolithViewTasksBody').select('tr').find(function(el) {
+ return el.retrieve('tasklist') == list &&
+ el.retrieve('taskid') == task;
+ }).remove();
+ },
+
+ /**
* Parses a date attribute string into a Date object.
*
* For other strings use Date.parse().
},
/**
+ * Deletes a task from the cache.
+ *
+ * @param string task A task ID.
+ * @param string list A task list string.
+ */
+ _deleteTasksCache: function(task, list)
+ {
+ this._deleteCache(task, [ 'external', 'tasks/' + list ]);
+ [ 'complete', 'incomplete' ].each(function(type) {
+ if (!Object.isUndefined(this.tcache.get(type)) &&
+ !Object.isUndefined(this.tcache.get(type).get(list))) {
+ this.tcache.get(type).get(list).unset(task);
+ }
+ }, this);
+ },
+
+ /**
* Return all events for a single day from all displayed calendars merged
* into a single hash.
*
e.stop();
return;
+ case 'kronolithTaskDelete':
+ var tasklist = $F('kronolithTaskOldList'),
+ taskid = $F('kronolithTaskId');
+ this.doAction('DeleteTask',
+ { 'list': tasklist, 'id': taskid },
+ function(r) {
+ if (r.response.deleted) {
+ this._removeTask(taskid, tasklist);
+ } else {
+ $('kronolithViewTasksBody').select('tr').find(function(el) {
+ return el.retrieve('tasklist') == tasklist &&
+ el.retrieve('taskid') == taskid;
+ }).toggle();
+ }
+ }.bind(this));
+ $('kronolithViewTasksBody').select('tr').find(function(el) {
+ return el.retrieve('tasklist') == tasklist &&
+ el.retrieve('taskid') == taskid;
+ }).hide();
+ this._closeRedBox();
+ window.history.back();
+ e.stop();
+ return;
+
case 'kronolithEventCancel':
case 'kronolithTaskCancel':
this._closeRedBox();
if (!Horde_Auth::isAdmin() &&
!array_key_exists($task->tasklist,
- Nag::listTasklists(false, PERMS_DELETE))) {
- return PEAR::raiseError(_("Permission Denied"));
- }
+ Nag::listTasklists(false, PERMS_DELETE))) {
+ return PEAR::raiseError(_("Permission Denied"));
+ }
return $storage->delete($task->id);
}
/**
+ * Deletes a task identified by tasklist and ID.
+ *
+ * @param string $tasklist A tasklist id.
+ * @param string $id A task id.
+ */
+ public function deleteTask($tasklist, $id)
+ {
+ require_once dirname(__FILE__) . '/base.php';
+
+ if (!Horde_Auth::isAdmin() &&
+ !array_key_exists($tasklist,
+ Nag::listTasklists(false, PERMS_DELETE))) {
+ return PEAR::raiseError(_("Permission Denied"));
+ }
+
+ $storage = Nag_Driver::singleton($tasklist);
+ return $storage->delete($id);
+ }
+
+ /**
* Replaces the task identified by UID with the content represented in the
* specified content type.
*