/beancounter/static/js/main.js
JavaScript | 102 lines | 69 code | 16 blank | 17 comment | 2 complexity | e2cc77023082e342627987fa46e37bac MD5 | raw file
Possible License(s): 0BSD
- // vim: fdm=marker
- /*
- * Copyright (c) 2011-2012 Audrius KaĹžukauskas
- *
- * This file is part of BeanCounter and is released under
- * the ISC license, see LICENSE for more details.
- */
- /*jslint indent: 4, browser: true, nomen: true, sloppy: true */
- /*global $, _, Backbone, B */
- // Set 'disabled' property and class for a button.
- $.fn.disabled = function (disable) { // {{{
- this.prop('disabled', disable);
- if (disable) {
- this.addClass('disable');
- } else {
- this.removeClass('disable');
- }
- }; // }}}
- B.Router = Backbone.Router.extend({ // {{{
- routes: {
- '': 'showDefault',
- 'entries/:year-:month': 'showEntries',
- 'tags': 'showTags',
- 'charts': 'showCharts'
- },
- showDefault: function () {
- $('#tabs').tabs('activate', 'entries');
- this.navigateEntries();
- },
- showEntries: function (year, month) {
- this.entries.setMonth($.datepick.newDate(year, month, 1));
- $('#tabs').tabs('activate', 'entries');
- },
- showTags: function () {
- $('#tabs').tabs('activate', 'tags');
- },
- showCharts: function () {
- $('#tabs').tabs('activate', 'charts');
- },
- navigateEntries: function () {
- this.navigate('entries/' +
- $.datepick.formatDate('yyyy-mm', this.entries.currMonth));
- }
- }); // }}}
- $(function () { // {{{
- var entriesTab, tagsTab, chartsTab, router;
- // Set up date picker.
- $.datepick.setDefaults({
- dateFormat: $.datepick.W3C,
- firstDay: 1,
- defaultDate: new Date(),
- selectDefaultDate: true,
- yearRange: 'c-5:c+5',
- showAnim: 'fadeIn',
- showSpeed: 'fast',
- renderer: $.extend({}, $.datepick.defaultRenderer, {
- picker: $.datepick.defaultRenderer.picker
- .replace(/\{link:clear\}/, '')
- })
- });
- // Initialize tags tab.
- tagsTab = new B.Tags.Views.Tab();
- B.tags = tagsTab.collection;
- // Initialize entries tab.
- entriesTab = new B.Entries.Views.Tab();
- // Initialize charts tab.
- chartsTab = new B.Charts.Tab();
- // Set up router.
- router = new B.Router();
- router.entries = entriesTab.collection;
- entriesTab.router = router;
- // Initialize tabs.
- $('#tabs').tabs({
- entries: function () {
- router.navigateEntries();
- },
- tags: function () {
- router.navigate('tags');
- },
- charts: function () {
- router.navigate('charts');
- }
- });
- // Initialize routing.
- Backbone.history.start({pushState: true});
- }); // }}}