Moved javascript filters functions to application.js.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8698 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-01-24 18:02:22 +00:00
parent 669a8c68a7
commit 858bd8dc40
2 changed files with 99 additions and 103 deletions

View File

@ -1,106 +1,3 @@
<script type="text/javascript">
//<![CDATA[
function add_filter() {
select = $('add_filter_select');
field = select.value
Element.show('tr_' + field);
check_box = $('cb_' + field);
check_box.checked = true;
toggle_filter(field);
select.selectedIndex = 0;
for (i=0; i<select.options.length; i++) {
if (select.options[i].value == field) {
select.options[i].disabled = true;
}
}
}
function toggle_filter(field) {
check_box = $('cb_' + field);
if (check_box.checked) {
Element.show("operators_" + field);
Form.Element.enable("operators_" + field);
toggle_operator(field);
} else {
Element.hide("operators_" + field);
Form.Element.disable("operators_" + field);
enableValues(field, []);
}
}
function enableValues(field, indexes) {
var f = $$(".values_" + field);
for(var i=0;i<f.length;i++) {
if (indexes.include(i)) {
Form.Element.enable(f[i]);
f[i].up('span').show();
} else {
f[i].value = '';
Form.Element.disable(f[i]);
f[i].up('span').hide();
}
}
if (indexes.length > 0) {
Element.show("div_values_" + field);
} else {
Element.hide("div_values_" + field);
}
}
function toggle_operator(field) {
operator = $("operators_" + field);
switch (operator.value) {
case "!*":
case "*":
case "t":
case "w":
case "o":
case "c":
enableValues(field, []);
break;
case "><":
enableValues(field, [0,1]);
break;
case "<t+":
case ">t+":
case "t+":
case ">t-":
case "<t-":
case "t-":
enableValues(field, [2]);
break;
default:
enableValues(field, [0]);
break;
}
}
function toggle_multi_select(el) {
var select = $(el);
if (select.multiple == true) {
select.multiple = false;
} else {
select.multiple = true;
}
}
function submit_query_form(id) {
selectAllOptions("selected_columns");
$(id).submit();
}
function apply_filters_observer() {
$$("#query_form input[type=text]").invoke("observe", "keypress", function(e){
if(e.keyCode == Event.KEY_RETURN) {
submit_query_form("query_form");
}
});
}
Event.observe(document,"dom:loaded", apply_filters_observer);
//]]>
</script>
<table width="100%"> <table width="100%">
<tr> <tr>
<td> <td>
@ -153,3 +50,4 @@ Event.observe(document,"dom:loaded", apply_filters_observer);
</tr> </tr>
</table> </table>
<%= hidden_field_tag 'f[]', '' %> <%= hidden_field_tag 'f[]', '' %>
<%= javascript_tag 'Event.observe(window,"load",apply_filters_observer);' %>

View File

@ -83,6 +83,104 @@ function hideFieldset(el) {
fieldset.down('div').hide(); fieldset.down('div').hide();
} }
function add_filter() {
select = $('add_filter_select');
field = select.value
Element.show('tr_' + field);
check_box = $('cb_' + field);
check_box.checked = true;
toggle_filter(field);
select.selectedIndex = 0;
for (i=0; i<select.options.length; i++) {
if (select.options[i].value == field) {
select.options[i].disabled = true;
}
}
}
function toggle_filter(field) {
check_box = $('cb_' + field);
if (check_box.checked) {
Element.show("operators_" + field);
Form.Element.enable("operators_" + field);
toggle_operator(field);
} else {
Element.hide("operators_" + field);
Form.Element.disable("operators_" + field);
enableValues(field, []);
}
}
function enableValues(field, indexes) {
var f = $$(".values_" + field);
for(var i=0;i<f.length;i++) {
if (indexes.include(i)) {
Form.Element.enable(f[i]);
f[i].up('span').show();
} else {
f[i].value = '';
Form.Element.disable(f[i]);
f[i].up('span').hide();
}
}
if (indexes.length > 0) {
Element.show("div_values_" + field);
} else {
Element.hide("div_values_" + field);
}
}
function toggle_operator(field) {
operator = $("operators_" + field);
switch (operator.value) {
case "!*":
case "*":
case "t":
case "w":
case "o":
case "c":
enableValues(field, []);
break;
case "><":
enableValues(field, [0,1]);
break;
case "<t+":
case ">t+":
case "t+":
case ">t-":
case "<t-":
case "t-":
enableValues(field, [2]);
break;
default:
enableValues(field, [0]);
break;
}
}
function toggle_multi_select(el) {
var select = $(el);
if (select.multiple == true) {
select.multiple = false;
} else {
select.multiple = true;
}
}
function submit_query_form(id) {
selectAllOptions("selected_columns");
$(id).submit();
}
function apply_filters_observer() {
$$("#query_form input[type=text]").invoke("observe", "keypress", function(e){
if(e.keyCode == Event.KEY_RETURN) {
submit_query_form("query_form");
}
});
}
var fileFieldCount = 1; var fileFieldCount = 1;
function addFileField() { function addFileField() {