1 $(document).ready(function() {
2 $('#select_template').find("input:submit").hide();
3 $('#select_template').change(function() {
4 $('#select_template').submit();
6 $("span.match_regex_prefix" ).hide();
7 $("span.match_regex_suffix" ).hide();
9 $("#add_action").submit(function(){
10 var action = $("#action").val();
11 if ( action == 'move_field' || action == 'copy_field' || action == 'copy_and_replace_field') {
12 if ( $("#from_subfield").val().length != $("#to_subfield").val().length ) {
13 alert( MSG_MMT_SUBFIELDS_MATCH );
16 if ( $("#to_field").val().length <= 0 ) {
17 alert( MSG_MMT_DESTINATION_REQUIRED );
20 if ( ( $("#to_field").val() < 10 && $("#to_subfield").val().length > 0 ) ||
21 ( $("#from_field").val() < 10 && $("#from_subfield").val().length > 0 ) ) {
22 alert( MSG_MMT_CONTROL_FIELD_EMPTY );
25 if ( ( $("#from_field").val() < 10 && $("#to_subfield").val().length === 0 ) ||
26 ( $("#to_field").val() < 10 && $("#from_subfield").val().length === 0 ) ) {
27 alert( MSG_MMT_CONTROL_FIELD );
31 if ( action == 'update_field' ) {
32 if ( $("#from_subfield").val().length <= 0 ) {
33 alert( MSG_MMT_SOURCE_SUBFIELD );
37 if ( $("#from_field").val().length <= 0 ) {
38 alert( MSG_MMT_SOURCE_FIELD );
43 $("#conditional_field,#from_field").change(function(){
48 function updateAllEvery(){
49 if ( $("#conditional_field").is(":visible") ) {
50 if ( $("#conditional_field").val() == $("#from_field").val() && $("#from_field").val().length > 0 ) {
51 $("#field_number option[value='0']").html( MSG_MMT_EVERY );
53 $("#field_number option[value='0']").html( MSG_MMT_ALL );
58 function onActionChange(selectObj) {
59 // get the index of the selected option
60 var idx = selectObj.selectedIndex;
62 // get the value of the selected option
63 var action = selectObj.options[idx].value;
67 show('field_number_block');
68 hide('with_value_block');
69 hide('to_field_block');
73 hide('field_number_block');
74 show('with_value_block');
75 hide('to_field_block');
79 show('field_number_block');
80 hide('with_value_block');
81 show('to_field_block');
85 show('field_number_block');
86 hide('with_value_block');
87 show('to_field_block');
90 case 'copy_and_replace_field':
91 show('field_number_block');
92 hide('with_value_block');
93 show('to_field_block');
99 function onConditionalChange(selectObj) {
100 // get the index of the selected option
101 var idx = selectObj.selectedIndex;
103 // get the value of the selected option
104 var action = selectObj.options[idx].value;
108 hide('conditional_block');
113 show('conditional_block');
118 function onConditionalComparisonChange(selectObj) {
119 // get the index of the selected option
120 var idx = selectObj.selectedIndex;
122 // get the value of the selected option
123 var action = selectObj.options[idx].value;
128 show('conditional_comparison_block');
132 hide('conditional_comparison_block');
137 function onToFieldRegexChange( checkboxObj ) {
138 if ( checkboxObj.checked ) {
139 show('to_field_regex_value_block');
141 hide('to_field_regex_value_block');
145 function onConditionalRegexChange( checkboxObj ) {
146 if ( checkboxObj.checked ) {
147 $("span.match_regex_prefix" ).show();
148 $("span.match_regex_suffix" ).show();
150 $("span.match_regex_prefix" ).hide();
151 $("span.match_regex_suffix" ).hide();
155 function show(eltId) {
156 elt = document.getElementById( eltId );
157 elt.style.display='inline';
160 function hide(eltId) {
161 clearFormElements( eltId );
162 elt = document.getElementById( eltId );
163 elt.style.display='none';
166 function clearFormElements(divId) {
167 myBlock = document.getElementById( divId );
169 var inputElements = myBlock.getElementsByTagName( "input" );
170 for (var i = 0; i < inputElements.length; i++) {
171 switch( inputElements[i].type ) {
173 inputElements[i].value = '';
176 inputElements[i].checked = false;
181 var selectElements = myBlock.getElementsByTagName( "select" );
182 for (var i = 0; i < selectElements.length; i++) {
183 selectElements[i].selectedIndex = 0;
188 function confirmDeleteAction() {
189 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE_ACTION );
192 function confirmDelete() {
193 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE );
196 var modaction_legend_innerhtml;
197 var action_submit_value;
199 function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
200 to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
201 conditional_comparison, conditional_value, conditional_regex, description
203 document.getElementById('mmta_id').value = mmta_id;
205 setSelectByValue( 'action', action );
206 document.getElementById('action').onchange();
208 setSelectByValue( 'field_number', field_number );
210 document.getElementById('from_field').value = from_field;
211 document.getElementById('from_subfield').value = from_subfield;
212 document.getElementById('field_value').value = field_value;
213 document.getElementById('to_field').value = to_field;
214 document.getElementById('to_subfield').value = to_subfield;
215 $("#to_regex_search").val(to_regex_search);
216 $("#to_regex_replace").val(to_regex_replace);
217 $("#to_regex_modifiers").val(to_regex_modifiers);
219 document.getElementById('to_field_regex').checked = conditional_regex.length;
220 document.getElementById('to_field_regex').onchange();
222 setSelectByValue( 'conditional', conditional );
223 document.getElementById('conditional').onchange();
225 document.getElementById('conditional_field').value = conditional_field;
226 document.getElementById('conditional_subfield').value = conditional_subfield;
228 setSelectByValue( 'conditional_comparison', conditional_comparison );
229 document.getElementById('conditional_comparison').onchange();
231 document.getElementById('conditional_value').value = conditional_value;
233 document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
235 document.getElementById('description').value = description;
237 window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
238 document.getElementById('modaction_legend').innerHTML = MSG_MMT_EDIT_ACTION.format(ordering);
240 window.action_submit_value = document.getElementById('action_submit').value;
241 document.getElementById('action_submit').value = MSG_MMT_UPDATE_ACTION;
246 function cancelEditAction() {
247 document.getElementById('mmta_id').value = '';
249 setSelectByValue( 'action', 'delete_field' );
250 document.getElementById('action').onchange();
252 document.getElementById('from_field').value = '';
253 document.getElementById('from_subfield').value = '';
254 document.getElementById('field_value').value = '';
255 document.getElementById('to_field').value = '';
256 document.getElementById('to_subfield').value = '';
257 $("#to_regex_search").val("");
258 $("#to_regex_replace").val("");
259 $("#to_regex_modifiers").val("");
261 document.getElementById('to_field_regex').checked = false;
262 document.getElementById('to_field_regex').onchange();
264 setSelectByValue( 'conditional', '' );
265 document.getElementById('conditional').onchange();
267 document.getElementById('conditional_field').value = '';
268 document.getElementById('conditional_subfield').value = '';
270 setSelectByValue( 'conditional_comparison', '' );
271 document.getElementById('conditional_comparison').onchange();
273 document.getElementById('conditional_value').value = '';
275 document.getElementById('conditional_regex').checked = false;
277 document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml;
278 document.getElementById('action_submit').value = window.action_submit_value;
283 function setSelectByValue( selectId, value ) {
284 s = document.getElementById( selectId );
286 for ( i = 0; i < s.options.length; i++ ) {
287 if ( s.options[i].value == value ) {