Case:

We want to hide print button for some opportunity stages

Algorithm of realization:

  1. You should create replacing client schema for OpportunityPageV2  and OpportunitySectionV2.
  2. Create attributes on both pages:

    attributes: {
        "isPrintButtonVisible": {
            "dataValueType": Terrasoft.DataValueType.BOOLEAN
        }
    }

    in addition add on Opportunity page:

    "Stage": {
        "onChange": "onStageChanged"
    }

     

  3. Create message which will send stage from OpportunityPage  to OpportunitySection when we work in combined mode.

    Add following code to OpportunitySection:

    messages: {
        "PrintButtonVisibleMessage": {
            mode: Terrasoft.MessageMode.PTP,
            direction: Terrasoft.MessageDirectionType.SUBSCRIBE
        }
    },

    And to OpportunityPage:

    messages: {
        "PrintButtonVisibleMessage": {
            mode: Terrasoft.MessageMode.PTP,
            direction: Terrasoft.MessageDirectionType.PUBLISH
        }
    },

     

  4. Create methods which will set button visibility and publish message about it on OpportunityPage:

    printButtonVisiblePublishMessage: function() {
        return this.sandbox.publish("PrintButtonVisibleMessage", this.get("isPrintButtonVisible"), ["key"]);
    },
    onStageChanged: function() {
        this.setPrintButtonVisibility();
        this.printButtonVisiblePublishMessage();
    },
    setPrintButtonVisibility: function() {
        var stage = this.get("Stage");
     
        if (stage.value === "423774cb-5ae6-df11-971b-001d60e938c6") {
            this.set("isPrintButtonVisible", true);
        } else {
            this.set("isPrintButtonVisible", false);
        }
    }

     

  5. Create methods which will handle stage changing on OpportunitySection if we work in combined mode

    init: function() {
        this.callParent(arguments);
        this.sandbox.subscribe("PrintButtonVisibleMessage", this.onPrintButtonVisibleMessage, this, ["key"]);
    },
    onPrintButtonVisibleMessage: function(isButtonVisible) {
        this.set("isPrintButtonVisible", isButtonVisible);
    }

     

  6. Bind button visibility to isPrintButtonVisible attribute

    1. OpportunityPage

      {
          "operation": "merge",
          "name": "PrintButton",
          "values": {
              "visible": {
                  "bindTo": "isPrintButtonVisible"
              }
          }
      },

       

    2. OpportunitySection

      {
          "operation": "merge",
          "name": "CombinedModePrintButton",
          "values": {
              "visible": {
                  "bindTo": "isPrintButtonVisible"
              }
          }
      }

       

Like 0

Like

Share

0 comments
Show all comments

Symptoms

Mobile application simulator does not work. System.ArgumentException: An item with the same key has already been added

Cause

This error is not caused by incorrect changes in the application configuration.

It islikely that localized strings were added to the mobile application's manifest, which duplicates the lines from MobileApplicationManifestMobile.

Solution

Update the application to the latest version (7.5.0) or change the localized strings in the custom schema (for example, "UsrMobileApplicationManifestCustom2Schema").

For example, add the "Custom" prefix in the name of localized lines.

Necessary conditions and possible restrictions

System administrator rights

Like 0

Like

Share

0 comments
Show all comments

Case description:

You need to add a custom fixed filter by column Type to the Contact section.

Algorithm of realization:

  1. Create replacing client schema for your section.
  2. Create localizable strings which will contain captions of the filter and menu item.
  3. Create image which will contain image of the filter.
  4. Source code of the "ContactSectionV2" :

define("ContactSectionV2", [], function() {
    return {
        entitySchemaName: "Contact",
        methods: {
            initFixedFiltersConfig: function () {
                var fixedFilterConfig = {
                    entitySchema: "ContactType",
                    filters: [
                        {
                            name: "TypeFilter",
                            columnName: "Type",
                            caption: this.get("Resources.Strings.ContactTypeFilterCaption"),
                            dataValueType: this.Terrasoft.DataValueType.LOOKUP,
                            appendCurrentContactMenuItem: false,
                            addNewFilterCaption: this.get("Resources.Strings.SelectContactTypeCaption"),
                            hint: this.get("Resources.Strings.SelectContactTypeCaption"),
                            buttonImageConfig: this.get("Resources.Images.ContactTypeFilterImage")
                        }
                    ]
                };
                this.set("FixedFilterConfig", fixedFilterConfig);
            }
        }
    };
});

The result would be:

Like 0

Like

Share

0 comments
Show all comments

Case description:

Add record completeness into custom section.

