diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 9cc1579e0..7d495dca8 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -5,6 +5,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](acc-wizard/acc-wizard.d.ts) [acc-wizard](https://github.com/sathomas/acc-wizard) by [Cyril Schumacher](https://github.com/cyrilschumacher) * [:link:](accounting/accounting.d.ts) [accounting.js](http://josscrowcroft.github.io/accounting.js) by [Sergey Gerasimov](https://github.com/gerich-home) * [:link:](ace/ace.d.ts) [Ace Ajax.org Cloud9 Editor](http://ace.ajax.org) by [Diullei Gomes](https://github.com/Diullei) +* [:link:](acorn/acorn.d.ts) [Acorn](https://github.com/marijnh/acorn) by [RReverser](https://github.com/RReverser) * [:link:](add2home/add2home.d.ts) [add2home](http://cubiq.org/add-to-home-screen) by [James Wilkins](http://www.codeplex.com/site/users/view/jamesnw) * [:link:](adm-zip/adm-zip.d.ts) [adm-zip](https://github.com/cthackers/adm-zip) by [John Vilk](https://github.com/jvilk) * [:link:](alertify/alertify.d.ts) [alertify](http://fabien-d.github.io/alertify.js) by [John Jeffery](http://github.com/jjeffery) @@ -195,7 +196,8 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](errorhandler/errorhandler.d.ts) [errorhandler](https://github.com/expressjs/errorhandler) by [Santi Albo](https://github.com/santialbo) * [:link:](es6-promise/es6-promise.d.ts) [es6-promise](https://github.com/jakearchibald/ES6-Promise) by [François de Campredon](https://github.com/fdecampredon), [vvakame](https://github.com/vvakame) * [:link:](escape-latex/escape-latex.d.ts) [escape-latex](https://github.com/dangmai/escape-latex) by [Oliver Schneider](https://github.com/olsio) -* [:link:](esprima/esprima.d.ts) [Esprima](http://esprima.org) by [teppeis](https://github.com/teppeis) +* [:link:](esprima/esprima.d.ts) [Esprima](http://esprima.org) by [teppeis](https://github.com/teppeis), [RReverser](https://github.com/RReverser) +* [:link:](estree/estree.d.ts) [ESTree AST specification](https://github.com/estree/estree) by [RReverser](https://github.com/RReverser) * [:link:](event-loop-lag/event-loop-lag.d.ts) [event-loop-lag](https://github.com/pebble/event-loop-lag) by [Rogier Schouten](https://github.com/rogierschouten) * [:link:](eventemitter2/eventemitter2.d.ts) [EventEmitter2](https://github.com/asyncly/EventEmitter2) by [ryiwamoto](https://github.com/ryiwamoto) * [:link:](eventemitter3/eventemitter3.d.ts) [EventEmitter3](https://github.com/primus/eventemitter3) by [Yuichi Murata](https://github.com/mrk21) @@ -277,9 +279,9 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](greensock/greensock.d.ts) [GreenSock Animation Platform](http://www.greensock.com/get-started-js) by [Robert S](https://github.com/codebelt) * [:link:](gridfs-stream/gridfs-stream.d.ts) [gridfs-stream](https://github.com/aheckmann/gridfs-stream) by [Lior Mualem](https://github.com/liorm) * [:link:](gruntjs/gruntjs.d.ts) [Grunt 0.4.x](http://gruntjs.com) by [Jeff May](https://github.com/jeffmay), [Basarat Ali Syed](https://github.com/basarat) -* [:link:](gsap/Core.d.ts) [GSAP](http://greensock.com) by [VILIC VANE](https://vilic.github.io) * [:link:](gsap/TweenLite.d.ts) [GSAP](http://greensock.com) by [VILIC VANE](https://vilic.github.io) * [:link:](gsap/Ease.d.ts) [GSAP](http://greensock.com) by [VILIC VANE](https://vilic.github.io) +* [:link:](gsap/Core.d.ts) [GSAP](http://greensock.com) by [VILIC VANE](https://vilic.github.io) * [:link:](gulp/gulp.d.ts) [Gulp v3.8.x](http://gulpjs.com) by [Drew Noakes](https://drewnoakes.com) * [:link:](gulp-autoprefixer/gulp-autoprefixer.d.ts) [gulp-autoprefixer](https://github.com/sindresorhus/gulp-autoprefixer) by [Asana](https://asana.com) * [:link:](gulp-concat/gulp-concat.d.ts) [gulp-concat](http://github.com/wearefractal/gulp-concat) by [Keita Kagurazaka](https://github.com/k-kagurazaka) @@ -596,9 +598,9 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](xml2js/xml2js.d.ts) [node-xml2js](https://github.com/Leonidas-from-XIV/node-xml2js) by [Michel Salib](https://github.com/michelsalib), [Jason McNeil](https://github.com/jasonrm) * [:link:](node/node.d.ts) [Node.js](http://nodejs.org) by [Microsoft TypeScript](http://typescriptlang.org), [DefinitelyTyped](https://github.com/borisyankov/DefinitelyTyped) * [:link:](restify/restify.d.ts) [node.js REST framework](https://github.com/mcavage/node-restify) by [Bret Little](https://github.com/blittle) -* [:link:](acl/acl-redisBackend.d.ts) [node_acl](https://github.com/optimalbits/node_acl) by [Qubo](https://github.com/tkQubo) -* [:link:](acl/acl-mongodbBackend.d.ts) [node_acl](https://github.com/optimalbits/node_acl) by [Qubo](https://github.com/tkQubo) * [:link:](acl/acl.d.ts) [node_acl](https://github.com/optimalbits/node_acl) by [Qubo](https://github.com/tkQubo) +* [:link:](acl/acl-mongodbBackend.d.ts) [node_acl](https://github.com/optimalbits/node_acl) by [Qubo](https://github.com/tkQubo) +* [:link:](acl/acl-redisBackend.d.ts) [node_acl](https://github.com/optimalbits/node_acl) by [Qubo](https://github.com/tkQubo) * [:link:](mdns/mdns.d.ts) [node_mdns](https://github.com/agnat/node_mdns) by [Stefan Steinhart](https://github.com/reppners) * [:link:](node_redis/node_redis.d.ts) [node_redis](https://github.com/mranney/node_redis) by [Boris Yankov](https://github.com/borisyankov) * [:link:](each/each.d.ts) [NodeEach](http://www.adaltas.com/projects/node-each) by [Michael Zabka](https://github.com/misak113) @@ -608,8 +610,8 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](nopt/nopt.d.ts) [nopt](https://github.com/npm/nopt) by [jbondc](https://github.com/jbondc) * [:link:](notifyjs/notifyjs.d.ts) [notify.js](https://github.com/alexgibson/notify.js) by [soundTricker](https://github.com/soundTricker) * [:link:](notify/notify.d.ts) [Notify.js](https://github.com/jpillora/notifyjs) by [Xiaohan Zhang](https://github.com/hellochar) -* [:link:](nouislider/nouislider.d.ts) [nouislider](https://github.com/leongersen/noUiSlider) by [Corey Jepperson](https://github.com/acoreyj) * [:link:](wnumb/wnumb.d.ts) [nouislider](https://github.com/leongersen/wnumb) by [Corey Jepperson](https://github.com/acoreyj) +* [:link:](nouislider/nouislider.d.ts) [nouislider](https://github.com/leongersen/noUiSlider) by [Corey Jepperson](https://github.com/acoreyj) * [:link:](noVNC/noVNC.d.ts) [noVNC](https://github.com/kanaka/noVNC) by [Ken Smith](https://github.com/smithkl42) * [:link:](npm/npm.d.ts) [npm](https://github.com/npm/npm) by [Maxime LUCE](https://github.com/SomaticIT) * [:link:](nprogress/NProgress.d.ts) [NProgress](https://github.com/rstacruz/nprogress) by [Judah Gabriel Himango](http://debuggerdotbreak.wordpress.com) @@ -656,9 +658,9 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](poly2tri/poly2tri.d.ts) [poly2tri](http://github.com/r3mi/poly2tri.js) by [Elemar Junior](https://github.com/elemarjr) * [:link:](polymer/polymer.d.ts) [polymer](https://github.com/polymer) by [Louis Grignon](https://github.com/lgrignon) * [:link:](polymer/polymer.paper-dialog.d.ts) [polymer's paper-dialog](https://github.com/Polymer/paper-dialog) by [Louis Grignon](https://github.com/lgrignon) -* [:link:](polymer/polymer.core-drawer-panel.d.ts) [polymer's paper-toast](https://github.com/Polymer/core-drawer-panel) by [Louis Grignon](https://github.com/lgrignon) * [:link:](polymer/polymer.core-overlay.d.ts) [polymer's paper-toast](https://github.com/Polymer/core-selector) by [Louis Grignon](https://github.com/lgrignon) * [:link:](polymer/polymer.paper-toast.d.ts) [polymer's paper-toast](https://github.com/Polymer/paper-toast) by [Louis Grignon](https://github.com/lgrignon) +* [:link:](polymer/polymer.core-drawer-panel.d.ts) [polymer's paper-toast](https://github.com/Polymer/core-drawer-panel) by [Louis Grignon](https://github.com/lgrignon) * [:link:](polymer/polymer.core-selector.d.ts) [polymer's paper-toast](https://github.com/Polymer/core-selector) by [Louis Grignon](https://github.com/lgrignon) * [:link:](popcorn/popcorn.d.ts) [Popcorn](https://github.com/mozilla/popcorn-js) by [grapswiz](https://github.com/grapswiz) * [:link:](pouchDB/pouch.d.ts) [Pouch](http://pouchdb.com) by [Bill Sears](https://github.com/MrBigDog2U) diff --git a/acorn/acorn-tests.ts b/acorn/acorn-tests.ts new file mode 100644 index 000000000..1c5cf27ba --- /dev/null +++ b/acorn/acorn-tests.ts @@ -0,0 +1,30 @@ +/// +/// + +import acorn = require('acorn'); + +var token: acorn.Token; +var tokens: acorn.Token[]; +var comment: acorn.Comment; +var comments: acorn.Comment[]; +var program: ESTree.Program; +var any: any; +var string: string; + +// acorn +string = acorn.version; +program = acorn.parse('code'); +program = acorn.parse('code', {range: true, onToken: tokens, onComment: comments}); +program = acorn.parse('code', { + ranges: true, + onToken: (token) => tokens.push(token), + onComment: (isBlock, text, start, end) => { } +}); + +// Token +token = tokens[0]; +string = token.type.label; +any = token.value; + +// Comment +string = comment.value; diff --git a/acorn/acorn.d.ts b/acorn/acorn.d.ts new file mode 100644 index 000000000..eaba47e3b --- /dev/null +++ b/acorn/acorn.d.ts @@ -0,0 +1,67 @@ +// Type definitions for Acorn v1.0.1 +// Project: https://github.com/marijnh/acorn +// Definitions by: RReverser +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module acorn { + var version: string; + function parse(input: string, options?: Options): ESTree.Program; + function parseExpressionAt(input: string, pos: number, options?: Options): ESTree.Expression; + var defaultOptions: Options; + + interface TokenType { + label: string; + keyword: string; + beforeExpr: boolean; + startsExpr: boolean; + isLoop: boolean; + isAssign: boolean; + prefix: boolean; + postfix: boolean; + binop: number; + updateContext: (prevType: TokenType) => any; + } + + interface AbstractToken { + start: number; + end: number; + loc: ESTree.SourceLocation; + range: [number, number]; + } + + interface Token extends AbstractToken { + type: TokenType; + value: any; + } + + interface Comment extends AbstractToken { + type: string; + value: string; + } + + interface Options { + ecmaVersion?: number; + sourceType?: string; + onInsertedSemicolon?: (lastTokEnd: number, lastTokEndLoc?: ESTree.Position) => any; + onTrailingComma?: (lastTokEnd: number, lastTokEndLoc?: ESTree.Position) => any; + allowReserved?: boolean; + allowReturnOutsideFunction?: boolean; + allowImportExportEverywhere?: boolean; + allowHashBang?: boolean; + locations?: boolean; + onToken?: ((token: Token) => any) | Token[]; + onComment?: ((isBlock: boolean, text: string, start: number, end: number, startLoc?: ESTree.Position, endLoc?: ESTree.Position) => any) | Comment[]; + ranges?: boolean; + program?: ESTree.Program; + sourceFile?: string; + directSourceFile?: string; + preserveParens?: boolean; + plugins?: { [name: string]: Function; }; + } +} + +declare module "acorn" { + export = acorn +} diff --git a/angular-material/angular-material.d.ts b/angular-material/angular-material.d.ts index cf7a20d79..1e3eda18a 100644 --- a/angular-material/angular-material.d.ts +++ b/angular-material/angular-material.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Angular Material 0.8.3+ (ng.material module) +// Type definitions for Angular Material 0.8.3+ (angular.material module) // Project: https://github.com/angular/material // Definitions by: Matt Traynham // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -12,14 +12,14 @@ declare module angular.material { controller?: any; locals?: {[index: string]: any}; targetEvent?: any; - resolve?: {[index: string]: ng.IPromise} + resolve?: {[index: string]: angular.IPromise} controllerAs?: string; parent?: Element; disableParentScroll?: boolean; } interface MDBottomSheetService { - show(options: MDBottomSheetOptions): ng.IPromise; + show(options: MDBottomSheetOptions): angular.IPromise; hide(response?: any): void; cancel(response?: any): void; } @@ -49,14 +49,14 @@ declare module angular.material { controller?: any; locals?: {[index: string]: any}; bindToController?: boolean; - resolve?: {[index: string]: ng.IPromise} + resolve?: {[index: string]: angular.IPromise} controllerAs?: string; parent?: Element; onComplete?: Function; } interface MDDialogService { - show(dialog: MDDialogOptions|MDPresetDialog): ng.IPromise; + show(dialog: MDDialogOptions|MDPresetDialog): angular.IPromise; confirm(): MDConfirmDialog; alert(): MDAlertDialog; hide(response?: any): void; @@ -64,7 +64,7 @@ declare module angular.material { } interface MDIcon { - (path: string): ng.IPromise; + (path: string): angular.IPromise; } interface MDIconProvider { @@ -110,14 +110,14 @@ declare module angular.material { controller?: any; locals?: {[index: string]: any}; bindToController?: boolean; - resolve?: {[index: string]: ng.IPromise} + resolve?: {[index: string]: angular.IPromise} controllerAs?: string; parent?: Element; } interface MDToastService { - show(optionsOrPreset: MDToastOptions|MDToastPreset): ng.IPromise; - showSimple(): ng.IPromise; + show(optionsOrPreset: MDToastOptions|MDToastPreset): angular.IPromise; + showSimple(): angular.IPromise; simple(): MDSimpleToastPreset; build(): MDToastPreset; updateContent(): void; diff --git a/angular-ui-router/angular-ui-router.d.ts b/angular-ui-router/angular-ui-router.d.ts index 0cf796832..f5dfbeca5 100644 --- a/angular-ui-router/angular-ui-router.d.ts +++ b/angular-ui-router/angular-ui-router.d.ts @@ -62,7 +62,7 @@ declare module angular.ui { reloadOnSearch?: boolean; } - interface IStateProvider extends IServiceProvider { + interface IStateProvider extends ng.IServiceProvider { state(name:string, config:IState): IStateProvider; state(config:IState): IStateProvider; decorator(name?: string, decorator?: (state: IState, parent: Function) => any): any; @@ -81,7 +81,7 @@ declare module angular.ui { type(name: string, definition: any, definitionFn?: any): any; } - interface IUrlRouterProvider extends IServiceProvider { + interface IUrlRouterProvider extends ng.IServiceProvider { when(whenPath: RegExp, handler: Function): IUrlRouterProvider; when(whenPath: RegExp, handler: any[]): IUrlRouterProvider; when(whenPath: RegExp, toPath: string): IUrlRouterProvider; @@ -143,7 +143,7 @@ declare module angular.ui { * * @param options Options object. */ - go(to: string, params?: {}, options?: IStateOptions): IPromise; + go(to: string, params?: {}, options?: IStateOptions): ng.IPromise; transitionTo(state: string, params?: {}, updateLocation?: boolean): void; transitionTo(state: string, params?: {}, options?: IStateOptions): void; includes(state: string, params?: {}): boolean; diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index 834ebc831..7de8eb807 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -238,7 +238,7 @@ declare module Backbone { initial(n: number): TModel[]; inject(iterator: (memo: any, element: TModel, index: number) => any, initialMemo: any, context?: any): any; isEmpty(object: any): boolean; - invoke(methodName: string, arguments?: any[]): any; + invoke(methodName: string, args?: any[]): any; last(): TModel; last(n: number): TModel[]; lastIndexOf(element: TModel, fromIndex?: number): number; diff --git a/breeze/breeze-tests.ts b/breeze/breeze-tests.ts index 979bc5683..f309462af 100644 --- a/breeze/breeze-tests.ts +++ b/breeze/breeze-tests.ts @@ -3,7 +3,6 @@ import core = breeze.core; import config = breeze.config; - function test_dataType() { var typ = breeze.DataType.DateTime; var nm = typ.getName(); @@ -888,4 +887,4 @@ function test_config() { config.registerType(f1, "myCtor"); s = config.stringifyPad; o = config.typeRegistry; -} \ No newline at end of file +} diff --git a/chartjs/chart.d.ts b/chartjs/chart.d.ts index a73ecc94e..d85f9b476 100644 --- a/chartjs/chart.d.ts +++ b/chartjs/chart.d.ts @@ -115,6 +115,7 @@ interface CircularInstance extends ChartInstance { update: () => void; addData: (valuesArray: CircularChartData[], index: number) => void; removeData: (index: number) => void; + segments: Array; } interface LineChartOptions extends ChartOptions { diff --git a/chosen/chosen.jquery.d.ts b/chosen/chosen.jquery.d.ts index 890b4221e..1c9507339 100644 --- a/chosen/chosen.jquery.d.ts +++ b/chosen/chosen.jquery.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Chosen.JQuery 0.9 +// Type definitions for Chosen.JQuery 1.4.2 // Project: http://harvesthq.github.com/chosen/ // Definitions by: Boris Yankov // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -8,18 +8,23 @@ interface ChosenOptions { allow_single_deselect?: boolean; - disable_search_threshold?: number; disable_search?: boolean; + disable_search_threshold?: number; + enable_split_word_search?: boolean; + inherit_select_classes?: boolean; + max_selected_options?: number; + no_results_text?: string; + placeholder_text_multiple?: string; + placeholder_text_single?: string; search_contains?: boolean; single_backstroke_delete?: boolean; - max_selected_options?: number; - placeholder_text_multiple?: string; - placeholder_text?: string; - placeholder_text_single?: string; - no_results_text?: string; + width?: number; + display_disabled_options?: boolean; + display_selected_options?: boolean; + include_group_label_in_selected?: boolean; } interface JQuery { chosen(): JQuery; chosen(options: ChosenOptions): JQuery; -} \ No newline at end of file +} diff --git a/circular-json/circular-json-tests.ts b/circular-json/circular-json-tests.ts new file mode 100644 index 000000000..d3f2e0951 --- /dev/null +++ b/circular-json/circular-json-tests.ts @@ -0,0 +1,31 @@ +/// + +import CircularJSON = require('circular-json'); + +var replacer = (key: any, val: any) => { + return val; +} + +var replacerArray = ['a', 'x']; + +// implements JSON interface +var json_obj: JSON = CircularJSON; + +CircularJSON.parse('{"a":"b"}'); + +CircularJSON.parse('{"a":"b"}', replacer); + +// just stringify a value +CircularJSON.stringify({a: 'b'}); + +// do replacements for part of the object +CircularJSON.stringify({a: 'b'}, replacer); +CircularJSON.stringify({a: 'b'}, replacerArray); + +// add whitespace to the output +CircularJSON.stringify({a: 'b'}, replacer, 5); +CircularJSON.stringify({a: 'b'}, replacerArray, 5); + +// do not actually set up a re-parseable object +CircularJSON.stringify({a: 'b'}, replacer, 5, true); +CircularJSON.stringify({a: 'b'}, replacerArray, 5, true); diff --git a/circular-json/circular-json.d.ts b/circular-json/circular-json.d.ts new file mode 100644 index 000000000..2aa27e947 --- /dev/null +++ b/circular-json/circular-json.d.ts @@ -0,0 +1,15 @@ +// Type definitions for circular-json v0.1.6 +// Project: https://github.com/WebReflection/circular-json +// Definitions by: Jonathan Pevarnek +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module 'circular-json' { + interface ICircularJSON extends JSON { + parse(text: string, reviver?: (key: any, value: any) => any): any; + stringify(value: any, replacer?: ((key: string, value: any) => any) | any[], space?: any, placeholder?: boolean): string; + } + + var CircularJSON: ICircularJSON; + + export = CircularJSON; +} diff --git a/ember/ember.d.ts b/ember/ember.d.ts index 22cbb8ab5..636a7af68 100644 --- a/ember/ember.d.ts +++ b/ember/ember.d.ts @@ -444,7 +444,7 @@ declare module Ember { static metaForProperty(key: string): {}; static isClass: boolean; static isMethod: boolean; - static initializer(arguments?: ApplicationInitializerArguments): void; + static initializer(args?: ApplicationInitializerArguments): void; /** Call advanceReadiness after any asynchronous setup logic has completed. Each call to deferReadiness must be matched by a call to advanceReadiness @@ -1318,9 +1318,9 @@ declare module Ember { Creates an instance of the class. @param arguments A hash containing values with which to initialize the newly instantiated object. **/ - static create(arguments?: {}): T; + static create(args: {}): T; detect(obj: any): boolean; - reopen(arguments?: {}): T; + reopen(args?: {}): T; } class MutableArray implements Array, MutableEnumberable { addArrayObserver(target: any, opts?: EnumerableConfigurationOptions): any[]; @@ -1581,17 +1581,17 @@ declare module Ember { /** Creates a subclass of the Object class. **/ - static extend(arguments?: CoreObjectArguments): T; - static extend(mixins? : Mixin, arguments?: CoreObjectArguments): T; + static extend(args?: CoreObjectArguments): T; + static extend(mixins? : Mixin, args?: CoreObjectArguments): T; /** Creates an instance of the class. @param arguments A hash containing values with which to initialize the newly instantiated object. **/ - static create(arguments?: {}): T; + static create(args?: {}): T; /** Equivalent to doing extend(arguments).create(). If possible use the normal create method instead. **/ - static createWithMixins(arguments?: {}): T; + static createWithMixins(args?: {}): T; static detect(obj: any): boolean; static detectInstance(obj: any): boolean; /** @@ -1608,13 +1608,13 @@ declare module Ember { Augments a constructor's prototype with additional properties and functions. To add functions and properties to the constructor itself, see reopenClass. **/ - static reopen(arguments?: {}): T; + static reopen(args?: {}): T; /** Augments a constructor's own properties and functions. To add functions and properties to instances of a constructor by extending the constructor's prototype see reopen. **/ - static reopenClass(arguments?: {}): T; + static reopenClass(args?: {}): T; static isClass: boolean; static isMethod: boolean; addObserver: ModifyObserver; diff --git a/esprima/esprima-tests.ts b/esprima/esprima-tests.ts index d2635a404..f1a0f7ad9 100644 --- a/esprima/esprima-tests.ts +++ b/esprima/esprima-tests.ts @@ -1,27 +1,12 @@ +/// /// import esprima = require('esprima'); -import Syntax = esprima.Syntax; var token: esprima.Token; -var options: esprima.Options; -var comment: Syntax.Comment; -var program: Syntax.Program; -var statement: Syntax.Statement; -var expression: Syntax.Expression; -var property: Syntax.Property; -var identifier: Syntax.Identifier; -var literal: Syntax.Literal; -var switchCase: Syntax.SwitchCase; -var catchClause: Syntax.CatchClause; -var variableDeclaratorOrExpression: Syntax.VariableDeclaratorOrExpression; -var literalOrIdentifier: Syntax.LiteralOrIdentifier; -var blockStatementOrExpression: Syntax.BlockStatementOrExpression; -var identifierOrExpression: Syntax.IdentifierOrExpression; -var any: any; +var comment: esprima.Comment; +var program: ESTree.Program; var string: string; -var boolean: boolean; -var number: number; // esprima string = esprima.version; @@ -34,171 +19,5 @@ token = esprima.tokenize('code', {range: true})[0]; string = token.type; string = token.value; -// Program -string = program.type; -statement = program.body[0]; -comment = program.comments[0] - -// Location -number = program.loc.start.line; -number = program.loc.start.column; -number = program.loc.end.line; -number = program.loc.end.column; -number = program.range[0]; - // Comment string = comment.value; - -// Statement -// BlockStatement -var blockStatement: Syntax.BlockStatement; -string = blockStatement.type; -statement = blockStatement.body[0]; -comment = blockStatement.leadingComments[0]; -comment = blockStatement.trailingComments[0]; - -// ExpressionStatement -var expressionStatement: Syntax.ExpressionStatement; -expression = expressionStatement.expression; - -// IfStatement -var ifStatement: Syntax.IfStatement; -expression = ifStatement.test; -statement = ifStatement.consequent; -statement = ifStatement.alternate; - -// LabeledStatement -var labeledStatement: Syntax.LabeledStatement; -identifier = labeledStatement.label; -statement = labeledStatement.body; - -// WithStatement -var withStatement: Syntax.WithStatement; -expression = withStatement.object; - -// SwitchStatement -var switchStatement: Syntax.SwitchStatement; -expression = switchStatement.discriminant; -switchCase = switchStatement.cases[0]; -boolean = switchStatement.lexical; - -// ReturnStatement -var returnStatement: Syntax.ReturnStatement; -expression = returnStatement.argument; - -// TryStatement -var tryStatement: Syntax.TryStatement; -blockStatement = tryStatement.block; -catchClause = tryStatement.handler; -catchClause = tryStatement.guardedHandlers[0]; -blockStatement = tryStatement.finalizer; - -// ForStatement -var forStatement: Syntax.ForStatement; -variableDeclaratorOrExpression = forStatement.init; -expression = forStatement.update; - -// ForInStatement -var forInStatement: Syntax.ForInStatement; -variableDeclaratorOrExpression = forInStatement.left; -expression = forInStatement.right; -boolean = forInStatement.each; - -// Expression -// ArrayExpression -var arrayExpression: Syntax.ArrayExpression; -string = arrayExpression.type; -expression = arrayExpression.elements[0]; - -// ObjectExpression -var objectExpression: Syntax.ObjectExpression; -property = objectExpression.properties[0]; -string = property.type; -literalOrIdentifier = property.key; -expression = property.value; -string = property.kind; - -// FunctionExpression -var functionExpression: Syntax.FunctionExpression; -identifier = functionExpression.id; -identifier = functionExpression.params[0]; -expression = functionExpression.defaults[0]; -identifier = functionExpression.rest; -blockStatementOrExpression = functionExpression.body; -boolean = functionExpression.generator; -boolean = functionExpression.expression; - -// SequenceExpression -var sequenceExpression: Syntax.SequenceExpression; -expression = sequenceExpression.expressions[0] - -// UnaryExpression -var unaryExpression: Syntax.UnaryExpression; -string = unaryExpression.operator; -boolean = unaryExpression.prefix; - -// BinaryExpression -var binaryExpression: Syntax.BinaryExpression; -expression = binaryExpression.left; -expression = binaryExpression.right; - -// ConditionalExpression -var conditionalExpression: Syntax.ConditionalExpression; -expression = conditionalExpression.test; -expression = conditionalExpression.alternate; -expression = conditionalExpression.consequent; - -// NewExpression -var newExpression: Syntax.NewExpression; -expression = newExpression.callee; -expression = newExpression.arguments[0]; - -// CallExpression -var callExpression: Syntax.CallExpression; -expression = callExpression.callee; -expression = callExpression.arguments[0]; - -// MemberExpression -var memberExpression: Syntax.MemberExpression; -expression = memberExpression.object; -identifierOrExpression = memberExpression.property; -boolean = memberExpression.computed; - -// Declarations -var functionDeclaration: Syntax.FunctionDeclaration; -identifier = functionDeclaration.id; -var params:Syntax.Identifier[] = functionDeclaration.params; -var defaults:Syntax.Expression[] = functionDeclaration.defaults; -identifier = functionDeclaration.rest; -var body:Syntax.BlockStatementOrExpression = functionDeclaration.body; -boolean = functionDeclaration.generator; -boolean = functionDeclaration.expression; - -var variableDeclaration: Syntax.VariableDeclaration; -var declarations:Syntax.VariableDeclarator[] = variableDeclaration.declarations; -string = variableDeclaration.kind; // "var" | "let" | "const" - -var variableDeclarator: Syntax.VariableDeclarator; -identifier = variableDeclarator.id; // Pattern -expression = variableDeclarator.init; - -// Clauses -// SwitchCase -string = switchCase.type; -expression = switchCase.test; -statement = switchCase.consequent[0]; - -// CatchClause -string = catchClause.type; -identifier = catchClause.param; -expression = catchClause.guard; -blockStatement = catchClause.body; - -// Misc -// Identifier -string = identifier.type; -string = identifier.name; - -// Literal -string = literal.type; -any = literal.value; diff --git a/esprima/esprima.d.ts b/esprima/esprima.d.ts index d62bb09bb..10e37a530 100644 --- a/esprima/esprima.d.ts +++ b/esprima/esprima.d.ts @@ -1,18 +1,24 @@ -// Type definitions for Esprima v1.2.0 +// Type definitions for Esprima v2.1.0 // Project: http://esprima.org -// Definitions by: teppeis +// Definitions by: teppeis , RReverser // Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + declare module esprima { - var version: string; - function parse(code: string, options?: Options): Syntax.Program; - function tokenize(code: string, options?: Options): Array; + var version: string + function parse(code: string, options?: Options): ESTree.Program + function tokenize(code: string, options?: Options): Array interface Token { type: string value: string } + interface Comment extends ESTree.Node { + value: string + } + interface Options { loc?: boolean range?: boolean @@ -23,244 +29,6 @@ declare module esprima { tolerant?: boolean source?: boolean } - - module Syntax { - // Node - interface Node { - type: string - loc?: LineLocation - range?: number[] - leadingComments?: Comment[] - trailingComments?: Comment[] - } - interface LineLocation { - start: Position - end: Position - } - interface Position { - line: number - column: number - } - - // Comment - interface Comment extends Node { - value: string - } - - // Program - interface Program extends Node { - body: Statement[] - comments?: Comment[] - } - - // Function - interface Function extends Node { - id: Identifier // | null - params: Identifier[] - defaults: Expression[] - rest: Identifier // | null - body: BlockStatementOrExpression - generator: boolean - expression: boolean - } - interface BlockStatementOrExpression extends BlockStatement, Expression { - } - - // Statement - interface Statement extends Node { - } - interface EmptyStatement extends Statement { - } - interface BlockStatement extends Statement { - body: Statement[] - } - interface ExpressionStatement extends Statement { - expression: Expression - } - interface IfStatement extends Statement { - test: Expression - consequent: Statement - alternate: Statement - } - interface LabeledStatement extends Statement { - label: Identifier - body: Statement - } - interface BreakStatement extends Statement { - label: Identifier // | null - } - interface ContinueStatement extends Statement { - label: Identifier // | null - } - interface WithStatement extends Statement { - object: Expression - body: Statement - } - interface SwitchStatement extends Statement { - discriminant: Expression - cases: SwitchCase[] - lexical: boolean - } - interface ReturnStatement extends Statement { - argument: Expression // | null - } - interface ThrowStatement extends Statement { - argument: Expression - } - interface TryStatement extends Statement { - block: BlockStatement - handler: CatchClause // | null - guardedHandlers: CatchClause[] - finalizer: BlockStatement // | null - } - interface WhileStatement extends Statement { - test: Expression - body: Statement - } - interface DoWhileStatement extends Statement { - body: Statement - test: Expression - } - interface ForStatement extends Statement { - init: VariableDeclaratorOrExpression // | null - test: Expression // | null - update: Expression // | null - body: Statement - } - interface ForInStatement extends Statement { - left: VariableDeclaratorOrExpression - right: Expression - body: Statement - each: boolean - } - interface VariableDeclaratorOrExpression extends VariableDeclarator, Expression { - } - interface DebuggerStatement extends Statement { - } - interface StatementOrList extends Array, Statement { - } - - // Declaration - interface Declaration extends Statement { - } - interface FunctionDeclaration extends Declaration { - id: Identifier - params: Identifier[] // Pattern - defaults: Expression[] - rest: Identifier - body: BlockStatementOrExpression - generator: boolean - expression: boolean - } - interface VariableDeclaration extends Declaration { - declarations: VariableDeclarator[] - kind: string // "var" | "let" | "const" - } - interface VariableDeclarator extends Node { - id: Identifier // Pattern - init: Expression - } - - // Expression - interface Expression extends Node { // | Pattern - } - //interface Expression extends - // ThisExpression, ArrayExpression, ObjectExpression, FunctionExpression, - // ArrowFunctionExpression, SequenceExpression, UnaryExpression, BinaryExpression, - // AssignmentExpression, UpdateExpression, LogicalExpression, ConditionalExpression, - // NewExpression, CallExpression, MemberExpression { - //} - interface ThisExpression extends Expression { - } - interface ArrayExpression extends Expression { - elements: Expression[] // [ Expression | null ] - } - interface ObjectExpression extends Expression { - properties: Property[] - } - interface Property extends Node { - key: LiteralOrIdentifier // Literal | Identifier - value: Expression - kind: string // "init" | "get" | "set" - } - interface LiteralOrIdentifier extends Literal, Identifier { - } - interface FunctionExpression extends Function, Expression { - } - interface ArrowFunctionExpression extends Function, Expression { - } - interface SequenceExpression extends Expression { - expressions: Expression[] - } - interface UnaryExpression extends Expression { - operator: string // UnaryOperator - prefix: boolean - argument: Expression - } - interface BinaryExpression extends Expression { - operator: string // BinaryOperator - left: Expression - right: Expression - } - interface AssignmentExpression extends Expression { - operator: string // AssignmentOperator - left: Expression - right: Expression - } - interface UpdateExpression extends Expression { - operator: string // UpdateOperator - argument: Expression - prefix: boolean - } - interface LogicalExpression extends Expression { - operator: string // LogicalOperator - left: Expression - right: Expression - } - interface ConditionalExpression extends Expression { - test: Expression - alternate: Expression - consequent: Expression - } - interface NewExpression extends Expression { - callee: Expression - arguments: Expression[] - } - interface CallExpression extends Expression { - callee: Expression - arguments: Expression[] - } - interface MemberExpression extends Expression { - object: Expression - property: IdentifierOrExpression // Identifier | Expression - computed: boolean - } - interface IdentifierOrExpression extends Identifier, Expression { - } - - // Pattern - // interface Pattern extends Node { - // } - - // Clauses - interface SwitchCase extends Node { - test: Expression - consequent: Statement[] - } - interface CatchClause extends Node { - param: Identifier // Pattern - guard: Expression - body: BlockStatement - } - - // Misc - interface Identifier extends Node, Expression { // | Pattern - name: string - } - interface Literal extends Node, Expression { - value: any // string | boolean | null | number | RegExp - } - } } declare module "esprima" { diff --git a/estree/estree-tests.ts b/estree/estree-tests.ts new file mode 100644 index 000000000..bbf16586d --- /dev/null +++ b/estree/estree-tests.ts @@ -0,0 +1,177 @@ +/// + +var program: ESTree.Program; +var statement: ESTree.Statement; +var expression: ESTree.Expression; +var property: ESTree.Property; +var identifier: ESTree.Identifier; +var literal: ESTree.Literal; +var switchCase: ESTree.SwitchCase; +var catchClause: ESTree.CatchClause; +var pattern: ESTree.Pattern; +var assignmentPattern: ESTree.AssignmentPattern; +var variableDeclaratorOrExpression: ESTree.VariableDeclaration | ESTree.Expression; +var literalOrIdentifier: ESTree.Literal | ESTree.Identifier; +var blockStatementOrExpression: ESTree.BlockStatement | ESTree.Expression; +var identifierOrExpression: ESTree.Expression; +var any: any; +var string: string; +var boolean: boolean; +var number: number; + +// Program +string = program.type; +statement = program.body[0]; + +// Location +number = program.loc.start.line; +number = program.loc.start.column; +number = program.loc.end.line; +number = program.loc.end.column; +number = program.range[0]; + +// Statement +// BlockStatement +var blockStatement: ESTree.BlockStatement; +string = blockStatement.type; +statement = blockStatement.body[0]; + +// ExpressionStatement +var expressionStatement: ESTree.ExpressionStatement; +expression = expressionStatement.expression; + +// IfStatement +var ifStatement: ESTree.IfStatement; +expression = ifStatement.test; +statement = ifStatement.consequent; +statement = ifStatement.alternate; + +// LabeledStatement +var labeledStatement: ESTree.LabeledStatement; +identifier = labeledStatement.label; +statement = labeledStatement.body; + +// WithStatement +var withStatement: ESTree.WithStatement; +expression = withStatement.object; + +// SwitchStatement +var switchStatement: ESTree.SwitchStatement; +expression = switchStatement.discriminant; +switchCase = switchStatement.cases[0]; +boolean = switchStatement.lexical; + +// ReturnStatement +var returnStatement: ESTree.ReturnStatement; +expression = returnStatement.argument; + +// TryStatement +var tryStatement: ESTree.TryStatement; +blockStatement = tryStatement.block; +catchClause = tryStatement.handler; +blockStatement = tryStatement.finalizer; + +// ForStatement +var forStatement: ESTree.ForStatement; +variableDeclaratorOrExpression = forStatement.init; +expression = forStatement.update; + +// ForInStatement +var forInStatement: ESTree.ForInStatement; +variableDeclaratorOrExpression = forInStatement.left; +expression = forInStatement.right; + +// Expression +// ArrayExpression +var arrayExpression: ESTree.ArrayExpression; +string = arrayExpression.type; +expression = arrayExpression.elements[0]; + +// ObjectExpression +var objectExpression: ESTree.ObjectExpression; +property = objectExpression.properties[0]; +string = property.type; +expression = property.key; +expression = property.value; +string = property.kind; + +// FunctionExpression +var functionExpression: ESTree.FunctionExpression; +identifier = functionExpression.id; +assignmentPattern = functionExpression.params[0]; +pattern = assignmentPattern.left; +expression = assignmentPattern.right; +blockStatementOrExpression = functionExpression.body; +boolean = functionExpression.generator; + +// SequenceExpression +var sequenceExpression: ESTree.SequenceExpression; +expression = sequenceExpression.expressions[0] + +// UnaryExpression +var unaryExpression: ESTree.UnaryExpression; +string = unaryExpression.operator; +boolean = unaryExpression.prefix; + +// BinaryExpression +var binaryExpression: ESTree.BinaryExpression; +expression = binaryExpression.left; +expression = binaryExpression.right; + +// ConditionalExpression +var conditionalExpression: ESTree.ConditionalExpression; +expression = conditionalExpression.test; +expression = conditionalExpression.alternate; +expression = conditionalExpression.consequent; + +// NewExpression +var newExpression: ESTree.NewExpression; +expression = newExpression.callee; +expression = newExpression.arguments[0]; + +// CallExpression +var callExpression: ESTree.CallExpression; +expression = callExpression.callee; +expression = callExpression.arguments[0]; + +// MemberExpression +var memberExpression: ESTree.MemberExpression; +expression = memberExpression.object; +identifierOrExpression = memberExpression.property; +boolean = memberExpression.computed; + +// Declarations +var functionDeclaration: ESTree.FunctionDeclaration; +identifier = functionDeclaration.id; +var params:ESTree.Pattern[] = functionDeclaration.params; +var body:ESTree.BlockStatement | ESTree.Expression = functionDeclaration.body; +boolean = functionDeclaration.generator; + +var variableDeclaration: ESTree.VariableDeclaration; +var declarations:ESTree.VariableDeclarator[] = variableDeclaration.declarations; +string = variableDeclaration.kind; // "var" | "let" | "const" + +var variableDeclarator: ESTree.VariableDeclarator; +pattern = variableDeclarator.id; // Pattern +expression = variableDeclarator.init; + +// Clauses +// SwitchCase +string = switchCase.type; +expression = switchCase.test; +statement = switchCase.consequent[0]; + +// CatchClause +string = catchClause.type; +pattern = catchClause.param; +expression = catchClause.guard; +blockStatement = catchClause.body; + +// Misc +// Identifier +string = identifier.type; +string = identifier.name; + +// Literal +string = literal.type; +any = literal.value; diff --git a/estree/estree.d.ts b/estree/estree.d.ts new file mode 100644 index 000000000..329396b7c --- /dev/null +++ b/estree/estree.d.ts @@ -0,0 +1,369 @@ +// Type definitions for ESTree AST specification +// Project: https://github.com/estree/estree +// Definitions by: RReverser +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module ESTree { + interface Node { + type: string; + loc?: SourceLocation; + range?: [number, number]; + } + + interface SourceLocation { + source?: string; + start: Position; + end: Position; + } + + interface Position { + line: number; + column: number; + } + + interface Program extends Node { + body: Array; + sourceType: string; + } + + interface Function extends Node { + id?: Identifier; + params: Array; + body: BlockStatement | Expression; + generator: boolean; + } + + interface Statement extends Node {} + + interface EmptyStatement extends Statement {} + + interface BlockStatement extends Statement { + body: Array; + } + + interface ExpressionStatement extends Statement { + expression: Expression; + } + + interface IfStatement extends Statement { + test: Expression; + consequent: Statement; + alternate?: Statement; + } + + interface LabeledStatement extends Statement { + label: Identifier; + body: Statement; + } + + interface BreakStatement extends Statement { + label?: Identifier; + } + + interface ContinueStatement extends Statement { + label?: Identifier; + } + + interface WithStatement extends Statement { + object: Expression; + body: Statement; + } + + interface SwitchStatement extends Statement { + discriminant: Expression; + cases: Array; + lexical: boolean; + } + + interface ReturnStatement extends Statement { + argument?: Expression; + } + + interface ThrowStatement extends Statement { + argument: Expression; + } + + interface TryStatement extends Statement { + block: BlockStatement; + handler?: CatchClause; + finalizer?: BlockStatement; + } + + interface WhileStatement extends Statement { + test: Expression; + body: Statement; + } + + interface DoWhileStatement extends Statement { + body: Statement; + test: Expression; + } + + interface ForStatement extends Statement { + init?: VariableDeclaration | Expression; + test?: Expression; + update?: Expression; + body: Statement; + } + + interface ForInStatement extends Statement { + left: VariableDeclaration | Expression; + right: Expression; + body: Statement; + } + + interface DebuggerStatement extends Statement {} + + interface Declaration extends Statement {} + + interface FunctionDeclaration extends Function, Declaration { + id: Identifier; + } + + interface VariableDeclaration extends Declaration { + declarations: Array; + kind: string; + } + + interface VariableDeclarator extends Node { + id: Pattern; + init?: Expression; + } + + interface Expression extends Node {} + + interface ThisExpression extends Expression {} + + interface ArrayExpression extends Expression { + elements: Array; + } + + interface ObjectExpression extends Expression { + properties: Array; + } + + interface Property extends Node { + key: Expression; + value: Expression; + kind: string; + method: boolean; + shorthand: boolean; + computed: boolean; + } + + interface FunctionExpression extends Function, Expression {} + + interface SequenceExpression extends Expression { + expressions: Array; + } + + interface UnaryExpression extends Expression { + operator: UnaryOperator; + prefix: boolean; + argument: Expression; + } + + interface BinaryExpression extends Expression { + operator: BinaryOperator; + left: Expression; + right: Expression; + } + + interface AssignmentExpression extends Expression { + operator: AssignmentOperator; + left: Pattern | MemberExpression; + right: Expression; + } + + interface UpdateExpression extends Expression { + operator: UpdateOperator; + argument: Expression; + prefix: boolean; + } + + interface LogicalExpression extends Expression { + operator: LogicalOperator; + left: Expression; + right: Expression; + } + + interface ConditionalExpression extends Expression { + test: Expression; + alternate: Expression; + consequent: Expression; + } + + interface CallExpression extends Expression { + callee: Expression | Super; + arguments: Array; + } + + interface NewExpression extends CallExpression {} + + interface MemberExpression extends Expression, Pattern { + object: Expression | Super; + property: Expression; + computed: boolean; + } + + interface Pattern extends Node {} + + interface SwitchCase extends Node { + test?: Expression; + consequent: Array; + } + + interface CatchClause extends Node { + param: Pattern; + guard: any; + body: BlockStatement; + } + + interface Identifier extends Node, Expression, Pattern { + name: string; + } + + interface Literal extends Node, Expression { + value?: string | boolean | number | RegExp; + } + + interface RegexLiteral extends Literal { + regex: { + pattern: string; + flags: string; + }; + } + + type UnaryOperator = string; + + type BinaryOperator = string; + + type LogicalOperator = string; + + type AssignmentOperator = string; + + type UpdateOperator = string; + + interface ForOfStatement extends ForInStatement {} + + interface Super extends Node {} + + interface SpreadElement extends Node { + argument: Expression; + } + + interface ArrowFunctionExpression extends Function, Expression { + expression: boolean; + } + + interface YieldExpression extends Expression { + argument?: Expression; + } + + interface TemplateLiteral extends Expression { + quasis: Array; + expressions: Array; + } + + interface TaggedTemplateExpression extends Expression { + tag: Expression; + quasi: TemplateLiteral; + } + + interface TemplateElement extends Node { + tail: boolean; + value: { + cooked: string; + value: string; + }; + } + + interface AssignmentProperty extends Property { + value: Pattern; + kind: string; + method: boolean; + } + + interface ObjectPattern extends Pattern { + properties: Array; + } + + interface ArrayPattern extends Pattern { + elements: Array; + } + + interface RestElement extends Pattern { + argument: Pattern; + } + + interface AssignmentPattern extends Pattern { + left: Pattern; + right: Expression; + } + + interface Class extends Node { + id?: Identifier; + superClass: Expression; + body: ClassBody; + } + + interface ClassBody extends Node { + body: Array; + } + + interface MethodDefinition extends Node { + key: Identifier; + value: FunctionExpression; + kind: string; + computed: boolean; + static: boolean; + } + + interface ClassDeclaration extends Class, Declaration { + id: Identifier; + } + + interface ClassExpression extends Class, Expression {} + + interface MetaProperty extends Expression { + meta: Identifier; + property: Identifier; + } + + interface ImportDeclaration extends Node { + specifiers: Array; + source: Literal; + } + + interface ImportSpecifier { + imported: Identifier; + local: Identifier; + } + + interface ImportDefaultSpecifier { + local: Identifier; + } + + interface ImportNamespaceSpecifier { + local: Identifier; + } + + interface ExportNamedDeclaration extends Node { + declaration?: Declaration; + specifiers: Array; + source?: Literal; + } + + interface ExportSpecifier { + exported: Identifier; + local: Identifier; + } + + interface ExportDefaultDeclaration extends Node { + declaration: Declaration | Expression; + } + + interface ExportAllDeclaration extends Node { + source: Literal; + } +} \ No newline at end of file diff --git a/express-debug/express-debug-tests.ts b/express-debug/express-debug-tests.ts new file mode 100644 index 000000000..6f702856e --- /dev/null +++ b/express-debug/express-debug-tests.ts @@ -0,0 +1,21 @@ +/// + +import express = require('express'); +import debug = require('express-debug'); +var app = express(); + +debug(app, { + depth: 4, + theme: 'public/css/debug.css', + extra_panels: [{ + name: 'mypanel', + template: '/absolute/path/to/mypanel.jade', + process: function(locals) { + return { locals: { mypanel: true, }}; + } + }], + panels: ['locals', 'request', 'session'], + path: '/express-debug', + extra_attrs: '', + sort: false, +}); diff --git a/express-debug/express-debug.d.ts b/express-debug/express-debug.d.ts new file mode 100644 index 000000000..d185f5c69 --- /dev/null +++ b/express-debug/express-debug.d.ts @@ -0,0 +1,83 @@ +// Type definitions for express-debug 1.1.1 +// Project: https://github.com/devoidfury/express-debug +// Definitions by: Federico Bond +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/* =================== USAGE =================== + + import debug = require('express-debug'); + debug(app, options); + + =============================================== */ + +/// + +declare module "express-debug" { + import express = require('express'); + + interface CustomPanel { + name: string; + + template: string; + + process(locals: any): any; + + standalone?: boolean; + + initialize?(req: express.Request): void; + + finalize?(req: express.Request): void; + + pre_render?(req: express.Request): void; + + post_render?(req: express.Request): void; + + options?: any; + } + + /** + * Node.js middleware for serving a favicon. + */ + function debug(app: express.Application, settings?: { + /** + * How deep to recurse through printed objects. This is the default unless the + * print_obj function is passed an options object with a 'depth' property. + */ + depth?: number; + + /** + * Absolute path to a css file to include and override EDT's default css. + */ + theme?: string; + + /** + * Additional panels to show. + */ + extra_panels?: CustomPanel[]; + + /** + * Allows changing the default panel. + */ + panels?: string[]; + + /** + * Path to render standalone express-debug. + */ + path?: string; + + /** + * If you need to add arbitrary attributes to the containing element of EDT, + * this allows you to. + */ + extra_attrs?: string; + + /** + * Global option to determine sort order of printed object values. false for + * default order, true for basic default sort, or a function to use for sort. + */ + sort?: boolean | ((a: number, b: number) => number); + + }): void; + + export = debug; +} diff --git a/googlemaps/google.maps.d.ts b/googlemaps/google.maps.d.ts index eb85899c4..3ba451c8a 100644 --- a/googlemaps/google.maps.d.ts +++ b/googlemaps/google.maps.d.ts @@ -1345,6 +1345,55 @@ declare module google.maps { } export module places { + + export class AutocompleteService extends MVCObject { + constructor(); + getPlacePredictions(request: AutocompletionRequest, callback: (result: AutocompletePrediction[], status: PlacesServiceStatus) => void): void; + getQueryPredictions(request: QueryAutocompletionRequest, callback: (result: QueryAutocompletePrediction[], status: PlacesServiceStatus) => void): void; + } + + export interface AutocompletionRequest { + input: string; + bounds?: LatLngBounds; + componentRestrictions?: ComponentRestrictions; + location?: LatLng; + offset?: number; + radius?: number; + types?: string[]; + } + + export interface QueryAutocompletionRequest { + input: string; + bounds?: LatLngBounds; + location?: LatLng; + offset?: number; + radius?: number; + } + + export interface AutocompletePrediction { + description: string; + matched_substrings: PredictionSubstring[]; + place_id: string; + terms: PredictionTerm[]; + types: string[] + } + + export interface PredictionTerm { + offset: number; + value: string; + } + + export interface PredictionSubstring { + length: number; + offset: number; + } + + export interface QueryAutocompletePrediction { + description: string; + matched_substrings: PredictionSubstring[]; + place_id: string; + terms: PredictionTerm[]; + } export class Autocomplete extends MVCObject { constructor (inputField: HTMLInputElement, opts?: AutocompleteOptions); diff --git a/hapi/hapi-tests.ts b/hapi/hapi-tests.ts index c0f8d9f6e..11ad81d2d 100644 --- a/hapi/hapi-tests.ts +++ b/hapi/hapi-tests.ts @@ -82,5 +82,18 @@ server.route([{ } }]); +// config.validate parameters should be optional +server.route([{ + method: 'GET', + path: '/hello2', + handler: function(request: Hapi.Request, reply: Function) { + reply('hello world2'); + }, + config: { + validate: { + } + } +}]); + // Start the server server.start(); diff --git a/hapi/hapi.d.ts b/hapi/hapi.d.ts index 2cd06cd6e..de8dba6b8 100644 --- a/hapi/hapi.d.ts +++ b/hapi/hapi.d.ts @@ -568,7 +568,7 @@ declare module "hapi" { optionsthe server validation options. next(err, value)the callback function called when validation is completed. */ - headers: boolean | IJoi | IValidationFunction; + headers?: boolean | IJoi | IValidationFunction; /** validation rules for incoming request path parameters, after matching the path against the route and extracting any parameters then stored in request.params.Values allowed: @@ -579,7 +579,7 @@ declare module "hapi" { valuethe object containing the path parameters. optionsthe server validation options. next(err, value)the callback function called when validation is completed. */ - params: boolean | IJoi | IValidationFunction; + params?: boolean | IJoi | IValidationFunction; /** validation rules for an incoming request URI query component (the key- value part of the URI between '?' and '#').The query is parsed into its individual key- value pairs (using the qs module) and stored in request.query prior to validation.Values allowed: trueany query parameters allowed (no validation performed).This is the default. falseno query parameters allowed. @@ -588,7 +588,7 @@ declare module "hapi" { valuethe object containing the query parameters. optionsthe server validation options. next(err, value)the callback function called when validation is completed. */ - query: boolean | IJoi | IValidationFunction; + query?: boolean | IJoi | IValidationFunction; /** validation rules for an incoming request payload (request body).Values allowed: trueany payload allowed (no validation performed).This is the default. falseno payload allowed. @@ -597,9 +597,9 @@ declare module "hapi" { valuethe object containing the payload object. optionsthe server validation options. next(err, value)the callback function called when validation is completed. */ - payload: boolean | IJoi | IValidationFunction; + payload?: boolean | IJoi | IValidationFunction; /** an optional object with error fields copied into every validation error response. */ - errorFields: any; + errorFields?: any; /** determines how to handle invalid requests.Allowed values are: 'error'return a Bad Request (400) error response.This is the default value. 'log'log the error but continue processing the request. @@ -609,9 +609,9 @@ declare module "hapi" { replythe continuation reply interface. sourcethe source of the invalid field (e.g. 'path', 'query', 'payload'). errorthe error object prepared for the client response (including the validation function error under error.data). */ - failAction: string | IRouteFailFunction; + failAction?: string | IRouteFailFunction; /** options to pass to Joi.Useful to set global options such as stripUnknown or abortEarly (the complete list is available here: https://github.com/hapijs/joi#validatevalue-schema-options-callback ).Defaults to no options. */ - options: any; + options?: any; }; /** define timeouts for processing durations: */ timeout?: { diff --git a/jquery-jsonrpcclient/jquery-jsonrpcclient-tests.ts b/jquery-jsonrpcclient/jquery-jsonrpcclient-tests.ts new file mode 100644 index 000000000..7d23caddf --- /dev/null +++ b/jquery-jsonrpcclient/jquery-jsonrpcclient-tests.ts @@ -0,0 +1,23 @@ +/// +/// + +var foo = new $.JsonRpcClient({ ajaxUrl: '/backend/jsonrpc' }); +foo.call( + 'bar', ['A parameter', 'B parameter'], + function (result) { alert('Foo bar answered: ' + result.my_answer); }, + function (error) { console.log('There was an error', error); } +); + + +var foo = new $.JsonRpcClient({ ajaxUrl: '/backend/jsonrpc' }); +foo.batch( + function (batch) { + batch.call('bar', ['A parameter', 'B parameter'], function () { }, function () { }); + batch.call('baz', { parameters: 'could be object' }, function () { }, function () { }); + }, + function (all_result_array) { alert('All done.'); }, + function (error_data) { alert('Error in batch response.'); } + ); + +var foo = new $.JsonRpcClient({ ajaxUrl: '/backend/jsonrpc', socketUrl: 'ws://example.com/' }); +foo.call('bar', ['param'], function () { }, function () { }); \ No newline at end of file diff --git a/jquery-jsonrpcclient/jquery-jsonrpcclient.d.ts b/jquery-jsonrpcclient/jquery-jsonrpcclient.d.ts new file mode 100644 index 000000000..de008dc09 --- /dev/null +++ b/jquery-jsonrpcclient/jquery-jsonrpcclient.d.ts @@ -0,0 +1,97 @@ +// Type definitions for jquery.jsonrpc 0.7.0 +// Project: https://github.com/Textalk/jquery.jsonrpcclient.js +// Definitions by: Maksim Karelov +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +interface JsonRpcClientOptions extends JQueryAjaxSettings { + ajaxUrl?: string; + headers?: {[key:string]: any}; + sockerUrl?: string; + onmessage?: () => void; + onopen?: () => void; + onclose?: () => void; + onerror?: () => void; + getSockect?: (onmessageCb: () => void) => WebSocket; +} + +interface JsonRpcClient { + /** + * @fn call + * @memberof JsonRpcClient + * + * @param {string} method The method to run on JSON-RPC server. + * @param {object|array} params The params; an array or object. + * @param {function} successCb A callback for successful request. + * @param {function} errorCb A callback for error. + * + * @return {object} Returns the deferred object that $.ajax returns or {null} for websockets + */ + call(method: string, params: Object | Array, successCb: (result: any) => void, errorCb: (result: any) => void): JQueryDeferred; + + /** + * Notify sends a command to the server that won't need a response. In http, there is probably + * an empty response - that will be dropped, but in ws there should be no response at all. + * + * This is very similar to call, but has no id and no handling of callbacks. + * + * @fn notify + * @memberof JsonRpcClient + * + * @param {string} method The method to run on JSON-RPC server. + * @param {object|array} params The params; an array or object. + * + * @return {object} Returns the deferred object that $.ajax returns or {null} for websockets + */ + notify(method: string, params: Object | Array): JQueryDeferred; + + /** + * Make a batch-call by using a callback. + * + * The callback will get an object "batch" as only argument. On batch, you can call the methods + * "call" and "notify" just as if it was a normal JsonRpcClient object, and all calls will be + * sent as a batch call then the callback is done. + * + * @fn batch + * @memberof JsonRpcClient + * + * @param {function} callback This function will get a batch handler to run call and notify on. + * @param {function} allDoneCb A callback function to call after all results have been handled. + * @param {function} errorCb A callback function to call if there is an error from the server. + * Note, that batch calls should always get an overall success, and the + * only error + */ + batch(callback: (batch: JsonRpcClient) => void, allDoneCb: (result: any) => void, errorCb: (error: any) => void): void; +} + +interface JsonRpcClientFactory { + /** + * @fn new + * @memberof JsonRpcClient + * + * @param {object} options An object stating the backends: + * ajaxUrl A url (relative or absolute) to a http(s) backend. + * headers An object that will be passed along to $.ajax in options.headers + * xhrFields An object that will be passed along to $.ajax in options.xhrFields + * socketUrl A url (relative of absolute) to a ws(s) backend. + * onmessage A socket message handler for other messages (non-responses). + * onopen A socket onopen handler. (Not used for custom getSocket.) + * onclose A socket onclose handler. (Not used for custom getSocket.) + * onerror A socket onerror handler. (Not used for custom getSocket.) + * getSocket A function returning a WebSocket or null. + * It must take an onmessage_cb and bind it to the onmessage event + * (or chain it before/after some other onmessage handler). + * Or, it could return null if no socket is available. + * The returned instance must have readyState <= 1, and if less than 1, + * react to onopen binding. + * timeout (optional) A number of ms to wait before timing out and failing a + * call. If specified a setTimeout will be used to keep track of calls + * made through a websocket. + */ + new (options?: JsonRpcClientOptions): JsonRpcClient; +} + +interface JQueryStatic { + JsonRpcClient: JsonRpcClientFactory; +} \ No newline at end of file diff --git a/jquery.pickadate/jquery.pickadate.d.ts b/jquery.pickadate/jquery.pickadate.d.ts index 274f20f90..62b20bb22 100644 --- a/jquery.pickadate/jquery.pickadate.d.ts +++ b/jquery.pickadate/jquery.pickadate.d.ts @@ -39,6 +39,7 @@ interface pickadateOptions extends pickerOptions { formatSubmit?: string; // e.g. 'yyyy/mm/dd' hiddenPrefix?: string; // default undefined hiddenSuffix?: string; // default '_submit' + hiddenName?: boolean; // default undefined // Dropdown selectors selectYears?: any; // Specify the number of years selectable using an even integer - half before and half after the year in focus: @@ -223,23 +224,21 @@ interface TimePickerSetThings extends SetThings { interval?: any; } -interface PickerObject { +interface PickerObject { /** The picker's relative input element wrapped as a jQuery object. */ $node: JQuery; /** The picker's relative root holder element wrapped as a jQuery object. */ $root: JQuery; -} -interface DatePickerObject extends PickerObject { - open(withoutFocus?: boolean): DatePickerObject; - close(withFocus?: boolean): DatePickerObject; + open(withoutFocus?: boolean): TPickerObject; + close(withFocus?: boolean): TPickerObject; /** Rebuild the picker. */ - start(): DatePickerObject; + start(): TPickerObject; /** Destroy the picker. */ - stop(): DatePickerObject; + stop(): TPickerObject; /** * Refresh the picker box after adding something to the holder. @@ -247,10 +246,10 @@ interface DatePickerObject extends PickerObject { * has it’s contents re-rendered. To render the entire picker from * the root up, pass true as the first argument. */ - render(entirePicker?: boolean): DatePickerObject; + render(entirePicker?: boolean): TPickerObject; /** Clear the value in the picker's input element. */ - clear(): DatePickerObject; + clear(): TPickerObject; /** Short for picker.get('value') */ get(): string; @@ -262,19 +261,19 @@ interface DatePickerObject extends PickerObject { get(thing: 'value'): string; /** Returns the item object that is visually selected. */ - get(thing: 'select'): DatePickerItemObject; + get(thing: 'select'): TItemObject; /** Returns the item object that is visually highlighted. */ - get(thing: 'highlight'): DatePickerItemObject; + get(thing: 'highlight'): TItemObject; /** Returns the item object that sets the current view. */ - get(thing: 'view'): DatePickerItemObject; + get(thing: 'view'): TItemObject; /** Returns the item object that limits the picker's lower range. */ - get(thing: 'min'): DatePickerItemObject; + get(thing: 'min'): TItemObject; /** Returns the item object that limits the picker's upper range. */ - get(thing: 'max'): DatePickerItemObject; + get(thing: 'max'): TItemObject; /** Returns a boolean value of whether the picker is open or not. */ get(thing: 'open'): boolean; @@ -292,99 +291,29 @@ interface DatePickerObject extends PickerObject { get(thing: string, format: string): string; /** Set the properties, objects, and states to change the state of the picker. */ - set(thing: string, value?: any): DatePickerObject; - set(things: SetThings): DatePickerObject; + set(thing: string, value?: any, options?: any): TPickerObject; + set(things: TOptions, options?: any): TPickerObject; /** Bind callbacks to get fired off when the relative picker method is called. */ - on(methodName, callback: () => void ): DatePickerObject; + on(methodName, callback: () => void): TPickerObject; /** Bind multiple callbacks at once to get fired off when the relative picker method is called. */ - on(callbackObject: CallbackObject): DatePickerObject; + on(callbackObject: CallbackObject): TPickerObject; /** Trigger callbacks that have been queued up using the the on method. */ - trigger(event: string): DatePickerObject; + trigger(event: string): TPickerObject; } -interface TimePickerObject extends PickerObject { - open(withoutFocus?: boolean): TimePickerObject; - close(withFocus?: boolean): TimePickerObject; - - /** Rebuild the picker. */ - start(): TimePickerObject; - - /** Destroy the picker. */ - stop(): TimePickerObject; - - /** - * Refresh the picker box after adding something to the holder. - * By default, only the "face" of the picker (i.e. the box element) - * has it’s contents re-rendered. To render the entire picker from - * the root up, pass true as the first argument. - */ - render(entirePicker?: boolean): TimePickerObject; - - /** Clear the value in the picker's input element. */ - clear(): TimePickerObject; - - /** Short for picker.get('value') */ - get(): string; - - /** Get the properties, objects, and states that make up the current state of the picker. */ - get(thing: string): any; - - /** Returns the string value of the picker's input element. */ - get(thing: 'value'): string; - - /** Returns the item object that is visually selected. */ - get(thing: 'select'): TimePickerItemObject; - - /** Returns the item object that is visually highlighted. */ - get(thing: 'highlight'): TimePickerItemObject; - - /** Returns the item object that sets the current view. */ - get(thing: 'view'): TimePickerItemObject; - - /** Returns the item object that limits the picker's lower range. */ - get(thing: 'min'): TimePickerItemObject; - - /** Returns the item object that limits the picker's upper range. */ - get(thing: 'max'): TimePickerItemObject; - - /** Returns a boolean value of whether the picker is open or not. */ - get(thing: 'open'): boolean; - - /** Returns a boolean value of whether the picker has started or not. */ - get(thing: 'start'): boolean; - - /** Returns a unique 9-digit integer that is the ID of the picker. */ - get(thing: 'id'): number; - - /** Returns an array of items that determine which item objects to disable on the picker. */ - get(thing: 'disable'): any[]; - - /** Returns a formatted string for the item object specified by `thing` */ - get(thing: string, format: string): string; - - /** Set the properties, objects, and states to change the state of the picker. */ - set(thing: string, value?: any): TimePickerObject; - set(things: TimePickerSetThings): TimePickerObject; - - /** Bind callbacks to get fired off when the relative picker method is called. */ - on(methodName, callback: () => void ): TimePickerObject; - - /** Bind multiple callbacks at once to get fired off when the relative picker method is called. */ - on(callbackObject: CallbackObject): TimePickerObject; - - /** Trigger callbacks that have been queued up using the the on method. */ - trigger(event: string): TimePickerObject; -} +interface DatePickerObject extends PickerObject { } +interface TimePickerObject extends PickerObject { } interface JQuery { - pickadate(options?: pickadateOptions): HTMLInputElement; - pickatime(options?: pickatimeOptions): HTMLInputElement; + pickadate(methodName: "picker"): DatePickerObject; + pickadate(methodName: string): any; + pickadate(options?: pickadateOptions): JQuery; + + pickatime(methodName: "picker"): TimePickerObject; + pickatime(methodName: string): any; + pickatime(options?: pickatimeOptions): JQuery; } -interface HTMLInputElement { - pickadate(picker: string): DatePickerObject; - pickatime(picker: string): TimePickerObject; -} diff --git a/jsonpath/jsonpath-tests.ts b/jsonpath/jsonpath-tests.ts new file mode 100644 index 000000000..d7fd50868 --- /dev/null +++ b/jsonpath/jsonpath-tests.ts @@ -0,0 +1,55 @@ +/// + +import jp = require('jsonpath'); + +var data: any; + +/** + * jp.query(obj, pathExpression) + * Find elements in obj matching pathExpression. Returns an array of elements that satisfy the provided JSONPath expression, or an empty array if none were matched. + */ +var authors = jp.query(data, '$..author'); + +/** + * jp.paths(obj, pathExpression) + * Find elements in obj matching pathExpression. Returns an array of element paths that satisfy the provided JSONPath expression. Each path is itself an array of keys representing the location within obj of the matching element. + */ +var paths = jp.paths(data, '$..author'); + +/** + * jp.nodes(obj, pathExpression) + * Find elements and their corresponding paths in obj matching pathExpression. Returns an array of node objects where each node has a path containing an array of keys representing the location within obj, and a value pointing to the matched element. + */ +var nodes = jp.nodes(data, '$..author'); + +/** + * jp.value(obj, pathExpression, [newValue]) + * Returns the value of the first element matching pathExpression. If newValue is provided, sets the value of the first matching element and returns the new value. + */ +var value = jp.value(data, '$.store..price'); +jp.value(data, '$.store..price', 12.5); + +/** + * jp.parent(obj, pathExpression) + * Returns the parent of the first matching element. + */ +var parent = jp.parent(data, '$.store..price'); + +/** + * jp.apply(obj, pathExpression, fn) + * Runs the supplied function fn on each matching element, and replaces each matching element with the return value from the function. The function accepts the value of the matching element as its only parameter. Returns matching nodes with their updated values. + */ +var nodes = jp.apply(data, '$..author', (value: string) => { return value.toUpperCase() }); + +/** + * jp.parse(pathExpression) + * Parse the provided JSONPath expression into path components and their associated operations. + */ +var path = jp.parse('$..author'); + +/** + * jp.stringify(path) + * Returns a path expression in string form, given a path. The supplied path may either be a flat array of keys, as returned by jp.nodes for example, or may alternatively be a fully parsed path expression in the form of an array of path components as returned by jp.parse. + */ +var pathExpression = jp.stringify(['$', 'store', 'book', 0, 'author']); + diff --git a/jsonpath/jsonpath.d.ts b/jsonpath/jsonpath.d.ts new file mode 100644 index 000000000..db5322017 --- /dev/null +++ b/jsonpath/jsonpath.d.ts @@ -0,0 +1,21 @@ +// Type definitions for jsonpath 0.1.3 +// Project: https://www.npmjs.org/package/jsonpath +// Definitions by: Hiroki Horiuchi +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "jsonpath" { + + type PathComponent = string|number; + + export function query(obj: any, pathExpression: string): any[]; + export function paths(obj: any, pathExpression: string): PathComponent[][]; + export function nodes(obj: any, pathExpression: string): { path: PathComponent[]; value: any; }[]; + export function value(obj: any, pathExpression: string): any; + export function value(obj: any, pathExpression: string, newValue: any): any; + export function parent(obj: any, pathExpression: string): any; + export function apply(obj: any, pathExpression: string, fn: (x: any) => any): { path: PathComponent[]; value: any; }[]; + export function parse(pathExpression: string): any[]; + export function stringify(path: PathComponent[]): string; + +} + diff --git a/less-middleware/less-middleware-tests.ts b/less-middleware/less-middleware-tests.ts new file mode 100644 index 000000000..0a84203b6 --- /dev/null +++ b/less-middleware/less-middleware-tests.ts @@ -0,0 +1,28 @@ +/// + +import express = require('express'); +import lessMiddleware = require('less-middleware'); +var app = express(); + +app.use(lessMiddleware('public', { + cacheFile: null, + debug: false, + dest: 'dest', + force: false, + once: false, + pathRoot: 'root', + postprocess: { + css: function(css, req) { return css; }, + }, + preprocess: { + less: function(src, req) { return src; }, + path: function(pathname, req) { return pathname; }, + importPaths: function(paths, req) { return paths; } + }, + render: { + compress: 'auto', + yuicompress: false, + paths: ['foo', 'bar'] + }, + storeCss: function(css, req, next) {}, +})); diff --git a/less-middleware/less-middleware.d.ts b/less-middleware/less-middleware.d.ts new file mode 100644 index 000000000..ee0e0069d --- /dev/null +++ b/less-middleware/less-middleware.d.ts @@ -0,0 +1,108 @@ +// Type definitions for less-middleware 2.0.1 +// Project: https://github.com/emberfeather/less.js-middleware +// Definitions by: Federico Bond +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/* =================== USAGE =================== + + import lessMiddleware = require('less-middleware'); + app.use(lessMiddleware(source, options)); + + =============================================== */ + +/// + +declare module "less-middleware" { + import express = require('express'); + + /** + * Middleware created to allow processing of Less files for Connect JS framework + * and by extension the Express JS framework + */ + function lessMiddleware(source: string, options?: { + /** + * Show more verbose logging? + */ + debug?: boolean; + + /** + * Destination directory to output the compiled .css files. + */ + dest?: string; + + /** + * Always re-compile less files on each request. + */ + force?: boolean; + + /** + * Only recompile once after each server restart. + * Useful for reducing disk i/o on production. + */ + once?: boolean; + + /** + * Common root of the source and destination. + * It is prepended to both the source and destination before being used. + */ + pathRoot?: string; + + /** + * Object containing functions relevant to preprocessing data. + */ + postprocess?: { + + /** + * Function that modifies the compiled css output before being stored. + */ + css?(css: string, req: express.Request): string; + }; + + /** + * Object containing functions relevant to preprocessing data. + */ + preprocess?: { + + /** + * Function that modifies the raw less output before being parsed and compiled. + */ + less?(css: string, req: express.Request): string; + + /** + * Function that modifies the less pathname before being loaded from the filesystem. + */ + path?(pathname: string, req: express.Request): string; + + /** + * Function that modifies the import paths used by the less parser per request. + */ + importPaths?(paths: string[], req: express.Request): string[]; + }; + + /** + * Options for the less render. + */ + render?: { + + compress?: string; + yuicompress?: boolean; + paths?: string[]; + }; + + /** + * Function that is in charge of storing the css in the filesystem. + */ + storeCss?(pathname: string, css: string, req: express.Request, next: Function): void; + + /** + * Path to a JSON file that will be used to cache less data across server restarts. + * This can greatly speed up initial load time after a server restart - if the less + * files haven't changed and the css files still exist, specifying this option will + * mean that the less files don't need to be recompiled after a server restart. + */ + cacheFile?: string; + + }): express.RequestHandler; + + export = lessMiddleware; +} diff --git a/less/less-tests.ts b/less/less-tests.ts index a984306ee..71dfbae76 100644 --- a/less/less-tests.ts +++ b/less/less-tests.ts @@ -2,33 +2,12 @@ import less = require("less"); -declare var __dirname: string; - -less.render('.class { width: (1 + 1) }', (e, css) => console.log(css)); - -var parser: less.Parser = new less.Parser; - -parser.parse('.class { width: (1 + 1) }', function (err, tree) { - if (err) return console.error(err); - tree.toCSS(); +less.render(".class { width: (1 + 1) }").then((output) => { + console.log(output.css); }); -var parser2 = new less.Parser({ - paths: ['.', './lib'], - filename: 'style.less' +less.render("fail").then((output) => { + throw new Error("promise should have been rejected"); +}, () => { + console.log("rejected as expected"); }); - -parser2.parse('.class { width: (1 + 1) }', (e, tree) => tree.toCSS({ compress: true })); - -var lessParser = new less.Parser({ - paths: [__dirname], - filename: "out.less" -}); - -lessParser.parse('.class { width: (1 + 1) }', function (err, tree) { - tree.rules.forEach(function (rule) { - if (rule.path) { - console.log(rule.path); - } - }); -}); \ No newline at end of file diff --git a/less/less.d.ts b/less/less.d.ts index 4c096525d..2c10ce50e 100644 --- a/less/less.d.ts +++ b/less/less.d.ts @@ -1,556 +1,75 @@ // Type definitions for LESS // Project: http://lesscss.org/ -// Definitions by: AndrewGaspar +// Definitions by: Tom Hasner // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare module less { - class LessError { - constructor(e: Error, env); +declare module Less { + // Promise definitions from ../es6-promise/es6-promise.d.ts + interface Thenable { + then(onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Thenable; + } - type: any; - message: string; + class Promise implements Thenable { + constructor(callback: (resolve : (value?: R | Thenable) => void, reject: (error?: any) => void) => void); + + then(onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Promise; + + catch(onRejected?: (error: any) => U | Thenable): Promise; + + finally(finallyCallback: () => any): Promise; + } + + interface RootFileInfo { filename: string; - index; - line: number; - callLine: number; - callExtract; - stack; - column; - extract: any[]; + relativeUrls: boolean; + rootpath: string; + currentDirectory: string; + entryPath: string; + rootFilename: string; + } + + class PluginManager { + constructor(less: LessStatic); + } + + interface Plugin { + install: (less: LessStatic, pluginManager: PluginManager) => void; + } + + interface SourceMapOption { + sourceMapURL: string; + sourceMapBasepath: string; + sourceMapRootpath: string; + outputSourceFiles: boolean; + sourceMapFileInline: boolean; } interface Options { - contents?; - rootpath?: string; - files?; - paths?: string[]; - mime?: string; + sourceMap?: SourceMapOption; filename?: string; - optimization?: number; - dumpLineNumbers?: boolean; - strictImports?; - entryPath?: string; - relativeUrls?; - errback? (path: string, paths: string[], callback: Function, env: Options); - frames?; - compress?: boolean; + plugins: Plugin[]; + rootFileInfo?: RootFileInfo; } - export module tree { - export module mixin { // TODO - export class Call { - - } - - export class Definition extends Ruleset { - - } - } - - export module functions { - export function rgb(r: number, g: number, b: number): Color; - export function rgba(r: number, g: number, b: number, a: number): Color; - export function hsl(h: number, s?: number, l?: number): Color; - export function hsla(h: number, s?: number, l?: number, a?: number): Color; - export function hsv(h: number, s: number, v: number): Color; - export function hsva(h: number, s: number, v: number, a: number): Color; - export function hue(color: Color): Dimension; - export function saturation(color: Color): Dimension; - export function lightness(color: Color): Dimension; - export function red(color: Color): Dimension; - export function green(color: Color): Dimension; - export function blue(color: Color): Dimension; - export function alpha(color: Color): Dimension; - export function luma(color: Color): Dimension; - export function saturate(color: Color, amount: IValuableNumber): Color; - export function desaturate(color: Color, amount: IValuableNumber): Color; - export function lighten(color: Color, amount: IValuableNumber): Color; - export function darken(color: Color, amount: IValuableNumber): Color; - export function fadein(color: Color, amount: IValuableNumber): Color; - export function fadeout(color: Color, amount: IValuableNumber): Color; - export function fade(color: Color, amount: IValuableNumber): Color; - export function spin(color: Color, amount: IValuableNumber): Color; - export function mix(color1: Color, color2: Color, weight: Dimension): Color; - export function greyscale(color: Color): Color; - export function contrast(color: Color, dark?: Color, light?: Color, threshold?: IValuableNumber): Color; - export function contrast(color: Color, dark?: Color, light?: Color, threshold?: number): Color; - export function e(str: string): Anonymous; - export function e(str: JavaScript): Anonymous; - export function escape(str: IValuableString): Anonymous; - export function unit(val: IValuableNumber, unit?: ICSSable): Dimension; - export function round(n: Dimension, f?: IValuableNumber): Dimension; - export function round(n: number, f?: IValuableNumber): number; - export function ceil(n: number): number; - export function ceil(n: Dimension): Dimension; - export function floor(n: number): number; - export function floor(n: Dimension): Dimension; - export function argb(color: Color): Anonymous; - export function percentage(n: IValuableNumber): Dimension; - export function color(n: Quoted): Color; - export function iscolor(n): Keyword; - export function isnumber(n): Keyword; - export function isstring(n): Keyword; - export function iskeyword(n): Keyword; - export function isurl(n): Keyword; - export function ispixel(n): Keyword; - export function ispercentage(n): Keyword; - export function isem(n): Keyword; - export function multiply(color1: Color, color2: Color): Color; - export function screen(color1: Color, color2: Color): Color; - export function overlay(color1: Color, color2: Color): Color; - export function softlight(color1: Color, color2: Color): Color; - export function hardlight(color1: Color, color2: Color): Color; - export function difference(color1: Color, color2: Color): Color; - export function exclusion(color1: Color, color2: Color): Color; - export function average(color1: Color, color2: Color): Color; - export function negation(color1: Color, color2: Color): Color; - export function tint(color: Color, amount: Dimension): Color; - export function shade(color: Color, amount: Dimension): Color; - } - - export var colors: any; // Could be module - got lazy - - interface HasDebugInfo { - debugInfo: DebugInfo; - } - - interface DebugInfo { - lineNumber; - fileName: string; - } - - interface HSL { - h: number; - s: number; - l: number; - a: number; - } - - interface DebugInfoFunction { - (env: Options, ctx: HasDebugInfo): string; - asComment(ctx: HasDebugInfo): string; - asMediaQuery(ctx: HasDebugInfo): string; - } - - interface RuleContainer { - [name: string]: Rule; - } - - interface ICSSable { - toCSS(ctx?, env?: Options): string; - } - - interface IEvalable { - eval(env: Options): IEvalable; - } - - interface IInjectable extends ICSSable, IEvalable {} - - interface IOperable { - operate(op: Operation, other: IOperable): IOperable; - } - - interface IComparable { - compare(x: IComparable): number; - } - - interface IColorable { - toColor(): Color; - } - - interface IValuableNumber { - value: number; - } - - interface IValuableString { - value: string; - } - - export class Color implements IOperable, IInjectable, IComparable { - constructor(rgb: string, a: number); - constructor(rgb: number[], a: number); - - rgb: number[]; - alpha: number; - eval(): Color; - toCSS(): string; - operate(op: Operation, other: Color): Color; - operate(op: Operation, other: IColorable): Color; - toHSL(): HSL; - toARGB(): string; - compare(x: Color): number; - } - - export class Directive implements IInjectable { - constructor(name, value); - - name; - value: ICSSable; - ruleset: Ruleset; - - toCSS(ctx?, env?: Options): string; - eval(env: Options): Directive; - - variable(name); - find(); - rulesets(); - } - - export class Operation implements IEvalable { - constructor(op, operands); - - op: string; - operands: IEvalable; - - eval(env: Options): IEvalable; - - operate(op: string, a: number, b: number): number; - } - - export class Dimension implements IColorable, IInjectable, IOperable, IComparable { - constructor(value: number, unit: string); - - value: number; - unit: string; - - eval(): Dimension; - toColor(): Color; - toCSS(): string; - operate(op: Operation, other: Dimension): Dimension; - compare(other: IComparable): number; - } - - export class Keyword implements IInjectable, IComparable { - constructor(value: string); - - value: string; - - eval(): Keyword; - toCSS(): string; - compare(other: IComparable): number; - - static True: Keyword; - static False: Keyword; - } - - export class Variable implements IEvalable { - constructor(name: string, index, file: string); - - name: string; - index; - file: string; - - eval(env: Options): IEvalable; - } - - export class AbstractRuleset implements IEvalable { - selectors: Selector[]; - rules: any[]; - strictImports; - - eval(env: Options): Ruleset; - evalImports(env: Options): void; - makeImportant(): Ruleset; - matchArgs(args: any): boolean; - resetCache(): void; - variables(): RuleContainer; - variable(): Rule; - rulesets(): Ruleset[]; - find(selector: Selector, self: Rule): Rule[]; - joinSelectors(paths: string[], context: any[][], selectors: Selector[]): void; - joinSelector(paths: string[], context: any[][], selector: Selector): void; - mergeElementsOnToSelectors(elements: Element[], selectors: Selector[]): void; - } - - export class Ruleset extends AbstractRuleset { - constructor(selectors: Selector[], rules: Rule[], strictImports); - - toCSS(context?: any[][], env?: Options): string; - } - - export class Element implements IInjectable { - constructor(combinator: Combinator, value, index); - - combinator: Combinator; - value; - index; - - eval(env: Options): Element; - toCSS(env?: Options): string; - } - - export class Combinator implements ICSSable { - constructor(value: string); - - value: string; - - toCSS(env?: Options): string; - } - - export class Selector implements IInjectable { - constructor(elements: Element[]); - - match(other: Selector): boolean; - eval(env: Options): Selector; - toCSS(env?: Options): string; - } - - export class Quoted implements IInjectable, IComparable { - constructor(str: string, content: string, escaped: boolean, i); - - escaped: boolean; - value: string; - quote: string; - index; - - toCSS(): string; - eval(env: Options): Quoted; - compare(x: IComparable): number; - } - - export class Expression implements IInjectable { - constructor(value: IEvalable[]); - - value: IEvalable[]; - - eval(env: Options): IEvalable; - toCSS(env?: Options): string; - } - - export class Rule implements IInjectable { - constructor(name: string, value?: Value, important?: string, index?, inline?: boolean); - - name: string; - value: Value; - important: string; - index; - inline: boolean; - - toCSS(env?: Options): string; - eval(context): Rule; - - makeImportant(): Rule; - } - - export class Shorthand implements IInjectable { - constructor(a: ICSSable, b: ICSSable); - - a: ICSSable; - b: ICSSable; - - toCSS(env?: Options): string; - eval(): Shorthand; - } - - export class Call implements IInjectable { - constructor(name: string, args: IEvalable[], index, filename: string); - - name: string; - args: IEvalable[]; - index; - filename: string; - - eval(env: Options): IEvalable; - toCSS(env?: Options): string; - } - - export class URL implements IInjectable { - constructor(val, rootpath: string); - - value; - rootpath: string; - - toCSS(): string; - eval(ctx): URL; - } - - export class Alpha implements IInjectable { - constructor(val); - - value; - - toCSS(): string; - eval(env: Options): Alpha; - } - - export class Import implements IInjectable { - constructor(path, imports, features: ICSSable, once: boolean, index, rootpath); - - once: boolean; - index; - features: ICSSable; - rootpath; - path: string; - css: boolean; - - toCSS(env?: Options): string; - eval(env: Options): IEvalable; - } - - export class Comment implements IInjectable { - constructor(value: string, silent); - - value: string; - silent: boolean; - - toCSS(env?: Options): string; - eval(): Comment; - } - - export class Anonymous implements IInjectable, IComparable { - constructor(value: string); - - value: string; - - toCSS(): string; - eval(): Anonymous; - compare(x): number; - } - - export class Value implements IInjectable { - constructor(value: IEvalable[]); - - value: IEvalable[]; - is: string; - - eval(env: Options): IEvalable; - toCSS(env?: Options): string; - } - - export class JavaScript implements IEvalable { - constructor(expression: string, index, escaped: boolean); - - escaped: boolean; - expression: string; - index; - - eval(env: Options): IEvalable; - } - - export class Assignment implements IInjectable { - constructor(key: string, val); - constructor(key: string, val: ICSSable); - constructor(key: string, val: IEvalable); - - key: string; - value; - - toCSS(): string; - eval(env: Options): Assignment; - } - - export class Condition { - constructor(op: string, l, r, i, negate: boolean); - - op: string; - lvalue; - rvalue; - index; - negate: boolean; - - eval(env: Options): boolean; - } - - export class Paren implements IInjectable { - constructor(node: IInjectable); - value: IInjectable; - - toCSS(env?: Options): string; - eval(env: Options): Paren; - } - - export class Media implements IInjectable { - constructor(value, features); - - selectors: Selector[]; - features: Value; - ruleset: Ruleset; - - toCSS(ctx?, env?: Options): string; - eval(env: Options): IEvalable; - - variable(name): Rule; - rulesets(): Ruleset[]; - find(selector: Selector, self: Rule): Rule[]; - - emptySelectors(): Selector[]; - evalTop(env: Options): IEvalable; - evalNested(env: Options): Ruleset; - permute(arr: any[]): any[]; - bubbleSelectors(selectors: Selector[]): void; - } - - export class Ratio implements IInjectable { - constructor(value: string); - - value: string; - - toCSS(env?: Options): string; - eval(): Ratio; - } - - export class UnicodeDescriptor implements IInjectable { - constructor(value: string); - - value: string; - - toCSS(env?: Options): string; - eval(): UnicodeDescriptor; - } - - export class Attribute implements IInjectable { - constructor(value: string); - - value: string; - - toCSS(env?: Options): string; - genCSS(env: Options, output): string; - eval(): Attribute; - } - - export var debugInfo: DebugInfoFunction; - export function find(obj: any[], fun: Function): any; - export function jsify(obj: any): string; - export function operate(op: string, a: number, b: number): number; - - export var True: Keyword; - export var False: Keyword; + interface RenderOutput { + css: string; + map: string; + imports: string[]; } +} - class ParserNode extends tree.AbstractRuleset { - toCSS(): string; - toCSS(options: { compress: boolean; }, variables?): string; - } +interface LessStatic { + render(input: string, callback: (output: Less.RenderOutput) => void): void; + render(input: string, options: Less.Options, callback: (output: Less.RenderOutput) => void): void; - export class Parser { - constructor(env?: Options); + render(input: string): Less.Promise; + render(input: string, options: Less.Options): Less.Promise; - imports: { - paths: string[]; - queue: string[]; - files; - contents; - mime: string; - error; - push(path: string, callback: (e, root, imported) => void); - }; // TODO - - parse: (str: string, callback: (error: LessError, root: ParserNode) => void ) => void; - - parsers: { // Major TODO - }; - } - - export function render(input: string, callback: (e, css: string) => void): void; - export function render(input: string, options: Options, - callback: (e, css: string) => void): void; - - export function formatError(ctx, options: { color: boolean; }): string; - export function writeError(ctx, options: { color: boolean; }): void; - - export var version: number[]; + version: number[]; } declare module "less" { - export = less; + export = less; } + +declare var less: LessStatic; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 426162e2e..55d35707f 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -5745,6 +5745,18 @@ declare module _ { **/ isEmpty(value: any): boolean; } + + //_.isError + interface LoDashStatic { + /** + * Checks if value is an Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, + * or URIError object. + * @param value The value to check. + * @return True if value is an error object, else false. + */ + isError(value: any): boolean; + } + //_.isEqual interface LoDashStatic { diff --git a/marionette/marionette.d.ts b/marionette/marionette.d.ts index ee528b666..2b9b25635 100644 --- a/marionette/marionette.d.ts +++ b/marionette/marionette.d.ts @@ -38,7 +38,7 @@ declare module Backbone { include(value: any): boolean; initial(): View; initial(n: number): View[]; - invoke(methodName: string, arguments?: any[]): any; + invoke(methodName: string, args?: any[]): any; isEmpty(object: any): boolean; last(): View; last(n: number): View[]; @@ -533,7 +533,7 @@ declare module Marionette { * Calls the method named by methodName on each value in the collection. Any extra * arguments passed to invoke will be forwarded on to the method invocation. */ - invoke(methodName: string, arguments?: any[]): any; + invoke(methodName: string, args?: any[]): any; /** * Returns true if the RegionManager contains no regions. diff --git a/mozilla-spidermonkey-parser-api/mozilla-spidermonkey-parser-api-tests.ts b/mozilla-spidermonkey-parser-api/mozilla-spidermonkey-parser-api-tests.ts deleted file mode 100644 index 76dba72a5..000000000 --- a/mozilla-spidermonkey-parser-api/mozilla-spidermonkey-parser-api-tests.ts +++ /dev/null @@ -1,127 +0,0 @@ -/// - -import Syntax = spiderMonkeyParserAPI.Syntax; - -var literal:Syntax.Literal = { - loc: { - source: null, - start: { - line: 1, - column: 10 - }, - end: { - line: 1, - column: 12 - } - }, - type: "Literal", - value: 42 -}; - -// generated by http://esprima.org/demo/parse.html?code=%22use%20strict%22%3B%0A%0Afunction%20Test%20()%20%7B%0A%7D%0A%0ATest.prototype.hello%20%3D%20function(word)%20%7B%0A%09word%20%3D%20word%20%7C%7C%20%22TypeScript%22%3B%0A%09return%20word%3B%0A%7D%3B%0A -var program:Syntax.Program = { - "type": "Program", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "Literal", - "value": "use strict", - "raw": "\"use strict\"" - } - }, - { - "type": "FunctionDeclaration", - "id": { - "type": "Identifier", - "name": "Test" - }, - "params": [], - "defaults": [], - "body": { - "type": "BlockStatement", - "body": [] - }, - "rest": null, - "generator": false, - "expression": false - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "Identifier", - "name": "Test" - }, - "property": { - "type": "Identifier", - "name": "prototype" - } - }, - "property": { - "type": "Identifier", - "name": "hello" - } - }, - "right": { - "type": "FunctionExpression", - "id": null, - "params": [ - { - "type": "Identifier", - "name": "word" - } - ], - "defaults": [], - "body": { - "type": "BlockStatement", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "word" - }, - "right": { - "type": "LogicalExpression", - "operator": "||", - "left": { - "type": "Identifier", - "name": "word" - }, - "right": { - "type": "Literal", - "value": "TypeScript", - "raw": "\"TypeScript\"" - } - } - } - }, - { - "type": "ReturnStatement", - "argument": { - "type": "Identifier", - "name": "word" - } - } - ] - }, - "rest": null, - "generator": false, - "expression": false - } - } - } - ] -}; diff --git a/mozilla-spidermonkey-parser-api/mozilla-spidermonkey-parser-api.d.ts b/mozilla-spidermonkey-parser-api/mozilla-spidermonkey-parser-api.d.ts deleted file mode 100644 index e91029137..000000000 --- a/mozilla-spidermonkey-parser-api/mozilla-spidermonkey-parser-api.d.ts +++ /dev/null @@ -1,614 +0,0 @@ -// Type definitions for Mozilla SpiderMonkey Parser API 1.8.5 -// Project: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Parser_API -// Definitions by: vvakame -// Definitions: https://github.com/borisyankov/DefinitelyTyped - -declare module spiderMonkeyParserAPI { - - // NOTE if property can hold null, that property to be optional. - - module Syntax { - /** - * By default, Reflect.parse() produces Node objects, which are plain JavaScript objects (i.e., their prototype derives from the standard Object prototype). - * All node types implement the following interface: - */ - interface Node { - /** - * The type field is a string representing the AST variant type. - * Each subtype of Node is documented below with the specific string of its type field. - * You can use this field to determine which interface a node implements. - */ - type: string; - /** - * The loc field represents the source location information of the node. - * If the parser produced no information about the node's source location, the field is null; otherwise it is an object consisting of a start position (the position of the first character of the parsed source region) and an end position (the position of the first character after the parsed source region): - */ - loc?: SourceLocation; - } - - interface SourceLocation { - source?: string; - start: Position; - end: Position; - } - - /** - * Each Position object consists of a line number (1-indexed) and a column number (0-indexed): - */ - interface Position { - line: number; // uint32 >= 1; - column: number; // uint32 >= 0; - } - - /** - * A complete program source tree. - */ - interface Program extends Node { - type: string; // "Program" - body: Statement[]; - } - - /** - * A function declaration or expression. - * The body of the function may be a block statement, or in the case of an expression closure, an expression. - * If the generator flag is true, the function is a generator function, i.e., contains a yield expression in its body (other than in a nested function). - * If the expression flag is true, the function is an expression closure and the body field is an expression. - */ - interface Function extends Node { - id?: Identifier; - params: Pattern[]; - defaults: Expression[]; - rest?: Identifier; - body?: BlockStatement | Expression; - generator: boolean; - expression: boolean; - } - - /** - * Any statement. - */ - interface Statement extends Node { - } - - /** - * An empty statement, i.e., a solitary semicolon. - */ - interface EmptyStatement extends Statement { - type: string; // "EmptyStatement"; - } - - /** - * A block statement, i.e., a sequence of statements surrounded by braces. - */ - interface BlockStatement extends Statement { - type: string; // "BlockStatement"; - body: Statement[]; - } - - /** - * An if statement. - */ - interface IfStatement extends Statement { - type: string; // "IfStatement"; - test: Expression; - consequent: Statement; - alternate?: Statement; - } - - /** - * A labeled statement, i.e., a statement prefixed by a break/continue label. - */ - interface LabeledStatement extends Statement { - type: string; // "LabeledStatement"; - label: Identifier; - body: Statement; - } - - /** - * A break statement. - */ - interface BreakStatement extends Statement { - type: string; // "BreakStatement"; - label?: Identifier; - } - - /** - * A continue statement. - */ - interface ContinueStatement extends Statement { - type: string; // "ContinueStatement"; - label?: Identifier; - } - - /** - * A with statement. - */ - interface WithStatement extends Statement { - type: string; // "WithStatement"; - object: Expression; - body: Statement; - } - - /** - * A switch statement. - * The lexical flag is metadata indicating whether the switch statement contains any unnested let declarations (and therefore introduces a new lexical scope). - */ - interface SwitchStatement extends Statement { - type: string; // "SwitchStatement"; - discriminant: Expression; - cases: SwitchCase[]; - lexical: boolean; - } - - /** - * A return statement. - */ - interface ReturnStatement extends Statement { - type: string; // "ReturnStatement"; - argument?: Expression; - } - - /** - * A throw statement. - */ - interface ThrowStatement extends Statement { - type: string; // "ThrowStatement"; - argument: Expression; - } - - /** - * A try statement. - */ - interface TryStatement extends Statement { - type: string; //"TryStatement"; - block: BlockStatement; - handler?: CatchClause; - guardedHandlers: CatchClause[]; - finalizer?: BlockStatement; - } - - /** - * A while statement. - */ - interface WhileStatement extends Statement { - type: string; // "WhileStatement"; - test: Expression; - body: Statement; - } - - /** - * A do/while statement. - */ - interface DoWhileStatement extends Statement { - type: string; // "DoWhileStatement"; - body: Statement; - test: Expression; - } - - /** - * A for statement. - */ - interface ForStatement extends Statement { - type: string; // "ForStatement"; - init?: VariableDeclaration | Expression; - test?: Expression; - update?: Expression; - body: Statement; - } - - /** - * A for/in statement, or, if each is true, a for each/in statement. - */ - interface ForInStatement extends Statement { - type: string; // "ForInStatement"; - left: VariableDeclaration | Expression; - right: Expression; - body: Statement; - each: boolean; - } - - /** - * A for/of statement. - */ - interface ForOfStatement extends Statement { - type: string; // "ForOfStatement"; - left: VariableDeclaration | Expression; - right: Expression; - body: Statement; - } - - /** - * A let statement. - */ - interface LetStatement extends Statement { - type: string; // "LetStatement"; - head: VariableDeclarator[]; - body: Statement; - } - - /** - * A debugger statement. - */ - interface DebuggerStatement extends Statement { - type: string; // "DebuggerStatement"; - } - - /** - * Any declaration node. Note that declarations are considered statements; this is because declarations can appear in any statement context in the language recognized by the SpiderMonkey parser. - */ - interface Declaration extends Statement { - } - - /** - * A function declaration. - */ - interface FunctionDeclaration extends Function, Declaration { - type: string; // "FunctionDeclaration"; - id: Identifier; // Note: The id field cannot be null. - params: Pattern[]; - defaults: Expression[]; - rest?: Identifier; - body: BlockStatement | Expression; - generator: boolean; - expression: boolean; - } - - /** - * A variable declaration, via one of var, let, or const. - */ - interface VariableDeclaration extends Declaration { - type: string; // "VariableDeclaration"; - declarations: VariableDeclarator[]; - kind: string; // "var" | "let" | "const"; - } - - /** - * A variable declarator. - */ - interface VariableDeclarator extends Node { - type: string; // "VariableDeclarator"; - id: Pattern; // Note: The id field cannot be null. - init?: Expression; - } - - /** - * Any expression node. - * Since the left-hand side of an assignment may be any expression in general, an expression can also be a pattern. - */ - interface Expression extends Node, Pattern { - } - - /** - * A this expression. - */ - interface ThisExpression extends Expression { - type: string; // "ThisExpression"; - } - - /** - * An array expression. - */ - interface ArrayExpression extends Expression { - type: string; // "ArrayExpression"; - elements: Expression[]; // [ Expression | null ]; - } - - /** - * An object expression. - */ - interface ObjectExpression extends Expression { - type: string; // "ObjectExpression"; - properties: Property[]; - } - - /** - * A literal property in an object expression can have either a string or number as its value. - * Ordinary property initializers have a kind value "init"; getters and setters have the kind values "get" and "set", respectively. - */ - interface Property extends Node { - type: string; // "Property"; - key: Literal | Identifier; - value: Expression; - kind: string; // "init" | "get" | "set"; - } - - /** - * A function expression. - */ - interface FunctionExpression extends Function, Expression { - type: string; // "FunctionExpression"; - id?: Identifier; - params: Pattern[]; - defaults: Expression[]; - rest?: Identifier; - body: BlockStatement | Expression; - generator: boolean; - expression: boolean; - } - - /** - * A fat arrow function expression, i.e., `let foo = (bar) => { ... body ... }`. - */ - interface ArrowExpression extends Function, Expression { - type: string; // "ArrowExpression"; - params: Pattern[]; - defaults: Expression[]; - rest?: Identifier; - body: BlockStatement | Expression; - generator: boolean; - expression: boolean; - } - - /** - * A sequence expression, i.e., a comma-separated sequence of expressions. - */ - interface SequenceExpression extends Expression { - type: string; // "SequenceExpression"; - expressions: Expression[]; - } - - /** - * A unary operator expression. - */ - interface UnaryExpression extends Expression { - type: string; // "UnaryExpression"; - operator: UnaryOperator; - prefix: boolean; - argument: Expression; - } - - /** - * A binary operator expression. - */ - interface BinaryExpression extends Expression { - type: string; // "BinaryExpression"; - operator: BinaryOperator; - left: Expression; - right: Expression; - } - - /** - * An assignment operator expression. - */ - interface AssignmentExpression extends Expression { - type: string; // "AssignmentExpression"; - operator: AssignmentOperator; - left: Expression; - right: Expression; - } - - /** - * An update (increment or decrement) operator expression. - */ - interface UpdateExpression extends Expression { - type: string; // "UpdateExpression"; - operator: UpdateOperator; - argument: Expression; - prefix: boolean; - } - - /** - * A logical operator expression. - */ - interface LogicalExpression extends Expression { - type: string; // "LogicalExpression"; - operator: LogicalOperator; - left: Expression; - right: Expression; - } - - /** - * A conditional expression, i.e., a ternary ?/: expression. - */ - interface ConditionalExpression extends Expression { - type: string; // "ConditionalExpression"; - test: Expression; - alternate: Expression; - consequent: Expression; - } - - /** - * A new expression. - */ - interface NewExpression extends Expression { - type: string; // "NewExpression"; - callee: Expression; - arguments: Expression[]; - } - - /** - * A function or method call expression. - */ - interface CallExpression extends Expression { - type: string; // "CallExpression"; - callee: Expression; - arguments: Expression[]; - } - - /** - * A member expression. - * If computed === true, the node corresponds to a computed e1[e2] expression and property is an Expression. - * If computed === false, the node corresponds to a static e1.x expression and property is an Identifier. - */ - interface MemberExpression extends Expression { - type: string; // "MemberExpression"; - object: Expression; - property: Identifier | Expression; - computed: boolean; - } - - /** - * A yield expression. - */ - interface YieldExpression extends Expression { - type: string; // "YieldExpression"; - argument?: Expression; - } - - /** - * An array comprehension. - * The blocks array corresponds to the sequence of for and for each blocks. - * The optional filter expression corresponds to the final if clause, if present. - */ - interface ComprehensionExpression extends Expression { - type: string; // "ComprehensionExpression"; - body: Expression; - blocks: ComprehensionBlock[]; - filter?: Expression; - } - - /** - * A generator expression. - * As with array comprehensions, the blocks array corresponds to the sequence of for and for each blocks, and the optional filter expression corresponds to the final if clause, if present. - */ - interface GeneratorExpression extends Expression { - type: string; // "GeneratorExpression"; - body: Expression; - blocks: ComprehensionBlock[]; - filter?: Expression; - } - - /** - * A graph expression, aka "sharp literal," such as #1={ self: #1# }. - */ - interface GraphExpression extends Expression { - type: string; // "GraphExpression"; - index: number; // uint32; - expression: Literal; - } - - /** - * A graph index expression, aka "sharp variable," such as #1#. - */ - interface GraphIndexExpression extends Expression { - type: string; // "GraphIndexExpression"; - index: number; // uint32; - } - - /** - * A let expression. - */ - interface LetExpression extends Expression { - type: string; // "LetExpression"; - head: VariableDeclarator[]; - body: Expression; - } - - /** - * JavaScript 1.7 introduced destructuring assignment and binding forms. - * All binding forms (such as function parameters, variable declarations, and catch block headers) accept array and object destructuring patterns in addition to plain identifiers. - * The left-hand sides of assignment expressions can be arbitrary expressions, but in the case where the expression is an object or array literal, it is interpreted by SpiderMonkey as a destructuring pattern. - * - * Since the left-hand side of an assignment can in general be any expression, in an assignment context, a pattern can be any expression. - * In binding positions (such as function parameters, variable declarations, and catch headers), patterns can only be identifiers in the base case, not arbitrary expressions. - */ - interface Pattern extends Node { - } - - /** - * An object-destructuring pattern. A literal property in an object pattern can have either a string or number as its value. - */ - interface ObjectPattern extends Pattern { - type: string; // "ObjectPattern"; - properties: {key: Literal | Identifier; value: Pattern;}[]; // [ { key: Literal | Identifier, value: Pattern } ]; - } - - /** - * An array-destructuring pattern. - */ - interface ArrayPattern extends Pattern { - type: string; // "ArrayPattern"; - elements: Pattern[]; // [ Pattern | null ]; - } - - /** - * A case (if test is an Expression) or default (if test === null) clause in the body of a switch statement. - */ - interface SwitchCase extends Node { - type: string; // "SwitchCase"; - test?: Expression; - consequent: Statement[]; - } - - /** - * A catch clause following a try block. - * The optional guard property corresponds to the optional expression guard on the bound variable. - */ - interface CatchClause extends Node { - type: string; // "CatchClause"; - param: Pattern; - guard?: Expression; - body: BlockStatement; - } - - /** - * A for or for each block in an array comprehension or generator expression. - */ - interface ComprehensionBlock extends Node { - type: string; // "ComprehensionBlock"; - left: Pattern; - right: Expression; - each: boolean; - } - - /** - * An identifier. - * Note that an identifier may be an expression or a destructuring pattern. - */ - interface Identifier extends Node, Expression, Pattern { - type: string; // "Identifier"; - name: string; - } - - /** - * A literal token. Note that a literal can be an expression. - */ - interface Literal extends Node, Expression { - type: string; // "Literal"; - value?: string | boolean | number | RegExp; - } - - /** - * A unary operator token. - */ - interface UnaryOperator extends String { - // "-" | "+" | "!" | "~" | "typeof" | "void" | "delete" - } - - /** - * A binary operator token. - */ - interface BinaryOperator extends String { - // "==" | "!=" | "===" | "!==" - // | "<" | "<=" | ">" | ">=" - // | "<<" | ">>" | ">>>" - // | "+" | "-" | "*" | "/" | "%" - // | "|" | "^" | "&" | "in" - // | "instanceof" | ".." - // Note: The .. operator is E4X-specific. - } - - /** - * A logical operator token. - */ - interface LogicalOperator extends String { - // "||" | "&&" - } - - /** - * An assignment operator token. - */ - interface AssignmentOperator extends String { - // "=" | "+=" | "-=" | "*=" | "/=" | "%=" - // | "<<=" | ">>=" | ">>>=" - // | "|=" | "^=" | "&=" - } - - /** - * An update (increment or decrement) operator token. - */ - interface UpdateOperator extends String { - // "++" | "--" - } - } -} diff --git a/ng-grid/ng-grid-tests.ts b/ng-grid/ng-grid-tests.ts index 82105ea5b..d8d153f28 100644 --- a/ng-grid/ng-grid-tests.ts +++ b/ng-grid/ng-grid-tests.ts @@ -63,7 +63,7 @@ selectionProvider.selectedItems = []; selectionProvider.selectedIndex = 1; selectionProvider.lastClickedRow = {}; selectionProvider.ignoreSelectedItemChanges = false; -selectionProvider.pKeyParser = {}; +selectionProvider.pKeyParser = {}; selectionProvider.ChangeSelection({}, {}); nr = selectionProvider.getSelection({}); nr = selectionProvider.getSelectionIndex({}); @@ -256,15 +256,15 @@ nr = gridScope.totalRowWidth(); a = gridScope.headerScrollerDim(); var gridInstance: ngGrid.IGridInstance = {}; -gridInstance.$canvas = {}; -gridInstance.$viewport = {}; -gridInstance.$groupPanel = {}; -gridInstance.$footerPanel = {}; -gridInstance.$headerScroller = {}; -gridInstance.$headerContainer = {}; -gridInstance.$headers = {}; -gridInstance.$topPanel = {}; -gridInstance.$root = {}; +gridInstance.$canvas = {}; +gridInstance.$viewport = {}; +gridInstance.$groupPanel = {}; +gridInstance.$footerPanel = {}; +gridInstance.$headerScroller = {}; +gridInstance.$headerContainer = {}; +gridInstance.$headers = {}; +gridInstance.$topPanel = {}; +gridInstance.$root = {}; gridInstance.config = {}; gridInstance.data = {}; gridInstance.elementDims = {}; @@ -290,7 +290,7 @@ gridInstance.clearSortingData(); gridInstance.configureColumnWidths(); gridInstance.fixColumnIndexes(); gridInstance.fixGroupIndexes(); -var p:ng.IPromise = gridInstance.getTemplate(''); +var p:angular.IPromise = gridInstance.getTemplate(''); p = gridInstance.init(); p = gridInstance.initTemplates(); gridInstance.minRowsToRender(); @@ -302,12 +302,12 @@ gridInstance.sortColumnsInit(); gridInstance.sortData({}, {}); var test_styleProvider:ngGrid.IStyleProvider = new ngStyleProvider({}, {}); -var test_searchProvider:ngGrid.ISearchProvider = new ngSearchProvider({}, {}, {}); -var test_selectionProvider:ngGrid.ISelectionProvider = new ngSelectionProvider({}, {}, {}); -var test_eventProvider:ngGrid.IEventProvider = new ngEventProvider({}, {}, {}, {}); +var test_searchProvider:ngGrid.ISearchProvider = new ngSearchProvider({}, {}, {}); +var test_selectionProvider:ngGrid.ISelectionProvider = new ngSelectionProvider({}, {}, {}); +var test_eventProvider:ngGrid.IEventProvider = new ngEventProvider({}, {}, {}, {}); var test_aggregate:ngGrid.IAggregate = new ngAggregate({}, {}, 10, true); var test_renderedRange:ngGrid.IRenderedRange = new ngRenderedRange(1, 2); var test_dimension:ngGrid.IDimension = new ngDimension({}); var test_row:ngGrid.IRow = new ngRow({}, {}, {}, 0, {}); -var test_column:ngGrid.IColumn = new ngColumn({}, {}, {}, {}, {}, {}); +var test_column:ngGrid.IColumn = new ngColumn({}, {}, {}, {}, {}, {}); var test_footer:ngGrid.IFooter = new ngFooter({}, {}); diff --git a/ng-grid/ng-grid.d.ts b/ng-grid/ng-grid.d.ts index 3bb3b2daa..0fb267faa 100644 --- a/ng-grid/ng-grid.d.ts +++ b/ng-grid/ng-grid.d.ts @@ -30,9 +30,9 @@ declare module ngGrid { export interface IDomAccessProvider { previousColumn:IColumn; grid:IGridInstance; - changeUserSelect(elm:ng.IAugmentedJQuery, value:string):void; + changeUserSelect(elm:angular.IAugmentedJQuery, value:string):void; focusCellElement($scope:IGridScope, index:number):void; - selectionHandlers($scope:IGridScope, elm:ng.IAugmentedJQuery):void; + selectionHandlers($scope:IGridScope, elm:angular.IAugmentedJQuery):void; } export interface IStyleProviderStatic { @@ -43,7 +43,7 @@ declare module ngGrid { } export interface ISearchProviderStatic { - new($scope:IGridScope, grid:IGridInstance, $filter:ng.IFilterService):ISearchProvider; + new($scope:IGridScope, grid:IGridInstance, $filter:angular.IFilterService):ISearchProvider; } export interface ISearchProvider { @@ -53,7 +53,7 @@ declare module ngGrid { } export interface ISelectionProviderStatic { - new(grid:IGridInstance, $scope:IGridScope, $parse:ng.IParseService):ISelectionProvider; + new(grid:IGridInstance, $scope:IGridScope, $parse:angular.IParseService):ISelectionProvider; } export interface ISelectionProvider { @@ -62,7 +62,7 @@ declare module ngGrid { selectedIndex:number; lastClickedRow:any; ignoreSelectedItemChanges:boolean; - pKeyParser:ng.ICompiledExpression; + pKeyParser:angular.ICompiledExpression; ChangeSelection(rowItem:any, event:any):void; getSelection(entity:any):number; getSelectionIndex(entity:any):number; @@ -71,7 +71,7 @@ declare module ngGrid { } export interface IEventProviderStatic { - new(grid:IGridInstance, $scope:IGridScope, domUtilityService:service.IDomUtilityService, $timeout:ng.ITimeoutService):IEventProvider; + new(grid:IGridInstance, $scope:IGridScope, domUtilityService:service.IDomUtilityService, $timeout:angular.ITimeoutService):IEventProvider; } export interface IEventProvider { @@ -203,7 +203,7 @@ declare module ngGrid { } export interface IColumnStatic { - new(config:IGridOptions, $scope:IGridScope, grid:IGridInstance, domUtilityService:service.IDomUtilityService, $templateCache:ng.ITemplateCacheService, $utils:any):IColumn; + new(config:IGridOptions, $scope:IGridScope, grid:IGridInstance, domUtilityService:service.IDomUtilityService, $templateCache:angular.ITemplateCacheService, $utils:any):IColumn; } export interface IColumn { @@ -251,7 +251,7 @@ declare module ngGrid { setVars(fromCol:IColumn):void; } - export interface IGridScope extends ng.IScope { + export interface IGridScope extends angular.IScope { elementsNeedMeasuring:boolean; columns:any[]; renderedRows:any[]; @@ -292,15 +292,15 @@ declare module ngGrid { } export interface IGridInstance { - $canvas:ng.IAugmentedJQuery; - $viewport:ng.IAugmentedJQuery; - $groupPanel:ng.IAugmentedJQuery; - $footerPanel:ng.IAugmentedJQuery; - $headerScroller:ng.IAugmentedJQuery; - $headerContainer:ng.IAugmentedJQuery; - $headers:ng.IAugmentedJQuery; - $topPanel:ng.IAugmentedJQuery; - $root:ng.IAugmentedJQuery; + $canvas:angular.IAugmentedJQuery; + $viewport:angular.IAugmentedJQuery; + $groupPanel:angular.IAugmentedJQuery; + $footerPanel:angular.IAugmentedJQuery; + $headerScroller:angular.IAugmentedJQuery; + $headerContainer:angular.IAugmentedJQuery; + $headers:angular.IAugmentedJQuery; + $topPanel:angular.IAugmentedJQuery; + $root:angular.IAugmentedJQuery; config:IGridOptions; data:any; elementDims:IElementDimension; @@ -327,9 +327,9 @@ declare module ngGrid { configureColumnWidths():void; fixColumnIndexes():void; fixGroupIndexes():void; - getTemplate(key:string):ng.IPromise; - init():ng.IPromise; - initTemplates():ng.IPromise; + getTemplate(key:string):angular.IPromise; + init():angular.IPromise; + initTemplates():angular.IPromise; minRowsToRender():void; refreshDomSizes():void; resizeOnData(col:IColumn):void; @@ -602,7 +602,7 @@ declare module ngGrid { eventStorage:any; numberOfGrids:number; immediate:number; - AssignGridContainers($scope:IGridScope, rootel:ng.IAugmentedJQuery, grid:IGridInstance):void; + AssignGridContainers($scope:IGridScope, rootel:angular.IAugmentedJQuery, grid:IGridInstance):void; getRealWidth(obj:IDimension):number; UpdateGridLayout($scope:IGridScope, grid:IGridInstance):void; setStyleText(grid:IGridInstance, css:string):void; diff --git a/node-azure/azure.d.ts b/node-azure/azure.d.ts index 91c5c0bf0..7e52a8be3 100644 --- a/node-azure/azure.d.ts +++ b/node-azure/azure.d.ts @@ -832,8 +832,8 @@ declare module "azure" { whereKeys(partitionKey: string, rowKey: string): TableQuery; whereNextKeys(partitionKey: string, rowKey: string): TableQuery; where(condition: string, ...values: string[]): TableQuery; - and(condition: string, ...arguments: string[]): TableQuery; - or(condition: string, ...arguments: string[]): TableQuery; + and(condition: string, ...args: string[]): TableQuery; + or(condition: string, ...args: string[]): TableQuery; top(integer: number): TableQuery; toQueryObject(): any; toPath(): string; diff --git a/sanitizer/sanitizer-tests.ts b/sanitizer/sanitizer-tests.ts new file mode 100644 index 000000000..6a4c8982d --- /dev/null +++ b/sanitizer/sanitizer-tests.ts @@ -0,0 +1,53 @@ +/// + +import sanitizer = require('sanitizer'); + +// example copied from the tests https://github.com/theSmaw/Caja-HTML-Sanitizer/blob/master/test/test-sanitizer.js#L346 +var events:any[] = []; +var addTextEvent = function(type:string, text:string, param:any) { + var n = events.length; + + if (events[n - 3] === type && events[n - 1] === param) { + events[n - 2] += text; + } else { + events.push(type, text, param); + } +}; + +sanitizer.makeSaxParser({ + startTag: function(name, attribs, param) { + events.push('startTag', name + '[' + attribs.join(';') + ']', param); + }, + + endTag: function(name, param) { + events.push('endTag', name, param); + }, + + pcdata: function(text, param) { + addTextEvent('pcdata', text, param); + }, + + cdata: function(text, param) { + addTextEvent('cdata', text, param); + }, + + rcdata: function(text, param) { + addTextEvent('rcdata', text, param); + }, + + comment: function(text, param) { + events.push('comment', text, param); + }, + + startDoc: function(param) { + events.push('startDoc', '', param); + }, + + endDoc: function(param) { + events.push('endDoc', '', param); + } +}); +sanitizer.escape(''); +sanitizer.sanitize(''); +sanitizer.normalizeRCData(''); +sanitizer.unescapeEntities(''); diff --git a/sanitizer/sanitizer.d.ts b/sanitizer/sanitizer.d.ts new file mode 100644 index 000000000..16d9448c9 --- /dev/null +++ b/sanitizer/sanitizer.d.ts @@ -0,0 +1,27 @@ +// Type definitions for Sanitizer +// Project: https://github.com/theSmaw/Caja-HTML-Sanitizer +// Definitions by: Dave Taylor +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module 'sanitizer' { + export interface ISaxHandler { + startTag(name:string, attribs:string[], param:any):void; + endTag(name:string, param:any):void; + pcdata(text:string, param:any):void; + cdata(text:string, param:any):void; + rcdata(text:string, param:any):void; + comment(text:string, param:any):void; + startDoc(param:any):void; + endDoc(param:any):void; + } + + export function escape(s:string):string; + + export function makeSaxParser(yourHandler:ISaxHandler):(...any:any[])=>any; + + export function normalizeRCData(s:string):string; + + export function sanitize(s:string):string; + + export function unescapeEntities(s:string):string; +} diff --git a/sweetalert/sweetalert-tests.ts b/sweetalert/sweetalert-tests.ts new file mode 100644 index 000000000..1ccb93ba3 --- /dev/null +++ b/sweetalert/sweetalert-tests.ts @@ -0,0 +1,93 @@ +/// + +// A basic message +swal("Here's a message!"); + +// A title with a text under +swal("Here's a message!", "It's pretty, isn't it?"); + +// A success message! +swal("Good job!", "You clicked the button!", "success"); + +// A warning message, with a function attached to the "Confirm"-button... +swal({ + title: "Are you sure?", + text: "You will not be able to recover this imaginary file!", + type: "warning", + showCancelButton: true, + confirmButtonColor: "#DD6B55", + confirmButtonText: "Yes, delete it!", + closeOnConfirm: false +}, + function () { + swal("Deleted!", "Your imaginary file has been deleted.", "success"); + }); + +// ... and by passing a parameter, you can execute something else for "Cancel". +swal({ + title: "Are you sure?", + text: "You will not be able to recover this imaginary file!", + type: "warning", + showCancelButton: true, + confirmButtonColor: "#DD6B55", + confirmButtonText: "Yes, delete it!", + cancelButtonText: "No, cancel plx!", + closeOnConfirm: false, + closeOnCancel: false +}, + function (isConfirm) { + if (isConfirm) { + swal("Deleted!", "Your imaginary file has been deleted.", "success"); + } else { + swal("Cancelled", "Your imaginary file is safe :)", "error"); + } + }); + +// A message with a custom icon +swal({ + title: "Sweet!", + text: "Here's a custom image.", + imageUrl: "images/thumbs-up.jpg" +}); + +// An HTML message +swal({ + title: "HTML Title!", + text: "A custom html message.", + html: true +}); + +// A message with auto close timer +swal({ + title: "Auto close alert!", + text: "I will close in 2 seconds.", + timer: 2000, + showConfirmButton: false +}); + +// A replacement for the "prompt" function +swal({ + title: "An input!", + text: "Write something interesting:", + type: "input", + showCancelButton: true, + closeOnConfirm: false, + animation: "slide-from-top" +}, + function (inputValue) { + if (inputValue === false) return false; + + if (inputValue === "") { + swal.showInputError("You need to write something!"); + return false; + } + + swal("Nice!", "You wrote: " + inputValue, "success"); + } + ); + +swal.setDefaults({ confirmButtonColor: "#000000" }); + +swal.close(); + +swal.showInputError("Invalid email!"); \ No newline at end of file diff --git a/sweetalert/sweetalert.d.ts b/sweetalert/sweetalert.d.ts new file mode 100644 index 000000000..d5b4cd607 --- /dev/null +++ b/sweetalert/sweetalert.d.ts @@ -0,0 +1,181 @@ +// Type definitions for SweetAlert 0.5.0 +// Project: https://github.com/t4t5/sweetalert/ +// Definitions by: Markus Peloso +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare var sweetAlert: SweetAlert.SweetAlertStatic; +declare var swal: SweetAlert.SweetAlertStatic; + +declare module "sweetalert" { + export = swal; +} + +declare module SweetAlert { + interface SettingsBase { + /** + * A description for the modal. + * Default: null + */ + text?: string; + + /** + * The type of the modal. SweetAlert comes with 4 built-in types which will show a corresponding icon animation: "warning", "error", "success" and "info". You can also set it as "input" to get a prompt modal. + * Default: null + */ + type?: string; + + /** + * If set to true, the user can dismiss the modal by pressing the Escape key. + * Default: true + */ + allowEsxcapeKey?: boolean; + + /** + * A custom CSS class for the modal. + * Default: null + */ + customClass?: string; + + /** + * If set to true, the user can dismiss the modal by clicking outside it. + * Default: false + */ + allowOutsideClick?: boolean; + + /** + * If set to true, a "Cancel"-button will be shown, which the user can click on to dismiss the modal. + * Default: false + */ + showCancelButton?: boolean; + + /** + * If set to false, the "OK/Confirm"-button will be hidden. Make sure you set a timer or set allowOutsideClick to true when using this, in order not to annoy the user. + * Default: true + */ + showConfirmButton?: boolean; + + /** + * Use this to change the text on the "Confirm"-button. If showCancelButton is set as true, the confirm button will automatically show "Confirm" instead of "OK". + * Default: "OK" + */ + confirmButtonText?: string; + + /** + * Use this to change the background color of the "Confirm"-button (must be a HEX value). + * Default: "#AEDEF4" + */ + confirmButtonColor?: string; + + /** + * Use this to change the text on the "Cancel"-button. + * Default: "Cancel" + */ + cancelButtonText?: string; + + /** + * Set to false if you want the modal to stay open even if the user presses the "Confirm"-button. This is especially useful if the function attached to the "Confirm"-button is another SweetAlert. + * Default: true + */ + closeOnConfirm?: boolean; + + /** + * Add a customized icon for the modal.Should contain a string with the path to the image. + * Default: null + */ + imageUrl?: string; + + /** + * If imageUrl is set, you can specify imageSize to describes how big you want the icon to be in px. Pass in a string with two values separated by an "x". The first value is the width, the second is the height. + * Default: "80x80" + */ + imageSize?: string; + + /** + * Auto close timer of the modal.Set in ms (milliseconds). + * Default: null + */ + timer?: number; + + /** + * If set to true, will not escape title and text parameters. (Set to false if you're worried about XSS attacks.) + * Default: false + */ + html?: boolean; + + /** + * If set to false, the modal's animation will be disabled. Possible animations: "slide-from-top", "slide-from-bottom", "pop" (use true instead) and "none" (use false instead). + * Default: true, "pop" + */ + animation?: boolean | string; + + /** + * Change the type of the input field when using type: "input" (this can be useful if you want users to type in their password for example). + * Default: "text" + */ + inputType?: string; + } + + interface Settings extends SettingsBase { + /** + * The title of the modal. + */ + title: string; + } + + interface SetDefaultsSettings extends SettingsBase { + /** + * The title of the modal. + * Default: null + */ + title?: string; + } + + /** + * Is true or false if the user confirms or cancels the alert. Except for the type "input", then when the user confirms the alert, this variable contains the value of the input element. + */ + type CallbackArgument = boolean | string; + + interface SweetAlertStatic { + /** + * SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. An awesome replacement for JavaScript's alert. + * @param title The title of the modal. + */ + (title: string): void; + + /** + * SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. An awesome replacement for JavaScript's alert. + * @param title The title of the modal. + * @param text A description for the modal. + */ + (title: string, text: string): void; + + /** + * SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. An awesome replacement for JavaScript's alert. + * @param title The title of the modal. + * @param text A description for the modal. + * @param type The type of the modal. SweetAlert comes with 4 built-in types which will show a corresponding icon animation: "warning", "error", "success" and "info". You can also set it as "input" to get a prompt modal. + */ + (title: string, text: string, type: string): void; + + /** + * SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. An awesome replacement for JavaScript's alert. + * @param callback The callback from the users action. The value is true or false if the user confirms or cancels the alert. Except for the type "input", then when the user confirms the alert, the argument contains the value of the input element. + */ + (settings: Settings, callback?: (isConfirmOrInputValue: CallbackArgument) => any): void; + + /** + * If you end up using a lot of the same settings when calling SweetAlert, you can use setDefaults at the start of your program to set them once and for all! + */ + setDefaults(settings: SetDefaultsSettings): void; + + /** + * Close the currently open SweetAlert programmatically. + */ + close(): void; + + /** + * Show an error message after validating the input field, if the user's data is bad. + */ + showInputError(errorMessage: string): void; + } +} \ No newline at end of file diff --git a/winrt/winrt.d.ts b/winrt/winrt.d.ts index 91c0a2801..883860b00 100644 --- a/winrt/winrt.d.ts +++ b/winrt/winrt.d.ts @@ -12203,8 +12203,8 @@ declare module Windows { createWithId(tileId: string): Windows.UI.StartScreen.SecondaryTile; } export class SecondaryTile implements Windows.UI.StartScreen.ISecondaryTile { - constructor(tileId: string, shortName: string, displayName: string, arguments: string, tileOptions: Windows.UI.StartScreen.TileOptions, logoReference: Windows.Foundation.Uri); - constructor(tileId: string, shortName: string, displayName: string, arguments: string, tileOptions: Windows.UI.StartScreen.TileOptions, logoReference: Windows.Foundation.Uri, wideLogoReference: Windows.Foundation.Uri); + constructor(tileId: string, shortName: string, displayName: string, args: string, tileOptions: Windows.UI.StartScreen.TileOptions, logoReference: Windows.Foundation.Uri); + constructor(tileId: string, shortName: string, displayName: string, args: string, tileOptions: Windows.UI.StartScreen.TileOptions, logoReference: Windows.Foundation.Uri, wideLogoReference: Windows.Foundation.Uri); constructor(tileId: string); constructor(); arguments: string; diff --git a/xrm/clientglobalcontext.d.ts b/xrm/clientglobalcontext.d.ts new file mode 100644 index 000000000..ae7bcc219 --- /dev/null +++ b/xrm/clientglobalcontext.d.ts @@ -0,0 +1,14 @@ +// Type definitions for Microsoft Dynamics xRM ClientGlobalContext.js.aspx +// Project: http://msdn.microsoft.com/en-us/library/gg328255.aspx +// Definitions by: David Berry +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +/** + * Gets the xRM application context, for HTML web resources + * @returns {Xrm.Context} The application context for the user's current session. + * @remarks The ClientGlobalContext.js.aspx page will include some global event handlers. These event handlers will + * cancel the onselectstart, contextmenu, and ondragstart events. + */ +declare function GetGlobalContext(): Xrm.Context; \ No newline at end of file diff --git a/xrm/parature.d.ts b/xrm/parature.d.ts new file mode 100644 index 000000000..030c97b68 --- /dev/null +++ b/xrm/parature.d.ts @@ -0,0 +1,143 @@ +// Type definitions for Microsoft Parature extentions to Xrm.Page - available for CRM Online Only +// Project: http://msdn.microsoft.com/en-us/library/gg328255.aspx +// Definitions by: David Berry +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module Xrm.Page +{ + /** + * Interface for Parature's knowledge base search control. + * + * @sa Control + */ + export interface KbSearchControl extends Control + { + /** + * Use this method to add an event handler to the OnResultOpened event. + * + * @param {Function} handler The handler. + */ + addOnResultOpened( handler: () => void ): void; + + /** + * Use this method to add an event handler to the OnSelection event. + * + * @param {Function} handler The handler. + */ + addOnSelection( handler: () => void ): void; + + /** + * Use this method to get the text used as the search criteria for the knowledge base management control. + * + * @return The search query. + */ + getSearchQuery(): string; + + /** + * Use this method to get the currently selected result of the search control. The currently selected result also + * represents the result that is currently open. + * + * @return The selected result. + */ + getSelectedResult(): KbSearchResult; + + /** + * Use this method to remove an event handler from the OnResultOpened event. + * + * @param {Function} handler The handler. + */ + removeOnResultOpened( handler: () => void ): void; + + /** + * Use this method to remove an event handler from the OnSelection event. + * + * @param {Function} handler The handler. + */ + removeOnSelection( handler: () => void ): void; + + /** + * Use this method to set the text used as the search criteria for the knowledge base management control. + * + * @param {string} query The text for the search query. + */ + setSearchQuery( query: string ): void; + } + + /** + * Interface for a Parature knowledge base search result. + */ + export interface KbSearchResult + { + /** + * The HTML markup containing the content of the article. + */ + answer: string; + + /** + * The Article ID in a Parature department + */ + articleId: string; + + /** + * Unique Article ID for the Parature system. + */ + articleUid: string; + + /** + * The date the article was created. + */ + createdOn: Date; + + /** + * The date the article was or will be expired. + */ + expiredDate: Date; + + /** + * Whether the article is associated with the parent record or not + */ + isAssociated: boolean; + + /** + * Date on which the article was last modified. + */ + lastModifiedOn: Date; + + /** + * Support Portal URL of the article. + */ + publicUrl: string; + + /** + * Whether the Article is in published or draft state. + */ + published: boolean; + + /** + * The title of the article. + */ + question: string; + + /** + * The rating of the article. + */ + rating: number; + + /** + * A short snippet of article content which contains the areas where the search query was hit. + */ + searchBlurb: string; + + /** + * Link to the article in the Parature service desk. + */ + serviceDeskUri: string; + + /** + * The number of times an article is viewed on the Parature portal by customers. + */ + timesViewed: number; + } +} diff --git a/xrm/xrm-6.d.ts b/xrm/xrm-6.d.ts new file mode 100644 index 000000000..f2a88eb44 --- /dev/null +++ b/xrm/xrm-6.d.ts @@ -0,0 +1,2071 @@ +// Type definitions for Microsoft Dynamics xRM API v6 +// Project: http://msdn.microsoft.com/en-us/library/gg328255.aspx +// Definitions by: David Berry +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module Xrm +{ + /** + * Interface for the client context. + */ + export interface ClientContext + { + /** + * Returns a value to indicate which client the script is executing in. + * + * @return The client, as either "Web", "Outlook", or "Mobile" + */ + getClient(): string; + + /** + * Gets client's current state. + * + * @return The client state, as either "Online" or "Offline" + */ + getClientState(): string; + } + + /** + * Interface for the xRM application context. + */ + export interface Context + { + /** + * The client's context instance. + */ + client: ClientContext; + + /** + * Gets client's base URL for Dynamics CRM + * + * @return The client's base URL + * @remarks For Dynamics CRM On-Premises: http(s)://server/org + * For Dynamics CRM Online: https://org.crm.dynamics.com + * For Dynamics CRM for Outlook (Offline): http://localhost:2525 + */ + getClientUrl(): string; + + /** + * Gets current styling theme. + * + * @return The name of the current theme, as either "default", "Office12Blue", or "Office14Silver" + * + * @remarks This function does not work with Dynamics CRM for tablets. + */ + getCurrentTheme(): string; + + /** + * Gets organization's LCID (language code). + * + * @return The organization language code. + * + * @see {@link http://msdn.microsoft.com/en-us/library/ms912047(WinEmbedded.10).aspx|Microsoft Locale ID Values} + */ + getOrgLcid(): number; + + /** + * Gets organization's unique name. + * + * @return The organization's unique name. + * + * @remarks This value can be found on the Developer Resources page within Dynamics CRM + */ + getOrgUniqueName(): string; + + /** + * Gets query string parameters. + * + * @return The query string parameters, in a dictionary object representing name and value pairs. + */ + getQueryStringParameters(): { [index: string]: any }; + + /** + * Gets user's unique identifier. + * + * @return The user's identifier in Guid format. + * + * @remarks Example: "{B05EC7CE-5D51-DF11-97E0-00155DB232D0}" + */ + getUserId(): string; + + /** + * Gets user's LCID (language code). + * + * @return The user's language code. + * + * @see {@link http://msdn.microsoft.com/en-us/library/ms912047(WinEmbedded.10).aspx|Microsoft Locale ID Values} + */ + getUserLcid(): number; + + /** + * Gets the name of the current user. + * + * @return The user's name. + */ + getUserName(): string; + + /** + * Gets all user security roles. + * + * @return An array of user role identifiers, in Guid format. + * + * @remarks Example: ["cf4cc7ce-5d51-df11-97e0-00155db232d0"] + */ + getUserRoles(): string[]; + + /** + * Prefixes the current organization's unique name to a string; typically a URL path. + * + * @param {string} sPath Local pathname of the resource. + * + * @return A path string with the organization name. + * + * @remarks Format: "/"+ OrgName + sPath + */ + prependOrgName( sPath: string ): string; + } + + /** + * A definition module for asynchronous interface declarations. + */ + export module Async + { + /** + * Interface for success callbacks. + */ + export interface SuccessCallbackDelegate + { + /** + * Called when the operation is successful. + */ + (): void; + } + + /** + * Interface for error callbacks. + */ + export interface ErrorCallbackDelegate + { + /** + * Called when the operation fails. + * + * @param {number} errorCode The error code. + * @param {string} message The message. + */ + ( errorCode: number, message: string ): void; + } + + /** + * Interface for Xrm.Page.data promises. + */ + export interface XrmPromise + { + /** + * A basic 'then' promise. + * + * @param {SuccessCallbackDelegate} successCallback The success callback. + * @param {ErrorCallbackDelegate} errorCallback The error callback. + */ + then( successCallback: SuccessCallbackDelegate, errorCallback: ErrorCallbackDelegate ): void; + } + } + + /** + * A definition module for collection interface declarations. + */ + export module Collection + { + /** + * Interface for a matching delegate. + * + * @tparam T Generic type parameter. + */ + export interface MatchingDelegate + { + /** + * Called for each item in an array + * + * @param {T} item The item. + * @param {number} index Zero-based index of the item array. + * + * @return true if the item matches, false if it does not. + */ + ( item: T, index?: number ): boolean; + } + + /** + * Interface for iterative delegate. + * + * @tparam T Generic type parameter. + */ + export interface IterativeDelegate + { + /** + * Called for each item in an array + * + * @param {T} item The item. + * @param {number} index Zero-based index of the item array. + */ + ( item: T, index?: number ): void; + } + + /** + * Interface for an item collection. + * + * @tparam T Generic type parameter. + */ + export interface ItemCollection + { + /** + * Applies an operation to all items in this collection. + * + * @param {IterativeDelegate{T}} delegate An iterative delegate function + */ + forEach( delegate: IterativeDelegate ): void; + + /** + * Gets. + * + * @param {MatchingDelegate{T}} delegate A matching delegate function + * + * @return A T[] whose members have been validated by delegate. + */ + get( delegate: MatchingDelegate ): T[]; + + /** + * Gets the item given by the index. + * + * @param {number} itemNumber The item number to get. + * + * @return The T in the itemNumber-th place. + */ + get( itemNumber: number ): T; + + /** + * Gets the item given by the key. + * + * @param {string} itemName The item name to get. + * + * @return The T matching the key itemName. + * + * @see {@link Xrm.Page.Control.getName()} for Control-naming schemes. + */ + get( itemName: string ): T; + + /** + * Gets the entire array of T. + * + * @return A T[]. + */ + get(): T[]; + + /** + * Gets the length of the collection. + * + * @return The length. + */ + getLength(): number; + } + } + + /** + * The Xrm.Page API + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328255.aspx|Documentation} for details. + */ + export module Page + { + /** + * Enumeration of entity form states/types. + */ + export const enum FormType + { + Undefined = 0, + Create = 1, + Update = 2, + ReadOnly = 3, + Disabled = 4, + BulkEdit = 6 + } + + /** + * Enumeration of entity form save modes. + */ + export const enum SaveMode + { + Save = 1, + SaveAndClose = 2, + SaveAndNew = 59, + AutoSave = 70, + SaveAsCompleted = 58, + Deactivate = 5, + Reactivate = 6, + Assign = 47, + Send = 7, + Qualify = 16, + Disqualify = 15 + } + + /** + * Interface for the event context. + */ + export interface EventContext + { + /** + * Gets the Xrm context. + * + * @return The Xrm context. + */ + getContext(): Context; + + /** + * Gets the handler's depth, which is the order in which the handler is executed. + * + * @return The depth, a 0-based index. + */ + getDepth(): number; + + /** + * Gets save-event arguments. + * + * @return The event arguments. + * + * @remarks Returns null for all but the "save" event. + */ + getEventArgs(): SaveEventArguments; + + /** + * Gets a reference to the object for which event occurred. + * + * @return The event source. + */ + getEventSource(): Xrm.Page.Attribute | Xrm.Page.Entity; + + /** + * Gets the shared variable with the specified key. + * + * @tparam T Generic type parameter. + * @param {string} key The key. + * + * @return The shared variable. + * + * @remarks Used to pass values between handlers of an event. + */ + getSharedVariable( key: string ): T; + + /** + * Sets a shared variable. + * + * @tparam T Generic type parameter. + * @param {string} key The key. + * @param {T} value The value. + * + * @remarks Used to pass values between handlers of an event. + */ + setSharedVariable( key: string, value: T ): void; + } + + /** + * Interface for a context-sensitive handler. + */ + export interface ContextSensitiveHandler + { + /** + * @param {EventContext} context The context. + */ + ( context?: EventContext ): void; + } + + /** + * Base interface for UI elements. + */ + export interface UiElement + { + /** + * Gets the label. + * + * @return The label. + */ + getLabel(): string; + + /** + * Gets the visibility state. + * + * @return true if the tab is visible, otherwise false. + */ + getVisible(): boolean; + + /** + * Sets the label. + * + * @param {string} label The label. + */ + setLabel( label: string ): void; + + /** + * Sets the visibility state. + * + * @param {boolean} visible true to show, false to hide. + */ + setVisible( visible: boolean ): void; + } + + /** + * Interface for focusable UI elements. + */ + export interface UiFocusable + { + /** + * Sets focus on the element. + */ + setFocus(): void; + } + + /** + * Interface for a Lookup value. + */ + export interface LookupValue + { + /** + * The identifier. + */ + id: string; + + /** + * The name + */ + name?: string; + + /** + * Type of the entity. + */ + entityType: string; + } + + /** + * Interface for an OptionSet value. + */ + export interface OptionSetValue + { + /** + * The label text. + */ + 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. + */ + value: string; + } + + /** + * Interface for a privilege. + */ + export interface Privilege + { + /** + * true if the user can read. + */ + canRead: boolean; + + /** + * true if the user can update. + */ + canUpdate: boolean; + + /** + * true if the user can create. + */ + canCreate: boolean; + } + + /** + * Interface for an Entity attribute. + */ + export interface Attribute + { + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; + + /** + * Adds a handler to be called when the attribute's value is changed. + * + * @param {ContextSensitiveHandler} handler The function reference. + */ + addOnChange( handler: ContextSensitiveHandler ): void; + + /** + * Fire all "on change" event handlers. + */ + fireOnChange(): void; + + /** + * Gets attribute type. + * + * @return The attribute's type name. + * + * @remarks Values returned are: boolean + * datetime + * decimal + * double + * integer + * lookup + * memo + * money + * optionset + * string + */ + getAttributeType(): string; + + /** + * Gets the attribute format. + * + * @return The format of the attribute. + * + * @see {@link getAttributeType()} + * + * @remarks Values returned are: date (datetime) + * datetime (datetime) + * duration (integer) + * email (string) + * language (optionset) + * none (integer) + * phone (string) + * text (string) + * textarea (string) + * tickersymbol (string) + * timezone (optionset) + * url (string) + */ + getFormat(): string; + + /** + * Gets a boolean value indicating whether this Attribute has unsaved changes. + * + * @return true if there are unsaved changes, otherwise false. + */ + getIsDirty(): boolean; + + /** + * Gets the logical name of the attribute. + * + * @return The logical name. + */ + getName(): string; + + /** + * Gets a reference to the record context of this attribute. + * + * @return The parent record context. + */ + getParent(): Entity; + + /** + * Gets the current level of requirement for the attribute. + * + * @return The required level, as either "none", "required", or "recommended" + */ + getRequiredLevel(): string; + + /** + * Gets current submit mode for the attribute. + * + * @return The submit mode, as either "always", "never", or "dirty" + * + * @remarks The default value is "dirty" + */ + getSubmitMode(): string; + + /** + * Gets the current user's privileges for the attribute. + * + * @return The user privileges. + */ + getUserPrivilege(): Privilege; + + /** + * Removes the handler from the "on change" event. + * + * @param {ContextSensitiveHandler} handler The handler. + */ + 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; + + /** + * Sets the submit mode. + * + * @param {string} submitMode The submit mode, as either "always", "never", or "dirty". + * + * @remarks The default value is "dirty" + */ + setSubmitMode( submitMode: string ): void; + } + + /** + * Interface for a Number attribute. + * + * @sa Attribute + */ + export interface NumberAttribute extends Attribute + { + /** + * Gets the maximum value allowed. + * + * @return The maximum value allowed. + */ + getMax(): number; + + /** + * Gets the minimum value allowed. + * + * @return The minimum value allowed. + */ + getMin(): number; + + /** + * Gets the attribute's configured precision. + * + * @return The total number of allowed decimal places. + */ + getPrecision(): number; + + /** + * Gets the value. + * + * @return The value. + */ + getValue(): number; + + /** + * Sets the value. + * + * @param {number} value The value. + * + * @remarks Attributes on Quick Create Forms will not save values set with this method. + */ + setValue( value: number ): void; + } + + /** + * Interface for a String attribute. + * + * @sa Attribute + */ + export interface StringAttribute extends Attribute + { + /** + * Gets maximum length allowed. + * + * @return The maximum length allowed. + * + * @remarks The email form's "Description" attribute does not have the this method. + */ + getMaxLength(): number; + + /** + * Gets the value. + * + * @return The value. + */ + getValue(): string; + + /** + * Sets the value. + * + * @param {string} value The value. + * + * @remarks A String field with the {@link Attribute.getFormat|email} format enforces email + * address formatting. Attributes on Quick Create Forms will not save values set + * with this method. + */ + setValue( value: string ): void; + } + + /** + * Common interface for enumeration attributes (OptionSet and Boolean). + * + * @sa Attribute + */ + export interface EnumAttribute extends Attribute + { + /** + * Gets the initial value of the attribute. + * + * @return The initial value. + * @remarks Valid for optionset and boolean attribute types + */ + getInitialValue(): number | boolean; + } + + /** + * Interface for a Boolean attribute. + * + * @sa EnumAttribute + */ + export interface BooleanAttribute extends EnumAttribute + { + /** + * Gets the value. + * + * @return true if it succeeds, false if it fails. + */ + getValue(): boolean; + + /** + * Sets the value. + * + * @param {boolean} value The value. + * + * @remarks Attributes on Quick Create Forms will not save values set with this method. + */ + setValue( value: boolean ): void; + } + + /** + * Interface for a Date attribute. + * + * @sa Attribute + */ + export interface DateAttribute extends Attribute + { + /** + * Gets the value. + * + * @return The value. + */ + getValue(): Date; + + /** + * Sets the value. + * + * @param {Date} value The value. + * + * @remarks Attributes on Quick Create Forms will not save values set with this method. + */ + setValue( value: Date ): void; + } + + /** + * Interface an OptionSet attribute. + * + * @sa EnumAttribute + */ + export interface OptionSetAttribute extends EnumAttribute + { + /** + * Gets the option matching a value. + * + * @param {number} value The enumeration value of the option desired. + * + * @return The option. + */ + getOption( value: number ): OptionSetValue; + + /** + * Gets the option matching a label. + * + * @param {string} label The label of the option desired. + * + * @return The option. + */ + getOption( label: string ): OptionSetValue; + + /** + * Gets all of the options. + * + * @return An array of options. + */ + getOptions(): OptionSetValue[]; + + /** + * Gets selected option. + * + * @return The selected option. + */ + getSelectedOption(): OptionSetValue; + + /** + * Gets the label of the currently selected option. + * + * @return The current value's label. + */ + getText(): string; + + /** + * Gets the value. + * + * @return The value. + */ + getValue(): number; + + /** + * Sets the value. + * + * @param {number} value The value. + * + * @remarks The getOptions() method returns option values as strings. You must use parseInt + * to convert them to numbers before you can use those values to set the value of an + * OptionSet attribute. Attributes on Quick Create Forms will not save values set + * with this method. + */ + setValue( value: number ): void; + } + + /** + * Interface a Lookup attribute. + * + * @sa Attribute + */ + export interface LookupAttribute extends Attribute + { + /** + * Gets a boolean value indicating whether the Lookup is a multi-value PartyList. + * + * @return true the attribute is a PartyList, otherwise false. + */ + getIsPartyList(): boolean; + + /** + * Gets the value. + * + * @return An array of LookupValue. + */ + getValue(): LookupValue[]; + + /** + * Sets the value. + * + * @param {LookupValue[]} value The value. + * + * @remarks Attributes on Quick Create Forms will not save values set with this method. + */ + setValue( value: LookupValue[] ): void; + } + + /** + * Interface for the form's record context, Xrm.Page.data.entity + */ + export interface Entity + { + /** + * The collection of attributes for the record. + */ + attributes: Collection.ItemCollection; + + /** + * Adds a handler to be called when the record is saved. + * + * @param {ContextSensitiveHandler} handler The handler. + */ + addOnSave( handler: ContextSensitiveHandler ): void; + + /** + * Gets an serialized-XML string representing data that will be passed to the server upon saving + * the record. + * + * @return The XML in string format. + * + * @remarks This function does not work with Microsoft Dynamics CRM for tablets. Example: + * "Contoso55555425 + * 555-1234". + */ + getDataXml(): string; + + /** + * Gets entity's logical name. + * + * @return The logical name. + */ + getEntityName(): string; + + /** + * Gets the record's unique identifier. + * + * @return The identifier, in Guid format. + * + * @remarks Example: "{825CB223-A651-DF11-AA8B-00155DBA3804}". + */ + getId(): string; + + /** + * Gets a boolean value indicating whether the record has unsaved changes. + * + * @return true if there are unsaved changes, otherwise false. + */ + getIsDirty(): boolean; + + /** + * Gets the record's primary attribute value. + * + * @return The primary attribute value. + * + * @remarks The value for this attribute is used when links to the record are displayed. + */ + getPrimaryAttributeValue(): string; + + /** + * Removes the handler from the "on save" event. + * + * @param {ContextSensitiveHandler} handler The handler. + */ + removeOnSave( handler: ContextSensitiveHandler ): void; + + /** + * Saves the record. + * + * @remarks When using quick create forms in the web application the saveandnew option is not + * applied. It will always work as if saveandclose were used. Quick create forms in + * Microsoft Dynamics CRM for tablets will apply the saveandnew behavior. + */ + 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; + } + + /** + * Interface for save event arguments. + */ + export interface SaveEventArguments + { + /** + * Gets save mode, as an integer. + * + * @return The save mode. + * @remarks Values returned are: 1 Save + * 2 Save and Close + * 59 Save and New + * 70 AutoSave (Where enabled; can be used with an OnSave handler + * to conditionally disable auto-saving) + * 58 Save as Completed (Activities) + * 5 Deactivate + * 6 Reactivate + * 47 Assign (All user- or team-owned entities) + * 7 Send (Email) + * 16 Qualify (Lead) + * 15 Disqualify (Lead) + */ + getSaveMode(): SaveMode; + + /** + * Returns a boolean value to indicate if the record's save has been prevented. + * + * @return true if saving is prevented, otherwise false. + */ + isDefaultPrevented(): boolean; + + /** + * Prevents the save operation from being submitted to the server. + * @remarks All remaining "on save" handlers will continue execution. + */ + preventDefault(): void; + } + + /** + * Interface for the Xrm.Page.data API. + */ + export interface Data + { + /** + * The record context of the form. + */ + entity: Entity; + + /** + * Asynchronously refreshes data on the form, without reloading the page. + * + * @param {boolean} save true to save the record, after the refresh + * + * @return An Async.XrmPromise. + */ + refresh( save: boolean ): Async.XrmPromise; + + /** + * Asynchronously saves the record. + * + * @return An Async.XrmPromise. + */ + save(): Async.XrmPromise; + } + + /** + * Interface for Xrm.Page.ui controls. + * + * @sa UiElement + */ + export interface Control extends UiElement + { + /** + * Clears the notification identified by uniqueId. + * + * @param {string} uniqueId (Optional) Unique identifier. + * + * @return true if it succeeds, false if it fails. + * + * @remarks If the uniqueId parameter is not used, the current notification shown will be removed. + */ + clearNotification( uniqueId?: string ): boolean; + + /** + * Gets the control's type. + * + * @return The control type. + * @remarks Values returned are: standard + * iframe + * lookup + * optionset + * subgrid + * webresource + * notes + * timercontrol + */ + getControlType(): string; + + /** + * Gets a boolean value, indicating whether the control is disabled. + * + * @return true if it is disabled, otherwise false. + */ + getDisabled(): boolean; + + /** + * Gets the name of the control on the form. + * + * @return The name of the control. + * + * @remarks The name assigned to a control is not determined until the form loads. Changes to + * the form may change the name assigned to a given control. + * When you use the control getName method the name of the first control will be the + * same as the name of the attribute. The second instance of a control for that + * attribute will be "1". The pattern +N + * will continue for each additional control added to the form for a specific + * attribute. When a form displays a business process flow control in the header, + * additional controls will be added for each attribute that is displayed in the + * business process flow. These controls have a unique name like the following: + * header_process_. + */ + getName(): string; + + /** + * Gets a reference to the Section parent of the control. + * + * @return The parent Section. + */ + getParent(): Section; + + /** + * Sets the state of the control to either enabled, or disabled. + * + * @param {boolean} disabled true to disable, false to enable. + */ + setDisabled( disabled: boolean ): void; + + /** + * Sets a control-local notification message. + * + * @param {string} message The message. + * @param {string} uniqueId Unique identifier. + * + * @return true if it succeeds, false if it fails. + * + * @remarks When this method is used on Microsoft Dynamics CRM for tablets a red "X" icon + * appears next to the control. Tapping on the icon will display the message. + */ + setNotification( message: string, uniqueId: string ): boolean; + } + + /** + * Interface for a standard control. + * + * @sa Control + */ + export interface StandardControl extends Control + { + /** + * Gets the control's bound attribute. + * + * @tparam T An Attribute type. + * + * @return The attribute. + */ + getAttribute(): T; + + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): Attribute; + } + + /** + * Interface for a Date control. + * + * @sa StandardControl + */ + export interface DateControl extends StandardControl + { + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): DateAttribute; + + /** + * Sets the visibility of the time component of the Date control. + * + * @param {boolean} showTimeValue true to show, false to hide the time value. + */ + setShowTime( showTimeValue: boolean ): void; + } + + /** + * Interface for a Lookup control. + * + * @sa StandardControl + */ + export interface LookupControl extends StandardControl + { + /** + * Adds a handler to the "pre search" event of the Lookup control. + * + * @param {Function} handler The handler. + */ + addPreSearch( handler: () => void ): void; + + /** + * Adds an additional custom filter to the lookup, with the "AND" filter operator. + * Can only be used within a "pre search" event handler + * + * @sa addPreSearch + * + * @param {string} filter Specifies the filter, as a serialized FetchXML + * "filter" node. + * @param {string} entityLogicalName (Optional) The logical name of the entity. + * + * @remarks If entityLogicalName is not specified, the filter will be applied to all entities + * valid for the Lookup control. + * Example filter: + * + * + */ + addCustomFilter( filter: string, entityLogicalName?: string ): void; + + /** + * Adds a custom view for the Lookup dialog. + * + * @param {string} viewId Unique identifier for the view, in Guid format. + * @param {string} entityName Name of the entity. + * @param {string} viewDisplayName Name of the view to display. + * @param {string} fetchXml The FetchXML query for the view's contents, serialized as a string. + * @param {string} layoutXml The Layout XML, serialized as a string. + * @param {boolean} isDefault true, to treat this view as default. + * + * @remarks Cannot be used on "Owner" Lookup controls. + * The viewId is never saved to CRM, but must be unique across available views. Generating + * a new value can be accomplished with a {@link http://www.guidgen.com/|Guid generator}. + * Example viewId value: "{00000000-0000-0000-0000-000000000001}" + * Layout XML Reference: {@link http://msdn.microsoft.com/en-us/library/gg334522.aspx} + */ + addCustomView( viewId: string, entityName: string, viewDisplayName: string, fetchXml: string, layoutXml: string, isDefault: boolean ): void; + + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): LookupAttribute; + + /** + * Gets the unique identifier of the default view. + * + * @return The default view, in Guid format. + * + * @remarks Example: "{00000000-0000-0000-0000-000000000000}" + */ + getDefaultView(): string; + + /** + * Removes the handler from the "pre search" event of the Lookup control. + * + * @param {Function} handler The handler. + */ + removePreSearch( handler: () => void ): void; + + /** + * Sets the Lookup's default view. + * + * @param {string} viewGuid Unique identifier for the view. + * + * @remarks Example viewGuid value: "{00000000-0000-0000-0000-000000000000}" + */ + setDefaultView( viewGuid: string ): void; + } + + /** + * Interface for an OptionSet control. + * + * @sa StandardControl + */ + export interface OptionSetControl extends StandardControl + { + /** + * Adds an option. + * + * @param {OptionSetValue} option The option. + * @param {number} index (Optional) zero-based index of the option. + * + * @remarks This method does not check that the values within the options you add are valid. + * If index is not provided, the new option will be added to the end of the list. + */ + addOption( option: OptionSetValue, index?: number ): void; + + /** + * Clears all options. + */ + clearOptions(): void; + + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): OptionSetAttribute; + + /** + * Removes the option matching the value. + * + * @param {number} value The value. + */ + removeOption( value: number ): void; + } + + /** + * Interface for a CRM grid control. + * + * @sa Control + */ + export interface GridControl extends Control + { + /** + * Refreshes the sub grid. + * + * @remarks Not available during the "on load" event of the form. + */ + refresh(): void; + } + + /** + * Interface for a framed control, which is either a Web Resource or an Iframe. + * + * @sa Control + * + * @remarks An Iframe control provides additional methods, so use {@link IframeControl} where + * appropriate. Silverlight controls should use {@link SilverlightControl}. + */ + export interface FramedControl extends Control + { + /** + * Gets the DOM element containing the control. + * + * @return The container object. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getObject(): HTMLIFrameElement; + + /** + * Gets the URL value of the control. + * + * @return The source URL. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getSrc(): string; + + /** + * Sets the URL value of the control. + * + * @param {string} src The source URL. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + setSrc( src: string ): void; + } + + /** + * Interface for an Iframe control. + * + * @sa FramedControl + */ + export interface IframeControl extends FramedControl + { + /** + * Gets initial URL defined for the Iframe. + * + * @return The initial URL. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getInitialUrl(): string; + } + + /** + * Interface for a Silverlight control. + * + * @sa Control + */ + export interface SilverlightControl extends Control + { + /** + * Gets the query string value passed to Silverlight. + * + * @return The data. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getData(): string; + + /** + * Sets the query string value passed to Silverlight. + * + * @param {string} data The data. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + setData( data: string ): void; + + /** + * Gets the DOM element containing the control. + * + * @return The container object. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getObject(): HTMLObjectElement; + } + + /** + * Interface for a form tab. + * + * @sa UiElement + * @sa UiFocusable + */ + export interface Tab extends UiElement, UiFocusable + { + /** + * A reference to the collection of form sections within this tab. + */ + sections: Collection.ItemCollection
; + + /** + * Gets display state of the tab. + * + * @return The display state, as either "expanded" or "collapsed" + */ + getDisplayState(): string; + + /** + * Gets the name of the tab. + * + * @return The name. + */ + getName(): string; + + /** + * Gets a reference to the Xrm.Page.ui parent of the tab. + * + * @return The parent. + */ + 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; + } + + /** + * Interface for a form section. + * + * @sa UiElement + */ + export interface Section extends UiElement + { + /** + * A reference to the collection of controls within this tab. + */ + controls: Collection.ItemCollection; + + /** + * Gets the name of the section. + * + * @return The name. + */ + getName(): string; + + /** + * Gets a reference to the Xrm.Page.Tab parent of this item. + * + * @return The parent. + */ + getParent(): Tab; + } + + /** + * Interface for Xrm.Page.ui API. + */ + export interface Ui + { + /** + * A reference to the collection of controls on the form. + */ + controls: Collection.ItemCollection; + + /** + * The form selector API. + * + * @remarks This API does not exist with Microsoft Dynamics CRM for tablets. + */ + formSelector: FormSelector; + + /** + * The navigation API. + * + * @remarks This API does not exist with Microsoft Dynamics CRM for tablets. + */ + navigation: Navigation; + + /** + * A reference to the collection of tabs on the form. + */ + tabs: Collection.ItemCollection; + + /** + * Clears the form notification described by uniqueId. + * + * @param {string} uniqueId Unique identifier. + * + * @return true if it succeeds, otherwise false. + */ + clearFormNotification( uniqueId: string ): boolean; + + /** + * Closes the form. + */ + close(): void; + + /** + * Gets form type. + * + * @return The form type. + * + * @remarks Values returned are: 0 Undefined + * 1 Create + * 2 Update + * 3 Read Only + * 4 Disabled + * 6 Bulk Edit + * Deprecated values are 5 (Quick Create), and 11 (Read Optimized) + */ + getFormType(): FormType; + + /** + * Gets view port height. + * + * @return The view port height, in pixels. + * + * @remarks This method does not work with Microsoft Dynamics CRM for tablets. + */ + getViewPortHeight(): number; + + /** + * Gets view port width. + * + * @return The view port width, in pixels. + * + * @remarks This method does not work with Microsoft Dynamics CRM for tablets. + */ + getViewPortWidth(): number; + + /** + * Re-evaluates the ribbon's configured EnableRules + * + * @remarks This method does not work with Microsoft Dynamics CRM for tablets. + */ + 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; + } + + /** + * Interface for a navigation item. + * + * @sa UiElement + * @sa UiFocusable + */ + export interface NavigationItem extends UiElement, UiFocusable + { + /** + * Gets the name of the item. + * + * @return The identifier. + */ + getId(): string; + } + + /** + * Interface for Xrm.Page.ui.navigation. + */ + export interface Navigation + { + /** + * A reference to the collection of available navigation items. + */ + items: Collection.ItemCollection; + } + + /** + * Interface for an entity's form selector item. + */ + export interface FormItem + { + /** + * Gets the unique identifier of the form. + * + * @return The identifier, in Guid format. + */ + getId(): string; + + /** + * Gets the label for the form. + * + * @return The label. + */ + getLabel(): string; + + /** + * Navigates the user to this form. + */ + navigate(): void; + } + + /** + * Interface for the form selector API. + */ + export interface FormSelector + { + /** + * Gets current form. + * + * @return The current item. + * + * @remarks When only one form is available this method will return null. + */ + getCurrentItem(): FormItem; + + /** + * A reference to the collection of available forms. + */ + items: Collection.ItemCollection; + } + + /** + * A reference to the xRM application context. + */ + export var context: Context; + + /** + * A reference to the form's user interface API. + */ + export var ui: Ui; + + /** + * A reference to the form's data API. + */ + export var data: Data; + + /** + * Gets all attributes. + * + * @return An array of attributes. + */ + export function getAttribute(): Attribute[]; + + /** + * Gets an attribute matching attributeName. + * + * @tparam T An Attribute type. + * @param {string} attributeName Name of the attribute. + * + * @return The attribute. + */ + export function getAttribute( attributeName: string ): T; + + /** + * Gets an attribute matching attributeName. + * + * @param {string} attributeName Name of the attribute. + * + * @return The attribute. + */ + export function getAttribute( attributeName: string ): Attribute; + + /** + * Gets an attribute by index. + * + * @param {number} index The attribute index. + * + * @return The attribute. + */ + export function getAttribute( index: number ): Attribute; + + /** + * Gets an attribute. + * + * @param {Collection.MatchingDelegate{Attribute}} delegateFunction A matching delegate function + * + * @return An array of attribute. + */ + export function getAttribute( delegateFunction: Collection.MatchingDelegate ): Attribute[]; + + /** + * Gets all controls. + * + * @return An array of controls. + */ + export function getControl(): Control[]; + + /** + * Gets a control matching controlName. + * + * @tparam T A Control type + * @param {string} controlName Name of the control. + * + * @return The control. + */ + export function getControl( controlName: string ): T; + + /** + * Gets a control matching controlName. + * + * @param {string} controlName Name of the control. + * + * @return The control. + */ + export function getControl( controlName: string ): Control; + + /** + * Gets a control by index. + * + * @param {number} index The control index. + * + * @return The control. + */ + export function getControl( index: number ): Control; + + /** + * Gets a control. + * + * @param {Collection.MatchingDelegate{Control}} delegateFunction A matching delegate function. + * + * @return An array of control. + */ + export function getControl( delegateFunction: Collection.MatchingDelegate ): Control[]; + } + + /** + * An definition module for URL-based, CRM component parameters. + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + */ + export module Url + { + /** + * An enumeration for view types. + */ + export const enum ViewType + { + SystemView = 1039, + UserView = 4230 + } + + /** + * 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: + * "&key=value". + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + * + * @remarks A member for "pagetype" is not provided. The value "entityrecord" is required in + * the URL, for forms. Example: "pagetype=entityrecord" + */ + export interface FormOpenParameters + { + /** + * The logical name of the entity. + */ + etn: string; + + /** + * Additional parameters can be provided to the request. This can only be used to provide + * default field values for the form, or pass data to custom parameters that have been + * customized for the form. See example below for setting the selected form. + * + * @remarks Example: encodeURIComponent( "formid={8c9f3e6f-7839-e211-831e-00155db7d98f}" ); + */ + extraqs?: string; + + /** + * 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; + + /** + * Controls whether the Navigation bar is displayed on the form. + * Accepted values are: "on" (The navigation bar is displayed.) + * "off" (The navigation bar is not displayed.) + * "entity" (On an entity form, only the navigation options for related + * entities are available.) + */ + navbar?: string; + } + + /** + * Interface for defining parameters on a request to open a view with main.aspx (as with + * window.open). Useful for parsing the keys and values into a string of the format: + * "&key=value". + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + * + * @remarks A member for "pagetype" is not provided. The value "entitylist" is required in + * the URL, for views. Example: "pagetype=entitylist" + */ + export interface ViewOpenParameters + { + /** + * The logical name of the entity. + */ + etn: string; + + /** + * The unique identifier of a view, in Guid format, which is valid for the entity described by + * {@link etn}. + */ + viewid: string; + + /** + * The type of view identified by {@link viewid}. + * + * @remarks Accepted values are: 1039 System View + * 4230 User View. + */ + viewtype: ViewType; + + /** + * 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; + + /** + * Controls whether the Navigation bar is displayed on the form. + * Accepted values are: "on" (The navigation bar is displayed.) + * "off" (The navigation bar is not displayed.) + * "entity" (On an entity form, only the navigation options for related + * entities are available.) + */ + navbar?: string; + } + + /** + * Interface for defining parameters of a request to open a dialog with rundialog.aspx (as with + * window.open). Useful for parsing the keys and values into a string of the format: + * "&key=value". + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + */ + export interface DialogOpenParameters + { + /** + * The unique identifier of the dialog, in Guid format, which is valid for the entity described + * by: {@link EntityName} + */ + DialogId: string; + + /** + * The logical name of the entity. + */ + EntityName: string; + + /** + * The unique identifier for the targeted record. + */ + ObjectId: string; + } + + /** + * Interface for defining parameters of a request to open a report with viewer.apsx (as with + * window.open). Useful for parsing out the keys and values into a string of the format: + * "&key=value" + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + */ + export interface ReportOpenParameters + { + /** + * The action to perform, as either "run" or "filter". + * + * @remarks "run" Executes the report with default filters. + * "filter" Presents the user with the filter editor, and a "Run Report" button. + */ + action: string; + + /** + * The file name of the report. For out-of-box reports, this parameter enables context-sensitive + * help. + */ + helpID?: string; + + /** + * The unique identifier, held in the report's 'reportid' attribute, in Guid format. + */ + id: string; + } + } + + /** + * The Xrm.Utility API + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328255.aspx|Documentation} for details. + */ + export module Utility + { + /** + * Interface for defining parameters on a Xrm.Utility.openEntityForm() request. + */ + export interface FormOpenParameters + { + /** + * The identifier of the form to use, when several are available. + */ + formid: string; + + /** + * Controls whether the Navigation bar is displayed on the form. + * Accepted values are: "on" (The navigation bar is displayed.) + * "off" (The navigation bar is not displayed.) + * "entity" (On an entity form, only the navigation options for related + * entities are available.) + */ + navbar?: string; + + /** + * 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; + + /** + * Additional parameters can be provided to the request, by overloading + * this object with additional key and value pairs. This can only be used + * to provide default field values for the form, or pass data to custom + * parameters that have been customized for the form. + */ + [index: string]: string; + } + + /** + * Displays an alert dialog, with an "OK" button. + * + * @param {string} message The message. + * @param {function()} onCloseCallback The "OK" callback. + */ + export function alertDialog( message: string, onCloseCallback: () => void ): void; + + /** + * Displays a confirmation dialog, with "OK" and "Cancel" buttons. + * + * @param {string} message The message. + * @param {function()} yesCloseCallback The "OK" callback. + * @param {function()} noCloseCallback The "Cancel" callback. + */ + export function confirmDialog( message: string, yesCloseCallback: () => void, noCloseCallback: () => void ): void; + + /** + * Query if 'entityType' is an Activity entity. + * + * @param {string} entityType Type of the entity. + * + * @return true if the entity is an Activity, false if not. + */ + export function isActivityType( entityType: string ): boolean; + + /** + * Opens an entity form. + * + * @param {string} name The entity's logical name. + * @param {string} id (Optional) The unique identifier for the record. + * @param {FormParameters} parameters (Optional) Options for controlling the operation. + */ + export function openEntityForm( name: string, id?: string, parameters?: FormOpenParameters ): void; + + /** + * Opens an HTML Web Resource in a new browser window. + * + * @param {string} webResourceName Name of the HTML web resource. Can be used to pass URL + * parameters. See Remarks. + * @param {string} webResourceData (Optional) Data to pass into the Web Resource's data parameter. + * It is advised to use encodeURIcomponent() to encode the value. + * @param {number} width (Optional) The width of the new window. + * @param {number} height (Optional) The height of the new window. + * + * @return A Window reference, containing the opened Web Resource. + * + * @remarks This function will not work with Microsoft Dynamics CRM for tablets. + * Valid WebResource URL Parameters: typename + * type + * id + * orgname + * userlcid + * data (identical to this method's webResourceData parameter) + * formid + */ + export function openWebResource( webResourceName: string, webResourceData?: string, width?: number, height?: number ): Window; + } +} diff --git a/xrm/xrm-6.tests.ts b/xrm/xrm-6.tests.ts new file mode 100644 index 000000000..a791d861e --- /dev/null +++ b/xrm/xrm-6.tests.ts @@ -0,0 +1,69 @@ +/// +/// + +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(); + +var grids = Xrm.Page.getControl(( control ) => +{ + return control.getControlType() === "subgrid"; +}); + +var selectedGridReferences: Xrm.Page.LookupValue[] = []; + +grids.forEach(( gridControl: Xrm.Page.GridControl ) => +{ + gridControl.refresh(); +}); + +var lookupAttribute = Xrm.Page.getControl( "customerid" ); + +lookupAttribute.addCustomFilter( ` + +`, "account" ); + +lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); }); + +var lookupValues = lookupAttribute.getAttribute().getValue(); + +if ( lookupValues !== null ) + if ( !lookupValues[0].id || !lookupValues[0].entityType ) + throw new Error("Invalid value in Lookup control."); + +Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); }); + +Xrm.Page.ui.tabs.forEach(( tab ) => +{ + tab.setVisible( true ); + + tab.sections.forEach(( section ) => + { + section.setVisible( true ); + }); +}); + +Xrm.Page.data.entity.addOnSave(( context ) => +{ + var eventArgs = context.getEventArgs(); + + if ( eventArgs.getSaveMode() === Xrm.Page.SaveMode.AutoSave || eventArgs.getSaveMode() === Xrm.Page.SaveMode.SaveAndClose ) + eventArgs.preventDefault(); +}); + +alert( `The current form type is: ${Xrm.Page.ui.getFormType() }` ); + +alert( `The current entity type is: ${Xrm.Page.data.entity.getEntityName() }` ); diff --git a/xrm/xrm-7.0.d.ts b/xrm/xrm-7.0.d.ts new file mode 100644 index 000000000..42814382d --- /dev/null +++ b/xrm/xrm-7.0.d.ts @@ -0,0 +1,2350 @@ +// Type definitions for Microsoft Dynamics xRM API v7.0 +// Project: http://www.microsoft.com/en-us/download/details.aspx?id=44567 +// Definitions by: David Berry , Matt Ngan +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module Xrm +{ + /** + * Interface for the client context. + */ + export interface ClientContext + { + /** + * Returns a value to indicate which client the script is executing in. + * + * @return The client, as either "Web", "Outlook", or "Mobile" + */ + getClient(): string; + + /** + * Gets client's current state. + * + * @return The client state, as either "Online" or "Offline" + */ + getClientState(): string; + } + + /** + * Interface for the xRM application context. + */ + export interface Context + { + /** + * The client's context instance. + */ + client: ClientContext; + + /** + * Gets client's base URL for Dynamics CRM + * + * @return The client's base URL + * @remarks For Dynamics CRM On-Premises: http(s)://server/org + * For Dynamics CRM Online: https://org.crm.dynamics.com + * For Dynamics CRM for Outlook (Offline): http://localhost:2525 + */ + getClientUrl(): string; + + /** + * Gets current styling theme. + * + * @return The name of the current theme, as either "default", "Office12Blue", or "Office14Silver" + * + * @remarks This function does not work with Dynamics CRM for tablets. + */ + getCurrentTheme(): string; + + /** + * Gets whether automatic save is enabled. + * + * @return true if automatic saving is enabled, otherwise false. + */ + getIsAutoSaveEnabled(): boolean; + + /** + * Gets organization's LCID (language code). + * + * @return The organization language code. + * + * @see {@link http://msdn.microsoft.com/en-us/library/ms912047(WinEmbedded.10).aspx|Microsoft Locale ID Values} + */ + getOrgLcid(): number; + + /** + * Gets organization's unique name. + * + * @return The organization's unique name. + * + * @remarks This value can be found on the Developer Resources page within Dynamics CRM + */ + getOrgUniqueName(): string; + + /** + * Gets query string parameters. + * + * @return The query string parameters, in a dictionary object representing name and value pairs. + */ + getQueryStringParameters(): { [index: string]: any }; + + /** + * Gets user's unique identifier. + * + * @return The user's identifier in Guid format. + * + * @remarks Example: "{B05EC7CE-5D51-DF11-97E0-00155DB232D0}" + */ + getUserId(): string; + + /** + * Gets user's LCID (language code). + * + * @return The user's language code. + * + * @see {@link http://msdn.microsoft.com/en-us/library/ms912047(WinEmbedded.10).aspx|Microsoft Locale ID Values} + */ + getUserLcid(): number; + + /** + * Gets the name of the current user. + * + * @return The user's name. + */ + getUserName(): string; + + /** + * Gets all user security roles. + * + * @return An array of user role identifiers, in Guid format. + * + * @remarks Example: ["cf4cc7ce-5d51-df11-97e0-00155db232d0"] + */ + getUserRoles(): string[]; + + /** + * Prefixes the current organization's unique name to a string; typically a URL path. + * + * @param {string} sPath Local pathname of the resource. + * + * @return A path string with the organization name. + * + * @remarks Format: "/"+ OrgName + sPath + */ + prependOrgName( sPath: string ): string; + } + + /** + * A definition module for asynchronous interface declarations. + */ + export module Async + { + /** + * Called when the operation is successful. + */ + export type SuccessCallbackDelegate = () => void; + + /** + * Called when the operation fails. + * + * @param {number} errorCode The error code. + * @param {string} message The message. + */ + export type ErrorCallbackDelegate = ( errorCode: number, message: string ) => void; + + /** + * Interface for Xrm.Page.data promises. + */ + export interface XrmPromise + { + /** + * A basic 'then' promise. + * + * @param {SuccessCallbackDelegate} successCallback The success callback. + * @param {ErrorCallbackDelegate} errorCallback The error callback. + */ + then( successCallback: SuccessCallbackDelegate, errorCallback: ErrorCallbackDelegate ): void; + } + } + + /** + * A definition module for collection interface declarations. + */ + export module Collection + { + /** + * Interface for a matching delegate. + * + * @tparam T Generic type parameter. + */ + export interface MatchingDelegate + { + /** + * Called for each item in an array + * + * @param {T} item The item. + * @param {number} index Zero-based index of the item array. + * + * @return true if the item matches, false if it does not. + */ + ( item: T, index?: number ): boolean; + } + + /** + * Interface for iterative delegate. + * + * @tparam T Generic type parameter. + */ + export interface IterativeDelegate + { + /** + * Called for each item in an array + * + * @param {T} item The item. + * @param {number} index Zero-based index of the item array. + */ + ( item: T, index?: number ): void; + } + + /** + * Interface for an item collection. + * + * @tparam T Generic type parameter. + */ + export interface ItemCollection + { + /** + * Applies an operation to all items in this collection. + * + * @param {IterativeDelegate{T}} delegate An iterative delegate function + */ + forEach( delegate: IterativeDelegate ): void; + + /** + * Gets. + * + * @param {MatchingDelegate{T}} delegate A matching delegate function + * + * @return A T[] whose members have been validated by delegate. + */ + get( delegate: MatchingDelegate ): T[]; + + /** + * Gets the item given by the index. + * + * @param {number} itemNumber The item number to get. + * + * @return The T in the itemNumber-th place. + */ + get( itemNumber: number ): T; + + /** + * Gets the item given by the key. + * + * @param {string} itemName The item name to get. + * + * @return The T matching the key itemName. + * + * @see {@link Xrm.Page.Control.getName()} for Control-naming schemes. + */ + get( itemName: string ): T; + + /** + * Gets the entire array of T. + * + * @return A T[]. + */ + get(): T[]; + + /** + * Gets the length of the collection. + * + * @return The length. + */ + getLength(): number; + } + } + + /** + * The Xrm.Page API + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328255.aspx|Documentation} for details. + */ + export module Page + { + /** + * Enumeration of entity form states/types. + */ + export const enum FormType + { + Undefined = 0, + Create = 1, + Update = 2, + ReadOnly = 3, + Disabled = 4, + BulkEdit = 6 + } + + /** + * Enumeration of entity form save modes. + */ + export const enum SaveMode + { + Save = 1, + SaveAndClose = 2, + SaveAndNew = 59, + AutoSave = 70, + SaveAsCompleted = 58, + Deactivate = 5, + Reactivate = 6, + Assign = 47, + Send = 7, + Qualify = 16, + Disqualify = 15 + } + + /** + * Enumeration of stage categories. + */ + export const enum StageCategory + { + Qualify = 0, + Develop = 1, + Propose = 2, + Close = 3, + Identify = 4, + Research = 5, + Resolve = 6 + } + + 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}". + */ + getId(): string; + + /** + * Returns the name of the process. + * + * @return The name. + */ + getName(): string; + + /** + * Returns an collection of stages in the process. + * + * @return The stages. + */ + getStages(): Collection.ItemCollection; + + /** + * Returns a boolean value to indicate if the process is rendered. + * + * @return true if the process is rendered, false if not. + */ + isRendered(): boolean; + } + + /** + * Interface for CRM Business Process Flow stages. + */ + export interface Stage + { + /** + * Returns an object with a getValue method which will return the integer value of the business process flow + * category. + * + * @return The stage category. + */ + getCategory(): { getValue(): StageCategory }; + + /** + * Returns the logical name of the entity associated with the stage. + * + * @return The entity name. + */ + getEntityName(): string; + + /** + * Returns the unique identifier of the stage. + * + * @return The identifier of the Stage, in GUID format. + * + * @remarks Example: "{825CB223-A651-DF11-AA8B-00155DBA3804}". + */ + getId(): string; + + /** + * Returns the name of the stage. + * + * @return The name. + */ + getName(): string; + + /** + * Returns the status of the stage. + * + * @return The status. + * + * @remarks This method will return either "active" or "inactive". + */ + getStatus(): string; + + /** + * Returns a collection of steps in the stage. + * + * @return An array of Step. + */ + getSteps(): Step[]; + } + + export interface Step + { + /** + * Returns the logical name of the attribute associated to the step. + * + * @return The attribute. + * + * @remarks Some steps don’t contain an attribute value. + */ + getAttribute(): string; + + /** + * Returns the name of the step. + * + * @return The name. + */ + getName(): string; + + /** + * Returns whether the step is required in the business process flow. + * + * @return true if required, false if not. + * + * @remarks Returns true if the step is marked as required in the Business Process Flow editor; otherwise, false. + * There is no connection between this value and the values you can change in the Xrm.Page.data.entity + * attribute RequiredLevel methods. + */ + isRequired(): boolean; + } + + /** + * Interface for the event context. + */ + export interface EventContext + { + /** + * Gets the Xrm context. + * + * @return The Xrm context. + */ + getContext(): Context; + + /** + * Gets the handler's depth, which is the order in which the handler is executed. + * + * @return The depth, a 0-based index. + */ + getDepth(): number; + + /** + * Gets save-event arguments. + * + * @return The event arguments. + * + * @remarks Returns null for all but the "save" event. + */ + getEventArgs(): SaveEventArguments; + + /** + * Gets a reference to the object for which event occurred. + * + * @return The event source. + */ + getEventSource(): Xrm.Page.Attribute | Xrm.Page.Entity; + + /** + * Gets the shared variable with the specified key. + * + * @tparam T Generic type parameter. + * @param {string} key The key. + * + * @return The shared variable. + * + * @remarks Used to pass values between handlers of an event. + */ + getSharedVariable( key: string ): T; + + /** + * Sets a shared variable. + * + * @tparam T Generic type parameter. + * @param {string} key The key. + * @param {T} value The value. + * + * @remarks Used to pass values between handlers of an event. + */ + setSharedVariable( key: string, value: T ): void; + } + + /** + * Interface for a context-sensitive handler. + */ + export interface ContextSensitiveHandler + { + /** + * @param {EventContext} context The context. + */ + ( context?: EventContext ): void; + } + + /** + * Base interface for UI elements. + */ + export interface UiElement + { + /** + * Gets the label. + * + * @return The label. + */ + getLabel(): string; + + /** + * Gets the visibility state. + * + * @return true if the tab is visible, otherwise false. + */ + getVisible(): boolean; + + /** + * Sets the label. + * + * @param {string} label The label. + */ + setLabel( label: string ): void; + + /** + * Sets the visibility state. + * + * @param {boolean} visible true to show, false to hide. + */ + setVisible( visible: boolean ): void; + } + + /** + * Interface for focusable UI elements. + */ + export interface UiFocusable + { + /** + * Sets focus on the element. + */ + setFocus(): void; + } + + /** + * Interface for a Lookup value. + */ + export interface LookupValue + { + /** + * The identifier. + */ + id: string; + + /** + * The name + */ + name?: string; + + /** + * Type of the entity. + */ + entityType: string; + } + + /** + * Interface for an OptionSet value. + */ + export interface OptionSetValue + { + /** + * The label text. + */ + 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. + */ + value: string; + } + + /** + * Interface for a privilege. + */ + export interface Privilege + { + /** + * true if the user can read. + */ + canRead: boolean; + + /** + * true if the user can update. + */ + canUpdate: boolean; + + /** + * true if the user can create. + */ + canCreate: boolean; + } + + /** + * Interface for an Entity attribute. + */ + export interface Attribute + { + /** + * Adds a handler to be called when the attribute's value is changed. + * + * @param {ContextSensitiveHandler} handler The function reference. + */ + addOnChange( handler: ContextSensitiveHandler ): void; + + /** + * Fire all "on change" event handlers. + */ + fireOnChange(): void; + + /** + * Gets attribute type. + * + * @return The attribute's type name. + * + * @remarks Values returned are: boolean + * datetime + * decimal + * double + * integer + * lookup + * memo + * money + * optionset + * string + */ + getAttributeType(): string; + + /** + * Gets the attribute format. + * + * @return The format of the attribute. + * + * @see {@link getAttributeType()} + * + * @remarks Values returned are: date (datetime) + * datetime (datetime) + * duration (integer) + * email (string) + * language (optionset) + * none (integer) + * phone (string) + * text (string) + * textarea (string) + * tickersymbol (string) + * timezone (optionset) + * url (string) + */ + getFormat(): string; + + /** + * Gets a boolean value indicating whether this Attribute has unsaved changes. + * + * @return true if there are unsaved changes, otherwise false. + */ + getIsDirty(): boolean; + + /** + * Gets the logical name of the attribute. + * + * @return The logical name. + */ + getName(): string; + + /** + * Gets a reference to the record context of this attribute. + * + * @return The parent record context. + */ + getParent(): Entity; + + /** + * Gets the current level of requirement for the attribute. + * + * @return The required level, as either "none", "required", or "recommended" + */ + getRequiredLevel(): string; + + /** + * Gets current submit mode for the attribute. + * + * @return The submit mode, as either "always", "never", or "dirty" + * + * @remarks The default value is "dirty" + */ + getSubmitMode(): string; + + /** + * Gets the current user's privileges for the attribute. + * + * @return The user privileges. + */ + getUserPrivilege(): Privilege; + + /** + * Removes the handler from the "on change" event. + * + * @param {ContextSensitiveHandler} handler The handler. + */ + 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; + + /** + * Sets the submit mode. + * + * @param {string} submitMode The submit mode, as either "always", "never", or "dirty". + * + * @remarks The default value is "dirty" + */ + setSubmitMode( submitMode: string ): void; + + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; + } + + /** + * Interface for a Number attribute. + * + * @sa Attribute + */ + export interface NumberAttribute extends Attribute + { + /** + * Gets the maximum value allowed. + * + * @return The maximum value allowed. + */ + getMax(): number; + + /** + * Gets the minimum value allowed. + * + * @return The minimum value allowed. + */ + getMin(): number; + + /** + * Gets the attribute's configured precision. + * + * @return The total number of allowed decimal places. + */ + getPrecision(): number; + + /** + * Gets the value. + * + * @return The value. + */ + getValue(): number; + + /** + * Sets the value. + * + * @param {number} value The value. + * + * @remarks Attributes on Quick Create Forms will not save values set with this method. + */ + setValue( value: number ): void; + } + + /** + * Interface for a String attribute. + * + * @sa Attribute + */ + export interface StringAttribute extends Attribute + { + /** + * Gets maximum length allowed. + * + * @return The maximum length allowed. + * + * @remarks The email form's "Description" attribute does not have the this method. + */ + getMaxLength(): number; + + /** + * Gets the value. + * + * @return The value. + */ + getValue(): string; + + /** + * Sets the value. + * + * @param {string} value The value. + * + * @remarks A String field with the {@link Attribute.getFormat|email} format enforces email + * address formatting. Attributes on Quick Create Forms will not save values set + * with this method. + */ + setValue( value: string ): void; + } + + /** + * Common interface for enumeration attributes (OptionSet and Boolean). + * + * @sa Attribute + */ + export interface EnumAttribute extends Attribute + { + /** + * Gets the initial value of the attribute. + * + * @return The initial value. + * @remarks Valid for optionset and boolean attribute types + */ + getInitialValue(): number | boolean; + } + + /** + * Interface for a Boolean attribute. + * + * @sa EnumAttribute + */ + export interface BooleanAttribute extends EnumAttribute + { + /** + * Gets the value. + * + * @return true if it succeeds, false if it fails. + */ + getValue(): boolean; + + /** + * Sets the value. + * + * @param {boolean} value The value. + * + * @remarks Attributes on Quick Create Forms will not save values set with this method. + */ + setValue( value: boolean ): void; + } + + /** + * Interface for a Date attribute. + * + * @sa Attribute + */ + export interface DateAttribute extends Attribute + { + /** + * Gets the value. + * + * @return The value. + */ + getValue(): Date; + + /** + * Sets the value. + * + * @param {Date} value The value. + * + * @remarks Attributes on Quick Create Forms will not save values set with this method. + */ + setValue( value: Date ): void; + } + + /** + * Interface an OptionSet attribute. + * + * @sa EnumAttribute + */ + export interface OptionSetAttribute extends EnumAttribute + { + /** + * Gets the option matching a value. + * + * @param {number} value The enumeration value of the option desired. + * + * @return The option. + */ + getOption( value: number ): OptionSetValue; + + /** + * Gets the option matching a label. + * + * @param {string} label The label of the option desired. + * + * @return The option. + */ + getOption( label: string ): OptionSetValue; + + /** + * Gets all of the options. + * + * @return An array of options. + */ + getOptions(): OptionSetValue[]; + + /** + * Gets selected option. + * + * @return The selected option. + */ + getSelectedOption(): OptionSetValue; + + /** + * Gets the label of the currently selected option. + * + * @return The current value's label. + */ + getText(): string; + + /** + * Gets the value. + * + * @return The value. + */ + getValue(): number; + + /** + * Sets the value. + * + * @param {number} value The value. + * + * @remarks The getOptions() method returns option values as strings. You must use parseInt + * to convert them to numbers before you can use those values to set the value of an + * OptionSet attribute. Attributes on Quick Create Forms will not save values set + * with this method. + */ + setValue( value: number ): void; + } + + /** + * Interface a Lookup attribute. + * + * @sa Attribute + */ + export interface LookupAttribute extends Attribute + { + /** + * Gets a boolean value indicating whether the Lookup is a multi-value PartyList. + * + * @return true the attribute is a PartyList, otherwise false. + */ + getIsPartyList(): boolean; + + /** + * Gets the value. + * + * @return An array of LookupValue. + */ + getValue(): LookupValue[]; + + /** + * Sets the value. + * + * @param {LookupValue[]} value The value. + * + * @remarks Attributes on Quick Create Forms will not save values set with this method. + */ + setValue( value: LookupValue[] ): void; + } + + /** + * Interface for the form's record context, Xrm.Page.data.entity + */ + export interface Entity + { + /** + * Adds a handler to be called when the record is saved. + * + * @param {ContextSensitiveHandler} handler The handler. + */ + addOnSave( handler: ContextSensitiveHandler ): void; + + /** + * Gets an serialized-XML string representing data that will be passed to the server upon saving + * the record. + * + * @return The XML in string format. + * + * @remarks This function does not work with Microsoft Dynamics CRM for tablets. Example: + * "Contoso55555425 + * 555-1234". + */ + getDataXml(): string; + + /** + * Gets entity's logical name. + * + * @return The logical name. + */ + getEntityName(): string; + + /** + * Gets the record's unique identifier. + * + * @return The identifier, in Guid format. + * + * @remarks Example: "{825CB223-A651-DF11-AA8B-00155DBA3804}". + */ + getId(): string; + + /** + * Gets a boolean value indicating whether the record has unsaved changes. + * + * @return true if there are unsaved changes, otherwise false. + */ + getIsDirty(): boolean; + + /** + * Gets the record's primary attribute value. + * + * @return The primary attribute value. + * + * @remarks The value for this attribute is used when links to the record are displayed. + */ + getPrimaryAttributeValue(): string; + + /** + * Removes the handler from the "on save" event. + * + * @param {ContextSensitiveHandler} handler The handler. + */ + removeOnSave( handler: ContextSensitiveHandler ): void; + + /** + * Saves the record. + * + * @remarks When using quick create forms in the web application the saveandnew option is not + * applied. It will always work as if saveandclose were used. Quick create forms in + * Microsoft Dynamics CRM for tablets will apply the saveandnew behavior. + */ + 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; + + /** + * The collection of attributes for the record. + */ + attributes: Collection.ItemCollection; + } + + /** + * Interface for save event arguments. + */ + export interface SaveEventArguments + { + /** + * Gets save mode, as an integer. + * + * @return The save mode. + * @remarks Values returned are: 1 Save + * 2 Save and Close + * 59 Save and New + * 70 AutoSave (Where enabled; can be used with an OnSave handler + * to conditionally disable auto-saving) + * 58 Save as Completed (Activities) + * 5 Deactivate + * 6 Reactivate + * 47 Assign (All user- or team-owned entities) + * 7 Send (Email) + * 16 Qualify (Lead) + * 15 Disqualify (Lead) + */ + getSaveMode(): SaveMode; + + /** + * Returns a boolean value to indicate if the record's save has been prevented. + * + * @return true if saving is prevented, otherwise false. + */ + isDefaultPrevented(): boolean; + + /** + * Prevents the save operation from being submitted to the server. + * @remarks All remaining "on save" handlers will continue execution. + */ + preventDefault(): void; + } + + /** + * Module for the Xrm.Page.data API. + */ + export module data + { + /** + * Interface for the Xrm.Page.data.process API. + */ + export interface ProcessManager + { + /** + * Returns a Process object representing the active process. + * + * @return current active process. + */ + getActiveProcess(): Process; + + /** + * Set a Process as 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; + + /** + * Returns a Stage object representing the active stage. + * + * @return current active stage. + */ + getActiveStage(): Stage; + + /** + * Set a stage as the active stage. + * + * @param {string} stageId the Id of the stage to make the active stage. + * @param {function} callbackFunction (Optional) a function to call when the operation is complete. + */ + setActiveStage( stageId: string, callbackFunction?: ProcessCallbackDelegate ): void; + + /** + * Use this method to get a collection of stages currently in the active path with methods to interact with the + * stages displayed in the business process flow control. The active path represents stages currently rendered in + * the process control based on the branching rules and current data in the record. + * + * @return A collection of all completed stages, the currently active stage, and the predicted set of future stages + * based on satisfied conditions in the branching rule. This may be a subset of the stages returned with + * Xrm.Page.data.process.getActiveProcess because it will only include those stages which represent a valid + * transition from the current stage based on branching that has occurred in the process. + */ + getActivePath(): Collection.ItemCollection; + + /** + * 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. + */ + getEnabledProcesses( callbackFunction: ( enabledProcesses: ProcessDictionary ) => void ): void; + + /** + * 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. + */ + addOnStageChange( 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. + */ + removeOnStageSelected( handler: ContextSensitiveHandler ): void; + + /** + * Progresses to the next stage. + * + * @param {ProcessCallbackDelegate} callbackFunction (Optional) A function to call when the operation is + * complete. + */ + moveNext( callbackFunction?: ProcessCallbackDelegate ): void; + + /** + * Moves to the previous stage. + * + * @param {ProcessCallbackDelegate} callbackFunction (Optional) A function to call when the operation is + * complete. + */ + movePrevious( callbackFunction?: ProcessCallbackDelegate ): void; + } + + /** + * Called when process change methods have completed. + * + * @param {string} status The result of the process change operation. + * @remarks Values returned are: success (The operation succeeded.) + * crossEntity (The previous stage is for a different entity.) + * beginning (The active stage is the first stage of the active path.) + * invalid (The operation failed because the selected stage isn’t the same + * as the active stage.) + * unreachable (The stage exists on a different path.) + */ + export type ProcessCallbackDelegate = ( status: string ) => void; + + /** + * Represents a key-value pair, where the key is the Process Flow's ID, and the value is the name thereof. + */ + export type ProcessDictionary = { [index: string]: string }; + + /** + * Asynchronously refreshes data on the form, without reloading the page. + * + * @param {boolean} save true to save the record, after the refresh. + * + * @return An Async.XrmPromise. + */ + export function refresh( save: boolean ): Async.XrmPromise; + + /** + * Asynchronously saves the record. + * + * @return An Async.XrmPromise. + */ + export function save(): Async.XrmPromise; + + /** + * The record context of the form. + */ + export var entity: Entity; + + /** + * The process API for Xrm.Page.data. + * + * @remarks This member may be undefined when Process Flows are not used by the current entity. + */ + export var process: ProcessManager; + } + + /** + * Interface for Xrm.Page.ui controls. + * + * @sa UiElement + */ + export interface Control extends UiElement + { + /** + * Clears the notification identified by uniqueId. + * + * @param {string} uniqueId (Optional) Unique identifier. + * + * @return true if it succeeds, false if it fails. + * + * @remarks If the uniqueId parameter is not used, the current notification shown will be removed. + */ + clearNotification( uniqueId?: string ): boolean; + + /** + * Gets the control's type. + * + * @return The control type. + * @remarks Values returned are: standard + * iframe + * lookup + * optionset + * subgrid + * webresource + * notes + * timercontrol + */ + getControlType(): string; + + /** + * Gets a boolean value, indicating whether the control is disabled. + * + * @return true if it is disabled, otherwise false. + */ + getDisabled(): boolean; + + /** + * Gets the name of the control on the form. + * + * @return The name of the control. + * + * @remarks The name assigned to a control is not determined until the form loads. Changes to + * the form may change the name assigned to a given control. + * When you use the control getName method the name of the first control will be the + * same as the name of the attribute. The second instance of a control for that + * attribute will be "1". The pattern +N + * will continue for each additional control added to the form for a specific + * attribute. When a form displays a business process flow control in the header, + * additional controls will be added for each attribute that is displayed in the + * business process flow. These controls have a unique name like the following: + * header_process_. + */ + getName(): string; + + /** + * Gets a reference to the Section parent of the control. + * + * @return The parent Section. + */ + getParent(): Section; + + /** + * Sets the state of the control to either enabled, or disabled. + * + * @param {boolean} disabled true to disable, false to enable. + */ + setDisabled( disabled: boolean ): void; + + /** + * Sets a control-local notification message. + * + * @param {string} message The message. + * @param {string} uniqueId Unique identifier. + * + * @return true if it succeeds, false if it fails. + * + * @remarks When this method is used on Microsoft Dynamics CRM for tablets a red "X" icon + * appears next to the control. Tapping on the icon will display the message. + */ + setNotification( message: string, uniqueId: string ): boolean; + } + + /** + * Interface for a standard control. + * + * @sa Control + */ + export interface StandardControl extends Control + { + /** + * Gets the control's bound attribute. + * + * @tparam T An Attribute type. + * + * @return The attribute. + */ + getAttribute(): T; + + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): Attribute; + } + + /** + * Interface for a Date control. + * + * @sa StandardControl + */ + export interface DateControl extends StandardControl + { + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): DateAttribute; + + /** + * Sets the visibility of the time component of the Date control. + * + * @param {boolean} showTimeValue true to show, false to hide the time value. + */ + setShowTime( showTimeValue: boolean ): void; + } + + /** + * Interface for a Lookup control. + * + * @sa StandardControl + */ + export interface LookupControl extends StandardControl + { + /** + * Adds a handler to the "pre search" event of the Lookup control. + * + * @param {Function} handler The handler. + */ + addPreSearch( handler: () => void ): void; + + /** + * Adds an additional custom filter to the lookup, with the "AND" filter operator. + * Can only be used within a "pre search" event handler + * + * @sa addPreSearch + * + * @param {string} filter Specifies the filter, as a serialized FetchXML + * "filter" node. + * @param {string} entityLogicalName (Optional) The logical name of the entity. + * + * @remarks If entityLogicalName is not specified, the filter will be applied to all entities + * valid for the Lookup control. + * Example filter: + * + * + */ + addCustomFilter( filter: string, entityLogicalName?: string ): void; + + /** + * Adds a custom view for the Lookup dialog. + * + * @param {string} viewId Unique identifier for the view, in Guid format. + * @param {string} entityName Name of the entity. + * @param {string} viewDisplayName Name of the view to display. + * @param {string} fetchXml The FetchXML query for the view's contents, serialized as a string. + * @param {string} layoutXml The Layout XML, serialized as a string. + * @param {boolean} isDefault true, to treat this view as default. + * + * @remarks Cannot be used on "Owner" Lookup controls. + * The viewId is never saved to CRM, but must be unique across available views. Generating + * a new value can be accomplished with a {@link http://www.guidgen.com/|Guid generator}. + * Example viewId value: "{00000000-0000-0000-0000-000000000001}" + * Layout XML Reference: {@link http://msdn.microsoft.com/en-us/library/gg334522.aspx} + */ + addCustomView( viewId: string, entityName: string, viewDisplayName: string, fetchXml: string, layoutXml: string, isDefault: boolean ): void; + + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): LookupAttribute; + + /** + * Gets the unique identifier of the default view. + * + * @return The default view, in Guid format. + * + * @remarks Example: "{00000000-0000-0000-0000-000000000000}" + */ + getDefaultView(): string; + + /** + * Removes the handler from the "pre search" event of the Lookup control. + * + * @param {Function} handler The handler. + */ + removePreSearch( handler: () => void ): void; + + /** + * Sets the Lookup's default view. + * + * @param {string} viewGuid Unique identifier for the view. + * + * @remarks Example viewGuid value: "{00000000-0000-0000-0000-000000000000}" + */ + setDefaultView( viewGuid: string ): void; + } + + /** + * Interface for an OptionSet control. + * + * @sa StandardControl + */ + export interface OptionSetControl extends StandardControl + { + /** + * Adds an option. + * + * @param {OptionSetValue} option The option. + * @param {number} index (Optional) zero-based index of the option. + * + * @remarks This method does not check that the values within the options you add are valid. + * If index is not provided, the new option will be added to the end of the list. + */ + addOption( option: OptionSetValue, index?: number ): void; + + /** + * Clears all options. + */ + clearOptions(): void; + + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): OptionSetAttribute; + + /** + * Removes the option matching the value. + * + * @param {number} value The value. + */ + removeOption( value: number ): void; + } + + /** + * Interface for a CRM grid control. + * + * @sa Control + */ + export interface GridControl extends Control + { + /** + * Refreshes the sub grid. + * + * @remarks Not available during the "on load" event of the form. + */ + refresh(): void; + } + + /** + * Interface for a framed control, which is either a Web Resource or an Iframe. + * + * @sa Control + * + * @remarks An Iframe control provides additional methods, so use {@link IframeControl} where + * appropriate. Silverlight controls should use {@link SilverlightControl}. + */ + export interface FramedControl extends Control + { + /** + * Gets the DOM element containing the control. + * + * @return The container object. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getObject(): HTMLIFrameElement; + + /** + * Gets the URL value of the control. + * + * @return The source URL. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getSrc(): string; + + /** + * Sets the URL value of the control. + * + * @param {string} src The source URL. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + setSrc( src: string ): void; + } + + /** + * Interface for an Iframe control. + * + * @sa FramedControl + */ + export interface IframeControl extends FramedControl + { + /** + * Gets initial URL defined for the Iframe. + * + * @return The initial URL. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getInitialUrl(): string; + } + + /** + * Interface for a Silverlight control. + * + * @sa Control + */ + export interface SilverlightControl extends Control + { + /** + * Gets the query string value passed to Silverlight. + * + * @return The data. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getData(): string; + + /** + * Sets the query string value passed to Silverlight. + * + * @param {string} data The data. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + setData( data: string ): void; + + /** + * Gets the DOM element containing the control. + * + * @return The container object. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getObject(): HTMLObjectElement; + } + + /** + * Interface for a form tab. + * + * @sa UiElement + * @sa UiFocusable + */ + export interface Tab extends UiElement, UiFocusable + { + /** + * Gets display state of the tab. + * + * @return The display state, as either "expanded" or "collapsed" + */ + getDisplayState(): string; + + /** + * Gets the name of the tab. + * + * @return The name. + */ + getName(): string; + + /** + * Gets a reference to the Xrm.Page.ui parent of the tab. + * + * @return The parent. + */ + getParent(): typeof 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; + + /** + * A reference to the collection of form sections within this tab. + */ + sections: Collection.ItemCollection
; + } + + /** + * Interface for a form section. + * + * @sa UiElement + */ + export interface Section extends UiElement + { + /** + * Gets the name of the section. + * + * @return The name. + */ + getName(): string; + + /** + * Gets a reference to the Xrm.Page.Tab parent of this item. + * + * @return The parent. + */ + getParent(): Tab; + + /** + * A reference to the collection of controls within this tab. + */ + controls: Collection.ItemCollection; + } + + /** + * Module for Xrm.Page.ui API. + */ + export module ui + { + /** + * 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; + + /** + * Sets the visibility state. + * + * @param {boolean} visible true to show, false to hide. + */ + setVisible( visible: boolean ): void; + } + + /** + * Clears the form notification described by uniqueId. + * + * @param {string} uniqueId Unique identifier. + * + * @return true if it succeeds, otherwise false. + */ + export function clearFormNotification( uniqueId: string ): boolean; + + /** + * Closes the form. + */ + export function close(): void; + + /** + * Gets form type. + * + * @return The form type. + * + * @remarks Values returned are: 0 Undefined + * 1 Create + * 2 Update + * 3 Read Only + * 4 Disabled + * 6 Bulk Edit + * Deprecated values are 5 (Quick Create), and 11 (Read Optimized) + */ + export function getFormType(): FormType; + + /** + * Gets view port height. + * + * @return The view port height, in pixels. + * + * @remarks This method does not work with Microsoft Dynamics CRM for tablets. + */ + export function getViewPortHeight(): number; + + /** + * Gets view port width. + * + * @return The view port width, in pixels. + * + * @remarks This method does not work with Microsoft Dynamics CRM for tablets. + */ + export function getViewPortWidth(): number; + + /** + * Re-evaluates the ribbon's configured EnableRules + * + * @remarks This method does not work with Microsoft Dynamics CRM for tablets. + */ + export function 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. + */ + export function 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. + */ + export function 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. + */ + export function 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. + */ + export function setFormNotification( message: string, level: string, uniqueId: string ): boolean; + + export var process: ProcessManager; + + /** + * A reference to the collection of controls on the form. + */ + export var controls: Collection.ItemCollection; + + /** + * The form selector API. + * + * @remarks This API does not exist with Microsoft Dynamics CRM for tablets. + */ + export var formSelector: FormSelector; + + /** + * The navigation API. + * + * @remarks This API does not exist with Microsoft Dynamics CRM for tablets. + */ + export var navigation: Navigation; + + /** + * A reference to the collection of tabs on the form. + */ + export var tabs: Collection.ItemCollection; + } + + /** + * Interface for a navigation item. + * + * @sa UiElement + * @sa UiFocusable + */ + export interface NavigationItem extends UiElement, UiFocusable + { + /** + * Gets the name of the item. + * + * @return The identifier. + */ + getId(): string; + } + + /** + * Interface for Xrm.Page.ui.navigation. + */ + export interface Navigation + { + /** + * A reference to the collection of available navigation items. + */ + items: Collection.ItemCollection; + } + + /** + * Interface for an entity's form selector item. + */ + export interface FormItem + { + /** + * Gets the unique identifier of the form. + * + * @return The identifier, in Guid format. + */ + getId(): string; + + /** + * Gets the label for the form. + * + * @return The label. + */ + getLabel(): string; + + /** + * Navigates the user to this form. + */ + navigate(): void; + } + + /** + * Interface for the form selector API. + */ + export interface FormSelector + { + /** + * Gets current form. + * + * @return The current item. + * + * @remarks When only one form is available this method will return null. + */ + getCurrentItem(): FormItem; + + /** + * A reference to the collection of available forms. + */ + items: Collection.ItemCollection; + } + + /** + * A reference to the xRM application context. + */ + export var context: Context; + + /** + * Gets all attributes. + * + * @return An array of attributes. + */ + export function getAttribute(): Attribute[]; + + /** + * Gets an attribute matching attributeName. + * + * @tparam T An Attribute type. + * @param {string} attributeName Name of the attribute. + * + * @return The attribute. + */ + export function getAttribute( attributeName: string ): T; + + /** + * Gets an attribute matching attributeName. + * + * @param {string} attributeName Name of the attribute. + * + * @return The attribute. + */ + export function getAttribute( attributeName: string ): Attribute; + + /** + * Gets an attribute by index. + * + * @param {number} index The attribute index. + * + * @return The attribute. + */ + export function getAttribute( index: number ): Attribute; + + /** + * Gets an attribute. + * + * @param {Collection.MatchingDelegate{Attribute}} delegateFunction A matching delegate function + * + * @return An array of attribute. + */ + export function getAttribute( delegateFunction: Collection.MatchingDelegate ): Attribute[]; + + /** + * Gets all controls. + * + * @return An array of controls. + */ + export function getControl(): Control[]; + + /** + * Gets a control matching controlName. + * + * @tparam T A Control type + * @param {string} controlName Name of the control. + * + * @return The control. + */ + export function getControl( controlName: string ): T; + + /** + * Gets a control matching controlName. + * + * @param {string} controlName Name of the control. + * + * @return The control. + */ + export function getControl( controlName: string ): Control; + + /** + * Gets a control by index. + * + * @param {number} index The control index. + * + * @return The control. + */ + export function getControl( index: number ): Control; + + /** + * Gets a control. + * + * @param {Collection.MatchingDelegate{Control}} delegateFunction A matching delegate function. + * + * @return An array of control. + */ + export function getControl( delegateFunction: Collection.MatchingDelegate ): Control[]; + } + + /** + * An definition module for URL-based, CRM component parameters. + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + */ + export module Url + { + /** + * An enumeration for view types. + */ + export const enum ViewType + { + SystemView = 1039, + UserView = 4230 + } + + /** + * 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: + * "&key=value". + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + * + * @remarks A member for "pagetype" is not provided. The value "entityrecord" is required in + * the URL, for forms. Example: "pagetype=entityrecord" + */ + export interface FormOpenParameters + { + /** + * The logical name of the entity. + */ + etn: string; + + /** + * Additional parameters can be provided to the request. This can only be used to provide + * default field values for the form, or pass data to custom parameters that have been + * customized for the form. See example below for setting the selected form. + * + * @remarks Example: encodeURIComponent( "formid={8c9f3e6f-7839-e211-831e-00155db7d98f}" ); + */ + extraqs?: string; + + /** + * 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; + + /** + * Controls whether the Navigation bar is displayed on the form. + * Accepted values are: "on" (The navigation bar is displayed.) + * "off" (The navigation bar is not displayed.) + * "entity" (On an entity form, only the navigation options for related + * entities are available.) + */ + navbar?: string; + } + + /** + * Interface for defining parameters on a request to open a view with main.aspx (as with + * window.open). Useful for parsing the keys and values into a string of the format: + * "&key=value". + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + * + * @remarks A member for "pagetype" is not provided. The value "entitylist" is required in + * the URL, for views. Example: "pagetype=entitylist" + */ + export interface ViewOpenParameters + { + /** + * The logical name of the entity. + */ + etn: string; + + /** + * The unique identifier of a view, in Guid format, which is valid for the entity described by + * {@link etn}. + */ + viewid: string; + + /** + * The type of view identified by {@link viewid}. + * + * @remarks Accepted values are: 1039 System View + * 4230 User View. + */ + viewtype: ViewType; + + /** + * 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; + + /** + * Controls whether the Navigation bar is displayed on the form. + * Accepted values are: "on" (The navigation bar is displayed.) + * "off" (The navigation bar is not displayed.) + * "entity" (On an entity form, only the navigation options for related + * entities are available.) + */ + navbar?: string; + } + + /** + * Interface for defining parameters of a request to open a dialog with rundialog.aspx (as with + * window.open). Useful for parsing the keys and values into a string of the format: + * "&key=value". + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + */ + export interface DialogOpenParameters + { + /** + * The unique identifier of the dialog, in Guid format, which is valid for the entity described + * by: {@link EntityName} + */ + DialogId: string; + + /** + * The logical name of the entity. + */ + EntityName: string; + + /** + * The unique identifier for the targeted record. + */ + ObjectId: string; + } + + /** + * Interface for defining parameters of a request to open a report with viewer.apsx (as with + * window.open). Useful for parsing out the keys and values into a string of the format: + * "&key=value" + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + */ + export interface ReportOpenParameters + { + /** + * The action to perform, as either "run" or "filter". + * + * @remarks "run" Executes the report with default filters. + * "filter" Presents the user with the filter editor, and a "Run Report" button. + */ + action: string; + + /** + * The file name of the report. For out-of-box reports, this parameter enables context-sensitive + * help. + */ + helpID?: string; + + /** + * The unique identifier, held in the report's 'reportid' attribute, in Guid format. + */ + id: string; + } + } + + /** + * The Xrm.Utility API + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328255.aspx|Documentation} for details. + */ + export module Utility + { + export interface OpenParameters + { + /** + * Additional parameters can be provided to the request, by overloading + * this object with additional key and value pairs. This can only be used + * to provide default field values for the form, or pass data to custom + * parameters that have been customized for the form. + */ + [index: string]: string; + } + + /** + * Interface for defining parameters on a Xrm.Utility.openEntityForm() request. + */ + export interface FormOpenParameters extends OpenParameters + { + /** + * The identifier of the form to use, when several are available. + */ + formid: string; + + /** + * Controls whether the Navigation bar is displayed on the form. + * Accepted values are: "on" (The navigation bar is displayed.) + * "off" (The navigation bar is not displayed.) + * "entity" (On an entity form, only the navigation options for related + * entities are available.) + */ + navbar?: string; + + /** + * 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; + } + + /** + * Displays an alert dialog, with an "OK" button. + * + * @param {string} message The message. + * @param {function()} onCloseCallback The "OK" callback. + */ + export function alertDialog( message: string, onCloseCallback: () => void ): void; + + /** + * Displays a confirmation dialog, with "OK" and "Cancel" buttons. + * + * @param {string} message The message. + * @param {function()} yesCloseCallback The "OK" callback. + * @param {function()} noCloseCallback The "Cancel" callback. + */ + export function confirmDialog( message: string, yesCloseCallback: () => void, noCloseCallback: () => void ): void; + + /** + * Query if 'entityType' is an Activity entity. + * + * @param {string} entityType Type of the entity. + * + * @return true if the entity is an Activity, false if not. + */ + export function isActivityType( entityType: string ): boolean; + + /** + * Opens an entity form. + * + * @param {string} name The entity's logical name. + * @param {string} id (Optional) The unique identifier for the record. + * @param {FormParameters} parameters (Optional) A dictionary object that passes extra query string parameters to the form. + */ + export function openEntityForm( name: string, id?: string, parameters?: FormOpenParameters ): void; + + /** + * Opens an HTML Web Resource in a new browser window. + * + * @param {string} webResourceName Name of the HTML web resource. Can be used to pass URL + * parameters. See Remarks. + * @param {string} webResourceData (Optional) Data to pass into the Web Resource's data parameter. + * It is advised to use encodeURIcomponent() to encode the value. + * @param {number} width (Optional) The width of the new window. + * @param {number} height (Optional) The height of the new window. + * + * @return A Window reference, containing the opened Web Resource. + * + * @remarks This function will not work with Microsoft Dynamics CRM for tablets. + * Valid WebResource URL Parameters: typename + * type + * id + * orgname + * userlcid + * data (identical to this method's webResourceData parameter) + * formid + */ + export function openWebResource( webResourceName: string, webResourceData?: string, width?: number, height?: number ): Window; + } +} diff --git a/xrm/xrm-7.0.tests.ts b/xrm/xrm-7.0.tests.ts new file mode 100644 index 000000000..cb648e585 --- /dev/null +++ b/xrm/xrm-7.0.tests.ts @@ -0,0 +1,72 @@ +/// +/// + +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(); + +var grids = Xrm.Page.getControl(( control ) => +{ + return control.getControlType() === "subgrid"; +}); + +var selectedGridReferences: Xrm.Page.LookupValue[] = []; + +grids.forEach(( gridControl: Xrm.Page.GridControl ) => +{ + gridControl.refresh(); +}); + +var lookupAttribute = Xrm.Page.getControl( "customerid" ); + +lookupAttribute.addCustomFilter( ` + +`, "account" ); + +lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); }); + +var lookupValues = lookupAttribute.getAttribute().getValue(); + +if ( lookupValues !== null ) + if ( !lookupValues[0].id || !lookupValues[0].entityType ) + throw new Error("Invalid value in Lookup control."); + +if (Xrm.Page.data.process != null) + Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ) }); + +Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); }); + +Xrm.Page.ui.tabs.forEach(( tab ) => +{ + tab.setVisible( true ); + + tab.sections.forEach(( section ) => + { + section.setVisible( true ); + }); +}); + +Xrm.Page.data.entity.addOnSave(( context ) => +{ + var eventArgs = context.getEventArgs(); + + if ( eventArgs.getSaveMode() === Xrm.Page.SaveMode.AutoSave || eventArgs.getSaveMode() === Xrm.Page.SaveMode.SaveAndClose ) + eventArgs.preventDefault(); +}); + +alert( `The current form type is: ${Xrm.Page.ui.getFormType() }` ); + +alert( `The current entity type is: ${Xrm.Page.data.entity.getEntityName() }` ); diff --git a/xrm/xrm-tests.ts b/xrm/xrm-tests.ts new file mode 100644 index 000000000..610662c7d --- /dev/null +++ b/xrm/xrm-tests.ts @@ -0,0 +1,103 @@ +/// +/// +/// + +/// 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.getControl( "customerid" ); +var lookupAttribute2 = Xrm.Page.getControl( "customerid" ); + +/// Demonstrate ES6 String literal syntax + +lookupAttribute.addCustomFilter( ` + +`, "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() === 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() }` ); + +alert( `The current entity type is: ${Xrm.Page.data.entity.getEntityName() }` ); diff --git a/xrm/xrm.d.ts b/xrm/xrm.d.ts new file mode 100644 index 000000000..8b82136a4 --- /dev/null +++ b/xrm/xrm.d.ts @@ -0,0 +1,2586 @@ +// 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 , Matt Ngan +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module Xrm +{ + /** + * Interface for the client context. + */ + export interface ClientContext + { + /** + * Returns a value to indicate which client the script is executing in. + * + * @return The client, as either "Web", "Outlook", or "Mobile" + */ + getClient(): string; + + /** + * Gets client's current state. + * + * @return The client state, as either "Online" or "Offline" + */ + getClientState(): string; + } + + /** + * Interface for the xRM application context. + */ + export interface Context + { + /** + * The client's context instance. + */ + client: ClientContext; + + /** + * Gets client's base URL for Dynamics CRM + * + * @return The client's base URL + * @remarks For Dynamics CRM On-Premises: http(s)://server/org + * For Dynamics CRM Online: https://org.crm.dynamics.com + * For Dynamics CRM for Outlook (Offline): http://localhost:2525 + */ + getClientUrl(): string; + + /** + * Gets current styling theme. + * + * @return The name of the current theme, as either "default", "Office12Blue", or "Office14Silver" + * + * @remarks This function does not work with Dynamics CRM for tablets. + */ + getCurrentTheme(): string; + + /** + * Gets whether automatic save is enabled. + * + * @return true if automatic saving is enabled, otherwise false. + */ + getIsAutoSaveEnabled(): boolean; + + /** + * Gets organization's LCID (language code). + * + * @return The organization language code. + * + * @see {@link http://msdn.microsoft.com/en-us/library/ms912047(WinEmbedded.10).aspx|Microsoft Locale ID Values} + */ + getOrgLcid(): number; + + /** + * Gets organization's unique name. + * + * @return The organization's unique name. + * + * @remarks This value can be found on the Developer Resources page within Dynamics CRM + */ + getOrgUniqueName(): string; + + /** + * Gets query string parameters. + * + * @return The query string parameters, in a dictionary object representing name and value pairs. + */ + getQueryStringParameters(): { [index: string]: any }; + + /** + * Returns the difference between the local time and Coordinated Universal Time (UTC). + * + * @return The time zone offset, in minutes. + */ + getTimeZoneOffsetMinutes(): number; + + /** + * Gets user's unique identifier. + * + * @return The user's identifier in Guid format. + * + * @remarks Example: "{B05EC7CE-5D51-DF11-97E0-00155DB232D0}" + */ + getUserId(): string; + + /** + * Gets user's LCID (language code). + * + * @return The user's language code. + * + * @see {@link http://msdn.microsoft.com/en-us/library/ms912047(WinEmbedded.10).aspx|Microsoft Locale ID Values} + */ + getUserLcid(): number; + + /** + * Gets the name of the current user. + * + * @return The user's name. + */ + getUserName(): string; + + /** + * Gets all user security roles. + * + * @return An array of user role identifiers, in Guid format. + * + * @remarks Example: ["cf4cc7ce-5d51-df11-97e0-00155db232d0"] + */ + getUserRoles(): string[]; + + /** + * Prefixes the current organization's unique name to a string; typically a URL path. + * + * @param {string} sPath Local pathname of the resource. + * + * @return A path string with the organization name. + * + * @remarks Format: "/"+ OrgName + sPath + */ + prependOrgName( sPath: string ): string; + } + + /** + * A definition module for asynchronous interface declarations. + */ + export module Async + { + /** + * Called when the operation is successful. + */ + export type SuccessCallbackDelegate = () => void; + + /** + * Called when the operation fails. + * + * @param {number} errorCode The error code. + * @param {string} message The message. + */ + export type ErrorCallbackDelegate = ( errorCode: number, message: string ) => void; + + /** + * Interface for Xrm.Page.data promises. + */ + export interface XrmPromise + { + /** + * A basic 'then' promise. + * + * @param {SuccessCallbackDelegate} successCallback The success callback. + * @param {ErrorCallbackDelegate} errorCallback The error callback. + */ + then( successCallback: SuccessCallbackDelegate, errorCallback: ErrorCallbackDelegate ): void; + } + } + + /** + * A definition module for collection interface declarations. + */ + export module Collection + { + /** + * Interface for a matching delegate. + * + * @tparam T Generic type parameter. + */ + export interface MatchingDelegate + { + /** + * Called for each item in an array + * + * @param {T} item The item. + * @param {number} index Zero-based index of the item array. + * + * @return true if the item matches, false if it does not. + */ + ( item: T, index?: number ): boolean; + } + + /** + * Interface for iterative delegate. + * + * @tparam T Generic type parameter. + */ + export interface IterativeDelegate + { + /** + * Called for each item in an array + * + * @param {T} item The item. + * @param {number} index Zero-based index of the item array. + */ + ( item: T, index?: number ): void; + } + + /** + * Interface for an item collection. + * + * @tparam T Generic type parameter. + */ + export interface ItemCollection + { + /** + * Applies an operation to all items in this collection. + * + * @param {IterativeDelegate{T}} delegate An iterative delegate function + */ + forEach( delegate: IterativeDelegate ): void; + + /** + * Gets. + * + * @param {MatchingDelegate{T}} delegate A matching delegate function + * + * @return A T[] whose members have been validated by delegate. + */ + get( delegate: MatchingDelegate ): T[]; + + /** + * Gets the item given by the index. + * + * @param {number} itemNumber The item number to get. + * + * @return The T in the itemNumber-th place. + */ + get( itemNumber: number ): T; + + /** + * Gets the item given by the key. + * + * @param {string} itemName The item name to get. + * + * @return The T matching the key itemName. + * + * @see {@link Xrm.Page.Control.getName()} for Control-naming schemes. + */ + get( itemName: string ): T; + + /** + * Gets the entire array of T. + * + * @return A T[]. + */ + get(): T[]; + + /** + * Gets the length of the collection. + * + * @return The length. + */ + getLength(): number; + } + } + + /** + * The Xrm.Page API + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328255.aspx|Documentation} for details. + */ + export module Page + { + /** + * Enumeration of entity form states/types. + */ + export const enum FormType + { + Undefined = 0, + Create = 1, + Update = 2, + ReadOnly = 3, + Disabled = 4, + BulkEdit = 6 + } + + /** + * Enumeration of entity form save modes. + */ + export const enum SaveMode + { + Save = 1, + SaveAndClose = 2, + SaveAndNew = 59, + AutoSave = 70, + SaveAsCompleted = 58, + Deactivate = 5, + Reactivate = 6, + Assign = 47, + Send = 7, + Qualify = 16, + Disqualify = 15 + } + + /** + * Enumeration of stage categories. + */ + export const enum StageCategory + { + Qualify = 0, + Develop = 1, + Propose = 2, + Close = 3, + Identify = 4, + Research = 5, + Resolve = 6 + } + + /** + * Enumeration of grid control context resolutions. + */ + export const enum GridControlContext + { + Unknown = 0, + RibbonContextForm = 1, + RibbonContextListing = 2, + FormContextUnrelated = 3, + FormContextRelated = 4 + } + + /** + * Interface for a CRM Business Process Flow instance. + */ + 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}". + */ + getId(): string; + + /** + * Returns the name of the process. + * + * @return The name. + */ + getName(): string; + + /** + * Returns an collection of stages in the process. + * + * @return The stages. + */ + getStages(): Collection.ItemCollection; + + /** + * Returns a boolean value to indicate if the process is rendered. + * + * @return true if the process is rendered, false if not. + */ + isRendered(): boolean; + } + + /** + * Interface for CRM Business Process Flow stages. + */ + export interface Stage + { + /** + * Returns an object with a getValue method which will return the integer value of the business process flow + * category. + * + * @return The stage category. + */ + getCategory(): { getValue(): StageCategory }; + + /** + * Returns the logical name of the entity associated with the stage. + * + * @return The entity name. + */ + getEntityName(): string; + + /** + * Returns the unique identifier of the stage. + * + * @return The identifier of the Stage, in GUID format. + * + * @remarks Example: "{825CB223-A651-DF11-AA8B-00155DBA3804}". + */ + getId(): string; + + /** + * Returns the name of the stage. + * + * @return The name. + */ + getName(): string; + + /** + * Returns the status of the stage. + * + * @return The status. + * + * @remarks This method will return either "active" or "inactive". + */ + getStatus(): string; + + /** + * Returns a collection of steps in the stage. + * + * @return An array of Step. + */ + getSteps(): Step[]; + } + + export interface Step + { + /** + * Returns the logical name of the attribute associated to the step. + * + * @return The attribute. + * + * @remarks Some steps don’t contain an attribute value. + */ + getAttribute(): string; + + /** + * Returns the name of the step. + * + * @return The name. + */ + getName(): string; + + /** + * Returns whether the step is required in the business process flow. + * + * @return true if required, false if not. + * + * @remarks Returns true if the step is marked as required in the Business Process Flow editor; otherwise, false. + * There is no connection between this value and the values you can change in the Xrm.Page.data.entity + * attribute RequiredLevel methods. + */ + isRequired(): boolean; + } + + /** + * Interface for the event context. + */ + export interface EventContext + { + /** + * Gets the Xrm context. + * + * @return The Xrm context. + */ + getContext(): Context; + + /** + * Gets the handler's depth, which is the order in which the handler is executed. + * + * @return The depth, a 0-based index. + */ + getDepth(): number; + + /** + * Gets save-event arguments. + * + * @return The event arguments. + * + * @remarks Returns null for all but the "save" event. + */ + getEventArgs(): SaveEventArguments; + + /** + * Gets a reference to the object for which event occurred. + * + * @return The event source. + */ + getEventSource(): Xrm.Page.Attribute | Xrm.Page.Entity; + + /** + * Gets the shared variable with the specified key. + * + * @tparam T Generic type parameter. + * @param {string} key The key. + * + * @return The shared variable. + * + * @remarks Used to pass values between handlers of an event. + */ + getSharedVariable( key: string ): T; + + /** + * Sets a shared variable. + * + * @tparam T Generic type parameter. + * @param {string} key The key. + * @param {T} value The value. + * + * @remarks Used to pass values between handlers of an event. + */ + setSharedVariable( key: string, value: T ): void; + } + + /** + * Interface for a context-sensitive handler. + */ + export interface ContextSensitiveHandler + { + /** + * @param {EventContext} context The context. + */ + ( context?: EventContext ): void; + } + + /** + * Base interface for UI elements. + */ + export interface UiElement + { + /** + * Gets the label. + * + * @return The label. + */ + getLabel(): string; + + /** + * Gets the visibility state. + * + * @return true if the tab is visible, otherwise false. + */ + getVisible(): boolean; + + /** + * Sets the label. + * + * @param {string} label The label. + */ + setLabel( label: string ): void; + + /** + * Sets the visibility state. + * + * @param {boolean} visible true to show, false to hide. + */ + setVisible( visible: boolean ): void; + } + + /** + * Interface for focusable UI elements. + */ + export interface UiFocusable + { + /** + * Sets focus on the element. + */ + setFocus(): void; + } + + /** + * Interface for a Lookup value. + */ + export interface LookupValue + { + /** + * The identifier. + */ + id: string; + + /** + * The name + */ + name?: string; + + /** + * Type of the entity. + */ + entityType: string; + } + + /** + * Interface for an OptionSet value. + */ + export interface OptionSetValue + { + /** + * The label text. + */ + 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. + */ + value: string; + } + + /** + * Interface for a privilege. + */ + export interface Privilege + { + /** + * true if the user can read. + */ + canRead: boolean; + + /** + * true if the user can update. + */ + canUpdate: boolean; + + /** + * true if the user can create. + */ + canCreate: boolean; + } + + /** + * Interface for an Entity attribute. + */ + export interface Attribute + { + /** + * Adds a handler to be called when the attribute's value is changed. + * + * @param {ContextSensitiveHandler} handler The function reference. + */ + addOnChange( handler: ContextSensitiveHandler ): void; + + /** + * Fire all "on change" event handlers. + */ + fireOnChange(): void; + + /** + * Gets attribute type. + * + * @return The attribute's type name. + * + * @remarks Values returned are: boolean + * datetime + * decimal + * double + * integer + * lookup + * memo + * money + * optionset + * string + */ + getAttributeType(): string; + + /** + * Gets the attribute format. + * + * @return The format of the attribute. + * + * @see {@link getAttributeType()} + * + * @remarks Values returned are: date (datetime) + * datetime (datetime) + * duration (integer) + * email (string) + * language (optionset) + * none (integer) + * phone (string) + * text (string) + * textarea (string) + * tickersymbol (string) + * timezone (optionset) + * url (string) + */ + getFormat(): string; + + /** + * Gets a boolean value indicating whether this Attribute has unsaved changes. + * + * @return true if there are unsaved changes, otherwise false. + */ + getIsDirty(): boolean; + + /** + * Gets the logical name of the attribute. + * + * @return The logical name. + */ + getName(): string; + + /** + * Gets a reference to the record context of this attribute. + * + * @return The parent record context. + */ + getParent(): Entity; + + /** + * Gets the current level of requirement for the attribute. + * + * @return The required level, as either "none", "required", or "recommended" + */ + getRequiredLevel(): string; + + /** + * Gets current submit mode for the attribute. + * + * @return The submit mode, as either "always", "never", or "dirty" + * + * @remarks The default value is "dirty" + */ + getSubmitMode(): string; + + /** + * Gets the current user's privileges for the attribute. + * + * @return The user privileges. + */ + getUserPrivilege(): Privilege; + + /** + * Removes the handler from the "on change" event. + * + * @param {ContextSensitiveHandler} handler The handler. + */ + 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; + + /** + * Sets the submit mode. + * + * @param {string} submitMode The submit mode, as either "always", "never", or "dirty". + * + * @remarks The default value is "dirty" + */ + setSubmitMode( submitMode: string ): void; + + /** + * A collection of all the controls on the form that interface with this attribute. + */ + controls: Collection.ItemCollection; + } + + /** + * Interface for a Number attribute. + * + * @sa Attribute + */ + export interface NumberAttribute extends Attribute + { + /** + * Gets the maximum value allowed. + * + * @return The maximum value allowed. + */ + getMax(): number; + + /** + * Gets the minimum value allowed. + * + * @return The minimum value allowed. + */ + getMin(): number; + + /** + * Gets the attribute's configured precision. + * + * @return The total number of allowed decimal places. + */ + getPrecision(): number; + + /** + * Gets the value. + * + * @return The value. + */ + getValue(): number; + + /** + * Sets the value. + * + * @param {number} value The value. + * + * @remarks Attributes on Quick Create Forms will not save values set with this method. + */ + setValue( value: number ): void; + } + + /** + * Interface for a String attribute. + * + * @sa Attribute + */ + export interface StringAttribute extends Attribute + { + /** + * Gets maximum length allowed. + * + * @return The maximum length allowed. + * + * @remarks The email form's "Description" attribute does not have the this method. + */ + getMaxLength(): number; + + /** + * Gets the value. + * + * @return The value. + */ + getValue(): string; + + /** + * Sets the value. + * + * @param {string} value The value. + * + * @remarks A String field with the {@link Attribute.getFormat|email} format enforces email + * address formatting. Attributes on Quick Create Forms will not save values set + * with this method. + */ + setValue( value: string ): void; + } + + /** + * Common interface for enumeration attributes (OptionSet and Boolean). + * + * @sa Attribute + */ + export interface EnumAttribute extends Attribute + { + /** + * Gets the initial value of the attribute. + * + * @return The initial value. + * @remarks Valid for optionset and boolean attribute types + */ + getInitialValue(): number | boolean; + } + + /** + * Interface for a Boolean attribute. + * + * @sa EnumAttribute + */ + export interface BooleanAttribute extends EnumAttribute + { + /** + * Gets the value. + * + * @return true if it succeeds, false if it fails. + */ + getValue(): boolean; + + /** + * Sets the value. + * + * @param {boolean} value The value. + * + * @remarks Attributes on Quick Create Forms will not save values set with this method. + */ + setValue( value: boolean ): void; + } + + /** + * Interface for a Date attribute. + * + * @sa Attribute + */ + export interface DateAttribute extends Attribute + { + /** + * Gets the value. + * + * @return The value. + */ + getValue(): Date; + + /** + * Sets the value. + * + * @param {Date} value The value. + * + * @remarks Attributes on Quick Create Forms will not save values set with this method. + */ + setValue( value: Date ): void; + } + + /** + * Interface an OptionSet attribute. + * + * @sa EnumAttribute + */ + export interface OptionSetAttribute extends EnumAttribute + { + /** + * Gets the option matching a value. + * + * @param {number} value The enumeration value of the option desired. + * + * @return The option. + */ + getOption( value: number ): OptionSetValue; + + /** + * Gets the option matching a label. + * + * @param {string} label The label of the option desired. + * + * @return The option. + */ + getOption( label: string ): OptionSetValue; + + /** + * Gets all of the options. + * + * @return An array of options. + */ + getOptions(): OptionSetValue[]; + + /** + * Gets selected option. + * + * @return The selected option. + */ + getSelectedOption(): OptionSetValue; + + /** + * Gets the label of the currently selected option. + * + * @return The current value's label. + */ + getText(): string; + + /** + * Gets the value. + * + * @return The value. + */ + getValue(): number; + + /** + * Sets the value. + * + * @param {number} value The value. + * + * @remarks The getOptions() method returns option values as strings. You must use parseInt + * to convert them to numbers before you can use those values to set the value of an + * OptionSet attribute. Attributes on Quick Create Forms will not save values set + * with this method. + */ + setValue( value: number ): void; + } + + /** + * Interface a Lookup attribute. + * + * @sa Attribute + */ + export interface LookupAttribute extends Attribute + { + /** + * Gets a boolean value indicating whether the Lookup is a multi-value PartyList. + * + * @return true the attribute is a PartyList, otherwise false. + */ + getIsPartyList(): boolean; + + /** + * Gets the value. + * + * @return An array of LookupValue. + */ + getValue(): LookupValue[]; + + /** + * Sets the value. + * + * @param {LookupValue[]} value The value. + * + * @remarks Attributes on Quick Create Forms will not save values set with this method. + */ + setValue( value: LookupValue[] ): void; + } + + /** + * Interface for the form's record context, Xrm.Page.data.entity + */ + export interface Entity + { + /** + * Adds a handler to be called when the record is saved. + * + * @param {ContextSensitiveHandler} handler The handler. + */ + addOnSave( handler: ContextSensitiveHandler ): void; + + /** + * Gets an serialized-XML string representing data that will be passed to the server upon saving + * the record. + * + * @return The XML in string format. + * + * @remarks This function does not work with Microsoft Dynamics CRM for tablets. Example: + * "Contoso55555425 + * 555-1234". + */ + getDataXml(): string; + + /** + * Gets entity's logical name. + * + * @return The logical name. + */ + getEntityName(): string; + + /** + * Gets the record's unique identifier. + * + * @return The identifier, in Guid format. + * + * @remarks Example: "{825CB223-A651-DF11-AA8B-00155DBA3804}". + */ + getId(): string; + + /** + * Gets a boolean value indicating whether the record has unsaved changes. + * + * @return true if there are unsaved changes, otherwise false. + */ + getIsDirty(): boolean; + + /** + * Gets the record's primary attribute value. + * + * @return The primary attribute value. + * + * @remarks The value for this attribute is used when links to the record are displayed. + */ + getPrimaryAttributeValue(): string; + + /** + * Removes the handler from the "on save" event. + * + * @param {ContextSensitiveHandler} handler The handler. + */ + removeOnSave( handler: ContextSensitiveHandler ): void; + + /** + * Saves the record. + * + * @remarks When using quick create forms in the web application the saveandnew option is not + * applied. It will always work as if saveandclose were used. Quick create forms in + * Microsoft Dynamics CRM for tablets will apply the saveandnew behavior. + */ + 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; + + /** + * The collection of attributes for the record. + */ + attributes: Collection.ItemCollection; + } + + /** + * Interface for save event arguments. + */ + export interface SaveEventArguments + { + /** + * Gets save mode, as an integer. + * + * @return The save mode. + * @remarks Values returned are: 1 Save + * 2 Save and Close + * 59 Save and New + * 70 AutoSave (Where enabled; can be used with an OnSave handler + * to conditionally disable auto-saving) + * 58 Save as Completed (Activities) + * 5 Deactivate + * 6 Reactivate + * 47 Assign (All user- or team-owned entities) + * 7 Send (Email) + * 16 Qualify (Lead) + * 15 Disqualify (Lead) + */ + getSaveMode(): SaveMode; + + /** + * Returns a boolean value to indicate if the record's save has been prevented. + * + * @return true if saving is prevented, otherwise false. + */ + isDefaultPrevented(): boolean; + + /** + * Prevents the save operation from being submitted to the server. + * @remarks All remaining "on save" handlers will continue execution. + */ + preventDefault(): void; + } + + /** + * Module for the Xrm.Page.data API. + */ + export module data + { + /** + * Interface for the Xrm.Page.data.process API. + */ + export interface ProcessManager + { + /** + * Returns a Process object representing the active process. + * + * @return current active process. + */ + getActiveProcess(): Process; + + /** + * Set a Process as 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; + + /** + * Returns a Stage object representing the active stage. + * + * @return current active stage. + */ + getActiveStage(): Stage; + + /** + * Set a stage as the active stage. + * + * @param {string} stageId the Id of the stage to make the active stage. + * @param {function} callbackFunction (Optional) a function to call when the operation is complete. + */ + setActiveStage( stageId: string, callbackFunction?: ProcessCallbackDelegate ): void; + + /** + * Use this method to get a collection of stages currently in the active path with methods to interact with the + * stages displayed in the business process flow control. The active path represents stages currently rendered in + * the process control based on the branching rules and current data in the record. + * + * @return A collection of all completed stages, the currently active stage, and the predicted set of future stages + * based on satisfied conditions in the branching rule. This may be a subset of the stages returned with + * Xrm.Page.data.process.getActiveProcess because it will only include those stages which represent a valid + * transition from the current stage based on branching that has occurred in the process. + */ + getActivePath(): Collection.ItemCollection; + + /** + * 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. + */ + getEnabledProcesses( callbackFunction: ( enabledProcesses: ProcessDictionary ) => void ): void; + + /** + * 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. + */ + addOnStageChange( 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. + */ + removeOnStageSelected( handler: ContextSensitiveHandler ): void; + + /** + * Progresses to the next stage. + * + * @param {ProcessCallbackDelegate} callbackFunction (Optional) A function to call when the operation is + * complete. + */ + moveNext( callbackFunction?: ProcessCallbackDelegate ): void; + + /** + * Moves to the previous stage. + * + * @param {ProcessCallbackDelegate} callbackFunction (Optional) A function to call when the operation is + * complete. + */ + movePrevious( callbackFunction?: ProcessCallbackDelegate ): void; + } + + /** + * Called when process change methods have completed. + * + * @param {string} status The result of the process change operation. + * @remarks Values returned are: success (The operation succeeded.) + * crossEntity (The previous stage is for a different entity.) + * beginning (The active stage is the first stage of the active path.) + * invalid (The operation failed because the selected stage isn’t the same + * as the active stage.) + * unreachable (The stage exists on a different path.) + */ + export type ProcessCallbackDelegate = ( status: string ) => void; + + /** + * Represents a key-value pair, where the key is the Process Flow's ID, and the value is the name thereof. + */ + export type ProcessDictionary = { [index: string]: string }; + + /** + * Asynchronously refreshes data on the form, without reloading the page. + * + * @param {boolean} save true to save the record, after the refresh. + * + * @return An Async.XrmPromise. + */ + export function refresh( save: boolean ): Async.XrmPromise; + + /** + * Asynchronously saves the record. + * + * @return An Async.XrmPromise. + */ + export function save(): Async.XrmPromise; + + /** + * The record context of the form. + */ + export var entity: Entity; + + /** + * The process API for Xrm.Page.data. + * + * @remarks This member may be undefined when Process Flows are not used by the current entity. + */ + export var process: ProcessManager; + } + + /** + * Interface for Xrm.Page.ui controls. + * + * @sa UiElement + */ + export interface Control extends UiElement + { + /** + * Clears the notification identified by uniqueId. + * + * @param {string} uniqueId (Optional) Unique identifier. + * + * @return true if it succeeds, false if it fails. + * + * @remarks If the uniqueId parameter is not used, the current notification shown will be removed. + */ + clearNotification( uniqueId?: string ): boolean; + + /** + * Gets the control's type. + * + * @return The control type. + * @remarks Values returned are: standard + * iframe + * lookup + * optionset + * subgrid + * webresource + * notes + * timercontrol + * kbsearch (CRM Online Only, use parature.d.ts) + */ + getControlType(): string; + + /** + * Gets a boolean value, indicating whether the control is disabled. + * + * @return true if it is disabled, otherwise false. + */ + getDisabled(): boolean; + + /** + * Gets the name of the control on the form. + * + * @return The name of the control. + * + * @remarks The name assigned to a control is not determined until the form loads. Changes to + * the form may change the name assigned to a given control. + * When you use the control getName method the name of the first control will be the + * same as the name of the attribute. The second instance of a control for that + * attribute will be "1". The pattern +N + * will continue for each additional control added to the form for a specific + * attribute. When a form displays a business process flow control in the header, + * additional controls will be added for each attribute that is displayed in the + * business process flow. These controls have a unique name like the following: + * header_process_. + */ + getName(): string; + + /** + * Gets a reference to the Section parent of the control. + * + * @return The parent Section. + */ + getParent(): Section; + + /** + * Sets the state of the control to either enabled, or disabled. + * + * @param {boolean} disabled true to disable, false to enable. + */ + setDisabled( disabled: boolean ): void; + + /** + * Sets a control-local notification message. + * + * @param {string} message The message. + * @param {string} uniqueId Unique identifier. + * + * @return true if it succeeds, false if it fails. + * + * @remarks When this method is used on Microsoft Dynamics CRM for tablets a red "X" icon + * appears next to the control. Tapping on the icon will display the message. + */ + setNotification( message: string, uniqueId: string ): boolean; + } + + /** + * Interface for a standard control. + * + * @sa Control + */ + export interface StandardControl extends Control + { + /** + * Gets the control's bound attribute. + * + * @tparam T An Attribute type. + * + * @return The attribute. + */ + getAttribute(): T; + + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): Attribute; + } + + /** + * Interface for a Date control. + * + * @sa StandardControl + */ + export interface DateControl extends StandardControl + { + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): DateAttribute; + + /** + * Gets the status of the time-of-day component of the Date control. + * + * @return true if the time is shown, otherwise false. + */ + getShowTime(): boolean; + + /** + * Sets the visibility of the time component of the Date control. + * + * @param {boolean} showTimeValue true to show, false to hide the time value. + */ + setShowTime( showTimeValue: boolean ): void; + } + + /** + * Interface for a Lookup control. + * + * @sa StandardControl + */ + export interface LookupControl extends StandardControl + { + /** + * Adds a handler to the "pre search" event of the Lookup control. + * + * @param {Function} handler The handler. + */ + addPreSearch( handler: () => void ): void; + + /** + * Adds an additional custom filter to the lookup, with the "AND" filter operator. + * Can only be used within a "pre search" event handler + * + * @sa addPreSearch + * + * @param {string} filter Specifies the filter, as a serialized FetchXML + * "filter" node. + * @param {string} entityLogicalName (Optional) The logical name of the entity. + * + * @remarks If entityLogicalName is not specified, the filter will be applied to all entities + * valid for the Lookup control. + * Example filter: + * + * + */ + addCustomFilter( filter: string, entityLogicalName?: string ): void; + + /** + * Adds a custom view for the Lookup dialog. + * + * @param {string} viewId Unique identifier for the view, in Guid format. + * @param {string} entityName Name of the entity. + * @param {string} viewDisplayName Name of the view to display. + * @param {string} fetchXml The FetchXML query for the view's contents, serialized as a string. + * @param {string} layoutXml The Layout XML, serialized as a string. + * @param {boolean} isDefault true, to treat this view as default. + * + * @remarks Cannot be used on "Owner" Lookup controls. + * The viewId is never saved to CRM, but must be unique across available views. Generating + * a new value can be accomplished with a {@link http://www.guidgen.com/|Guid generator}. + * Example viewId value: "{00000000-0000-0000-0000-000000000001}" + * Layout XML Reference: {@link http://msdn.microsoft.com/en-us/library/gg334522.aspx} + */ + addCustomView( viewId: string, entityName: string, viewDisplayName: string, fetchXml: string, layoutXml: string, isDefault: boolean ): void; + + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): LookupAttribute; + + /** + * Gets the unique identifier of the default view. + * + * @return The default view, in Guid format. + * + * @remarks Example: "{00000000-0000-0000-0000-000000000000}" + */ + getDefaultView(): string; + + /** + * Removes the handler from the "pre search" event of the Lookup control. + * + * @param {Function} handler The handler. + */ + removePreSearch( handler: () => void ): void; + + /** + * Sets the Lookup's default view. + * + * @param {string} viewGuid Unique identifier for the view. + * + * @remarks Example viewGuid value: "{00000000-0000-0000-0000-000000000000}" + */ + setDefaultView( viewGuid: string ): void; + } + + /** + * Interface for an OptionSet control. + * + * @sa StandardControl + */ + export interface OptionSetControl extends StandardControl + { + /** + * Adds an option. + * + * @param {OptionSetValue} option The option. + * @param {number} index (Optional) zero-based index of the option. + * + * @remarks This method does not check that the values within the options you add are valid. + * If index is not provided, the new option will be added to the end of the list. + */ + addOption( option: OptionSetValue, index?: number ): void; + + /** + * Clears all options. + */ + clearOptions(): void; + + /** + * Gets the control's bound attribute. + * + * @return The attribute. + */ + getAttribute(): OptionSetAttribute; + + /** + * Removes the option matching the value. + * + * @param {number} value The value. + */ + removeOption( value: number ): void; + } + + /** + * Interface for a CRM grid control. + * + * @sa Control + */ + export interface GridControl extends Control + { + /** + * Use this method to add event handlers to the GridControl's OnLoad event. + * + * @param {Function} handler The event handler. + */ + addOnLoad( handler: () => void ): void; + + /** + * This method returns context information about the GridControl. + * + * @return The context type. + */ + getContextType(): GridControlContext; + + /** + * Use this method to get the logical name of the entity data displayed in the grid. + * + * @return The entity name. + */ + getEntityName(): string; + + /** + * Use this method to get access to the Grid available in the GridControl. + * + * @return The grid. + */ + getGrid(): ui.Grid; + + /** + * Use this method to get access to the ViewSelector available for the GridControl when it is configured to display views. + * + * @return The view selector. + */ + getViewSelector(): ui.ViewSelector; + + /** + * Refreshes the sub grid. + * + * @remarks Not available during the "on load" event of the form. + */ + refresh(): void; + + /** + * Use this method to remove event handlers from the GridControl's OnLoad event. + * + * @param {Function} handler The handler. + */ + removeOnLoad( handler: () => void ): void; + } + + /** + * Interface for a framed control, which is either a Web Resource or an Iframe. + * + * @sa Control + * + * @remarks An Iframe control provides additional methods, so use {@link IframeControl} where + * appropriate. Silverlight controls should use {@link SilverlightControl}. + */ + export interface FramedControl extends Control + { + /** + * Gets the DOM element containing the control. + * + * @return The container object. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getObject(): HTMLIFrameElement; + + /** + * Gets the URL value of the control. + * + * @return The source URL. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getSrc(): string; + + /** + * Sets the URL value of the control. + * + * @param {string} src The source URL. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + setSrc( src: string ): void; + } + + /** + * Interface for an Iframe control. + * + * @sa FramedControl + */ + export interface IframeControl extends FramedControl + { + /** + * Gets initial URL defined for the Iframe. + * + * @return The initial URL. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getInitialUrl(): string; + } + + /** + * Interface for a Silverlight control. + * + * @sa Control + */ + export interface SilverlightControl extends Control + { + /** + * Gets the query string value passed to Silverlight. + * + * @return The data. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getData(): string; + + /** + * Sets the query string value passed to Silverlight. + * + * @param {string} data The data. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + setData( data: string ): void; + + /** + * Gets the DOM element containing the control. + * + * @return The container object. + * + * @remarks Unavailable for Microsoft Dynamics CRM for tablets. + */ + getObject(): HTMLObjectElement; + } + + /** + * Interface for a form tab. + * + * @sa UiElement + * @sa UiFocusable + */ + export interface Tab extends UiElement, UiFocusable + { + /** + * Gets display state of the tab. + * + * @return The display state, as either "expanded" or "collapsed" + */ + getDisplayState(): string; + + /** + * Gets the name of the tab. + * + * @return The name. + */ + getName(): string; + + /** + * Gets a reference to the Xrm.Page.ui parent of the tab. + * + * @return The parent. + */ + getParent(): typeof 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; + + /** + * A reference to the collection of form sections within this tab. + */ + sections: Collection.ItemCollection
; + } + + /** + * Interface for a form section. + * + * @sa UiElement + */ + export interface Section extends UiElement + { + /** + * Gets the name of the section. + * + * @return The name. + */ + getName(): string; + + /** + * Gets a reference to the Xrm.Page.Tab parent of this item. + * + * @return The parent. + */ + getParent(): Tab; + + /** + * A reference to the collection of controls within this tab. + */ + controls: Collection.ItemCollection; + } + + /** + * Module for Xrm.Page.ui API. + */ + export module ui + { + /** + * 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; + + /** + * Sets the visibility state. + * + * @param {boolean} visible true to show, false to hide. + */ + setVisible( visible: boolean ): void; + } + + /** + * Interface for a grid. Use Grid methods to access information about data in the grid. Grid is returned by the + * GridControl.getGrid method. + */ + export interface Grid + { + /** + * Returns a collection of every GridRow in the Grid. + * + * @return The rows. + */ + getRows(): Collection.ItemCollection; + + /** + * Returns a collection of every selected GridRow in the Grid. + * + * @return The selected rows. + */ + getSelectedRows(): Collection.ItemCollection; + + /** + * Returns the total number of records in the Grid. + * + * @return The total record count. + */ + getTotalRecordCount(): number; + } + + /** + * Interface for a grid row. Use the GridRow.getData method to access the GridRowData. A collection of GridRow is + * returned by Grid.getRows and Grid.getSelectedRows methods. + */ + export interface GridRow + { + /** + * Returns the GridRowData for the GridRow. + * + * @return The data. + */ + getData(): GridRowData; + } + + /** + * Interface for grid row data. Use the GridRowData.getEntity method to access the GridEntity. GridRowData is + * returned by the GridRow.getData method. + */ + export interface GridRowData + { + /** + * Returns the GridEntity for the GridRowData. + * + * @return The entity. + */ + getEntity(): GridEntity; + } + + /** + * Interface for a grid entity. Use the GridEntity methods to access data about the specific records in the rows. + * GridEntity is returned by the GridRowData.getEntity method. + */ + export interface GridEntity + { + /** + * Returns the logical name for the record in the row. + * + * @return The entity name. + */ + getEntityName(): string; + + /** + * Returns a LookupValue that references this record. + * + * @return The entity reference. + */ + getEntityReference(): LookupValue; + + /** + * Returns the id for the record in the row. + * + * @return The identifier of the GridEntity, in GUID format. + * + * @remarks Example return: "{00000000-0000-0000-0000-000000000000}" + */ + getId(): string; + + /** + * Returns the primary attribute value for the record in the row. (Commonly the name.) + * + * @return The primary attribute value. + */ + getPrimaryAttributeValue(): string; + } + + /** + * Interface for the view selector. Use the ViewSelector methods to get or set information about the view selector + * of the grid control. + */ + export interface ViewSelector + { + /** + * Use this method to get a reference to the current view. + * + * @return The current view. + */ + getCurrentView(): ViewSelectorItem; + + /** + * Use this method to determine whether the view selector is visible. + * + * @return true if visible, false if not. + */ + isVisible(): boolean; + + /** + * Use this method to set the current view. + * + * @param {ViewSelectorItem} viewSelectorItem The view selector item. + */ + setCurrentView( viewSelectorItem: ViewSelectorItem ): void; + } + + /** + * Interface for a view selector item. This object contains data that identifies a view. Use this as a parameter to + * the ViewSelector.setCurrentView method. + */ + export interface ViewSelectorItem + { + /** + * Returns a LookupValue that references this view. + * + * @return The entity reference. + */ + getEntityReference(): LookupValue; + } + + /** + * Clears the form notification described by uniqueId. + * + * @param {string} uniqueId Unique identifier. + * + * @return true if it succeeds, otherwise false. + */ + export function clearFormNotification( uniqueId: string ): boolean; + + /** + * Closes the form. + */ + export function close(): void; + + /** + * Gets form type. + * + * @return The form type. + * + * @remarks Values returned are: 0 Undefined + * 1 Create + * 2 Update + * 3 Read Only + * 4 Disabled + * 6 Bulk Edit + * Deprecated values are 5 (Quick Create), and 11 (Read Optimized) + */ + export function getFormType(): FormType; + + /** + * Gets view port height. + * + * @return The view port height, in pixels. + * + * @remarks This method does not work with Microsoft Dynamics CRM for tablets. + */ + export function getViewPortHeight(): number; + + /** + * Gets view port width. + * + * @return The view port width, in pixels. + * + * @remarks This method does not work with Microsoft Dynamics CRM for tablets. + */ + export function getViewPortWidth(): number; + + /** + * Re-evaluates the ribbon's configured EnableRules + * + * @remarks This method does not work with Microsoft Dynamics CRM for tablets. + */ + export function 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. + */ + export function 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. + */ + export function 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. + */ + export function 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. + */ + export function setFormNotification( message: string, level: string, uniqueId: string ): boolean; + + export var process: ProcessManager; + + /** + * A reference to the collection of controls on the form. + */ + export var controls: Collection.ItemCollection; + + /** + * The form selector API. + * + * @remarks This API does not exist with Microsoft Dynamics CRM for tablets. + */ + export var formSelector: FormSelector; + + /** + * The navigation API. + * + * @remarks This API does not exist with Microsoft Dynamics CRM for tablets. + */ + export var navigation: Navigation; + + /** + * A reference to the collection of tabs on the form. + */ + export var tabs: Collection.ItemCollection; + } + + /** + * Interface for a navigation item. + * + * @sa UiElement + * @sa UiFocusable + */ + export interface NavigationItem extends UiElement, UiFocusable + { + /** + * Gets the name of the item. + * + * @return The identifier. + */ + getId(): string; + } + + /** + * Interface for Xrm.Page.ui.navigation. + */ + export interface Navigation + { + /** + * A reference to the collection of available navigation items. + */ + items: Collection.ItemCollection; + } + + /** + * Interface for an entity's form selector item. + */ + export interface FormItem + { + /** + * Gets the unique identifier of the form. + * + * @return The identifier, in Guid format. + */ + getId(): string; + + /** + * Gets the label for the form. + * + * @return The label. + */ + getLabel(): string; + + /** + * Navigates the user to this form. + */ + navigate(): void; + } + + /** + * Interface for the form selector API. + */ + export interface FormSelector + { + /** + * Gets current form. + * + * @return The current item. + * + * @remarks When only one form is available this method will return null. + */ + getCurrentItem(): FormItem; + + /** + * A reference to the collection of available forms. + */ + items: Collection.ItemCollection; + } + + /** + * A reference to the xRM application context. + */ + export var context: Context; + + /** + * Gets all attributes. + * + * @return An array of attributes. + */ + export function getAttribute(): Attribute[]; + + /** + * Gets an attribute matching attributeName. + * + * @tparam T An Attribute type. + * @param {string} attributeName Name of the attribute. + * + * @return The attribute. + */ + export function getAttribute( attributeName: string ): T; + + /** + * Gets an attribute matching attributeName. + * + * @param {string} attributeName Name of the attribute. + * + * @return The attribute. + */ + export function getAttribute( attributeName: string ): Attribute; + + /** + * Gets an attribute by index. + * + * @param {number} index The attribute index. + * + * @return The attribute. + */ + export function getAttribute( index: number ): Attribute; + + /** + * Gets an attribute. + * + * @param {Collection.MatchingDelegate{Attribute}} delegateFunction A matching delegate function + * + * @return An array of attribute. + */ + export function getAttribute( delegateFunction: Collection.MatchingDelegate ): Attribute[]; + + /** + * Gets all controls. + * + * @return An array of controls. + */ + export function getControl(): Control[]; + + /** + * Gets a control matching controlName. + * + * @tparam T A Control type + * @param {string} controlName Name of the control. + * + * @return The control. + */ + export function getControl( controlName: string ): T; + + /** + * Gets a control matching controlName. + * + * @param {string} controlName Name of the control. + * + * @return The control. + */ + export function getControl( controlName: string ): Control; + + /** + * Gets a control by index. + * + * @param {number} index The control index. + * + * @return The control. + */ + export function getControl( index: number ): Control; + + /** + * Gets a control. + * + * @param {Collection.MatchingDelegate{Control}} delegateFunction A matching delegate function. + * + * @return An array of control. + */ + export function getControl( delegateFunction: Collection.MatchingDelegate ): Control[]; + } + + /** + * An definition module for URL-based, CRM component parameters. + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + */ + export module Url + { + /** + * An enumeration for view types. + */ + export const enum ViewType + { + SystemView = 1039, + UserView = 4230 + } + + /** + * 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: + * "&key=value". + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + * + * @remarks A member for "pagetype" is not provided. The value "entityrecord" is required in + * the URL, for forms. Example: "pagetype=entityrecord" + */ + export interface FormOpenParameters + { + /** + * The logical name of the entity. + */ + etn: string; + + /** + * Additional parameters can be provided to the request. This can only be used to provide + * default field values for the form, or pass data to custom parameters that have been + * customized for the form. See example below for setting the selected form. + * + * @remarks Example: encodeURIComponent( "formid={8c9f3e6f-7839-e211-831e-00155db7d98f}" ); + */ + extraqs?: string; + + /** + * 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; + + /** + * Controls whether the Navigation bar is displayed on the form. + * Accepted values are: "on" (The navigation bar is displayed.) + * "off" (The navigation bar is not displayed.) + * "entity" (On an entity form, only the navigation options for related + * entities are available.) + */ + navbar?: string; + } + + /** + * Interface for defining parameters on a request to open a view with main.aspx (as with + * window.open). Useful for parsing the keys and values into a string of the format: + * "&key=value". + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + * + * @remarks A member for "pagetype" is not provided. The value "entitylist" is required in + * the URL, for views. Example: "pagetype=entitylist" + */ + export interface ViewOpenParameters + { + /** + * The logical name of the entity. + */ + etn: string; + + /** + * The unique identifier of a view, in Guid format, which is valid for the entity described by + * {@link etn}. + */ + viewid: string; + + /** + * The type of view identified by {@link viewid}. + * + * @remarks Accepted values are: 1039 System View + * 4230 User View. + */ + viewtype: ViewType; + + /** + * 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; + + /** + * Controls whether the Navigation bar is displayed on the form. + * Accepted values are: "on" (The navigation bar is displayed.) + * "off" (The navigation bar is not displayed.) + * "entity" (On an entity form, only the navigation options for related + * entities are available.) + */ + navbar?: string; + } + + /** + * Interface for defining parameters of a request to open a dialog with rundialog.aspx (as with + * window.open). Useful for parsing the keys and values into a string of the format: + * "&key=value". + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + */ + export interface DialogOpenParameters + { + /** + * The unique identifier of the dialog, in Guid format, which is valid for the entity described + * by: {@link EntityName} + */ + DialogId: string; + + /** + * The logical name of the entity. + */ + EntityName: string; + + /** + * The unique identifier for the targeted record. + */ + ObjectId: string; + } + + /** + * Interface for defining parameters of a request to open a report with viewer.apsx (as with + * window.open). Useful for parsing out the keys and values into a string of the format: + * "&key=value" + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328483.aspx} for details. + */ + export interface ReportOpenParameters + { + /** + * The action to perform, as either "run" or "filter". + * + * @remarks "run" Executes the report with default filters. + * "filter" Presents the user with the filter editor, and a "Run Report" button. + */ + action: string; + + /** + * The file name of the report. For out-of-box reports, this parameter enables context-sensitive + * help. + */ + helpID?: string; + + /** + * The unique identifier, held in the report's 'reportid' attribute, in Guid format. + */ + id: string; + } + } + + /** + * The Xrm.Utility API + * + * @see {@link http://msdn.microsoft.com/en-us/library/gg328255.aspx|Documentation} for details. + */ + export module Utility + { + export interface OpenParameters + { + /** + * Additional parameters can be provided to the request, by overloading + * this object with additional key and value pairs. This can only be used + * to provide default field values for the form, or pass data to custom + * parameters that have been customized for the form. + */ + [index: string]: string; + } + + /** + * Interface for defining parameters on a Xrm.Utility.openEntityForm() request. + */ + export interface FormOpenParameters extends OpenParameters + { + /** + * The identifier of the form to use, when several are available. + */ + formid: string; + + /** + * Controls whether the Navigation bar is displayed on the form. + * Accepted values are: "on" (The navigation bar is displayed.) + * "off" (The navigation bar is not displayed.) + * "entity" (On an entity form, only the navigation options for related + * entities are available.) + */ + navbar?: string; + + /** + * 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; + } + + /** + * Interface for window options. + */ + export interface WindowOptions + { + /** + * Direct the form to open in a new window. + */ + openInNewWindow: boolean; + } + + /** + * Displays an alert dialog, with an "OK" button. + * + * @param {string} message The message. + * @param {function()} onCloseCallback The "OK" callback. + */ + export function alertDialog( message: string, onCloseCallback: () => void ): void; + + /** + * Displays a confirmation dialog, with "OK" and "Cancel" buttons. + * + * @param {string} message The message. + * @param {function()} yesCloseCallback The "OK" callback. + * @param {function()} noCloseCallback The "Cancel" callback. + */ + export function confirmDialog( message: string, yesCloseCallback: () => void, noCloseCallback: () => void ): void; + + /** + * Query if 'entityType' is an Activity entity. + * + * @param {string} entityType Type of the entity. + * + * @return true if the entity is an Activity, false if not. + */ + export function isActivityType( entityType: string ): boolean; + + /** + * Opens an entity form. + * + * @param {string} name The entity's logical name. + * @param {string} id (Optional) The unique identifier for the record. + * @param {FormParameters} parameters (Optional) A dictionary object that passes extra query string parameters to the form. + * @param {WindowOptions} windowOptions (Optional) Options for controlling the window. + */ + export function openEntityForm( name: string, id?: string, parameters?: FormOpenParameters, windowOptions?: WindowOptions ): void; + + /** + * Opens quick create. + * + * @param {Function} callback The function that will be called when a record is created. This + * function is passed a LookupValue object as a parameter. + * @param {string} entityLogicalName The logical name of the entity to create. + * @param {Page.LookupValue} createFromEntity (Optional) Designates a record that will provide default values + * based on mapped attribute values. + * @param {OpenParameters} parameters (Optional) A dictionary object that passes extra query string + * parameters to the form. Invalid query string parameters will cause an + * error. + */ + export function openQuickCreate( callback: ( recordReference: Page.LookupValue ) => void, + entityLogicalName: string, + createFromEntity?: Page.LookupValue, + parameters?: OpenParameters ): void; + + /** + * Opens an HTML Web Resource in a new browser window. + * + * @param {string} webResourceName Name of the HTML web resource. Can be used to pass URL + * parameters. See Remarks. + * @param {string} webResourceData (Optional) Data to pass into the Web Resource's data parameter. + * It is advised to use encodeURIcomponent() to encode the value. + * @param {number} width (Optional) The width of the new window. + * @param {number} height (Optional) The height of the new window. + * + * @return A Window reference, containing the opened Web Resource. + * + * @remarks This function will not work with Microsoft Dynamics CRM for tablets. + * Valid WebResource URL Parameters: typename + * type + * id + * orgname + * userlcid + * data (identical to this method's webResourceData parameter) + * formid + */ + export function openWebResource( webResourceName: string, webResourceData?: string, width?: number, height?: number ): Window; + } +}