1 $(document).ready(function() {
2 window.modaction_legend_innerhtml = $("#modaction_legend").text();
3 window.action_submit_value = $("#action_submit").val();
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 );
44 if ( $("#conditional").val() == 'if' || $("#conditional").val() == 'unless' ) {
45 if ( $("#conditional_field").val() == '' ) {
46 alert( MSG_MMT_CONDITIONAL_FIELD_REQUIRED );
49 if ( $("#conditional_comparison").val() == '' ) {
50 alert( MSG_MMT_CONDITIONAL_COMPARISON_REQUIRED );
53 if ( $("#conditional_value").val() == '' &&
54 ( $("#conditional_comparison").val() == 'equals' || $("#conditional_comparison").val() == 'not_equals' ) ) {
55 if ( document.getElementById('conditional_regex').checked == true ) {
56 alert( MSG_MMT_CONDITIONAL_VALUE_REGEX_REQUIRED );
59 alert( MSG_MMT_CONDITIONAL_VALUE_REQUIRED );
66 $("#conditional_field,#from_field").change(function(){
70 $("#new_action").on("click",function(e){
73 $("#add_action").show();
77 $(".duplicate_template").on("click",function(e){
79 var template_id = $(this).data("template_id");
80 $("#duplicate_a_template").val(template_id);
81 $("#duplicate_current_template").val(1);
84 $('#createTemplate').on('shown.bs.modal', function (e) {
86 $("#template_name").focus();
89 $("#duplicate_a_template").on("change",function(e){
91 if( this.value === '' ){
92 $("#duplicate_current_template").val("");
94 $("#duplicate_current_template").val(1);
98 $(".delete_template").on("click",function(){
99 return confirmDelete();
104 function updateAllEvery(){
105 if ( $("#conditional_field").is(":visible") ) {
106 if ( $("#conditional_field").val() == $("#from_field").val() && $("#from_field").val().length > 0 ) {
107 $("#field_number option[value='0']").html( MSG_MMT_EVERY );
109 $("#field_number option[value='0']").html( MSG_MMT_ALL );
114 function onActionChange(selectObj) {
115 // get the index of the selected option
116 var idx = selectObj.selectedIndex;
118 // get the value of the selected option
119 var action = selectObj.options[idx].value;
123 show('field_number_block');
124 hide('with_value_block');
125 hide('to_field_block');
129 hide('field_number_block');
130 show('with_value_block');
131 hide('to_field_block');
135 hide('field_number_block');
136 show('with_value_block');
137 hide('to_field_block');
141 show('field_number_block');
142 hide('with_value_block');
143 show('to_field_block');
147 show('field_number_block');
148 hide('with_value_block');
149 show('to_field_block');
152 case 'copy_and_replace_field':
153 show('field_number_block');
154 hide('with_value_block');
155 show('to_field_block');
161 function onConditionalChange(selectObj) {
162 // get the index of the selected option
163 var idx = selectObj.selectedIndex;
165 // get the value of the selected option
166 var action = selectObj.options[idx].value;
170 hide('conditional_block');
175 show('conditional_block');
180 function onConditionalComparisonChange(selectObj) {
181 // get the index of the selected option
182 var idx = selectObj.selectedIndex;
184 // get the value of the selected option
185 var action = selectObj.options[idx].value;
190 show('conditional_comparison_block');
194 hide('conditional_comparison_block');
199 function onToFieldRegexChange( checkboxObj ) {
200 if ( checkboxObj.checked ) {
201 show('to_field_regex_value_block');
203 hide('to_field_regex_value_block');
207 function onConditionalRegexChange( checkboxObj ) {
208 if ( checkboxObj.checked ) {
209 $("span.match_regex_prefix" ).show();
210 $("span.match_regex_suffix" ).show();
212 $("span.match_regex_prefix" ).hide();
213 $("span.match_regex_suffix" ).hide();
217 function show(eltId) {
218 elt = document.getElementById( eltId );
219 elt.style.display='inline';
222 function hide(eltId) {
223 clearFormElements( eltId );
224 elt = document.getElementById( eltId );
225 elt.style.display='none';
228 function clearFormElements(divId) {
229 myBlock = document.getElementById( divId );
231 var inputElements = myBlock.getElementsByTagName( "input" );
232 for (var i = 0; i < inputElements.length; i++) {
233 switch( inputElements[i].type ) {
235 inputElements[i].value = '';
238 inputElements[i].checked = false;
243 var selectElements = myBlock.getElementsByTagName( "select" );
244 for (var i = 0; i < selectElements.length; i++) {
245 selectElements[i].selectedIndex = 0;
250 function confirmDeleteAction() {
251 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE_ACTION );
254 function confirmDelete() {
255 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE );
258 var modaction_legend_innerhtml;
259 var action_submit_value;
261 function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
262 to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
263 conditional_comparison, conditional_value, conditional_regex, description
265 $("#add_action").show();
266 document.getElementById('mmta_id').value = mmta_id;
268 setSelectByValue( 'action', action );
269 $('#action').change();
271 setSelectByValue( 'field_number', field_number );
273 document.getElementById('from_field').value = from_field;
274 document.getElementById('from_subfield').value = from_subfield;
275 document.getElementById('field_value').value = field_value;
276 document.getElementById('to_field').value = to_field;
277 document.getElementById('to_subfield').value = to_subfield;
278 if ( to_regex_search == '' && to_regex_replace == '' && to_regex_modifiers == '' ) {
279 $('#to_field_regex').prop('checked', false).change();
281 $('#to_field_regex').prop('checked', true).change();
282 $("#to_regex_search").val(to_regex_search);
283 $("#to_regex_replace").val(to_regex_replace);
284 $("#to_regex_modifiers").val(to_regex_modifiers);
287 setSelectByValue( 'conditional', conditional );
288 $('#conditional').change();
290 document.getElementById('conditional_field').value = conditional_field;
291 document.getElementById('conditional_subfield').value = conditional_subfield;
293 setSelectByValue( 'conditional_comparison', conditional_comparison );
294 $('#conditional_comparison').change();
296 document.getElementById('conditional_value').value = conditional_value;
298 document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
299 $('#conditional_regex').change();
301 document.getElementById('description').value = description;
303 window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
304 document.getElementById('modaction_legend').innerHTML = MSG_MMT_EDIT_ACTION.format(ordering);
306 window.action_submit_value = document.getElementById('action_submit').value;
307 document.getElementById('action_submit').value = MSG_MMT_UPDATE_ACTION;
310 function cancelEditAction() {
311 document.getElementById('mmta_id').value = '';
313 setSelectByValue( 'action', 'delete_field' );
314 $('#action').change();
316 document.getElementById('from_field').value = '';
317 document.getElementById('from_subfield').value = '';
318 document.getElementById('field_value').value = '';
319 document.getElementById('to_field').value = '';
320 document.getElementById('to_subfield').value = '';
321 $("#to_regex_search").val("");
322 $("#to_regex_replace").val("");
323 $("#to_regex_modifiers").val("");
324 $("#description").val("");
326 $('#to_field_regex').prop('checked', false).change();
328 setSelectByValue( 'conditional', '' );
329 $('#conditional').change();
331 document.getElementById('conditional_field').value = '';
332 document.getElementById('conditional_subfield').value = '';
334 setSelectByValue( 'conditional_comparison', '' );
335 $('#conditional_comparison').change();
337 document.getElementById('conditional_value').value = '';
339 document.getElementById('conditional_regex').checked = false;
341 document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml;
342 document.getElementById('action_submit').value = window.action_submit_value;
343 $("#add_action").hide();
346 function setSelectByValue( selectId, value ) {
347 s = document.getElementById( selectId );
349 for ( i = 0; i < s.options.length; i++ ) {
350 if ( s.options[i].value == value ) {