/********************************************************************************* ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 * ("License"); You may not use this file except in compliance with the License * The Original Code is: vtiger CRM Open Source * The Initial Developer of the Original Code is vtiger. * Portions created by vtiger are Copyright (C) vtiger. * All Rights Reserved. ********************************************************************************/ /** * 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(){ $("status").style.display="inline"; var oModulePick = $('pickmodule') var module=oModulePick.options[oModulePick.selectedIndex].value; var oRolePick = $('pickid'); var role=oRolePick.options[oRolePick.selectedIndex].value; new Ajax.Request( 'index.php', { queue: { position: 'end', scope: 'command' }, method: 'post', postBody: 'action=PickListAjax&module=PickList&directmode=ajax&file=PickList&moduleName='+encodeURIComponent(module)+'&roleid='+role, onComplete: function(response) { $("status").style.display="none"; $("picklist_datas").innerHTML=response.responseText; } } ); 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 elem = $('pickid'); var role=elem.options[elem.selectedIndex].value; $("status").style.display="inline"; new Ajax.Request( 'index.php', { queue: { position: 'end', scope: 'command' }, method: 'post', postBody: 'action=PickListAjax&module=PickList&file=AssignValues&moduleName='+encodeURIComponent(module)+'&fieldname='+encodeURIComponent(fieldname)+'&fieldlabel='+encodeURIComponent(fieldlabel)+'&roleid='+role, onComplete: function(response) { $("status").style.display="none"; $("actiondiv").style.display="block"; $("actiondiv").innerHTML=response.responseText; placeAtCenter($('actiondiv')); } } ); } /** * 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; document.getElementById('replaceVal').value = value; $('replaceVal').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; $('replaceVal').value = 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 moduleElem = $('pickmodule'); var module = moduleElem.options[moduleElem.selectedIndex].value; var oModPick = $('allpick'); var fieldName=oModPick.options[oModPick.selectedIndex].value; var fieldLabel=oModPick.options[oModPick.selectedIndex].text; $("status").style.display="inline"; new Ajax.Request( 'index.php', { queue: { position: 'end', scope: 'command' }, method: 'post', postBody: 'action=PickListAjax&module=PickList&mode=delete&file=ShowActionDivs&moduleName='+encodeURIComponent(module)+'&fieldname='+encodeURIComponent(fieldName)+'&fieldlabel='+encodeURIComponent(fieldLabel), onComplete: function(response) { $("status").style.display="none"; $("actiondiv").style.display ='block'; $("actiondiv").innerHTML=response.responseText; placeAtCenter($('actiondiv')); } } ); } /** * this function is used to show the add div for a picklist */ function showAddDiv(){ var moduleElem = $('pickmodule'); var module = moduleElem.options[moduleElem.selectedIndex].value; var oModPick = $('allpick'); var fieldName=oModPick.options[oModPick.selectedIndex].value; var fieldLabel=oModPick.options[oModPick.selectedIndex].text; $("status").style.display="inline"; new Ajax.Request( 'index.php', { queue: { position: 'end', scope: 'command' }, method: 'post', postBody: 'action=PickListAjax&module=PickList&mode=add&file=ShowActionDivs&moduleName='+encodeURIComponent(module)+'&fieldname='+encodeURIComponent(fieldName)+'&fieldlabel='+encodeURIComponent(fieldLabel), onComplete: function(response) { $("status").style.display="none"; $("actiondiv").style.display ='block'; $("actiondiv").innerHTML=response.responseText; placeAtCenter($('actiondiv')); } } ); } /** * this function is used to show the edit div for a picklist */ function showEditDiv(){ var moduleElem = $('pickmodule'); var module = moduleElem.options[moduleElem.selectedIndex].value; var oModPick = $('allpick'); var fieldName=oModPick.options[oModPick.selectedIndex].value; var fieldLabel=oModPick.options[oModPick.selectedIndex].text; $("status").style.display="inline"; new Ajax.Request( 'index.php', { queue: { position: 'end', scope: 'command' }, method: 'post', postBody: 'action=PickListAjax&module=PickList&mode=edit&file=ShowActionDivs&moduleName='+encodeURIComponent(module)+'&fieldname='+encodeURIComponent(fieldName)+'&fieldlabel='+encodeURIComponent(fieldLabel), onComplete: function(response) { $("status").style.display="none"; $("actiondiv").style.display ='block'; $("actiondiv").innerHTML=response.responseText; placeAtCenter($('actiondiv')); } } ); } /** * 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|\\|\/)/gi)!=-1) { alert(alert_arr.SPECIAL_CHARACTERS+'"<" ">" "\\" "/"'+alert_arr.NOT_ALLOWED); return false } } var node = document.getElementsByClassName('picklist_noneditable_options'); var nonEdit = new Array(); for(var i=0;i -1){ for (var i=0,j=0;i|\\|\/)/gi)!=-1) { alert(alert_arr.SPECIAL_CHARACTERS+'"<" ">" "\\" "/"'+alert_arr.NOT_ALLOWED); return false } oldVal[i] = node[i].value; } pickReplace(module, fieldname, JSON.stringify(newVal), JSON.stringify(oldVal)); } /** * this function is used to modify the picklist values * @param string module - the module name * @param string fieldname - the field name * @param array newVal - the new values for the picklist in json encoded string format * @param array oldVal - the old values for the picklist in json encoded string format */ function pickReplace(module, fieldname, newVal, oldVal){ $("status").style.display="inline"; new Ajax.Request( 'index.php', { queue: { position: 'end', scope: 'command' }, method: 'post', postBody: 'action=PickListAjax&module=PickList&mode=edit&file=PickListAction&fld_module='+encodeURIComponent(module)+'&fieldname='+encodeURIComponent(fieldname)+'&newValues='+encodeURIComponent(newVal)+'&oldValues='+encodeURIComponent(oldVal), onComplete: function(response) { var str = response.responseText; if(str == "SUCCESS"){ changeModule(); fnhide('actiondiv'); }else{ alert(str); } $("status").style.display="none"; } } ); } /** * this function validates the delete action * @param string fieldname - the name of the picklist field * @param string module - the name of the module */ function validateDelete(fieldname, module){ var node = $('replace_picklistval'); var replaceVal = node.options[node.selectedIndex].value; if(trim(replaceVal) == ''){ alert(alert_arr.LBL_BLANK_REPLACEMENT); return false; } if(!confirm(alert_arr.LBL_WANT_TO_DELETE)){ return false; } node = document.getElementById('delete_availPickList'); var arr = new Array(); 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]; }