Profile Tooltip Plug-in
Introduction
This article introduces the Profile Tooltip Plug-in.
The Profile Tooltip plug-in displays a tooltip when the user hovers over the User selection field.
This tooltip includes some information of the user that are recorded in their user profile page.
This plug-in uses Tippy.js , a highly customizable tooltip, to create and display tooltips.
Plug-in file
The packaged sample plug-in zip file can be downloaded from the
Releases page
on GitHub.
Install the plug-in into your domain by following
the plug-in installation guide on the Help page
.
You can then add the plug-in to a specific App by following
the plug-in adding guide on the Help page
.
Overview
Set your form up to support the plug-in by adding a User selection field in your App.
There is only one setting on the config page.
For this setting, select a User selection field from the drop-down list where you want the tooltip to be displayed.
Save the settings, and update the App.
When you hover over users listed in the specified User selection field on the Record Details page, a tooltip will be shown containing their Email, phone numbers and timezone.
File structure
The sample codes used in the plug-in are listed under the src file in our
GitHub repository
.
The plug-in is created with the following file structure:
|
|
This file builds the HTML of the plug-in settings page.
Each <div>
tag with the "block" class represents 1 row of related HTML elements.
The first "block" contains the HTML of the first (an only) setting, where the user chooses which User selection field where the tooltip feature will be applied to. A select tag is stated in the HTML, that creates a drop-down field with a value of "-----". This drop-down field is later populated by the config.js file.
|
|
This CSS file is provided on
GitHub
. This file styles HTML elements on the plug-in config page to fit in with Kintone's UI.
We recommend that you do not make changes to 51-modern-default.css. If you need to style additional elements, or over-ride the default styles, those changes should be added into config.css.
This supporting CSS file is used to style some areas of the plug-in config page that 51-modern-default.css doesn't cover.
This JavaScript file runs on the plug-in config page.
This file uses the
kintone-config-helper
library to help build out form elements for the plug-in settings.
The function setDropDown is called when the plug-in config page loads.
|
|
This function calls the KintoneConfigHelper.getFields method from the kintone-config-helper library.
By passing 'USER_SELECT' as the parameter, an array of field information of all User selection fields are returned.
|
|
This file styles the regular pages of the App such as the record list page and the record details page.
For this plug-in, this file adds style to the tooltips that are displayed when the user hovers over user names in the User selection field.
This file runs on the regular pages of the App, such as the Record List and Record Details pages, but not on the plug-in config page.
The
getConfig API
is first called to store data that was saved in the plug-in config page to a variable.
|
|
An object is then created containing the titles of the tooltip contents. The keys in this object relate to the response parameter properties of the Get Users API that is later called in the code.
|
|
The rest of the code runs when the app.record.detail.show event (when the Record Details page loads) is triggered.
|
|
The current value of the User selection Field (specified in the config page) is placed into a variable. As User selection Fields can hold information of multiple users, User selection Field values are arrays by default. If the length of this array is 0 (i.e. no user information is saved in this User selection Field), no further codes are executed.
|
|
The kintone.app.record.getFieldElement method is called to retrieve the field element of the User selection field. In this plug-in, we want to be able to hover over each user name to produce separate tooltips, rather than hovering over any part of the User selection Field to display all tooltips. To do this, we need to dig a little deeper in the DOM - the targetLink variable stores a list of element nodes for each user within the User selection Field.
|
|
The variable fieldValCodeList then stores an array of User codes (the log in names) of the users in the User selection field. The User codes are used for the parameters of the Get Users API to get a list of User related data. The obtained data is sorted, and used together with the tippy function from the Tippy.js library to create the tooltips.
|
|
The kintone-config-helper.js file is a library that supports the development of the plug-in config page. View the Introduction to Kintone Config Helper article for more details.
The manifest file states the paths of the files that will be used in the plug-in.
For the desktop pages, the
Tippy.js
library, desktop.js and desktop.css files are specified.
|
|
For the config pages, it links to the jQuery library hosted on the Kintone CDN and the kintone-config-helper library.
|
|
The array in the value of the required_params key states which settings in the plug-in config page are required. If these settings are not saved using the setConfig API , errors will be displayed on other pages of the App, stating that the plug-in settings have not been configured yet.
|
|
The name, description, and homepage_url key-value pairs are labels and links displayed in the plug-in config pages.
|
|
Finally
Licenses
This plug-in is open sourced under the
MIT License
. It allows open- or closed-sourced distribution, including commercial use.
If you would like to add more functionality to the plug-in, you are welcome to clone our repository to make your own changes and redistribute it. We generally do not accept external pull requests for the sample plug-in as this repository exists for educational purposes.
If you have any questions related to building Kintone plug-ins, please post your question in the
Kintone Developer Program Community Forum
.