alertjs Documentation

时间:2018-11-08 15:42:27   收藏:0   阅读:188

原文地址:https://github.com/PaulNieuwelaar/alertjs/wiki/Documentation#alertshow

 

For version 3.0 documentation, click here.

Installation & Usage

  1. Download and install the unmanaged solution (recommended), or download the source files from other downloads, and create the required web resources manually using your own publisher prefix and naming style (not recommended as there are hardcoded references in the files).
  2. Make sure to publish all customizations if installing the unmanaged solution, or creating the web resources manually.
  3. Create a new JavaScript web resource or use an existing web resource to create your custom functions which will call the alert.js functions.
  4. Add a reference to the alert.js web resource on your form or view (the other required files are loaded automatically).
    • For forms, this is simply added through the form properties.
    • For views, add a "JavaScript Function Action" to the "Command Actions" for your button command, calling the alert.js web resource, where the function is "isNaN" (without quotes). Using the Ribbon Workbench to edit the command is recommended. 技术分享图片
  5. Add a reference to your custom JavaScript web resource where you‘re making the calls to alert.js. This should be added after the reference to alert.js.
  6. Call your custom function from your JavaScript library, e.g. from the command bar button, or from the form onload event.

Supported Functions

Alert.show

Use this method to show a light-box message. This can be called from a form, view, or anywhere that supports JavaScript. As of version 2.0, the unsupported CRM light-box is no longer being used. Instead a custom dialog is displayed, 100% contained within the solution, meaning the lightbox displays seamlessly on any browser.

Alert.show(title, message, buttons, icon, width, height, baseUrl, preventCancel, padding)

技术分享图片

Parameters

title

"Would you like to create a sale?"

message

"This will create and open the new sale record."

buttons

[
    new Alert.Button("Create Sale", createSaleFunction, true),
    new Alert.Button("Not now")
]

icon

"QUESTION"

width

500

height

250

baseUrl

"http://server/org"

preventCancel

true

padding

30

Alert.hide

Use this method to manually hide the alert from code. This is useful if you have a background process running which once completed, will automatically close the alert. This function accepts no input parameters, and has no return type. This will simply hide any alert being displayed at the time.

Alert.hide()

Alert.showLoading

Use this method to display a small loading spinner with the text "Loading...". This is just a simple wrapper for the Alert.show method with a few standardised defaults, making it easier to reuse when needing to display a loading message.

Alert.showLoading(url)

技术分享图片

Parameters

url

"http://server/org"

Alert.showWebResource

Use this method to display an HTML web resource inside a light-box. The URL of the web resource is generated and then passed into the Alert.showIFrame function, which creates an iframe to the web resource. You can also optionally add custom titles, buttons, and padding, just like the standard Alert.show function.

Alert.showWebResource(webResourceName, width, height, title, buttons, baseUrl, preventCancel, padding)

To access the web resource document, i.e. to get the values from inputs on the web resource, you can make a call to Alert.getIFrameWindow from the button callback of this alert, or from any other JavaScript. This allows you to access any elements inside the web resource being displayed.

To access CRM components from inside the web resource document, i.e. to execute some other form logic on click of a button inside your web resource, you can make a call to Alert.getCrmWindow from anywhere inside the web resource. This allows you to call other functions, or access form fields directly from within the web resource.

技术分享图片

Parameters

webResourceName

"new_/html/tester.html?Data=" + encodeURIComponent("someVar1=1&someVar2=2")

width

1600

height

900

title

"Change Account Name"

buttons

[new Alert.Button("OK", doSomething)]

baseUrl

"http://server/org"

preventCancel

true

padding

30

Alert.showDialogProcess

Use this method to display a CRM dialog process inside a light-box. The URL of the dialog process is generated and then passed into the Alert.showIFrame function, which creates an iframe to the dialog process. You can also optionally specify a callback function which will execute when the dialog is completed or cancelled, allowing you to refresh the form for example.

Alert.showDialogProcess(dialogId, entityName, recordId, callback, width, height, baseUrl)

技术分享图片

Parameters

dialogId

"ac03c16e-40b2-41c4-9831-4f651b77f393"

entityName

"account"

recordId

Xrm.Page.data.entity.getId()

callback

function () {
    Xrm.Page.data.refresh(); 
}

width

1600

height

900

baseUrl

