From e83c88b8797853952ba0ca830e165b0dc2aa1ca5 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 9 Mar 2015 14:27:23 +0100 Subject: [PATCH] add extra javascript file for user interface functions --- src/opnsense/www/js/opnsense_ui.js | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/opnsense/www/js/opnsense_ui.js diff --git a/src/opnsense/www/js/opnsense_ui.js b/src/opnsense/www/js/opnsense_ui.js new file mode 100644 index 000000000..908a17ca2 --- /dev/null +++ b/src/opnsense/www/js/opnsense_ui.js @@ -0,0 +1,37 @@ +/** + * 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 + */ +function saveFormToEndpoint(url,formid) { + data = getFormData(formid); + ajaxCall(url=url,sendData=data,callback=function(data,status){ + if ( status == "success") { + // if there are validation issues, update our screen and show a dialog. + if (data['validations'] != undefined) { + // update field validation + handleFormValidation(formid,data['validations']); + BootstrapDialog.show({ + type:BootstrapDialog.TYPE_WARNING, + title: 'Input validation', + message: 'Please correct validation errors in form' + }); + } + } 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.
' + + 'Response from server was:
'+JSON.stringify(data)+'' + }); + } + + }); + +} \ No newline at end of file