From 76e30ecf783c4fc3edc2166ba38921b565e7566d Mon Sep 17 00:00:00 2001 From: buinsky Date: Tue, 9 Dec 2014 21:03:14 +0300 Subject: [PATCH] Dynamically show 'Start' and 'Pause' menu items --- src/webui/www/public/scripts/contextmenu.js | 57 ++++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/webui/www/public/scripts/contextmenu.js b/src/webui/www/public/scripts/contextmenu.js index 660bfb54a..b459ec892 100644 --- a/src/webui/www/public/scripts/contextmenu.js +++ b/src/webui/www/public/scripts/contextmenu.js @@ -129,29 +129,82 @@ var ContextMenu = new Class({ updateMenuItems: function () { all_are_seq_dl = true; + there_are_seq_dl = false; all_are_f_l_piece_prio = true; + there_are_f_l_piece_prio = false; all_are_downloaded = true; + all_are_paused = true; + there_are_paused = false; var h = myTable.selectedIds(); h.each(function(item, index){ tr = myTable.rows.get(item); + if (tr.getAttribute('seq_dl') != 'true') all_are_seq_dl = false; + else + there_are_seq_dl = true; + if (tr.getAttribute('f_l_piece_prio') != 'true') all_are_f_l_piece_prio = false; + else + there_are_f_l_piece_prio = true; + if (tr.getAttribute('downloaded') != 'true') all_are_downloaded = false; + + state = tr.getAttribute('state'); + if ((state != 'pausedUP') && (state != 'pausedDL')) + all_are_paused = false; + else + there_are_paused = true; }); + show_seq_dl = true; + + if (!all_are_seq_dl && there_are_seq_dl) + show_seq_dl = false; + + show_f_l_piece_prio = true; + + if (!all_are_f_l_piece_prio && there_are_f_l_piece_prio) + show_f_l_piece_prio = false; + if (all_are_downloaded) { this.hideItem('SequentialDownload'); this.hideItem('FirstLastPiecePrio'); } else { - this.showItem('SequentialDownload'); - this.showItem('FirstLastPiecePrio'); + if (!show_seq_dl && show_f_l_piece_prio) + this.menu.getElement('a[href$=FirstLastPiecePrio]').parentNode.addClass('separator'); + else + this.menu.getElement('a[href$=FirstLastPiecePrio]').parentNode.removeClass('separator'); + + if (show_seq_dl) + this.showItem('SequentialDownload'); + else + this.hideItem('SequentialDownload'); + + if (show_f_l_piece_prio) + this.showItem('FirstLastPiecePrio'); + else + this.hideItem('FirstLastPiecePrio'); + this.setItemChecked('SequentialDownload', all_are_seq_dl); this.setItemChecked('FirstLastPiecePrio', all_are_f_l_piece_prio); } + + if (all_are_paused) { + this.showItem('Start'); + this.hideItem('Pause'); + } else { + if (there_are_paused) { + this.showItem('Start'); + this.showItem('Pause'); + } else { + this.hideItem('Start'); + this.showItem('Pause'); + } + } }, //show menu