1 $(document).ready(function() {
2 window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
3 window.action_submit_value = document.getElementById('action_submit').value;
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(){
52 $("#add_action").show();
56 $(".duplicate_template").on("click",function(){
57 var template_id = $(this).data("template_id");
58 $("#duplicate_a_template").val(template_id);
59 $("#duplicate_current_template").val(1);
62 $('#createTemplate').on('shown', function () {
63 $("#template_name").focus();
66 $("#duplicate_a_template").on("change",function(){
67 if( this.value == '' ){
68 $("#duplicate_current_template").val("");
70 $("#duplicate_current_template").val(1);
74 $(".delete_template").on("click",function(){
75 return confirmDelete();
80 function updateAllEvery(){
81 if ( $("#conditional_field").is(":visible") ) {
82 if ( $("#conditional_field").val() == $("#from_field").val() && $("#from_field").val().length > 0 ) {
83 $("#field_number option[value='0']").html( MSG_MMT_EVERY );
85 $("#field_number option[value='0']").html( MSG_MMT_ALL );
90 function onActionChange(selectObj) {
91 // get the index of the selected option
92 var idx = selectObj.selectedIndex;
94 // get the value of the selected option
95 var action = selectObj.options[idx].value;
99 show('field_number_block');
100 hide('with_value_block');
101 hide('to_field_block');
105 hide('field_number_block');
106 show('with_value_block');
107 hide('to_field_block');
111 show('field_number_block');
112 hide('with_value_block');
113 show('to_field_block');
117 show('field_number_block');
118 hide('with_value_block');
119 show('to_field_block');
122 case 'copy_and_replace_field':
123 show('field_number_block');
124 hide('with_value_block');
125 show('to_field_block');
131 function onConditionalChange(selectObj) {
132 // get the index of the selected option
133 var idx = selectObj.selectedIndex;
135 // get the value of the selected option
136 var action = selectObj.options[idx].value;
140 hide('conditional_block');
145 show('conditional_block');
150 function onConditionalComparisonChange(selectObj) {
151 // get the index of the selected option
152 var idx = selectObj.selectedIndex;
154 // get the value of the selected option
155 var action = selectObj.options[idx].value;
160 show('conditional_comparison_block');
164 hide('conditional_comparison_block');
169 function onToFieldRegexChange( checkboxObj ) {
170 if ( checkboxObj.checked ) {
171 show('to_field_regex_value_block');
173 hide('to_field_regex_value_block');
177 function onConditionalRegexChange( checkboxObj ) {
178 if ( checkboxObj.checked ) {
179 $("span.match_regex_prefix" ).show();
180 $("span.match_regex_suffix" ).show();
182 $("span.match_regex_prefix" ).hide();
183 $("span.match_regex_suffix" ).hide();
187 function show(eltId) {
188 elt = document.getElementById( eltId );
189 elt.style.display='inline';
192 function hide(eltId) {
193 clearFormElements( eltId );
194 elt = document.getElementById( eltId );
195 elt.style.display='none';
198 function clearFormElements(divId) {
199 myBlock = document.getElementById( divId );
201 var inputElements = myBlock.getElementsByTagName( "input" );
202 for (var i = 0; i < inputElements.length; i++) {
203 switch( inputElements[i].type ) {
205 inputElements[i].value = '';
208 inputElements[i].checked = false;
213 var selectElements = myBlock.getElementsByTagName( "select" );
214 for (var i = 0; i < selectElements.length; i++) {
215 selectElements[i].selectedIndex = 0;
220 function confirmDeleteAction() {
221 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE_ACTION );
224 function confirmDelete() {
225 return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE );
228 var modaction_legend_innerhtml;
229 var action_submit_value;
231 function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
232 to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
233 conditional_comparison, conditional_value, conditional_regex, description
235 $("#add_action").show();
236 document.getElementById('mmta_id').value = mmta_id;
238 setSelectByValue( 'action', action );
239 document.getElementById('action').onchange();
241 setSelectByValue( 'field_number', field_number );
243 document.getElementById('from_field').value = from_field;
244 document.getElementById('from_subfield').value = from_subfield;
245 document.getElementById('field_value').value = field_value;
246 document.getElementById('to_field').value = to_field;
247 document.getElementById('to_subfield').value = to_subfield;
248 $("#to_regex_search").val(to_regex_search);
249 $("#to_regex_replace").val(to_regex_replace);
250 $("#to_regex_modifiers").val(to_regex_modifiers);
252 document.getElementById('to_field_regex').checked = conditional_regex.length;
253 document.getElementById('to_field_regex').onchange();
255 setSelectByValue( 'conditional', conditional );
256 document.getElementById('conditional').onchange();
258 document.getElementById('conditional_field').value = conditional_field;
259 document.getElementById('conditional_subfield').value = conditional_subfield;
261 setSelectByValue( 'conditional_comparison', conditional_comparison );
262 document.getElementById('conditional_comparison').onchange();
264 document.getElementById('conditional_value').value = conditional_value;
266 document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
268 document.getElementById('description').value = description;
270 window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
271 document.getElementById('modaction_legend').innerHTML = MSG_MMT_EDIT_ACTION.format(ordering);
273 window.action_submit_value = document.getElementById('action_submit').value;
274 document.getElementById('action_submit').value = MSG_MMT_UPDATE_ACTION;
277 function cancelEditAction() {
278 document.getElementById('mmta_id').value = '';
280 setSelectByValue( 'action', 'delete_field' );
281 document.getElementById('action').onchange();
283 document.getElementById('from_field').value = '';
284 document.getElementById('from_subfield').value = '';
285 document.getElementById('field_value').value = '';
286 document.getElementById('to_field').value = '';
287 document.getElementById('to_subfield').value = '';
288 $("#to_regex_search").val("");
289 $("#to_regex_replace").val("");
290 $("#to_regex_modifiers").val("");
291 $("#description").val("");
293 document.getElementById('to_field_regex').checked = false;
294 document.getElementById('to_field_regex').onchange();
296 setSelectByValue( 'conditional', '' );
297 document.getElementById('conditional').onchange();
299 document.getElementById('conditional_field').value = '';
300 document.getElementById('conditional_subfield').value = '';
302 setSelectByValue( 'conditional_comparison', '' );
303 document.getElementById('conditional_comparison').onchange();
305 document.getElementById('conditional_value').value = '';
307 document.getElementById('conditional_regex').checked = false;
309 document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml;
310 document.getElementById('action_submit').value = window.action_submit_value;
311 $("#add_action").hide();
314 function setSelectByValue( selectId, value ) {
315 s = document.getElementById( selectId );
317 for ( i = 0; i < s.options.length; i++ ) {
318 if ( s.options[i].value == value ) {