diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2011-01-20 00:01:55 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2011-01-20 00:01:55 +0000 |
commit | 80e1900b03b2a5315c791f9240f9d7641ae67562 (patch) | |
tree | 15a05c8a7cfc6f251cf58589f4aa243260979807 /libs/web/htdocs | |
parent | c176c70d5bfec1061f894c31dd6f2fd826c2d8cf (diff) |
libs/web: implement sortable rows for uci reordering
Diffstat (limited to 'libs/web/htdocs')
-rw-r--r-- | libs/web/htdocs/luci-static/resources/cbi.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libs/web/htdocs/luci-static/resources/cbi.js b/libs/web/htdocs/luci-static/resources/cbi.js index 992b5588e..ac4eaa9b2 100644 --- a/libs/web/htdocs/luci-static/resources/cbi.js +++ b/libs/web/htdocs/luci-static/resources/cbi.js @@ -718,6 +718,50 @@ function cbi_validate_field(cbid, optional, type) } } +function cbi_row_swap(elem, up, store) +{ + var tr = elem.parentNode; + while (tr && tr.nodeName != 'tr') + tr = tr.parentNode; + + var table = tr.parentNode; + while (table && table.nodeName != 'table') + table = table.parentNode; + + var s = up ? 3 : 2; + var e = up ? table.rows.length : table.rows.length - 1; + + for (var idx = s; idx < e; idx++) + { + if (table.rows[idx] == tr) + { + if (up) + tr.parentNode.insertBefore(table.rows[idx], table.rows[idx-1]); + else + tr.parentNode.insertBefore(table.rows[idx+1], table.rows[idx]); + + break; + } + } + + var ids = [ ]; + for (idx = 2; idx < table.rows.length; idx++) + { + table.rows[idx].className = table.rows[idx].className.replace( + /cbi-rowstyle-[12]/, 'cbi-rowstyle-' + (1 + (idx % 2)) + ); + + if (table.rows[idx].id && table.rows[idx].id.match(/-(cfg[0-9a-f]+)$/) ) + ids.push(RegExp.$1); + } + + var input = document.getElementById(store); + if (input) + input.value = ids.join(' '); + + return false; +} + if( ! String.serialize ) String.serialize = function(o) { |