Duration display, time formatting, UI tweaks.

Client Behaviour (ts.js)
========================

- Created EntryView.getViewModel: translates model data to view data,
  specifically synthesizes the start time and duration from the timestamp.
- Added nextModel option to EntryView, needed for calculating the entry
  duration.
- Created EntryView.formatStart: given the timestamp, return the start time,
  in HH:MM format. Code is written for both 24hr and 12hr format, still need
  to write a selector mechanism. For now, uses 12hr format.
- Created EntryView.formatDuration: Get the duration of the entry based on
  this entry's timestamp and and the next entry's timestamp in a display-able
  form. If nextModel is `null` or `undefined` it is assumed that `model`
  is the most recent model and duration is calculated against the current time.
- Changed EntryView.render to use getViewModel.
- Added 'blur' listeners to the mark and timestamp input fields to close them
  without persisting the changes.
- Created EntryView.update: Refresh the display based on the model using the
  existing DOM elements.
- EntryView.save() now uses EntryView.update() instead of EntryView.render()
  and no longer includes an implicit close()
- EntryView.close() has been split into seperate save() and close() functions,
  to persist the changes and hide the input dialogs, respectively.
- EntryListView.addOne now passes the nextModel to EntryViews is creates.
- EntryListView.createNewEntryOnEnter() now clear the new intry input after
  creating a new entry.
- EntryListView.render() now uses a for-structure to traverse the entry
  collection and passes the nextModel (if there is one) to EntryListView.addOne.

Client UI (ts-screen.scss)
==========================

- Font size, family, and color adjusted on timeline and user input fields.
- Day seperator secondary header colors adjusted.
- Mark column width shortened, timestamp and duration columns widened.
- Styles added for notes UI

Client UI (index.yaws)
======================

- Markup changes needed for getViewModel chanes.
- Expanded day seperator.
This commit is contained in:
Jonathan Bernard 2011-05-07 22:03:02 -05:00
parent 036177cfed
commit 74d8a7f015
2 changed files with 43 additions and 3 deletions

View File

@ -84,10 +84,11 @@ out(YArg) ->
<script type="text/html" id="entryTemplate">
<div class="mark">{{mark}}</div>
<input class="mark-input" type="text" value="{{mark}}"/>
<div class="timestamp">{{timestamp}}</div>
<div class="timestamp">{{start}}</div>
<input class="timestamp-input" type="text" value="{{timestamp}}"/>
<!-- TODO <div class="duration">4<span class="tick-tock">:</span>03<span class="tick-tock">:</span>57</div>-->
<div class="duration">{{duration}}</div>
<div class="notes">{{notes}}</div>
<input class="notes-input" type="textarea" value="{{notes}}"/>
</script>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
@ -121,7 +122,11 @@ out(YArg) ->
</div>
<div id="entry-list">
<div class="day-seperator">Today</div>
<div class="day-seperator">
<h4 class="mark">Today</h4>
<h5 class="timestamp">start</h5>
<h5 class="duration">duration</h5>
</div>
<div id="new-entry">
<input id="new-entry-input" class="mark-input"
placeholder="Start a new task..." type="text" />

View File

@ -107,6 +107,10 @@ $(document).ready(function(){
this.nextModel = options.nextModel;
},
/**
* Refresh the display based on the model replacing the existing
* HTML content. Add new `blur` listeners to the input fields.
*/
render: function() {
$(this.el).html(ich.entryTemplate(this.getViewModel()));
this.$(".mark-input").bind('blur', this.close);
@ -114,6 +118,10 @@ $(document).ready(function(){
return this;
},
/**
* Refresh the display based on the model using the existing DOM
* elements.
*/
update: function() {
var data = this.getViewModel();
this.$('.mark').text(data.mark);
@ -121,6 +129,7 @@ $(document).ready(function(){
this.$('.timestamp').text(data.start);
this.$('.timestamp-input').val(data.timestamp);
this.$('.duration').text(data.duration);
return this;
},
editMark: function() {
@ -135,6 +144,10 @@ $(document).ready(function(){
return this;
},
/**
* Translate the model data into a form suitable to be displayed.
* @return a map including display-able `start` and `duration` values.
*/
getViewModel: function() {
var data = this.model.toJSON();
@ -145,10 +158,12 @@ $(document).ready(function(){
return data;
},
/** Close editable fields. */
close: function() {
$(this.el).removeClass('edit-mark edit-timestamp');
},
/** Persist changes in input fields. */
save: function() {
this.model.save({
mark: this.$('.mark-input').val(),
@ -156,11 +171,21 @@ $(document).ready(function(){
this.update();
},
/** Event handler for keypresses on entry input fields. */
updateOnEnter: function(e) {
if(e.keyCode == 13) { this.save(); this.close(); }
},
/**
* Get the display-able start time from the entry timestamp.
* @param startDate a Date object, the entry timestamp.
* @return display-able start time in HH:MM format.
*/
formatStart: function(startDate) {
/* Code is written for both 24hr and 12hr formats. I still need to
* create a mechanism for selecting between them. For now, use the
* 12hr format. */
// 24 hour
// return startDate.getHours() + ":" + startDate.getMinutes();
@ -170,6 +195,16 @@ $(document).ready(function(){
" " + (startDate.getHours() > 11 ? "pm" : "am");
},
/**
* Get the duration of the entry based on this entry's timestamp and
* and the next entry's timestamp in a display-able form. If nextModel
* is `null` or `undefined` it is assumed that `model` is the most
* recent model and duration is calculated against the current time.
*
* @param model EntryModel representing this entry.
* @param nextModel EntryModel representing the next entry.
* @return the duration between model and nextModel, formatted for
* display: `Xd Yhr Zm`. */
formatDuration: function(model, nextModel) {
var d1 = new Date(model.get('timestamp'));
var d2, diff;