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 document.getElementById('action').onchange();
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 document.getElementById('to_field_regex').checked = false;
260 document.getElementById('to_field_regex').onchange();
262 document.getElementById('to_field_regex').checked = true;
263 document.getElementById('to_field_regex').onchange();
264 $("#to_regex_search").val(to_regex_search);
265 $("#to_regex_replace").val(to_regex_replace);
266 $("#to_regex_modifiers").val(to_regex_modifiers);
269 setSelectByValue( 'conditional', conditional );
270 document.getElementById('conditional').onchange();
272 document.getElementById('conditional_field').value = conditional_field;
273 document.getElementById('conditional_subfield').value = conditional_subfield;
275 setSelectByValue( 'conditional_comparison', conditional_comparison );
276 document.getElementById('conditional_comparison').onchange();
278 document.getElementById('conditional_value').value = conditional_value;
280 document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
282 document.getElementById('description').value = description;
284 window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
285 document.getElementById('modaction_legend').innerHTML = MSG_MMT_EDIT_ACTION.format(ordering);
287 window.action_submit_value = document.getElementById('action_submit').value;
288 document.getElementById('action_submit').value = MSG_MMT_UPDATE_ACTION;
291 function cancelEditAction() {
292 document.getElementById('mmta_id').value = '';
294 setSelectByValue( 'action', 'delete_field' );
295 document.getElementById('action').onchange();
297 document.getElementById('from_field').value = '';
298 document.getElementById('from_subfield').value = '';
299 document.getElementById('field_value').value = '';
300 document.getElementById('to_field').value = '';
301 document.getElementById('to_subfield').value = '';
302 $("#to_regex_search").val("");
303 $("#to_regex_replace").val("");
304 $("#to_regex_modifiers").val("");
305 $("#description").val("");
307 document.getElementById('to_field_regex').checked = false;
308 document.getElementById('to_field_regex').onchange();
310 setSelectByValue( 'conditional', '' );
311 document.getElementById('conditional').onchange();
313 document.getElementById('conditional_field').value = '';
314 document.getElementById('conditional_subfield').value = '';
316 setSelectByValue( 'conditional_comparison', '' );
317 document.getElementById('conditional_comparison').onchange();
319 document.getElementById('conditional_value').value = '';
321 document.getElementById('conditional_regex').checked = false;
323 document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml;
324 document.getElementById('action_submit').value = window.action_submit_value;
325 $("#add_action").hide();
328 function setSelectByValue( selectId, value ) {
329 s = document.getElementById( selectId );
331 for ( i = 0; i < s.options.length; i++ ) {
332 if ( s.options[i].value == value ) {