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 show('field_number_block');
116 hide('with_value_block');
117 show('to_field_block');
121 show('field_number_block');
122 hide('with_value_block');
123 show('to_field_block');
126 case 'copy_and_replace_field':
127 show('field_number_block');
128 hide('with_value_block');
129 show('to_field_block');
135 function onConditionalChange(selectObj) {
136 // get the index of the selected option
137 var idx = selectObj.selectedIndex;
139 // get the value of the selected option
140 var action = selectObj.options[idx].value;
144 hide('conditional_block');
149 show('conditional_block');
154 function onConditionalComparisonChange(selectObj) {
155 // get the index of the selected option
156 var idx = selectObj.selectedIndex;
158 // get the value of the selected option
159 var action = selectObj.options[idx].value;
164 show('conditional_comparison_block');
168 hide('conditional_comparison_block');
173 function onToFieldRegexChange( checkboxObj ) {
174 if ( checkboxObj.checked ) {
175 show('to_field_regex_value_block');
177 hide('to_field_regex_value_block');
181 function onConditionalRegexChange( checkboxObj ) {
182 if ( checkboxObj.checked ) {
183 $("span.match_regex_prefix" ).show();
184 $("span.match_regex_suffix" ).show();
186 $("span.match_regex_prefix" ).hide();
187 $("span.match_regex_suffix" ).hide();
191 function show(eltId) {
192 elt = document.getElementById( eltId );
193 elt.style.display='inline';
196 function hide(eltId) {
197 clearFormElements( eltId );
198 elt = document.getElementById( eltId );
199 elt.style.display='none';
202 function clearFormElements(divId) {
203 myBlock = document.getElementById( divId );
205 var inputElements = myBlock.getElementsByTagName( "input" );
206 for (var i = 0; i < inputElements.length; i++) {
207 switch( inputElements[i].type ) {
209 inputElements[i].value = '';
212 inputElements[i].checked = false;
217 var selectElements = myBlock.getElementsByTagName( "select" );
218 for (var i = 0; i < selectElements.length; i++) {
219 selectElements[i].selectedIndex = 0;
224 function confirmDeleteAction() {
225 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE_ACTION );
228 function confirmDelete() {
229 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE );
232 var modaction_legend_innerhtml;
233 var action_submit_value;
235 function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
236 to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
237 conditional_comparison, conditional_value, conditional_regex, description
239 $("#add_action").show();
240 document.getElementById('mmta_id').value = mmta_id;
242 setSelectByValue( 'action', action );
243 document.getElementById('action').onchange();
245 setSelectByValue( 'field_number', field_number );
247 document.getElementById('from_field').value = from_field;
248 document.getElementById('from_subfield').value = from_subfield;
249 document.getElementById('field_value').value = field_value;
250 document.getElementById('to_field').value = to_field;
251 document.getElementById('to_subfield').value = to_subfield;
252 if ( to_regex_search == '' && to_regex_replace == '' && to_regex_modifiers == '' ) {
253 document.getElementById('to_field_regex').checked = false;
254 document.getElementById('to_field_regex').onchange();
256 document.getElementById('to_field_regex').checked = true;
257 document.getElementById('to_field_regex').onchange();
258 $("#to_regex_search").val(to_regex_search);
259 $("#to_regex_replace").val(to_regex_replace);
260 $("#to_regex_modifiers").val(to_regex_modifiers);
263 setSelectByValue( 'conditional', conditional );
264 document.getElementById('conditional').onchange();
266 document.getElementById('conditional_field').value = conditional_field;
267 document.getElementById('conditional_subfield').value = conditional_subfield;
269 setSelectByValue( 'conditional_comparison', conditional_comparison );
270 document.getElementById('conditional_comparison').onchange();
272 document.getElementById('conditional_value').value = conditional_value;
274 document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
276 document.getElementById('description').value = description;
278 window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
279 document.getElementById('modaction_legend').innerHTML = MSG_MMT_EDIT_ACTION.format(ordering);
281 window.action_submit_value = document.getElementById('action_submit').value;
282 document.getElementById('action_submit').value = MSG_MMT_UPDATE_ACTION;
285 function cancelEditAction() {
286 document.getElementById('mmta_id').value = '';
288 setSelectByValue( 'action', 'delete_field' );
289 document.getElementById('action').onchange();
291 document.getElementById('from_field').value = '';
292 document.getElementById('from_subfield').value = '';
293 document.getElementById('field_value').value = '';
294 document.getElementById('to_field').value = '';
295 document.getElementById('to_subfield').value = '';
296 $("#to_regex_search").val("");
297 $("#to_regex_replace").val("");
298 $("#to_regex_modifiers").val("");
299 $("#description").val("");
301 document.getElementById('to_field_regex').checked = false;
302 document.getElementById('to_field_regex').onchange();
304 setSelectByValue( 'conditional', '' );
305 document.getElementById('conditional').onchange();
307 document.getElementById('conditional_field').value = '';
308 document.getElementById('conditional_subfield').value = '';
310 setSelectByValue( 'conditional_comparison', '' );
311 document.getElementById('conditional_comparison').onchange();
313 document.getElementById('conditional_value').value = '';
315 document.getElementById('conditional_regex').checked = false;
317 document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml;
318 document.getElementById('action_submit').value = window.action_submit_value;
319 $("#add_action").hide();
322 function setSelectByValue( selectId, value ) {
323 s = document.getElementById( selectId );
325 for ( i = 0; i < s.options.length; i++ ) {
326 if ( s.options[i].value == value ) {