Merge pull request #14460 from clownwilleatme/master

Adding new features for XRM v8.2
This commit is contained in:
Arthur Ozga
2017-02-08 15:44:57 -08:00
committed by GitHub
8 changed files with 808 additions and 210 deletions
+692 -143
View File
File diff suppressed because it is too large Load Diff
+38
View File
@@ -0,0 +1,38 @@
{
"rules": {
"class-name": true,
"comment-format": [ true, "check-space" ],
"indent": [ true, "spaces" ],
"no-duplicate-variable": true,
"no-eval": true,
"no-internal-module": false,
"no-trailing-whitespace": false,
"no-var-keyword": true,
"one-line": [ true, "check-whitespace" ],
"quotemark": [ true, "double" ],
"semicolon": true,
"triple-equals": [ true, "allow-null-check" ],
"align": [ true, "parameters", "statements" ],
"jsdoc-format": true,
"no-consecutive-blank-lines": true,
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"variable-name": [ true, "ban-keywords" ],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
]
}
}
+4 -4
View File
@@ -210,10 +210,10 @@ declare namespace Xrm
}
/**
* Interface for an item collection.
*
* @tparam T Generic type parameter.
*/
* Interface for an item collection.
*
* @tparam T Generic type parameter.
*/
export interface ItemCollection<T>
{
/**
+9 -10
View File
@@ -1,13 +1,12 @@
function _getContext()
{
var errorMessage = "Context is not available.";
if ( typeof GetGlobalContext != "undefined" )
const errorMessage = "Context is not available.";
if ( typeof GetGlobalContext !== "undefined" )
{ return GetGlobalContext(); }
else
{
if ( typeof Xrm != "undefined" )
if ( typeof Xrm !== "undefined" )
{
return Xrm.Page.context;
}
@@ -15,21 +14,21 @@ function _getContext()
}
}
var crmContext = _getContext();
const crmContext = _getContext();
var grids = Xrm.Page.getControl(( control ) =>
const grids = Xrm.Page.getControl(( control ) =>
{
return control.getControlType() === "subgrid";
});
var selectedGridReferences: Xrm.Page.LookupValue[] = [];
const selectedGridReferences: Xrm.Page.LookupValue[] = [];
grids.forEach(( gridControl: Xrm.Page.GridControl ) =>
{
gridControl.refresh();
});
var lookupAttribute = Xrm.Page.getControl<Xrm.Page.LookupControl>( "customerid" );
const lookupAttribute = Xrm.Page.getControl<Xrm.Page.LookupControl>( "customerid" );
lookupAttribute.addCustomFilter( `<filter type="and">
<condition attribute="address1_city" operator="eq" value="Redmond" />
@@ -37,7 +36,7 @@ lookupAttribute.addCustomFilter( `<filter type="and">
lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); });
var lookupValues = lookupAttribute.getAttribute().getValue();
const lookupValues = lookupAttribute.getAttribute().getValue();
if ( lookupValues !== null )
if ( !lookupValues[0].id || !lookupValues[0].entityType )
@@ -57,7 +56,7 @@ Xrm.Page.ui.tabs.forEach(( tab ) =>
Xrm.Page.data.entity.addOnSave(( context ) =>
{
var eventArgs = context.getEventArgs();
const eventArgs = context.getEventArgs();
if ( eventArgs.getSaveMode() === Xrm.Page.SaveMode.AutoSave || eventArgs.getSaveMode() === Xrm.Page.SaveMode.SaveAndClose )
eventArgs.preventDefault();
+12 -12
View File
@@ -125,7 +125,7 @@ declare namespace Xrm
* @return An array of control.
*/
getControl( delegateFunction: Collection.MatchingDelegate<Page.Control> ): Page.Control[];
}
};
/**
* Provides a container for useful functions not directly related to the current page.
@@ -207,7 +207,7 @@ declare namespace Xrm
* formid
*/
openWebResource( webResourceName: string, webResourceData?: string, width?: number, height?: number ): Window;
}
};
}
/**
@@ -552,10 +552,10 @@ declare namespace Xrm
}
/**
* Interface for an item collection.
*
* @tparam T Generic type parameter.
*/
* Interface for an item collection.
*
* @tparam T Generic type parameter.
*/
export interface ItemCollection<T>
{
/**
@@ -640,12 +640,12 @@ declare namespace Xrm
export interface Process
{
/**
* Returns the unique identifier of the process.
*
* @return The identifier for this process, in GUID format.
*
* @remarks Example: "{825CB223-A651-DF11-AA8B-00155DBA3804}".
*/
* Returns the unique identifier of the process.
*
* @return The identifier for this process, in GUID format.
*
* @remarks Example: "{825CB223-A651-DF11-AA8B-00155DBA3804}".
*/
getId(): string;
/**
-2
View File
@@ -3,8 +3,6 @@
// Definitions by: David Berry <https://github.com/6ix4our/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace Xrm.Page
{
/**
+14 -16
View File
@@ -9,12 +9,12 @@ parent.Xrm.Page.context.getOrgLcid();
function _getContext()
{
var errorMessage = "Context is not available.";
if ( typeof GetGlobalContext != "undefined" )
const errorMessage = "Context is not available.";
if ( typeof GetGlobalContext !== "undefined" )
{ return GetGlobalContext(); }
else
{
if ( typeof Xrm != "undefined" )
if ( typeof Xrm !== "undefined" )
{
return Xrm.Page.context;
}
@@ -22,16 +22,16 @@ function _getContext()
}
}
var crmContext = _getContext();
const crmContext = _getContext();
/// Demonstrate iterator typing
var grids = Xrm.Page.getControl(( control ) =>
const grids = Xrm.Page.getControl(( control ) =>
{
return control.getControlType() === "subgrid";
});
var selectedGridReferences: Xrm.Page.LookupValue[] = [];
const selectedGridReferences: Xrm.Page.LookupValue[] = [];
/// Demonstrate iterator typing with v7.1 additions
@@ -40,13 +40,13 @@ 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" );
const lookupAttribute = <Xrm.Page.LookupControl>Xrm.Page.getControl( "customerid" );
const lookupAttribute2 = Xrm.Page.getControl<Xrm.Page.LookupControl>( "customerid" );
/// Demonstrate ES6 String literal syntax
@@ -58,7 +58,7 @@ lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); });
/// Demonstrate strong-typed attribute association with strong-typed control
var lookupValues = lookupAttribute.getAttribute().getValue();
const lookupValues = lookupAttribute.getAttribute().getValue();
if ( lookupValues !== null )
if ( !lookupValues[0].id || !lookupValues[0].entityType )
@@ -67,7 +67,7 @@ if ( lookupValues !== null )
/// Demonstrate v7.0 BPF API
if (Xrm.Page.data.process != null)
Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ) });
Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ); });
/// Demonstrate v7.1 Quick Create form
@@ -93,7 +93,7 @@ Xrm.Page.ui.tabs.forEach(( tab ) =>
Xrm.Page.data.entity.addOnSave(( context ) =>
{
var eventArgs = context.getEventArgs();
const eventArgs = context.getEventArgs();
if ( eventArgs.getSaveMode() === XrmEnum.SaveMode.AutoSave || eventArgs.getSaveMode() === XrmEnum.SaveMode.SaveAndClose )
eventArgs.preventDefault();
@@ -107,7 +107,7 @@ 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 optionSetAttribute = Xrm.Page.getAttribute<Xrm.Page.OptionSetAttribute>( "statuscode" );
const optionValue: number = optionSetAttribute.getOptions()[0].value;
/// Demonstrate Control.setFocus();
@@ -116,7 +116,7 @@ optionSetAttribute.controls.get(0).setFocus();
/// Demonstrate setFormNotification
var level: Xrm.Page.ui.FormNotificationLevel;
let level: Xrm.Page.ui.FormNotificationLevel;
level = "ERROR";
Xrm.Page.ui.setFormNotification("Test", level, "uniqueId");
@@ -132,5 +132,3 @@ attribute.setSubmitMode(submitMode);
attribute.setSubmitMode(submitMode);
attribute.setRequiredLevel(requirementLevel);
attribute.setRequiredLevel(requirementLevelString);
+39 -23
View File
@@ -1,6 +1,4 @@
/// Demonstrate usage in the browser's window object
window.Xrm.Utility.alertDialog( "message", () => {} );
@@ -10,12 +8,12 @@ parent.Xrm.Page.context.getOrgLcid();
function _getContext()
{
var errorMessage = "Context is not available.";
if ( typeof GetGlobalContext != "undefined" )
const errorMessage = "Context is not available.";
if ( typeof GetGlobalContext !== "undefined" )
{ return GetGlobalContext(); }
else
{
if ( typeof Xrm != "undefined" )
if ( typeof Xrm !== "undefined" )
{
return Xrm.Page.context;
}
@@ -23,16 +21,16 @@ function _getContext()
}
}
var crmContext = _getContext();
const crmContext = _getContext();
/// Demonstrate iterator typing
var grids = Xrm.Page.getControl(( control ) =>
const grids = Xrm.Page.getControl(( control ) =>
{
return control.getControlType() === "subgrid";
});
var selectedGridReferences: Xrm.Page.LookupValue[] = [];
const selectedGridReferences: Xrm.Page.LookupValue[] = [];
/// Demonstrate iterator typing with v7.1 additions
@@ -45,8 +43,8 @@ grids.forEach(( gridControl: Xrm.Page.GridControl ) =>
/// Demonstrate generic overload vs typecast
var lookupAttribute = <Xrm.Page.LookupControl>Xrm.Page.getControl( "customerid" );
var lookupAttribute2 = Xrm.Page.getControl<Xrm.Page.LookupControl>( "customerid" );
const lookupAttribute = <Xrm.Page.LookupControl>Xrm.Page.getControl( "customerid" );
const lookupAttribute2 = Xrm.Page.getControl<Xrm.Page.LookupControl>( "customerid" );
/// Demonstrate ES6 String literal syntax
@@ -58,7 +56,7 @@ lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); });
/// Demonstrate strong-typed attribute association with strong-typed control
var lookupValues = lookupAttribute.getAttribute().getValue();
const lookupValues = lookupAttribute.getAttribute().getValue();
if ( lookupValues !== null )
if ( !lookupValues[0].id || !lookupValues[0].entityType )
@@ -67,15 +65,16 @@ if ( lookupValues !== null )
/// Demonstrate v7.0 BPF API
if (Xrm.Page.data.process != null)
Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ) });
Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ); });
/// Demonstrate v7.1 Quick Create form
Xrm.Utility.openQuickCreate("account").then(( object ) => { if (object) alert( `Newly created record Id: ${object.savedEntityReference.id}` ); }, (error) => {console.log(`Code: ${error.errorCode}, Message: ${error.message}`)});
Xrm.Utility.openQuickCreate("account").then(( object ) => { if (object) alert( `Newly created record Id: ${object.savedEntityReference.id}` ); }, (error) => {console.log(`Code: ${error.errorCode}, Message: ${error.message}`); });
/// Make all controls visible.
Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); });
// Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); }); // No longer works
Xrm.Page.ui.controls.forEach((control: Xrm.Page.StandardControl) => { control.setVisible(true); }); // Must cast to StandardControl
/// Make all tabs and sections visible.
@@ -93,7 +92,7 @@ Xrm.Page.ui.tabs.forEach(( tab ) =>
Xrm.Page.data.entity.addOnSave(( context ) =>
{
var eventArgs = context.getEventArgs();
const eventArgs = context.getEventArgs();
if ( eventArgs.getSaveMode() === XrmEnum.SaveMode.AutoSave || eventArgs.getSaveMode() === XrmEnum.SaveMode.SaveAndClose )
eventArgs.preventDefault();
@@ -107,7 +106,7 @@ 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 optionSetAttribute = Xrm.Page.getAttribute<Xrm.Page.OptionSetAttribute>( "statuscode" );
const optionValue: number = optionSetAttribute.getOptions()[0].value;
/// Demonstrate Control.setFocus();
@@ -116,27 +115,27 @@ optionSetAttribute.controls.get(0).setFocus();
/// Demonstrate setFormNotification
var level: Xrm.Page.ui.FormNotificationLevel;
let 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";
const requirementLevelString = "none";
let submitMode: Xrm.Page.SubmitMode = "always";
let submitModeString = "always";
const submitModeString = "always";
let attribute = Xrm.Page.getAttribute<Xrm.Page.LookupAttribute>("customerid");
attribute.setSubmitMode(submitMode);
attribute.setSubmitMode(submitMode);
attribute.setSubmitMode(submitModeString); // Works if the string is a const
attribute.setRequiredLevel(requirementLevel);
attribute.setRequiredLevel(requirementLevelString);
attribute.setRequiredLevel(requirementLevelString); // Works if the string is a const
/// Demonstrate v8 AutoComplete
let autoCompleteControl = Xrm.Page.getControl<Xrm.Page.AutoLookupControl>("name");
var userInput = autoCompleteControl.getValue();
const userInput = autoCompleteControl.getValue();
const accountResult = { };
const resultSet: Xrm.Page.AutoCompleteResultSet = {
results: new Array() as Xrm.Page.AutoCompleteResult[],
@@ -164,6 +163,23 @@ autoCompleteControl.removeOnKeyPress(() => {});
autoCompleteControl.showAutoComplete(resultSet);
autoCompleteControl.hideAutoComplete();
/// Demonstrate v8.2 quick form controls
const quickForm = Xrm.Page.ui.quickForms.get(0);
quickForm.getControlType(); // == "quickform"
quickForm.getName();
quickForm.getParent();
quickForm.getVisible(); // From UiCanSetVisibleElement
quickForm.getLabel(); // From UiLabelElement
quickForm.setLabel("Label"); // From UiLabelElement
quickForm.refresh();
// Get standard control
const ctrl = Xrm.Page.getControl<Xrm.Page.StandardControl>("controlName");
ctrl.getControlType();
ctrl.getName();
ctrl.getParent();
ctrl.getLabel();
ctrl.setLabel("Label name");
ctrl.getVisible();
ctrl.setVisible(true);