{\r\n\r\n return this.props.ErrorMessage.length!==0 ? (\r\n \r\n \r\n
\r\n ) : ();\r\n }\r\n}\r\n","\"use strict\";\r\n//******************************************************************************\r\n// Copyright 2018-2020, ShareSquared Inc., All Rights Reserved.\r\n//\r\n// Author: Ted Iverson\r\n// Created: 08/21/2020\r\n//\r\n// The contents of this file are proprietary and considered trade secret.\r\n// Any disclosure outside of its intended use is expressly prohibited.\r\n//******************************************************************************\r\nvar __extends = (this && this.__extends) || (function () {\r\n var extendStatics = function (d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n };\r\n return function (d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n };\r\n})();\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\n//#region Imports\r\nvar React = require(\"react\");\r\nrequire(\"jquery/src/jquery\");\r\nvar Label_1 = require(\"@fluentui/react/lib/Label\");\r\nvar Button_1 = require(\"@fluentui/react/lib/Button\");\r\nvar DatePicker_1 = require(\"@fluentui/react/lib/DatePicker\");\r\nvar TextField_1 = require(\"@fluentui/react/lib/TextField\");\r\nvar Dropdown_1 = require(\"@fluentui/react/lib/Dropdown\");\r\nvar react_bootstrap_1 = require(\"react-bootstrap\");\r\nvar Spinner_1 = require(\"@fluentui/react/lib/Spinner\");\r\nvar react_1 = require(\"@fluentui/react\");\r\nvar RequestForm = /** @class */ (function (_super) {\r\n __extends(RequestForm, _super);\r\n function RequestForm(props, state) {\r\n var _this = _super.call(this, props, state) || this;\r\n // tracks the properties of each field on the form so we can have the information\r\n // during the building of the query (mainly Type and Mapped Property)\r\n _this.formFieldProps = new Map();\r\n _this.state = { FormValues: {}, InvalidControlIds: new Map(), Processing: false, Submitted: false };\r\n return _this;\r\n }\r\n RequestForm.prototype.renderField = function (field, idx) {\r\n var _this = this;\r\n var f;\r\n switch (field.fieldType.toLowerCase()) {\r\n default:\r\n case \"text\": {\r\n var id_1 = \"ftxt_\" + idx;\r\n this.formFieldProps.set(id_1, { Id: id_1, Type: field.fieldType, PropertyName: field.property, });\r\n f = (React.createElement(TextField_1.TextField, { id: id_1, key: id_1, label: field.label, required: field.required, className: \"S2Input S2TextField\", value: this.state.FormValues[id_1], onChange: function (evt, v) {\r\n if (v !== undefined) {\r\n var o = _this.state.FormValues;\r\n o[id_1] = v;\r\n _this.setState({ FormValues: o, Submitted: false });\r\n }\r\n }, onGetErrorMessage: function (value) {\r\n return field.required ? _this.validateRequired(id_1, value) : undefined;\r\n } }));\r\n break;\r\n }\r\n case \"multitext\": {\r\n var id_2 = \"fmtxt_\" + idx;\r\n this.formFieldProps.set(id_2, { Id: id_2, Type: field.fieldType, PropertyName: field.property, });\r\n f = (React.createElement(TextField_1.TextField, { id: id_2, key: id_2, label: field.label, className: \"S2Input S2TextField\", multiline: true, resizable: true, required: field.required, value: this.state.FormValues[id_2], onChange: function (evt, v) {\r\n if (v !== undefined) {\r\n var o = _this.state.FormValues;\r\n o[id_2] = v;\r\n _this.setState({ FormValues: o, Submitted: false });\r\n }\r\n }, onGetErrorMessage: function (value) {\r\n return field.required ? _this.validateRequired(id_2, value) : undefined;\r\n } }));\r\n break;\r\n }\r\n case \"widemultitext\": {\r\n var id_3 = \"fmtxt_\" + idx;\r\n this.formFieldProps.set(id_3, { Id: id_3, Type: field.fieldType, PropertyName: field.property, });\r\n f = (React.createElement(TextField_1.TextField, { id: id_3, key: id_3, label: field.label, className: \"S2Input S2TextField\", multiline: true, rows: 10, resizable: true, required: field.required, value: this.state.FormValues[id_3], onChange: function (evt, v) {\r\n if (v !== undefined) {\r\n var o = _this.state.FormValues;\r\n o[id_3] = v;\r\n _this.setState({ FormValues: o, Submitted: false });\r\n }\r\n }, onGetErrorMessage: function (value) {\r\n return field.required ? _this.validateRequired(id_3, value) : undefined;\r\n } }));\r\n break;\r\n }\r\n case \"date\": {\r\n var id1_1 = \"fdt_\" + idx;\r\n this.formFieldProps.set(id1_1, { Id: id1_1, Type: field.fieldType, PropertyName: field.property });\r\n f = (React.createElement(\"span\", { key: \"spandt_\" + idx },\r\n React.createElement(DatePicker_1.DatePicker, { id: id1_1, key: id1_1, label: field.label, isRequired: field.required, className: \"S2Input S2DateField\", title: \"on or after\", placeholder: \"on or after\", value: this.state.FormValues[id1_1], onSelectDate: function (dt) {\r\n if (dt !== undefined && dt !== null) {\r\n var o = _this.state.FormValues;\r\n o[id1_1] = dt;\r\n _this.setState({ FormValues: o, Submitted: false });\r\n }\r\n } })));\r\n break;\r\n }\r\n case \"number\": {\r\n var id_4 = \"fnum_\" + idx;\r\n this.formFieldProps.set(id_4, { Id: id_4, Type: field.fieldType, PropertyName: field.property });\r\n f = (React.createElement(\"span\", { key: \"spannum_\" + idx },\r\n React.createElement(TextField_1.TextField, { id: id_4, key: id_4, label: field.label, className: \"S2Input S2NumberField\", required: field.required, title: \"equal to or greater\", placeholder: \"equal to or greater\", value: this.state.FormValues[id_4], onChange: function (evt, v) {\r\n if (v !== undefined) {\r\n var o = _this.state.FormValues;\r\n o[id_4] = v;\r\n _this.setState({ FormValues: o, Submitted: false });\r\n }\r\n }, onGetErrorMessage: function (value) {\r\n return field.required ? _this.validateRequired(id_4, value) : undefined;\r\n } })));\r\n break;\r\n }\r\n case \"boolean\": {\r\n var id_5 = \"fbool_\" + idx;\r\n this.formFieldProps.set(id_5, { Id: id_5, Type: field.fieldType, PropertyName: field.property });\r\n f = (React.createElement(Dropdown_1.Dropdown, { id: id_5, key: id_5, label: field.label, className: \"S2Input S2BooleanField\", options: [\r\n { key: '', text: '' },\r\n { key: '1', text: 'Yes' },\r\n { key: '0', text: 'No' }\r\n ], selectedKey: this.state.FormValues[id_5], onChange: function (evt, v) {\r\n if (v !== undefined) {\r\n var o = _this.state.FormValues;\r\n o[id_5] = v.key;\r\n _this.setState({ FormValues: o, Submitted: false });\r\n }\r\n } }));\r\n break;\r\n }\r\n case \"list\": {\r\n var id_6 = \"flst_\" + idx;\r\n this.formFieldProps.set(id_6, { Id: id_6, Type: field.fieldType, PropertyName: field.property });\r\n f = (React.createElement(Dropdown_1.Dropdown, { id: id_6, key: id_6, className: \"S2Input S2ListField\", placeholder: \"Select option(s)\", label: field.label, multiSelect: true, required: field.required, options: field.options.map(function (o) {\r\n return { key: o, text: o };\r\n }), selectedKeys: this.state.FormValues[id_6] !== undefined ? this.state.FormValues[id_6].split(\";\") : [], onChange: function (evt, v) {\r\n var curOptions = _this.state.FormValues[id_6] !== undefined ? _this.state.FormValues[id_6].split(\";\") : [];\r\n var foundIndex = curOptions.indexOf(v === null || v === void 0 ? void 0 : v.key);\r\n if ((v === null || v === void 0 ? void 0 : v.selected) && foundIndex === -1)\r\n curOptions.push(v === null || v === void 0 ? void 0 : v.key);\r\n if (!(v === null || v === void 0 ? void 0 : v.selected) && foundIndex !== -1)\r\n curOptions.splice(foundIndex, 1);\r\n var o = _this.state.FormValues;\r\n o[id_6] = curOptions.join(\";\");\r\n _this.setState({ FormValues: o, Submitted: false });\r\n } }));\r\n break;\r\n }\r\n }\r\n return f;\r\n };\r\n RequestForm.prototype.renderCol = function (fields, rowsPerCol, colNumber) {\r\n var _this = this;\r\n return (React.createElement(react_bootstrap_1.Col, { key: \"col_\" + colNumber, lg: \"4\" }, fields.map(function (f, idx) {\r\n return _this.renderField(f, (idx + 1) + (colNumber * rowsPerCol));\r\n })));\r\n };\r\n RequestForm.prototype.renderWideCol = function (fields, rowsPerCol, colNumber) {\r\n var _this = this;\r\n return (React.createElement(react_bootstrap_1.Col, { key: \"col_\" + colNumber, lg: \"12\" }, fields.map(function (f, idx) {\r\n return _this.renderField(f, (idx + 1) + (colNumber * rowsPerCol));\r\n })));\r\n };\r\n RequestForm.prototype.renderFormRowsx = function () {\r\n var template = this.props.Template;\r\n // split the fields across the 3 columns and render\r\n var RowsPerCol = Math.ceil(template.requestForm.fields.length / 3);\r\n var rows = [];\r\n rows.push(this.renderCol(template.requestForm.fields.slice(0, RowsPerCol), RowsPerCol, 0));\r\n rows.push(this.renderCol(template.requestForm.fields.slice(RowsPerCol, (RowsPerCol * 2)), RowsPerCol, 1));\r\n rows.push(this.renderCol(template.requestForm.fields.slice(RowsPerCol * 2), RowsPerCol, 2));\r\n return (React.createElement(react_bootstrap_1.Row, null, rows));\r\n };\r\n RequestForm.prototype.renderFormRows = function () {\r\n var template = this.props.Template;\r\n // filter out fields that have a value supplied as they won't be\r\n // presented to the user on the form\r\n var formFields = template.requestForm.fields.filter(function (f) {\r\n return (f.value === undefined || f.value === null || f.value.length === 0) ? f : null;\r\n });\r\n // process all non-wide fields first and spread across columns\r\n var nonWideFields = formFields.filter(function (f) {\r\n return f.fieldType.toLowerCase() !== \"widemultitext\" ? f : null;\r\n });\r\n // split the fields across the 3 columns and render\r\n var RowsPerCol = Math.ceil(nonWideFields.length / 3);\r\n var rows = [];\r\n rows.push(this.renderCol(nonWideFields.slice(0, RowsPerCol), RowsPerCol, 0));\r\n rows.push(this.renderCol(nonWideFields.slice(RowsPerCol, (RowsPerCol * 2)), RowsPerCol, 1));\r\n rows.push(this.renderCol(nonWideFields.slice(RowsPerCol * 2), RowsPerCol, 2));\r\n // process all wide fields last\r\n var wideFields = formFields.filter(function (f) {\r\n return f.fieldType.toLowerCase() === \"widemultitext\" ? f : null;\r\n });\r\n rows.push(this.renderWideCol(wideFields, 1, 0));\r\n return (React.createElement(react_bootstrap_1.Row, null, rows));\r\n };\r\n RequestForm.prototype.render = function () {\r\n var _this = this;\r\n return (React.createElement(\"div\", { className: \"S2RequestForm\", hidden: !this.props.IsVisible },\r\n React.createElement(react_bootstrap_1.Container, null,\r\n React.createElement(react_bootstrap_1.Row, null,\r\n React.createElement(react_bootstrap_1.Col, { lg: \"9\" },\r\n React.createElement(Label_1.Label, { className: \"S2RequestLabel\" }, this.props.GlobalSettings.manualRequestTitle)),\r\n React.createElement(react_bootstrap_1.Col, { lg: \"3\" },\r\n React.createElement(\"span\", { className: \"S2Buttons\" },\r\n React.createElement(Spinner_1.Spinner, { size: Spinner_1.SpinnerSize.small, hidden: !this.state.Processing }),\r\n React.createElement(Button_1.PrimaryButton, { className: \"S2RequestButton\", text: \"Submit\", hidden: this.state.Processing, disabled: this.state.InvalidControlIds.size !== 0, onClick: function () { _this.requestClicked(); } }),\r\n React.createElement(Button_1.DefaultButton, { className: \"S2ClearButton\", text: \"Cancel\", onClick: function () { _this.clearClicked(); } })))),\r\n React.createElement(react_bootstrap_1.Row, { hidden: this.state.Processing || !this.state.Submitted },\r\n React.createElement(react_bootstrap_1.Col, { lg: \"12\" },\r\n React.createElement(react_1.MessageBar, { onDismiss: function () {\r\n _this.clearClicked();\r\n }, messageBarType: react_1.MessageBarType.success }, this.props.GlobalSettings.submitSuccess))),\r\n React.createElement(react_bootstrap_1.Row, null,\r\n React.createElement(react_bootstrap_1.Col, { lg: \"12\" },\r\n React.createElement(\"span\", { className: \"S2RequestDescription\" }, this.props.GlobalSettings.manualRequestDescription))),\r\n (this.props.Template !== null) ? this.renderFormRows() : null)));\r\n };\r\n RequestForm.prototype.validateRequired = function (id, value) {\r\n var notValid = value === undefined || value.length === 0;\r\n if (!notValid && this.state.InvalidControlIds.has(id)) {\r\n var i = this.state.InvalidControlIds;\r\n this.state.InvalidControlIds.delete(id);\r\n this.setState({ InvalidControlIds: i });\r\n }\r\n else if (notValid && !this.state.InvalidControlIds.has(id)) {\r\n var i = this.state.InvalidControlIds;\r\n this.state.InvalidControlIds.set(id, true);\r\n this.setState({ InvalidControlIds: i });\r\n }\r\n //this.setState({ Submitted: false });\r\n return notValid ? (React.createElement(\"span\", { style: { display: \"none\" } })) : undefined;\r\n };\r\n RequestForm.prototype.setErrorMessage = function (message) {\r\n if (this.props.OnError)\r\n this.props.OnError(message);\r\n };\r\n RequestForm.prototype.buildJSONForRequest = function () {\r\n var _this = this;\r\n var props = {\r\n Query: this.props.Query\r\n };\r\n // set the fixed submission values\r\n this.props.Template.requestForm.fields.forEach(function (f) {\r\n if (f.value !== undefined && f.value !== null && f.value.length !== 0) {\r\n props[f.property] = f.value;\r\n }\r\n });\r\n this.formFieldProps.forEach(function (f) {\r\n var value = _this.state.FormValues[f.Id];\r\n if (value !== undefined && value !== null && value.length !== 0) {\r\n switch (f.Type.toLowerCase()) {\r\n default:\r\n case \"text\": {\r\n props[f.PropertyName] = value;\r\n break;\r\n }\r\n case \"date\": {\r\n var dt = new Date(Date.parse(value));\r\n props[f.PropertyName] = \"\" + dt.getFullYear() + \"-\" + _this.zeroPad(dt.getMonth() + 1) + \"-\" + _this.zeroPad(dt.getDate());\r\n break;\r\n }\r\n case \"number\": {\r\n props[f.PropertyName] = value;\r\n break;\r\n }\r\n case \"boolean\": {\r\n props[f.PropertyName] = value;\r\n break;\r\n }\r\n case \"list\": {\r\n var listprops = [];\r\n // NOTE: lists are multi-select and are handled implicitly by\r\n // SharePoint search as ORs\r\n value.split(\";\").forEach(function (v, idx) {\r\n if (v.length !== 0) {\r\n listprops.push(v);\r\n }\r\n });\r\n props[f.PropertyName] = listprops;\r\n break;\r\n }\r\n }\r\n }\r\n });\r\n //console.log(`props: ${JSON.stringify(props)}`);\r\n return JSON.stringify(props);\r\n };\r\n RequestForm.prototype.zeroPad = function (num) {\r\n var s = '';\r\n if (num < 10) {\r\n s = '0';\r\n }\r\n s += num.toString();\r\n return s;\r\n };\r\n RequestForm.prototype.requestClicked = function () {\r\n var _this = this;\r\n this.setState({ Processing: true });\r\n fetch((window.location.pathname === \"/\" ? \"\" : window.location.pathname) + \"/api/manualrequest\", {\r\n method: \"POST\",\r\n headers: {\r\n 'Content-Type': 'application/json'\r\n },\r\n body: JSON.stringify({ Text: this.buildJSONForRequest() })\r\n })\r\n .then(function (response) { return response.text(); })\r\n .then(function (response) {\r\n //console.log(`response`, response);\r\n var success = response === \"true\";\r\n if (success) {\r\n var o_1 = _this.state.FormValues;\r\n _this.formFieldProps.forEach(function (f) {\r\n o_1[f.Id] = \"\";\r\n });\r\n _this.setState({ Submitted: true, FormValues: o_1 });\r\n }\r\n else {\r\n _this.handleError(_this.props.GlobalSettings.submitError);\r\n }\r\n _this.setState({ Processing: false });\r\n })\r\n .catch(function (e) {\r\n console.log(e);\r\n _this.handleError(_this.props.GlobalSettings.submitError);\r\n _this.setState({ Processing: false });\r\n });\r\n };\r\n RequestForm.prototype.handleError = function (errorMessage) {\r\n if (this.props.OnError) {\r\n this.props.OnError(errorMessage);\r\n }\r\n };\r\n RequestForm.prototype.clearClicked = function () {\r\n var o = this.state.FormValues;\r\n this.formFieldProps.forEach(function (f) {\r\n o[f.Id] = \"\";\r\n });\r\n this.setState({ FormValues: o });\r\n if (this.props.OnClear !== undefined)\r\n this.props.OnClear();\r\n };\r\n return RequestForm;\r\n}(React.Component));\r\nexports.default = RequestForm;\r\n//# sourceMappingURL=RequestForm.js.map","// This optional code is used to register a service worker.\r\n// register() is not called by default.\r\n\r\n// This lets the app load faster on subsequent visits in production, and gives\r\n// it offline capabilities. However, it also means that developers (and users)\r\n// will only see deployed updates on subsequent visits to a page, after all the\r\n// existing tabs open on the page have been closed, since previously cached\r\n// resources are updated in the background.\r\n\r\n// To learn more about the benefits of this model and instructions on how to\r\n// opt-in, read https://bit.ly/CRA-PWA\r\n\r\nconst isLocalhost = Boolean(\r\n window.location.hostname === 'localhost' ||\r\n // [::1] is the IPv6 localhost address.\r\n window.location.hostname === '[::1]' ||\r\n // 127.0.0.0/8 are considered localhost for IPv4.\r\n window.location.hostname.match(\r\n /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\r\n )\r\n);\r\n\r\ntype Config = {\r\n onSuccess?: (registration: ServiceWorkerRegistration) => void;\r\n onUpdate?: (registration: ServiceWorkerRegistration) => void;\r\n};\r\n\r\nexport function register(config?: Config) {\r\n if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {\r\n // The URL constructor is available in all browsers that support SW.\r\n const publicUrl = new URL(\r\n process.env.PUBLIC_URL,\r\n window.location.href\r\n );\r\n if (publicUrl.origin !== window.location.origin) {\r\n // Our service worker won't work if PUBLIC_URL is on a different origin\r\n // from what our page is served on. This might happen if a CDN is used to\r\n // serve assets; see https://github.com/facebook/create-react-app/issues/2374\r\n return;\r\n }\r\n\r\n window.addEventListener('load', () => {\r\n const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;\r\n\r\n if (isLocalhost) {\r\n // This is running on localhost. Let's check if a service worker still exists or not.\r\n checkValidServiceWorker(swUrl, config);\r\n\r\n // Add some additional logging to localhost, pointing developers to the\r\n // service worker/PWA documentation.\r\n navigator.serviceWorker.ready.then(() => {\r\n console.log(\r\n 'This web app is being served cache-first by a service ' +\r\n 'worker. To learn more, visit https://bit.ly/CRA-PWA'\r\n );\r\n });\r\n } else {\r\n // Is not localhost. Just register service worker\r\n registerValidSW(swUrl, config);\r\n }\r\n });\r\n }\r\n}\r\n\r\nfunction registerValidSW(swUrl: string, config?: Config) {\r\n navigator.serviceWorker\r\n .register(swUrl)\r\n .then(registration => {\r\n registration.onupdatefound = () => {\r\n const installingWorker = registration.installing;\r\n if (installingWorker == null) {\r\n return;\r\n }\r\n installingWorker.onstatechange = () => {\r\n if (installingWorker.state === 'installed') {\r\n if (navigator.serviceWorker.controller) {\r\n // At this point, the updated precached content has been fetched,\r\n // but the previous service worker will still serve the older\r\n // content until all client tabs are closed.\r\n console.log(\r\n 'New content is available and will be used when all ' +\r\n 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'\r\n );\r\n\r\n // Execute callback\r\n if (config && config.onUpdate) {\r\n config.onUpdate(registration);\r\n }\r\n } else {\r\n // At this point, everything has been precached.\r\n // It's the perfect time to display a\r\n // \"Content is cached for offline use.\" message.\r\n console.log('Content is cached for offline use.');\r\n\r\n // Execute callback\r\n if (config && config.onSuccess) {\r\n config.onSuccess(registration);\r\n }\r\n }\r\n }\r\n };\r\n };\r\n })\r\n .catch(error => {\r\n console.error('Error during service worker registration:', error);\r\n });\r\n}\r\n\r\nfunction checkValidServiceWorker(swUrl: string, config?: Config) {\r\n // Check if the service worker can be found. If it can't reload the page.\r\n fetch(swUrl, {\r\n headers: { 'Service-Worker': 'script' }\r\n })\r\n .then(response => {\r\n // Ensure service worker exists, and that we really are getting a JS file.\r\n const contentType = response.headers.get('content-type');\r\n if (\r\n response.status === 404 ||\r\n (contentType != null && contentType.indexOf('javascript') === -1)\r\n ) {\r\n // No service worker found. Probably a different app. Reload the page.\r\n navigator.serviceWorker.ready.then(registration => {\r\n registration.unregister().then(() => {\r\n window.location.reload();\r\n });\r\n });\r\n } else {\r\n // Service worker found. Proceed as normal.\r\n registerValidSW(swUrl, config);\r\n }\r\n })\r\n .catch(() => {\r\n console.log(\r\n 'No internet connection found. App is running in offline mode.'\r\n );\r\n });\r\n}\r\n\r\nexport function unregister() {\r\n if ('serviceWorker' in navigator) {\r\n navigator.serviceWorker.ready\r\n .then(registration => {\r\n registration.unregister();\r\n })\r\n .catch(error => {\r\n console.error(error.message);\r\n });\r\n }\r\n}\r\n"],"sourceRoot":""}