// Generated by CoffeeScript 1.3.3 (function() { var CalendarApplication, CalendarDate, CalendarDatesController, CalendarEvent, CalendarEventsController, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; CalendarDate = (function(_super) { __extends(CalendarDate, _super); function CalendarDate() { return CalendarDate.__super__.constructor.apply(this, arguments); } CalendarDate.configure('CalendarDate', 'element', 'date', 'active'); CalendarDate.deactivateAllDates = function() { return CalendarDate.each(function(date) { return date.updateAttributes({ active: false }); }); }; return CalendarDate; })(Spine.Model); window.CalendarDate = CalendarDate; CalendarEvent = (function(_super) { __extends(CalendarEvent, _super); function CalendarEvent() { return CalendarEvent.__super__.constructor.apply(this, arguments); } CalendarEvent.configure('CalendarEvent', 'held_on', 'active', 'element'); CalendarEvent.activateAllEventsOn = function(date) { var event, _i, _len, _ref, _results; _ref = CalendarEvent.findAllByAttribute('held_on', date); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { event = _ref[_i]; _results.push(event.updateAttributes({ active: true })); } return _results; }; CalendarEvent.deactivateAllEvents = function() { return CalendarEvent.each(function(event) { return event.updateAttributes({ active: false }); }); }; return CalendarEvent; })(Spine.Model); window.CalendarEvent = CalendarEvent; CalendarDatesController = (function(_super) { __extends(CalendarDatesController, _super); function CalendarDatesController(element) { this.element = element; this.initializeDates(); } CalendarDatesController.prototype.initializeDates = function() { var date, el, _i, _len, _ref, _results; _ref = this.element.find('.date'); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { el = _ref[_i]; date = CalendarDate.create({ element: $(el), date: $(el).data('date'), active: false }); _results.push(this.initializeEventSelect(date)); } return _results; }; CalendarDatesController.prototype.initializeEventSelect = function(date) { date.element.bind('click', function() { date.trigger('activate'); CalendarDate.deactivateAllDates(); return date.updateAttributes({ active: true }); }); date.bind('activate', function(date) { CalendarEvent.deactivateAllEvents(); return CalendarEvent.activateAllEventsOn(date.date); }); return date.bind('change', function(date) { if (date.active === true) { date.element.addClass('selected'); } if (date.active === false) { return date.element.removeClass('selected'); } }); }; return CalendarDatesController; })(Spine.Module); window.CalendarDatesController = CalendarDatesController; CalendarEventsController = (function(_super) { __extends(CalendarEventsController, _super); function CalendarEventsController(element) { var el, event, _i, _len, _ref; _ref = element.find('.event_detail'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { el = _ref[_i]; event = CalendarEvent.create({ element: $(el).hide(), held_on: $(el).data('event-date'), active: false }); this.initializeEventSelect(event); } } CalendarEventsController.prototype.initializeEventSelect = function(event) { return event.bind('change', function() { if (event.active === true) { event.element.show(); } if (event.active === false) { return event.element.hide(); } }); }; return CalendarEventsController; })(Spine.Module); window.CalendarEventsController = CalendarEventsController; CalendarApplication = (function() { var calendarElements; function CalendarApplication() {} calendarElements = { 'ul.dates': CalendarDatesController, 'ul.event_details': CalendarEventsController }; CalendarApplication.initialize = function() { var controller, el, element, _results; _results = []; for (element in calendarElements) { controller = calendarElements[element]; _results.push((function() { var _i, _len, _ref, _results1; _ref = $(element); _results1 = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { el = _ref[_i]; _results1.push(new controller($(el))); } return _results1; })()); } return _results; }; return CalendarApplication; })(); window.CalendarApplication = CalendarApplication; }).call(this);