not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

  1. define(function (require) {
  2. var controller = {};
  3. // Take a model and view and act as the controller between them.
  4. controller.Controller = function (model, view) {
  5. this.model = model;
  6. this.view = view;
  7. this.ENTER_KEY = 13;
  8. this.ESCAPE_KEY = 27;
  9. };
  10. controller.Controller.prototype.loadItems = function (items) {
  11. this.model.load(items);
  12. var list = document.getElementById("todo-list");
  13. list.innerHTML = this.view.show(items);
  14. };
  15. controller.Controller.prototype.addItem = function (title) {
  16. if (title.trim() === '') {
  17. return false;
  18. }
  19. var item = this.model.create(title);
  20. var list = document.getElementById("todo-list");
  21. list.innerHTML += this.view.show([item]);
  22. return true;
  23. };
  24. controller.Controller.prototype.removeItem = function (id) {
  25. this.model.remove(id);
  26. this.loadItems(this.model.items);
  27. };
  28. controller.Controller.prototype.toggleComplete = function (id, checkbox) {
  29. var completed = checkbox.checked ? 1 : 0;
  30. this.model.update(id, {completed: completed});
  31. this.loadItems(this.model.items);
  32. };
  33. return controller;
  34. });