opnsense_ui.js 1.48 KB
Newer Older
1 2 3 4 5 6 7 8 9
/**
 * User interface shared components, requires opnsense.js for supporting functions.
 */

/**
 * save form to server
 * @param url endpoint url
 * @param formid parent id to grep input data from
 */
10
function saveFormToEndpoint(url,formid,callback_ok) {
11 12 13
    data = getFormData(formid);
    ajaxCall(url=url,sendData=data,callback=function(data,status){
        if ( status == "success") {
14 15 16
            // update field validation
            handleFormValidation(formid,data['validations']);

17 18 19 20 21 22 23
            // if there are validation issues, update our screen and show a dialog.
            if (data['validations'] != undefined) {
                BootstrapDialog.show({
                    type:BootstrapDialog.TYPE_WARNING,
                    title: 'Input validation',
                    message: 'Please correct validation errors in form'
                });
24 25 26
            } else if ( callback_ok != undefined ) {
                // execute callback function
                callback_ok();
27
            }
28

29 30 31 32 33 34 35 36 37 38 39 40 41
        } else {
            // error handling, show internal errors
            // Normally the form should only return validation issues, if other things go wrong throw an error.
            BootstrapDialog.show({
                type: BootstrapDialog.TYPE_ERROR,
                title: 'save',
                message: 'Unable to save data, an internal error occurred.<br> ' +
                'Response from server was: <br> <small>'+JSON.stringify(data)+'</small>'
            });
        }

    });

42
}