events.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. App.Events = (function(lng, undefined) {
  2. //Login
  3. lng.dom('#btnLogin').tap(function(event) {
  4. lng.Router.section('main');
  5. App.Data.refresh();
  6. });
  7. //Create new todo
  8. lng.dom('#btnNewTodo').tap(function(event) {
  9. var name = lng.dom('#txtNewName');
  10. var description = lng.dom('#txtNewDescription');
  11. var type = lng.dom('#txtNewType');
  12. App.Data.insertTodo({
  13. name: name.val(),
  14. description: description.val(),
  15. done: 0,
  16. created_at: Date('now')
  17. });
  18. name.val('');
  19. description.val('');
  20. App.View.returnToMain('ToDo created', 'check');
  21. });
  22. //View ToDo
  23. lng.dom('#done li, #pending li').tap(function(event) {
  24. var todo_id = lng.dom(this).attr('id');
  25. App.View.todo(todo_id)
  26. });
  27. //Done ToDo
  28. lng.dom('#btnDoneTodo').tap(function(event) {
  29. var current_todo = lng.Data.Cache.get('current_todo');
  30. App.Data.doneTodo(current_todo.id);
  31. App.View.returnToMain('ToDo done', 'check');
  32. });
  33. //Update ToDo
  34. lng.dom('#btnUpdateTodo').tap(function(event) {
  35. var current_todo = lng.Data.Cache.get('current_todo');
  36. var name = lng.dom('#txtEditName');
  37. var description = lng.dom('#txtEditDescription');
  38. var type = lng.dom('#txtNewType');
  39. App.Data.updateTodo(current_todo.id, {
  40. name: name.val(),
  41. description: description.val()
  42. });
  43. App.View.returnToMain('ToDo updated', 'pencil');
  44. });
  45. //Delete ToDo
  46. lng.dom('#btnDeleteTodo').tap(function(event) {
  47. var current_todo = lng.Data.Cache.get('current_todo');
  48. var options = [
  49. {
  50. name: '...Yes, delete it!',
  51. icon: 'check',
  52. color: 'green',
  53. callback: function(){
  54. App.Data.removeTodo(current_todo.id);
  55. App.View.returnToMain('ToDo deleted', 'trash');
  56. }
  57. },
  58. {
  59. name: '...No, sorry.',
  60. icon: 'home',
  61. color: 'red',
  62. callback: function() {
  63. lng.Sugar.Growl.hide();
  64. }
  65. }
  66. ];
  67. lng.Sugar.Growl.option('Are you sure?', options);
  68. });
  69. })(Lungo);