JavaScript

{dialog.object}submitListDataAndMediaFiles Method

Syntax

{dialog.object}.submitListDataAndMediaFiles(listName, XbasicFunctionName [, ajaxObject [, objUpload]]);

Arguments

listNamestring

Name of List to submit.

XbasicFunctionNamestring

Name of Xbasic function to call once data has been uploaded to the server. List data submitted to the server is in the e object. I.e. e._listData

ajaxObjectJSON Object

Defines properties for the Ajax callback that is made to the server. Allows you to define handlers for various conditions such as 'deviceOffline', 'ajax callback error', etc. See example below.

objUploadJSON Object

Defines settings for the where the media files are to be uploaded. See example below.

Description

Submit edited rows in a List to a server, but first upload media files to the Alpha Anywhere server or to Amazon S3.

Discussion

This is a very advanced method intended for users who want to write their own code to process data that was edited in a List.

The method submits the dirty rows in the List to the server and then calls the specified Xbasic function to process the submitted data.

However, and most importantly, before the data in the List are submitted to the server, the media files (images, videos and audio files) in the dirty List rows are first uploaded to a target server ( either the Alpha server, or Amazon S3). If there are errors in uploading any of the media files, the List row with the error is not submitted to the server.

Creating the ajaxObject Parameter 

Here is an example for the ajaxObject parameter:

var ajaxObject = {
    errorFunction: function() { alert('failed ajax'); },
    onComplete: function() { alert('ajax done');},
    deviceOfflineFunction: function() { alert('offline '); }
}

Creating the objUpload Parameter for Alpha Anywhere Server 

Here is an example for the objUpload parameter defining settings for uploading the media files to the Alpha Anywhere server:

var objUpload = {
    target: 'alphaanywhere',
    showProgress: true,
    onComplete: function(array) {},
    onMediaUploadErrors: function(array) {

            alert('there were media upload errors');

    },
    xbasicAfterFileUploaded: 'xbAfterUpload',
    progress: {
        color: '#9fa1e8',
        width: '300px',
        individualProgress: false,
        showTotalProgress: true,
        allowCancel: false,
        progressElement: '{dialog.componentname}.V.R1.PLACEHOLDER_1'
    }
}

Creating objUpload Parameter for Amazon S3 

Here is an example for the objUpload parameter defining settings for uploading the media files to Amazon S3:

var objUpload = {
    target: 's3',

    s3: {
        connectionString: 'alphamediacapture',
        protectedRead: false,
        template: 'https://alphamediacapture.s3.amazonaws.com/__name__'
    },
    showProgress: true,
    onComplete: function(array) {},
    onMediaUploadErrors: function(array) {

            alert('there were media upload errors');

    },
    progress: {
        color: '#9fa1e8',
        width: '300px',
        individualProgress: false,
        showTotalProgress: true,
        allowCancel: false,
        progressElement: '{dialog.componentname}.V.R1.PLACEHOLDER_1'
    }
}

Example: Uploading to Alpha Anywhere Server 

In this example, the media files are being uploaded to the Alpha Anywhere server and after each media file has been uploaded, the Xbasic function specified by the xbasicAfterFileUploaded property is called to persist the uploaded file to the target location on the Alpha server. In the above example, the Xbasic function is called 'xbAfterUpload'

Here is an example Xbasic function for the xbasicAfterFileUploaded handler:

function xbAfterUpload as v (e as p)

    dim extension as c
    extension = file.filename_parse(e.fileInfo.fileName,"e")

    dim targetFileName as c
    dir_create_recurse("c:\mydata")
    targetFileName = "c:\mydata" + chr(92) + e.fileInfo.FileName
    Request.variables.file.SaveToFile(targetFileName)

    'THIS NEXT LINE IS CRITICALLY IMPORTANT --
    'IT UPDATES THE 'ARRAY' WITH THE DIRTY RECORDS FROM THE LIST
    'WITH THE FILENAMES OF THE MEDIA FILES ON THE ALPHA SERVER.

    e.javascript = "array[" + e.arrayIndex + "].targetFileName = '" + 
    js_escape(targetFilename) + "';"

end function

See Also