diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-02-22 20:21:27 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-02-22 20:21:27 +0100 |
commit | 18bac944b4b0a63e99f6b6971de6ae788d3e39f1 (patch) | |
tree | ad3b7d39992346f27eb5af9b0c6eef95d01ab0fb /apps | |
parent | 92db4f8be099c32b477bba33412b1d2fc7a04dbc (diff) | |
download | nextcloud-server-18bac944b4b0a63e99f6b6971de6ae788d3e39f1.tar.gz nextcloud-server-18bac944b4b0a63e99f6b6971de6ae788d3e39f1.zip |
Change loading of tasks to ajax call
Diffstat (limited to 'apps')
-rw-r--r-- | apps/tasks/ajax/gettasks.php | 58 | ||||
-rw-r--r-- | apps/tasks/css/style.css | 6 | ||||
-rw-r--r-- | apps/tasks/index.php | 26 | ||||
-rw-r--r-- | apps/tasks/js/tasks.js | 38 | ||||
-rw-r--r-- | apps/tasks/templates/tasks.php | 17 |
5 files changed, 109 insertions, 36 deletions
diff --git a/apps/tasks/ajax/gettasks.php b/apps/tasks/ajax/gettasks.php new file mode 100644 index 00000000000..7dc94dacb45 --- /dev/null +++ b/apps/tasks/ajax/gettasks.php @@ -0,0 +1,58 @@ +<?php +/** + * Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +// Init owncloud +require_once('../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('tasks'); + +$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), true); +$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get()); + +$tasks = array(); +foreach( $calendars as $calendar ){ + $calendar_tasks = OC_Calendar_Object::all($calendar['id']); + foreach( $calendar_tasks as $task ){ + if($task['objecttype']!='VTODO'){ + continue; + } + if(is_null($task['summary'])){ + continue; + } + $object = OC_VObject::parse($task['calendardata']); + $vtodo = $object->VTODO; + $task = array( 'id' => $task['id'] ); + $task['summary'] = $vtodo->getAsString('SUMMARY'); + $task['description'] = $vtodo->getAsString('DESCRIPTION'); + $task['location'] = $vtodo->getAsString('LOCATION'); + $task['categories'] = $vtodo->getAsArray('CATEGORIES'); + $due = $vtodo->DUE; + if ($due) { + $due = $due->getDateTime(); + $due->setTimezone(new DateTimeZone($user_timezone)); + $task['due'] = $due->format('Y-m-d H:i:s'); + } + else { + $task['due'] = false; + } + $task['priority'] = $vtodo->getAsString('PRIORITY'); + $completed = $vtodo->COMPLETED; + if ($completed) { + $completed = $completed->getDateTime(); + $completed->setTimezone(new DateTimeZone($user_timezone)); + $task['completed'] = $completed->format('Y-m-d H:i:s'); + } + else { + $task['completed'] = false; + } + $task['complete'] = $vtodo->getAsString('PERCENT-COMPLETE'); + $tasks[] = $task; + } +} + +OC_JSON::encodedPrint($tasks); diff --git a/apps/tasks/css/style.css b/apps/tasks/css/style.css index 738f4f625b8..3a61d627162 100644 --- a/apps/tasks/css/style.css +++ b/apps/tasks/css/style.css @@ -2,3 +2,9 @@ #task_details td { padding:2px; text-align:left ;vertical-align:top; } .error_msg{color:red;} .error{border-color:red;border-width:2px;} +.task{position:relative;padding:0.5em 1em;} +.task_actions{display:none;} +.task .categories{position:absolute;right:0.6em;text-align:right;top:0.5em} +.task .categories a{background-color:#1d2d44;color:white;border-radius:0.4em;display:inline-block;opacity:0.2;margin:0 0.2em;padding:0 0.4em;} +#tasks{position:fixed; overflow: auto; top:6.4em; width:40em; background:#f8f8f8; border-right:1px solid #ddd; } +#task_details{position:absolute;left:53em;top:6.4em;} diff --git a/apps/tasks/index.php b/apps/tasks/index.php index f0e6c2e4ddb..3e324e797f8 100644 --- a/apps/tasks/index.php +++ b/apps/tasks/index.php @@ -18,29 +18,6 @@ if( count($calendars) == 0 ) { exit; } -$id = isset( $_GET['id'] ) ? $_GET['id'] : null; - -$tasks = array(); -foreach( $calendars as $calendar ){ - $calendar_tasks = OC_Calendar_Object::all($calendar['id']); - foreach( $calendar_tasks as $task ){ - if($task['objecttype']!='VTODO'){ - continue; - } - if(is_null($task['summary'])){ - continue; - } - $tasks[] = array( 'name' => $task['summary'], 'id' => $task['id'] ); - } -} - -$details = null; -if( !is_null($id) || count($tasks)){ - if(is_null($id)) $id = $tasks[0]['id']; - $task = OC_Calendar_Object::find($id); - $details = Sabre_VObject_Reader::read($task['calendardata'])->VTODO; -} - OC_UTIL::addScript('tasks', 'tasks'); OC_UTIL::addStyle('tasks', 'style'); OC_APP::setActiveNavigationEntry('tasks_index'); @@ -48,8 +25,5 @@ OC_APP::setActiveNavigationEntry('tasks_index'); $l10n = new OC_L10N('tasks'); $priority_options = OC_Task_App::getPriorityOptions(); $output = new OC_Template('tasks', 'tasks', 'user'); -$output->assign('tasks', $tasks); -$output->assign('details', $details); $output->assign('priority_options', $priority_options); -$output->assign('id',$id); $output -> printPage(); diff --git a/apps/tasks/js/tasks.js b/apps/tasks/js/tasks.js index e695925aad4..aba3eca7ce1 100644 --- a/apps/tasks/js/tasks.js +++ b/apps/tasks/js/tasks.js @@ -2,14 +2,44 @@ $(document).ready(function(){ /*------------------------------------------------------------------------- * Actions for startup *-----------------------------------------------------------------------*/ - if( $('#tasks li').length > 0 ){ - $('#tasks li').first().addClass('active'); - } + $.getJSON(OC.filePath('tasks', 'ajax', 'gettasks.php'), function(jsondata) { + var tasks = $('#tasks').empty(); + var actions = $('#task_actions_template'); + $(jsondata).each(function(i, task) { + var task_container = $('<div>').appendTo(tasks) + .addClass('task') + .data('task', task) + .attr('data-id', task.id) + .append($('<p>') + .html('<a href="index.php?id='+task.id+'">'+task.summary+'</a>') + .addClass('summary') + ) + .append(actions.clone().removeAttr('id')) + ; + if (task.categories.length > 0) { + var categories = $('<div>') + .addClass('categories') + .appendTo(task_container); + $(task.categories).each(function(i, category){ + categories.append($('<a>') + .text(category) + ); + }); + } + }); + if( $('#tasks div').length > 0 ){ + $('#tasks div').first().addClass('active'); + } + + }); + + fillHeight($('#tasks')); + fillWindow($('#task_details')); /*------------------------------------------------------------------------- * Event handlers *-----------------------------------------------------------------------*/ - $('#tasks li').live('click',function(){ + $('#tasks div').live('click',function(){ var id = $(this).data('id'); var oldid = $('#task_details').data('id'); if(oldid != 0){ diff --git a/apps/tasks/templates/tasks.php b/apps/tasks/templates/tasks.php index 70f14b4215e..60562c4a6f5 100644 --- a/apps/tasks/templates/tasks.php +++ b/apps/tasks/templates/tasks.php @@ -3,11 +3,16 @@ <input type="button" id="tasks_newtask" value="<?php echo $l->t('Add Task'); ?>"> </form> </div> -<div id="tasks" class="leftcontent"> - <ul> - <?php echo $this->inc("part.tasks"); ?> - </ul> +<div id="tasks"> +<p><?php echo $l->t('Loading tasks...') ?></p> </div> -<div id="task_details" class="rightcontent" data-id="<?php echo $_['id']; ?>"> - <?php echo $this->inc("part.details"); ?> +<div id="task_details"> </div> +<p id="task_actions_template" class="task_actions"> + <span class="task_delete"> + <img title="Delete" src="<?php echo image_path('core', 'actions/delete.svg') ?>" class="svg"> + </span> + <span class="task_edit"> + <img title="Edit" src="<?php echo image_path('core', 'actions/rename.svg') ?>" class="svg"> + </span> +</p> |