/scripts/XrmPageTemplate.js
JavaScript | 2658 lines | 1634 code | 160 blank | 864 comment | 363 complexity | cd7069f0b78a74c601d0665624d47bdf MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /// <reference path="PageData.js" />
-
- // DO NOT MODIFY THIS FILE.
-
- // After you have installed the Xrm.Page Script Development Form Snapshot solution in your organization,
- // use the Xrm.Page Snapshot button on the Customize tab of a form to generate a pageData object.
- // Copy the pageData object definition into the PageData.js file in this Visual Studio project.
- // - You should overwrite the existing definition
- // In your JScript library you should now get IntelliSense completion support for child objects of the Xrm.Page
- // Methods in Xrm.Page will provide IntelliSense guidance.
- // Methods that change Xrm.Page data will allow retrieving and setting data values.
- // Use the TestPage.htm to include scripts to test functions in your library.
-
-
- if (typeof (pageData) == "undefined") {
- var message = ["You must include the output of the Xrm.Page Snapshot in the\n",
- " PageData.js file for this solution. After you have installed the Xrm.Page Script Development Form Snapshot solution\n",
- " open an entity form and click the Customize tab in the ribbon. Click\n",
- " the Xrm.Page Snapshot button and copy the output into PageData.js."]
- alert(message.join(""));
-
- }
-
- var _cntrlDictionary = {};
- var _attDictionary = {};
- var _formsDictionary = null;
- var _navItemDictionary = {};
- var Xrm = new _xrm();
-
- function _xrm() {
- this.Page = new _page();
- if (pageData.xrmUtilityExists)
- {
- this.Utility = new _utility();
- }
-
- this.__namespace = true;
- }
- _xrm.prototype.toString = function () {
- return "[object Xrm namespace]";
- }
-
- function _page() {
- this.context = new _context();
- this.data = new _data();
- this.ui = new _ui();
- this.getAttribute = function (argument) {
- /// <summary>
- /// Returns one or more attributes depending on the arguments passed.
- /// </summary>
- /// <param name="argument" mayBeNull="true" optional="true" >
- /// <para>1: None: Returns an array of all the attributes.</para>
- /// <para>2: String: Returns the attribute where the argument matches the name.</para>
- /// <para>3: Number: Returns the attribute where the argument matches the index.</para>
- /// <para>4: Function: Returns any attributes that cause the delegate function to return true.</para>
- /// </param>
- return Xrm.Page.data.entity.attributes.get(argument);
- }
- this.getControl = function (argument) {
- /// <summary>
- /// Returns one or more controls depending on the arguments passed.
- /// </summary>
- /// <param name="argument" type="Object" mayBeNull="true" optional="true" >
- /// <para>1: None: Returns an array of all the controls.</para>
- /// <para>2: String: Returns the control where the argument matches the name.</para>
- /// <para>3: Number: Returns the control where the argument matches the index.</para>
- /// <para>4: Function: Returns any controls that cause the delegate function to return true.</para>
- /// </param>
- return Xrm.Page.ui.controls.get(argument);
- }
- }
- _page.prototype.toString = function () {
- return "[object Xrm.Page]";
- }
-
- function _utility() {
- this.openEntityForm = function (name, id, parameters) {
- /// <summary>
- /// Opens an entity form.
- /// </summary>
- /// <param name="name" type="String" mayBeNull="false" optional="false" >
- /// The logical name of an entity.
- /// </param>
- /// <param name="id" type="String" mayBeNull="true" optional="true" >
- /// The string representation of a unique identifier or the record to open in the form. If not set, a form to create a new record is opened.
- /// </param>
- /// <param name="parameters" type="Object" mayBeNull="true" optional="true" >
- /// A dictionary object that passes extra query string parameters to the form. Invalid query string parameters will cause an error.
- /// </param>
- /// <returns type="window" />
- var url;
- if (Xrm.Page.context.getClientUrl)
- { url = Xrm.Page.context.getClientUrl(); }
- else
- { url = Xrm.Page.context.getServerUrl(); }
- url = url + "/main.aspx?etn="+name+"&pagetype=entityrecord";
- if (id != null)
- { url = url + "&id=%7B" + id + "%7D"; }
- if (parameters != null)
- {
- var extraqs = "&extraqs=";
- var strings = [];
- for (var i in parameters) {
- strings.push(i + "=" + parameters[i])
- }
- extraqs += encodeURIComponent(strings.join("&"));
- url += extraqs;
- }
- return window.open(url, "_blank");
-
- };
- this.openWebResource = function (webResourceName, webResourceData, width, height) {
- /// <summary>
- /// Opens an HTML web resource.
- /// </summary>
- /// <param name="webResourceName" type="String" mayBeNull="false" optional="false" >
- /// The name of the HTML web resource to open.
- /// </param>
- /// <param name="webResourceData" type="String" mayBeNull="true" optional="true" >
- /// Data to be passed into the data parameter.
- /// </param>
- /// <param name="width" type="Number" mayBeNull="true" optional="true" >
- /// The width of the window to open in pixels.
- /// </param>
- /// <param name="height" type="Number" mayBeNull="true" optional="true" >
- /// The height of the window to open in pixels.
- /// </param>
- ///<returns type="window" />
-
- var url;
- if (Xrm.Page.context.getClientUrl)
- { url = Xrm.Page.context.getClientUrl(); }
- else
- { url = Xrm.Page.context.getServerUrl(); }
- url = url + "/WebResources/" + webResourceName;
- if (webResourceData != null)
- {
- url += "?Data=" + webResourceData;
- }
- var features = null;
- if (width != null)
- {
- features = "width=" + width;
- }
- if (height != null)
- {
- if (features == null)
- { features = "height=" + height; }
- else
- { features += ",height=" + height;; }
- }
- return window.open(url, "_blank",features);
-
- };
-
- }
- _utility.prototype.toString = function () {
- return "[object Xrm.Utility]";
- }
-
- function _context() {
- this.getAuthenticationHeader = function () {
- /// <summary>
- /// Returns the encoded SOAP header necessary to use Microsoft Dynamics CRM 4.0 web service calls using Jscript.
- /// </summary>
- /// <returns type="String" />
- return pageData.AuthenticationHeader.replace(/</g, "<").replace(/>/g, ">");
- }
- this.getCurrentTheme = function () {
- /// <summary>
- /// Returns the current theme used in the application.
- /// </summary>
- /// <returns type="String" />
- return pageData.CurrentTheme
- }
- this.getOrgLcid = function () {
- /// <summary>
- /// Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the base language for the organization.
- /// </summary>
- /// <returns type="Number" />
- return pageData.OrgLcid;
- }
- this.getOrgUniqueName = function () {
- /// <summary>
- /// Returns the unique text value of the organization’s name.
- /// </summary>
- /// <returns type="String" />
- return pageData.OrgUniqueName;
- }
- this.getQueryStringParameters = function () {
- /// <summary>
- /// Returns a dictionary object of key value pairs representing the query string arguments that were passed to the page.
- /// </summary>
- /// <returns type="Object" />
- return pageData.QueryStringParameters;
- }
- this.getServerUrl = function () {
- /// <summary>
- /// Deprecated. Returns the base server URL. When a user is working offline with the Microsoft Dynamics CRM for Microsoft Office Outlook client, the URL is to the local Microsoft Dynamics CRM Web services.
- /// </summary>
- /// <returns type="String" />
- return pageData.ServerUrl;
- }
- if (pageData.ClientUrl)
- {
- this.getClientUrl = function () {
- /// <summary>
- /// Returns the client URL. This URL is the root to the CRM application as it appears in the browser address bar.
- /// </summary>
- /// <returns type="String" />
- return pageData.ClientUrl;
- }
- }
-
- this.getUserId = function () {
- /// <summary>
- /// Returns GUID value of the SystemUser.id value for the current user.
- /// </summary>
- /// <returns type="String" />
- return pageData.UserId;
- }
- this.getUserLcid = function () {
- /// <summary>
- /// Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the user selected as their preferred language.
- /// </summary>
- /// <returns type="Number" />
- return pageData.UserLcid
- }
- this.getUserRoles = function () {
- /// <summary>
- /// Returns an array of strings representing the GUID values of each of the security roles that the user is associated with.
- /// </summary>
- /// <returns type="Array" />
- return pageData.UserRoles
- }
- this.isOutlookClient = function () {
- /// <summary>
- /// Returns Whether the client is the Outlook client
- /// </summary>
- /// <returns type="Boolean" />
- return pageData.isOutlookClient
- }
- this.isOutlookOnline = function () {
- /// <summary>
- /// Returns whether the use of the Outlook client is connected to the server. Returns false when they are working offline.
- /// </summary>
- /// <returns type="Boolean" />
- return pageData.isOutlookOnline
- }
- this.prependOrgName = function (url) {
- /// <summary>
- /// Accepts a string and prepends the organization name to it with a leading forward slash: "/"+OrgUniqueName + url
- /// </summary>
- /// <returns type="String" />
- return "/" + this.getOrgUniqueName() + url;
- }
-
- }
- _context.prototype.toString = function () {
- return "[object Xrm.Page.context]";
- }
-
- function _data() {
- this.entity = new _entity();
-
- }
- _data.prototype.toString = function () {
- return "[object Xrm.Page.data]";
- }
-
- function _ui() {
- this.controls = new _controlsCollection();
- this.formSelector = new _formSelector();
- this.navigation = new _navigationItems();
- this.tabs = new _tabCollection();
- this.close = function () {
- /// <summary>
- /// Closes the form.
- /// </summary>
- }
- this.getCurrentControl = function () {
- /// <summary>
- /// Returns the control object that currently has focus on the form.
- /// </summary>
- /// <returns type="Object" />
- return _cntrlDictionary[pageData.CurrentControl];
- }
- this.getFormType = function () {
- /// <summary>
- /// Indicates the form context for the record.
- /// <para> 0 : Undefined</para>
- /// <para> 1 : Create</para>
- /// <para> 2 : Update</para>
- /// <para> 3 : Read Only</para>
- /// <para> 4 : Disabled</para>
- /// <para> 5 : Quick Create (Deprecated)</para>
- /// <para> 6 : Bulk Edit</para>
- /// <para> 11: Read Optimized</para>
- /// </summary>
- /// <returns type="Number" />
- return pageData.FormType;
- }
- this.getViewPortHeight = function () {
- /// <summary>
- /// Returns the height of the viewport in pixels.
- /// </summary>
- /// <returns type="Number" />
- return pageData.ViewPortHeight;
- }
- this.getViewPortWidth = function () {
- /// <summary>
- /// Returns the width of the viewport in pixels.
- /// </summary>
- /// <returns type="Number" />
- return pageData.ViewPortWidth;
- }
- this.refreshRibbon = function () {
- /// <summary>
- /// Causes the ribbon to re-evaluate data that controls what is displayed in it.
- /// </summary>
- }
- }
- _ui.prototype.toString = function () {
- return "[object Xrm.Page.ui]";
- }
-
- function _navigationItems() {
- this.items = new _navItemCollection();
- }
- _navigationItems.prototype.toString = function () {
- return "[object Xrm.Page.ui.navigation]";
- }
-
- function _entity() {
- saveEventHandlers = [];
- this.addOnSave = function (functionPointer) {
- /// <summary>
- /// Adds the event handler function to be called when the entity is saved.
- /// It will be added to the bottom of the event pipeline and called after the other event handlers.
- /// </summary>
- if (typeof functionPointer == "function")
- { saveEventHandlers.push(functionPointer); }
- else
- { throw new Error("Xrm.Page.data.entity.addOnSave method requires a function to be passed as a parameter.") }
-
- };
- this.removeOnSave = function (functionPointer) {
- /// <summary>
- /// Removes the the event handler function from the event pipeline.
- /// </summary>
- var newSaveHandlers = [];
- for (var i = 0; i < saveEventHandlers.length; i++) {
- if (saveEventHandlers[i] != functionPointer)
- { newSaveHandlers.push(saveEventHandlers[i]); }
- }
- saveEventHandlers = newSaveHandlers;
-
- };
- this.getDataXml = function () {
- /// <summary>
- /// Returns a string representing the xml that will be sent to the server when the record is saved. Only data in fields that have changed are set to the server.
- /// </summary>
- /// <returns type="String" />
- var dataXml = [];
- var entityName = pageData.EntityName;
-
- dataXml.push("<" + entityName + ">");
- for (var attribute in _attDictionary) {
- var att = _attDictionary[attribute];
- var value = att.getValue();
- if (att.getIsDirty()) {
- if (value == null) {
- dataXml.push("<" + att.getName() + "/>")
- }
- else {
- switch (att.getAttributeType()) {
- case "lookup":
- //ActivityParty are formatted different from regular lookups
- var attributeName = att.getName()
- if ((attributeName == "allparties") ||
- (attributeName == "bcc") ||
- (attributeName == "cc") ||
- (attributeName == "customers") ||
- (attributeName == "from") ||
- (attributeName == "optionalattendees") ||
- (attributeName == "organizer") ||
- (attributeName == "partners") ||
- (attributeName == "requiredattendees") ||
- (attributeName == "resources") ||
- (attributeName == "to")) {
- dataXml.push("<" + attributeName + ">");
- for (var i = 0; i < value.length; i++) {
- dataXml.push("<activityparty>");
- dataXml.push("<partyid name=\"" + value[i].name + "\" type=\"" + value[i].entityType + "\">" + value[i].id + "</partyid>");
- dataXml.push("</activityparty>");
- }
- dataXml.push("</" + attributeName + ">");
- }
- else {
- var value = att.getValue();
- dataXml.push("<" + attributeName + " type=\"" + value[0].entityType + "\" name=\"" + value[0].name + "\">" + value[0].id + "</" + attributeName + ">")
- }
- break;
- default:
- dataXml.push("<" + att.getName() + ">" + value + "</" + att.getName() + ">")
- break;
- }
- }
- }
- }
-
- dataXml.push("</" + entityName + ">");
- return dataXml.join("");
-
- };
- this.getEntityName = function () {
- /// <summary>
- /// Returns a string representing the logical name of the entity for the record.
- /// </summary>
- /// <returns type="String" />
- return pageData.EntityName;
- };
- this.getId = function () {
- /// <summary>
- /// Returns a string representing the GUID id value for the record.
- /// </summary>
- /// <returns type="String" />
- return pageData.Id;
- };
- this.getIsDirty = function () {
- /// <summary>
- /// Returns a Boolean value that indicates if any fields in the form have been modified.
- /// </summary>
- /// <returns type="Boolean" />
- return pageData.IsDirty;
- };
- this.save = function (argument) {
- /// <summary>
- /// Saves the record.
- /// </summary>
- /// <param name="argument" type="String" mayBeNull="true" optional="true" >
- /// <para>1: None: If no parameter is included the record will simply be saved. </para>
- /// <para>2: "saveandclose" : Saves record and closes the form.</para>
- /// <para>3: "saveandnew" : Saves the record and opens a blank form for a new record.</para>
- /// </param>
- for (var i = 0; i < saveEventHandlers.length; i++) {
- saveEventHandlers[i]();
- }
- for (var attribute in _attDictionary) {
- _attDictionary[attribute]._setClean();
- }
- pageData.IsDirty = false;
- };
- this.attributes = new _attributesCollection();
- }
- _entity.prototype.toString = function () {
- var stringvalue = "[object entity : \'" + this.getEntityName() + "\' Id: '" + this.getId() + "\' isDirty: " + this.getIsDirty().toString() + "]";
- return stringvalue;
- }
-
- function _attributesCollection() {
- for (var i = 0; i < pageData.Attributes.length; i++) {
- var att = pageData.Attributes[i];
- switch (att.Type) {
- case "datetime":
- _attDictionary[att.Name] = new _datetimeAttribute(att);
- break;
- case "lookup":
- _attDictionary[att.Name] = new _lookupAttribute(att);
- break;
- case "memo":
- _attDictionary[att.Name] = new _memoAttribute(att);
- break;
- case "string":
- _attDictionary[att.Name] = new _stringAttribute(att);
- break;
- case "decimal":
- _attDictionary[att.Name] = new _decimalAttribute(att);
- break;
- case "double":
- _attDictionary[att.Name] = new _doubleAttribute(att);
- break;
- case "integer":
- _attDictionary[att.Name] = new _integerAttribute(att);
- break;
- case "money":
- _attDictionary[att.Name] = new _moneyAttribute(att);
- break;
- case "boolean":
- _attDictionary[att.Name] = new _booleanAttribute(att);
- break;
- case "optionset":
- _attDictionary[att.Name] = new _optionsetAttribute(att);
- break;
- default:
- throw new Error("Unrecognized attribute type:" + att.Type);
- break;
- }
-
- }
- this.forEach = function (delegate_function) {
- /// <summary>
- /// Applies the action contained within a delegate function.
- /// </summary>
- /// <param name="delegate_function" type="Function" mayBeNull="false" optional="false" >
- /// The delegate_function must include parameters for attribute and index. i.e : MyFunction(attribute,index).
- /// </param>
- // for (var i = 0; i < attributes.length; i++)
- // {
- // delegate_function(attributes[i], i);
- // }
- var i = 0;
- for (var attribute in _attDictionary) {
- delegate_function(_attDictionary[attribute], i);
- i++;
- }
- };
- this.get = function (argument) {
- /// <summary>
- /// Returns one or more attributes depending on the arguments passed.
- /// </summary>
- /// <param name="argument" mayBeNull="true" optional="true" >
- /// <para>1: None: Returns an array of all the attributes.</para>
- /// <para>2: String: Returns the attribute where the argument matches the name.</para>
- /// <para>3: Number: Returns the attribute where the argument matches the index.</para>
- /// <para>4: Function: Returns any attributes that cause the delegate function to return true.</para>
- /// </param>
- var argType = typeof argument;
-
- if (argument == null) {
- var allAttributes = [];
- for (var i in _attDictionary) {
- allAttributes.push(_attDictionary[i]);
- }
- return allAttributes;
- }
-
- switch (argType) {
- case "number":
- var i = 0;
- for (var attribute in _attDictionary) {
- if (argument == i) {
- return _attDictionary[attribute];
- }
- i++;
- }
- return null;
- break;
- case "string":
- return _attDictionary[argument];
- return null;
- break;
- case "function":
- var returnAtts = [];
- var i = 0;
- for (var attribute in _attDictionary) {
- if (argument(_attDictionary[attribute], i)) {
- returnAtts.push(_attDictionary[attribute]);
- }
- i++;
- }
- return returnAtts
- break;
- }
-
- };
- this.getLength = function () {
- /// <summary>
- /// Returns the number of items in the collection.
- /// </summary>
- /// <returns type="Number" />
- return pageData.Attributes.length;;
- };
- }
- _attributesCollection.prototype.toString = function () {
- var stringvalue = "[object Xrm.Page.data.entity.attributes: " + this.getLength() + " attributes ]";
- return stringvalue;
- }
-
- function _controlsCollection() {
-
- for (var i = 0; i < pageData.Controls.length; i++) {
- var ctrl = pageData.Controls[i];
- ctrl.parent = getControlParent(ctrl.Name);
- switch (ctrl.Type) {
- case "standard":
- _cntrlDictionary[ctrl.Name] = new _standardControl(ctrl);
- break;
- case "iframe":
- _cntrlDictionary[ctrl.Name] = new _iframeControl(ctrl);
- break;
- case "lookup":
- _cntrlDictionary[ctrl.Name] = new _lookupControl(ctrl);
- break;
- case "optionset":
- _cntrlDictionary[ctrl.Name] = new _optionsetControl(ctrl);
- break;
- case "subgrid":
- _cntrlDictionary[ctrl.Name] = new _subgridControl(ctrl);
- break;
- case "webresource":
- _cntrlDictionary[ctrl.Name] = new _webresourceControl(ctrl);
- break;
- case "notes":
- _cntrlDictionary[ctrl.Name] = new _notesControl(ctrl);
- break;
- default:
- throw new Error("Unrecognized control type:" + ctrl.Type);
- break;
- }
- }
- function getControlParent(controlName) {
- var parentSectionNotFound = true;
- for (var tab in pageData.Tabs) {
- for (var section in pageData.Tabs[tab].Sections) {
- for (var control in pageData.Tabs[tab].Sections[section].Controls) {
- if (pageData.Tabs[tab].Sections[section].Controls[control].Name == controlName) {
- parentSectionNotFound = false;
- return pageData.Tabs[tab].Sections[section].Name;
- }
- }
- }
- }
- if (parentSectionNotFound)
- { throw new Error("Parent section for control " + controlName + " was not found."); }
- }
- this.forEach = function (delegate_function) {
- /// <summary>
- /// Applies the action contained within a delegate function.
- /// </summary>
- /// <param name="delegate_function" type="Object" mayBeNull="false" optional="false" >
- /// The function must include parameters for control and index. i.e Myfunction(control, index).
- /// </param>
- var i = 0;
- for (var control in _cntrlDictionary) {
- delegate_function(_cntrlDictionary[control], i);
- i++;
- }
- };
- this.get = function (argument) {
- /// <summary>
- /// Returns one or more controls depending on the arguments passed.
- /// </summary>
- /// <param name="argument" type="Object" mayBeNull="true" optional="true" >
- /// <para>1: None: Returns an array of all the controls.</para>
- /// <para>2: String: Returns the control where the argument matches the name.</para>
- /// <para>3: Number: Returns the control where the argument matches the index.</para>
- /// <para>4: Function: Returns any controls that cause the delegate function to return true.</para>
- /// </param>
- var argType = typeof argument;
-
- if (argument == null) {
- var allControls = [];
- for (var i in _cntrlDictionary) {
- allControls.push(_cntrlDictionary[i]);
- }
- return allControls;
- }
-
- switch (argType) {
- case "number":
- var i = 0;
- for (var control in _cntrlDictionary) {
- if (argument == i) {
- return _cntrlDictionary[control];
- }
- i++;
- }
- return null;
- break;
- case "string":
- return _cntrlDictionary[argument];
- break;
- case "function":
- var returnControls = [];
- var i = 0;
- for (var control in _cntrlDictionary) {
- if (argument(_cntrlDictionary[control], i)) {
- returnControls.push(_cntrlDictionary[control]);
- }
- i++;
- }
- return returnControls
- break;
- }
- };
- this.getLength = function () {
- /// <summary>
- /// Returns the number of items in the collection.
- /// </summary>
- /// <returns type="Number" />
- return pageData.ControlsLength;
- };
-
- }
- _controlsCollection.prototype.toString = function () {
- var stringvalue = "[object Xrm.Page.ui.controls: " + this.getLength() + " controls ]";
- return stringvalue;
- }
-
- function _childControlsCollection(ControlNames) {
- var controlNames = ControlNames;
-
- this.forEach = function (delegate_function) {
- /// <summary>
- /// Applies the action contained within a delegate function.
- /// </summary>
- /// <param name="delegate_function" type="Object" mayBeNull="false" optional="false" >
- /// The function must include parameters for control and index. i.e Myfunction(control, index).
- /// </param>
-
- var parentControls = {}
- for (var i = 0; i < controlNames.length; i++) {
- parentControls[controlNames[i].Name] = _cntrlDictionary[controlNames[i].Name];
- }
-
- var i = 0;
- for (var control in parentControls) {
- delegate_function(parentControls[control], i);
- i++;
- }
- };
- this.get = function (argument) {
- /// <summary>
- /// Returns one or more controls depending on the arguments passed.
- /// </summary>
- /// <param name="argument" type="Object" mayBeNull="true" optional="true" >
- /// <para>1: None: Returns an array of all the controls.</para>
- /// <para>2: String: Returns the control where the argument matches the name.</para>
- /// <para>3: Number: Returns the control where the argument matches the index.</para>
- /// <para>4: Function: Returns any controls that cause the delegate function to return true.</para>
- /// </param>
- if (controlNames.length == 0) {
- return null;
- }
- else {
- var parentControls = {}
- for (var i = 0; i < controlNames.length; i++) {
- parentControls[controlNames[i].Name] = _cntrlDictionary[controlNames[i].Name];
- }
-
- var matchingControls = [];
-
- var argType = typeof argument;
-
- if (argument == null) {
- for (var control in parentControls) {
- matchingControls.push(parentControls[control]);
- }
- }
-
- switch (argType) {
- case "number":
- return parentControls[controlNames[argument].Name]
- break;
- case "string":
- return parentControls[argument];
- break;
- case "function":
- var i = 0;
- for (var control in parentControls) {
- if (argument(parentControls[control], i)) {
- matchingControls.push(parentControls[control]);
- }
- i++;
- }
- break;
- }
- return matchingControls;
- }
-
- };
- this.getLength = function () {
- /// <summary>
- /// Returns the number of items in the collection.
- /// </summary>
- /// <returns type="Number" />
- return ControlNames.length;
- };
- }
- _childControlsCollection.prototype.toString = function () {
- var stringvalue = "[object controls collection: " + this.getLength() + " controls]";
- return stringvalue;
- }
-
- function _formSelector() {
- if (pageData.Forms.length > 0) {
- _formsDictionary = {};
- for (var i = 0; i < pageData.Forms.length; i++) {
- _formsDictionary[pageData.Forms[i].Id] = new _formItem(pageData.Forms[i]);
- }
- }
-
- this.items = new _formItemsCollection();
- this.getCurrentItem = function () {
- if (_formsDictionary != null) {
- return _formsDictionary[pageData.CurrentForm.Id];
- }
- else { return null; }
- };
- }
- _formSelector.prototype.toString = function () {
- var stringvalue = "[object Xrm.Page.ui.formSelector: current item:" + ((this.getCurrentItem() == null) ? "null" : this.getCurrentItem().getLabel()) + "]";
- return stringvalue;
- }
-
- function _formItemsCollection() {
- this.forEach = function (delegateFunction) {
- /// <summary>
- /// Applies the action contained within a delegate function.
- /// </summary>
- /// <param name="delegate_function" type="Function" mayBeNull="false" optional="false" >
- /// The function must include parameters for form item and index. i.e Myfunction(item, index).
- /// </param>
- if (_formsDictionary != null) {
- var i = 0;
- for (var form in _formsDictionary) {
- delegateFunction(_formsDictionary[form], i);
- i++;
- }
- }
- };
- this.get = function (argument) {
- /// <summary>
- /// Returns one or more form items depending on the arguments passed.
- /// </summary>
- /// <param name="argument" mayBeNull="true" optional="true" >
- /// <para>1: None: Returns an array of all the form items.</para>
- /// <para>2: String: Returns the form item where the argument matches the id.</para>
- /// <para>3: Number: Returns the form item where the argument matches the index.</para>
- /// <para>4: Function: Returns any form items that cause the delegate function to return true.</para>
- /// </param>
- var matchedForms = [];
-
- if (argument == null) {
- if (_formsDictionary != null) {
- for (var form in _formsDictionary) {
- matchedForms.push(_formsDictionary[form]);
- }
- }
- }
- var argType = typeof argument;
- switch (argType) {
- case "number":
- var i = 0;
- for (var form in _formsDictionary) {
- if (i == argument) {
- return _formsDictionary[form];
- i++;
- }
- }
- break;
- case "string":
- return _formsDictionary[argument];
- break;
- case "function":
- var i = 0;
- for (var form in _formsDictionary) {
- if (argument(_formsDictionary[form], i)) {
- matchedForms.push(_formsDictionary[form]);
- }
- i++;
- }
- break;
- }
- return matchedForms;
- };
- this.getLength = function () {
- /// <summary>
- /// Returns the number of items in the collection.
- /// </summary>
- /// <returns type="Number" />
- return pageData.Forms.length;
- };
-
- }
- _formItemsCollection.prototype.toString = function () {
- var stringvalue = "[object Xrm.Page.ui.formSelector.items collection: " + this.getLength() + " items]";
- return stringvalue;
- }
-
- function _formItem(item) {
- var id = item.Id;
- var label = item.Label;
- this.getId = function () {
- /// <summary>
- /// Returns the id of the form item
- /// </summary>
- /// <returns type="String" />
- return id;
- };
- this.getLabel = function () {
- /// <summary>
- /// Returns the label for the form item
- /// </summary>
- /// <returns type="String" />
- return label;
- };
- this.navigate = function () {
- /// <summary>
- /// Closes the current form and opens the specified form.
- /// </summary>
- };
- }
- _formItem.prototype.toString = function () {
- var stringvalue = "[object form item: " + this.getLabel() + " id: " + this.getId() + "]";
- return stringvalue;
- }
-
- function _navItemCollection() {
- for (var i = 0; i < pageData.Navigation.length; i++) {
- var item = pageData.Navigation[i];
- _navItemDictionary[item.Id] = new _navItem(item);
- }
- this.forEach = function (delegate_function) {
- /// <summary>
- /// Applies the action contained within a delegate function.
- /// </summary>
- /// <param name="delegate_function" type="Function" mayBeNull="false" optional="false" >
- /// The function must include parameters for navigation item and index. i.e Myfunction(item, index).
- /// </param>
- var i = 0;
- for (var item in _navItemDictionary) {
- delegate_function(_navItemDictionary[item], i);
- i++;
- }
-
- };
- this.get = function (argument) {
- /// <summary>
- /// Returns one or more items depending on the arguments passed.
- /// </summary>
- /// <param name="argument" mayBeNull="true" optional="true" >
- /// <para>1: None: Returns an array of all the items.</para>
- /// <para>2: String: Returns the item where the argument matches the id.</para>
- /// <para>3: Number: Returns the item where the argument matches the index.</para>
- /// <para>4: Function: Returns any items that cause the delegate function to return true.</para>
- /// </param>
-
- var matchingItems = [];
- if (argument == null) {
- var matchingItems = [];
- for (var item in _navItemDictionary) {
- matchingItems.push(_navItemDictionary[item]);
- }
- return matchingItems;
-
- }
- var argType = typeof argument;
- switch (argType) {
- case "number":
- var index = 0;
- for (var item in _navItemDictionary) {
- if (index == argument) {
- return _navItemDictionary[item];
- }
- index++;
- }
- break;
- case "string":
- return _navItemDictionary[argument];
- break;
- case "function":
- var index = 0;
- for (var item in _navItemDictionary) {
- if (argument(_navItemDictionary[item], index)) {
- matchingItems.push(_navItemDictionary[item]);
- }
- index++;
- }
- break;
- }
- return matchingItems;
- };
- this.getLength = function () {
- /// <summary>
- /// Returns the number of items in the collection.
- /// </summary>
- /// <returns type="Number" />
- return pageData.Navigation.length;
- };
- }
- _navItemCollection.prototype.toString = function () {
- var stringvalue = "[object Xrm.Page.ui.navigation.items: " + this.getLength() + " items]";
- return stringvalue;
- }
-
- function _navItem(item) {
- var id, label, isVisible;
-
- id = item.Id;
- label = item.Label;
- isVisible = item.Visible;
- this.getId = function () {
- /// <summary>
- /// Returns the id of the item
- /// </summary>
- /// <returns type="String" />
- return id;
- };
- this.getLabel = function () {
- /// <summary>
- /// Returns the label for the item
- /// </summary>
- /// <returns type="String" />
- return label;
- };
- this.getVisible = function () {
- /// <summary>
- /// Returns whether the item is currently visible.
- /// </summary>
- /// <returns type="Boolean" />
- return isVisible;
- };
- this.setFocus = function () {
- /// <summary>
- /// Sets focus on the item
- /// </summary>
- };
- this.setLabel = function (labelText) {
- /// <summary>
- /// Sets the label text of the item.
- /// </summary>
- /// <param name="labelText" type="String" mayBeNull="false" optional="false" >
- /// The new text for the label.
- /// </param>
- if (typeof labelText == "string")
- { label = labelText; }
- else
- { throw new Error("Invalid argument. Expected string value."); }
- };
- this.setVisible = function (visible) {
- /// <summary>
- /// Sets whether the item is visible
- /// </summary>
- /// <param name="visible" type="Boolean" mayBeNull="false" optional="false" >
- /// The boolean value indicating whether the item is visible
- /// </param>
- if (typeof isVisible == "boolean") {
- isVisible = visible;
- }
- else { throw new Error("Invalid argument. Expected boolean value.") }
- };
-
- }
- _navItem.prototype.toString = function () {
- var stringvalue = "[object navigation item : \'" + this.getId() + "\' label: '" + this.getLabel() + "\' visible: " + this.getVisible() + "]";
- return stringvalue;
- }
-
- // =====================================================
- // ATTRIBUTES ==========================================
- // =====================================================
-
- //Start Attribute definitions -------------------------------------------------------------------
-
- // ATTRIBUTE Base ===================================================================
- function _attributeBase(att) {
- var name, format, isDirty, requiredLevel, submitMode, userPrivilege, controls, changeEventHandlers, errorMessage;
- name = att.Name;
-
- format = att.Format;
- isDirty = att.IsDirty;
- requiredLevel = att.RequiredLevel;
- submitMode = att.SubmitMode;
- userPrivilege = att.UserPrivilege;
- controlNames = att.Controls;
- changeEventHandlers = [];
-
- this.addOnChange = function (functionPointer) {
- /// <summary>
- /// Adds an event handler function to the OnChange event for the attribute. It will be called after the other event handler functions in the event pipeline.
- /// </summary>
- if (typeof functionPointer == "function") {
- changeEventHandlers.push(functionPointer);
- }
- else {
- errorMessage = "Error using addOnChange with the " + name + " attribute. The parameter passed is not a function.";
- throw new Error(errorMessage);
- }
-
- };
- this.removeOnChange = function (functionPointer) {
- /// <summary>
- /// Removes and event handler function from the OnChange event for the attribute.
- /// </summary>
- if (typeof functionPointer != "function") {
- errorMessage = "Error using removeOnChange with the " + name + " attribute. The parameter passed is not a function.";
- throw new Error(errorMessage);
- }
-
- var newHandlers = [];
- for (var i = 0; i < changeEventHandlers.length; i++) {
- if (changeEventHandlers[i] != functionPointer) {
- newHandlers.push(changeEventHandlers[i]);
- }
- }
- changeEventHandlers = newHandlers;
- };
- this.fireOnChange = function () {
- /// <summary>
- /// Causes the OnChange event to occur on the attribute so that any script associated to that event can execute.
- /// </summary>
- isDirty = true;
- pageData.IsDirty = true;
- for (var i = 0; i < changeEventHandlers.length; i++) {
- changeEventHandlers[i]();
- }
- };
- this.getFormat = function () {
- /// <summary>
- /// Returns a string value that represents formatting options for the attribute. The value may be null.
- /// </summary>
- /// <returns type="String" />
- return format;
- };
- this.getIsDirty = function () {
- /// <summary>
- /// Returns a Boolean value indicating if there are unsaved changes to the attribute value.
- /// </summary>
- /// <returns type="Boolean" />
- return isDirty;
- };
- this.getName = function () {
- /// <summary>
- /// Returns a string representing the logical name of the attribute.
- /// </summary>
- /// <returns type="String" />
- return name;
- };
- this.getParent = function () {
- /// <summary>
- /// Returns the entity object that is the parent to the attribute. In the case of an attribute this is Xrm.Page.data.entity.
- /// </summary>
- return function () { return Xrm.Page.data.entity; }();
- };
- this.getRequiredLevel = function () {
- /// <summary>
- /// Returns a string value indicating whether a value for the attribute is required or recommended. Will return either "none", "required", or "recommended".
- /// </summary>
- /// <returns type="String" />
- return requiredLevel;
- };
- this.getSubmitMode = function () {
- /// <summary>
- /// Returns a string indicating when data from the attribute will be submitted when the record is saved. Will return either "always", "never", or "dirty".
- /// </summary>
- /// <returns type="String" />
- return submitMode;
- };
- this.getUserPrivilege = function () {
- /// <summary>
- /// Returns an array of privileges that contain Boolean values indicating if the user can create, read or update data values for an attribute.
- /// </summary>
- /// <returns type="Array" />
- return userPrivilege;
- };
- this.setRequiredLevel = function (level) {
- /// <summary>
- /// Sets the required level for the attribute
- /// </summary>
- /// <param name="level" type="String" mayBeNull="false" optional="false" >
- /// Valid values include "none", "required", and "recommended".
- /// </param>
- if (level == "none" || level == "required" || level == "recommended")
- { requiredLevel = level; }
- else
- {
- errorMessage = "Error using setRequiredLevel on the " + name + " attribute. Invalid argument. Valid arguments for setRequiredLevel include \"none\", \"required\", and \"recommended\".";
- throw new Error(errorMessage);
- }
- };
- this.setSubmitMode = function (mode) {
- /// <summary>
- /// Sets whether data from the attribute will be submitted when the record is saved.
- /// </summary>
- /// <param name="mode" type="String" mayBeNull="false" optional="false" >
- /// Valid values include "always", "never", and "dirty".
- /// </param>
- if (mode == "always" || mode == "never" || mode == "dirty")
- { submitMode = mode; }
- else
- {
- errorMessage = "Error using setSubmitMode on the " + name + " attribute. Invalid argument. Valid arguments for setSubmitMode include \"always\", \"never\", and \"dirty\".";
- throw new Error(errorMessage);
- }
- };
- this._setClean = function () {
- /// <summary>
- /// Private function for design time to be called when entity saved. Not an actual Microsoft CRM attribute method.
- /// </summary>
- isDirty = false;
- }
-
- this.controls = new _childControlsCollection(controlNames);
-
-
-
- }
-
- // NUMBER Base ===================================================================
- function _numberBaseAttribute(att) {
- _attributeBase.call(this, att);
- var value, max, min, precision, errorMessage;
- value = att.Value;
- max = att.Max;
- min = att.Min;
- precision = att.Precision;
- this.getMax = function () {
- /// <summary>
- /// Returns a number indicating the maximum allowed value for an attribute.
- /// </summary>
- /// <returns type="Number" />
- return max;
- };
- this.getMin = function () {
- /// <summary>
- /// Returns a number indicating the minimum allowed value for an attribute.
- /// </summary>
- /// <returns type="Number" />
- return min;
- };
- this.getPrecision = function () {
- /// <summary>
- /// Returns the number of digits allowed to the right of the decimal point.
- /// </summary>
- /// <returns type="Number" />
- return precision;
- };
- this.getValue = function () {
- /// <summary>
- /// Retrieves the data value for the decimal attribute
- /// </summary>
- /// <returns type="Number" />
- return value;
- };
- this.setValue = function (newValue) {
- /// <summary>
- /// Sets the data value for a decimal attribute.
- /// </summary>
- /// <param name="newValue" type="Number" mayBeNull="false" optional="false" >
- /// The new value for the decimal attribute
- /// </param>
- if (newValue == null && value != null) {
- value = newValue;
- this.fireOnChange();
- return;
- }
- if (typeof newValue == "number") {
- if (value != newValue) {
- if (newValue <= max && newValue >= min) {
- value = newValue;
- this.fireOnChange();
- }
- else {
- errorMessage = "Out of Range. The value of the " + this.getName() + " attribute must be between " + min + " and " + max + "."
- throw new Error(errorMessage);
- }
- }
- }
- else {
- errorMessage = "Invalid argument setting " + this.getName() + ". Use a Number parameter value when using setValue on a " + this.getAttributeType() + " attribute."
- throw new Error(message);
- }
- };
- }
-
- // BOOLEAN ===================================================================
- function _booleanAttribute(att) {
- _attributeBase.call(this, att);
- var initialValue, value, errorMessage;
- initialValue = att.InitialValue;
- value = att.Value;
- this.getAttributeType = function () {
- /// <summary>
- /// Returns a string value that represents the type of attribute. In this case 'boolean'.
- /// </summary>
- /// <returns type="String" />
- return "boolean";
- };
- this.getInitialValue = function () {
- /// <summary>
- /// Returns the value of the attribute when the record was last saved or the default value before the record is saved.
- /// </summary>
- /// <r…
Large files files are truncated, but you can click here to view the full file