Commit 36045a3a authored by MrMan's avatar MrMan

Working selection mechanics

parent 1c60a6bd
......@@ -110,8 +110,6 @@ EMAILS = EMAILS.sort(function(a, b) {
var ELLIPSIS_CHAR_LIMIT = 60;
/**
* Email service that will manage checking
*
......@@ -131,6 +129,25 @@ EmailService.prototype.selectEmailById = function(id, opts) {
if (opts && opts.redraw) { m.redraw(); }
};
EmailService.prototype.resetSelectedEmailId = function(opts) {
this.selectedEmailId = null;
if (opts && opts.redraw) { m.redraw(); }
};
EmailService.prototype.toggleSelectionStatusById = function(id, opts) {
if (!id) { throw new Error("Invalid email object, ID is missing"); }
// Reset if currently selected and exit early
if (this.getEmailSelectedStatusById(id)) {
this.resetSelectedEmailId();
return;
}
this.selectEmailById(id);
if (opts && opts.redraw) { m.redraw(); }
};
EmailService.prototype.getEmailSelectedStatusById = function(id) {
if (!id) { throw new Error("Invalid email object, ID is missing"); }
return this.selectedEmailId === id;
......@@ -144,6 +161,28 @@ EmailService.prototype.checkEmailById = function(id, opts) {
if (opts && opts.redraw) { m.redraw(); }
};
EmailService.prototype.resetEmailCheckedStatusById = function(id, opts) {
if (!id) { throw new Error("Invalid email object, ID is missing"); }
delete this.checkedEmailIds[id]; // This is kinda bad to do a lot
if (opts && opts.redraw) { m.redraw(); }
};
EmailService.prototype.toggleCheckedStatusById = function(id, opts) {
if (!id) { throw new Error("Invalid email object, ID is missing"); }
// Reset if currently selected and exit early
if (this.getEmailCheckedStatusById(id)) {
this.resetEmailCheckedStatusById(id);
return;
}
this.checkEmailById(id);
if (opts && opts.redraw) { m.redraw(); }
};
EmailService.prototype.getEmailCheckedStatusById = function(id) {
if (!id) { throw new Error("Invalid email object, ID is missing"); }
......@@ -408,14 +447,14 @@ var EmailListItem = {
".component.email-list-item.clickable",
{
class: additionalClasses.join(" "),
onclick: function() { EMAIL_SVC.selectEmailById(email.id); }
onclick: function() { EMAIL_SVC.toggleSelectionStatusById(email.id); }
},
[
m(".header", [
m(".lhs", [
m("input[type=checkbox]", {
checked: isChecked,
onclick: function() { EMAIL_SVC.checkEmailById(email.id); }
onclick: function() { EMAIL_SVC.toggleCheckedStatusById(email.id); }
}),
m("span.sm-margin-left.sender", email.from.name),
m("span.sm-margin-left.tag", email.label),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment