diff --git a/www/js/ts.js b/www/js/ts.js index d03d052..9c9636c 100644 --- a/www/js/ts.js +++ b/www/js/ts.js @@ -91,14 +91,6 @@ $(document).ready(function(){ _.bindAll(this, "url", "create"); }, - /*create: function(model, options) { - if (!(model instanceof Backbone.Model)) { - model.user_id = this.timelineModel.get('user_id'); - model.timeline_id = this.timelineModel.get('timeline_id'); } - else { - model.set('user_id') = this.timelineModel.get('user_id') - },*/ - url: function() { return "/ts_api/entries/" + this.timelineModel.get('user_id') + "/" + this.timelineModel.get('id'); } }); @@ -338,6 +330,14 @@ $(document).ready(function(){ // add it to the container after the topmost separator ("Today") this.topSeparator.after(el); + // If this entry and the next entry are not on the same day, put a + // day separator between them. + var nextDay = nextEntry ? nextEntry.get("timestamp") : new Date(); + if (entry.get("timestamp").getDate() != nextDay.getDate()) { + this.topSeparator.after(ich.daySeparatorTemplate( + {separatorLabel: this.formatDaySeparator( + TS.app.currentDay, entry.get("timestamp")) })); } + // hide it if excluded if (excluded) { $(el).fadeOut('slow'); @@ -379,14 +379,10 @@ $(document).ready(function(){ // clear existing elements in the view container this.entryContainer.empty(); - // last day we have printed a separator for - var today = new Date() - var currentDay = this.collection.at(0) ? - this.collection.at(0).get("timestamp"): today; - - // add the top-most day separator + // add the top-most day separator; should always be "Today" this.topSeparator = ich.daySeparatorTemplate({ - separatorLabel: this.formatDaySeparator(today, today) }); + separatorLabel: this.formatDaySeparator( + TS.app.currentDay, new Date()) }); this.entryContainer.prepend(this.topSeparator); // iterate through the collection and render the elements. @@ -394,13 +390,6 @@ $(document).ready(function(){ var entry = this.collection.at(i); var nextEntry = (i + 1 < len ? this.collection.at(i + 1) : null); - // we are rendering buttom up, which means we need to insert the - // day separator before the first entry of the *next* period - if (currentDay.getDate() != entry.get("timestamp").getDate()) { - this.topSeparator.after(ich.daySeparatorTemplate( - {separatorLabel: this.formatDaySeparator(today, currentDay)})); - currentDay = entry.get('timestamp'); } - this.renderOne(entry, nextEntry); } }, formatDaySeparator: function(today, labelDay) { @@ -415,27 +404,27 @@ $(document).ready(function(){ var monthDiff = today.getMonth() - labelDay.getMonth(); var dayDiff = today.getDate() - labelDay.getDate(); - // more than a calendar year old + // more than a calendar year old: Weekday, Month Date, Year if (yearDiff > 0) { return days[labelDay.getDay()] + ", " + months[labelDay.getMonth()] + " " + labelDay.getDate() + ", " + labelDay.getFullYear(); } - // same calendar year, more than a week ago + // same calendar year, more than a week ago: Weekday, Month Date else if (monthDiff > 0 || dayDiff > 7) { return days[labelDay.getDay()] + ", " + months[labelDay.getMonth()] + " " + labelDay.getDate(); } - // less than a week ago, more than yesterday + // less than a week ago, more than yesterday, Last Weekday else if (dayDiff > 1) { return "Last " + days[labelDay.getDay()]; } - // yesterday + // Yesterday else if (dayDiff == 1) { return "Yesterday"; } - // today + // Today else if (dayDiff == 0) { return "Today"; } } }); TS.TimelineListView = Backbone.View.extend({ @@ -536,9 +525,10 @@ $(document).ready(function(){ initialize: function() { _.bindAll(this, 'initializeViews', 'loadInitialData', - 'selectTimeline'); + 'periodicRefresh', 'selectTimeline'); - appThis = this; + TS.app = this; + TS.app.currentDay = new Date(); // create the login dialog this.loginDialog = new TS.LoginView @@ -548,12 +538,13 @@ $(document).ready(function(){ else { // this is async (waiting for user input) this.loginDialog.authenticate(function() { - appThis.initializeData(appThis.loadInitialData())}); } }, + TS.app.initializeData(TS.app.loadInitialData())}); } + + // Schedule our update function. + setInterval(this.periodicRefresh, 60000); }, initializeData: function(data) { - TS.app = this; - // create user data this.user = {}; this.user.model = new TS.UserModel(data.user); @@ -610,6 +601,18 @@ $(document).ready(function(){ return data; }, + periodicRefresh: function() { + + var now = new Date(); + + if (this.currentDay.getDate() != now.getDate()) { + // It's a new day! Rerender our whole list. + this.entries.render(); } + else { + // Refresh our latest entry view so the duration is up to date. + var models = this.entries.collection.models; + models[models.length - 1].view.render(); } }, + selectTimeline: function(e) { if (e) { // get the timeline model diff --git a/www/prototype.html b/www/prototype.html deleted file mode 100644 index 70be8ef..0000000 --- a/www/prototype.html +++ /dev/null @@ -1,247 +0,0 @@ - - - - TimeStamper - Simple Time Tracking - - - - - - - - - -
-
- Work-related activities. - -
-
( work )
- - -
-
- -
-
Jonathan Bernard
- -
-
- jdbernard
- -
-
- -
- -
-
-

Today

-
start
-
duration
-
-
- -
- -
-
-
ITHelp: Entering tickets.
- -
12:32
- -
4hr 3m
-
Some notes should go here, but they should be hidden by default
-
-
-
ITHelp: Helping Steve wth WR Updates.
- -
9:56
- -
1hr 15m
-
Some notes should go here, but they should be hidden by default
-
-
-
Email
- -
9:10
- -
47m
-
Some notes should go here, but they should be hidden by default
-
-
-

Yesterday

-
start
-
duration
-
-
-
ITHelp: Working #7801.
- -
3:12 pm
- -
12m
-
Some notes should go here, but they should be hidden by default
-
-
-
Lunch.
- -
11:47 am
- -
3hr 25m
-
Some notes should go here, but they should be hidden by default
-
-
-
ITHelp: Entering tickets.
- -
9:20 am
- -
2hr 27m
-
Some notes should go here, but they should be hidden by default
-
-
-
ITHelp: Reproducing #7796.
- -
9:11 am
- -
9m
-
Some notes should go here, but they should be hidden by default
-
-
-

Monday

-
start
-
duration
-
-
-
ITHelp: Working #7733.
- -
16:41
- -
1hr 8m
-
Some notes should go here, but they should be hidden by default
-
-
-
Zend Training: Building Security Into Your PHP Applications
- -
10:30
- -
4hr 11m
-
Some notes should go here, but they should be hidden by default
-
-
-
ITHelp.
- -
8:40
- -
1hr 50m
-
Some notes should go here, but they should be hidden by default
-
-
-

Friday, April 29th

-
start
-
duration
-
-
-
Training Steve: Databases and SQL
- -
16:09
- -
55m
-
Some notes should go here, but they should be hidden by default
-
-
-
Preparing Instructional Material: Database Basics
- -
15:12
- -
57m
-
Some notes should go here, but they should be hidden by default
-
-
-
ITHelp: Working #7729.
- -
15:09
- -
3m
-
Some notes should go here, but they should be hidden by default
-
-
-
ITHelp.
- -
14:44
- -
25m
-
Some notes should go here, but they should be hidden by default
-
-
-
ITHelp: Working #7728.
- -
14:41
- -
3m
-
Some notes should go here, but they should be hidden by default
-
-
-
ITHelp.
- -
14:00
- -
41m
-
Some notes should go here, but they should be hidden by default
-
-
-
Lunch.
- -
13:05
- -
55m
-
Some notes should go here, but they should be hidden by default
-
-
-
ITHelp: Working #7725.
- -
12:40
- -
20m
-
Some notes should go here, but they should be hidden by default
-
-
-
Zend Training: Building Security Into You PHP Applications.
- -
10:30
- -
2hr 10m
-
Some notes should go here, but they should be hidden by default
-
-
-
Zend Training: Preparing for security training.
- -
09:25
- -
1hr 5m
-
Some notes should go here, but they should be hidden by default
-
-
-
ITHelp: Working #7700.
- -
09:17
- -
8m
-
Some notes should go here, but they should be hidden by default
-
-
-
- - - - - - diff --git a/www/test.html b/www/test.html deleted file mode 100644 index 2cdad8c..0000000 --- a/www/test.html +++ /dev/null @@ -1,38 +0,0 @@ - - - Testing Backbone.js - - - - - - - - - - - -
-
username
-
fullname
-
- -
- -
-
-
- - - - -
-
-

-
- - - -