Article

Hiding print button for different opportunity stages

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