How to do it:

  1. Add Completeness field into your section object. This one should be an integer.

  2. Add record about your section into Completeness table. You can do it with following SQL script:

    INSERT INTO Completeness (Name, EntitySchemaName, ResultColumnName, Scale)
        VALUES ('Quotes', 'VistQuotes', 'VistCompleteness', '{"sectorsBounds":{"min":0,"middleFrom":50,"middleTo":80,"max":100}}')

    You should specify Name, EntitySchemaName, ResultColumnName and Scale columns.

  3. Create replacing client module for your page (for example VistQuotes1Page in my case).
  4. Add dependencies on following schemas: "CompletenessIndicator", "CompletenessMixin", "css!CompletenessCSSV2", "TooltipUtilities".
  5. Add two attributes into "attributes" area:

    CompletenessValue: {
        dataValueType: Terrasoft.DataValueType.INTEGER,
        value: 0
    },
    MissingParametersCollection: {
        dataValueType: Terrasoft.DataValueType.COLLECTION
    }

     

  6. Add two mixins (CompletenessMixin, TooltipUtilitiesMixin) into your schema.

    mixins: {
        CompletenessMixin: "Terrasoft.CompletenessMixin",
        TooltipUtilitiesMixin: "Terrasoft.TooltipUtilities"
    },

     

  7. Add the following methods:

    methods: {
        init: function() {
            this.set("MissingParametersCollection", this.Ext.create("Terrasoft.BaseViewModelCollection"));
            this.callParent(arguments);
        },
        onDetailChanged: function() {
            this.callParent(arguments);
            this.calculateCompleteness();
        },
        onEntityInitialized: function() {
            this.callParent(arguments);
            if (this.isEditMode()) {
                var collection = this.get("MissingParametersCollection");
                collection.clear();
                this.set("CompletenessValue", 0);
                this.calculateCompleteness();
            }
        },
        onSaved: function() {
            var callParentOnSaved = this.get("CallParentOnSaved");
            this.callParent(arguments);
            if (!callParentOnSaved && !this.isNewMode() && !this.get("IsProcessMode")) {
                this.calculateCompleteness();
            }
        },
        calculateCompleteness: function() {
            var config = {
                recordId: this.get("Id"),
                schemaName: this.entitySchemaName
            };
            this.mixins.CompletenessMixin.getCompleteness.call(this, config, this.calculateCompletenessResponce, this);
        },
        calculateCompletenessResponce: function(completenessResponce) {
            if (this.Ext.isEmpty(completenessResponce)) {
                return;
            }
            var missingParametersCollection = completenessResponce.missingParametersCollection;
            var completeness = completenessResponce.completenessValue;
            var scale = completenessResponce.scale;
            if (!this.Ext.isEmpty(missingParametersCollection)) {
                var collection = this.get("MissingParametersCollection");
                collection.clear();
                collection.loadAll(missingParametersCollection);
            }
            if (this.Ext.isObject(scale) && this.Ext.isArray(scale.sectorsBounds)) {
                this.set("CompletenessSectorsBounds", scale.sectorsBounds);
            }
            if (this.Ext.isNumber(completeness)) {
                this.set("CompletenessValue", completeness);
            }
        }
    },

     

  8. Insert completeness bar into your page with code like following:

    diff: /**SCHEMA_DIFF*/[
        {
            "operation": "insert",
            "parentName": "MetricsContainer",
            "propertyName": "items",
            "name": "CompletenessContainer",
            "values": {
                "itemType": Terrasoft.ViewItemType.CONTAINER,
                "items": []
            }
        },
        {
            "operation": "insert",
            "parentName": "CompletenessContainer",
            "propertyName": "items",
            "name": "CompletenessValue",
            "values": {
                "generator": "ConfigurationRectProgressBarGenerator.generateProgressBar",
                "controlConfig": {
                    "value": {
                        "bindTo": "CompletenessValue"
                    },
                    "menu": {
                        "items": {
                            "bindTo": "MissingParametersCollection"
                        }
                    },
                    "sectorsBounds": {
                        "bindTo": "CompletenessSectorsBounds"
                    }
                },
                "tips": [],
                "layout": {
                    "column": 0,
                    "row": 0,
                    "rowSpan": 1,
                    "colSpan": 1
                }
            }
        },
        {
            "operation": "insert",
            "parentName": "CompletenessValue",
            "propertyName": "tips",
            "name": "CompletenessTip",
            "values": {
                "content": {"bindTo": "Resources.Strings.CompletenessHint"}
            }
        }
    ]/**SCHEMA_DIFF*/

    Full example code you can find below:

define("VistQuotes1Page", ["CompletenessIndicator", "CompletenessMixin", "css!CompletenessCSSV2", "TooltipUtilities"],
    function() {
    return {
        entitySchemaName: "VistQuotes",
        attributes: {
            CompletenessValue: {
                dataValueType: Terrasoft.DataValueType.INTEGER,
                value: 0
            },
            MissingParametersCollection: {
                dataValueType: Terrasoft.DataValueType.COLLECTION
            }
        },
        modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
        details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
        businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
        methods: {
            init: function() {
                this.set("MissingParametersCollection", this.Ext.create("Terrasoft.BaseViewModelCollection"));
                this.callParent(arguments);
            },
            onDetailChanged: function() {
                this.callParent(arguments);
                this.calculateCompleteness();
            },
            onEntityInitialized: function() {
                this.callParent(arguments);
                if (this.isEditMode()) {
                    var collection = this.get("MissingParametersCollection");
                    collection.clear();
                    this.set("CompletenessValue", 0);
                    this.calculateCompleteness();
                }
            },
            onSaved: function() {
                var callParentOnSaved = this.get("CallParentOnSaved");
                this.callParent(arguments);
                if (!callParentOnSaved && !this.isNewMode() && !this.get("IsProcessMode")) {
                    this.calculateCompleteness();
                }
            },
            calculateCompleteness: function() {
                var config = {
                    recordId: this.get("Id"),
                    schemaName: this.entitySchemaName
                };
                this.mixins.CompletenessMixin.getCompleteness.call(this, config, this.calculateCompletenessResponce, this);
            },
            calculateCompletenessResponce: function(completenessResponce) {
                if (this.Ext.isEmpty(completenessResponce)) {
                    return;
                }
                var missingParametersCollection = completenessResponce.missingParametersCollection;
                var completeness = completenessResponce.completenessValue;
                var scale = completenessResponce.scale;
                if (!this.Ext.isEmpty(missingParametersCollection)) {
                    var collection = this.get("MissingParametersCollection");
                    collection.clear();
                    collection.loadAll(missingParametersCollection);
                }
                if (this.Ext.isObject(scale) && this.Ext.isArray(scale.sectorsBounds)) {
                    this.set("CompletenessSectorsBounds", scale.sectorsBounds);
                }
                if (this.Ext.isNumber(completeness)) {
                    this.set("CompletenessValue", completeness);
                }
            }
        },
        mixins: {
            CompletenessMixin: "Terrasoft.CompletenessMixin",
            TooltipUtilitiesMixin: "Terrasoft.TooltipUtilities"
        },
        dataModels: /**SCHEMA_DATA_MODELS*/{}/**SCHEMA_DATA_MODELS*/,
        diff: /**SCHEMA_DIFF*/[
            {
                "operation": "insert",
                "parentName": "MetricsContainer",
                "propertyName": "items",
                "name": "CompletenessContainer",
                "values": {
                    "itemType": Terrasoft.ViewItemType.CONTAINER,
                    "items": []
                }
            },
            {
                "operation": "insert",
                "parentName": "CompletenessContainer",
                "propertyName": "items",
                "name": "CompletenessValue",
                "values": {
                    "generator": "ConfigurationRectProgressBarGenerator.generateProgressBar",
                    "controlConfig": {
                        "value": {
                            "bindTo": "CompletenessValue"
                        },
                        "menu": {
                            "items": {
                                "bindTo": "MissingParametersCollection"
                            }
                        },
                        "sectorsBounds": {
                            "bindTo": "CompletenessSectorsBounds"
                        }
                    },
                    "tips": [],
                    "layout": {
                        "column": 0,
                        "row": 0,
                        "rowSpan": 1,
                        "colSpan": 1
                    }
                }
            },
            {
                "operation": "insert",
                "parentName": "CompletenessValue",
                "propertyName": "tips",
                "name": "CompletenessTip",
                "values": {
                    "content": {"bindTo": "Resources.Strings.CompletenessHint"}
                }
            },
            {
                "operation": "insert",
                "name": "VistStatusa33f682a-dd58-4739-919d-cb84b9d2fc70",
                "values": {
                    "layout": {
                        "colSpan": 12,
                        "rowSpan": 1,
                        "column": 12,
                        "row": 10,
                        "layoutName": "Header"
                    },
                    "bindTo": "VistStatus",
                    "enabled": true
                },
                "parentName": "Header",
                "propertyName": "items",
                "index": 46
            }
        ]/**SCHEMA_DIFF*/
    };
});

 

