This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#=============================================================================== | |
## INITIAL PAGE VISIT ## | |
#=============================================================================== | |
GET /tasks (no params) | |
Processing by TasksController#index as HTML | |
Employee Load (0.5ms) SELECT "employees".* FROM "employees" WHERE "employees"."id" = 1 LIMIT 1 | |
Task Load (0.9ms) SELECT DISTINCT(completed_on) FROM "tasks" WHERE "tasks"."employee_id" = 1 AND (completed_on <= '2012-01-12') ORDER BY completed_on DESC LIMIT 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee < ActiveRecord::Base | |
... | |
def recent_tasks(options = {}) | |
completed_on = if options[:completed_on].present? | |
Date.parse options[:completed_on] | |
else | |
Date.current | |
end | |
completed_on = 2.business_days.after(completed_on.to_time).to_date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a id="previous" href="#"></a> | |
<% for task in @tasks: %> | |
<span class="date <%= task.status() %>" data-date="<%= task.get 'completed_on' %>"> | |
<p class="time"><%= task.get 'time' %></p> | |
<p class="name"><%= Date.parse(task.get('completed_on')).toString 'ddd' %></p> | |
<p class="range"> | |
<a href="#"><%= Date.parse(task.get('completed_on')).toString 'MM/dd' %></a> | |
</p> | |
</span> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Timesheet.Views.DateScrollView extends Backbone.View | |
el: '.DateScrollPane' | |
template: JST['tasks/date_scroll_view'] | |
initialize: -> | |
@collection.bind 'reset', @render | |
... | |
@model.bind 'change:completed_on', @refreshSelection | |
... | |
render: => | |
completedOn = Date.parse @model.get('completed_on') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
/* | |
* Add this to the top of your post. This will get interpreted in and applies to your page | |
* e.g. | |
* | |
* (this code) | |
* | |
* # My Summer Vacation | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:javascript | |
$(function () { | |
Timesheet.Tasks.reset(#{@tasks.to_json.html_safe}); | |
... | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reset collection.reset(models, [options]) | |
Adding and removing models one at a time is all well and good, but | |
sometimes you have so many models to change that you'd rather just | |
update the collection in bulk. Use reset to replace a collection with a | |
new list of models (or attribute hashes), triggering a single "reset" | |
event at the end. Pass {silent: true} to suppress the "reset" event. | |
Using reset with no arguments is useful as a way to empty the | |
collection. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
events: | |
"click .date": "selectDate" | |
"click #previous": "previous" | |
"click #next": "next" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There are several special options that, if passed, will be attached | |
directly to the view: model, collection, el, id, className, and tagName. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Timesheet.Routers.TasksRouter extends Backbone.Router | |
routes: | |
"": "index", | |
"new?completed_on=:completedOn": "new" | |
initialize: -> | |
@newTask = new Timesheet.Models.Task Timesheet.localGet('task') | |
... | |
@dateScrollView = new Timesheet.Views.DateScrollView | |
model: @newTask | |
collection: Timesheet.Tasks |