Article

Add a button on EditPage

Case description:

You need to add a button to the Opportunity edit page.

Algorithm of realization:

  1. Create replacing client schema for your page.
  2. Create localizable string which will contain caption of the button.







    Figure 1. Adding a localizable string

     
  3. Source code of the "OpportunityPageV2" :

    define("OpportunityPageV2", [], function() {
        return {
            entitySchemaName: "Opportunity",
            messages: {
                "SetNewQuoteButtonVisibility": {
                    mode: this.Terrasoft.MessageMode.PTP,
                    direction: this.Terrasoft.MessageDirectionType.PUBLISH
                }
            },
            methods: {
                onNewQuoteClick: function() {
                    //TODO: implement your logic here
                    this.showInformationDialog("Hello");
                },
                getNewQuoteButtonVisible: function() {
                    var newMode = this.isNewMode();
                    var result = !newMode; //TODO: implement your logic for visibility here
                    this.sandbox.publish("SetNewQuoteButtonVisibility", result, [this.sandbox.id]);
                    return result;
                }
            },
            diff: /**SCHEMA_DIFF*/[
                {
                    "operation": "insert",
                    "name": "NewQuoteButton",
                    "parentName": "LeftContainer",
                    "propertyName": "items",
                    "values": {
                        "itemType": Terrasoft.ViewItemType.BUTTON,
                        "style": Terrasoft.controls.ButtonEnums.style.DEFAULT,
                        "caption": {"bindTo": "Resources.Strings.NewQuoteBtn"},
                        "click": {"bindTo": "onNewQuoteClick"},
                        "visible": {"bindTo": "getNewQuoteButtonVisible"},
                        "classes": {
                            "textClass": ["actions-button-margin-right"]
                        }
                    }
                }
            ]/**SCHEMA_DIFF*/
        };
    });

     

  4. Create replacing client schema for the section.
  5. Create section's localizable string for a button caption.

    define("OpportunitySectionV2", [], function() {
        return {
            attributes: {
                "IsNewQuoteButtonVisible": {
                    dataValueType: this.Terrasoft.DataValueType.BOOLEAN,
                    value: false
                }
            },
            messages: {
                "SetNewQuoteButtonVisibility": {
                    mode: this.Terrasoft.MessageMode.PTP,
                    direction: this.Terrasoft.MessageDirectionType.SUBSCRIBE
                }
            },
            methods: {
                subscribeSandboxEvents: function() {
                    this.callParent(arguments);
                    this.sandbox.subscribe("SetNewQuoteButtonVisibility", function(result) {
                        this.set("IsNewQuoteButtonVisible", result);
                    }, this, [this.getCardModuleSandboxId()]);
                }
            },
            diff: /**SCHEMA_DIFF*/[
                {
                    "operation": "insert",
                    "name": "NewQuoteButton",
                    "parentName": "CombinedModeActionButtonsCardLeftContainer",
                    "propertyName": "items",
                    "values": {
                        "itemType": Terrasoft.ViewItemType.BUTTON,
                        "style": Terrasoft.controls.ButtonEnums.style.DEFAULT,
                        "caption": {"bindTo": "Resources.Strings.NewQuoteBtn"},
                        "visible": { "bindTo": "IsNewQuoteButtonVisible" },
                        "click": {"bindTo": "onCardAction"},
                        "tag": "onNewQuoteClick",
                        "classes": {
                            "textClass": ["actions-button-margin-right"]
                        }
                    }
                }
            ]/**SCHEMA_DIFF*/
        };
    });

     

The result would be:

Like 1

Like

Share

0 comments
Show all comments