From b62c4869f7c43804601b7786809e7e7a2508566d Mon Sep 17 00:00:00 2001 From: alecpl Date: Sun, 2 May 2010 15:09:36 +0000 Subject: - Allow columns order change per user - drag&drop (#1485795) --- program/js/app.js | 54 +++++++++-- program/js/list.js | 269 +++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 296 insertions(+), 27 deletions(-) (limited to 'program/js') diff --git a/program/js/app.js b/program/js/app.js index b2888d028..dd3feeeca 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -166,7 +166,8 @@ function rcube_webmail() if (this.gui_objects.messagelist) { this.message_list = new rcube_list_widget(this.gui_objects.messagelist, - {multiselect:true, multiexpand:true, draggable:true, keyboard:true, dblclick_time:this.dblclick_time}); + {multiselect:true, multiexpand:true, draggable:true, keyboard:true, + column_movable:this.env.col_movable, column_fixed:0, dblclick_time:this.dblclick_time}); this.message_list.row_init = function(o){ p.init_message_row(o); }; this.message_list.addEventListener('dblclick', function(o){ p.msglist_dbl_click(o); }); this.message_list.addEventListener('click', function(o){ p.msglist_click(o); }); @@ -176,11 +177,11 @@ function rcube_webmail() this.message_list.addEventListener('dragmove', function(e){ p.drag_move(e); }); this.message_list.addEventListener('dragend', function(e){ p.drag_end(e); }); this.message_list.addEventListener('expandcollapse', function(e){ p.msglist_expand(e); }); + this.message_list.addEventListener('column_replace', function(e){ p.msglist_set_coltypes(e); }); document.onmouseup = function(e){ return p.doc_mouse_up(e); }; this.gui_objects.messagelist.parentNode.onmousedown = function(e){ return p.click_on_list(e); }; - this.set_message_coltypes(this.env.coltypes); this.message_list.init(); this.enable_command('toggle_status', 'toggle_flag', 'menu-open', 'menu-save', true); @@ -1487,6 +1488,24 @@ function rcube_webmail() if (this.env.messages[row.uid]) this.env.messages[row.uid].expanded = row.expanded; }; + + this.msglist_set_coltypes = function(list) + { + var i, found, name, cols = list.list.tHead.rows[0].cells; + + this.env.coltypes = []; + + for (i=0; i= 0) + this.set_env('flagged_col', found); + + this.http_post('save-pref', { '_name':'list_cols', '_value':this.env.coltypes }); + }; this.check_droptarget = function(id) { @@ -1692,6 +1711,9 @@ function rcube_webmail() { var update, add_url = ''; + if (!sort_col) sort_col = this.env.sort_col; + if (!sort_order) sort_order = this.env.sort_order; + if (this.env.sort_col != sort_col || this.env.sort_order != sort_order) { update = 1; this.set_list_sorting(sort_col, sort_order); @@ -1702,9 +1724,25 @@ function rcube_webmail() add_url += '&_threads=' + threads; } - if (cols.join() != this.env.coltypes.join()) { - update = 1; - add_url += '&_cols=' + cols.join(','); + if (cols && cols.length) { + // make sure new columns are added at the end of the list + var i, idx, name, newcols = [], oldcols = this.env.coltypes; + for (i=0; i= 0) { + if ((found = $.inArray('subject', this.env.coltypes)) >= 0) { this.set_env('subject_col', found); if (this.message_list) this.message_list.subject_col = found+1; } - if((found = $.inArray('flag', this.env.coltypes)) >= 0) + if ((found = $.inArray('flag', this.env.coltypes)) >= 0) this.set_env('flagged_col', found); + + this.message_list.init_header(); }; // replace content of row count display diff --git a/program/js/list.js b/program/js/list.js index 8d6d9f1e6..9493121d5 100644 --- a/program/js/list.js +++ b/program/js/list.js @@ -33,6 +33,7 @@ function rcube_list_widget(list, p) this.rows = []; this.selection = []; this.rowcount = 0; + this.colcount = 0; this.subject_col = -1; this.shiftkey = false; @@ -40,11 +41,14 @@ function rcube_list_widget(list, p) this.multiexpand = false; this.multi_selecting = false; this.draggable = false; + this.column_movable = false; this.keyboard = false; this.toggleselect = false; this.dont_select = false; this.drag_active = false; + this.col_drag_active = false; + this.column_fixed = null; this.last_selected = 0; this.shift_start = 0; this.in_selection_before = false; @@ -72,18 +76,15 @@ init: function() this.rows = []; this.rowcount = 0; - var row; - for(var r=0; r 1) { + this.drag_start = true; + this.drag_mouse_start = rcube_event.get_mouse_pos(e); + + rcube_event.add_listener({event:'mousemove', object:this, method:'column_drag_mouse_move'}); + rcube_event.add_listener({event:'mouseup', object:this, method:'column_drag_mouse_up'}); + + // enable dragging over iframes + this.add_dragfix(); + + // find selected column number + for (var i=0; i') - .css({background: '#fff', - width: this.offsetWidth+'px', height: this.offsetHeight+'px', - position: 'absolute', opacity: '0.001', zIndex: 1000 - }) - .css($(this).offset()) - .appendTo('body'); - }); + this.add_dragfix(); } return false; @@ -287,7 +331,7 @@ click_row: function(e, id) if (!this.drag_active) { // remove temp divs - $('div.iframe-dragdrop-fix').each(function() { this.parentNode.removeChild(this); }); + this.del_dragfix(); rcube_event.cancel(e); } @@ -931,7 +975,11 @@ key_down: function(e) switch (rcube_event.get_keycode(e)) { case 27: if (this.drag_active) - return this.drag_mouse_up(e); + return this.drag_mouse_up(e); + if (this.col_drag_active) { + this.selected_column = null; + return this.column_drag_mouse_up(e); + } case 40: case 38: @@ -1040,7 +1088,9 @@ drag_mouse_move: function(e) return false; if (!this.draglayer) - this.draglayer = $('
').attr('id', 'rcmdraglayer').css({ position:'absolute', display:'none', 'z-index':2000 }).appendTo(document.body); + this.draglayer = $('
').attr('id', 'rcmdraglayer') + .css({ position:'absolute', display:'none', 'z-index':2000 }) + .appendTo(document.body); // also select childs of (collapsed) threads for dragging var selection = $.merge([], this.selection); @@ -1134,7 +1184,7 @@ drag_mouse_up: function(e) rcube_event.remove_listener({event:'mouseup', object:this, method:'drag_mouse_up'}); // remove temp divs - $('div.iframe-dragdrop-fix').each(function() { this.parentNode.removeChild(this); }); + this.del_dragfix(); this.triggerEvent('dragend'); @@ -1142,6 +1192,185 @@ drag_mouse_up: function(e) }, +/** + * Handler for mouse move events for dragging list column + */ +column_drag_mouse_move: function(e) +{ + if (this.drag_start) { + // check mouse movement, of less than 3 pixels, don't start dragging + var i, m = rcube_event.get_mouse_pos(e); + + if (!this.drag_mouse_start || (Math.abs(m.x - this.drag_mouse_start.x) < 3 && Math.abs(m.y - this.drag_mouse_start.y) < 3)) + return false; + + if (!this.col_draglayer) { + var lpos = $(this.list).offset(), + cells = this.list.tHead.rows[0].cells; + + // create dragging layer + this.col_draglayer = $('
').attr('id', 'rcmcoldraglayer') + .css(lpos).css({ position:'absolute', 'z-index':2001, + 'background-color':'white', opacity:0.75, + height: (this.frame.offsetHeight-2)+'px', width: (this.frame.offsetWidth-2)+'px' }) + .appendTo(document.body) + // ... and column position indicator + .append($('
').attr('id', 'rcmcolumnindicator') + .css({ position:'absolute', 'border-right':'2px dotted #555', + 'z-index':2002, height: (this.frame.offsetHeight-2)+'px' })); + + this.cols = []; + this.list_pos = this.list_min_pos = lpos.left; + // save columns positions + for (i=0; i= this.cols[i]/2 + this.list_pos + cpos) + cpos += this.cols[i]; + else + break; + } + + // handle fixed columns on left + if (i == 0 && this.list_min_pos > pos.x) + cpos = this.list_min_pos - this.list_pos; + // empty list needs some assignment + else if (!this.list.rowcount && i == this.cols.length) + cpos -= 2; + $('#rcmcolumnindicator').css({ width: cpos+'px'}); + this.triggerEvent('column_dragmove', e?e:window.event); + } + + this.drag_start = false; + + return false; +}, + + +/** + * Handler for mouse up events for dragging list columns + */ +column_drag_mouse_up: function(e) +{ + document.onmousemove = null; + + if (this.col_draglayer) { + (this.col_draglayer).remove(); + this.col_draglayer = null; + } + + if (this.col_drag_active) + this.focus(); + this.col_drag_active = false; + + rcube_event.remove_listener({event:'mousemove', object:this, method:'column_drag_mouse_move'}); + rcube_event.remove_listener({event:'mouseup', object:this, method:'column_drag_mouse_up'}); + // remove temp divs + this.del_dragfix(); + + if (this.selected_column !== null && this.cols && this.cols.length) { + var i, cpos = 0, pos = rcube_event.get_mouse_pos(e); + + // find destination position + for (i=0; i= this.cols[i]/2 + this.list_pos + cpos) + cpos += this.cols[i]; + else + break; + } + + if (i != this.selected_column && i != this.selected_column+1) { + this.column_replace(this.selected_column, i); + } + } + + this.triggerEvent('column_dragend'); + + return rcube_event.cancel(e); +}, + + +/** + * Creates a layer for drag&drop over iframes + */ +add_dragfix: function() +{ + $('iframe').each(function() { + $('
') + .css({background: '#fff', + width: this.offsetWidth+'px', height: this.offsetHeight+'px', + position: 'absolute', opacity: '0.001', zIndex: 1000 + }) + .css($(this).offset()) + .appendTo(document.body); + }); +}, + + +/** + * Removes the layer for drag&drop over iframes + */ +del_dragfix: function() +{ + $('div.iframe-dragdrop-fix').each(function() { this.parentNode.removeChild(this); }); +}, + + +/** + * Replaces two columns + */ +column_replace: function(from, to) +{ + var cells = this.list.tHead.rows[0].cells, + elem = cells[from], + before = cells[to], + td = document.createElement('td'); + + // replace header cells + if (before) + cells[0].parentNode.insertBefore(td, before); + else + cells[0].parentNode.appendChild(td); + cells[0].parentNode.replaceChild(elem, td); + + // replace list cells + for (r=0; r from ? to - 1 : to; + + this.triggerEvent('column_replace'); +}, + + /** * Creating the list in background */ -- cgit v1.2.3