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 show('field_number_block');
136 hide('with_value_block');
137 show('to_field_block');
141 show('field_number_block');
142 hide('with_value_block');
143 show('to_field_block');
146 case 'copy_and_replace_field':
147 show('field_number_block');
148 hide('with_value_block');
149 show('to_field_block');
155 function onConditionalChange(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;
164 hide('conditional_block');
169 show('conditional_block');
174 function onConditionalComparisonChange(selectObj) {
175 // get the index of the selected option
176 var idx = selectObj.selectedIndex;
178 // get the value of the selected option
179 var action = selectObj.options[idx].value;
184 show('conditional_comparison_block');
188 hide('conditional_comparison_block');
193 function onToFieldRegexChange( checkboxObj ) {
194 if ( checkboxObj.checked ) {
195 show('to_field_regex_value_block');
197 hide('to_field_regex_value_block');
201 function onConditionalRegexChange( checkboxObj ) {
202 if ( checkboxObj.checked ) {
203 $("span.match_regex_prefix" ).show();
204 $("span.match_regex_suffix" ).show();
206 $("span.match_regex_prefix" ).hide();
207 $("span.match_regex_suffix" ).hide();
211 function show(eltId) {
212 elt = document.getElementById( eltId );
213 elt.style.display='inline';
216 function hide(eltId) {
217 clearFormElements( eltId );
218 elt = document.getElementById( eltId );
219 elt.style.display='none';
222 function clearFormElements(divId) {
223 myBlock = document.getElementById( divId );
225 var inputElements = myBlock.getElementsByTagName( "input" );
226 for (var i = 0; i < inputElements.length; i++) {
227 switch( inputElements[i].type ) {
229 inputElements[i].value = '';
232 inputElements[i].checked = false;
237 var selectElements = myBlock.getElementsByTagName( "select" );
238 for (var i = 0; i < selectElements.length; i++) {
239 selectElements[i].selectedIndex = 0;
244 function confirmDeleteAction() {
245 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE_ACTION );
248 function confirmDelete() {
249 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE );
252 var modaction_legend_innerhtml;
253 var action_submit_value;
255 function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
256 to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
257 conditional_comparison, conditional_value, conditional_regex, description
259 $("#add_action").show();
260 document.getElementById('mmta_id').value = mmta_id;
262 setSelectByValue( 'action', action );
263 $('#action').change();
265 setSelectByValue( 'field_number', field_number );
267 document.getElementById('from_field').value = from_field;
268 document.getElementById('from_subfield').value = from_subfield;
269 document.getElementById('field_value').value = field_value;
270 document.getElementById('to_field').value = to_field;
271 document.getElementById('to_subfield').value = to_subfield;
272 if ( to_regex_search == '' && to_regex_replace == '' && to_regex_modifiers == '' ) {
273 $('#to_field_regex').prop('checked', false).change();
275 $('#to_field_regex').prop('checked', true).change();
276 $("#to_regex_search").val(to_regex_search);
277 $("#to_regex_replace").val(to_regex_replace);
278 $("#to_regex_modifiers").val(to_regex_modifiers);
281 setSelectByValue( 'conditional', conditional );
282 $('#conditional').change();
284 document.getElementById('conditional_field').value = conditional_field;
285 document.getElementById('conditional_subfield').value = conditional_subfield;
287 setSelectByValue( 'conditional_comparison', conditional_comparison );
288 $('#conditional_comparison').change();
290 document.getElementById('conditional_value').value = conditional_value;
292 document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
293 $('#conditional_regex').change();
295 document.getElementById('description').value = description;
297 window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
298 document.getElementById('modaction_legend').innerHTML = MSG_MMT_EDIT_ACTION.format(ordering);
300 window.action_submit_value = document.getElementById('action_submit').value;
301 document.getElementById('action_submit').value = MSG_MMT_UPDATE_ACTION;
304 function cancelEditAction() {
305 document.getElementById('mmta_id').value = '';
307 setSelectByValue( 'action', 'delete_field' );
308 $('#action').change();
310 document.getElementById('from_field').value = '';
311 document.getElementById('from_subfield').value = '';
312 document.getElementById('field_value').value = '';
313 document.getElementById('to_field').value = '';
314 document.getElementById('to_subfield').value = '';
315 $("#to_regex_search").val("");
316 $("#to_regex_replace").val("");
317 $("#to_regex_modifiers").val("");
318 $("#description").val("");
320 $('#to_field_regex').prop('checked', false).change();
322 setSelectByValue( 'conditional', '' );
323 $('#conditional').change();
325 document.getElementById('conditional_field').value = '';
326 document.getElementById('conditional_subfield').value = '';
328 setSelectByValue( 'conditional_comparison', '' );
329 $('#conditional_comparison').change();
331 document.getElementById('conditional_value').value = '';
333 document.getElementById('conditional_regex').checked = false;
335 document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml;
336 document.getElementById('action_submit').value = window.action_submit_value;
337 $("#add_action").hide();
340 function setSelectByValue( selectId, value ) {
341 s = document.getElementById( selectId );
343 for ( i = 0; i < s.options.length; i++ ) {
344 if ( s.options[i].value == value ) {