Spanish Total.js
English
Documentation For AI agents
Contents

Add a plugin

Create a new plugin with its own menu item, screen and API action.

.md GitHub
On this page

The quickest way to add a plugin is to copy the sample plugin Profiles and rename it. This recipe builds a plugin called Orders.

1. Copy the sample

Copy the folder plugins/profiles to plugins/orders, and rename the file schemas/profiles.js to schemas/orders.js:

cp -R plugins/profiles plugins/orders
mv plugins/orders/schemas/profiles.js plugins/orders/schemas/orders.js

2. Describe the plugin

Replace the content of plugins/orders/index.js with:

exports.icon = 'ti ti-shopping-cart';
exports.name = '@(Orders)';
exports.position = 3;
exports.permissions = [{ id: 'orders', name: 'Orders' }];
exports.visible = user => user.sa || user.permissions.includes('orders');
exports.routes = [
    { url: '/orders/{id}/', html: 'detail' }
];

exports.install = function() {
    ROUTE('+API   ?   -orders    --> Orders/list');
};
  • icon and name are the menu item. Icons are Total.js icon classes that start with ti ti-, such as ti ti-box.
  • position sets the order in the menu.
  • The ROUTE line makes the API action orders available to the screen.

Every option is listed in Plugin options.

3. Write the action

Replace the content of plugins/orders/schemas/orders.js with:

NEWACTION('Orders/list', {
    name: 'List of orders',
    permissions: 'orders',
    action: function($) {
        var arr = [];
        for (var i = 0; i < 3; i++)
            arr.push('Demo order ' + (i + 1));
        $.callback(arr);
    }
});

Here you read your real data, for example from the database.

4. Adapt the screen

In plugins/orders/public/index.html, change the three places that name the sample:

  • BREADCRUMB.add('@(Profiles)', NAV.url); becomes BREADCRUMB.add('@(Orders)', NAV.url);
  • REDIRECT('/profiles/{0}/'.format(id)); becomes REDIRECT('/orders/{0}/'.format(id));
  • exports.tapi('profiles ERROR', ... becomes exports.tapi('orders ERROR', ...

In plugins/orders/public/detail.html, change @(Profiles) to @(Orders).

5. Restart and check

Restart Pluginable and sign in. Orders is in the side menu and on the home screen, and it lists the demo orders.

The new Orders plugin open in the admin, with three demo orders

Next steps:

Made in Europe