PageRenderTime 60ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/beancounter/static/js/main.js

https://bitbucket.org/xamox/beancounter
JavaScript | 102 lines | 69 code | 16 blank | 17 comment | 2 complexity | e2cc77023082e342627987fa46e37bac MD5 | raw file
Possible License(s): 0BSD
  1. // vim: fdm=marker
  2. /*
  3. * Copyright (c) 2011-2012 Audrius KaĹžukauskas
  4. *
  5. * This file is part of BeanCounter and is released under
  6. * the ISC license, see LICENSE for more details.
  7. */
  8. /*jslint indent: 4, browser: true, nomen: true, sloppy: true */
  9. /*global $, _, Backbone, B */
  10. // Set 'disabled' property and class for a button.
  11. $.fn.disabled = function (disable) { // {{{
  12. this.prop('disabled', disable);
  13. if (disable) {
  14. this.addClass('disable');
  15. } else {
  16. this.removeClass('disable');
  17. }
  18. }; // }}}
  19. B.Router = Backbone.Router.extend({ // {{{
  20. routes: {
  21. '': 'showDefault',
  22. 'entries/:year-:month': 'showEntries',
  23. 'tags': 'showTags',
  24. 'charts': 'showCharts'
  25. },
  26. showDefault: function () {
  27. $('#tabs').tabs('activate', 'entries');
  28. this.navigateEntries();
  29. },
  30. showEntries: function (year, month) {
  31. this.entries.setMonth($.datepick.newDate(year, month, 1));
  32. $('#tabs').tabs('activate', 'entries');
  33. },
  34. showTags: function () {
  35. $('#tabs').tabs('activate', 'tags');
  36. },
  37. showCharts: function () {
  38. $('#tabs').tabs('activate', 'charts');
  39. },
  40. navigateEntries: function () {
  41. this.navigate('entries/' +
  42. $.datepick.formatDate('yyyy-mm', this.entries.currMonth));
  43. }
  44. }); // }}}
  45. $(function () { // {{{
  46. var entriesTab, tagsTab, chartsTab, router;
  47. // Set up date picker.
  48. $.datepick.setDefaults({
  49. dateFormat: $.datepick.W3C,
  50. firstDay: 1,
  51. defaultDate: new Date(),
  52. selectDefaultDate: true,
  53. yearRange: 'c-5:c+5',
  54. showAnim: 'fadeIn',
  55. showSpeed: 'fast',
  56. renderer: $.extend({}, $.datepick.defaultRenderer, {
  57. picker: $.datepick.defaultRenderer.picker
  58. .replace(/\{link:clear\}/, '')
  59. })
  60. });
  61. // Initialize tags tab.
  62. tagsTab = new B.Tags.Views.Tab();
  63. B.tags = tagsTab.collection;
  64. // Initialize entries tab.
  65. entriesTab = new B.Entries.Views.Tab();
  66. // Initialize charts tab.
  67. chartsTab = new B.Charts.Tab();
  68. // Set up router.
  69. router = new B.Router();
  70. router.entries = entriesTab.collection;
  71. entriesTab.router = router;
  72. // Initialize tabs.
  73. $('#tabs').tabs({
  74. entries: function () {
  75. router.navigateEntries();
  76. },
  77. tags: function () {
  78. router.navigate('tags');
  79. },
  80. charts: function () {
  81. router.navigate('charts');
  82. }
  83. });
  84. // Initialize routing.
  85. Backbone.history.start({pushState: true});
  86. }); // }}}