Eric lippert - Amazon Web Services
Eric lippert - Amazon Web Services
Eric lippert - Amazon Web Services
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Id: ko.protectedObservable(timeCard.Id),<br />
Summary: ko.protectedObservable(timeCard.Summary),<br />
Description: ko.protectedObservable(timeCard.<br />
Description),<br />
StartDate: ko.protectedObservable((new Date(timeCard.<br />
StartDate)).toJSON()),<br />
EndDate: ko.protectedObservable((new Date(timeCard.<br />
EndDate)).toJSON()),<br />
Status: ko.protectedObservable(timeCard.Status)<br />
};<br />
}<br />
}<br />
The View<br />
Once the view model is in place, we setup our view by updating<br />
the Index.cshtml. This page is served up by the HomeController,<br />
but we don’t have any Controller side code for it. We’ll make<br />
AJAX calls to the API controller to manipulate data.<br />
<br />
<br />
<br />
<br />
Add New TimeCard<br />
<br />
<br />
<br />
<br />
Summary<br />
Start Date<br />
End Date<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Select<br />
Demo<br />
VCalendar<br />
<br />
<br />
<br />
<br />
<br />
Summary<br />
<br />
<br />
Description<br />
<br />
<br />
Start Date<br />
<br />
<br />
End Date<br />
<br />
<br />
Status<br />
<br />
<br />
Save<br />
Cancel<br />
<br />
<br />
<br />
@section Scripts{<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
}<br />
We have split the view into two using the ‘left-section’ and<br />
‘right-section’ CSS classes. The ‘left-section’ has the List of all<br />
the TimeCards whereas the ‘right-section’ shows the currently<br />
selected card if any.<br />
To edit a card, we ‘Select’ it first. This populates the<br />
selectedTimeCard property in the view model which is bound to<br />
the ‘right-section’ and thus it comes up automatically. Once we<br />
do the changes and save, the data is posted back to the server<br />
and the selectedTimeCard is cleared out.<br />
The implementation for adding new, selecting and saving data is<br />
in the timekeeper-client.js.<br />
66 | DNCmagazine www.dotnetcurry.com