build/tincan.js
function (stmt, cfg) {
            this.log("saveStatement");
            var requestCfg = {
                    url: "statements",
                    headers: {}
                },
                versionedStatement,
                requestAttachments = [],
                boundary,
                i;

            cfg = cfg || {};

            try {
                versionedStatement = stmt.asVersion( this.version );
            }
            catch (ex) {
                if (this.allowFail) {
                    this.log("[warning] statement could not be serialized in version (" + this.version + "): " + ex);
                    if (typeof cfg.callback !== "undefined") {
                        cfg.callback(null, null);
                        return;
                    }
                    return {
                        err: null,
                        xhr: null
                    };
                }

                this.log("[error] statement could not be serialized in version (" + this.version + "): " + ex);
                if (typeof cfg.callback !== "undefined") {
                    cfg.callback(ex, null);
                    return;
                }
                return {
                    err: ex,
                    xhr: null
                };
            }

            if (versionedStatement.hasOwnProperty("attachments") && stmt.hasAttachmentWithContent()) {
                boundary = this._getBoundary();

                requestCfg.headers["Content-Type"] = "multipart/mixed; boundary=" + boundary;

                for (i = 0; i < stmt.attachments.length; i += 1) {
                    if (stmt.attachments[i].content !== null) {
                        requestAttachments.push(stmt.attachments[i]);
                    }
                }

                try {
                    requestCfg.data = this._getMultipartRequestData(boundary, versionedStatement, requestAttachments);
                }
                catch (ex) {
                    if (this.allowFail) {
                        this.log("[warning] multipart request data could not be created (attachments probably not supported): " + ex);
                        if (typeof cfg.callback !== "undefined") {
                            cfg.callback(null, null);
                            return;
                        }
                        return {
                            err: null,
                            xhr: null
                        };
                    }

                    this.log("[error] multipart request data could not be created (attachments probably not supported): " + ex);
                    if (typeof cfg.callback !== "undefined") {
                        cfg.callback(ex, null);
                        return;
                    }
                    return {
                        err: ex,
                        xhr: null
                    };
                }
            }
            else {
                requestCfg.headers["Content-Type"] = "application/json";
                requestCfg.data = JSON.stringify(versionedStatement);
            }
            if (stmt.id !== null) {
                requestCfg.method = "PUT";
                requestCfg.params = {
                    statementId: stmt.id
                };
            }
            else {
                requestCfg.method = "POST";
            }

            if (typeof cfg.callback !== "undefined") {
                requestCfg.callback = cfg.callback;
            }

            return this.sendRequest(requestCfg);
        }
function (stmt, cfg) {
            this.log("saveStatement");
            var requestCfg = {
                    url: "statements",
                    headers: {}
                },
                versionedStatement,
                requestAttachments = [],
                boundary,
                i;

            cfg = cfg || {};

            try {
                versionedStatement = stmt.asVersion( this.version );
            }
            catch (ex) {
                if (this.allowFail) {
                    this.log("[warning] statement could not be serialized in version (" + this.version + "): " + ex);
                    if (typeof cfg.callback !== "undefined") {
                        cfg.callback(null, null);
                        return;
                    }
                    return {
                        err: null,
                        xhr: null
                    };
                }

                this.log("[error] statement could not be serialized in version (" + this.version + "): " + ex);
                if (typeof cfg.callback !== "undefined") {
                    cfg.callback(ex, null);
                    return;
                }
                return {
                    err: ex,
                    xhr: null
                };
            }

            if (versionedStatement.hasOwnProperty("attachments") && stmt.hasAttachmentWithContent()) {
                boundary = this._getBoundary();

                requestCfg.headers["Content-Type"] = "multipart/mixed; boundary=" + boundary;

                for (i = 0; i < stmt.attachments.length; i += 1) {
                    if (stmt.attachments[i].content !== null) {
                        requestAttachments.push(stmt.attachments[i]);
                    }
                }

                try {
                    requestCfg.data = this._getMultipartRequestData(boundary, versionedStatement, requestAttachments);
                }
                catch (ex) {
                    if (this.allowFail) {
                        this.log("[warning] multipart request data could not be created (attachments probably not supported): " + ex);
                        if (typeof cfg.callback !== "undefined") {
                            cfg.callback(null, null);
                            return;
                        }
                        return {
                            err: null,
                            xhr: null
                        };
                    }

                    this.log("[error] multipart request data could not be created (attachments probably not supported): " + ex);
                    if (typeof cfg.callback !== "undefined") {
                        cfg.callback(ex, null);
                        return;
                    }
                    return {
                        err: ex,
                        xhr: null
                    };
                }
            }
            else {
                requestCfg.headers["Content-Type"] = "application/json";
                requestCfg.data = JSON.stringify(versionedStatement);
            }
            if (stmt.id !== null) {
                requestCfg.method = "PUT";
                requestCfg.params = {
                    statementId: stmt.id
                };
            }
            else {
                requestCfg.method = "POST";
            }

            if (typeof cfg.callback !== "undefined") {
                requestCfg.callback = cfg.callback;
            }

            return this.sendRequest(requestCfg);
        }
