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 );
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.bs.modal', 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(){
79 return confirmDelete();
84 function updateAllEvery(){
85 if ( $("#conditional_field").is(":visible") ) {
86 if ( $("#conditional_field").val() == $("#from_field").val() && $("#from_field").val().length > 0 ) {
87 $("#field_number option[value='0']").html( MSG_MMT_EVERY );
89 $("#field_number option[value='0']").html( MSG_MMT_ALL );
94 function onActionChange(selectObj) {
95 // get the index of the selected option
96 var idx = selectObj.selectedIndex;
98 // get the value of the selected option
99 var action = selectObj.options[idx].value;
103 show('field_number_block');
104 hide('with_value_block');
105 hide('to_field_block');
109 hide('field_number_block');
110 show('with_value_block');
111 hide('to_field_block');
115 hide('field_number_block');
116 show('with_value_block');
117 hide('to_field_block');
121 show('field_number_block');
122 hide('with_value_block');
123 show('to_field_block');
127 show('field_number_block');
128 hide('with_value_block');
129 show('to_field_block');
132 case 'copy_and_replace_field':
133 show('field_number_block');
134 hide('with_value_block');
135 show('to_field_block');
141 function onConditionalChange(selectObj) {
142 // get the index of the selected option
143 var idx = selectObj.selectedIndex;
145 // get the value of the selected option
146 var action = selectObj.options[idx].value;
150 hide('conditional_block');
155 show('conditional_block');
160 function onConditionalComparisonChange(selectObj) {
161 // get the index of the selected option
162 var idx = selectObj.selectedIndex;
164 // get the value of the selected option
165 var action = selectObj.options[idx].value;
170 show('conditional_comparison_block');
174 hide('conditional_comparison_block');
179 function onToFieldRegexChange( checkboxObj ) {
180 if ( checkboxObj.checked ) {
181 show('to_field_regex_value_block');
183 hide('to_field_regex_value_block');
187 function onConditionalRegexChange( checkboxObj ) {
188 if ( checkboxObj.checked ) {
189 $("span.match_regex_prefix" ).show();
190 $("span.match_regex_suffix" ).show();
192 $("span.match_regex_prefix" ).hide();
193 $("span.match_regex_suffix" ).hide();
197 function show(eltId) {
198 elt = document.getElementById( eltId );
199 elt.style.display='inline';
202 function hide(eltId) {
203 clearFormElements( eltId );
204 elt = document.getElementById( eltId );
205 elt.style.display='none';
208 function clearFormElements(divId) {
209 myBlock = document.getElementById( divId );
211 var inputElements = myBlock.getElementsByTagName( "input" );
212 for (var i = 0; i < inputElements.length; i++) {
213 switch( inputElements[i].type ) {
215 inputElements[i].value = '';
218 inputElements[i].checked = false;
223 var selectElements = myBlock.getElementsByTagName( "select" );
224 for (var i = 0; i < selectElements.length; i++) {
225 selectElements[i].selectedIndex = 0;
230 function confirmDeleteAction() {
231 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE_ACTION );
234 function confirmDelete() {
235 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE );
238 var modaction_legend_innerhtml;
239 var action_submit_value;
241 function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
242 to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
243 conditional_comparison, conditional_value, conditional_regex, description
245 $("#add_action").show();
246 document.getElementById('mmta_id').value = mmta_id;
248 setSelectByValue( 'action', action );
249 $('#action').change();
251 setSelectByValue( 'field_number', field_number );
253 document.getElementById('from_field').value = from_field;
254 document.getElementById('from_subfield').value = from_subfield;
255 document.getElementById('field_value').value = field_value;
256 document.getElementById('to_field').value = to_field;
257 document.getElementById('to_subfield').value = to_subfield;
258 if ( to_regex_search == '' && to_regex_replace == '' && to_regex_modifiers == '' ) {
259 $('#to_field_regex').prop('checked', false).change();
261 $('#to_field_regex').prop('checked', true).change();
262 $("#to_regex_search").val(to_regex_search);
263 $("#to_regex_replace").val(to_regex_replace);
264 $("#to_regex_modifiers").val(to_regex_modifiers);
267 setSelectByValue( 'conditional', conditional );
268 $('#conditional').change();
270 document.getElementById('conditional_field').value = conditional_field;
271 document.getElementById('conditional_subfield').value = conditional_subfield;
273 setSelectByValue( 'conditional_comparison', conditional_comparison );
274 $('#conditional_comparison').change();
276 document.getElementById('conditional_value').value = conditional_value;
278 document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
280 document.getElementById('description').value = description;
282 window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
283 document.getElementById('modaction_legend').innerHTML = MSG_MMT_EDIT_ACTION.format(ordering);
285 window.action_submit_value = document.getElementById('action_submit').value;
286 document.getElementById('action_submit').value = MSG_MMT_UPDATE_ACTION;
289 function cancelEditAction() {
290 document.getElementById('mmta_id').value = '';
292 setSelectByValue( 'action', 'delete_field' );
293 $('#action').change();
295 document.getElementById('from_field').value = '';
296 document.getElementById('from_subfield').value = '';
297 document.getElementById('field_value').value = '';
298 document.getElementById('to_field').value = '';
299 document.getElementById('to_subfield').value = '';
300 $("#to_regex_search").val("");
301 $("#to_regex_replace").val("");
302 $("#to_regex_modifiers").val("");
303 $("#description").val("");
305 $('#to_field_regex').prop('checked', false).change();
307 setSelectByValue( 'conditional', '' );
308 $('#conditional').change();
310 document.getElementById('conditional_field').value = '';
311 document.getElementById('conditional_subfield').value = '';
313 setSelectByValue( 'conditional_comparison', '' );
314 $('#conditional_comparison').change();
316 document.getElementById('conditional_value').value = '';
318 document.getElementById('conditional_regex').checked = false;
320 document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml;
321 document.getElementById('action_submit').value = window.action_submit_value;
322 $("#add_action").hide();
325 function setSelectByValue( selectId, value ) {
326 s = document.getElementById( selectId );
328 for ( i = 0; i < s.options.length; i++ ) {
329 if ( s.options[i].value == value ) {