Like 0

Like

Share

2 comments

Hi when i login by Sale role it not calculate the completeness in custom section.

vinh.nx,

 

Hello, 

 

The functionality of completeness doesn't take column or record permissions into account and even you have column permissions enabled for any of the columns that is used for completeness calculation the completeness indicator will be updated anyway.

 

Please double-check all the steps from the instruction since something is missing in your configuration.

 

Best regards,

Oscar

Show all comments

Symptoms

  1. There are several identical positions for the distribution of rights for operations
  2. The current user does not have permission to access the MobileData object

Cause

Access rights to mobile application objects are not distributed and organizational structure is not updated.

Solution

  1. Distribute access rights to mobile application objects
  2. Update the organizational structure

Necessary conditions and possible restrictions

Admin rights.

 

 

 

Like 0

Like

Share

0 comments
Show all comments

Symptoms

Type: Terrasoft.SqlProxyException%0D%0A

Message: An exception occurred SQL%0D%0A%0D%0AТип: Terrasoft.SqlException%0D%0AСообщение: undefined: Cannot call method 'setRecord' of undefined%0D%0A%0D%0A

Cause

This message indicates that the device has been connected to by different users. This sometimes occurs when switching the database.

Solution

Clear the database cache and re-synchronize.



Important - all unsynchronized will be deleted from the mobile device when you clear the cache.

Like 0

Like

Share

0 comments
Show all comments

Case description:

You need to show a ModalBox with build-in Iframe.

Realization algorithm

1)First of all, you need to create an Iframe module. (IntDonateIframeControl)

Ext.define("Terrasoft.controls.IntDonateIframeControl", {
    extend: "Terrasoft.Component",
    alternateClassName: "Terrasoft.IntDonateIframeControl",
    tpl: [
        /*jshint quotmark:true */
        '<iframe id="{id}" src="{src}" class="{wrapClass}"></iframe>'
        /*jshint quotmark:false */
    ],
    id: null,
    src: "https://academy.terrasoft.ru/",
    wrapClass: ["usr-iframe"],
    setIframeSrc: function(value) {
        value = value || "";
        if (this.src !== value) {
            this.src = value;
            this.safeRerender();
        }
    },
    init: function() {
        this.callParent(arguments);
        var selectors = this.selectors = this.selectors || {};
        selectors.wrapEl = selectors.wrapEl || "#" + this.id;
    },
    LoadPageBySrc: function() {
        var iframe = this.getWrapEl();
        iframe.dom.src = this.src;
    },
    onAfterRender: function() {
        this.callParent(arguments);
        this.LoadPageBySrc();
    },
    onAfterReRender: function() {
        this.callParent(arguments);
        this.LoadPageBySrc();
    },
    getBindConfig: function() {
        var bindConfig = this.callParent(arguments);
        return Ext.apply(bindConfig, {
            src: {
                changeMethod: "setIframeSrc"
            }
        });
    },
    getTplData: function() {
        var tplData = this.callParent(arguments);
        return Ext.apply(tplData, {
            src: this.src,
            wrapClass: this.wrapClass
        });
    }
});

2)You need to create a page that will contain Iframe and will be displayed in Modal Box.(IntDonateModalPage)

define("IntDonateModalPage", ["IntDonateIframeControl", "css!IntDonateIframeControl"], function() {
    return {
        attributes: {
            "TestText": {
                dataValueType: Terrasoft.DataValueType.TEXT,
                type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN
            }
        },
        messages: {
        },
        methods: {
            init: function(callback, scope) {
                this.callParent(arguments);
            },
            getHeader: function() {
                return this.get("Resources.Strings.PageCaption");
            },
            onRender: function() {
                this.callParent(arguments);
                var moduleInfo = this.get("moduleInfo");
                var boxSizes = moduleInfo.modalBoxSize;
                var width = boxSizes.width;
                var height = boxSizes.height;
                this.updateSize(width, height);
            }
        },
        //Insert already existed Iframe
        diff: [
            {
                "operation": "insert",
                "parentName": "CardContentContainer",
                "propertyName": "items",
                "name": "IntDonateIframe",
                "values": {
                    "generator": function() {
                        return {
                            "className": "Terrasoft.IntDonateIframeControl"
                        };
                    }
                }
            },
            {
                "operation": "insert",
                "name": "MyContainer",
                "propertyName": "items",
                "values": {
                    "itemType": Terrasoft.ViewItemType.CONTAINER,
                    "items": []
                }
            },
            {
                "operation": "insert",
                "parentName": "MyContainer",
                "propertyName": "items",
                "name": "MyGridContainer",
                "values": {
                    "itemType": Terrasoft.ViewItemType.GRID_LAYOUT,
                    "items": []
                }
            },
            {
                "operation": "insert",
                "parentName": "MyGridContainer",
                "propertyName": "items",
                "name": "TestText",
                "values": {
                    "bindTo": "TestText",
                    "caption": "Test text",
                    "layout": {"column": 0, "row": 0, "colSpan": 10}
                }
            }
        ]
    };
});

