events.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. App.Events = (function(lng, undefined) {
  2. //Login
  3. lng.Dom.Event.live('#btnLogin', 'TAP', function(evet) {
  4. lng.Router.section('main');
  5. App.Data.refresh();
  6. });
  7. //Create new todo
  8. lng.Dom.Event.live('#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.Event.live('#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.Event.live('#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.Event.live('#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', 'write');
  44. });
  45. //Delete ToDo
  46. lng.Dom.Event.live('#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. lng.Sugar.Growl.option('Are you sure?', options);
  60. });
  61. })(LUNGO);