Skip to content

Commit

Permalink
Fixed removing category
Browse files Browse the repository at this point in the history
  • Loading branch information
Max authored and Max committed Aug 12, 2018
1 parent 283a41d commit fc8eb02
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions js/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var TODO = (function(window, document, $) {
$(this).parent().addClass('active');
var categoryId = parseInt($(this).parent().attr('data-category-id'), 10);
$('.tasks').attr('hidden', true);
$('.category-name').text($(this).text()).velocity('fadeIn');
$('.category-name').text($(this).text());
module.showTasks(categoryId);
module.setCategoryView(categoryId);
});
Expand Down Expand Up @@ -318,7 +318,7 @@ var TODO = (function(window, document, $) {
'</div>' +
'</div>';
}
$(html).appendTo('.tasks').velocity('fadeIn');
$(html).appendTo('.tasks');
};

// Add new task
Expand Down Expand Up @@ -363,6 +363,7 @@ var TODO = (function(window, document, $) {
'</li>';
categories[categoryId] = name;
module.saveCategories();
$('.category-name').text(name);
$(html).appendTo('.categories-menu');
$('.categories-menu [data-category-id="' + categoryId + '"]').velocity('slideDown');
$('.categories-menu > li').removeClass('active');
Expand Down Expand Up @@ -483,20 +484,23 @@ var TODO = (function(window, document, $) {
};

// Remove task
module.removeTask = function(id) {
module.removeTask = function(id, categoryId) {
if(!categoryId) {
categoryId = '-1';
}
delete tasks[id];
$('.tasks [data-id="' + id + '"]').velocity('slideUp', {
complete: function() {
$('.tasks [data-id="' + id + '"]').remove()
}
});
var numberOfTasksInCategory = 0;
var categoryId = parseInt($('.categories-menu > li.active').attr('data-category-id'), 10);
for(var key in tasks) {
if (!tasks.hasOwnProperty(key)) {
continue;
}
var task = tasks[key];
console.log(task)
if(task.categoryId === categoryId) {
numberOfTasksInCategory += 1;
}
Expand Down Expand Up @@ -537,7 +541,7 @@ var TODO = (function(window, document, $) {
}
var task = tasks[key];
if(task.categoryId === id) {
module.removeTask(key);
module.removeTask(key, id);
}
}
removed.velocity('slideUp', {
Expand Down

0 comments on commit fc8eb02

Please sign in to comment.