3)In page, you need to insert a button. After button click, Modal Dialog with Iframe should appear. (IntExcelReportPage)

define("IntExcelReportPage", ["IntReportConstants", "MaskHelper"],
    function(constants, MaskHelper) {
    return {
        entitySchemaName: "IntExcelReport",
        details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
        modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
        diff: /**SCHEMA_DIFF*/[
            {
                "operation": "insert",
                "name": "DonateButton",
                "values": {
                    "itemType": Terrasoft.ViewItemType.BUTTON,
                    "style": Terrasoft.controls.ButtonEnums.style.RED,
                    "caption": {
                        "bindTo": "Resources.Strings.DonateButton"
                    },
                    "click": {
                        "bindTo": "donateButtonClick"
                    }
                },
                "parentName": "RightContainer",
                "propertyName": "items",
                "index": 1
            }
        ]/**SCHEMA_DIFF*/,
        messages: {},
        attributes: {},
        mixins: {},
        methods: {
            subscribeSandboxEvents: function() {
                this.callParent(arguments);
                this.sandbox.subscribe("GetMasterEntitySchema", function() {
                    return this.get("IntEntitySchemaName");
                }, this, [this.getDetailId("IntRelatedSchemasDetail") + "_DetailModalBox"]);
                this.sandbox.subscribe("IntUploadFileClick", this.onFilesSelected, this, [this.sandbox.id]);
                this.sandbox.subscribe("GetModuleInfo", this.getDonateModalBoxConfig, this,
                    [this.getDonateModalBoxId()]);
            },
            donateButtonClick: function() {
                this.sandbox.loadModule("ModalBoxSchemaModule", {
                    id: this.getDonateModalBoxId()
                });
            },
            getDonateModalBoxConfig: function() {
                return {
                    "schemaName": "IntDonateModalPage",
                    "modalBoxSize": {
                        "width": "680px",
                        "height": "400px"
                    }
                };
            },
            getDonateModalBoxId: function() {
                return this.sandbox.id + "_DonateModalBox";
            }
        }
    };
});

Result

NB!

It's vital to note, that some websites don't allow insert them as Iframe

Like 0

Like

Share

2 comments

Hi,

Can you explain the values that variables IntReportConstants,

IntEntitySchemaName,

IntRelatedSchemasDetail,

IntUploadFileClick

in IntExcelReportPage hold?

 

 

Hi,



I know this post was old, but how to fix this?

 

Message GetMasterEntitySchema is not defined in CardModuleV2 (SectionModuleV2_AccountSectionV2_CardModuleV2) module 





I'm following this tutorial.



Thank you.

Show all comments

Case:

We need to add input mask on a "Phone number" field ( format "(99)999-99-99").

1. Create MultiMaskEdit client module and copy the source code listed bellow (skip this step if schema "MultiMaskEdit" already present in the configuration)

MultiMaskEdit code

