<script src="/scripts/lib/ sammy.js" type="text/ javascript"></script>
<!-- Folders -->
<ul class="folders" data-bind= "foreach: folders">
<li data-bind="text: $data,
css: { selected: $data == $root.chosenFolderId() },
click: $root.goToFolder"></li>
</ul>
<!-- Mails grid -->
<table class="mails" data-bind ="with: chosenFolderData">
<thead><tr><th>From</th><th> To</th><th>Subject</th><th>Dat e</th></tr></thead>
<tbody data-bind="foreach: mails">
<tr data-bind="click: $root.goToMail">
<td data-bind="text: from"></td>
<td data-bind="text: to"></td>
<td data-bind="text: subject"></td>
<td data-bind="text: date"></td>
</tr>
</tbody>
</table>
<!-- Chosen mail -->
<div class="viewMail" data- bind="with: chosenMailData">
<div class="mailInfo">
<h1 data-bind="text: subject"></h1>
<p><label>From</label>: <spa n data-bind="text: from"></span></p>
<p><label>To</label>: <span data-bind="text: to"></span></p>
<p><label>Date</label>: <spa n data-bind="text: date"></span></p>
</div>
<p class="message" data-bind ="html: messageContent" />
</div>
function WebmailViewModel() {
// Data
var self = this;
self.folders = ['Inbox', ' Archive', 'Sent', 'Spam'];
self.chosenFolderId = ko.obs ervable();
self.chosenFolderData = ko.o bservable();
self.chosenMailData = ko.obs ervable();
// Behaviours
self.goToFolder = function(f older) { location.hash = folde r };
self.goToMail = function(mai l) { location.hash = mail.fold er + '/' + mail.id };
// Client-side routes
Sammy(function() {
this.get('#:folder', functio n() {
self.chosenFolderId(this.par ams.folder);
self.chosenMailData(null);
$.get("/mail", { folder: thi s.params.folder }, self.chosen FolderData);
});
this.get('#:folder/:mailId', function() {
self.chosenFolderId(this.par ams.folder);
self.chosenFolderData(null);
$.get("/mail", { mailId: thi s.params.mailId }, self.chosen MailData);
});
this.get('', function() { th is.app.runRoute('get', '# Inbox') });
}).run();
};
ko.applyBindings(new WebmailVi ewModel());
<!-- Folders -->
<ul class="folders" data-bind=
<li data-bind="text: $data,
css: { selected: $data == $root.chosenFolderId() },
click: $root.goToFolder"></li>
</ul>
<!-- Mails grid -->
<table class="mails" data-bind
<thead><tr><th>From</th><th>
<tbody data-bind="foreach: mails">
<tr data-bind="click: $root.goToMail">
<td data-bind="text: from"></td>
<td data-bind="text: to"></td>
<td data-bind="text: subject"></td>
<td data-bind="text: date"></td>
</tr>
</tbody>
</table>
<!-- Chosen mail -->
<div class="viewMail" data-
<div class="mailInfo">
<h1 data-bind="text: subject"></h1>
<p><label>From</label>: <spa
<p><label>To</label>: <span
<p><label>Date</label>: <spa
</div>
<p class="message" data-bind
</div>
// Data
var self = this;
self.folders = ['Inbox', '
self.chosenFolderId = ko.obs
self.chosenFolderData = ko.o
self.chosenMailData = ko.obs
// Behaviours
self.goToFolder = function(f
self.goToMail = function(mai
// Client-side routes
Sammy(function() {
this.get('#:folder', functio
self.chosenFolderId(this.par
self.chosenMailData(null);
$.get("/mail", { folder: thi
});
this.get('#:folder/:mailId',
self.chosenFolderId(this.par
self.chosenFolderData(null);
$.get("/mail", { mailId: thi
});
this.get('', function() { th
}).run();
};
ko.applyBindings(new WebmailVi
Комментариев нет:
Отправить комментарий