events.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. App.Events = (function(lng, undefined) {
  2. //Create new todo
  3. lng.Dom.Event.live('#btnNewTodo', 'TAP', function(event) {
  4. var name = lng.Dom.query('#txtNewName');
  5. var description = lng.Dom.query('#txtNewDescription');
  6. var type = lng.Dom.query('#txtNewType');
  7. App.Data.insertTodo({
  8. name: name.val(),
  9. description: description.val(),
  10. done: 0,
  11. created_at: Date('now')
  12. });
  13. name.val('');
  14. description.val('');
  15. App.View.returnToMain('ToDo created', 'check');
  16. });
  17. //View ToDo
  18. lng.Dom.Event.live('#done li, #pending li', 'TAP', function(event) {
  19. var todo_id = lng.Dom.query(this).attr('id');
  20. App.View.todo(todo_id)
  21. });
  22. //Done ToDo
  23. lng.Dom.Event.live('#btnDoneTodo', 'TAP', function(event) {
  24. var current_todo = lng.Data.Cache.get('current_todo');
  25. App.Data.doneTodo(current_todo.id);
  26. App.View.returnToMain('ToDo done', 'check');
  27. });
  28. //Update ToDo
  29. lng.Dom.Event.live('#btnUpdateTodo', 'TAP', function(event) {
  30. var current_todo = lng.Data.Cache.get('current_todo');
  31. var name = lng.Dom.query('#txtEditName');
  32. var description = lng.Dom.query('#txtEditDescription');
  33. var type = lng.Dom.query('#txtNewType');
  34. App.Data.updateTodo(current_todo.id, {
  35. name: name.val(),
  36. description: description.val()
  37. });
  38. App.View.returnToMain('ToDo updated', 'write');
  39. });
  40. //Delete ToDo
  41. lng.Dom.Event.live('#btnDeleteTodo', 'TAP', function(event) {
  42. var current_todo = lng.Data.Cache.get('current_todo');
  43. var options = [
  44. {
  45. name: '...Yes, delete it!',
  46. icon: 'check',
  47. color: 'green',
  48. callback: function(){
  49. App.Data.removeTodo(current_todo.id);
  50. App.View.returnToMain('ToDo deleted', 'trash');
  51. }
  52. }
  53. ];
  54. lng.Sugar.Growl.option('Are you sure?', options);
  55. });
  56. })(LUNGO);