diff --git a/src/Foundation.hs b/src/Foundation.hs index 46e176a19..a05a45558 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -1175,6 +1175,7 @@ siteLayout' headingOverride widget = do addScript $ StaticR js_utils_checkAll_js addScript $ StaticR js_utils_form_js addScript $ StaticR js_utils_inputs_js + addScript $ StaticR js_utils_massInput_js addScript $ StaticR js_utils_modal_js addScript $ StaticR js_utils_showHide_js -- addScript $ StaticR js_utils_tabber_js diff --git a/static/js/utils/massInput.js b/static/js/utils/massInput.js new file mode 100644 index 000000000..7b58bb625 --- /dev/null +++ b/static/js/utils/massInput.js @@ -0,0 +1,127 @@ +(function() { + 'use strict'; + + /** + * + * Mass Input Utility + * allows form shapes to be manipulated asynchronously: + * will asynchronously submit the form and replace the contents of the + * mass input with the one from the BE response + * + * Attribute: uw-mass-input + * (will be set up automatically on tables) + * + * Example usage: + * (table with one column thats only checkboxes) + */ + + var MASS_INPUT_UTIL_NAME = 'massInput'; + var MASS_INPUT_UTIL_SELECTOR = '[uw-mass-input]'; + + var MASS_INPUT_INITIALIZED_CLASS = 'mass-input--initialized'; + + var massInputUtil = function(element) { + var massInputId; + var massInputFormSubmitHandler; + var massInputForm; + + function init() { + if (!element) { + throw new Error('Mass Input utility cannot be setup without an element!'); + } + + massInputId = element.id; + massInputForm = element.closest('form'); + + if (!massInputForm) { + throw new Error('Mass Input utility cannot be setup without being wrapped in a