Aleksander Machniak
2013-10-25 89e50739b4ea47ef21e5d4864b7101585a94bea8
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.
2 files modified
65 ■■■■■ changed files
program/js/app.js 62 ●●●●● patch | view | raw | blame | history
program/js/list.js 3 ●●●● patch | view | raw | blame | history
program/js/app.js
@@ -862,37 +862,24 @@
        break;
      case 'toggle_status':
        if (props && !props._row)
          break;
        flag = 'read';
        if (props._row.uid) {
          uid = props._row.uid;
          // toggle read/unread
          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 = command == 'toggle_flag' ? 'flagged' : 'read';
        flag = 'flagged';
        if (props._row.uid) {
          uid = props._row.uid;
        if (uid = props) {
          // toggle flagged/unflagged
          if (flag == 'flagged') {
          if (this.message_list.rows[uid].flagged)
            flag = 'unflagged';
        }
          // toggle read/unread
          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 'always-load':
@@ -1752,7 +1739,7 @@
  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 @@
    // 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 @@
    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 });
  };
program/js/list.js
@@ -457,10 +457,11 @@
  var dblclicked = now - this.rows[id].clicked < this.dblclick_time;
  // selects/unselects currently selected row
  if (!this.drag_active && !dblclicked)
  if (!this.drag_active && this.in_selection_before == id && !dblclicked)
    this.select_row(id, mod_key, true);
    
  this.drag_start = false;
  this.in_selection_before = false;
  // row was double clicked
  if (this.rowcount && dblclicked && this.in_selection(id)) {