|
![]() |
#1 |
Участник
|
CRM DE LA CREME! Some useful CRMform jscripts
Источник: http://crmdelacreme.blogspot.com/200...-jscripts.html
============== <span style="font-family:arial;font-size:85%;">/* function isFormInCreateMode() function isFormInUpdateMode() isFormActive = function() hideNavBarItemById = function(navBarItemId) setNavBarItemVisibilityByName = function(sectionName, itemName, visible) hideNavBarItemByName = function(sectionName, itemName) showNavBarItemByName = function(sectionName, itemName) setFormEnabled = function(enabled) hideTabById = function(tabId) hideTabByName = function(tabName) setControlEnabled = function(fieldObject, enabled) setFieldRequired = function(fieldObject) setFieldRecommended = function(fieldObject) setFieldNotRequired = function(fieldObject) refParam = function() getLastKnownGood = function(fieldObject) setLastKnownGood = function(fieldObject, value) captureLastKnownGood = function(fieldObject) restoreLastKnownGood = function(fieldObject) hookValidationOnChange = function(fieldObject) hookValidationOnBlur = function(fieldObject) hookValidation = function(fieldObject, functionPointer, optionalFocusFieldObject) performValidation = function() function guidString4() createGuid = function() hideActionMenuItem = function(itemName) HideAssociatedViewButtons = function(loadAreaId, buttonTitles) */ // Check if form in CREATE mode isFormInCreateMode = function() { if (crmForm.FormType == 1) return true; else return false; } // Check if form in UPDATE mode isFormInUpdateMode = function() { if (crmForm.FormType == 2) return true; else return false; } isFormActive = function() { var active = true; if (crmForm.all.statecode != null && crmForm.all.statecode.DataValue != null ) active = (crmForm.all.statecode.DataValue == 0); if( active ) active = (crmForm.FormType 4); // not readonly or disabled return active; } /************************************************************************************************************************/ /* Navigation Map Functions /************************************************************************************************************************/ /* hide a navigation bar item */ hideNavBarItemById = function(navBarItemId) { var navBar = document.getElementById(navBarItemId) if (navBar != null) { navBar.style.display = "none"; } } /* hide a tab using the tab name as reference */ setNavBarSectionVisibilityByName = function( sectionName, visible ) { var groups = document.getElementById("crmNavBar").childNodes; if( groups != null ) { for( var i = 0; i < groups.length; i++ ) { var groupName = groups[i].childNodes[0]; if( groupName.innerText.trim() == sectionName ) { groupName.style.display = visible ? "block" : "none"; groups[i].childNodes[1].style.display = visible ? "block" : "none"; } } } } /* hide a tab using the tab name as reference */ setNavBarItemVisibilityByName = function( sectionName, itemName, visible ) { var groups = document.getElementById("crmNavBar").childNodes; if( groups != null ) { for( var i = 0; i < groups.length; i++ ) { var groupName = groups[i].childNodes[0]; if( groupName.innerText.trim() == sectionName ) { var items = groups[i].childNodes[1].childNodes; for( var n = 0; n < items.length; n++ ) { var item = items[n]; if( item.innerText.trim() == itemName ) item.style.display = visible ? "inline" : "none"; } } } } } /* hide a tab using the tab name as reference */ hideNavBarItemByName = function( sectionName, itemName ) { setNavBarItemVisibilityByName(sectionName, itemName, false); } /* hide a tab using the tab name as reference */ showNavBarItemByName = function( sectionName, itemName ) { setNavBarItemVisibilityByName(sectionName, itemName, true); } /************************************************************************************************************************/ /* Form Functions /************************************************************************************************************************/ setFormEnabled = function(enabled) { var iLen = crmForm.all.length; for (i = 0; i < iLen; i++) { crmForm.all[i].Disabled = !enabled; } } // gets the ordinal position of a tab getTabNumber = function( tabName ) { var tabs = document.getElementById("crmTabBar").childNodes; if( tabs != null ) { for (var i = 0; i < tabs.length; i++) { var tab = tabs[i]; if (tab.innerText == tabName) { return i; } } } return -1; } // returns a tab by name getTabByName = function( tabName ) { var tabs = document.getElementById("crmTabBar").childNodes; if (tabs != null) { var num = getTabNumber(tabName); if( num >= 0 ) { return tabs[num]; } } return null; } /* disable or enable tab using the tab name as reference */ setTabEnabledByName = function(tabName, enabled) { var tab = getTabByName(tabName); if( tab != null ) { tab.disabled = !enabled; } } /* hide a tab using the tab id as reference */ hideTabById = function(tabId) { var tab = document.getElementById(tabId); if( tab != null ) { tab.style.display = "none"; } } /* hide a tab using the tab name as reference */ hideTabByName = function(tabName) { var tab = getTabByName(tabName); if( tab != null ) { //alert(tab.style.display); tab.style.display = "none"; } } /* show a tab using the tab name as reference */ showTabByName = function(tabName) { var tab = getTabByName(tabName); if( tab != null ) { tab.style.display = "block"; } } /* Enabled/disable a control by setting the disabled property and toggling "ms-crm-ReadOnly" on the classname */ setControlEnabled = function(fieldObject, enabled) { fieldObject.disabled = !enabled; if (!enabled && fieldObject.className.indexOf("ms-crm-Text") >= 0) { // append readonly property to className if not already there if (fieldObject.className.indexOf("ms-crm-ReadOnly") < 0) fieldObject.className += " ms-crm-ReadOnly"; } else fieldObject.className = fieldObject.className.replace(/ ms-crm-ReadOnly/gi, ""); } setFieldRequired = function(fieldObject) { crmForm.SetFieldReqLevel(fieldObject.id, 2); } setFieldRecommended = function(fieldObject) { crmForm.SetFieldReqLevel(fieldObject.id, 1); } setFieldNotRequired = function(fieldObject) { crmForm.SetFieldReqLevel(fieldObject.id, 0); } /************************************************************************************************************************/ /* Validation base functions /************************************************************************************************************************/ /* represents a parameter object to be passed by reference * use param.setValue from a function to set the return value of the parameter * use param.getValue to read the returned value */ refParam = function() { this.array = new Array(1); this.setValue = function(v) { this.array[0] = v; } this.getValue = function() { return this.array[0]; } } /* gets/captures/restores the value of the field as the last known good value */ getLastKnownGood = function(fieldObject) { return fieldObject.getAttribute("lastKnownGood"); } setLastKnownGood = function(fieldObject, value) { fieldObject.setAttribute("lastKnownGood", value); } captureLastKnownGood = function(fieldObject) { setLastKnownGood(fieldObject, fieldObject.DataValue); } restoreLastKnownGood = function(fieldObject) { fieldObject.DataValue = getLastKnownGood(fieldObject); } /* * captures last known good value (captureLastKnownGood) * hooks validation of the field onto the "onchange" event */ hookValidationOnChange = function(fieldObject) { fieldObject.setAttribute("onblur", null); fieldObject.setAttribute("onchange", performValidation); } hookValidationOnBlur = function(fieldObject) { fieldObject.setAttribute("onchange", null); fieldObject.setAttribute("onblur", performValidation); } hookValidation = function(fieldObject, functionPointer, optionalFocusFieldObject) { captureLastKnownGood(fieldObject); fieldObject.setAttribute("validationFunction", functionPointer); if( optionalFocusFieldObject != null ) fieldObject.setAttribute("focusFieldObject", optionalFocusFieldObject); fieldObject.setAttribute("onchange", performValidation); } performValidation = function() { var fieldObject = event.srcElement; if( fieldObject.DataValue != getLastKnownGood(fieldObject) ) { var functionPointer = fieldObject.getAttribute("validationFunction"); var message = new refParam(); var valid = functionPointer(fieldObject, message); if( !valid ) { var msg = message.getValue() + "\r\n\nWould you like to correct the value?"; if( confirm(msg) ) { var focusObject = fieldObject.getAttribute("focusFieldObject"); if( focusObject == null ) focusObject = fieldObject; else { captureLastKnownGood(fieldObject); hookValidationOnChange(fieldObject); setLastKnownGood(focusObject, null); } focusObject.SetFocus(); event.returnValue = false; hookValidationOnBlur(focusObject); } else { restoreLastKnownGood(fieldObject); hookValidationOnChange(fieldObject); } } else { captureLastKnownGood(fieldObject); hookValidationOnChange(fieldObject); } } else hookValidationOnChange(fieldObject); } guidString4 = function() { return (((1 + Math.random()) * 0x10000) 0).toString(16).substring(1); } createGuid = function() { return (guidString4() + guidString4() + "-" + guidString4() + "-" + guidString4() + "-" + guidString4() + "-" + guidString4() + guidString4() + guidString4()).toUpperCase(); } /* hide action menu item */ hideActionMenuItem = function(itemName) { var element = document.getElementById(itemName) if (element != null) { element.style.display = "none"; } } hideActionMenuDeleteButton = function() { hideActionMenuItem("_MIonActionMenuClickdelete" + crmForm.ObjectTypeCode); } hideActionMenuDeactivateButton = function() { hideActionMenuItem("_MIchangeStatedeactivate" + crmForm.ObjectTypeCode + "5"); } hideActionMenuActivateButton = function() { hideActionMenuItem("_MIchangeStateactivate" + crmForm.ObjectTypeCode + "6"); } /* Hides the associated Views buttons. i.e Hides the add existing button. */ /* NB: If called multiple times, the settings of the previous calls are overwritten by the final one! */ /* A menu element on the "More actions" drop-down menu can be hidden * by adding a string such as 'More Actions::Activate' to the buttonTitles array. */ HideAssociatedViewButtons = function(loadAreaId, buttonTitles) { var navElement = document.getElementById('nav_' + loadAreaId); if (navElement != null) { navElement.onclick = function LoadAreaOverride() { // Call the original CRM method to launch the navigation link and create area iFrame loadArea(loadAreaId); HideViewButtons(document.getElementById(loadAreaId + 'Frame'), buttonTitles); } } } /* Used internally by the 'HideAssociatedViewButtons' method */ HideViewButtons = function(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++) { buttonTitleParts = buttonTitles[j].split('::'); if (buttonTitleParts.length > 0) { buttonTitle = buttonTitleParts[0]; for (var i = 0; i < liElements.length; i++) { liElement = liElements[i]; if (liElement.getAttribute('title') == buttonTitle) { if (buttonTitleParts.length == 1) { liElement.style.display = 'none'; break; } else { /* We want to hide a menu item in a drop-down menu. Find the descendant text element with the specified text. Then find its parent list item and hide it: */ menuText = buttonTitleParts[1]; var spanElements = liElement.getElementsByTagName('span'); for (var k = 0; k < spanElements.length; k++) { spanElement = spanElements[k]; if (spanElement.className == 'ms-crm-MenuItem-Text' ) { textElement = spanElement.firstChild; if (textElement != null && textElement.nodeType == 3) /* 3 = Node.TEXT_NODE */ { if (textElement.data == menuText) { liMenuItemElement = spanElement.parentNode.parentNode.parentNode; liMenuItemElement.style.display = 'none'; break; } } } } } } } } } } } } } // Load up a CRM entity into an iframe - typically the main view screen getCRMFormSource = function(tabSet) { if (crmForm.ObjectId != null) { var oId = crmForm.ObjectId; var oType = crmForm.ObjectTypeCode; var security = crmFormSubmit.crmFormSubmitSecurity.value; return "/userdefined/areas.aspx?oId=" + oId + "&oType=" + oType + "&security=" + security + "&tabSet=" + tabSet; } else { return "about:blank"; } } setVisibilityOfSectionContainingField = function(crmField, visibility) { if (visibility) { crmField.parentElement.parentElement.parentElement.style.display = 'block'; } else { crmField.parentElement.parentElement.parentElement.style.display = 'none'; } } hideSectionContainingField = function(crmField) { setVisibilityOfSectionContainingField(crmField, false); } setVisibilityOfSectionWithName = function(tabNumber, sectionName, visibility) { var tab = document.getElementById('tab' + tabNumber.toString()); if (tab != null) { var tdElements = tab.getElementsByTagName('td'); for (var i = 0; i < tdElements.length; i++) { tdElement = tdElements[i]; if (tdElement.className == 'ms-crm-Form-Section ms-crm-Form-SectionBar') { textElement = tdElement.firstChild; if (textElement != null && textElement.nodeType == 3) /* 3 = Node.TEXT_NODE */ { if (textElement.data == sectionName) { trSectionElement = tdElement.parentNode.parentNode.parentNode.parentNode.parentNode; if (visibility) { trSectionElement.style.display = 'block'; } else { trSectionElement.style.display = 'none'; } return true; } } } } } return false; } hideSectionWithName = function(tabNumber, sectionName) { return setVisibilityOfSectionWithName(tabNumber, sectionName, false); } hideSection = function(tabName, sectionName) { var tabNumber = getTabNumber(tabName); return setVisibilityOfSectionWithName(tabNumber, sectionName, false); } showSection = function(tabName, sectionName) { var tabNumber = getTabNumber(tabName); return setVisibilityOfSectionWithName(tabNumber, sectionName, true); } showModalWindow = function(url, objectparams, x, y, height, width) { return window.showModalDialog(url, objectparams, (height != null ? "dialogHeight:" + height.toString() + "px;" : "") + (width != null ? "dialogWidth:" + width.toString() + "px;" : "") + (y != null ? "dialogTop:" + y.toString() + "px;" : "") + (x != null ? "dialogLeft:" + x.toString() + "px;" : "") + "center:Yes;" + "help:No;" + "resizable:No;" + "scroll:No;" + "status:No;"); } FetchViewer = function( iframeId ) { var Instance = this; var vDynamicForm; var m_iframeTab; var m_iframeDoc; Instance.Entity = ""; Instance.Iframe = null; Instance.FetchXml = ""; Instance.QueryId = ""; Instance.LayoutXml = ""; Instance.RegisterOnTab = function( tabIndex ) { Instance.Iframe = document.getElementById( iframeId ); if( !Instance.Iframe ) return alert( "Iframe " + iframeId + " is undefined" ); m_iframeDoc = getIframeDocument(); var loadingGifHTML = ""; loadingGifHTML += ""; loadingGifHTML += ""; loadingGifHTML += " ![]() loadingGifHTML += "Loading View..."; loadingGifHTML += ""; m_iframeDoc.body.innerHTML = loadingGifHTML; if( parseInt( "0" + tabIndex ) == 0 ) Instance.Refresh(); else Instance.Iframe.attachEvent( "onreadystatechange" , RefreshOnReadyStateChange ); } function RefreshOnReadyStateChange() { if( Instance.Iframe.readyState != 'complete' ) return; Instance.Refresh(); } Instance.Refresh = function() { if( !Instance.Iframe ) return alert( "Iframe " + iframeId + " is undefined" ); m_iframeDoc = getIframeDocument(); Instance.Iframe.detachEvent( "onreadystatechange" , RefreshOnReadyStateChange ); var create = m_iframeDoc.createElement; var append1 = m_iframeDoc.appendChild; vDynamicForm = create(""); var append2 = vDynamicForm.appendChild; append2(create("")); append2(create("")); append2(create("")); append2(create("")); append2(create("")); append1( vDynamicForm ); vDynamicForm.action = prependOrgName("/AdvancedFind/fetchData.aspx"); vDynamicForm.FetchXml.value = Instance.FetchXml; vDynamicForm.LayoutXml.value = Instance.LayoutXml; vDynamicForm.EntityName.value = Instance.Entity; vDynamicForm.DefaultAdvFindViewId.value = Instance.QueryId; vDynamicForm.ViewType.value = 1039; vDynamicForm.submit(); Instance.Iframe.attachEvent( "onreadystatechange" , OnViewReady ); } function OnViewReady() { if( Instance.Iframe.readyState != 'complete' ) return; Instance.Iframe.style.border = 0; Instance.Iframe.detachEvent( "onreadystatechange" , OnViewReady ); m_iframeDoc = getIframeDocument(); m_iframeDoc.body.scroll = "no"; m_iframeDoc.body.style.padding = "0px"; } getIframeDocument = function() { return Instance.Iframe.contentWindow.document; } } // Set custom form title setFormTitle = function(title) { document.all.crmMenuBar.nextSibling.rows[0].cells[1].childNodes[0].innerText = title; } setLookupEnabled = function(control, enabled) { control.Disabled = !enabled; } /****************** BUTTONS *************************/ // Get an element in a document by it's class name // Parameters: // oElm = starting element // strTagName = tags to filter on, e.g. TR or * for all // oClassNames = arraylist of class names to find // Returns: // array of elements found function getElementsByClassName(oElm, strTagName, oClassNames){ var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName); var arrReturnElements = new Array(); var arrRegExpClassNames = new Array(); if(typeof oClassNames == "object"){ for(var i=0; i
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
|