function ( stmt , cfg ) { this . log ( "saveStatement" ) ; var requestCfg = { url : "statements" , headers : { } } , versionedStatement , requestAttachments = [ ] , boundary , i ; cfg = cfg || { } ; try { versionedStatement = stmt . asVersion ( this . version ) ; } catch ( ex ) { if ( this . allowFail ) { this . log ( "[warning] statement could not be serialized in version (" + this . version + "): " + ex ) ; if ( typeof cfg . callback !== "undefined" ) { cfg . callback ( null , null ) ; return ; } return { err : null , xhr : null } ; } this . log ( "[error] statement could not be serialized in version (" + this . version + "): " + ex ) ; if ( typeof cfg . callback !== "undefined" ) { cfg . callback ( ex , null ) ; return ; } return { err : ex , xhr : null } ; } if ( versionedStatement . hasOwnProperty ( "attachments" ) && stmt . hasAttachmentWithContent ( ) ) { boundary = this . _getBoundary ( ) ; requestCfg . headers [ "Content-Type" ] = "multipart/mixed; boundary=" + boundary ; for ( i = 0 ; i < stmt . attachments . length ; i += 1 ) { if ( stmt . attachments [ i ] . content !== null ) { requestAttachments . push ( stmt . attachments [ i ] ) ; } } try { requestCfg . data = this . _getMultipartRequestData ( boundary , versionedStatement , requestAttachments ) ; } catch ( ex ) { if ( this . allowFail ) { this . log ( "[warning] multipart request data could not be created (attachments probably not supported): " + ex ) ; if ( typeof cfg . callback !== "undefined" ) { cfg . callback ( null , null ) ; return ; } return { err : null , xhr : null } ; } this . log ( "[error] multipart request data could not be created (attachments probably not supported): " + ex ) ; if ( typeof cfg . callback !== "undefined" ) { cfg . callback ( ex , null ) ; return ; } return { err : ex , xhr : null } ; } } else { requestCfg . headers [ "Content-Type" ] = "application/json" ; requestCfg . data = JSON . stringify ( versionedStatement ) ; } if ( stmt . id !== null ) { requestCfg . method = "PUT" ; requestCfg . params = { statementId : stmt . id } ; } else { requestCfg . method = "POST" ; } if ( typeof cfg . callback !== "undefined" ) { requestCfg . callback = cfg . callback ; } return this . sendRequest ( requestCfg ) ; }
Save a statement, when used from a browser sends to the endpoint using the RESTful interface.
Use a callback to make the call asynchronous.

@method saveStatement
@param {TinCan.Statement} statement to send
@param {Object} [cfg] Configuration used when saving
@param {Function} [cfg.callback] Callback to execute on completion
Save a statement when used from a browser sends to the endpoint using the RESTful interface . Use a callback to make the call asynchronous .