Skip to content

Commit

Permalink
Remove error after time
Browse files Browse the repository at this point in the history
  • Loading branch information
Max authored and Max committed Aug 12, 2018
1 parent 001efca commit 5caaa40
Showing 1 changed file with 62 additions and 12 deletions.
74 changes: 62 additions & 12 deletions js/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ var TODO = (function(window, document, $) {

// Check local storage support
if (!store.enabled) {
errorEl.text('Local storage is not supported by your browser. Please disable "Private Mode", or upgrade to a modern browser.');
errorEl.show();
errorEl.find('> span').text('Local storage is not supported by your browser. Please disable "Private Mode", or upgrade to a modern browser.');
errorEl.velocity('fadeIn');
return;
}

Expand Down Expand Up @@ -44,8 +44,14 @@ var TODO = (function(window, document, $) {
$('.add-new-category-btn').on('click', function() {
var category = $('#new-category').val();
if(!category) {
errorEl.text('Category name cannot be empty');
errorEl.show();
errorEl.find('> span').text('Category name cannot be empty');
errorEl.velocity('fadeIn', {
complete: function() {
setTimeout(function() {
errorEl.velocity('fadeIn');
}, 1000);
}
});
return;
}
module.addCategory(category);
Expand All @@ -56,8 +62,8 @@ var TODO = (function(window, document, $) {
var categoryId = parseInt($('.categories-menu').find('.active').attr('data-category-id'), 10);
var content = $('#content').val();
if(!content) {
errorEl.text('Task cannot be empty');
errorEl.show();
errorEl.find('> span').text('Task cannot be empty');
errorEl.velocity('fadeIn');
return;
}
var content = $('#content').val();
Expand Down Expand Up @@ -95,20 +101,20 @@ var TODO = (function(window, document, $) {
var categoryId = parseInt($(this).attr('data-category-id'), 10);
var name = $('#edit-category').val();
if(content === '') {
errorEl.text('Task cannot be empty');
errorEl.show();
errorEl.find('> span').text('Task cannot be empty');
errorEl.velocity('fadeIn');
return;
}
$('#task-edit-modal').modal('hide');
$('#category-edit-modal').modal('hide');
module.editCategory(categoryId, name);
});

$('.task-edit-btn').on('click', function() {
var taskId = parseInt($(this).attr('data-id'), 10);
var content = $('#edit-task').val();
if(content === '') {
errorEl.text('Task cannot be empty');
errorEl.show();
errorEl.find('> span').text('Task cannot be empty');
errorEl.velocity('fadeIn');
return;
}
$('#task-edit-modal').modal('hide');
Expand Down Expand Up @@ -142,9 +148,12 @@ var TODO = (function(window, document, $) {
});

$('.categories-empty-main').on('click', function() {
if($(window).width() < 992) {
$('.categories-sidebar, .mobile-menu').addClass('active');
}
$('#new-category').addClass('add-category-input-animation').focus();
setTimeout(function() {
$('#new-category').removeClass('add-category-input-animation')
$('#new-category').removeClass('add-category-input-animation');
}, 1000);
});

Expand All @@ -165,6 +174,18 @@ var TODO = (function(window, document, $) {
}
});

$('#edit-category').keypress(function(event) {
if(event.keyCode == 13) {
$('.category-edit-btn').trigger('click');
}
});

$('#edit-task').keypress(function(event) {
if(event.keyCode == 13) {
$('.task-edit-btn').trigger('click');
}
});

$(document).on('click', '.btn-task-done', function() {
var task = $(this).closest('.task');
var taskId = parseInt(task.attr('data-id'), 10);
Expand All @@ -190,6 +211,10 @@ var TODO = (function(window, document, $) {
}
module.saveTasks();
});

$(document).on('click', '#error > button', function() {
errorEl.velocity('fadeOut');
});
};

// Get all tasks
Expand Down Expand Up @@ -290,6 +315,9 @@ var TODO = (function(window, document, $) {
'<button type="button" class="btn btn-task btn-task-remove"><i class="fas fa-times"></i></button>' +
'</div>' +
'</div>';
$('.tasks').removeAttr('hidden');
$('.tasks').velocity('slideDown');
$('#content').val('');
$(html).appendTo('.tasks');
$('.task[data-id="' + taskId + '"]').velocity('slideDown');
};
Expand All @@ -309,9 +337,11 @@ var TODO = (function(window, document, $) {
$('.categories-menu > li').removeClass('active');
$('.categories-menu').find('li:last').addClass('active');
$('.tasks').empty();
$('.tasks').attr('hidden', true);
categoriesEmpty.attr('hidden', true);
tasksWrapper.removeAttr('hidden');
module.setCategoryView(categoryId);
$('#new-category').val('');
};

// Get number of tasks
Expand Down Expand Up @@ -421,6 +451,26 @@ var TODO = (function(window, document, $) {
$('.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];
if(task.categoryId === categoryId) {
numberOfTasksInCategory += 1;
}
}
console.log(numberOfTasksInCategory)
if(numberOfTasksInCategory === 0) {
$('.tasks').velocity('slideUp', {
complete: function() {
$('.tasks').attr('hidden', true);
}
})
$('.tasks-category-empty').removeAttr('hidden');
}
module.saveTasks();
};

Expand Down

0 comments on commit 5caaa40

Please sign in to comment.