summaryrefslogtreecommitdiff
path: root/program/js/app.js
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2013-10-25 19:27:49 +0200
committerAleksander Machniak <machniak@kolabsys.com>2013-10-25 19:27:49 +0200
commit89e50739b4ea47ef21e5d4864b7101585a94bea8 (patch)
tree6e16606ea62541d168967f2993636a8d930dfd37 /program/js/app.js
parent113b461dfd626c11fda76bfa25cfada9e1b1fcc6 (diff)
Refactored status/flag toggle code, added touch event support on flag and status icons.
Fixed regression in commit 4e4c2511bc00cfc0 where click on flag/status/expando icons was selecting the message row.
Diffstat (limited to 'program/js/app.js')
-rw-r--r--program/js/app.js62
1 files changed, 26 insertions, 36 deletions
diff --git a/program/js/app.js b/program/js/app.js
index ad0015452..bfae977b9 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -862,37 +862,24 @@ function rcube_webmail()
break;
case 'toggle_status':
- if (props && !props._row)
- break;
-
- flag = 'read';
-
- if (props._row.uid) {
- uid = props._row.uid;
+ case 'toggle_flag':
+ flag = command == 'toggle_flag' ? 'flagged' : 'read';
+ if (uid = props) {
+ // toggle flagged/unflagged
+ if (flag == 'flagged') {
+ if (this.message_list.rows[uid].flagged)
+ flag = 'unflagged';
+ }
// toggle read/unread
- if (this.message_list.rows[uid].deleted)
+ else if (this.message_list.rows[uid].deleted)
flag = 'undelete';
else if (!this.message_list.rows[uid].unread)
flag = 'unread';
- }
- this.mark_message(flag, uid);
- break;
-
- case 'toggle_flag':
- if (props && !props._row)
- break;
-
- flag = 'flagged';
-
- if (props._row.uid) {
- uid = props._row.uid;
- // toggle flagged/unflagged
- if (this.message_list.rows[uid].flagged)
- flag = 'unflagged';
+ this.mark_message(flag, uid);
}
- this.mark_message(flag, uid);
+
break;
case 'always-load':
@@ -1752,7 +1739,7 @@ function rcube_webmail()
this.init_message_row = function(row)
{
- var expando, self = this, uid = row.uid,
+ var i, fn = {}, self = this, uid = row.uid,
status_icon = (this.env.status_col != null ? 'status' : 'msg') + 'icn' + row.uid;
if (uid && this.env.messages[uid])
@@ -1760,8 +1747,7 @@ function rcube_webmail()
// set eventhandler to status icon
if (row.icon = document.getElementById(status_icon)) {
- row.icon._row = row.obj;
- row.icon.onclick = function(e) { self.command('toggle_status', this); return rcube_event.cancel(e); };
+ fn.icon = function(e) { self.command('toggle_status', uid); };
}
// save message icon position too
@@ -1770,24 +1756,28 @@ function rcube_webmail()
else
row.msgicon = row.icon;
- // set eventhandler to flag icon, if icon found
+ // set eventhandler to flag icon
if (this.env.flagged_col != null && (row.flagicon = document.getElementById('flagicn'+row.uid))) {
- row.flagicon._row = row.obj;
- row.flagicon.onclick = function(e) { self.command('toggle_flag', this); return rcube_event.cancel(e); };
+ fn.flagicon = function(e) { self.command('toggle_flag', uid); };
}
- if (!row.depth && row.has_children && (expando = document.getElementById('rcmexpando'+row.uid))) {
- row.expando = expando;
- expando.onclick = function(e) { return self.expand_message_row(e, uid); };
+ // set event handler to thread expand/collapse icon
+ if (!row.depth && row.has_children && (row.expando = document.getElementById('rcmexpando'+row.uid))) {
+ fn.expando = function(e) { self.expand_message_row(e, uid); };
+ }
+
+ // attach events
+ $.each(fn, function(i, f) {
+ row[i].onclick = function(e) { f(e); return rcube_event.cancel(e); };
if (bw.touch) {
- expando.addEventListener('touchend', function(e) {
+ row[i].addEventListener('touchend', function(e) {
if (e.changedTouches.length == 1) {
- self.expand_message_row(e, uid);
+ f(e);
return rcube_event.cancel(e);
}
}, false);
}
- }
+ });
this.triggerEvent('insertrow', { uid:uid, row:row });
};