diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-03-08 22:27:29 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-03-08 22:27:29 +0100 |
commit | f8b62d49ee680084445538bbaab78fef60e22227 (patch) | |
tree | 195043fa33e840b543a483c9d08851d1c87ca9e5 /apps/tasks/js | |
parent | d1b2c10422692e182c0ec943d3a1925677a83f38 (diff) | |
download | nextcloud-server-f8b62d49ee680084445538bbaab78fef60e22227.tar.gz nextcloud-server-f8b62d49ee680084445538bbaab78fef60e22227.zip |
Tasks: Ordering of the task list
Diffstat (limited to 'apps/tasks/js')
-rw-r--r-- | apps/tasks/js/tasks.js | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/apps/tasks/js/tasks.js b/apps/tasks/js/tasks.js index 3cf428b33a1..4a9a0b69c4a 100644 --- a/apps/tasks/js/tasks.js +++ b/apps/tasks/js/tasks.js @@ -1,4 +1,16 @@ OC.Tasks = { + bool_string_cmp:function(a, b) { + if (a === b) { + return 0; + } + if (a === false) { + return -1; + } + if (b === false) { + return 1; + } + return a.localeCompare(b); + }, create_task_div:function(task) { var task_container = $('<div>') .addClass('task') @@ -78,6 +90,28 @@ OC.Tasks = { } task_container.data('show_count', hide_count); }); + }, + order:function(sort, get_property, empty_label) { + var tasks = $('#tasks .task').not('.clone'); + tasks.sort(sort); + var current = null; + tasks.detach(); + var $tasks = $('#tasks').empty(); + var container = $tasks; + tasks.each(function(){ + if (get_property) { + var label = get_property($(this).data('task')); + if(label != current) { + current = label; + container = $('<div>').appendTo($tasks); + if (label == '' && empty_label) { + label = empty_label; + } + $('<h1>').text(label).appendTo(container); + } + } + container.append(this); + }); } }; @@ -134,6 +168,82 @@ $(document).ready(function(){ OC.Tasks.filter(this, '.location.tag'); }); + $('#tasks_order_category').click(function(){ + var tasks = $('#tasks .task').not('.clone'); + var collection = {}; + tasks.each(function(i, task) { + var categories = $(task).data('task').categories; + $(categories).each(function() { + if (!collection.hasOwnProperty(this)) { + collection[this] = []; + } + collection[this].push(task); + if (categories.length > 1) { + task = $(task).clone(true).addClass('clone').get(0); + } + }); + if (categories.length == 0) { + if (!collection.hasOwnProperty('')) { + collection[''] = []; + } + collection[''].push(task); + } + }); + var labels = []; + for (var label in collection) { + labels.push(label); + } + labels.sort(); + tasks.detach(); + var $tasks = $('#tasks').empty(); + for (var index in labels) { + var label = labels[index]; + var container = $('<div>').appendTo($tasks); + if (label == '') { + label = t('tasks', 'No category'); + } + $('<h1>').text(label).appendTo(container); + container.append(collection[labels[index]]); + } + }); + + $('#tasks_order_due').click(function(){ + OC.Tasks.order(function(a, b){ + a = $(a).data('task').due; + b = $(b).data('task').due; + return OC.Tasks.bool_string_cmp(a, b); + }); + }); + + $('#tasks_order_complete').click(function(){ + OC.Tasks.order(function(a, b){ + return ($(a).data('task').complete - $(b).data('task').complete) || + OC.Tasks.bool_string_cmp($(a).data('task').completed, $(b).data('task').completed); + }); + }); + + $('#tasks_order_location').click(function(){ + OC.Tasks.order(function(a, b){ + a = $(a).data('task').location; + b = $(b).data('task').location; + return OC.Tasks.bool_string_cmp(a, b); + }); + }); + + $('#tasks_order_prio').click(function(){ + OC.Tasks.order(function(a, b){ + return $(a).data('task').priority + - $(b).data('task').priority; + }); + }); + + $('#tasks_order_label').click(function(){ + OC.Tasks.order(function(a, b){ + return $(a).data('task').summary.localeCompare( + $(b).data('task').summary); + }); + }); + $('#tasks_delete').live('click',function(){ var id = $('#task_details').data('id'); $.getJSON('ajax/delete.php',{'id':id},function(jsondata){ |