define("MultiMaskEdit", ["ext-base", "terrasoft"], function(Ext, Terrasoft) {
    /**
     * @class Terrasoft.controls.MultiMaskEdit
     */
    Ext.define("Terrasoft.controls.MultiMaskEdit", {
        extend: "Terrasoft.TextEdit",
        alternateClassName: "Terrasoft.MultiMaskEdit",
 
        /**
         * @public
         * @type {Terrasoft.Align}
         */
        textAlign: Terrasoft.Align.LEFT,
        /**
         * @protected
         * @overridden
         */
        onFocus: function() {
            this.callParent(arguments);
            var value = this.getTypedValue();
            this.setDomValue(value);
        },
        /**
         * @protected
         * @virtual
         * @return {String}
         */
        getInitValue: function() {
            var value = this.callParent(arguments);
            if (!Ext.isEmpty(value) && !Ext.isEmpty(this.masks)) {
                var formatValue = this.formatValue(value);
                this.value = formatValue.value;
                var validationInfo = this.getValidationInfo(formatValue);
                this.setValidationInfo(validationInfo);
            }
            return this.value;
        },
        getValidationInfo: function(value) {
            var formatValue = (!Ext.isEmpty(value) && Ext.isBoolean(value.isComplete)) ? value : this.formatValue(value);
            var validationInfo = {
                isValid: true,
                invalidMessage: ""
            };
            if (!formatValue.isComplete) {
                validationInfo = {
                    isValid: false,
                    invalidMessage: this.getIncorrectNumberMessage()
                };
            }
            return validationInfo;
        },
        getIncorrectNumberMessage: function() {
            return "Invalid number";
        },
        /**
         * @protected
         * @overridden
         * @param  {Event} e DOM keypress
         * @param  {String} type (optional)
         * значение Terrasoft.DataValueType.FLOAT
         */
        onKeyPress: function(e) {
            this.callParent(arguments);
            if (this.readonly || Ext.isEmpty(this.masks)) {
                return;
            }
            var isSpecialKey = Ext.isGecko && e.isSpecialKey();
            if (isSpecialKey) {
                return;
            }
            e.preventDefault();
            var keyUnicode = e.getKey();
            var key = String.fromCharCode(keyUnicode);
            if (this.baseCharsRe && !this.baseCharsRe.test(key)) {
                return;
            }
            var domEl = e.getTarget();
            var info = this.getInputInfo(domEl);
            var formatValue = this.formatValueByInsChar(key, info.caretPosition, info.valueBeforeCaret, info.valueSelected,
                info.valueAfterCaret);
            if (!formatValue) {
                return;
            }
            domEl.value = formatValue.value;
            Terrasoft.utils.dom.setCaretPosition(domEl, formatValue.pos);
            if (!this.validationInfo.isValid && formatValue.isComplete) {
                var validationInfo = {
                    isValid: true,
                    invalidMessage: ""
                };
                this.setValidationInfo(validationInfo);
            }
        },
        getInputInfo: function(domEl) {
            var selectedTextLength = Terrasoft.utils.dom.getSelectedTextLength(domEl);
            var caretPosition = Terrasoft.utils.dom.getCaretPosition(domEl);
            var value = domEl.value;
            var valueBeforeCaret = "";
            var valueAfterCaret = "";
            var valueSelected = "";
            if (Ext.isIE) {
                valueBeforeCaret = value.slice(0, caretPosition - selectedTextLength);
                valueAfterCaret = value.slice(caretPosition);
                caretPosition -= selectedTextLength;
            } else {
                valueBeforeCaret = value.slice(0, caretPosition);
                valueAfterCaret = value.slice(caretPosition + selectedTextLength);
            }
            if (selectedTextLength > 0) {
                valueSelected = value.slice(caretPosition, selectedTextLength + caretPosition);
            }
            return {
                selectedTextLength: selectedTextLength,
                caretPosition: caretPosition,
                value: value,
                valueBeforeCaret: valueBeforeCaret,
                valueAfterCaret: valueAfterCaret,
                valueSelected: valueSelected
            };
        },
        /**
         * @protected
         */
        onKeyDown: function(e) {
            this.callParent(arguments);
            if (Ext.isEmpty(this.masks)) {
                return;
            }
            var key = e.getKey();
            var matches, masks, placeHolders, commonStr;
            if (key === e.BACKSPACE || key === e.DELETE) {
                e.preventDefault();
                var domEl = e.getTarget();
                var info = this.getInputInfo(domEl);
 
                if (info.valueBeforeCaret === "" && info.valueAfterCaret === "") {
                    this.setDomValue("");
                }
 
                else if (info.selectedTextLength > 0) {
 
                    if (Ext.isEmpty(info.valueAfterCaret)) {
                        this.setDomValue(this.removeEndPlaceHolders(info.valueBeforeCaret));
                    } else {
 
                        matches = this.getMatchesByValue(info.valueBeforeCaret);
                        if (matches.matches.length === 0) {
                            return;
                        }
 
                        masks = this.getPropertyValuesFromArray(matches.matches, "mask");
 
                        placeHolders = this.getPropertyValuesFromArray(masks, "placeHolder");
                        var replaceText = this.getCommonStartString(placeHolders).substr(info.caretPosition, info.selectedTextLength);
                        if (replaceText.length === info.selectedTextLength) {
                            this.setDomValue(info.valueBeforeCaret + replaceText + info.valueAfterCaret);
                        }
                    }
                } else if (key === e.BACKSPACE && !Ext.isEmpty(info.valueBeforeCaret)) {
                    matches = this.getMatchesByValue(info.valueBeforeCaret);
                    if (matches.matches.length === 0) {
                        return;
                    }
 
                    masks = this.getPropertyValuesFromArray(matches.matches, "mask");
 
                    placeHolders = this.getPropertyValuesFromArray(masks, "placeHolder");
                    commonStr = this.getCommonStartString(placeHolders);
                    if (commonStr.length >= info.caretPosition) {
                        this.setDomValueAndCaret(info.valueBeforeCaret.slice(0, -1) + commonStr.substr(info.caretPosition - 1, 1) +
                            info.valueAfterCaret, info.caretPosition - 1);
                    }
                } else if (key === e.DELETE && !Ext.isEmpty(info.valueAfterCaret)) {
 
                    matches = this.getMatchesByValue(info.valueBeforeCaret);
                    if (matches.matches.length === 0) {
                        return;
                    }
 
                    masks = this.getPropertyValuesFromArray(matches.matches, "mask");
 
                    placeHolders = this.getPropertyValuesFromArray(masks, "placeHolder");
                    commonStr = this.getCommonStartString(placeHolders);
                    if (commonStr.length > info.caretPosition) {
                        this.setDomValueAndCaret(info.valueBeforeCaret + commonStr.substr(info.caretPosition, 1) +
                            info.valueAfterCaret.slice(1), info.caretPosition + 1);
                    }
                }
            }
        },
        maskConfig: {
            definitions: {
                //numbers
                "9": {
                    re: "[0-9]"
                },
                //cyryllic
                "к": {
                    re: "[а-яА-ЯёЁ]"
                },
                //латинские
                "l": {
                    re: "[a-zA-Z]"
                },
                //any letter
                "c": {
                    re: "[а-яА-ЯёЁa-zA-Z]"
                },
                //any letter or number
                "#": {
                    re: "[а-яА-ЯёЁA-Za-z0-9]"
                }
            },
            placeHolderChar: "_"
        },
        mask: [],
        /**
         * @protected
         * @overridden
         */
        init: function() {
            this.callParent(arguments);
            this.reSpecChars = [
                "\\", "(", ")", "+"
            ];
            this.addEvents(
                "paste");
            this.on("paste", this.onPaste, this);
            this.setMasks(this.mask);
        },
        /**
         * @protected
         * */
        setMasks: function(value) {
            this.masks = [];
            if (Ext.isEmpty(value)) {
                value = {
                    formats: []
                };
            }
            Terrasoft.each(value.formats, function(format, i) {
                this.masks[i] = this.getMaskByFormat(format);
            }, this);
            this.changeValue(this.value);
        },
        /**
         * {@link Terrasoft.Bindable}.
         * @overridden
         */
        getBindConfig: function() {
            var bindConfig = this.callParent(arguments);
            var multiMaskEditBindConfig = {
                mask: {
                    changeMethod: "setMasks"
                }
            };
            Ext.apply(bindConfig, multiMaskEditBindConfig);
            return bindConfig;
        },
        getMaskByFormat: function(format) {
            var mask = {};
            var matches = [];
            var placeHolderChar;
            var placeHolder = "";
            var def;
            var allRe = "";
 
            if (format) {
                Terrasoft.each(format.split(""), function(c) {
                    def = this.maskConfig.definitions[c];
                    if (def) {
                        allRe += def.re;
                        placeHolderChar = def.placeHolderChar || this.maskConfig.placeHolderChar || "_";
                        matches.push({
                            re: new RegExp(def.re),
                            placeHolderChar: placeHolderChar
                        });
 
                        placeHolder += placeHolderChar;
                    } else {
                        placeHolder += c;
                        matches.push(c);
                        if (this.reSpecChars.indexOf(c) > 0) {
                            allRe += "\\" + c;
                        } else {
                            allRe += c;
                        }
                    }
                }, this);
                mask.placeHolder = placeHolder;
                mask.matches = matches;
                if (allRe !== "") {
                    mask.re = {};
                    mask.re.full = new RegExp("^" + allRe + "$");
                }
            }
            return mask;
        },
        /**
         * @param value
         */
        removeEndPlaceHolders: function(value) {
            if (!Ext.isEmpty(value)) {
                var pos;
 
                for (var i = (value.length - 1); i >= 0; i--) {
 
                    if (value[i] !== this.maskConfig.placeHolderChar) {
                        break;
                    }
                    pos = i;
                }
                if (pos === 0) {
                    value = "";
                } else if (pos) {
                    value = value.slice(0, pos);
                }
            }
            return value;
        },
        /**
         * @param mask
         * @param c
         * @param pos
         * @param textBefore
         * @param textReplaced
         * @param textAfter
         * @param allowAutoFill
         * @returns {*}
         */
        maskValidateByInsChar: function(mask, c, pos, textBefore, textReplaced, textAfter, allowAutoFill) {
            var replacedLength = textReplaced.length;
            if (replacedLength > 0) {
                textAfter = mask.placeHolder.slice(pos, pos + textReplaced.length) + textAfter;
            }
            var value = textBefore + textAfter;
            var maskValidate;
            var match;
            if (!Ext.isEmpty(textAfter)) {
                match = mask.matches[pos];
                if (match && !match.re && mask.matches[pos] === c) {
                    return {
                        value: value,
                        pos: pos,
                        result: this.maskValidateValue(mask, value)
                    };
                }
            }
            value = textBefore + c + textAfter;
            match = mask.matches[pos];
            if (match) {
                if (match.re) {
                    if (textAfter[0] === mask.placeHolder.substr(pos, 1)) {
                        value = textBefore + c + textAfter.substring(1);
                        maskValidate = this.maskValidateValue(mask, value);
                        if (maskValidate.isValid) {
                            return {
                                value: value,
                                pos: pos,
                                result: maskValidate
                            };
                        }
                    }
                }
            }
            maskValidate = this.maskValidateValue(mask, value);
            if (maskValidate.isValid) {
                return {
                    value: value,
                    pos: pos,
                    result: maskValidate
                };
            }
            if (match && !match.re && allowAutoFill && pos < mask.placeHolder.length) {
                var result = this.maskValidateByInsChar(mask, c, pos + 1, textBefore + match,
                    textReplaced, textAfter.substring(1), allowAutoFill);
                if (result) {
                    return result;
                }
                return this.maskValidateByInsChar(mask, c, pos + 1, textBefore + match,
                    textReplaced, textAfter.substring(2), allowAutoFill);
            }
            //}
        },
        /**
         * @param c
         * @param pos
         * @param textBefore
         * @param textAfter
         * @param allowAutoFill
         * @returns {*}
         */
        formatValueByInsChar: function(c, pos, textBefore, textReplaced, textAfter, allowAutoFill) {
            var maskValidation;
            var bestResults = [];
            Terrasoft.each(this.masks, function(item) {
                maskValidation = this.maskValidateByInsChar(item, c, pos, textBefore, textReplaced, textAfter, allowAutoFill);
                if (maskValidation) {
                    maskValidation.mask = item;
                    if (bestResults.length === 0) {
                        bestResults.push(maskValidation);
                    } else if (maskValidation.pos < bestResults[0].pos) {
                        bestResults = [maskValidation];
                    }
                }
            }, this);
            if (bestResults.length > 0) {
                maskValidation = bestResults[0];
 
                var formatValue = this.formatValue(maskValidation.value);
                formatValue.insPos = maskValidation.pos;
                return formatValue;
            }
        },
        /**
         * @param mask
         * @param value
         * @returns {*}
         */
        maskValidateValue: function(mask, value) {
            var match;
            var matchPos = 0;
            if (mask.re.full.test(value)) {
                return {
                    matchPos: value.length,
                    inputPos: value.length,
                    isValid: true,
                    isComplete: true
                };
            }
            var result = {
                matchPos: 0,
                inputPos: 0,
                isValid: true,
                isComplete: false
            };
            value = this.removeEndPlaceHolders(value);
            if (Ext.isEmpty(value)) {
                return result;
            } else {
                Terrasoft.each(value.split(""), function(c, i) {
                    match = mask.matches[i];
                    if (!match) {
                        result = {
                            isValid: false,
                            isComplete: false
                        };
                        return false;
                    } else if (match.re) {
                        if (!match.re.test(c)) {
                            if (match.placeHolderChar === c) {
                                if (!result.inputPos) {
                                    result.inputPos = i;
                                }
                            } else {
                                result = {
                                    isValid: false,
                                    isComplete: false
                                };
                                return false;
                            }
                        }
                    } else if (c !== match) {
                        result = {
                            isValid: false,
                            isComplete: false
                        };
                        return false;
                    }
                    matchPos = i;
                }, this);
                result.matchPos = matchPos;
                if (!result.inputPos) {
                    if (result.isValid) {
                        result.inputPos = result.matchPos + 1;
                    } else {
                        result.inputPos = value.length;
                    }
                }
            }
            return result;
        },
        /**
         * @param value
         * @returns {{matches: Array, matchPos: number, inputPos: number}}
         */
        getMatchesByValue: function(value) {
            var matches = [];
            var minPositions = [];
            var matchPos = 0;
            var inputPos = 0;
            var maskValidation;
            var isComplete = false;
            Terrasoft.each(this.masks, function(mask) {
                maskValidation = this.maskValidateValue(mask, value);
                if (maskValidation.isValid) {
                    var maskMinPos = mask.matches.length;
                    Terrasoft.each(mask.matches, function(match, pos) {
                        if (typeof match === "object" && maskMinPos > pos) {
                            maskMinPos = pos;
                        }
                    });
                    minPositions.push(maskMinPos);
                    if (maskValidation.isComplete) {
                        isComplete = true;
                    }
                    matches.push({
                        mask: mask,
                        validation: maskValidation
                    });
                    if (matchPos < maskValidation.matchPos) {
                        matchPos = maskValidation.matchPos;
                    }
                    if (inputPos < maskValidation.inputPos) {
                        inputPos = maskValidation.inputPos;
                    }
                }
            }, this);
            var minPos = Math.min.apply(0, minPositions);
            return {
                matches: matches,
                matchPos: matchPos,
                inputPos: inputPos,
                minPos: minPos,
                isComplete: isComplete
            };
        },
        /**
         * @param values
         * @returns {*}
         */
        getCommonStartString: function(values) {
            var valuesCount = values.length;
            if (valuesCount === 0) {
                return "";
            } else if (valuesCount === 1) {
                return values[0];
            }
            var commonStr = "";
            var minLen = values[0].length;
            Terrasoft.each(values, function(value) {
                minLen = Math.min(minLen, value.length);
            });
            var isMatch;
            var c;
            for (var i = 0; i < minLen; i++) {
                isMatch = true;
                for (var j = 1; j < valuesCount; j++) {
                    isMatch = values[j][i] === values[j - 1][i];
                    if (!isMatch) {
                        break;
                    }
                    c = values[j][i];
                }
                if (isMatch) {
                    commonStr += c;
                } else {
                    return commonStr;
                }
            }
            return commonStr;
        },
        /**
         * @param a
         * @param name
         * @returns {Array}
         */
        getPropertyValuesFromArray: function(a, name) {
            var result = [];
            Terrasoft.each(a, function(e) {
                result.push(e[name]);
            }, this);
            return result;
        },
        /**
         * @overridden
         * @protected
         */
        initDomEvents: function() {
            this.callParent(arguments);
            var el = this.getEl();
            el.on({
                "paste": {
                    fn: this.onPaste,
                    scope: this
                }
            });
        },
        onBeforePasteFormatValue: Ext.emptyFn,
        onPaste: function(e) {
            if (Ext.isEmpty(this.masks)) {
                return;
            }
            var getSplitText = function(v, p) {
                return {
                    pos: p,
                    before: v.substr(0, p),
                    after: v.substr(p)
                };
            };
            e.preventDefault();
            if (e.browserEvent.clipboardData && e.browserEvent.clipboardData.getData) {
                if (/text\/plain/.test(e.browserEvent.clipboardData.types)) {
                    var clipBoardValue = e.browserEvent.clipboardData.getData("text/plain");
                    clipBoardValue = this.onBeforePasteFormatValue(clipBoardValue) || clipBoardValue;
                    if (Ext.isEmpty(clipBoardValue)) {
                        return;
                    }
                    var domEl = e.getTarget();
                    var info = this.getInputInfo(domEl);
                    var pos = info.caretPosition;
                    var splitText = {
                        before: info.valueBeforeCaret,
                        after: info.valueAfterCaret
                    };
                    var newValue = splitText.before + splitText.after;
                    Terrasoft.each(clipBoardValue.split(""), function(c) {
                        var formatValue = this.formatValueByInsChar(c, pos, splitText.before, "", splitText.after, true);
                        if (formatValue) {
                            newValue = formatValue.value;
                            pos = formatValue.insPos + 1;
                            splitText = getSplitText(newValue, pos);
                        }
                    }, this);
                    domEl.value = newValue;
                }
            }
            return;
        },
        /**
         * @param value
         * @returns {*}
         */
        formatValue: function(value) {
            var newValue = value;
            var placeHolders;
            if (Ext.isEmpty(value)) {
                placeHolders = this.getPropertyValuesFromArray(this.masks, "placeHolder");
                newValue = this.getCommonStartString(placeHolders);
                if (!Ext.isEmpty(newValue)) {
                    return this.formatValue(newValue);
                }
                return {
                    pos: 0,
                    value: "",
                    isComplete: false
                };
            }
            var matches = this.getMatchesByValue(value);
            if (matches.matches.length === 0) {
                if (matches.matchPos > 0) {
                    newValue = value.substr(0, matches.matchPos + 1);
                } else {
 
                    return {
                        pos: 0,
                        value: value,
                        isComplete: false
                    };
                }
                return this.formatValue(newValue);
            }
            var masks = this.getPropertyValuesFromArray(matches.matches, "mask");
            placeHolders = this.getPropertyValuesFromArray(masks, "placeHolder");
            var afterText = this.getCommonStartString(placeHolders).substr(matches.matchPos + 1);
            newValue = value.substr(0, matches.matchPos + 1) + afterText;
            matches = this.getMatchesByValue(newValue);
            return {
                pos: matches.inputPos,
                min: matches.minPos,
                value: newValue,
                isComplete: matches.isComplete
            };
        },
        /**
         * @param value
         * @param caretPosition
         */
        setDomValueAndCaret: function(value, caretPosition) {
            var formatValue = this.formatValue(value);
            if (!this.validationInfo.isValid && formatValue.isComplete) {
                var validationInfo = {
                    isValid: true,
                    invalidMessage: ""
                };
                this.setValidationInfo(validationInfo);
            }
            var el = this.getEl();
            if (el) {
                el.dom.value = formatValue.value;
                caretPosition = caretPosition > formatValue.min ? caretPosition : formatValue.min;
                Terrasoft.utils.dom.setCaretPosition(el.dom, caretPosition);
            }
        },
        /**
         * @param {String} value
         * @protected
         * @virtual
         */
        setDomValue: function(value) {
            this.setDomValueAndCaret(value);
        },
        /**
         * @protected
         * @param  {String} value
         * @return {Boolean}
         */
        changeValue: function(value) {
            if (!Ext.isEmpty(this.masks)) {
                var formatValue = this.formatValue(value);
                if (formatValue.value === this.formatValue(null).value) {
                    value = null;
                    formatValue.isComplete = true;
                    var el = this.getEl();
                    if (el) {
                        el.dom.value = "";
                    }
                }
                var validationInfo = this.getValidationInfo(formatValue);
                this.setValidationInfo(validationInfo);
            }
            return this.callParent(arguments);
        }
    });
});

