mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-29 00:51:29 +08:00
Merge pull request #11272 from daryllabar/master
Added the new 8.0 AutoComplete Features.
This commit is contained in:
2590
xrm/xrm-7.1.d.ts
vendored
Normal file
2590
xrm/xrm-7.1.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
137
xrm/xrm-7.1.tests.ts
Normal file
137
xrm/xrm-7.1.tests.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
/// <reference path="xrm.d.ts" />
|
||||
/// <reference path="parature.d.ts" />
|
||||
|
||||
/// Demonstrate usage in the browser's window object
|
||||
|
||||
window.Xrm.Utility.alertDialog( "message", () => {} );
|
||||
parent.Xrm.Page.context.getOrgLcid();
|
||||
|
||||
/// Demonstrate clientglobalcontext.d.ts
|
||||
|
||||
function _getContext()
|
||||
{
|
||||
var errorMessage = "Context is not available.";
|
||||
if ( typeof GetGlobalContext != "undefined" )
|
||||
{ return GetGlobalContext(); }
|
||||
else
|
||||
{
|
||||
if ( typeof Xrm != "undefined" )
|
||||
{
|
||||
return Xrm.Page.context;
|
||||
}
|
||||
else { throw new Error( errorMessage ); }
|
||||
}
|
||||
}
|
||||
|
||||
var crmContext = _getContext();
|
||||
|
||||
/// Demonstrate iterator typing
|
||||
|
||||
var grids = Xrm.Page.getControl(( control ) =>
|
||||
{
|
||||
return control.getControlType() === "subgrid";
|
||||
});
|
||||
|
||||
var selectedGridReferences: Xrm.Page.LookupValue[] = [];
|
||||
|
||||
/// Demonstrate iterator typing with v7.1 additions
|
||||
|
||||
grids.forEach(( gridControl: Xrm.Page.GridControl ) =>
|
||||
{
|
||||
gridControl.getGrid().getSelectedRows().forEach(( row ) =>
|
||||
{
|
||||
selectedGridReferences.push( row.getData().getEntity().getEntityReference() );
|
||||
})
|
||||
});
|
||||
|
||||
/// Demonstrate generic overload vs typecast
|
||||
|
||||
var lookupAttribute = <Xrm.Page.LookupControl>Xrm.Page.getControl( "customerid" );
|
||||
var lookupAttribute2 = Xrm.Page.getControl<Xrm.Page.LookupControl>( "customerid" );
|
||||
|
||||
/// Demonstrate ES6 String literal syntax
|
||||
|
||||
lookupAttribute.addCustomFilter( `<filter type="and">
|
||||
<condition attribute="address1_city" operator="eq" value="Redmond" />
|
||||
</filter>`, "account" );
|
||||
|
||||
lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); });
|
||||
|
||||
/// Demonstrate strong-typed attribute association with strong-typed control
|
||||
|
||||
var lookupValues = lookupAttribute.getAttribute().getValue();
|
||||
|
||||
if ( lookupValues !== null )
|
||||
if ( !lookupValues[0].id || !lookupValues[0].entityType )
|
||||
throw new Error("Invalid value in Lookup control.");
|
||||
|
||||
/// Demonstrate v7.0 BPF API
|
||||
|
||||
if (Xrm.Page.data.process != null)
|
||||
Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ) });
|
||||
|
||||
/// Demonstrate v7.1 Quick Create form
|
||||
|
||||
Xrm.Utility.openQuickCreate(( newRecord ) => { alert( `Newly created record Id: ${newRecord.id}` ); }, "account" );
|
||||
|
||||
/// Make all controls visible.
|
||||
|
||||
Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); });
|
||||
|
||||
/// Make all tabs and sections visible.
|
||||
|
||||
Xrm.Page.ui.tabs.forEach(( tab ) =>
|
||||
{
|
||||
tab.setVisible( true );
|
||||
|
||||
tab.sections.forEach(( section ) =>
|
||||
{
|
||||
section.setVisible( true );
|
||||
});
|
||||
});
|
||||
|
||||
/// Demonstrate OnSave event context.
|
||||
|
||||
Xrm.Page.data.entity.addOnSave(( context ) =>
|
||||
{
|
||||
var eventArgs = context.getEventArgs();
|
||||
|
||||
if ( eventArgs.getSaveMode() === XrmEnum.SaveMode.AutoSave || eventArgs.getSaveMode() === XrmEnum.SaveMode.SaveAndClose )
|
||||
eventArgs.preventDefault();
|
||||
});
|
||||
|
||||
/// Demonstrate ES6 String literal with templates
|
||||
|
||||
alert( `The current form type is: ${Xrm.Page.ui.getFormType() }` );
|
||||
|
||||
alert( `The current entity type is: ${Xrm.Page.data.entity.getEntityName() }` );
|
||||
|
||||
/// Demonstrate Optionset Value as int in Turbo Forms
|
||||
|
||||
var optionSetAttribute = Xrm.Page.getAttribute<Xrm.Page.OptionSetAttribute>( "statuscode" );
|
||||
const optionValue: number = optionSetAttribute.getOptions()[0].value;
|
||||
|
||||
/// Demonstrate Control.setFocus();
|
||||
|
||||
optionSetAttribute.controls.get(0).setFocus();
|
||||
|
||||
/// Demonstrate setFormNotification
|
||||
|
||||
var level: Xrm.Page.ui.FormNotificationLevel;
|
||||
level = "ERROR";
|
||||
Xrm.Page.ui.setFormNotification("Test", level, "uniqueId");
|
||||
|
||||
/// Demonstrate Requirement Level and Submit Mode both via string parameters and String Literal Types
|
||||
|
||||
let requirementLevel: Xrm.Page.RequirementLevel = "none";
|
||||
let requirementLevelString = "none";
|
||||
let submitMode: Xrm.Page.SubmitMode = "always";
|
||||
let submitModeString = "always";
|
||||
|
||||
let attribute = Xrm.Page.getAttribute<Xrm.Page.LookupAttribute>("customerid");
|
||||
attribute.setSubmitMode(submitMode);
|
||||
attribute.setSubmitMode(submitMode);
|
||||
attribute.setRequiredLevel(requirementLevel);
|
||||
attribute.setRequiredLevel(requirementLevelString);
|
||||
|
||||
|
||||
@@ -133,3 +133,38 @@ attribute.setSubmitMode(submitMode);
|
||||
attribute.setSubmitMode(submitMode);
|
||||
attribute.setRequiredLevel(requirementLevel);
|
||||
attribute.setRequiredLevel(requirementLevelString);
|
||||
|
||||
/// Demonstrate v8 AutoComplete
|
||||
|
||||
let autoCompleteControl = Xrm.Page.getControl<Xrm.Page.AutoLookupControl>("name");
|
||||
var userInput = autoCompleteControl.getValue();
|
||||
const accountResult = { };
|
||||
const resultSet: Xrm.Page.AutoCompleteResultSet = {
|
||||
results: new Array() as Xrm.Page.AutoCompleteResult[],
|
||||
commands: {
|
||||
id: "sp_commands",
|
||||
label: "Learn More",
|
||||
action() {
|
||||
// Specify what you want to do when the user
|
||||
// clicks the "Learn More" link at the bottom
|
||||
// of the auto-completion list.
|
||||
// For this sample, we are just opening a page
|
||||
// that provides information on working with
|
||||
// accounts in CRM.
|
||||
window.open("http://www.microsoft.com/en-us/dynamics/crm-customer-center/create-or-edit-an-account.aspx");
|
||||
}
|
||||
} as Xrm.Page.AutoCompleteCommand
|
||||
};
|
||||
resultSet.results.push({
|
||||
id: 0,
|
||||
fields: ["A. Datum Corporation"]
|
||||
});
|
||||
autoCompleteControl.addOnKeyPress(() => { });
|
||||
autoCompleteControl.fireOnKeyPress();
|
||||
autoCompleteControl.removeOnKeyPress(() => {});
|
||||
autoCompleteControl.showAutoComplete(resultSet);
|
||||
autoCompleteControl.hideAutoComplete();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
112
xrm/xrm.d.ts
vendored
112
xrm/xrm.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
// Type definitions for Microsoft Dynamics xRM API v7.1
|
||||
// Type definitions for Microsoft Dynamics xRM API v8.0
|
||||
// Project: http://www.microsoft.com/en-us/download/details.aspx?id=44567
|
||||
// Definitions by: David Berry <https://github.com/6ix4our/>, Matt Ngan <https://github.com/mattngan/>, Markus Mauch <https://github.com/markusmauch/>, Daryl LaBar <https://github.com/daryllabar>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@@ -865,6 +865,66 @@ declare namespace Xrm
|
||||
setFocus(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for Result value of AutoCompleteResultSet
|
||||
*/
|
||||
export interface AutoCompleteResult {
|
||||
/**
|
||||
* The Identifier
|
||||
*/
|
||||
id: string|number;
|
||||
|
||||
/**
|
||||
* Url of the icon to display
|
||||
*/
|
||||
icon?: string;
|
||||
|
||||
/**
|
||||
* Display value(s) for this auto-complete option
|
||||
*/
|
||||
fields: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for command of AutoCompleteResultSet. This is displayed at the bottom of the auto complete view
|
||||
*/
|
||||
export interface AutoCompleteCommand {
|
||||
/**
|
||||
* The Identifier
|
||||
*/
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* Url of the icon to display
|
||||
*/
|
||||
icon?: string;
|
||||
|
||||
/**
|
||||
* Label to display at the bottom of the auto complete view
|
||||
*/
|
||||
label: string;
|
||||
|
||||
/**
|
||||
* Action to perform when user clicks on label
|
||||
*/
|
||||
action(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for showAutoComplete argument
|
||||
*/
|
||||
export interface AutoCompleteResultSet {
|
||||
/**
|
||||
* Results to show
|
||||
*/
|
||||
results: AutoCompleteResult[];
|
||||
|
||||
/**
|
||||
* Command to show/execute at the bottom of the results displayed
|
||||
*/
|
||||
commands?: AutoCompleteCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for a Lookup value.
|
||||
*/
|
||||
@@ -1682,6 +1742,56 @@ declare namespace Xrm
|
||||
getAttribute(): Attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interace for Auto Lookup Control
|
||||
* This is not an Entity Lookup, but a control that supports AutoComplete/KeyPress Events (Text)
|
||||
* NOTE * This interface is not supported for CRM mobile clients (phones or tablets) and the interactive service hub. It is only available for Updated entities.
|
||||
*
|
||||
* @sa StandardControl
|
||||
*/
|
||||
export interface AutoLookupControl extends StandardControl {
|
||||
/**
|
||||
* Use this to add a function as an event handler for the keypress event so that the function is called when you type a character in the specific text or number field.
|
||||
* For a sample JavaScript code that uses the addOnKeyPress method to configure the auto-completion experience, see Sample: Auto-complete in CRM controls.
|
||||
*
|
||||
* @param {ContextSensitiveHandler} handler The function reference.
|
||||
*/
|
||||
addOnKeyPress(handler: ContextSensitiveHandler): void;
|
||||
|
||||
/**
|
||||
* Use this to manually fire an event handler that you created for a specific text or number field to be executed on the keypress event.
|
||||
*/
|
||||
fireOnKeyPress(): void;
|
||||
|
||||
/**
|
||||
* Gets the latest value in a control as the user types characters in a specific text or number field.
|
||||
* This method helps you to build interactive experiences by validating data and alerting users as they type characters in a control.
|
||||
* The getValue method is different from the attribute getValue method because the control method retrieves the value from the control
|
||||
* as the user is typing in the control as opposed to the attribute getValue method that retrieves the value after the user commits (saves) the field.
|
||||
*/
|
||||
getValue(): string;
|
||||
|
||||
/**
|
||||
* Hides the auto-completion drop-down list configured for a specific text field
|
||||
*/
|
||||
hideAutoComplete(): void;
|
||||
|
||||
/**
|
||||
* Use this to remove an event handler for a text or number field that you added using addOnKeyPress.
|
||||
*
|
||||
* Remarks: If an anonymous function is set using addOnKeyPress, it can’t be removed using this method.
|
||||
* @param {ContextSensitiveHandler} handler The function reference.
|
||||
*/
|
||||
removeOnKeyPress(handler: ContextSensitiveHandler): void;
|
||||
|
||||
/**
|
||||
* Shows upt to 10 matching strings in a drop-down list as users press keys to type charactrer in a specific text field.
|
||||
* On selecting an item in the drop-down list, the value in the text field changes to the selected item, the drop-down list disappears, and the OnChange event for the text field is invoked
|
||||
* @param resultSet
|
||||
*/
|
||||
showAutoComplete(resultSet: AutoCompleteResultSet): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for a Date control.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user