/************************************* * SPDX-FileCopyrightText: 2009-2020 Vtenext S.r.l. * SPDX-License-Identifier: AGPL-3.0-only ************************************/ /* crmv@114293 crmv@192033 */ /** * this function is used to get the picklist values using ajax * it does not accept any parameters but calculates the modulename and roleid from the document */ function changeModule(){ var module = jQuery('#pickmodule').val(); var role = jQuery('#pickid').val(); jQuery('#status').show(); jQuery.ajax({ url: 'index.php', method: 'POST', data: 'action=PickListAjax&module=PickList&directmode=ajax&file=PickList&moduleName='+encodeURIComponent(module)+'&roleid='+role, success: function(result) { jQuery('#status').hide(); jQuery("#picklist_datas").html(result); } }); fnhide('actiondiv'); } /** * this function is used to assign picklist values to role * @param string module - the module name * @param string fieldname - the name of the field * @param string fieldlabel - the label for the field */ function assignPicklistValues(module,fieldname,fieldlabel){ var role = jQuery('#pickid').val(); jQuery('#status').show(); jQuery.ajax({ url: 'index.php', method: 'POST', data: 'action=PickListAjax&module=PickList&file=AssignValues&moduleName='+encodeURIComponent(module)+'&fieldname='+encodeURIComponent(fieldname)+'&fieldlabel='+encodeURIComponent(fieldlabel)+'&roleid='+role, success: function(result) { jQuery('#status').hide(); jQuery("#actiondiv").html(result).show(); placeAtCenter(jQuery("#actiondiv").get(0)); } }); } /** * this function is used to select the value from select box of picklist to the edit box */ function selectForEdit(){ var node = document.getElementById('edit_availPickList'); if(node.selectedIndex >=0){ var value = node.options[node.selectedIndex].text; jQuery('#replaceVal').val(value).focus(); } } /** * this function checks if the edited value already exists; * if not it pushes the edited value back to the picklist */ function pushEditedValue(e){ var node = document.getElementById('edit_availPickList'); if(typeof e.keyCode != 'undefined'){ var keyCode = e.keyCode; //check if escape key is being pressed:: if yes then substitue the original value if(keyCode == 27){ node.options[node.selectedIndex].text = node.options[node.selectedIndex].value; jQuery('#replaceVal').val(node.options[node.selectedIndex].value); return; } } var newVal = trim(document.getElementById('replaceVal').value); for(var i=0;i=0){ node.options[node.selectedIndex].text = newVal; } } /** * this function is used to show the delete div for a picklist */ function showDeleteDiv(){ var module = jQuery('#pickmodule').val(); var oModPick = document.getElementById('allpick'); var fieldName=oModPick.options[oModPick.selectedIndex].value; var fieldLabel=oModPick.options[oModPick.selectedIndex].text; jQuery('#status').show(); jQuery.ajax({ url: 'index.php', method: 'POST', data: 'action=PickListAjax&module=PickList&mode=delete&file=ShowActionDivs&moduleName='+encodeURIComponent(module)+'&fieldname='+encodeURIComponent(fieldName)+'&fieldlabel='+encodeURIComponent(fieldLabel), success: function(result) { jQuery('#status').hide(); jQuery("#actiondiv").html(result).show(); placeAtCenter(jQuery("#actiondiv").get(0)); } }); } /** * this function is used to show the add div for a picklist */ function showAddDiv(){ var module = jQuery('#pickmodule').val(); var oModPick = document.getElementById('allpick'); var fieldName=oModPick.options[oModPick.selectedIndex].value; var fieldLabel=oModPick.options[oModPick.selectedIndex].text; jQuery('#status').show(); jQuery.ajax({ url: 'index.php', method: 'POST', data: 'action=PickListAjax&module=PickList&mode=add&file=ShowActionDivs&moduleName='+encodeURIComponent(module)+'&fieldname='+encodeURIComponent(fieldName)+'&fieldlabel='+encodeURIComponent(fieldLabel), success: function(result) { jQuery('#status').hide(); jQuery("#actiondiv").html(result).show(); placeAtCenter(jQuery("#actiondiv").get(0)); } }); } /** * this function is used to show the edit div for a picklist */ function showEditDiv(){ var module = jQuery('#pickmodule').val(); var oModPick = document.getElementById('allpick'); var fieldName=oModPick.options[oModPick.selectedIndex].value; var fieldLabel=oModPick.options[oModPick.selectedIndex].text; jQuery('#status').show(); jQuery.ajax({ url: 'index.php', method: 'POST', data: 'action=PickListAjax&module=PickList&mode=edit&file=ShowActionDivs&moduleName='+encodeURIComponent(module)+'&fieldname='+encodeURIComponent(fieldName)+'&fieldlabel='+encodeURIComponent(fieldLabel), success: function(result) { jQuery('#status').hide(); jQuery("#actiondiv").html(result).show(); placeAtCenter(jQuery("#actiondiv").get(0)); } }); } /** * this function validates the add action * @param string fieldname - the name of the picklist field * @param string module - the name of the module */ function validateAdd(fieldname, module){ var pickArr=new Array(); var pick_options = document.getElementsByClassName('picklist_existing_options'); for(var i=0;i -1) { var tmp_new_vals = []; var empty = false; jQuery.each(new_vals, function(k,v){ if (v != '' || !empty) { tmp_new_vals.push(v); if (v == '') empty = true; } }); new_vals = tmp_new_vals; } // crmv@198652 var bad_characters = [',','&','|','#']; var err = false; jQuery.each(new_vals, function(k,v){ jQuery.each(bad_characters, function(b,c){ if (v.indexOf(c) > -1) { err = true; } }); }); if (err) { alert(alert_arr.LBL_BAD_CHARACTER_PICKLIST_VALUE+' '+bad_characters.join(' ')); return false; } // crmv@198652e var node = document.getElementsByClassName('picklist_noneditable_options'); var nonEdit = new Array(); for(var i=0;i -1) { var tmp_arr = []; var empty = false; jQuery.each(arr, function(k,v){ if (v != '' || !empty) { tmp_arr.push(v); if (v == '') empty = true; } }); arr = tmp_arr; } var trimmedArr = new Array(); for(var i=0,j=0;i -1){ for (var i=0,j=0;i 0){ nonEditableLength = nonEditable.get(0).options.length; } // crmv@98693e if(arr.length == (node.length+nonEditableLength)){ alert(alert_arr.LBL_DELETE_ALL_WARNING); return false; } pickDelete(module,fieldname, arr, replaceVal); } }); } /** * this function deletes the given picklist values * @param string module - the module name * @param string fieldname - the field name of the picklist * @param array arr - the picklist values to delete * @param array replaceVal - the replacement value for the deleted value(s) */ function pickDelete(module, fieldname, arr, replaceVal){ jQuery('#status').show(); jQuery.ajax({ url: 'index.php', method: 'POST', data: 'action=PickListAjax&module=PickList&mode=delete&file=PickListAction&fld_module='+encodeURIComponent(module)+'&fieldname='+encodeURIComponent(fieldname)+'&values='+JSON.stringify(arr)+'&replaceVal='+encodeURIComponent(replaceVal), success: function(result) { if(result == "SUCCESS"){ changeModule(); fnhide('actiondiv'); }else{ alert(result); } jQuery('#status').hide(); } }); } /** * this function is used to assign the available picklist values to the assigend picklist values section */ function moveRight(){ var rightElem = document.getElementById('selectedColumns'); for (var i=0;i=0){ for (var i=0;i=0){ for (var i=1;i=0){ for (var i=elem.options.length-2;i>=0;i--){ if(elem.options[i].selected == true){ //swap with one down var first = elem.options[i+1]; var second = elem.options[i]; var temp = new Array(); temp.value = first.value; temp.innerHTML = first.innerHTML; first.value = second.value; first.innerHTML = second.innerHTML; second.value = temp.value; second.innerHTML = temp.innerHTML; first.selected = true; second.selected = false; } } } } /** * this function is used to save the assigned picklist values for a given role * @param string moduleName - the name of the module * @param string fieldName - the name of the field * @param string roleid - the id of the given role */ function saveAssignedValues(moduleName, fieldName, roleid){ var node = document.getElementById('selectedColumns'); if(node.length == 0){ alert(alert_arr.LBL_DELETE_ALL_WARNING); return false; } var arr = new Array(); for(var i=0;i -1){ for(var i=0,j=0; i= elem.childNodes.length){ return null; } return elem.childNodes[i]; }