• custom preview link


    1. function OnCrmPageLoad()  
    2. {     
    3.  /*  
    4.   Reference the to Lookup, Provide the lookup (control) id. 
    5.  */  
    6.   var PrvToLui = new LookupPreview("to");  
    7.  /*  
    8.   Add Account Preview Information ,  
    9.   returns an account entity wrapper object 
    10.  */  
    11.  var accountEntity = PrvToLui.AddEntity("account");  
    12.    
    13.  /*  
    14.   Add Account Preview Attributes,  
    15.   Provide lable and schema name for each attribute  
    16.  */  
    17.   accountEntity.AddAttribute("Street","address1_line1");  
    18.   accountEntity.AddAttribute("City","address1_city");  
    19.   accountEntity.AddAttribute("State","address1_stateorprovince");  
    20.   accountEntity.AddAttribute("Zip","address1_postalcode");  
    21.  /*  
    22.   Add Related Entity (Primary Contact) Information  
    23.   AddLinked requires the entity name and  
    24.   lookup field schema name on the account. 
    25.  */  
    26.  var contactEntity = accountEntity.AddLinked("contact","primarycontactid");  
    27.   contactEntity.AddAttribute("Primary Contact","fullname");  
    28.   contactEntity.AddAttribute("Contact Phone","telephone1");  
    29.    
    30.  /* ------------------------------------------------------------------ */  
    31.    
    32.  //Contact Entity Preview  
    33.  var contactEntity = PrvToLui.AddEntity("contact");  
    34.   contactEntity.AddAttribute("Street","address1_line1");  
    35.   contactEntity.AddAttribute("City","address1_city");  
    36.   contactEntity.AddAttribute("State","address1_stateorprovince");  
    37.   contactEntity.AddAttribute("Zip","address1_postalcode");  
    38.  /* ------------------------------------------------------------------ */  
    39.    
    40.  //Lead Entity Preview  
    41.  var leadEntity = PrvToLui.AddEntity("lead");  
    42.   leadEntity.AddAttribute("Full Name","fullname");  
    43.  /* ------------------------------------------------------------------ */  
    44.    
    45.  //Systemuser Entity Preview  
    46.  var userEntity = PrvToLui.AddEntity("systemuser");  
    47.   userEntity.AddAttribute("Preferred Phone","preferredphonecode");  
    48.   userEntity.AddAttribute("Main Phone","address1_telephone1");  
    49.    
    50.  var buEntity = userEntity.AddLinked("businessunit","businessunitid");  
    51.   buEntity.AddAttribute("Business Unit","name");  
    52.    
    53. }  
    54.   
    55. function LookupPreview( lookupId )  
    56. {  
    57.    var Instance = this;  
    58.   Instance.Lookup = document.getElementById( lookupId );  
    59.      
    60.    if(  isNullOrEmpty(Instance.Lookup) )   
    61.   return;  
    62.      
    63.    //Public   
    64.    Instance.Entities = [];  
    65.     
    66.    Instance.AddEntity = function(entityName){   
    67.   var Entity = new Object();  
    68.    Entity.Name = entityName;  
    69.    Entity.AddAttribute = function( labelName , attrName ){  
    70.     var Attributes = Instance.Entities[entityName].Attributes;  
    71.     var attribute  = new Attribute(entityName , attrName , labelName , attrName);  
    72.      Attributes[Attributes.length] = attribute;   
    73.      DisplayAttributes[DisplayAttributes.length] = attribute;  
    74.       }  
    75.    Entity.Attributes  = [];  
    76.    Entity.LinkedByName  = [];  
    77.    Entity.LinkedByIndex = [];  
    78.    Entity.AddLinked = function( lnkEntityName , referencingAttribute )  
    79.    {  
    80.     var LinkEntity = new Object();  
    81.      LinkEntity.Name = lnkEntityName;  
    82.      LinkEntity.Attributes = [];  
    83.      LinkEntity.RefAttribute = referencingAttribute;  
    84.      LinkEntity.AddAttribute = function( labelName , attrName )  
    85.      {  
    86.       var attribute = new Attribute(entityName , attrName , labelName , LinkEntity.RefAttribute + "." + attrName);  
    87.        LinkEntity.Attributes[LinkEntity.Attributes.length] = attribute;  
    88.        DisplayAttributes[DisplayAttributes.length] = attribute;  
    89.      }  
    90.      Entity.LinkedByIndex[Entity.LinkedByIndex.length] = Entity.LinkedByName[name] = LinkEntity;              
    91.     return LinkEntity;  
    92.    }  
    93.    Instance.Entities[entityName] = Entity;  
    94.   return Entity;  
    95.    }  
    96.      
    97.    Instance.Show = function(dataElement)  
    98.    {  
    99.   var control   = Instance.Lookup;              
    100.   var DataValue = control.DataValue;  
    101.     
    102.   if( isNullOrEmpty(DataValue) )   
    103.    return;  
    104.   if( isNullOrEmpty(Instance.Entities[DataValue[dataElement.Index].typename]) )  
    105.    return;  
    106.     
    107.   TooltipPopup = window.createPopup();              
    108.     
    109.   if( !dataElement.PreviewHTML )  
    110.   {  
    111.    var ToolTipHTML = "<fieldset style='100%;height:100%;border:1px solid gray;background-color: #d8e8ff;filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#eff3ff,EndColorStr=#c6dfff);padding-left:2px;'><legend style='background-color:#eff3ff;100;padding-left:13px;border:1px solid gray;font-size:12px;font-family:tahoma'><b>Preview</b></legend>";  
    112.    var xmlHttp = CreateXmlHttp();  
    113.    var xml = "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""";  
    114.     xml += " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""";  
    115.     xml += " xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">";  
    116.     xml += GenerateAuthenticationHeader();  
    117.     xml += "<soap:Body>";  
    118.     xml += "<Fetch xmlns=""http://schemas.microsoft.com/crm/2007/WebServices"">";  
    119.     xml += "<fetchXml>";  
    120.   
    121.    var fetchxml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";  
    122.    var DataVal  = control.DataValue[dataElement.Index];   
    123.    var entity   = DataVal.typename;   
    124.     fetchxml += "<entity name='" + entity + "'>";  
    125.    var attributes = Instance.Entities[entity].Attributes;  
    126.     for( var i = 0 ; i < attributes.length ; i++ )  
    127.       fetchxml += "<attribute name='" + attributes[i].Name + "'/>";  
    128.     fetchxml += "<filter type='and'>";  
    129.     fetchxml += "<condition attribute='" + entity + "id' operator='eq' value='" + DataVal.id + "'/>";  
    130.     fetchxml += "</filter>";  
    131.       
    132.     for( var i = 0 ; i < Instance.Entities[entity].LinkedByIndex.length ; i++ )  
    133.     {  
    134.      var linked = Instance.Entities[entity].LinkedByIndex[i];  
    135.      fetchxml += "<link-entity name='" + linked.Name + "' from='" + linked.Name + "id' to='" + linked.RefAttribute+ "' visible='false' link-type='outer'>";  
    136.      for( var j = 0 ; j < linked.Attributes.length ; j++ )  
    137.       fetchxml += "<attribute name='" + linked.Attributes[j].Name + "'/>";   
    138.      fetchxml += "</link-entity>";  
    139.     }     
    140.     fetchxml += "</entity>";  
    141.     fetchxml += "</fetch>";  
    142.       
    143.     xml += _HtmlEncode(fetchxml);  
    144.     xml += "</fetchXml>";  
    145.     xml += "</Fetch>";  
    146.     xml += "</soap:Body>";  
    147.     xml += "</soap:Envelope>";  
    148.   
    149.     xmlHttp.open("POST", "/mscrmservices/2007/crmservice.asmx", false );  
    150.     xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");  
    151.     xmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch");  
    152.     xmlHttp.send(xml);  
    153.       
    154.    var resultDoc   = loadXmlDocument(xmlHttp.responseXML.text);  
    155.    var previewHtml = "<br style='line-height:2px'/><table width='100%' style='font:12 px tahoma'>";   
    156.     dataElement.Width = 0;   
    157.     //debugger  
    158.     for( var i = 0 , j = 1; i < DisplayAttributes.length ; i++ )  
    159.     {   
    160.      var attribute = DisplayAttributes[i];  
    161.      if( attribute.Entity != entity ) continue;  
    162.        
    163.      var attrNode  = resultDoc.selectSingleNode("//" + attribute.XPathName );  
    164.      var attrValue = (attrNode)? attrNode.text:"";  
    165.        
    166.       dataElement.Height = (j++) * 22;  
    167.       var maxLength  = ( attrValue.length + attribute.Label.length ) * 9;  
    168.       if( dataElement.Width < maxLength )  
    169.        dataElement.Width = maxLength;  
    170.       previewHtml += "<tr><td style='padding:3px 0px 0px 0px;color:brown'><nobr>" + attribute.Label + "</nobr></td><td><nobr>" + attrValue  + "</nobr></td></tr>";  
    171.        
    172.     }  
    173.       
    174.     dataElement.Height += 20;  
    175.      
    176.     ToolTipHTML += previewHtml;  
    177.     ToolTipHTML += "</table></fieldset>";   
    178.     dataElement.PreviewHTML = ToolTipHTML;             
    179.    }  
    180.      
    181.    TooltipPopup.document.body.innerHTML = dataElement.PreviewHTML;        
    182.     
    183.   var Position = getControlPostion();  
    184.   var Left   = Position.X + 1;  
    185.   var Top    = Position.Y + 5;  
    186.   
    187.    TooltipPopup.show( Left , Top - dataElement.parentElement.scrollTop , dataElement.Width, dataElement.Height , null );  
    188.    }  
    189.      
    190.    Instance.Hide = function()  
    191.    {  
    192.   if( TooltipPopup )            
    193.    TooltipPopup.hide();  
    194.    }  
    195.      
    196.    Instance.OnLookupChange = function()  
    197.    {  
    198.   var jump = 0;  
    199.   if( Instance.Lookup.DataValue != null )  
    200.      {  
    201.    var DataElementsLen = Instance.Lookup.parentElement.previousSibling.childNodes[0].childNodes.length;  
    202.    var DataValuesLen   = Instance.Lookup.DataValue.length;  
    203.     jump = (DataElementsLen == DataValuesLen)? 1:2;  
    204.       
    205.      for( var i = 0 ; i < DataValuesLen*jump ; i+=jump )  
    206.      {    
    207.     var DataValueElemet = Instance.Lookup.parentElement.previousSibling.childNodes[0].childNodes[i];  
    208.     if( !isNullOrEmpty(DataValueElemet.onmouseover) ) continue;  
    209.       
    210.     DataValueElemet.Preview = Instance;  
    211.     DataValueElemet.Index = i/jump;  
    212.     DataValueElemet.onmouseover = function(){  
    213.      this.Preview.Show(this);  
    214.     }  
    215.     DataValueElemet.onmouseout = function(){  
    216.      this.Preview.Hide();  
    217.     }  
    218.      }  
    219.      }  
    220.    }  
    221.      
    222.    //Private   
    223.    var TooltipPopup;  
    224.    var DisplayAttributes;  
    225.      
    226.    function Init()  
    227.    {  
    228.   DisplayAttributes = [];  
    229.   Instance.Lookup.attachEvent( "onchange" , Instance.OnLookupChange );  
    230.   Instance.OnLookupChange();  //First Time  
    231.    }  
    232.      
    233.    function Attribute(entityName,attrName,attrLabel,attrXpathName)  
    234.    {  
    235.   this.Name = attrName;  
    236.   this.Entity = entityName;  
    237.   this.Label = attrLabel;  
    238.   this.XPathName = attrXpathName;  
    239.    }  
    240.      
    241.    function getControlPostion()  
    242.    {        
    243.   control = event.srcElement;  
    244.   var Position = new Object();        
    245.   var controlHeight = control.offsetHeight;        
    246.   var iY = 0, iX = 0;        
    247.   while( control != null )        
    248.   {              
    249.    iY += control.offsetTop;              
    250.    iX += control.offsetLeft;              
    251.    control = control.offsetParent;        
    252.   }        
    253.   Position.X = iX + screenLeft;        
    254.   Position.Y = iY + screenTop + controlHeight;        
    255.   return Position;  
    256.     }  
    257.   
    258.  function isNullOrEmpty( obj ){  
    259.   return obj == null || typeof(obj) == "undefined" || obj == "";  
    260.  }  
    261.      
    262.    Init();  
    263. }  
    264.   
    265. OnCrmPageLoad();
  • 相关阅读:
    将font-size设置为 12px 以下,Chrome浏览器只能显示12px怎么办?
    如何创建.gitignore文件,忽略不必要提交的文件
    linux中将网速设置成10baseT/Half用于测试
    点击checkbox后满足条件才改变状态
    使用parted和kpartx 来对sdcard镜像进行分区调整,顺便用一下losetup
    linux添加具有root权限的管理员账号
    windows下获取系统的UUID
    pip修改镜像源
    linux中umount和mount
    mac安装brew
  • 原文地址:https://www.cnblogs.com/janmson/p/1370096.html
Copyright © 2020-2023  润新知