Customizing User Manager

User Manager is a complex widget created with Webix Jet, the MV* framework for Webix Library. It is a ready-to-use application that needs minimal configuration and has an API for redefining the logic of inner modules.

You need to study the source code to customize views and models.

Jet App and Inner Modules

User Manager is built as a Jet App and wrapped in a Webix view, so you can initialize it in either way.

Views

The interface of User Manager is split into parts (views). Each view is a class that extends the JetView class and has its own handlers for setting the configuration and logic.

The sources for interface parts (Jet Views) are located in the sources/views folder.

views
  roles
  users
  audit.js
  details.js
  ...

Go to the Class Map page to see the list of all Jet views in User Manager and where they are in the interface.

Models/Services

User Manager models contain the logic for working with main entities (users/roles/rules), manipulating prompt and progress bar. They are defined as Jet Services.

The sources for models (Jet Services) are located in the sources/models folder.

models
  Local.js
  Operations.js
  Backend.js
  Prompt.js
  Progress.js

Service methods are called by the UI and can be called by a programmer as:

$$('um').getService('operations').addUser(obj);

Customizing Views

When you customize a view, you can:

  • override the config() method to change the UI
  • override the init() method to change the UI and behavior
  • override any existing method, but do it with caution
  • add and call your own methods

Check the Class Map to find which view renders the part you want to modify.

First, create your own view class by inheriting it from one of the default views or from userManager.views.JetView:

class CustomToolbar extends userManager.views["users/toolbar"] {
  config(){
    // get JSON object with configuration
    const ui = super.config();
    // exact changes depend on a particular view
    ui.height = 60;
    return ui;
  }
  init() {
    // call default logic
    super.init();
    // custom logic below
    this.doSomething();
  }
  doSomething(){
    // do something on init
  }
}

Then, replace the default view via the override map:

webix.ui({
    view: 'usermanager',
    url: 'https://docs.webix.com/usermanager-backend/',
    override: new Map([[userManager.views['users/toolbar'], CustomToolbar]]),
});

Adding Columns to the Users Grid

To add an extra column to the users grid, you need to change its JSON configuration:

class UserGrid extends userManager.views['users/grid'] {
    config() {
        const grid = super.config();
 
        const formatDate = webix.Date.dateToStr('%M %d, %Y %H:%i:%s');
        // adding "last visited" column
        const newColumn = {
            id: 'visited',
            header: 'Last seen',
            fillspace: 2,
            template(obj, type, value, column, index) {
                // parse ISO 8601 and apply formatting
                let date = new Date(value);
                return formatDate(date);
            },
        };
 
        grid.columns.push(newColumn);
 
        return grid;
    }
}

Related sample:  User Manager: Adding an Extra Column

You can find more use cases in the How-tos article.

Notes

Hiding Components

We do not recommend removing any component from the interface as the inner logic might still try accessing it. Instead, hide the components.

class CustomToolbar extends userManager.views['users/toolbar'] {
    init(view) {
        // default logic
        super.init(view);
        // hide "Role Matrix" toggle control
        view.queryView('toggle', 'all')[0].hide();
    }
}

Accessing Component Instances

Within a Jet view, you can access component instances in two ways.

Use the $$(id) method of JetView for an inner component that has the localId setting:

init() {
    // default logic
    super.init();
    // get instance of the component with "list" localId
    const form = this.$$("list");
}

Use queryView if localId is not defined:

init(view) {
    // default logic
    super.init();
    // get instance of the first list
    const list = view.queryView("list");
}

Checking the Compact Mode

You can find out whether the app is currently compact from any view or service method:

const compact = this.getParam('compact', true);

Getting State Properties

You can get state properties from any view or service method:

const state = this.app.getState();
// or
const state = this.getParam('state');

Customizing Jet Services

When you customize a service, you can:

  • add and call your own methods
  • override any existing method, but do it with caution

First, create your own service class and inherit it from one of the default services:

class MyBackend extends userManager.services.Backend {
    users() {
        // client-side data
        return webix.promise.resolve(users);
    }
}

Then, replace the default service via the override map:

webix.ui({
    view: 'usermanager',
    override: new Map([[userManager.services.Backend, MyBackend]]),
});

Related sample:  User Manager: Local Data

You can find more information about User Manager Backend service in the Working with Server article.

Backward Compatibility

User Manager is flexible: you can change almost anything in it. However, keep in mind the following:

  • The inner logic of User Manager modules may change in future releases.
  • We will try to maintain method signatures, but breaking changes might happen if they are necessary for further development of the widget.

Code for Edge Chromium must use a different syntax.

Back to top
Join Our Forum
We've retired comments here. Visit our forum for faster technical support, connect with other developers, and share your feedback there.