Skip to main content
Version: 8.0

Add a mini page to a module

Level: advanced
Example

Display the current user in the top right of Creatio next to the profile icon. Hover over the link to the current user to open the mini page.

1. Create a module schema

  1. Go to the Configuration section and select a user-made package to add the schema.

  2. Click AddModule on the section list toolbar.

  3. Fill out the schema properties in the Schema Designer:

    • Set Code to "UsrCurrentUserModule."
    • Set Title to "Current user module."

    Click Apply to apply the properties.

2. Create a view and view model of the module

Add the source code to the UsrCurrentUserModule module in the Schema Designer.

  1. Implement the class inherited from Terrasoft.BaseViewModel to create a view model.
  2. Enable the Terrasoft.MiniPageUtilities utility class in the mixins property of the view model. The class lets you use the mini page call methods.
  3. Implement the class inherited from Terrasoft.BaseModule to create a view.
  4. Override the following methods of the Terrasoft.BaseModule class in the new class:
    • init() initializes the view model of the module.
    • render() binds the view model to the container view display passed in the renderTo parameter.
    • getViewModel() creates the view model.
    • getView() retrieves the view to display it. The view must contain the full name of the current user and a hyperlink to the contact page. Define the hover event handler when creating the hyperlink.
  5. Define the viewModel property that stores the link to the retrieved view model.

View the source code of the module below.

UsrCurrentUserModule.js
/* Define the module. */
define("UsrCurrentUserModule", ["MiniPageUtilities"], function() {
/* Define the CurrentUserViewModel class. */
Ext.define("Terrasoft.configuration.CurrentUserViewModel", {
/* The parent class name. */
extend: "Terrasoft.BaseViewModel",
/* The shortened class name. */
alternateClassName: "Terrasoft.CurrentUserViewModel",
/* The mixins used. */
mixins: {
MiniPageUtilitiesMixin: "Terrasoft.MiniPageUtilities"
}
});
/* Define the UsrCurrentUserModule class. */
Ext.define("Terrasoft.configuration.UsrCurrentUserModule", {
/* The shortened class name. */
alternateClassName: "Terrasoft.UsrCurrentUserModule",
/* The parent class name. */
extend: "Terrasoft.BaseModule",
/* The Ext object. */
Ext: null,
/* The sandbox object. */
sandbox: null,
/* The Terrasoft object. */
Terrasoft: null,
/* The view model. */
viewModel: null,
/* Create the module views. */
getView: function() {
/* Retrieve the current user contact. */
var currentUser = Terrasoft.SysValue.CURRENT_USER_CONTACT;
/* The view that represents the Terrasoft.Hyperlink class instance. */
return Ext.create("Terrasoft.Hyperlink", {
/* Populate the link anchor text using the contact name. */
"caption": currentUser.displayValue,
/* The link hover event handler. */
"linkMouseOver": {"bindTo": "linkMouseOver"},
/* The property that contains the additional object parameters. */
"tag": {
/* The ID of the current user. */
"recordId": currentUser.value,
/* The object schema name. */
"referenceSchemaName": "Contact"
}
});
},
/* Create the view model of the module. */
getViewModel: function() {
return Ext.create("Terrasoft.CurrentUserViewModel");
},
/* Initialize the module. */
init: function() {
this.viewModel = this.getViewModel();
},
/* Display the module view. */
render: function(renderTo) {
/* Retrieve the view object. */
var view = this.getView();
/* Bind the view to the view model. */
view.bind(this.viewModel);
/* Display the view in the renderTo element. */
view.render(renderTo);
}
});
return Terrasoft.UsrCurrentUserModule;
});

3. Add the module styles

Add styles to the module to customize the appearance of the hyperlink.

To add the module styles:

  1. Select the LESS node in the Schema Designer.

  2. Add the following source code.

    Module styles
    .current-user-class a {
    font-weight: bold;
    font-size: 2.0em;
    margin: 6px 20px;
    }

    .current-user-class a:hover {
    text-decoration: none;
    }

Save the module.

4. Create the view display container

To display a link to the user profile in the top right of Creatio, place the container and upload the view of the module to the container.

To do this, create the schema of the replacing view model that expands the functionality of the MainHeaderSchema schema.

  1. Go to the Configuration section and select a user-made package to add the schema.

  2. Click AddReplacing view model on the section list toolbar.

  3. Select the MainHeaderSchema parent object in the Module Designer.

    After you confirm the parent object, Creatio will populate the other properties.

    Click Apply to apply the properties.

  4. Add the source code in the Module Designer.

    Use the diff property to display the view in the source code of the replacing view model schema. Set the RightHeaderContainer element as a parent element of the container to display the container in the top right of the page. Then, override the onRender() method and implement the upload of the created module in the method.

    View the source code of the replacing view model schema below.

    MainHeaderSchema.js
    /* Define the module. */
    define("MainHeaderSchema", [], function() {
    return {
    methods: {
    /* Execute the actions after displaying the view. */
    onRender: function() {
    /* Call the parent method. */
    this.callParent(arguments);
    /* Load the module of the current user. */
    this.loadCurrentUserModule();
    },
    /* Load the module of the current user. */
    loadCurrentUserModule: function() {
    /* Retrieve the container to upload the module. */
    var currentUserContainer = this.Ext.getCmp("current-user-container");
    /* Check if the container exists. */
    if (currentUserContainer && currentUserContainer.rendered) {
    /* Upload the module to the container. */
    this.sandbox.loadModule("UsrCurrentUserModule", {
    /* The container name. */
    renderTo: "current-user-container"
    });
    }
    }
    },
    diff: [
    {
    /* The element insert operation. */
    "operation": "insert",
    /* The element name. */
    "name": "CurrentUserContainer",
    /* The parent container name. */
    "parentName": "RightHeaderContainer",
    /* The property name. */
    "propertyName": "items",
    /* The element values. */
    "values": {
    /* The container ID. */
    "id": "current-user-container",
    /* The element type. */
    "itemType": Terrasoft.ViewItemType.CONTAINER,
    /* The container classes. */
    "wrapClass": ["current-user-class"],
    /* The container items. */
    "items": []
    }
    }
    ]
    };
    });
  5. Click Save on the Module Designer's toolbar.

Outcome of the example

After you refresh the web page, Creatio will display the full name of the current user and a hyperlink to their contact page. Hover over the link to bring up the mini page that contains the data of the current user.


Resources

Package with example implementation