1 $(document).ready(function() {
2 window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
3 window.action_submit_value = document.getElementById('action_submit').value;
5 $('#select_template').find("input:submit").hide();
6 $('#select_template').change(function() {
7 $('#select_template').submit();
9 $("span.match_regex_prefix" ).hide();
10 $("span.match_regex_suffix" ).hide();
12 $("#add_action").submit(function(){
13 var action = $("#action").val();
14 if ( action == 'move_field' || action == 'copy_field' || action == 'copy_and_replace_field') {
15 if ( $("#from_subfield").val().length != $("#to_subfield").val().length ) {
16 alert( MSG_MMT_SUBFIELDS_MATCH );
19 if ( $("#to_field").val().length <= 0 ) {
20 alert( MSG_MMT_DESTINATION_REQUIRED );
23 if ( ( $("#to_field").val() < 10 && $("#to_subfield").val().length > 0 ) ||
24 ( $("#from_field").val() < 10 && $("#from_subfield").val().length > 0 ) ) {
25 alert( MSG_MMT_CONTROL_FIELD_EMPTY );
28 if ( ( $("#from_field").val() < 10 && $("#to_subfield").val().length === 0 ) ||
29 ( $("#to_field").val() < 10 && $("#from_subfield").val().length === 0 ) ) {
30 alert( MSG_MMT_CONTROL_FIELD );
34 if ( action == 'update_field' ) {
35 if ( $("#from_subfield").val().length <= 0 ) {
36 alert( MSG_MMT_SOURCE_SUBFIELD );
40 if ( $("#from_field").val().length <= 0 ) {
41 alert( MSG_MMT_SOURCE_FIELD );
46 $("#conditional_field,#from_field").change(function(){
50 $("#new_action").on("click",function(e){
53 $("#add_action").show();
57 $(".duplicate_template").on("click",function(e){
59 var template_id = $(this).data("template_id");
60 $("#duplicate_a_template").val(template_id);
61 $("#duplicate_current_template").val(1);
64 $('#createTemplate').on('shown', function (e) {
66 $("#template_name").focus();
69 $("#duplicate_a_template").on("change",function(e){
71 if( this.value == '' ){
72 $("#duplicate_current_template").val("");
74 $("#duplicate_current_template").val(1);
78 $(".delete_template").on("click",function(e){
80 return confirmDelete();
85 function updateAllEvery(){
86 if ( $("#conditional_field").is(":visible") ) {
87 if ( $("#conditional_field").val() == $("#from_field").val() && $("#from_field").val().length > 0 ) {
88 $("#field_number option[value='0']").html( MSG_MMT_EVERY );
90 $("#field_number option[value='0']").html( MSG_MMT_ALL );
95 function onActionChange(selectObj) {
96 // get the index of the selected option
97 var idx = selectObj.selectedIndex;
99 // get the value of the selected option
100 var action = selectObj.options[idx].value;
104 show('field_number_block');
105 hide('with_value_block');
106 hide('to_field_block');
110 hide('field_number_block');
111 show('with_value_block');
112 hide('to_field_block');
116 show('field_number_block');
117 hide('with_value_block');
118 show('to_field_block');
122 show('field_number_block');
123 hide('with_value_block');
124 show('to_field_block');
127 case 'copy_and_replace_field':
128 show('field_number_block');
129 hide('with_value_block');
130 show('to_field_block');
136 function onConditionalChange(selectObj) {
137 // get the index of the selected option
138 var idx = selectObj.selectedIndex;
140 // get the value of the selected option
141 var action = selectObj.options[idx].value;
145 hide('conditional_block');
150 show('conditional_block');
155 function onConditionalComparisonChange(selectObj) {
156 // get the index of the selected option
157 var idx = selectObj.selectedIndex;
159 // get the value of the selected option
160 var action = selectObj.options[idx].value;
165 show('conditional_comparison_block');
169 hide('conditional_comparison_block');
174 function onToFieldRegexChange( checkboxObj ) {
175 if ( checkboxObj.checked ) {
176 show('to_field_regex_value_block');
178 hide('to_field_regex_value_block');
182 function onConditionalRegexChange( checkboxObj ) {
183 if ( checkboxObj.checked ) {
184 $("span.match_regex_prefix" ).show();
185 $("span.match_regex_suffix" ).show();
187 $("span.match_regex_prefix" ).hide();
188 $("span.match_regex_suffix" ).hide();
192 function show(eltId) {
193 elt = document.getElementById( eltId );
194 elt.style.display='inline';
197 function hide(eltId) {
198 clearFormElements( eltId );
199 elt = document.getElementById( eltId );
200 elt.style.display='none';
203 function clearFormElements(divId) {
204 myBlock = document.getElementById( divId );
206 var inputElements = myBlock.getElementsByTagName( "input" );
207 for (var i = 0; i < inputElements.length; i++) {
208 switch( inputElements[i].type ) {
210 inputElements[i].value = '';
213 inputElements[i].checked = false;
218 var selectElements = myBlock.getElementsByTagName( "select" );
219 for (var i = 0; i < selectElements.length; i++) {
220 selectElements[i].selectedIndex = 0;
225 function confirmDeleteAction() {
226 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE_ACTION );
229 function confirmDelete() {
230 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE );
233 var modaction_legend_innerhtml;
234 var action_submit_value;
236 function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
237 to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
238 conditional_comparison, conditional_value, conditional_regex, description
240 $("#add_action").show();
241 document.getElementById('mmta_id').value = mmta_id;
243 setSelectByValue( 'action', action );
244 document.getElementById('action').onchange();
246 setSelectByValue( 'field_number', field_number );
248 document.getElementById('from_field').value = from_field;
249 document.getElementById('from_subfield').value = from_subfield;
250 document.getElementById('field_value').value = field_value;
251 document.getElementById('to_field').value = to_field;
252 document.getElementById('to_subfield').value = to_subfield;
253 $("#to_regex_search").val(to_regex_search);
254 $("#to_regex_replace").val(to_regex_replace);
255 $("#to_regex_modifiers").val(to_regex_modifiers);
257 document.getElementById('to_field_regex').checked = conditional_regex.length;
258 document.getElementById('to_field_regex').onchange();
260 setSelectByValue( 'conditional', conditional );
261 document.getElementById('conditional').onchange();
263 document.getElementById('conditional_field').value = conditional_field;
264 document.getElementById('conditional_subfield').value = conditional_subfield;
266 setSelectByValue( 'conditional_comparison', conditional_comparison );
267 document.getElementById('conditional_comparison').onchange();
269 document.getElementById('conditional_value').value = conditional_value;
271 document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
273 document.getElementById('description').value = description;
275 window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
276 document.getElementById('modaction_legend').innerHTML = MSG_MMT_EDIT_ACTION.format(ordering);
278 window.action_submit_value = document.getElementById('action_submit').value;
279 document.getElementById('action_submit').value = MSG_MMT_UPDATE_ACTION;
282 function cancelEditAction() {
283 document.getElementById('mmta_id').value = '';
285 setSelectByValue( 'action', 'delete_field' );
286 document.getElementById('action').onchange();
288 document.getElementById('from_field').value = '';
289 document.getElementById('from_subfield').value = '';
290 document.getElementById('field_value').value = '';
291 document.getElementById('to_field').value = '';
292 document.getElementById('to_subfield').value = '';
293 $("#to_regex_search").val("");
294 $("#to_regex_replace").val("");
295 $("#to_regex_modifiers").val("");
296 $("#description").val("");
298 document.getElementById('to_field_regex').checked = false;
299 document.getElementById('to_field_regex').onchange();
301 setSelectByValue( 'conditional', '' );
302 document.getElementById('conditional').onchange();
304 document.getElementById('conditional_field').value = '';
305 document.getElementById('conditional_subfield').value = '';
307 setSelectByValue( 'conditional_comparison', '' );
308 document.getElementById('conditional_comparison').onchange();
310 document.getElementById('conditional_value').value = '';
312 document.getElementById('conditional_regex').checked = false;
314 document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml;
315 document.getElementById('action_submit').value = window.action_submit_value;
316 $("#add_action").hide();
319 function setSelectByValue( selectId, value ) {
320 s = document.getElementById( selectId );
322 for ( i = 0; i < s.options.length; i++ ) {
323 if ( s.options[i].value == value ) {