EN IT
Open2b version 7.8

Labels

Each app has labels, numbered from 1 to 64, that it can add to products, customers, and documents (orders, quotes, invoices, receipts, returns and packing slips) and they are shown in the back office once a name is assigned. An app's labels are not visible or editable by other apps.

To add labels to products, customers and documents and read added labels, use the commerce.labels methods. To assign a name and color to labels so they are shown in the back office, use the Admin.Labels.set method in JavaScript as described below.

Enable

Before using labels, you must enable them in the back office:

  1. Go to the back office in the Apps section
  2. Click Manage Apps.
  3. Click the row for the app.
  4. Select Show labels in the back office.
  5. Click Save.

Then add Admin SDK to the app HTML pages:

<script src="https://open2b.dev/admin-sdk/open2b-admin-sdk-v7.8.min.js"></script>

Methods

Admin.Labels.set(labels, function(error) { … })

Updates the name, color, and popup of the app labels.

Example:

// assigns the name 'published' to label 5
// assigns the name 'sold' and color '#FF00CC' to label 12, and specifies a popup to open when the label is clicked
Admin.Labels.set({
    5: { name: 'published' },
    12: {
        name: 'sold',
        color: 'FF00CC',
        popup: {
            handler: 'onPopupLoad', // Name of the JavaScript function to call when the dialog opens. The function will receive the resource type and identifier, and the label identifier. Must satisfy: /^[a-zA-Z_\$][a-zA-Z_\$0-9]{0,31}$/. 
            path: 'statistiche.html', // URL path of the page to open as a dialog. The path must be relative to the main app page path; if the two pages are in the same path, just specify the file name.
            width: 500, // Dialog width in pixels.
            height: 300 // Dialog height in pixels.
        }
    }
}, function(error) {
    if ( error != null ) { alert(error); return; }
    // done
});

Example:

// removes name and color from label 7 so it is not shown in the back office
Admin.Labels.set({ 7: null }, function(error) {
    if ( error != null ) { alert(error); return; }
    // done
});