mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-10 11:40:16 +08:00
Documented tests.
Provided a brief description of test purposes.
This commit is contained in:
+23
-20
@@ -2,6 +2,8 @@
|
||||
/// <reference path="clientglobalcontext.d.ts" />
|
||||
/// <reference path="parature.d.ts" />
|
||||
|
||||
/// Demonstrate clientglobalcontext.d.ts
|
||||
|
||||
function _getContext()
|
||||
{
|
||||
var errorMessage = "Context is not available.";
|
||||
@@ -19,16 +21,17 @@ function _getContext()
|
||||
|
||||
var crmContext = _getContext();
|
||||
|
||||
/// Delegate selector call into getControl
|
||||
/// Demonstrate iterator typing
|
||||
|
||||
var grids = Xrm.Page.getControl(( control ) =>
|
||||
{
|
||||
return control.getControlType() === "subgrid";
|
||||
});
|
||||
|
||||
/// Describing the shape of an array.
|
||||
var selectedGridReferences: Xrm.Page.LookupValue[] = [];
|
||||
|
||||
/// Dynamic casting into lambda, raising from Xrm.Page.Control to Xrm.Page.GridControl
|
||||
/// Demonstrate iterator typing with v7.1 additions
|
||||
|
||||
grids.forEach(( gridControl: Xrm.Page.GridControl ) =>
|
||||
{
|
||||
gridControl.getGrid().getSelectedRows().forEach(( row ) =>
|
||||
@@ -37,43 +40,42 @@ grids.forEach(( gridControl: Xrm.Page.GridControl ) =>
|
||||
})
|
||||
});
|
||||
|
||||
/// Working to a string attribute, through getControl
|
||||
var stringControlType = Xrm.Page.getControl<Xrm.Page.StandardControl>( "new_someStringAttribute" );
|
||||
var stringAttribute = stringControlType.getAttribute<Xrm.Page.StringAttribute>();
|
||||
/// Demonstrate generic overload vs typecast
|
||||
|
||||
stringAttribute.setValue( "New String Value" );
|
||||
var lookupAttribute = <Xrm.Page.LookupControl>Xrm.Page.getControl( "customerid" );
|
||||
var lookupAttribute2 = Xrm.Page.getControl<Xrm.Page.LookupControl>( "customerid" );
|
||||
|
||||
/// Demonstrate ES6 String literal syntax
|
||||
|
||||
|
||||
/// Specialized control interfaces expose only appropriate members
|
||||
var lookupAttribute = Xrm.Page.getControl<Xrm.Page.LookupControl>( "customerid" );
|
||||
|
||||
/// ES6 String-literal style
|
||||
lookupAttribute.addCustomFilter( `<filter type="and">
|
||||
<condition attribute="address1_city" operator="eq" value="Redmond" />
|
||||
</filter>`, "account" );
|
||||
|
||||
/// Lambda event handler declaration
|
||||
lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); });
|
||||
|
||||
/// Type inference by interface casts getAttribute and getValue appropriately
|
||||
/// 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.");
|
||||
|
||||
/// Working with the Business Process Flow API
|
||||
/// Demonstrate v7.0 BPF API
|
||||
|
||||
if (Xrm.Page.data.process != null)
|
||||
Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ) });
|
||||
|
||||
/// Opening the QuickCreate form.
|
||||
/// Demonstrate v7.1 Quick Create form
|
||||
|
||||
Xrm.Utility.openQuickCreate(( newRecord ) => { alert( `Newly created record Id: ${newRecord.id}` ); }, "account" );
|
||||
|
||||
/// Setting every control on the form to visible
|
||||
/// Make all controls visible.
|
||||
|
||||
Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); });
|
||||
|
||||
/// Setting every tab and section on the form to visible
|
||||
/// Make all tabs and sections visible.
|
||||
|
||||
Xrm.Page.ui.tabs.forEach(( tab ) =>
|
||||
{
|
||||
tab.setVisible( true );
|
||||
@@ -84,16 +86,17 @@ Xrm.Page.ui.tabs.forEach(( tab ) =>
|
||||
});
|
||||
});
|
||||
|
||||
/// OnSave handler with context
|
||||
/// Demonstrate OnSave event context.
|
||||
|
||||
Xrm.Page.data.entity.addOnSave(( context ) =>
|
||||
{
|
||||
var eventArgs = context.getEventArgs();
|
||||
|
||||
/// Use of enumerations for more descriptive code
|
||||
if ( eventArgs.getSaveMode() === Xrm.Page.SaveMode.AutoSave || eventArgs.getSaveMode() === Xrm.Page.SaveMode.SaveAndClose )
|
||||
eventArgs.preventDefault();
|
||||
});
|
||||
|
||||
/// Demonstrate ES6 String literal with templates
|
||||
|
||||
alert( `The current form type is: ${Xrm.Page.ui.getFormType() }` );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user