LogoLogo
Enterprise GuideCommunity Edition GuideDeveloper Guide
  • Using The Polarity Developer Guide
  • Quick Start
    • What's New
    • Installing Integrations
    • Quick Start Guide
    • Learning Resources
  • Building an Integration
    • Directory Layout
    • package.json
    • Configuration File
    • Integration Main Module
      • startup
      • doLookup
        • Entity Objects
        • Result Objects
        • Error Objects
      • onDetails
      • onMessage
      • validateOptions
    • Customizing the Overlay Window
      • Templates
        • Conditionals
        • Displaying a List of Items
        • Display Object Properties
        • Built-in Helpers
        • Displaying Icons
      • Component File
        • Aliased Properties
        • Computed Properties
        • Event Hooks
      • CSS Styles
    • Vendor Javascript
      • Inserting Javascript into DOM
    • README Guide
    • Debugging Integrations
      • Web Inspector
      • Using Integration Logs
      • Testing Main Module
  • Recipes
    • Enabling User Actions
    • Throttling Lookups
    • Using Custom Entity Types
    • Custom Summary Tags
    • Creating a Tabbed Interface
    • Accessing Username of Requestor
Powered by GitBook
On this page
  • Components
  • Setup
  • Accessing Data
  • Actions
  • sendIntegrationMessage(payload)
  1. Building an Integration
  2. Customizing the Overlay Window

Component File

Create computed properties, trigger actions, and add interactive elements to your template

PreviousDisplaying IconsNextAliased Properties

Last updated 3 years ago

Components

sample-integration/
├── components/
|   └── sample-integration.js

The components directory contains a component file that allows logic to be implemented and data to be manipulated on the client side of the integration (i.e., within the notification window). Components are typically used to format data on the client, or to receive user actions from the notification window. If you are creating a custom component then you should also create a .

Components are an extension of the Ember.Component class so if you are familiar with Ember components there are no differences. You can read about Ember Components from the official .

Setup

If you are following the recommend then your component file should be placed inside a components directory. At a minimum the component needs to extend and export a PolarityComponent object. Note that this is the primary difference between an Ember Component and a Polarity Integration Component.

The Ember object is already available within the Polarity component and does not need to be imported separately.

Components have access to the same data available to your templates (i.e., the data returned by your integration).

components/component.js
'use strict';

polarity.export = PolarityComponent.extend({
    // This is an valid component but does nothing           
});

Accessing Data

Components have access to the same data available to your templates (i.e., the data returned by your integration). You can access the data and even change it by using the get and set methods. All data returned by your integration in the result object is wrapped in a block object.

In the example, init is a special function that is called when a component is first initialized.

Note that we call this._super(...arguments) which calls the parent init method to ensure any setup from the parent component is executed.

// components/component.js
'use strict';

polarity.export = PolarityComponent.extend({
    init: function(){
        this._super(...arguments);

        // Get a property called `firstName` from `data.details`
        let firstName = this.get('block.data.details.firstName');

        // Set the value of firstName to be 'Ed' overwiting the existing value
        this.get('block.data.details.firstName', 'Ed');

        // Get the `isVolatile` flag
        let isVolatile = this.get('block.isVolatile');

        // Get the entity value
        let value = this.get('block.entity.value');
    }           
});

Actions

Component Actions allow the component to react to user interaction in the template. The common example is to allow the user to react to a button being pressed in the template.

First we need to setup our template with a button. When the button is clicked it will trigger the onClick action in our component.

We then create a function called doSomething inside the actions hash of our component. The doSomething function will be called anytime a user triggers the doSomething action by clicking on the button.

'use strict';

polarity.export = PolarityComponent.extend({
    actions:{
        doSomething: function(){
            // this function is triggered anytime a user clicks on the button                
        }   
    }                 
});

sendIntegrationMessage(payload)


@method sendIntegrationMessage
@param payload, the data you want to send to the server
@return Promise
'use strict';

polarity.export = PolarityComponent.extend({
    message: '',
    actions: {
        sendMessage: function () {
            let self = this;
            this.sendIntegrationMessage({data:'this is some data'}).then(
                function (response) {
                    self.set('message', "Success!");
                }).catch(function (err) {
                    self.set('message', "ERROR!");
            });
        }
    }
});

You can send messages to the server's method by using the utility method sendIntegrationMessage available via the Polarity Component.

The method returns a . If the promise resolves successfully it will return the response from the server.

custom template
Ember Component Guide
directory layout
onMessage
Promise