diff --git a/src/Foundation.hs b/src/Foundation.hs index 9f11f90bd..71999df4a 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -1311,6 +1311,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/src/Handler/Utils/Form/MassInput.hs b/src/Handler/Utils/Form/MassInput.hs index c91b60d20..f6a383e7c 100644 --- a/src/Handler/Utils/Form/MassInput.hs +++ b/src/Handler/Utils/Form/MassInput.hs @@ -37,6 +37,8 @@ import qualified Data.Foldable as Fold import Control.Monad.Reader.Class (MonadReader(local)) +import Text.Hamlet (hamletFile) + $(mapM tupleBoxCoord [2..4]) @@ -413,6 +415,12 @@ massInput MassInput{..} FieldSettings{..} fvRequired initialResult csrf = do MsgRenderer mr <- getMsgRenderer + whenM (hasCustomHeader HeaderMassInputShortcircuit) . liftHandlerT $ do + PageContent{..} <- widgetToPageContent $(widgetFile "widgets/massinput/massinput-standalone") + ur <- getUrlRenderParams + + sendResponse $ $(hamletFile "templates/widgets/massinput/massinput-standalone-wrapper.hamlet") ur + let fvLabel = toHtml $ mr fsLabel fvTooltip = toHtml . mr <$> fsTooltip diff --git a/src/Utils.hs b/src/Utils.hs index 5f31dfec5..9e79c33e7 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -678,7 +678,7 @@ takeSessionJson key = lookupSessionJson key <* deleteSession (toPathPiece key) -- Custom HTTP Request-Headers -- --------------------------------- -data CustomHeader = HeaderIsModal | HeaderDBTableShortcircuit +data CustomHeader = HeaderIsModal | HeaderDBTableShortcircuit | HeaderMassInputShortcircuit deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic) instance Universe CustomHeader diff --git a/static/js/utils/massInput.js b/static/js/utils/massInput.js new file mode 100644 index 000000000..fa8e075bf --- /dev/null +++ b/static/js/utils/massInput.js @@ -0,0 +1,193 @@ +(function() { + 'use strict'; + + /** + * + * Mass Input Utility + * allows form shapes to be manipulated asynchronously: + * will asynchronously submit the containing form and replace the contents + * of the mass input element with the one from the BE response + * The utility will only trigger an AJAX request if the mass input element has + * an active/focused element whilst the form is being submitted. + * + * Attribute: uw-mass-input + * + * Example usage: + *