Jam.py documentation

selections

selections

domain: client

language: javascript

class Item class

Description

The selections attribute stores a list of a primary key field values.

When a Multiple selection check box is checked on the Layout tab in the View Form Dialog or multiselect attribute of the table_options is set programmatically, the check box in the leftmost column of the table appears and each time a user clicks on the check box, the selections attrubute changes.

It can also be changed programmatically by using add or remove methods or assigning an array.

Example

In this example, the send_email function, on the client, uses Customers selection attribute to get array of primary key field values selected by users and send them to the send_email function defined in the server module of the item using the server method

function send_email(subject, message) {
    var selected = task.customers.selections;
    if (!selected.length) {
        selected.add(task.customers.id.value);
    }

    item.server('send_email', [selected, subject, message],
        function(result, err) {
            if (err) {
                item.alert('Failed to send the mail: ' + err);
            }
            else {
                item.alert('Successfully sent the mail');
            }
        }
    );
}

On the server, this array is used to retrieve information about selected customers using open method

import smtplib

def send_email(item, selected, subject, mess):
    cust = item.task.customers.copy()
    cust.set_where(id__in=selected)
    cust.open()
    to = []
    for c in cust:
        to.append(c.email.value)

    # code that sends email