imports/vx/client/code/vxapp.js
/**
     * This function provides update service a special type of data structure, where the user
     * experience is a list of rows with checkboxes, but the internal database format is an array
     * of codes that map to the "checked" rows. This type of data structure saves space and is more
     * concise in cases where there are many potential rows, but only a tiny subset are checked.
     *
     * @param {array} codeArray Invariant array of codes typically from codes.js.
     * @param {object} collection Collection to be updated.
     * @param {object} record Record to be updated.
     * @param {string} rowsPath Path to array within record.
     * @param {string} rowId Name of the property that uniquely identifies the row.
     * @param {string} checkboxdbName Name of the checkbox property that controls whether the element exists.
     * @param {object} component Component that has been updated.
     * @param {?} value Value that has been updated.
     * @param {string} componentRowId Optional component row ID.
     */
This function provides update service a special type of data structure, where the user
experience is a list of rows with checkboxes, but the internal database format is an array
of codes that map to the "checked" rows. This type of data structure saves space and is more
concise in cases where there are many potential rows, but only a tiny subset are checked.

@param {array} codeArray Invariant array of codes typically from codes.js.
@param {object} collection Collection to be updated.
@param {object} record Record to be updated.
@param {string} rowsPath Path to array within record.
@param {string} rowId Name of the property that uniquely identifies the row.
@param {string} checkboxdbName Name of the checkbox property that controls whether the element exists.
@param {object} component Component that has been updated.
@param {?} value Value that has been updated.
@param {string} componentRowId Optional component row ID.
This function provides update service a special type of data structure where the user experience is a list of rows with checkboxes but the internal database format is an array of codes that map to the " checked " rows . This type of data structure saves space and is more concise in cases where there are many potential rows but only a tiny subset are checked . @param { array } codeArray Invariant array of codes typically from codes . js . @param { object } collection Collection to be updated . @param { object } record Record to be updated . @param { string } rowsPath Path to array within record . @param { string } rowId Name of the property that uniquely identifies the row . @param { string } checkboxdbName Name of the checkbox property that controls whether the element exists . @param { object } component Component that has been updated . @param { ? } value Value that has been updated . @param { string } componentRowId Optional component row ID .
updateCodeArray(codeArray, collection, record, rowsPath, rowId, checkboxdbName, component, value, componentRowId) {
        try {
            if (!componentRowId) {
                const $item = $(`#${component.props.id}`).closest(".list-group-item")
                componentRowId = $item.attr("data-item-id")
                if (!componentRowId) {
                    OLog.error(`vxapp.js updateCodeArray recordId=${record._id} componentId=${component.props.id} ` +
                        `rowsPath=${rowsPath} componentRowId=${componentRowId}`)
                    return
                }
            }
            const rebuiltArray = []
            codeArray.forEach(code => {
                let element = _.find(get(record, rowsPath), element => {
                    return element[rowId] === code
                })
                if (componentRowId === code) {
                    if (component.props.dbName === checkboxdbName && !value) {
                        return
                    }
                    if (!element) {
                        element = {}
                        element[rowId] = code
                    }
                    set(element, component.props.dbName, value)
                }
                if (element) {
                    rebuiltArray.push(element)
                }
            })
            const mongoPath = Util.toMongoPath(rowsPath)
            const modifier = {}
            modifier.$set = {}
            modifier.$set[mongoPath] = rebuiltArray
            OLog.debug(`vxapp.js updateCodeArray recordId=${record._id} componentId=${component.props.id} ` +
                `rowsPath=${rowsPath} componentRowId=${componentRowId} modifier=${OLog.debugString(modifier)}`)
            collection.update(record._id, modifier)
            OLog.debug(`vxapp.js updateCodeArray recordId=${record._id} *success*`)
        }
        catch (error) {
            UX.notifyForError(error)
        }
    }
updateCodeArray ( codeArray , collection , record , rowsPath , rowId , checkboxdbName , component , value , componentRowId ) { try { if ( ! componentRowId ) { const $item = $ ( ` ${ component . props . id } ` ) . closest ( ".list-group-item" ) componentRowId = $item . attr ( "data-item-id" ) if ( ! componentRowId ) { OLog . error ( ` ${ record . _id } ${ component . props . id } ` + ` ${ rowsPath } ${ componentRowId } ` ) return } } const rebuiltArray = [ ] codeArray . forEach ( code => { let element = _ . find ( get ( record , rowsPath ) , element => { return element [ rowId ] === code } ) if ( componentRowId === code ) { if ( component . props . dbName === checkboxdbName && ! value ) { return } if ( ! element ) { element = { } element [ rowId ] = code } set ( element , component . props . dbName , value ) } if ( element ) { rebuiltArray . push ( element ) } } ) const mongoPath = Util . toMongoPath ( rowsPath ) const modifier = { } modifier . $set = { } modifier . $set [ mongoPath ] = rebuiltArray OLog . debug ( ` ${ record . _id } ${ component . props . id } ` + ` ${ rowsPath } ${ componentRowId } ${ OLog . debugString ( modifier ) } ` ) collection . update ( record . _id , modifier ) OLog . debug ( ` ${ record . _id } ` ) } catch ( error ) { UX . notifyForError ( error ) } }
This function provides update service a special type of data structure, where the user
 experience is a list of rows with checkboxes, but the internal database format is an array
 of codes that map to the "checked" rows.
This function provides update service a special type of data structure where the user experience is a list of rows with checkboxes but the internal database format is an array of codes that map to the " checked " rows .