FXS - Atileon/OC-p8 Wiki

Controller.addItem FIXED TYPO ERROR 'adddItem'

/**
   * 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.
   */
  //FIXED
  Controller.prototype.addItem = function(title) {
    var self = this;

    if (title.trim() === "") {
      return;
    }

    self.model.create(title, function() {
      self.view.render("clearNewTodo");
      self._filter(true);
    });
  };

Controller.editItemSave REFACTORED

/*
	 * Finishes the item editing mode successfully.
	 */
  Controller.prototype.editItemSave = function(id, title) {
    var self = this;

    //Refactored with trim when editing
    title = title.trim();

    // The while loops would be important if there wasn't be a way to "trim"
    // the data inserted on storage when updating a todo,
    // but instead of while loops we just trim the title for empty spaces as on the addItem method.
    // Thus this while loops could be deleted

    // while (title[0] === " ") {
    // 	title = title.slice(1);
    // }
    // while (title[title.length-1] === " ") {
    // 	title = title.slice(0, -1);
    // }

    if (title.length !== 0) {
      // console.log(title);
      self.model.update(id, { title: title }, function() {
        self.view.render("editItemDone", { id: id, title: title });
      });
    } else {
      self.removeItem(id);
    }
  };

controller.removeItem

 Controller.prototype.removeItem = function(id) {
    var self = this;
    // LOG NOT necessary
    // var items ;
    // self.model.read(function(data) {
    // 	items = data;
    // });
    // items.forEach(function(item) {
    // 	if (item.id === id) {
    // 		console.log("Element with ID: " + id + " has been removed.");
    // 	}
    // });

    self.model.remove(id, function() {
      self.view.render("removeItem", id);
    });

    self._filter();
  };