').text(category)
.click(function(){
OC.Tasks.filter(this, 'div.categories .tag');
$(this).toggleClass('active');
});
}
}
};
$(document).ready(function(){
$(window).resize(function () {
fillHeight($('#tasks_lists'));
fillWindow($('#tasks_list'));
});
$(window).trigger('resize');
/*-------------------------------------------------------------------------
* Actions for startup
*-----------------------------------------------------------------------*/
$.getJSON(OC.filePath('tasks', 'ajax', 'gettasks.php'), function(jsondata) {
var tasks = $('#tasks_list').empty().data('show_count', 0);
$(jsondata).each(function(i, task) {
tasks.append(OC.Tasks.create_task_div(task));
});
if( $('#tasks_list div').length > 0 ){
$('#tasks_list div').first().addClass('active');
}
$(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');
});
OCCategories.changed = OC.Tasks.categoriesChanged;
OCCategories.app = 'calendar';
});
/*-------------------------------------------------------------------------
* Event handlers
*-----------------------------------------------------------------------*/
$('#tasks_list div.categories .tag').live('click',function(){
OC.Tasks.filter(this, 'div.categories .tag');
var tag_text = $(this).text();
$('#tasks_lists div:not(".all"):not(".done")').each(function(){
if ($(this).text() == tag_text) {
$(this).toggleClass('active');
}
});
});
$('#tasks_list .priority.tag').live('click',function(){
OC.Tasks.filter(this, '.priority.tag');
});
$('#tasks_list .location.tag').live('click',function(){
OC.Tasks.filter(this, '.location.tag');
});
$('#tasks_order_category').click(function(){
var tasks = $('#tasks_list .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_list').empty();
for (var index in labels) {
var label = labels[index];
var container = $('
').appendTo($tasks);
if (label == '') {
label = t('tasks', 'No category');
}
$('
').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');
$.post('ajax/delete.php',{'id':id},function(jsondata){
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;
});
$('#tasks_addtask').click(function(){
var input = $('#tasks_newtask').val();
$.post(OC.filePath('tasks', 'ajax', 'addtask.php'),{text:input},function(jsondata){
if(jsondata.status == 'success'){
$('#tasks_list').append(OC.Tasks.create_task_div(jsondata.task));
}
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);
$('#tasks_list').append(OC.Tasks.create_task_div(jsondata.data.task));
}
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);
$('#task_details #categories').multiple_autocomplete({source: categories});
}
else{
alert(jsondata.data.message);
}
});
return false;
});
$('#tasks_edittaskform #percent_complete').live('change',function(event){
if ($(event.target).val() == 100){
$('#tasks_edittaskform #complete').show();
}else{
$('#tasks_edittaskform #complete').hide();
}
});
$('#tasks_edittaskform input[type="submit"]').live('click',function(){
$.post('ajax/edittask.php',$('#tasks_edittaskform').serialize(),function(jsondata){
$('.error_msg').remove();
$('.error').removeClass('error');
if(jsondata.status == 'success'){
var id = jsondata.data.id;
$('#task_details').data('id',id);
$('#task_details').html(jsondata.data.page);
var task = jsondata.data.task;
$('#tasks .task[data-id='+id+']')
.data('task', task)
.html(OC.Tasks.create_task_div(task).html());
}
else{
var errors = jsondata.data.errors;
for (k in errors){
$('#'+k).addClass('error')
.after(''+errors[k]+'');
}
$('.error_msg').effect('highlight', {}, 3000);
$('.error').effect('highlight', {}, 3000);
}
}, 'json');
return false;
});
OCCategories.app = 'calendar';
});