2012-02-24 00:11:31 +04:00
|
|
|
OC.Tasks = {
|
2012-03-09 01:27:29 +04:00
|
|
|
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);
|
|
|
|
},
|
2012-03-09 01:26:54 +04:00
|
|
|
create_task_div:function(task) {
|
2012-04-17 19:32:21 +04:00
|
|
|
var actions = $('#task_actions_template');
|
|
|
|
var summary_container = $('<p class="summary">')
|
|
|
|
.attr('title', task.description)
|
|
|
|
;
|
|
|
|
OC.Tasks.setSummary(summary_container, task);
|
2012-03-09 01:26:54 +04:00
|
|
|
var task_container = $('<div>')
|
|
|
|
.addClass('task')
|
|
|
|
.data('task', task)
|
|
|
|
.data('show_count', 0)
|
|
|
|
.attr('data-id', task.id)
|
2012-04-17 19:32:21 +04:00
|
|
|
.append(summary_container)
|
2012-04-18 19:28:16 +04:00
|
|
|
.append(actions.clone().removeAttr('id'))
|
2012-03-09 01:26:54 +04:00
|
|
|
;
|
2012-04-17 19:32:21 +04:00
|
|
|
task_container.find('.summary a').click(OC.Tasks.summaryClickHandler);
|
2012-04-15 17:39:49 +04:00
|
|
|
var checkbox = $('<input type="checkbox">')
|
|
|
|
.click(OC.Tasks.complete_task);
|
2012-03-09 01:26:54 +04:00
|
|
|
if (task.completed) {
|
|
|
|
checkbox.attr('checked', 'checked');
|
2012-04-15 17:39:49 +04:00
|
|
|
task_container.addClass('done');
|
2012-03-09 01:26:54 +04:00
|
|
|
}
|
|
|
|
$('<div>')
|
|
|
|
.addClass('completed')
|
|
|
|
.append(checkbox)
|
|
|
|
.prependTo(task_container);
|
|
|
|
var priority = task.priority;
|
|
|
|
$('<div>')
|
|
|
|
.addClass('tag')
|
|
|
|
.addClass('priority')
|
|
|
|
.addClass('priority-'+(priority?priority:'n'))
|
|
|
|
.text(priority)
|
|
|
|
.prependTo(task_container);
|
|
|
|
if (task.location) {
|
|
|
|
$('<div>')
|
|
|
|
.addClass('tag')
|
|
|
|
.addClass('location')
|
|
|
|
.text(task.location)
|
|
|
|
.appendTo(task_container);
|
|
|
|
}
|
2012-05-02 19:28:19 +04:00
|
|
|
var $categories = $('<div>')
|
|
|
|
.addClass('categories')
|
|
|
|
.appendTo(task_container);
|
|
|
|
$(task.categories).each(function(i, category){
|
|
|
|
$categories.append($('<a>')
|
|
|
|
.addClass('tag')
|
|
|
|
.text(category)
|
|
|
|
);
|
|
|
|
});
|
2012-04-18 19:28:16 +04:00
|
|
|
task_container.find('.task_more').click(OC.Tasks.moreClickHandler);
|
2012-05-02 19:28:19 +04:00
|
|
|
task_container.find('.task_less').click(OC.Tasks.lessClickHandler);
|
2012-04-18 19:28:16 +04:00
|
|
|
var description = $('<textarea>')
|
|
|
|
.addClass('description')
|
2012-04-21 01:37:42 +04:00
|
|
|
.blur(function(){
|
|
|
|
var task = $(this).closest('.task').data('task');
|
|
|
|
var description = $(this).val();
|
2012-05-04 19:27:10 +04:00
|
|
|
$.post(OC.filePath('tasks', 'ajax', 'update_property.php'), {id:task.id, type:'description', description:description}, function(jsondata){
|
2012-04-21 01:37:42 +04:00
|
|
|
if(jsondata.status == 'success') {
|
|
|
|
task.description = description;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
2012-04-18 19:28:16 +04:00
|
|
|
.text(task.description);
|
2012-04-20 20:16:39 +04:00
|
|
|
var due = $('<span>')
|
|
|
|
.addClass('due')
|
|
|
|
.append(t('tasks', 'Due'));
|
|
|
|
due
|
|
|
|
.append($('<input type="date">')
|
|
|
|
.addClass('date')
|
|
|
|
.datepicker({
|
|
|
|
dateFormat: 'dd-mm-yy',
|
|
|
|
onClose: OC.Tasks.dueUpdateHandler
|
|
|
|
}),
|
|
|
|
$('<input type="time">')
|
|
|
|
.addClass('time')
|
|
|
|
.timepicker({
|
|
|
|
showPeriodLabels:false,
|
|
|
|
onClose: OC.Tasks.dueUpdateHandler
|
|
|
|
})
|
|
|
|
);
|
|
|
|
if (task.due){
|
|
|
|
var date = new Date(parseInt(task.due)*1000);
|
|
|
|
due.find('.date').datepicker('setDate', date);
|
2012-04-21 00:56:59 +04:00
|
|
|
if (!task.due_date_only) {
|
|
|
|
due.find('.time').timepicker('setTime', date.getHours()+':'+date.getMinutes());
|
|
|
|
}
|
2012-04-20 20:16:39 +04:00
|
|
|
}
|
2012-04-18 19:28:16 +04:00
|
|
|
$('<div>')
|
|
|
|
.addClass('more')
|
|
|
|
.append(description)
|
2012-04-20 20:16:39 +04:00
|
|
|
.append(due)
|
2012-04-18 19:28:16 +04:00
|
|
|
.appendTo(task_container);
|
2012-04-23 20:03:19 +04:00
|
|
|
$('<input placeholder="'+t('tasks', 'List')+'">')
|
|
|
|
.addClass('categories')
|
|
|
|
.multiple_autocomplete({source: categories})
|
|
|
|
.val(task.categories)
|
|
|
|
.blur(function(){
|
|
|
|
var task = $(this).closest('.task').data('task');
|
|
|
|
var categories = $(this).val();
|
2012-05-04 19:27:10 +04:00
|
|
|
$.post(OC.filePath('tasks', 'ajax', 'update_property.php'), {id:task.id, type:'categories', categories:categories}, function(jsondata){
|
2012-04-23 20:03:19 +04:00
|
|
|
if(jsondata.status == 'success') {
|
|
|
|
task.categories = categories.split(',');
|
2012-05-02 19:28:19 +04:00
|
|
|
$categories.empty();
|
|
|
|
$(task.categories).each(function(i, category){
|
|
|
|
$categories.append($('<a>')
|
|
|
|
.addClass('tag')
|
|
|
|
.text(category)
|
|
|
|
);
|
|
|
|
});
|
2012-04-23 20:03:19 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.appendTo(task_container);
|
2012-04-27 22:26:12 +04:00
|
|
|
$('<input placeholder="'+t('tasks', 'Location')+'">')
|
|
|
|
.addClass('location')
|
|
|
|
.val(task.location)
|
|
|
|
.blur(function(){
|
|
|
|
var task = $(this).closest('.task').data('task');
|
|
|
|
var location = $(this).val();
|
2012-05-04 19:27:10 +04:00
|
|
|
$.post(OC.filePath('tasks', 'ajax', 'update_property.php'), {id:task.id, type:'location', location:location}, function(jsondata){
|
2012-04-27 22:26:12 +04:00
|
|
|
if(jsondata.status == 'success') {
|
|
|
|
task.location = location;
|
2012-05-02 19:28:19 +04:00
|
|
|
task_container.find('.location').text(location);
|
2012-04-27 22:26:12 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.appendTo(task_container);
|
2012-03-09 01:26:54 +04:00
|
|
|
return task_container;
|
|
|
|
},
|
2012-02-24 00:11:31 +04:00
|
|
|
filter:function(tag, find_filter) {
|
|
|
|
var tag_text = $(tag).text();
|
|
|
|
var filter = !$(tag).hasClass('active');
|
2012-04-16 17:17:32 +04:00
|
|
|
OC.Tasks.filterUpdate(filter, function(task_container){
|
2012-02-24 00:11:31 +04:00
|
|
|
var found = 0;
|
|
|
|
task_container.find(find_filter).each(function(){
|
|
|
|
if ($(this).text() == tag_text) {
|
|
|
|
$(this).toggleClass('active');
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
});
|
2012-04-16 17:17:32 +04:00
|
|
|
return found;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
filterUpdate:function(filter, find_filter) {
|
|
|
|
var show_count = $('#tasks_list').data('show_count');
|
|
|
|
show_count += filter ? +1 : -1;
|
|
|
|
$('#tasks_list').data('show_count', show_count);
|
2012-04-27 19:48:08 +04:00
|
|
|
$('#tasks_lists .task, #tasks_list .task').each(function(i, task_container){
|
2012-04-16 17:17:32 +04:00
|
|
|
task_container = $(task_container);
|
|
|
|
var task = task_container.data('task');
|
|
|
|
var found = find_filter(task_container);
|
2012-02-24 00:11:31 +04:00
|
|
|
var hide_count = task_container.data('show_count');
|
|
|
|
if (!filter) {
|
|
|
|
hide_count-=found;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hide_count+=found;
|
|
|
|
}
|
|
|
|
if (hide_count == show_count) {
|
|
|
|
task_container.show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
task_container.hide();
|
|
|
|
}
|
|
|
|
task_container.data('show_count', hide_count);
|
|
|
|
});
|
2012-03-09 01:27:29 +04:00
|
|
|
},
|
|
|
|
order:function(sort, get_property, empty_label) {
|
2012-04-27 19:48:08 +04:00
|
|
|
var tasks = $('#tasks_list .task').not('.clone');
|
2012-03-09 01:27:29 +04:00
|
|
|
tasks.sort(sort);
|
|
|
|
var current = null;
|
|
|
|
tasks.detach();
|
2012-04-16 17:17:32 +04:00
|
|
|
var $tasks = $('#tasks_list').empty();
|
2012-03-09 01:27:29 +04:00
|
|
|
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);
|
|
|
|
});
|
2012-04-15 17:39:49 +04:00
|
|
|
},
|
2012-04-17 19:32:21 +04:00
|
|
|
setSummary:function(summary_container, task){
|
2012-04-20 20:19:10 +04:00
|
|
|
var summary = $('<a href="index.php?id='+task.id+'">')
|
|
|
|
.text(task.summary)
|
2012-04-17 19:32:21 +04:00
|
|
|
.click(OC.Tasks.summaryClickHandler);
|
|
|
|
summary_container.html(summary);
|
|
|
|
},
|
|
|
|
summaryClickHandler:function(event){
|
|
|
|
event.preventDefault();
|
|
|
|
//event.stopPropagation();
|
|
|
|
var task = $(this).closest('.task').data('task');
|
|
|
|
var summary_container = $(this).parent();
|
|
|
|
var input = $('<input>').val($(this).text()).blur(function(){
|
|
|
|
var old_summary = task.summary;
|
|
|
|
task.summary = $(this).val();
|
|
|
|
OC.Tasks.setSummary(summary_container, task);
|
2012-05-04 19:27:10 +04:00
|
|
|
$.post(OC.filePath('tasks', 'ajax', 'update_property.php'), {id:task.id, type:'summary', summary:task.summary}, function(jsondata){
|
2012-04-17 19:32:21 +04:00
|
|
|
if(jsondata.status != 'success') {
|
|
|
|
task.summary = old_summary;
|
|
|
|
OC.Tasks.setSummary(summary_container, task);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
summary_container.empty().append(input);
|
|
|
|
input.focus();
|
|
|
|
return false;
|
|
|
|
},
|
2012-04-20 20:16:39 +04:00
|
|
|
dueUpdateHandler:function(){
|
|
|
|
var task = $(this).closest('.task').data('task');
|
|
|
|
var old_due = task.due;
|
|
|
|
var $date = $(this).parent().children('.date');
|
|
|
|
var $time = $(this).parent().children('.time');
|
|
|
|
var date = $date.datepicker('getDate');
|
2012-04-21 00:56:59 +04:00
|
|
|
var time = $time.val().split(':');
|
|
|
|
var due, date_only = false;
|
|
|
|
if (!date){
|
2012-04-20 20:16:39 +04:00
|
|
|
due = false;
|
|
|
|
} else {
|
2012-04-21 00:56:59 +04:00
|
|
|
if (time.length==2){
|
|
|
|
date.setHours(time[0]);
|
|
|
|
date.setMinutes(time[1]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
date_only = true;
|
|
|
|
}
|
2012-04-20 20:16:39 +04:00
|
|
|
due = date.getTime()/1000;
|
|
|
|
}
|
2012-05-04 19:27:10 +04:00
|
|
|
$.post(OC.filePath('tasks', 'ajax', 'update_property.php'), {id:task.id, type:'due', due:due, date:date_only?1:0}, function(jsondata){
|
2012-04-20 20:16:39 +04:00
|
|
|
if(jsondata.status != 'success') {
|
|
|
|
task.due = old_due;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-04-18 19:28:16 +04:00
|
|
|
moreClickHandler:function(event){
|
|
|
|
var $task = $(this).closest('.task'),
|
|
|
|
task = $task.data('task');
|
|
|
|
$task.find('.more').show();
|
2012-05-02 19:28:19 +04:00
|
|
|
$task.find('.task_more').hide();
|
|
|
|
$task.find('.task_less').show();
|
2012-04-23 20:03:19 +04:00
|
|
|
$task.find('div.categories').hide();
|
|
|
|
$task.find('input.categories').show();
|
2012-04-27 22:26:12 +04:00
|
|
|
$task.find('div.location').hide();
|
|
|
|
$task.find('input.location').show();
|
2012-04-18 19:28:16 +04:00
|
|
|
},
|
2012-05-02 19:28:19 +04:00
|
|
|
lessClickHandler:function(event){
|
|
|
|
var $task = $(this).closest('.task'),
|
|
|
|
task = $task.data('task');
|
|
|
|
$task.find('.more').hide();
|
|
|
|
$task.find('.task_more').show();
|
|
|
|
$task.find('.task_less').hide();
|
|
|
|
$task.find('div.categories').show();
|
|
|
|
$task.find('input.categories').hide();
|
|
|
|
$task.find('div.location').show();
|
|
|
|
$task.find('input.location').hide();
|
|
|
|
},
|
2012-04-15 17:39:49 +04:00
|
|
|
complete_task:function() {
|
|
|
|
var $task = $(this).closest('.task'),
|
|
|
|
task = $task.data('task'),
|
|
|
|
checked = $(this).is(':checked');
|
2012-05-04 19:27:10 +04:00
|
|
|
$.post(OC.filePath('tasks', 'ajax', 'update_property.php'), {id:task.id, type:'complete', checked:checked?1:0}, function(jsondata){
|
2012-04-15 17:39:49 +04:00
|
|
|
if(jsondata.status == 'success') {
|
|
|
|
task = jsondata.data;
|
|
|
|
$task.data('task', task)
|
|
|
|
if (task.completed) {
|
|
|
|
$task.addClass('done');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$task.removeClass('done');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
alert(jsondata.data.message);
|
|
|
|
}
|
|
|
|
}, 'json');
|
2012-04-16 17:17:32 +04:00
|
|
|
},
|
2012-04-23 20:03:19 +04:00
|
|
|
categoriesChanged:function(newcategories){
|
|
|
|
categories = $.map(newcategories, function(v) {return v;});
|
|
|
|
console.log('Task categories changed to: ' + categories);
|
|
|
|
$('input.categories').multiple_autocomplete('option', 'source', categories);
|
|
|
|
},
|
2012-04-16 17:17:32 +04:00
|
|
|
List: {
|
|
|
|
create_list_div:function(category){
|
|
|
|
return $('<div>').text(category)
|
|
|
|
.click(function(){
|
|
|
|
OC.Tasks.filter(this, 'div.categories .tag');
|
|
|
|
$(this).toggleClass('active');
|
|
|
|
});
|
|
|
|
}
|
2012-02-24 00:11:31 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-12 23:28:28 +04:00
|
|
|
$(document).ready(function(){
|
2012-04-27 19:48:08 +04:00
|
|
|
fillHeight($('#tasks_lists'));
|
|
|
|
fillWindow($('#tasks_list'));
|
2012-04-16 17:17:32 +04:00
|
|
|
|
2011-09-12 23:28:28 +04:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Actions for startup
|
|
|
|
*-----------------------------------------------------------------------*/
|
2012-02-22 23:21:27 +04:00
|
|
|
$.getJSON(OC.filePath('tasks', 'ajax', 'gettasks.php'), function(jsondata) {
|
2012-04-16 17:17:32 +04:00
|
|
|
var tasks = $('#tasks_list').empty().data('show_count', 0);
|
2012-02-22 23:21:27 +04:00
|
|
|
$(jsondata).each(function(i, task) {
|
2012-03-09 01:26:54 +04:00
|
|
|
tasks.append(OC.Tasks.create_task_div(task));
|
2012-02-22 23:21:27 +04:00
|
|
|
});
|
2012-04-16 17:17:32 +04:00
|
|
|
if( $('#tasks_list div').length > 0 ){
|
|
|
|
$('#tasks_list div').first().addClass('active');
|
2012-02-22 23:21:27 +04:00
|
|
|
}
|
2012-04-16 17:17:32 +04:00
|
|
|
$(categories).each(function(i, category) {
|
|
|
|
$('#tasks_lists .all').after(OC.Tasks.List.create_list_div(category));
|
|
|
|
});
|
|
|
|
$('#tasks_lists .all').click(function(){
|
|
|
|
$('#tasks_lists .active').click();
|
|
|
|
});
|
|
|
|
$('#tasks_lists .done').click(function(){
|
|
|
|
var filter = !$(this).hasClass('active');
|
|
|
|
OC.Tasks.filterUpdate(filter, function(task_container){
|
|
|
|
return task_container.hasClass('done');
|
|
|
|
});
|
|
|
|
$(this).toggleClass('active');
|
|
|
|
});
|
2012-04-23 20:03:19 +04:00
|
|
|
OCCategories.changed = OC.Tasks.categoriesChanged;
|
|
|
|
OCCategories.app = 'calendar';
|
2012-02-22 23:21:27 +04:00
|
|
|
});
|
|
|
|
|
2011-09-12 23:28:28 +04:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Event handlers
|
|
|
|
*-----------------------------------------------------------------------*/
|
2012-04-27 19:48:08 +04:00
|
|
|
$('#tasks_list div.categories .tag').live('click',function(){
|
2012-02-24 00:11:31 +04:00
|
|
|
OC.Tasks.filter(this, 'div.categories .tag');
|
2012-04-16 17:17:32 +04:00
|
|
|
var tag_text = $(this).text();
|
|
|
|
$('#tasks_lists div:not(".all"):not(".done")').each(function(){
|
|
|
|
if ($(this).text() == tag_text) {
|
|
|
|
$(this).toggleClass('active');
|
|
|
|
}
|
|
|
|
});
|
2012-02-24 00:11:31 +04:00
|
|
|
});
|
|
|
|
|
2012-04-27 19:48:08 +04:00
|
|
|
$('#tasks_list .priority.tag').live('click',function(){
|
2012-02-24 00:11:31 +04:00
|
|
|
OC.Tasks.filter(this, '.priority.tag');
|
|
|
|
});
|
|
|
|
|
2012-04-27 19:48:08 +04:00
|
|
|
$('#tasks_list .location.tag').live('click',function(){
|
2012-02-24 00:11:31 +04:00
|
|
|
OC.Tasks.filter(this, '.location.tag');
|
|
|
|
});
|
|
|
|
|
2012-03-09 01:27:29 +04:00
|
|
|
$('#tasks_order_category').click(function(){
|
2012-04-27 19:48:08 +04:00
|
|
|
var tasks = $('#tasks_list .task').not('.clone');
|
2012-03-09 01:27:29 +04:00
|
|
|
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();
|
2012-04-16 17:17:32 +04:00
|
|
|
var $tasks = $('#tasks_list').empty();
|
2012-03-09 01:27:29 +04:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-09-12 23:28:28 +04:00
|
|
|
$('#tasks_delete').live('click',function(){
|
|
|
|
var id = $('#task_details').data('id');
|
2012-06-09 16:32:51 +04:00
|
|
|
$.post('ajax/delete.php',{'id':id},function(jsondata){
|
2011-09-12 23:28:28 +04:00
|
|
|
if(jsondata.status == 'success'){
|
|
|
|
$('#tasks [data-id="'+jsondata.data.id+'"]').remove();
|
|
|
|
$('#task_details').data('id','');
|
|
|
|
$('#task_details').html('');
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
alert(jsondata.data.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2012-04-24 00:13:35 +04:00
|
|
|
$('#tasks_addtask').click(function(){
|
|
|
|
var input = $('#tasks_newtask').val();
|
2012-06-09 16:32:51 +04:00
|
|
|
$.post(OC.filePath('tasks', 'ajax', 'addtask.php'),{text:input},function(jsondata){
|
2011-09-12 23:28:28 +04:00
|
|
|
if(jsondata.status == 'success'){
|
2012-04-24 00:13:35 +04:00
|
|
|
$('#tasks_list').append(OC.Tasks.create_task_div(jsondata.task));
|
2011-09-12 23:28:28 +04:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
alert(jsondata.data.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#tasks_addtaskform input[type="submit"]').live('click',function(){
|
|
|
|
$.post('ajax/addtask.php',$('#tasks_addtaskform').serialize(),function(jsondata){
|
|
|
|
if(jsondata.status == 'success'){
|
|
|
|
$('#task_details').data('id',jsondata.data.id);
|
|
|
|
$('#task_details').html(jsondata.data.page);
|
2012-04-16 17:17:32 +04:00
|
|
|
$('#tasks_list').append(OC.Tasks.create_task_div(jsondata.data.task));
|
2011-09-12 23:28:28 +04:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
alert(jsondata.data.message);
|
|
|
|
}
|
|
|
|
}, 'json');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#tasks_edit').live('click',function(){
|
|
|
|
var id = $('#task_details').data('id');
|
|
|
|
$.getJSON('ajax/edittaskform.php',{'id':id},function(jsondata){
|
|
|
|
if(jsondata.status == 'success'){
|
|
|
|
$('#task_details').html(jsondata.data.page);
|
2012-04-14 16:55:37 +04:00
|
|
|
$('#task_details #categories').multiple_autocomplete({source: categories});
|
2011-09-12 23:28:28 +04:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
alert(jsondata.data.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-09-14 00:44:15 +04:00
|
|
|
$('#tasks_edittaskform #percent_complete').live('change',function(event){
|
|
|
|
if ($(event.target).val() == 100){
|
|
|
|
$('#tasks_edittaskform #complete').show();
|
|
|
|
}else{
|
|
|
|
$('#tasks_edittaskform #complete').hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-09-12 23:28:28 +04:00
|
|
|
$('#tasks_edittaskform input[type="submit"]').live('click',function(){
|
|
|
|
$.post('ajax/edittask.php',$('#tasks_edittaskform').serialize(),function(jsondata){
|
2011-09-20 23:25:28 +04:00
|
|
|
$('.error_msg').remove();
|
|
|
|
$('.error').removeClass('error');
|
2011-09-12 23:28:28 +04:00
|
|
|
if(jsondata.status == 'success'){
|
2012-03-09 01:26:54 +04:00
|
|
|
var id = jsondata.data.id;
|
|
|
|
$('#task_details').data('id',id);
|
2011-09-12 23:28:28 +04:00
|
|
|
$('#task_details').html(jsondata.data.page);
|
2012-03-09 01:26:54 +04:00
|
|
|
var task = jsondata.data.task;
|
|
|
|
$('#tasks .task[data-id='+id+']')
|
|
|
|
.data('task', task)
|
|
|
|
.html(OC.Tasks.create_task_div(task).html());
|
2011-09-12 23:28:28 +04:00
|
|
|
}
|
|
|
|
else{
|
2011-09-20 23:25:28 +04:00
|
|
|
var errors = jsondata.data.errors;
|
|
|
|
for (k in errors){
|
|
|
|
$('#'+k).addClass('error')
|
|
|
|
.after('<span class="error_msg">'+errors[k]+'</span>');
|
|
|
|
}
|
|
|
|
$('.error_msg').effect('highlight', {}, 3000);
|
|
|
|
$('.error').effect('highlight', {}, 3000);
|
2011-09-12 23:28:28 +04:00
|
|
|
}
|
|
|
|
}, 'json');
|
|
|
|
return false;
|
|
|
|
});
|
2012-04-14 16:55:37 +04:00
|
|
|
|
|
|
|
OCCategories.app = 'calendar';
|
2011-09-12 23:28:28 +04:00
|
|
|
});
|