2009-12-21

Upgrade of javascript function to hide "Add Existing ..." button

I improved the source code for one of my previous post — Remove 'Add Existing...' button from associated view entities form.

function HideAssociatedViewButtons(areaPrefix, loadAreaId, buttonTitles,addAreaParams){
 var navElement = document.getElementById(areaPrefix+loadAreaId); 
   if (navElement != null)    {
        navElement.onclick = function LoadAreaOverride(){
            if(addAreaParams.length>0)
    loadArea('area'+loadAreaId, addAreaParams[0]);
   else
    loadArea('area'+loadAreaId);
            var iframeid='area' + loadAreaId + 'Frame';
   HideViewButtons(document.getElementById(iframeid), buttonTitles);
        }
    }
}
 
function HideViewButtons(Iframe, buttonTitles) { 
    if (Iframe != null ) {
  Iframe.onreadystatechange = function HideTitledButtons() { 
            if (Iframe.readyState == 'complete') { 
                var iFrame = frames[window.event.srcElement.id]; 
                var liElements = iFrame.document.getElementsByTagName('li');
 
    for (var j = 0; j < buttonTitles.length; j++) { 
                    for (var i = 0; i < liElements.length; i++) { 
                        if (liElements[i].getAttribute('title') == buttonTitles[j]) { 
                            liElements[i].style.display = 'none'; 
                            break; 
                        }
                    } 
                } 
            } 
        } 
    }
} 

2009-12-03

On form load set some selected value for related entity pick-list

I had to set the value for related entity pick-list — filter of date for Activities of some account, like it was default Selected value.

SelectArea('Activities', 'scheduledend');
SelectArea('ActivityHistory', 'actualend');

function SelectArea(loadAreaId, selectId)
{
var navElement = document.getElementById('nav'+loadAreaId); 
if (navElement != null) 
{
 navElement.onclick = function LoadAreaOverride() {
  loadArea('area'+loadAreaId);
  var iframeid = 'area'+loadAreaId + 'Frame';
  var Iframe=document.getElementById(iframeid);
  if (Iframe != null ) {
   Iframe.onreadystatechange = function SetAllasDefault() { 
    if (Iframe.readyState == 'complete') { 
     var iFrame = frames[window.event.srcElement.id]; 
     var oSelect = iFrame.document.getElementById(selectId);
     var oOption = oSelect.options[oSelect.options.length-1];
     oOption.selected = true;
     oSelect.FireOnChange();
    }
   }
  }
 
  
 }
}
}
Put at form OnLoad() event;