diff --git a/app/views/queries/_columns.rhtml b/app/views/queries/_columns.rhtml index e11b286b62028b10927963bb5149367efe867287..91ee627b271363c47d28b36228e876ec0a597c40 100644 --- a/app/views/queries/_columns.rhtml +++ b/app/views/queries/_columns.rhtml @@ -5,15 +5,19 @@ :multiple => true, :size => 10, :style => "width:150px" %> </td> <td align="center" valign="middle"> - <input type="button" value="-->" + <input type="button" value="→" onclick="moveOptions(this.form.available_columns, this.form.selected_columns);" /><br /> - <input type="button" value="<--" + <input type="button" value="←" onclick="moveOptions(this.form.selected_columns, this.form.available_columns);" /> </td> <td><%= select_tag 'query[column_names][]', options_for_select(query.columns.collect {|column| [column.caption, column.name]}), :id => 'selected_columns', :multiple => true, :size => 10, :style => "width:150px" %> </td> + <td align="center" valign="middle"> + <input type="button" value="↑" onclick="moveOptionUp(this.form.selected_columns);" /><br /> + <input type="button" value="↓" onclick="moveOptionDown(this.form.selected_columns);" /> + </td> </tr> </table> diff --git a/public/javascripts/select_list_move.js b/public/javascripts/select_list_move.js index 1ced88232217fb85dd8e3b5f03ec1427480985f5..a9c5bfd36110367b44edeb77172a87db9c34c419 100644 --- a/public/javascripts/select_list_move.js +++ b/public/javascripts/select_list_move.js @@ -7,6 +7,17 @@ function addOption(theSel, theText, theValue) theSel.options[selLength] = newOpt; } +function swapOptions(theSel, index1, index2) +{ + var text, value; + text = theSel.options[index1].text; + value = theSel.options[index1].value; + theSel.options[index1].text = theSel.options[index2].text; + theSel.options[index1].value = theSel.options[index2].value; + theSel.options[index2].text = text; + theSel.options[index2].value = value; +} + function deleteOption(theSel, theIndex) { var selLength = theSel.length; @@ -45,6 +56,22 @@ function moveOptions(theSelFrom, theSelTo) if(NS4) history.go(0); } +function moveOptionUp(theSel) { + var index = theSel.selectedIndex; + if (index > 0) { + swapOptions(theSel, index-1, index); + theSel.selectedIndex = index-1; + } +} + +function moveOptionDown(theSel) { + var index = theSel.selectedIndex; + if (index < theSel.length - 1) { + swapOptions(theSel, index, index+1); + theSel.selectedIndex = index+1; + } +} + function selectAllOptions(id) { var select = $(id);