imports/vx/client/code/ux.js
/**
     * Given an instance of VXImage, push a photo in DataURL format to the storage provide and update MongoDB
     * with the image URL.  Alternatively, remove existing image. Finally, when adding a new image, this function
     * will transform the DataURL into an actual URL, seamlessly "pointing" the thumbnail image at the uploaded image.
     *
     * @param {object} component Instance of VXImage.
     * @param {function} callback After image update callback.
     */
Given an instance of VXImage, push a photo in DataURL format to the storage provide and update MongoDB
with the image URL.  Alternatively, remove existing image. Finally, when adding a new image, this function
will transform the DataURL into an actual URL, seamlessly "pointing" the thumbnail image at the uploaded image.

@param {object} component Instance of VXImage.
@param {function} callback After image update callback.
Given an instance of VXImage push a photo in DataURL format to the storage provide and update MongoDB with the image URL . Alternatively remove existing image . Finally when adding a new image this function will transform the DataURL into an actual URL seamlessly " pointing " the thumbnail image at the uploaded image . @param { object } component Instance of VXImage . @param { function } callback After image update callback .
updateImage(component, callback) {
        const content = component.getValue()
        const formProps = UX.getFormProps(component)
        if (Util.isHttpUrl(content)) {
            OLog.debug(`ux.js updateImage HTTP URL content detected, no further action will be taken, content=${content}`)
            callback(null, { success : true, icon : "ENVELOPE", key : "common.alert_transaction_success" })
            return
        }
        OLog.debug("ux.js updateImage non-HTTP content detected, continuing")
        let $set = {}
        let dbName = component.props.dbName || component.props.id
        if (!content) {
            OLog.debug("ux.js updateImage new content is not specified, image will be removed")
            $set[dbName] = null
            UX.updateImageUrl(formProps.collection, formProps._id, $set)
            UX.fixHolder()
            callback(null, { success : true, icon : "ENVELOPE", key : "common.alert_transaction_success" })
            return
        }
        if (Util.isDataUrl(content)) {
            let filename = Util.makeImageFilename(component.props.imageType, content)
            $set[dbName] = `${CX.CLOUDFILES_PREFIX}/${filename}`
            OLog.debug(`ux.js updateImage data URL detected, user has changed image, calling putImage, $set[dbName]=${$set[dbName]}`)
            Meteor.call("putImage", filename, content, (error, result) => {
                if (!error && result && result.success) {
                    UX.updateImageUrl(formProps.collection, formProps._id, $set)
                }
                callback(error, result)
            })
        }
    }
updateImage ( component , callback ) { const content = component . getValue ( ) const formProps = UX . getFormProps ( component ) if ( Util . isHttpUrl ( content ) ) { OLog . debug ( ` ${ content } ` ) callback ( null , { success : true , icon : "ENVELOPE" , key : "common.alert_transaction_success" } ) return } OLog . debug ( "ux.js updateImage non-HTTP content detected, continuing" ) let $set = { } let dbName = component . props . dbName || component . props . id if ( ! content ) { OLog . debug ( "ux.js updateImage new content is not specified, image will be removed" ) $set [ dbName ] = null UX . updateImageUrl ( formProps . collection , formProps . _id , $set ) UX . fixHolder ( ) callback ( null , { success : true , icon : "ENVELOPE" , key : "common.alert_transaction_success" } ) return } if ( Util . isDataUrl ( content ) ) { let filename = Util . makeImageFilename ( component . props . imageType , content ) $set [ dbName ] = ` ${ CX . CLOUDFILES_PREFIX } ${ filename } ` OLog . debug ( ` ${ $set [ dbName ] } ` ) Meteor . call ( "putImage" , filename , content , ( error , result ) => { if ( ! error && result && result . success ) { UX . updateImageUrl ( formProps . collection , formProps . _id , $set ) } callback ( error , result ) } ) } }
Given an instance of VXImage, push a photo in DataURL format to the storage provide and update MongoDB
 with the image URL.
Given an instance of VXImage push a photo in DataURL format to the storage provide and update MongoDB with the image URL .
// If this is an HTTP URL something is wrong, it means that Jasny File Input has not replaced the standard URL // with a Data URL.  This may be caused by the event listener being called twice after the Data URL has already // been replaced with the permanent URL. // If there is no content, the user has likely removed an existing image: // If this is a data URL, the user has changed the image, time to update the storage system: