From 19ad6b15e83f8969432ec171f585f552802b8576 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 12 Sep 2017 18:06:29 +0200 Subject: [PATCH] Add (unified) get_next/get_prev/get_single_selection methods for list and treelist widgets --- program/js/list.js | 16 ++++++++++++++++ program/js/treelist.js | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/program/js/list.js b/program/js/list.js index b07fc5efc..964815607 100644 --- a/program/js/list.js +++ b/program/js/list.js @@ -951,6 +951,22 @@ get_last_row: function() return null; }, +get_next: function() +{ + var row; + if (row = this.get_next_row()) { + return row.uid; + } +}, + +get_prev: function() +{ + var row; + if (row = this.get_prev_row()) { + return row.uid; + } +}, + row_tagname: function() { var row_tagnames = { table:'tr', ul:'li', '*':'div' }; diff --git a/program/js/treelist.js b/program/js/treelist.js index 2f70e84ff..a3a4011e9 100644 --- a/program/js/treelist.js +++ b/program/js/treelist.js @@ -95,6 +95,9 @@ function rcube_treelist_widget(node, p) this.get_item = get_item; this.get_node = get_node; this.get_selection = get_selection; + this.get_next = get_next; + this.get_prev = get_prev; + this.get_single_selection = get_selection; this.is_search = is_search; this.reset_search = reset_search; @@ -921,6 +924,44 @@ function rcube_treelist_widget(node, p) } + function get_next() + { + var node, child; + if (selection && (node = id2dom(selection))) { + child = node.children('ul').children('li:first'); + if (child.length) { + return dom2id(child); + } + + node = node.next(); + if (node.length) { + return dom2id(node); + } + } + } + + function get_prev() + { + var node, prev, child; + if (selection && (node = id2dom(selection))) { + prev = node.prev(); + child = prev.find('li:last'); + + if (child.length) { + return dom2id(child); + } + + if (prev.length) { + return dom2id(prev); + } + + node = node.parent().parent(); + if (node.length && node.is('li')) { + return dom2id(node); + } + } + } + ///// drag & drop support /**