"http://server/org"

Alert.showIFrame

Use this method to display a URL inside a light-box, via an iFrame. You can also optionally add custom titles, buttons, and padding, just like the standard Alert.show function.

Alert.showIFrame(iframeUrl, width, height, title, buttons, baseUrl, preventCancel, padding)

To access the iframe document, i.e. to get the values from inputs on the web page, you can make a call to Alert.getIFrameWindow from the button callback of this alert, or from any other JavaScript. This allows you to access any elements inside the web page being displayed. Note that cross-domain scripting is not allowed, so the web page being displayed in the iframe must be on the same domain as CRM for you to access its document via this method.

To access CRM components from inside the iframe document, i.e. to execute some other form logic on click of a button inside your web page, you can make a call to Alert.getCrmWindow from anywhere inside the web page. This allows you to call other functions, or access form fields directly from within the iframe document. Note that cross-domain scripting is not allowed, so the web page being displayed in the iframe must be on the same domain as CRM for you to call into CRM from its document.

技术分享图片

Parameters

iframeUrl

"http://bing.com"

width

1600

height

900

title

"Change Account Name"

buttons Type: Array of Alert.Button objects. The buttons to display at the bottom of the iframe. If this is set to null, no buttons will be displayed (i.e. if the buttons are managed inside the iframe). See the Alert.show documentation above for how to structure the buttons. To access values from the iframe, make a call to Alert.getIFrameWindow from the button callback.

[new Alert.Button("OK", doSomething)]

baseUrl

"http://server/org"

preventCancel

true

padding

30

Alert.getIFrameWindow

Use this method to get the context of an iFrame being displayed in the light-box. For example, if you‘re capturing input via a web resource, you can use this function to access the inputs on the web resource from inside a custom function. This allows you to use custom buttons to access the iFrame data.

Alert.getIFrameWindow()

Return type

var iFrameWindow = Alert.getIFrameWindow();

var value = iFrameWindow.document.getElementById("somefield").value;

Alert.getCrmWindow

This method gives you context of the CRM form (or client API wrapper if turbo forms are enabled). This allows you to access CRM functions, and your own custom JavaScript libraries from inside iFrame alerts. From inside a web resource, for example, you can call parent.Alert.getCrmWindow().doSomething();, where "doSomething()" represents a custom function loaded onto the parent form.

Alert.getCrmWindow()

Return type

var crmWindow = parent.Alert.getCrmWindow();

crmWindow.Xrm.Page.getAttribute("name").setValue("something")

Alert.htmlEncode

Use this method to encode a custom message which contains HTML characters, to allow it to be displayed inside the alert message. For example, if displaying formatted XML with indented spacing and XML tags, calling this method will format the text into an HTML friendly message that displays nicely inside the alert. The returned value should then be passed to the ‘message‘ of the Alert.show method.

NOTE: If you want to actually use HTML tags, like <b>bold</b>, you should not use this method.

Alert.htmlEncode(text)

技术分享图片

Parameters

text

"  <InnerFault>\n" +
"    <ErrorCode>-2147220969</ErrorCode>\n" +
"    <ErrorDetails xmlns:d3p1=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\" />\n" +
"    <Message>account With Id = b966e678-1d9d-e011-9293-000c2981699a Does Not Exist</Message>\n" +
"    <Timestamp>2016-06-22T04:13:14.4579317Z</Timestamp>\n" +
"    <InnerFault i:nil=\"true\" />\n" +
"    <TraceText i:nil=\"true\" />\n" +
"  </InnerFault>"

Return type

"&nbsp;&nbsp;&lt;InnerFault&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;ErrorCode&gt;-2147220969&lt;/ErrorCode&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;ErrorDetails xmlns:d3p1=&quot;http://schemas.datacontract.org/2004/07/System.Collections.Generic&quot; /&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;Message&gt;account With Id = b966e678-1d9d-e011-9293-000c2981699a Does Not Exist&lt;/Message&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;Timestamp&gt;2016-06-22T04:13:14.4579317Z&lt;/Timestamp&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;InnerFault i:nil=&quot;true&quot; /&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;TraceText i:nil=&quot;true&quot; /&gt;<br />&nbsp;&nbsp;&lt;/InnerFault&gt;"

技术分享图片

原文:https://www.cnblogs.com/BinBinGo/p/9929120.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!