Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mikebrind
Created July 11, 2018 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikebrind/80329fb84142ae3db8961aacb57e335d to your computer and use it in GitHub Desktop.
Save mikebrind/80329fb84142ae3db8961aacb57e335d to your computer and use it in GitHub Desktop.
function WebmailViewModel() {
// Data
var self = this;
self.folders = ['Inbox', 'Archive', 'Sent', 'Spam'];
self.chosenFolderId = ko.observable();
self.chosenFolderData = ko.observable();
self.chosenMailData = ko.observable();
// Behaviours
self.goToFolder = function(folder) {
self.chosenFolderId(folder);
self.chosenMailData(null); // Stop showing a mail
$.get('/mail', { folder: folder }, self.chosenFolderData);
};
self.goToMail = function(mail) {
self.chosenFolderId(mail.folder);
self.chosenFolderData(null); // Stop showing a folder
$.get("/mail", { mailId: mail.id }, self.chosenMailData);
};
// Show inbox by default
self.goToFolder('Inbox');
};
ko.applyBindings(new WebmailViewModel());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment