From 8727459efdb7b03e3b109d35412467d6ba482112 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Mon, 16 Nov 2009 15:28:44 +0100 Subject: [PATCH] Only load missing tasks if switching task states. --- kronolith/ajax.php | 6 ++-- kronolith/js/kronolith.js | 71 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/kronolith/ajax.php b/kronolith/ajax.php index d13deae2d..006582747 100644 --- a/kronolith/ajax.php +++ b/kronolith/ajax.php @@ -131,7 +131,7 @@ try { } $taskList = Horde_Util::getFormData('list'); - $taskType = Horde_Util::getFormData('taskType'); + $taskType = Horde_Util::getFormData('type'); $tasks = $registry->call('tasks/listTasks', array(null, null, null, $taskList, $taskType == 'future' ? 'all' : $taskType, true)); if (is_a($tasks, 'PEAR_Error')) { @@ -140,8 +140,8 @@ try { } $result = new stdClass; - $result->taskList = $taskList; - $result->taskType = $taskType; + $result->list = $taskList; + $result->type = $taskType; if (count($tasks)) { $result->tasks = $tasks; } diff --git a/kronolith/js/kronolith.js b/kronolith/js/kronolith.js index 19fe9c7ee..c9657f2e0 100644 --- a/kronolith/js/kronolith.js +++ b/kronolith/js/kronolith.js @@ -1463,14 +1463,35 @@ KronolithCore = { }, /** + * Returns the task cache storage names that hold the tasks of the + * requested task type. + * + * @param string taskType The task type. + * + * @return array The list of task cache storage names. + */ + _getTaskStorage: function(taskType) + { + var taskTypes; + if (taskType == 'all' || taskType == 'future') { + taskTypes = [ 'complete', 'incomplete' ]; + } else { + taskTypes = [ taskType ]; + } + return taskTypes; + }, + + /** * Loads tasks, either from cache or from the server. * - * @param integer taskType The tasks type (all, incomplete, complete, - * future or future_incomplete). + * @param integer taskType The tasks type (all, incomplete, complete, or + * future). * @param Array tasksLists The lists from where to obtain the tasks. */ _loadTasks: function(taskType, taskLists) { + var taskTypes = this._getTaskStorage(taskType), loading = false; + if (Object.isUndefined(taskLists)) { taskLists = []; $H(Kronolith.conf.calendars.tasklists).each(function(tasklist) { @@ -1481,14 +1502,28 @@ KronolithCore = { }); } - taskLists.each(function(taskList) { - this.startLoading('tasks:' + taskList, taskType, ''); - this._storeTasksCache($H(), taskType, taskList); - this.doAction('ListTasks', - { 'taskType': taskType, - 'list': taskList }, - this._loadTasksCallback.bind(this)); + taskTypes.each(function(type) { + taskLists.each(function(list) { + if (Object.isUndefined(this.tcache.get(type)) || + Object.isUndefined(this.tcache.get(type).get(list))) { + loading = true; + this.startLoading('tasks:' + list, type, ''); + this._storeTasksCache($H(), type, list); + this.doAction('ListTasks', + { 'type': type, + 'list': list }, + function(r) { + this._loadTasksCallback(r, taskType); + }.bind(this)); + } + }, this); }, this); + + if (!loading) { + taskLists.each(function(list) { + this._insertTasks(taskType, list); + }, this); + } }, /** @@ -1496,7 +1531,7 @@ KronolithCore = { * * @param object r The ajax response object. */ - _loadTasksCallback: function(r) + _loadTasksCallback: function(r, tasktype) { // Hide spinner. this.loading--; @@ -1504,14 +1539,14 @@ KronolithCore = { $('kronolithLoading').hide(); } - this._storeTasksCache(r.response.tasks || {}, r.response.taskType, r.response.taskList); + this._storeTasksCache(r.response.tasks || {}, r.response.type, r.response.list); // Check if this is the still the result of the most current request. if (this.view != 'tasks' || - this.eventsLoading['tasks:' + r.response.taskList] != r.response.taskType) { + this.eventsLoading['tasks:' + r.response.list] != r.response.type) { return; } - this._insertTasks(r.response.taskType, r.response.taskList); + this._insertTasks(tasktype, r.response.list); }, /** @@ -1523,18 +1558,12 @@ KronolithCore = { */ _insertTasks: function(taskType, taskList) { - var taskTypes, now = new Date(); + var taskTypes = this._getTaskStorage(taskType), now = new Date(); $('kronolithViewTasksBody').select('tr').findAll(function(el) { - return el.identify() != 'kronolithTasksTemplate'; + return el.retrieve('tasklist') == taskList; }).invoke('remove'); - if (taskType == 'all' || taskType == 'future') { - taskTypes = [ 'complete', 'incomplete' ]; - } else { - taskTypes = [ taskType ]; - } - taskTypes.each(function(type) { var tasks = this.tcache.get(type).get(taskList); $H(tasks).each(function(task) { -- 2.11.0