2. In the target schema add dependency to "MultiMaskEdit" schema and specify input mask format and className for the "Phone" filed in the controlConfig.

AccountMiniPage code

define("AccountMiniPage", ["MultiMaskEdit"], function() {
    return {
        entitySchemaName: "Account",
        diff: /**SCHEMA_DIFF*/[
            {
                "operation": "merge",
                "name": "Phone",
                "values": {
                    "controlConfig": {
                        "className": "Terrasoft.controls.MultiMaskEdit",
                        "mask": {
                            "formats": ["(99)999-99-99"]
                        }
                    }
                }
            }
        ]/**SCHEMA_DIFF*/
    };
});

Result:

Like 0

Like

Share

12 comments

Dear all, anyone knows where, I mean, the menus I must access to find the place where this code must be inserted?

Andre VItal,

Hello.

You have to do it in the configuration. You can read more in the article below, there is another example of the implementation:

https://academy.bpmonline.com/documents/technic-sdk/7-13/how-add-field-…

Best regards,

Matt

 

Matt Watts,

I tried creating a module where the code for 

MultiMaskEdit  is added then on my section page I have added 

define("UsrInterview1Page", [ "MultiMaskEdit", "css!UsrInterviewcss1"], function() {

//rest of the code

But the page seems to be unresponsive, did I miss out something?

Please help me in resolving this issue.

manikanta,

Hello.

First of all, please make sure that the MultiMaskEdit is a module, not a source code, most likely it is the cause of your issue. Secondly, please make sure that you have validated your code and eliminated all mistakes caused by the incorrect html tags, for example &gt; should be changed to >, &lt; to < and &amp; to simply &.

Lastly, please make sure that you have added your code to the correct target schema, i.e. if you need it for the account mini page then you should add the code from the second part of the article to the AccountMiniPage schema.

If you have done everything correctly you should be able to see the validation mask on the desired page.

Best regards,

Matt

Hello,

Thank you! Works fine on my side but I can no longer access to MiniPage Wizard.

Did I do something wrong!

Thank you for your help!

Dear Thibaut,

Please try validating the code as descrbed by Matt previously and also try generating source code and compiling of the instance.

Best regards,

Oscar

Dear Oscar,

Thank you for your reply.

I validated the code, generate source + compiling instance and the issue persist.

I get the error "Schema does not contain marker comments: 'SCHEMA_DETAILS'" in browser console when I try to load the designer page.

Any idea?

Thank you!

Hello,

Solved the issue by adding these 2 rows in the second code.

modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,

details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,

Regards

Hi all,

 

I follow the guide and add to the contact page:

But when I open contact, it's only blank.

What I do wrong?

Regards,

Phuong Nguyen

Phuong Akira,

 

The Mobile phone column in the diff should be MobilePhone (without a space):

{

                "operation": "merge",

                "name": "MobilePhone",

                "values": {

                    "controlConfig": {

                        "className": "Terrasoft.controls.MultiMaskEdit",

                        "mask": {

                            "formats": ["(99)999-99-99"]

                        }

                    }

                }

  },

Aside from that, everything would work. I've replicated it on my demo instance and it worked well. 

Also please make sure to replace &gt; to >, &lt; to < and &amp; to simply &. in MultiMaskEdit module.

 

Hello, 

 

Anyonw knows if there is posible change the format depends of another field? Like depends of the country change the format.

Federico Buffa,

You have an opportunity to specify all formats which you use in formats array in the diff and after the user start typing maskhelper select the proper format from those which you populate 

ex:

define("AccountPageV2", ["GlbMultiMaskEdit"], function() {

    return {

        entitySchemaName: "Account",

        attributes: {},

        modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,

        details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,

        businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,

        messages:{

        },

        methods: {

            onEntityInitialized: function(){

                this.callParent(arguments);

            }

        },

        dataModels: /**SCHEMA_DATA_MODELS*/{}/**SCHEMA_DATA_MODELS*/,

        diff: /**SCHEMA_DIFF*/[

            {

                "operation": "merge",

                "name": "AccountPhone",

                "values": {

                    "controlConfig": {

                        "className": "Terrasoft.controls.GlbMultiMaskEdit",

                        "mask": {

                            "formats": ["+38(99)999-99-99", "+546(999)-9999-9", "+1(999)-9-999-9", "(999)-0-00-999"]

                        }

                    }

                }

            }

        ]/**SCHEMA_DIFF*/

    };

}); 

 

Best regards,

Angela

Show all comments

Client context

MobileApplicationInvoiceManifest not found;

MobileApplicationoportunityManifest not found;

MobileApplicationLeadManifest not found;

Cause

The specified manifest is registered in the "Mobile application manifest" system setting by mistake.

Solution

Simply remove this manifest from the list in the specified system setting.

Necessary conditions

Admin rights. Clearing Redis after removing the manifest.

Like 0

Like

Share

0 comments
Show all comments

Symptoms

Connecting to the on-site application results in the following error (outdated browser): 

ServiceStack.Redis.RedisResponseException: MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error., sPort: 53192, LastCommand: \\r\\n в ServiceStack.Redis.RedisNativeClient.CreateResponseError(String error)\\r\\n в ServiceStack.Redis.RedisNativeClient.ReadInt()\\r\\n в ServiceStack.Redis.RedisNativeClient.Expire(String key, Int32 seconds)\\r\\n в ServiceStack.Redis.RedisClient.ExpireEntryIn(String key, TimeSpan expireIn)\\r\\n в Terrasoft.Redis.RedisSessionStateStoreProvider.ResetItemTimeout(HttpContext context, String id)\\r\\n в System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData)\\r\\n in System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication

Cause

This error is caused by Redis settings on the server.

Solution

Use third-party documentation to learn more. 

http://stackoverflow.com/questions/19581059/misconf-redis-is-configured-to-save-rdb-snapshots;

http://stackoverflow.com/questions/19873048/redis-is-configured-to-save-rdb-snapshots-but-is-currently-not-able-to-persist;

https://gist.github.com/kapkaev/4619127.

Use the mobile version of the application to ensure correct operation - the application may not work properly in mobile browsers.

 

Like 0

Like

Share

0 comments
Show all comments