Merge pull request #9696 from daryllabar/master

Added Missing function definitions and String Literal Types
This commit is contained in:
Mohamed Hegazy
2016-06-21 12:37:54 -07:00
committed by GitHub
2 changed files with 154 additions and 171 deletions
+30
View File
@@ -105,3 +105,33 @@ Xrm.Page.data.entity.addOnSave(( context ) =>
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);
+124 -171
View File
@@ -1,6 +1,6 @@
// Type definitions for Microsoft Dynamics xRM API v7.1
// 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/>
// 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
declare var Xrm: Xrm.XrmStatic;
@@ -210,6 +210,19 @@ declare namespace Xrm
}
}
/**
* Client Types for Xrm.Page.context.getClient().
*/
export type Client = "Web" | "Outlook" | "Mobile";
/**
* Client States for Xrm.Page.context.getClientState().
*/
export type ClientState = "Online" | "Offline";
/**
* Themes for Xrm.Page.context.getCurrentTheme().
*/
export type Theme = "default" | "Office12Blue" | "Office14Silver";
/**
* Interface for the client context.
*/
@@ -220,14 +233,14 @@ declare namespace Xrm
*
* @return The client, as either "Web", "Outlook", or "Mobile"
*/
getClient(): string;
getClient(): Client;
/**
* Gets client's current state.
*
* @return The client state, as either "Online" or "Offline"
*/
getClientState(): string;
getClientState(): ClientState;
}
/**
@@ -257,7 +270,7 @@ declare namespace Xrm
*
* @remarks This function does not work with Dynamics CRM for tablets.
*/
getCurrentTheme(): string;
getCurrentTheme(): Theme;
/**
* Gets whether automatic save is enabled.
@@ -437,49 +450,7 @@ declare namespace Xrm
*/
refreshRibbon(): void;
/**
* Sets a form-level notification.
*
* @param {string} message The message.
* @param {"ERROR"} level An error message.
* @param {string} uniqueId A unique identifier for the message.
*
* @return true if it succeeds, false if it fails.
*/
setFormNotification( message: string, level: "ERROR", uniqueId: string ): boolean;
/**
* Sets a form-level notification.
*
* @param {string} message The message.
* @param {"WARNING"} level A warning message.
* @param {string} uniqueId A unique identifier for the message.
*
* @return true if it succeeds, false if it fails.
*/
setFormNotification( message: string, level: "WARNING", uniqueId: string ): boolean;
/**
* Sets a form-level notification.
*
* @param {string} message The message.
* @param {"INFO"} level An informational message.
* @param {string} uniqueId A unique identifier for the message.
*
* @return true if it succeeds, false if it fails.
*/
setFormNotification( message: string, level: "INFO", uniqueId: string ): boolean;
/**
* Sets a form-level notification.
*
* @param {string} message The message.
* @param {string} level The level, as either "ERROR", "WARNING", or "INFO".
* @param {string} uniqueId A unique identifier for the message.
*
* @return true if it succeeds, otherwise false.
*/
setFormNotification( message: string, level: string, uniqueId: string ): boolean;
setFormNotification(message: string, level: Page.ui.FormNotificationLevel | string, uniqueId: string ): boolean;
process: Page.data.ProcessManager;
@@ -646,6 +617,23 @@ declare namespace Xrm
*/
export module Page
{
/**
* Requirement Level for Xrm.Page.Attribute.getRequiredLevel() and Xrm.Page.Attribute.setRequiredLevel().
*/
export type RequirementLevel = "none" | "recommended" | "required";
/**
* Save Modes for Xrm.Page.Entity.save().
*/
export type SaveMode = "saveandclose" | "saveandnew";
/**
* Status for Xrm.Page.Stage.getStatus().
*/
export type Status = "active" | "inactive";
/**
* Submit Mode for Xrm.Page.Attribute.getSubmitMode() and Xrm.Page.Attribute.setSubmitMode().
*/
export type SubmitMode = "always" | "dirty" | "never";
/**
* Interface for a CRM Business Process Flow instance.
*/
@@ -725,7 +713,7 @@ declare namespace Xrm
*
* @remarks This method will return either "active" or "inactive".
*/
getStatus(): string;
getStatus(): Status;
/**
* Returns a collection of steps in the stage.
@@ -798,7 +786,7 @@ declare namespace Xrm
*
* @return The event source.
*/
getEventSource(): Page.Attribute | Page.Entity;
getEventSource(): Attribute | Entity;
/**
* Gets the shared variable with the specified key.
@@ -912,12 +900,9 @@ declare namespace Xrm
text: string;
/**
* The value, as a string.
*
* @remarks You must use parseInt to convert this value to a number before you can use it to
* set the value of an OptionSetAttribute.
* The value, as a number
*/
value: string;
value: number;
}
/**
@@ -1024,7 +1009,7 @@ declare namespace Xrm
*
* @return The required level, as either "none", "required", or "recommended"
*/
getRequiredLevel(): string;
getRequiredLevel(): RequirementLevel;
/**
* Gets current submit mode for the attribute.
@@ -1033,7 +1018,7 @@ declare namespace Xrm
*
* @remarks The default value is "dirty"
*/
getSubmitMode(): string;
getSubmitMode(): SubmitMode;
/**
* Gets the current user's privileges for the attribute.
@@ -1049,54 +1034,12 @@ declare namespace Xrm
*/
removeOnChange( handler: ContextSensitiveHandler ): void;
/**
* Sets required level.
*
* @param {"none"} requirementLevel Not required.
*/
setRequiredLevel( requirementLevel: "none" ): void;
/**
* Sets required level.
*
* @param {"required"} requirementLevel Required.
*/
setRequiredLevel( requirementLevel: "required" ): void;
/**
* Sets required level.
*
* @param {"recommended"} requirementLevel Recommended.
*/
setRequiredLevel( requirementLevel: "recommended" ): void;
/**
* Sets the required level.
*
* @param {string} requirementLevel The requirement level, as either "none", "required", or "recommended"
*/
setRequiredLevel( requirementLevel: string ): void;
/**
* Sets submit mode.
*
* @param {"always"} submitMode Always submit this attribute.
*/
setSubmitMode( submitMode: "always" ): void;
/**
* Sets submit mode.
*
* @param {"never"} submitMode Never submit this attribute.
*/
setSubmitMode( submitMode: "never" ): void;
/**
* Sets submit mode.
*
* @param {"dirty"} submitMode Submit this attribute when changed.
*/
setSubmitMode( submitMode: "dirty" ): void;
setRequiredLevel(requirementLevel: RequirementLevel | string): void;
/**
* Sets the submit mode.
@@ -1105,7 +1048,7 @@ declare namespace Xrm
*
* @remarks The default value is "dirty"
*/
setSubmitMode( submitMode: string ): void;
setSubmitMode(submitMode: SubmitMode | string): void;
/**
* A collection of all the controls on the form that interface with this attribute.
@@ -1426,27 +1369,13 @@ declare namespace Xrm
*/
save(): void;
/**
* Saves the record with the given save mode.
*
* @param {"saveandclose"} saveMode Saves the record, and closes the form.
*/
save( saveMode: "saveandclose" ): void;
/**
* Saves the record with the given save mode.
*
* @param {"saveandnew"} saveMode Saves the record, and opens a blank form.
*/
save( saveMode: "saveandnew" ): void;
/**
* Saves the record with the given save mode.
*
* @param {string} saveMode (Optional) the save mode to save, as either "saveandclose" or
* "saveandnew".
*/
save( saveMode: string ): void;
save( saveMode: SaveMode | string): void;
/**
* The collection of attributes for the record.
@@ -1512,7 +1441,7 @@ declare namespace Xrm
/**
* Set a Process as the active process.
*
* @param {string} processId the Id of the process to make the active process.
* @param {string} processId The Id of the process to make the active process.
* @param {function} callbackFunction (Optional) a function to call when the operation is complete.
*/
setActiveProcess( processId: string, callbackFunction?: ProcessCallbackDelegate ): void;
@@ -1548,30 +1477,59 @@ declare namespace Xrm
* Use this method to asynchronously retrieve the enabled business process flows that the user can switch to for an
* entity.
*
* @param {Function} callbackFunction The callback function must accept a parameter
* that contains an object with dictionary
* properties where the name of the property is the
* Id of the business process flow and the value of
* the property is the name of the business process
* flow.
*
* The enabled processes are filtered according to
* the user’s privileges. The list of enabled
* processes is the same ones a user can see in the
* UI if they want to change the process manually.
* @param {Function} callbackFunction The callback function must accept a parameter that contains an object with
* dictionary properties where the name of the property is the Id of the
* business process flow and the value of the property is the name of the
* business process flow.
*
* The enabled processes are filtered according to the user’s privileges. The
* list of enabled processes is the same ones a user can see in the UI if they
* want to change the process manually.
*/
getEnabledProcesses( callbackFunction: ( enabledProcesses: ProcessDictionary ) => void ): void;
/**
* Use this method to get the currently selected stage.
*
* @return The currently selected stage.
*/
getSelectedStage(): Stage;
/**
* Use this to add a function as an event handler for the OnStageChange event so that it will be called when the
* business process flow stage changes.
*
* @param {ContextSensitiveHandler} handler The function will be added to the bottom of the event handler
* pipeline. The execution context is automatically set to be the first
* parameter passed to the event handler.
* @param {ContextSensitiveHandler} handler The function will be added to the bottom of the event
* handler pipeline. The execution context is automatically
* set to be the first parameter passed to the event handler.
*
* Use a reference to a named function rather than an
* anonymous function if you may later want to remove the
* event handler.
*/
addOnStageChange( handler: ContextSensitiveHandler ): void;
/**
* Use this to add a function as an event handler for the OnStageSelected event so that it will be called
* when a business process flow stage is selected.
*
* @param {ContextSensitiveHandler} handler The function will be added to the bottom of the event
* handler pipeline. The execution context is automatically
* set to be the first parameter passed to the event handler.
*
* Use a reference to a named function rather than an
* anonymous function if you may later want to remove the
* event handler.
*/
addOnStageSelected(handler: ContextSensitiveHandler): void;
/**
* Use this to remove a function as an event handler for the OnStageChange event.
*
* @param {ContextSensitiveHandler} handler If an anonymous function is set using the addOnStageChange method it
* cannot be removed using this method.
*/
removeOnStageChange(handler: ContextSensitiveHandler): void;
/**
* Use this to remove a function as an event handler for the OnStageChange event.
*
@@ -1621,7 +1579,7 @@ declare namespace Xrm
*
* @sa UiElement
*/
export interface Control extends UiElement
export interface Control extends UiElement, UiFocusable
{
/**
* Clears the notification identified by uniqueId.
@@ -2037,7 +1995,7 @@ declare namespace Xrm
*
* @return The display state, as either "expanded" or "collapsed"
*/
getDisplayState(): string;
getDisplayState(): ui.DisplayState;
/**
* Gets the name of the tab.
@@ -2053,26 +2011,12 @@ declare namespace Xrm
*/
getParent(): Ui;
/**
* Sets display state of the tab.
*
* @param {"collapsed"} displayState Collapsed tab.
*/
setDisplayState( displayState: "collapsed" ): void;
/**
* Sets display state of the tab.
*
* @param {"expanded"} displayState Expanded tab.
*/
setDisplayState( displayState: "expanded" ): void;
/**
* Sets display state of the tab.
*
* @param {string} displayState Display state of the tab, as either "expanded" or "collapsed"
*/
setDisplayState( displayState: string ): void;
setDisplayState(displayState: ui.DisplayState | string ): void;
/**
* A reference to the collection of form sections within this tab.
@@ -2112,31 +2056,27 @@ declare namespace Xrm
*/
export module ui
{
/**
* Form Notification Levels for Xrm.Ui.setFormNotification().
*/
export type FormNotificationLevel = "ERROR" | "INFO" | "WARNING";
/**
* Display States for Xrm.ui.ProcessMonitor.setDisplayState().
*/
export type DisplayState = "collapsed" | "expanded";
/**
* Interface for Xrm.Page.ui.process API
*/
export interface ProcessManager
{
/**
* Sets display state of the process flow control.
*
* @param {"collapsed"} displayState Collapsed process flow control.
*/
setDisplayState( displayState: "collapsed" ): void;
/**
* Sets display state of the process flow control.
*
* @param {"expanded"} displayState Expanded process flow control.
*/
setDisplayState( displayState: "expanded" ): void;
/**
* Sets display state of the process flow control.
*
* @param {string} displayState Display state of the process flow control, as either "expanded" or "collapsed"
*/
setDisplayState( displayState: string ): void;
setDisplayState(displayState: ui.DisplayState ): void;
/**
* Sets the visibility state.
@@ -2362,6 +2302,19 @@ declare namespace Xrm
*/
export module Url
{
/**
* Command Bar Display options for Xrm.Url.FormOpenParameters.cmdbar, Xrm.Url.ViewOpenParameters.cmdbar, and Xrm.Utility.FormOpenParameters.cmdbar.
*/
export type CmdBarDisplay = "true" | "false";
/**
* Navigation Bar Display options for Xrm.Url.FormOpenParameters.navbar, Xrm.Url.ViewOpenParameters.navbar, and Xrm.Utility.FormOpenParameters.navbar.
*/
export type NavBarDisplay = "entity" | "off" | "on";
/**
* Report Open Action options for Xrm.Url.ReportOpenParameters.actions.
*/
export type ReportAction = "filter" | "run";
/**
* Interface for defining parameters on a request to open a form with main.aspx (as with
* window.open). Useful for parsing the keys and values into a string of the format:
@@ -2393,7 +2346,7 @@ declare namespace Xrm
* Accepted values are: "true" (The command bar is displayed.)
* "false" (The command bar is not displayed.)
*/
cmdbar?: string;
cmdbar?: CmdBarDisplay;
/**
* Controls whether the Navigation bar is displayed on the form.
@@ -2402,7 +2355,7 @@ declare namespace Xrm
* "entity" (On an entity form, only the navigation options for related
* entities are available.)
*/
navbar?: string;
navbar?: NavBarDisplay;
}
/**
@@ -2441,7 +2394,7 @@ declare namespace Xrm
* Accepted values are: "true" (The command bar is displayed.)
* "false" (The command bar is not displayed.)
*/
cmdbar?: string;
cmdbar?: CmdBarDisplay;
/**
* Controls whether the Navigation bar is displayed on the form.
@@ -2450,7 +2403,7 @@ declare namespace Xrm
* "entity" (On an entity form, only the navigation options for related
* entities are available.)
*/
navbar?: string;
navbar?: NavBarDisplay;
}
/**
@@ -2494,7 +2447,7 @@ declare namespace Xrm
* @remarks "run" Executes the report with default filters.
* "filter" Presents the user with the filter editor, and a "Run Report" button.
*/
action: string;
action: ReportAction;
/**
* The file name of the report. For out-of-box reports, this parameter enables context-sensitive
@@ -2544,14 +2497,14 @@ declare namespace Xrm
* "entity" (On an entity form, only the navigation options for related
* entities are available.)
*/
navbar?: string;
navbar?: Url.NavBarDisplay;
/**
* Controls whether the command bar is displayed.
* Accepted values are: "true" (The command bar is displayed.)
* "false" (The command bar is not displayed.)
*/
cmdbar?: string;
cmdbar?: Url.CmdBarDisplay;
}
/**
@@ -2634,4 +2587,4 @@ declare namespace XrmEnum
SystemView = 1039,
UserView = 4230
}
}
}