Controller - dennisvintherjensen/OpenClassrooms-FED-Enhance-an-existing-project GitHub Wiki
Description
Handles requests coming from the View - the user interacts with the view, which will trigger an event that the Controller reacts to.
Properties
model
: The model in useview
: The view in use
Constructor
Controller(model, view)
: Takes a model and view and acts as the controller between them
Parameters
{Model} model
: The model to use{View} view
: The view to use
Methods
setView(locationHash)
: Loads and initialises the view
Parameters
{string} '' | 'active' | 'completed'
: The location hash that should be matched
showAll()
: An event to fire on load. Will get all items and display them in the todo-list
showActive()
: Renders all active tasks
showCompleted()
: Renders all completed tasks
addItem(title)
: An event to fire whenever you want to add an item. Simply pass in the event object and it'll handle the DOM insertion and saving of the new item.
Parameters
{string} title
: The title of the task to be added
editItem(id)
: Triggers the item editing mode.
Parameters
{number} id
: The id of the task
editItemSave(id, title)
: Finishes the item editing mode successfully.
Parameters
{number} id
: The id of the task{string} title
: The title of the task
editItemCancel(id)
: Cancels the item editing mode.
Parameters
{number} id
: The id of the task
removeItem(id)
: By giving it an ID it'll find the DOM element matching that ID, remove it from the DOM and also remove it from storage.
Parameters
{number} id
: The ID of the item to remove from the DOM and storage
removeCompletedItems()
: Will remove all completed items from the DOM and storage.
toggleComplete(id, completed, silent
: Give it an ID of a model and a checkbox and it will update the item in storage based on the checkbox's state.
Parameters
{number} id
: The ID of the element to complete or uncomplete{object} checkbox
: checkbox The checkbox to check the state of or not{boolean|undefined} silent
: Prevent re-filtering the todo items
toggleAll(completed)
: Will toggle ALL checkboxes' on/off state and completeness of models. Just pass in the event object.
Parameters
{event} completed
: The event object coming from the check all checkbox
_updateCount()
: Updates the pieces of the page which change depending on the remaining number of todos.
_filter(force)
: Re-filters the todo items, based on the active route.
Parameters
{boolean|undefined} force
: forces a re-painting of todo items.
_updateFilterState(currentPage)
: Simply updates the filter nav's selected states
Parameters
{string} currentPage
: the current location hash