controller.js - niyogakiza/Openclassroom_Project-8 GitHub Wiki

controller.js

This file called controller.js makes it possible to make the link between the model and the view, it passes the model and the view as arguments, then binds different events.

controller code breakdown

  • The setView loads and initializes the view
  • showAll: display all the todos items
  • showActive: displays only the active todos(the one that still not yet done)
  • showCompleted: displays all completed items
  • addItem: adds the item to the list
  • editItem: it makes editing mode possible
  • editItemSave: it saves edited item
  • editItemCancel: cancel the item editing mode
  • removeItem: it removes the item and its id
  • removeCompletedItems: removes all completed items from the DOM and storage
  • toggleComplete: it passes an id to know which to toggle as complete between complete and active then updates the completed ones
  • toggleAll: it will take all todos and display them with there current status(means the active and completed ones)
  • _updateCount: Updates the pieces of the page which change depending on the remaining number of todos.
  • _filter : it filters todos based on the current route.
  • _updateFilterState: it updates the current filter navigation(all,active and completed)