cabrillo.attachments - Client

The name space for Cabrillo JS attachment functions. This enables adding and viewing attachments.

cabrillo.attachments - addFile(String tableName, String sysId, Object params, String options)

Presents a document picker and uploads the selected file.

Table 1. Parameters
Name Type Description
tableName String Table name of the record to which to attach the attachment.
sysID String The sys_id of the record to which to attach the attachment.
params Object Reserved for future use. Set to null.
options String Reserved for future use. Set to null.
Table 2. Returns
Type Description
promise If successful a Cabrillo.Attachment object. If the operation fails, an error.
var table = 'incident';
var sysID = 'a9e30c7dc61122760116894de7bcc7bd';

cabrillo.attachments.addFile(table,
    sysID, 
    null,
    null
).then(function(attachment) {
    if (attachment) {
        console.log('Added a new file.', attachment);
    } else {
        console.log('User cancelled adding an attachment.');
    }
}, function(error) {
    console.log('Failed to attach new file.', error);
});

cabrillo.attachments -viewFile(Cabrillo.Attachment attachment, Cabrillo.Rect sourceRect, String sourceBase64Image)

Presents a document picker and uploads the selected file.

Note: Scaling using a sourceRect parameter with a sourceBase64 image is only supported on iOS. Android ignores these parameters and opens the image without a scaling animation.
Table 3. Parameters
Name Type Description
attachment Cabrillo.Attachment Describes the attachment to view.
sourceRect Cabrillo.Rect Optional. Describes the source rectangle of the image to scale up.
sourceBase64Image String Optional. A base64 representation of the source image to scale up.
Table 4. Returns
Type Description
promise If successful, is undefined; otherwise an error.
// A Cabrillo.Attachment dictionary to view
var attachment = {
    sys_id: '8e99daa3ff133100ba13ffffffffff2d',
    content_type: 'image/jpeg',
    path: '8e99daa3ff133100ba13ffffffffff2d.iix'
};

cabrillo.attachments.viewFile(attachment,
    null,
    null
).then(function() {
    // It worked. Nothing to do here.
}, function(error) {
    console.log('Failed to view file.', error);
});

To scale an image that was tapped into a native image viewer, the viewFile() method accepts optional arguments for the image's rectangle on the page as well as a base64 encoded thumbnail of the image. The thumbnail is scaled into the full size image with an animation.

// Grab image metadata from an image that was tapped
var imageMetadata = imageMetadataFromEvent(event);

// Optional rect of image on page
var imageRect = imageMetadata.rect;

// Optional base64 encoded image to scale up into native viewer
var base64EncodedImage = imageMetadata.base64;

// A Cabrillo.Attachment dictionary to view
var attachment = {
    sys_id: '8e99daa3ff133100ba13ffffffffff2d',
    content_type: 'image/jpeg',
    path: '8e99daa3ff133100ba13ffffffffff2d.iix'
}

cabrillo.attachments.viewFile(attachment,
    imageRect,
    base64EncodedImage
).then(function() {
    // It worked. Nothing to do here.
}, function(error) {
    console.log('Failed to view file.', error);
});