// the following code is for the hover over lookup window function OnCrmPageLoad() { /* Reference the to Lookup, Provide the lookup (control) id. */ var PrvToLui = new LookupPreview("new_primarycontactid"); /* Add Account Preview Information , returns an account entity wrapper object */ var accountEntity = PrvToLui.AddEntity("account"); /* Add Account Preview Attributes, Provide lable and schema name for each attribute */ accountEntity.AddAttribute("Business Phone","address1_line1"); accountEntity.AddAttribute("Mobile Phone","address1_city"); accountEntity.AddAttribute("Fax","address1_stateorprovince"); accountEntity.AddAttribute("E-mail","address1_postalcode"); /* Add Related Entity (Primary Contact) Information AddLinked requires the entity name and lookup field schema name on the account. */ var contactEntity = accountEntity.AddLinked("contact","primarycontactid"); contactEntity.AddAttribute("Primary Contact","fullname"); contactEntity.AddAttribute("Contact Phone","telephone1"); /* ------------------------------------------------------------------ */ //Contact Entity Preview var contactEntity = PrvToLui.AddEntity("contact"); contactEntity.AddAttribute("Business Phone","telephone1"); contactEntity.AddAttribute("Mobile Phone","mobilephone"); contactEntity.AddAttribute("Fax","fax"); contactEntity.AddAttribute("E-mail","emailaddress1"); var accountEntity = contactEntity.AddLinked("account","parentcustomerid"); accountEntity.AddAttribute("Parent Company", "name"); accountEntity.AddAttribute("Parent Street","address1_line1"); accountEntity.AddAttribute("Parent Suburb","address1_line2"); accountEntity.AddAttribute("Parent State","address1_stateorprovince"); accountEntity.AddAttribute("Parent Postcode","address1_postalcode"); accountEntity.AddAttribute("Parent Website","websiteurl"); /* ------------------------------------------------------------------ */ } function LookupPreview( lookupId ) { var Instance = this; Instance.Lookup = document.getElementById( lookupId ); if( isNullOrEmpty(Instance.Lookup) ) return; //Public Instance.Entities = []; Instance.AddEntity = function(entityName){ var Entity = new Object(); Entity.Name = entityName; Entity.AddAttribute = function( labelName , attrName ){ var Attributes = Instance.Entities[entityName].Attributes; var attribute = new Attribute(entityName , attrName , labelName , attrName); Attributes[Attributes.length] = attribute; DisplayAttributes[DisplayAttributes.length] = attribute; } Entity.Attributes = []; Entity.LinkedByName = []; Entity.LinkedByIndex = []; Entity.AddLinked = function( lnkEntityName , referencingAttribute ) { var LinkEntity = new Object(); LinkEntity.Name = lnkEntityName; LinkEntity.Attributes = []; LinkEntity.RefAttribute = referencingAttribute; LinkEntity.AddAttribute = function( labelName , attrName ) { var attribute = new Attribute(entityName , attrName , labelName , LinkEntity.RefAttribute + "." + attrName); LinkEntity.Attributes[LinkEntity.Attributes.length] = attribute; DisplayAttributes[DisplayAttributes.length] = attribute; } Entity.LinkedByIndex[Entity.LinkedByIndex.length] = Entity.LinkedByName[name] = LinkEntity; return LinkEntity; } Instance.Entities[entityName] = Entity; return Entity; } Instance.Show = function(dataElement) { var control = Instance.Lookup; var DataValue = control.DataValue; if( isNullOrEmpty(DataValue) ) return; if( isNullOrEmpty(Instance.Entities[DataValue[dataElement.Index].typename]) ) return; TooltipPopup = window.createPopup(); if( !dataElement.PreviewHTML ) { var ToolTipHTML = "
"; dataElement.PreviewHTML = ToolTipHTML; } TooltipPopup.document.body.innerHTML = dataElement.PreviewHTML; var Position = getControlPostion(); var Left = Position.X + 1; var Top = Position.Y + 5; TooltipPopup.show( Left , Top - dataElement.parentElement.scrollTop , dataElement.Width, dataElement.Height , null ); } Instance.Hide = function() { if( TooltipPopup ) TooltipPopup.hide(); } Instance.OnLookupChange = function() { var jump = 0; if( Instance.Lookup.DataValue != null ) { var DataElementsLen = Instance.Lookup.parentElement.previousSibling.childNodes[0].childNodes.length; var DataValuesLen = Instance.Lookup.DataValue.length; jump = (DataElementsLen == DataValuesLen)? 1:2; for( var i = 0 ; i < DataValuesLen*jump ; i+=jump ) { var DataValueElemet = Instance.Lookup.parentElement.previousSibling.childNodes[0].childNodes[i]; if( !isNullOrEmpty(DataValueElemet.onmouseover) ) continue; DataValueElemet.Preview = Instance; DataValueElemet.Index = i/jump; DataValueElemet.onmouseover = function(){ this.Preview.Show(this); } DataValueElemet.onmouseout = function(){ this.Preview.Hide(); } } } } //Private var TooltipPopup; var DisplayAttributes; function Init() { DisplayAttributes = []; Instance.Lookup.attachEvent( "onchange" , Instance.OnLookupChange ); Instance.OnLookupChange(); //First Time } function Attribute(entityName,attrName,attrLabel,attrXpathName) { this.Name = attrName; this.Entity = entityName; this.Label = attrLabel; this.XPathName = attrXpathName; } function getControlPostion() { control = event.srcElement; var Position = new Object(); var controlHeight = control.offsetHeight; var iY = 0, iX = 0; while( control != null ) { iY += control.offsetTop; iX += control.offsetLeft; control = control.offsetParent; } Position.X = iX + screenLeft; Position.Y = iY + screenTop + controlHeight; return Position; } function isNullOrEmpty( obj ){ return obj == null || typeof(obj) == "undefined" || obj == ""; } Init(); } OnCrmPageLoad();