openstack-uicore-foundation 4.0.35 → 4.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("openstack-uicore-foundation",[],t):"object"==typeof exports?exports["openstack-uicore-foundation"]=t():e["openstack-uicore-foundation"]=t()}(this,(()=>(()=>{"use strict";var e={2230:(e,t,r)=>{r.d(t,{default:()=>m});var n=r(580),a=r.n(n),s=r(6689),l=r.n(s),i=r(4656),o=r.n(i),u=r(418);const c=["onChange","value","className","options","id","children","error","disabled","name"];function d(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}class m extends l().Component{constructor(e){super(e);let t=!!e.value&&e.value.find((t=>!e.options.map((e=>e.value)).includes(t)));this.state={otherChecked:!!t},this.handleChange=this.handleChange.bind(this),this.handleOtherCBChange=this.handleOtherCBChange.bind(this)}handleChange(e){let t=this.props.options.map((e=>e.value)),r=this.props.value?[...this.props.value]:[];if("checkbox"===e.target.type)if(e.target.checked){const t=isNaN(e.target.value)?e.target.value:parseInt(e.target.value);r.push(t)}else r=r.filter((t=>t!=e.target.value));else r=r.filter((e=>t.includes(e))),r.push(e.target.value);let n={target:{id:this.props.id,value:r,type:"checkboxlist"}};this.props.onChange(n)}handleOtherCBChange(e){this.setState({otherChecked:e.target.checked})}render(){let e,t=this.props,{onChange:r,value:n,className:a,options:s,id:i,children:m,error:p,disabled:h,name:b}=t,{otherChecked:f}=(d(t,c),this.state),v=this.props.hasOwnProperty("inline"),y=this.props.hasOwnProperty("html"),g=this.props.hasOwnProperty("allowOther"),_=!!n&&n.find((e=>!s.map((e=>e.value)).includes(e))),O=this.props.hasOwnProperty("error")&&""!==p,E=this.props.hasOwnProperty("disabled")&&1==h;return e=v?{paddingLeft:"22px",marginLeft:"20px",float:"left"}:{paddingLeft:"22px",marginTop:"7px"},l().createElement("div",{id:`chl_wrapper_${i}`},l().createElement("div",{className:"checkboxes-div"+(O?" error":"")},s.map((t=>{let r=!!n&&n.includes(t.value);return l().createElement("div",{className:"form-check abc-checkbox",key:"radio_key_"+t.value,style:e},l().createElement("input",{type:"checkbox",id:`cb_${i}_${t.value}`,name:b||i,checked:r,disabled:E,onChange:this.handleChange,className:"form-check-input",value:t.value}),l().createElement("label",{className:"form-check-label",htmlFor:`cb_${i}_${t.value}`},y&&l().createElement(u.default,null,t.label),!y&&t.label))})),g&&l().createElement("div",{className:"form-check abc-checkbox",style:e},l().createElement("input",{type:"checkbox",id:"cb_other"+i,checked:f,disabled:E,onChange:this.handleOtherCBChange,className:"form-check-input",value:"other"}),l().createElement("label",{className:"form-check-label",htmlFor:"cb_other"+i},o().translate("general.other"))),g&&f&&l().createElement("div",{style:{paddingLeft:"22px",width:"50%"}},l().createElement("input",{className:"form-control",disabled:E,onChange:this.handleChange,value:_}))),O&&l().createElement("p",{className:"error-label"},p))}}m.propTypes={id:a().string.isRequired}},401:(e,t,r)=>{r.d(t,{default:()=>p});var n=r(6689),a=r.n(n),s=r(1929),l=r.n(s);const i=["onChange","value","className","error","clearable","disabled","overrideCSS"];function o(){return o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o.apply(this,arguments)}function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function c(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?u(Object(r),!0).forEach((function(t){d(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function d(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}class p extends a().Component{constructor(e){super(e),this.handleChange=this.handleChange.bind(this)}handleChange(e){let t=null;t=this.props.isMulti?e?e.map((e=>e.value)):null:e?e.value:null;let r={target:{id:this.props.id,value:t,type:"dropdown"}};this.props.onChange(r)}render(){let e=this.props,{onChange:t,value:r,className:n,error:s,clearable:u,disabled:d,overrideCSS:p}=e,h=m(e,i),b=this.props.hasOwnProperty("error")&&""!=s,f=this.props.hasOwnProperty("clearable"),v=this.props.hasOwnProperty("disabled")&&1==d,y=null,g=n;this.props.hasOwnProperty("overrideCSS")&&0!=p||(g="dropdown "+n+" "+(b?"error":"")),y=this.props.isMulti?this.props.options.filter((e=>r.includes(e.value))):r instanceof Object||null==r?r:this.props.options.find((e=>e.value==r));const _={menu:e=>c(c({},e),{},{zIndex:999})};return a().createElement("div",null,a().createElement(l(),o({className:g,value:y,onChange:this.handleChange,isClearable:f,isDisabled:v,styles:_},h)),b&&a().createElement("p",{className:"error-label"},s))}}},7027:(e,t,r)=>{r.d(t,{default:()=>c});var n=r(6689),a=r.n(n),s=r(418),l=r(580),i=r.n(l);const o=["onChange","value","className","error","disabled","options","id","name"];function u(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}class c extends a().Component{constructor(e){super(e),this.state={value:e.value},this.handleChange=this.handleChange.bind(this)}handleChange(e){let t={target:{id:this.props.id,value:e.target.value,type:"radio"}};this.props.onChange(t)}getLabel(e,t,r,n,l){return r?a().createElement("label",{className:"form-check-label",htmlFor:`radio_${t}_${e.value}`,style:{display:"inline-block"}},l&&a().createElement(s.default,null,e.label),!l&&e.label):n?a().createElement("label",{className:"form-check-label",htmlFor:`radio_${t}_${e.value}`},e.label):a().createElement("label",{className:"form-check-label",htmlFor:`radio_${t}_${e.value}`,style:{display:"inline-block"}},a().createElement("h4",{style:{marginTop:"0px"}},e.label),a().createElement(s.default,null,e.description))}render(){let e,t=this.props,{onChange:r,value:n,className:s,error:l,disabled:i,options:c,id:d,name:m}=t,p=(u(t,o),this.props.hasOwnProperty("error")&&""!=l),h=this.props.hasOwnProperty("inline"),b=this.props.hasOwnProperty("simple"),f=this.props.hasOwnProperty("html"),v=this.props.hasOwnProperty("disabled")&&1==i;return e=h?{paddingLeft:"22px",marginLeft:"20px",float:"left"}:{paddingLeft:"22px"},a().createElement("div",{id:`rl_wrapper_${d}`},c.map((t=>{let r=t.value==n;return a().createElement("div",{className:"form-check abc-radio",key:`radio_key_${d}_${t.value}`,style:e},a().createElement("input",{className:"form-check-input",type:"radio",id:`radio_${d}_${t.value}`,value:t.value,checked:r,onChange:this.handleChange,disabled:v,name:m||`radio_${d}`}),this.getLabel(t,d,h,b,f))})),p&&a().createElement("p",{className:"error-label"},l))}}c.propTypes={id:i().string.isRequired}},1833:(e,t,r)=>{r.d(t,{default:()=>o});var n=r(6689),a=r.n(n);const s=["onChange","value","className","error","containerClassName"];function l(){return l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},l.apply(this,arguments)}function i(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}class o extends a().Component{constructor(e){super(e),this.handleChange=this.handleChange.bind(this)}componentDidUpdate(e,t,r){this.props.value!==e.value&&(this.input.value=this.props.value)}handleChange(e){this.props.onChange(e)}render(){let e=this.props,{onChange:t,value:r,className:n,error:o,containerClassName:u}=e,c=i(e,s),d=this.props.hasOwnProperty("error")&&""!==o,m=this.props.hasOwnProperty("className")?n:"form-control",p=this.props.hasOwnProperty("containerClassName")?u:"container-form-control";return a().createElement("div",{className:p},a().createElement("input",l({className:`${m} ${d?"error":""}`,ref:e=>{this.input=e},defaultValue:r,onChange:this.handleChange},c)),d&&a().createElement("p",{className:"error-label"},o))}}},418:(e,t,r)=>{r.d(t,{default:()=>s});var n=r(6689),a=r.n(n);const s=({children:e,className:t=""})=>a().createElement("span",{className:t,dangerouslySetInnerHTML:{__html:null==e?void 0:e.replace(/\n/g,"<br />")}})},1995:(e,t,r)=>{function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach((function(t){s(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function s(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r.d(t,{default:()=>m});const l="ComboBox",i="CheckBoxList",o="RadioButtonList",u=[l,i,o],c="And",d="Equal";class m{constructor(e,t=[]){s(this,"_parseQuestion",(e=>{if(this.questionByName[e.name]=e,this.questionById[parseInt(e.id)]=e,e.hasOwnProperty("sub_question_rules"))for(let t of e.sub_question_rules)this.rules[parseInt(t.id)]=t,this._parseQuestion(t.sub_question)})),s(this,"_parseQuestions",(()=>{for(let e of this.questions)this._parseQuestion(e)})),s(this,"_allowsValues",(e=>u.includes(e.type))),s(this,"_allowsValue",((e,t)=>{let r=t.value.split(",").map((e=>parseInt(e)));for(let t of r)if(!e.values.map((e=>e.id)).includes(t))return!1;return!0})),s(this,"_getAnswerFor",(e=>{let t=Number.isInteger(e)?e:e.id,r=this.answers[t]||null;return r||null})),s(this,"_hasValue",(e=>""!==e.value)),s(this,"_answerContains",((e,t)=>e.value.split(",").includes(t))),s(this,"_isSubQuestionVisible",(e=>{let t=e.answer_values_operator===c;const r=this._getAnswerFor(e.parent_question_id);if(r)switch(e.visibility_condition){case d:for(let n of e.answer_values)t=e.answer_values_operator===c?t&&this._answerContains(r,n):t||this._answerContains(r,n);break;case"NotEqual":for(let n of e.answer_values)t=e.answer_values_operator===c?t&&!this._answerContains(r,n):t||!this._answerContains(r,n)}else t=e.visibility_condition!==d;return"Visible"===e.visibility?t:!t})),s(this,"_isAnswered",(e=>{const t=this._getAnswerFor(e);if("MainQuestion"===e.class)return!e.mandatory||!!t&&(!!this._hasValue(t)&&!(this._allowsValues(e)&&!this._allowsValue(e,t)));for(let r of e.parent_rules)if(this._isSubQuestionVisible(this.rules[r]))return!e.mandatory||!!t&&(!!this._hasValue(t)&&!(this._allowsValues(e)&&!this._allowsValue(e,t)));return!0})),s(this,"_checkQuestion",(e=>{let t=this._isAnswered(e);if(e.hasOwnProperty("sub_question_rules"))for(let r of e.sub_question_rules)t=t&&this._checkQuestion(r.sub_question);return t})),s(this,"_formatQuestionAnswer",(e=>{var t;let r={},n=null===(t=this.originalAnswers.find((t=>t.question_id===e.id)))||void 0===t?void 0:t.value;if(n&&("CheckBox"===e.type&&(n="false"!==n&&!!n),e.type!==o&&e.type!==l||(n=parseInt(n)),e.type===i&&(n=n.split(",").map((e=>parseInt(e)))||[])),r[e.name]=n||"",e.type===i&&""===r[e.name]&&(r[e.name]=[]),e.hasOwnProperty("sub_question_rules"))for(let t of e.sub_question_rules){let e=this._formatQuestionAnswer(t.sub_question);r=a(a({},r),e)}return r})),s(this,"formatAnswers",(()=>{let e={};return this.questions.forEach((t=>{let r=this._formatQuestionAnswer(t);e=a(a({},e),r)})),e})),s(this,"completed",(()=>{let e=!0;for(let t of this.questions)e=e&&this._checkQuestion(t);return e})),s(this,"getQuestionByName",(e=>this.questionByName[e]||null)),s(this,"getQuestionById",(e=>this.questionById[parseInt(e)]||null)),this.questions=e,this.originalAnswers=t,this.answers=[];for(let e of this.originalAnswers)this.answers[e.question_id]=e;this.questionByName={},this.questionById={},this.rules={},this._parseQuestions()}}},4656:e=>{e.exports=require("i18n-react/dist/i18n-react")},580:e=>{e.exports=require("prop-types")},6689:e=>{e.exports=require("react")},1929:e=>{e.exports=require("react-select")}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}(()=>{r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t}})(),(()=>{r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})}})(),(()=>{r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})();var n={};return(()=>{r.r(n),r.d(n,{default:()=>C});var e=r(6689),t=r.n(e),a=r(580),s=r.n(a),l=r(418),i=r(1833),o=r(401),u=r(7027),c=r(2230),d=r(1995);const m=require("react-final-form"),p=["input","meta","question","className","isDisabled","isRequired"],h=["input","meta","question","isDisabled","isRequired"],b=["input","meta","question","isDisabled","isRequired"],f=["input","meta","question","isDisabled","isRequired"];function v(){return v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},v.apply(this,arguments)}function y(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}const g=e=>{let{input:r,meta:n,question:a,className:s,isDisabled:l,isRequired:o}=e,u=y(e,p);return t().createElement(i.default,v({},r,u,{containerClassName:s,name:a.name,id:a.name,value:r.value,disabled:l,required:o,onChange:r.onChange,placeholder:a.placeholder}))},_=e=>{let{input:r,meta:n,question:a,isDisabled:s,isRequired:l}=e,i=y(e,h);return t().createElement(u.default,v({},r,i,{name:a.name,id:a.name,overrideCSS:!0,value:r.value,disabled:s,required:l,onChange:r.onChange}))},O=e=>{let{input:r,meta:n,question:a,isDisabled:s,isRequired:l}=e,i=y(e,b);return t().createElement(o.default,v({},r,i,{name:a.name,id:a.name,overrideCSS:!0,value:r.value,disabled:s,required:l,onChange:r.onChange}))},E=e=>{let{input:r,meta:n,question:a,isDisabled:s,isRequired:l}=e,i=y(e,f);return t().createElement(c.default,v({},r,i,{id:a.name,name:a.name,value:r.value,disabled:s,required:l,onChange:r.onChange}))},q=e=>e?e=>e?void 0:"Required":()=>{},w=t().forwardRef((({extraQuestions:r,userAnswers:n,onAnswerChanges:a,className:s="questions-form",questionContainerClassName:i="question-container",questionLabelContainerClassName:o="question-label-container",questionControlContainerClassName:u="question-control-container",readOnly:c=!1,debug:p=!1,buttonText:h="Submit",RequiredErrorMessage:b="Required",ValidationErrorClassName:f="extra-question-error",allowExtraQuestionsEdit:v=!0,onError:y=(e=>console.log("form errors: ",e))},w)=>{let C=null;const N=(0,e.useRef)({}),[k,x]=(0,e.useState)({});(0,e.useEffect)((()=>{j()}),[r]);const j=()=>{const e=new d.default(r,n);x(e.formatAnswers())},P=({when:e,rule:r,children:n})=>t().createElement(m.Field,{name:e,subscription:{value:!0}},(({input:{value:e}})=>R(r,F(e,r),n))),S=({name:e})=>t().createElement(m.Field,{name:e,subscription:{error:!0,touched:!0}},(({meta:{error:e,touched:r}})=>e&&r?t().createElement("div",{className:f},e):null)),F=(e,t)=>{let r=t.answer_values;if(Array.isArray(e)){if(!e.length)return!1;let n="And"===t.answer_values_operator;return r.forEach((r=>{n="And"===t.answer_values_operator?n&&e.includes(parseInt(r)):n||e.includes(parseInt(r))})),n}return r.includes(e.toString())},R=(e,t,r)=>"Visible"===e.visibility?"Equal"===e.visibility_condition?t?r:(delete N.current[e.sub_question.id],null):t?(delete N.current[e.sub_question.id],null):r:"Equal"===e.visibility_condition?t?(delete N.current[e.sub_question.id],null):r:t?r:(delete N.current[e.sub_question.id],null),A=e=>{var t;return e.mandatory?null!==(t=e.label)&&void 0!==t&&t.endsWith("</p>")?e.label.replace(/<\/p>$/g," <b>*</b></p>"):`${e.label} <b>*</b>`:e.label},D=r=>{let n=r.values;const a=!v&&k[r.name].length>0;var s,c,d;if("Text"===r.type)return t().createElement(e.Fragment,{key:r.name},t().createElement("div",{ref:e=>N.current[r.id]=e,className:i},t().createElement(l.default,{className:o},A(r)),t().createElement("div",{className:u},t().createElement(m.Field,{name:r.name,question:r,isDisabled:a,isRequired:r.mandatory,validate:q(r.mandatory),component:g}),t().createElement(S,{name:r.name}))),(null===(s=r.sub_question_rules)||void 0===s?void 0:s.length)>0&&r.sub_question_rules.map((e=>t().createElement(P,{key:e.id,when:r.name,rule:e},D(e.sub_question)))));if("TextArea"===r.type)return t().createElement(e.Fragment,{key:r.name},t().createElement("div",{ref:e=>N.current[r.id]=e,className:i},t().createElement(l.default,{className:o},A(r)),t().createElement("div",{className:u},t().createElement(m.Field,{validate:q(r.mandatory),name:r.name,id:r.name,disabled:a,required:r.mandatory,component:"textarea"}),t().createElement(S,{name:r.name}))),(null===(c=r.sub_question_rules)||void 0===c?void 0:c.length)>0&&r.sub_question_rules.map((e=>t().createElement(P,{key:e.id,when:r.name,rule:e},D(e.sub_question)))));if("CheckBox"===r.type)return t().createElement(e.Fragment,{key:r.name},t().createElement("div",{ref:e=>N.current[r.id]=e,style:{display:"flex"},className:i},t().createElement(l.default,{className:`eq-checkbox-label ${o}`},A(r)),t().createElement("div",{className:u},t().createElement("div",{className:"form-check abc-checkbox"},t().createElement(m.Field,{name:r.name,id:r.name,validate:q(r.mandatory),disabled:a,required:r.mandatory,type:"checkbox",className:"form-check-input",component:"input"}),t().createElement("label",{className:"form-check-label",htmlFor:r.name}),t().createElement(S,{name:r.name})))),(null===(d=r.sub_question_rules)||void 0===d?void 0:d.length)>0&&r.sub_question_rules.map((e=>t().createElement(P,{key:e.id,when:r.name,rule:e},D(e.sub_question)))));if("RadioButtonList"===r.type){var p;const s=n.map((e=>({label:e.label,value:e.id})));return t().createElement(e.Fragment,{key:r.name},t().createElement("div",{key:r.name,ref:e=>N.current[r.id]=e,className:i},t().createElement(l.default,{className:o},A(r)),t().createElement("div",{className:u},t().createElement(m.Field,{name:r.name,options:s,question:r,validate:q(r.mandatory),isDisabled:a,isRequired:r.mandatory,component:_}),t().createElement(S,{name:r.name}))),(null===(p=r.sub_question_rules)||void 0===p?void 0:p.length)>0&&r.sub_question_rules.map((e=>t().createElement(P,{key:e.id,when:r.name,rule:e},D(e.sub_question)))))}if("ComboBox"===r.type){var h;const s=n.map((e=>({label:e.label,value:e.id})));return t().createElement(e.Fragment,{key:r.name},t().createElement("div",{ref:e=>N.current[r.id]=e,className:i},t().createElement(l.default,{className:o},A(r)),t().createElement("div",{className:u},t().createElement(m.Field,{name:r.name,options:s,question:r,validate:q(r.mandatory),isDisabled:a,isRequired:r.mandatory,component:O}),t().createElement(S,{name:r.name}))),(null===(h=r.sub_question_rules)||void 0===h?void 0:h.length)>0&&r.sub_question_rules.map((e=>t().createElement(P,{key:e.id,when:r.name,rule:e},D(e.sub_question)))))}if("CheckBoxList"===r.type){var b;const s=n.map((e=>({label:e.label,value:e.id})));return t().createElement(e.Fragment,{key:r.name},t().createElement("div",{ref:e=>N.current[r.id]=e,className:i},t().createElement(l.default,{className:o},A(r)),t().createElement("div",{className:u},t().createElement(m.Field,{name:r.name,className:u,validate:q(r.mandatory),options:s,question:r,isDisabled:a,isRequired:r.mandatory,component:E}),t().createElement(S,{name:r.name}))),(null===(b=r.sub_question_rules)||void 0===b?void 0:b.length)>0&&r.sub_question_rules.map((e=>t().createElement(P,{key:e.id,when:r.name,rule:e},D(e.sub_question)))))}return null},I=(e,t,r)=>{var n;e.mandatory&&(e=>!!N.current[e.id])(e)&&(t.hasOwnProperty(e.name)&&""!==t[e.name]&&0!==t[e.name].length||(r[e.name]=b)),null===(n=e.sub_question_rules)||void 0===n||n.forEach((e=>{I(e.sub_question,t,r)}))};if(!Object.keys(k).length)return null;const $=(e,t,r)=>{var n;t.includes(e.name)&&r.push(e),null===(n=e.sub_question_rules)||void 0===n||n.forEach((e=>{$(e.sub_question,t,r)}))};return Object.keys(k).length?t().createElement("div",{className:s},t().createElement(m.Form,{validate:e=>{const t={};return r.forEach((r=>{I(r,e,t)})),Object.keys(t).length>0&&y(t),t},onSubmit:e=>{a(e)},initialValues:k},(({handleSubmit:e,form:n,submitting:a,pristine:s,values:l})=>(C=e,t().createElement("form",{onSubmit:t=>{const a=n.getRegisteredFields().filter((e=>n.getFieldState(e).invalid));a.length>0&&(e=>{const t=[];r.forEach((r=>{$(r,e,t)}));const n=t.sort(((e,t)=>e.order>t.order))[0];N.current[n.id].scrollIntoView({behavior:"smooth",block:"center"})})(a),e(t)},ref:w},c?t().createElement("fieldset",{disabled:"disabled"},r.map((e=>D(e)))):r.map((e=>D(e))),p&&t().createElement("pre",null,JSON.stringify(l,0,2)))))),!w&&t().createElement("button",{type:"submit",onClick:e=>{C(e)},style:{marginTop:10}},h)):null}));w.propTypes={extraQuestions:s().array.isRequired,userAnswers:s().array.isRequired,onAnswerChanges:s().func.isRequired,className:s().string,debug:s().bool,buttonText:s().string,questionContainerClassName:s().string,questionLabelContainerClassName:s().string,questionControlContainerClassName:s().string,RequiredErrorMessage:s().string,ValidationErrorClassName:s().string,allowExtraQuestionsEdit:s().bool};const C=w})(),n})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("openstack-uicore-foundation",[],t):"object"==typeof exports?exports["openstack-uicore-foundation"]=t():e["openstack-uicore-foundation"]=t()}(this,(()=>(()=>{"use strict";var e={2230:(e,t,r)=>{r.d(t,{default:()=>m});var n=r(580),a=r.n(n),s=r(6689),l=r.n(s),i=r(4656),o=r.n(i),u=r(418);const c=["onChange","value","className","options","id","children","error","disabled","name"];function d(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}class m extends l().Component{constructor(e){super(e);let t=!!e.value&&e.value.find((t=>!e.options.map((e=>e.value)).includes(t)));this.state={otherChecked:!!t},this.handleChange=this.handleChange.bind(this),this.handleOtherCBChange=this.handleOtherCBChange.bind(this)}handleChange(e){let t=this.props.options.map((e=>e.value)),r=this.props.value?[...this.props.value]:[];if("checkbox"===e.target.type)if(e.target.checked){const t=isNaN(e.target.value)?e.target.value:parseInt(e.target.value);r.push(t)}else r=r.filter((t=>t!=e.target.value));else r=r.filter((e=>t.includes(e))),r.push(e.target.value);let n={target:{id:this.props.id,value:r,type:"checkboxlist"}};this.props.onChange(n)}handleOtherCBChange(e){this.setState({otherChecked:e.target.checked})}render(){let e,t=this.props,{onChange:r,value:n,className:a,options:s,id:i,children:m,error:p,disabled:h,name:b}=t,{otherChecked:f}=(d(t,c),this.state),y=this.props.hasOwnProperty("inline"),v=this.props.hasOwnProperty("html"),g=this.props.hasOwnProperty("allowOther"),_=!!n&&n.find((e=>!s.map((e=>e.value)).includes(e))),O=this.props.hasOwnProperty("error")&&""!==p,E=this.props.hasOwnProperty("disabled")&&1==h;return e=y?{paddingLeft:"22px",marginLeft:"20px",float:"left"}:{paddingLeft:"22px",marginTop:"7px"},l().createElement("div",{id:`chl_wrapper_${i}`},l().createElement("div",{className:"checkboxes-div"+(O?" error":"")},s.map((t=>{let r=!!n&&n.includes(t.value);return l().createElement("div",{className:"form-check abc-checkbox",key:"radio_key_"+t.value,style:e},l().createElement("input",{type:"checkbox",id:`cb_${i}_${t.value}`,name:b||i,checked:r,disabled:E,onChange:this.handleChange,className:"form-check-input",value:t.value}),l().createElement("label",{className:"form-check-label",htmlFor:`cb_${i}_${t.value}`},v&&l().createElement(u.default,null,t.label),!v&&t.label))})),g&&l().createElement("div",{className:"form-check abc-checkbox",style:e},l().createElement("input",{type:"checkbox",id:"cb_other"+i,checked:f,disabled:E,onChange:this.handleOtherCBChange,className:"form-check-input",value:"other"}),l().createElement("label",{className:"form-check-label",htmlFor:"cb_other"+i},o().translate("general.other"))),g&&f&&l().createElement("div",{style:{paddingLeft:"22px",width:"50%"}},l().createElement("input",{className:"form-control",disabled:E,onChange:this.handleChange,value:_}))),O&&l().createElement("p",{className:"error-label"},p))}}m.propTypes={id:a().string.isRequired}},401:(e,t,r)=>{r.d(t,{default:()=>p});var n=r(6689),a=r.n(n),s=r(1929),l=r.n(s);const i=["onChange","value","className","error","clearable","disabled","overrideCSS"];function o(){return o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o.apply(this,arguments)}function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function c(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?u(Object(r),!0).forEach((function(t){d(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function d(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}class p extends a().Component{constructor(e){super(e),this.handleChange=this.handleChange.bind(this)}handleChange(e){let t=null;t=this.props.isMulti?e?e.map((e=>e.value)):null:e?e.value:null;let r={target:{id:this.props.id,value:t,type:"dropdown"}};this.props.onChange(r)}render(){let e=this.props,{onChange:t,value:r,className:n,error:s,clearable:u,disabled:d,overrideCSS:p}=e,h=m(e,i),b=this.props.hasOwnProperty("error")&&""!=s,f=this.props.hasOwnProperty("clearable"),y=this.props.hasOwnProperty("disabled")&&1==d,v=null,g=n;this.props.hasOwnProperty("overrideCSS")&&0!=p||(g="dropdown "+n+" "+(b?"error":"")),v=this.props.isMulti?this.props.options.filter((e=>r.includes(e.value))):r instanceof Object||null==r?r:this.props.options.find((e=>e.value==r));const _={menu:e=>c(c({},e),{},{zIndex:999})};return a().createElement("div",null,a().createElement(l(),o({className:g,value:v,onChange:this.handleChange,isClearable:f,isDisabled:y,styles:_},h)),b&&a().createElement("p",{className:"error-label"},s))}}},7027:(e,t,r)=>{r.d(t,{default:()=>c});var n=r(6689),a=r.n(n),s=r(418),l=r(580),i=r.n(l);const o=["onChange","value","className","error","disabled","options","id","name"];function u(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}class c extends a().Component{constructor(e){super(e),this.state={value:e.value},this.handleChange=this.handleChange.bind(this)}handleChange(e){let t={target:{id:this.props.id,value:e.target.value,type:"radio"}};this.props.onChange(t)}getLabel(e,t,r,n,l){return r?a().createElement("label",{className:"form-check-label",htmlFor:`radio_${t}_${e.value}`,style:{display:"inline-block"}},l&&a().createElement(s.default,null,e.label),!l&&e.label):n?a().createElement("label",{className:"form-check-label",htmlFor:`radio_${t}_${e.value}`},e.label):a().createElement("label",{className:"form-check-label",htmlFor:`radio_${t}_${e.value}`,style:{display:"inline-block"}},a().createElement("h4",{style:{marginTop:"0px"}},e.label),a().createElement(s.default,null,e.description))}render(){let e,t=this.props,{onChange:r,value:n,className:s,error:l,disabled:i,options:c,id:d,name:m}=t,p=(u(t,o),this.props.hasOwnProperty("error")&&""!=l),h=this.props.hasOwnProperty("inline"),b=this.props.hasOwnProperty("simple"),f=this.props.hasOwnProperty("html"),y=this.props.hasOwnProperty("disabled")&&1==i;return e=h?{paddingLeft:"22px",marginLeft:"20px",float:"left"}:{paddingLeft:"22px"},a().createElement("div",{id:`rl_wrapper_${d}`},c.map((t=>{let r=t.value==n;return a().createElement("div",{className:"form-check abc-radio",key:`radio_key_${d}_${t.value}`,style:e},a().createElement("input",{className:"form-check-input",type:"radio",id:`radio_${d}_${t.value}`,value:t.value,checked:r,onChange:this.handleChange,disabled:y,name:m||`radio_${d}`}),this.getLabel(t,d,h,b,f))})),p&&a().createElement("p",{className:"error-label"},l))}}c.propTypes={id:i().string.isRequired}},1833:(e,t,r)=>{r.d(t,{default:()=>o});var n=r(6689),a=r.n(n);const s=["onChange","value","className","error","containerClassName"];function l(){return l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},l.apply(this,arguments)}function i(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}class o extends a().Component{constructor(e){super(e),this.handleChange=this.handleChange.bind(this)}componentDidUpdate(e,t,r){this.props.value!==e.value&&(this.input.value=this.props.value)}handleChange(e){this.props.onChange(e)}render(){let e=this.props,{onChange:t,value:r,className:n,error:o,containerClassName:u}=e,c=i(e,s),d=this.props.hasOwnProperty("error")&&""!==o,m=this.props.hasOwnProperty("className")?n:"form-control",p=this.props.hasOwnProperty("containerClassName")?u:"container-form-control";return a().createElement("div",{className:p},a().createElement("input",l({className:`${m} ${d?"error":""}`,ref:e=>{this.input=e},defaultValue:r,onChange:this.handleChange},c)),d&&a().createElement("p",{className:"error-label"},o))}}},418:(e,t,r)=>{r.d(t,{default:()=>s});var n=r(6689),a=r.n(n);const s=({children:e,className:t=""})=>a().createElement("span",{className:t,dangerouslySetInnerHTML:{__html:null==e?void 0:e.replace(/\n/g,"<br />")}})},1995:(e,t,r)=>{function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach((function(t){s(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function s(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r.d(t,{default:()=>m});const l="ComboBox",i="CheckBoxList",o="RadioButtonList",u=[l,i,o],c="And",d="Equal";class m{constructor(e,t=[]){s(this,"_parseQuestion",(e=>{if(this.questionByName[e.name]=e,this.questionById[parseInt(e.id)]=e,e.hasOwnProperty("sub_question_rules"))for(let t of e.sub_question_rules)this.rules[parseInt(t.id)]=t,this._parseQuestion(t.sub_question)})),s(this,"_parseQuestions",(()=>{for(let e of this.questions)this._parseQuestion(e)})),s(this,"_allowsValues",(e=>u.includes(e.type))),s(this,"_allowsValue",((e,t)=>{let r=t.value.split(",").map((e=>parseInt(e)));for(let t of r)if(!e.values.map((e=>e.id)).includes(t))return!1;return!0})),s(this,"_getAnswerFor",(e=>{let t=Number.isInteger(e)?e:e.id,r=this.answers[t]||null;return r||null})),s(this,"_hasValue",(e=>""!==e.value)),s(this,"_answerContains",((e,t)=>e.value.split(",").includes(t))),s(this,"_isSubQuestionVisible",(e=>{let t=e.answer_values_operator===c;const r=this._getAnswerFor(e.parent_question_id);if(r)switch(e.visibility_condition){case d:for(let n of e.answer_values)t=e.answer_values_operator===c?t&&this._answerContains(r,n):t||this._answerContains(r,n);break;case"NotEqual":for(let n of e.answer_values)t=e.answer_values_operator===c?t&&!this._answerContains(r,n):t||!this._answerContains(r,n)}else t=e.visibility_condition!==d;return"Visible"===e.visibility?t:!t})),s(this,"_isAnswered",(e=>{const t=this._getAnswerFor(e);if("MainQuestion"===e.class)return!e.mandatory||!!t&&(!!this._hasValue(t)&&!(this._allowsValues(e)&&!this._allowsValue(e,t)));for(let r of e.parent_rules)if(this._isSubQuestionVisible(this.rules[r]))return!e.mandatory||!!t&&(!!this._hasValue(t)&&!(this._allowsValues(e)&&!this._allowsValue(e,t)));return!0})),s(this,"_checkQuestion",(e=>{let t=this._isAnswered(e);if(e.hasOwnProperty("sub_question_rules"))for(let r of e.sub_question_rules)t=t&&this._checkQuestion(r.sub_question);return t})),s(this,"_formatQuestionAnswer",(e=>{var t;let r={},n=null===(t=this.originalAnswers.find((t=>t.question_id===e.id)))||void 0===t?void 0:t.value;if(n&&("CheckBox"===e.type&&(n="false"!==n&&!!n),e.type!==o&&e.type!==l||(n=parseInt(n)),e.type===i&&(n=n.split(",").map((e=>parseInt(e)))||[])),r[e.name]=n||"",e.type===i&&""===r[e.name]&&(r[e.name]=[]),e.hasOwnProperty("sub_question_rules"))for(let t of e.sub_question_rules){let e=this._formatQuestionAnswer(t.sub_question);r=a(a({},r),e)}return r})),s(this,"formatAnswers",(()=>{let e={};return this.questions.forEach((t=>{let r=this._formatQuestionAnswer(t);e=a(a({},e),r)})),e})),s(this,"completed",(()=>{let e=!0;for(let t of this.questions)e=e&&this._checkQuestion(t);return e})),s(this,"getQuestionByName",(e=>this.questionByName[e]||null)),s(this,"getQuestionById",(e=>this.questionById[parseInt(e)]||null)),this.questions=e,this.originalAnswers=t,this.answers=[];for(let e of this.originalAnswers)this.answers[e.question_id]=e;this.questionByName={},this.questionById={},this.rules={},this._parseQuestions()}}},4656:e=>{e.exports=require("i18n-react/dist/i18n-react")},580:e=>{e.exports=require("prop-types")},6689:e=>{e.exports=require("react")},1929:e=>{e.exports=require("react-select")}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}(()=>{r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t}})(),(()=>{r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})}})(),(()=>{r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})();var n={};return(()=>{r.r(n),r.d(n,{default:()=>C});var e=r(6689),t=r.n(e),a=r(580),s=r.n(a),l=r(418),i=r(1833),o=r(401),u=r(7027),c=r(2230),d=r(1995);const m=require("react-final-form"),p=["input","meta","question","className","isDisabled","isRequired"],h=["input","meta","question","isDisabled","isRequired"],b=["input","meta","question","isDisabled","isRequired"],f=["input","meta","question","isDisabled","isRequired","maxValues"];function y(){return y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},y.apply(this,arguments)}function v(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}const g=e=>{let{input:r,meta:n,question:a,className:s,isDisabled:l,isRequired:o}=e,u=v(e,p);return t().createElement(i.default,y({},r,u,{containerClassName:s,name:a.name,id:a.name,value:r.value,disabled:l,required:o,onChange:r.onChange,placeholder:a.placeholder}))},_=e=>{let{input:r,meta:n,question:a,isDisabled:s,isRequired:l}=e,i=v(e,h);return t().createElement(u.default,y({},r,i,{name:a.name,id:a.name,overrideCSS:!0,value:r.value,disabled:s,required:l,onChange:r.onChange}))},O=e=>{let{input:r,meta:n,question:a,isDisabled:s,isRequired:l}=e,i=v(e,b);return t().createElement(o.default,y({},r,i,{name:a.name,id:a.name,overrideCSS:!0,value:r.value,disabled:s,required:l,onChange:r.onChange}))},E=e=>{let{input:r,meta:n,question:a,isDisabled:s,isRequired:l,maxValues:i}=e,o=v(e,f);return t().createElement(c.default,y({},r,o,{id:a.name,name:a.name,value:r.value,disabled:s,required:l,onChange:e=>{const t=e.target.value;return i>0&&t.length>i?null:r.onChange(e)}}))},q=e=>e?e=>e?void 0:"Required":()=>{},w=t().forwardRef((({extraQuestions:r,userAnswers:n,onAnswerChanges:a,className:s="questions-form",questionContainerClassName:i="question-container",questionLabelContainerClassName:o="question-label-container",questionControlContainerClassName:u="question-control-container",readOnly:c=!1,debug:p=!1,buttonText:h="Submit",RequiredErrorMessage:b="Required",ValidationErrorClassName:f="extra-question-error",allowExtraQuestionsEdit:y=!0,onError:v=(e=>console.log("form errors: ",e))},w)=>{let C=null;const N=(0,e.useRef)({}),[k,x]=(0,e.useState)({});(0,e.useEffect)((()=>{j()}),[r]);const j=()=>{const e=new d.default(r,n);x(e.formatAnswers())},P=({when:e,rule:r,children:n})=>t().createElement(m.Field,{name:e,subscription:{value:!0}},(({input:{value:e}})=>R(r,F(e,r),n))),S=({name:e})=>t().createElement(m.Field,{name:e,subscription:{error:!0,touched:!0}},(({meta:{error:e,touched:r}})=>e&&r?t().createElement("div",{className:f},e):null)),F=(e,t)=>{let r=t.answer_values;if(Array.isArray(e)){if(!e.length)return!1;let n="And"===t.answer_values_operator;return r.forEach((r=>{n="And"===t.answer_values_operator?n&&e.includes(parseInt(r)):n||e.includes(parseInt(r))})),n}return r.includes(e.toString())},R=(e,t,r)=>"Visible"===e.visibility?"Equal"===e.visibility_condition?t?r:(delete N.current[e.sub_question.id],null):t?(delete N.current[e.sub_question.id],null):r:"Equal"===e.visibility_condition?t?(delete N.current[e.sub_question.id],null):r:t?r:(delete N.current[e.sub_question.id],null),A=e=>{var t;return e.mandatory?null!==(t=e.label)&&void 0!==t&&t.endsWith("</p>")?e.label.replace(/<\/p>$/g," <b>*</b></p>"):`${e.label} <b>*</b>`:e.label},D=r=>{let n=r.values;const a=!y&&((e,t)=>{if(!t.hasOwnProperty(e.name))return!1;const r=t[e.name];return Array.isArray(r)||"string"==typeof r?r.length>0:"number"==typeof r?r>0:"boolean"==typeof r&&r})(r,k);var s,c,d;if("Text"===r.type)return t().createElement(e.Fragment,{key:r.name},t().createElement("div",{ref:e=>N.current[r.id]=e,className:i},t().createElement(l.default,{className:o},A(r)),t().createElement("div",{className:u},t().createElement(m.Field,{name:r.name,question:r,isDisabled:a,isRequired:r.mandatory,validate:q(r.mandatory),component:g}),t().createElement(S,{name:r.name}))),(null===(s=r.sub_question_rules)||void 0===s?void 0:s.length)>0&&r.sub_question_rules.map((e=>t().createElement(P,{key:e.id,when:r.name,rule:e},D(e.sub_question)))));if("TextArea"===r.type)return t().createElement(e.Fragment,{key:r.name},t().createElement("div",{ref:e=>N.current[r.id]=e,className:i},t().createElement(l.default,{className:o},A(r)),t().createElement("div",{className:u},t().createElement(m.Field,{validate:q(r.mandatory),name:r.name,id:r.name,disabled:a,required:r.mandatory,component:"textarea"}),t().createElement(S,{name:r.name}))),(null===(c=r.sub_question_rules)||void 0===c?void 0:c.length)>0&&r.sub_question_rules.map((e=>t().createElement(P,{key:e.id,when:r.name,rule:e},D(e.sub_question)))));if("CheckBox"===r.type)return t().createElement(e.Fragment,{key:r.name},t().createElement("div",{ref:e=>N.current[r.id]=e,style:{display:"flex"},className:i},t().createElement(l.default,{className:`eq-checkbox-label ${o}`},A(r)),t().createElement("div",{className:u},t().createElement("div",{className:"form-check abc-checkbox"},t().createElement(m.Field,{name:r.name,id:r.name,validate:q(r.mandatory),disabled:a,required:r.mandatory,type:"checkbox",className:"form-check-input",component:"input"}),t().createElement("label",{className:"form-check-label",htmlFor:r.name}),t().createElement(S,{name:r.name})))),(null===(d=r.sub_question_rules)||void 0===d?void 0:d.length)>0&&r.sub_question_rules.map((e=>t().createElement(P,{key:e.id,when:r.name,rule:e},D(e.sub_question)))));if("RadioButtonList"===r.type){var p;const s=n.map((e=>({label:e.label,value:e.id})));return t().createElement(e.Fragment,{key:r.name},t().createElement("div",{key:r.name,ref:e=>N.current[r.id]=e,className:i},t().createElement(l.default,{className:o},A(r)),t().createElement("div",{className:u},t().createElement(m.Field,{name:r.name,options:s,question:r,validate:q(r.mandatory),isDisabled:a,isRequired:r.mandatory,component:_}),t().createElement(S,{name:r.name}))),(null===(p=r.sub_question_rules)||void 0===p?void 0:p.length)>0&&r.sub_question_rules.map((e=>t().createElement(P,{key:e.id,when:r.name,rule:e},D(e.sub_question)))))}if("ComboBox"===r.type){var h;const s=n.map((e=>({label:e.label,value:e.id})));return t().createElement(e.Fragment,{key:r.name},t().createElement("div",{ref:e=>N.current[r.id]=e,className:i},t().createElement(l.default,{className:o},A(r)),t().createElement("div",{className:u},t().createElement(m.Field,{name:r.name,options:s,question:r,validate:q(r.mandatory),isDisabled:a,isRequired:r.mandatory,component:O}),t().createElement(S,{name:r.name}))),(null===(h=r.sub_question_rules)||void 0===h?void 0:h.length)>0&&r.sub_question_rules.map((e=>t().createElement(P,{key:e.id,when:r.name,rule:e},D(e.sub_question)))))}if("CheckBoxList"===r.type){var b;const s=n.map((e=>({label:e.label,value:e.id})));return t().createElement(e.Fragment,{key:r.name},t().createElement("div",{ref:e=>N.current[r.id]=e,className:i},t().createElement(l.default,{className:o},A(r)),t().createElement("div",{className:u},t().createElement(m.Field,{name:r.name,className:u,validate:q(r.mandatory),options:s,question:r,maxValues:r.max_selected_values,isDisabled:a,isRequired:r.mandatory,component:E}),t().createElement(S,{name:r.name}))),(null===(b=r.sub_question_rules)||void 0===b?void 0:b.length)>0&&r.sub_question_rules.map((e=>t().createElement(P,{key:e.id,when:r.name,rule:e},D(e.sub_question)))))}return null},I=(e,t,r)=>{var n;e.mandatory&&(e=>!!N.current[e.id])(e)&&(t.hasOwnProperty(e.name)&&""!==t[e.name]&&0!==t[e.name].length||(r[e.name]=b)),null===(n=e.sub_question_rules)||void 0===n||n.forEach((e=>{I(e.sub_question,t,r)}))};if(!Object.keys(k).length)return null;const $=(e,t,r)=>{var n;t.includes(e.name)&&r.push(e),null===(n=e.sub_question_rules)||void 0===n||n.forEach((e=>{$(e.sub_question,t,r)}))};return Object.keys(k).length?t().createElement("div",{className:s},t().createElement(m.Form,{validate:e=>{const t={};return r.forEach((r=>{I(r,e,t)})),Object.keys(t).length>0&&v(t),t},onSubmit:e=>{a(e)},initialValues:k},(({handleSubmit:e,form:n,submitting:a,pristine:s,values:l})=>(C=e,t().createElement("form",{onSubmit:t=>{const a=n.getRegisteredFields().filter((e=>n.getFieldState(e).invalid));a.length>0&&(e=>{const t=[];r.forEach((r=>{$(r,e,t)}));const n=t.sort(((e,t)=>e.order>t.order))[0];N.current[n.id].scrollIntoView({behavior:"smooth",block:"center"})})(a),e(t)},ref:w},c?t().createElement("fieldset",{disabled:"disabled"},r.map((e=>D(e)))):r.map((e=>D(e))),p&&t().createElement("pre",null,JSON.stringify(l,0,2)))))),!w&&t().createElement("button",{type:"submit",onClick:e=>{C(e)},style:{marginTop:10}},h)):null}));w.propTypes={extraQuestions:s().array.isRequired,userAnswers:s().array.isRequired,onAnswerChanges:s().func.isRequired,className:s().string,debug:s().bool,buttonText:s().string,questionContainerClassName:s().string,questionLabelContainerClassName:s().string,questionControlContainerClassName:s().string,RequiredErrorMessage:s().string,ValidationErrorClassName:s().string,allowExtraQuestionsEdit:s().bool};const C=w})(),n})()));
|
package/lib/security/methods.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define("openstack-uicore-foundation",[],o):"object"==typeof exports?exports["openstack-uicore-foundation"]=o():e["openstack-uicore-foundation"]=o()}(this,(()=>(()=>{"use strict";var e={4341:(e,o,t)=>{t.d(o,{SET_LOGGED_USER:()=>n});t(4656),t(4054),t(6793),t(8576);const n="SET_LOGGED_USER"},8576:(e,o,t)=>{t.r(o),t.d(o,{ACCESS_TOKEN_SKEW_TIME:()=>E,RESPONSE_TYPE_CODE:()=>R,RESPONSE_TYPE_IMPLICIT:()=>L,clearAccessToken:()=>D,clearAuthInfo:()=>G,doLogin:()=>C,doLoginBasicLogin:()=>j,emitAccessToken:()=>N,getAccessToken:()=>F,getAuthInfo:()=>B,getAuthUrl:()=>v,getIdToken:()=>J,getLogoutUrl:()=>P,getOAuth2ClientId:()=>H,getOAuth2Flow:()=>V,getOAuth2IDPBaseUrl:()=>z,getOAuth2Scopes:()=>W,initLogOut:()=>Y,passwordlessLogin:()=>Z,passwordlessStart:()=>X,refreshAccessToken:()=>$,storeAuthInfo:()=>M,useOAuth2RefreshToken:()=>K,validateIdToken:()=>Q});var n=t(6793),r=t(4824),i=t.n(r);const
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define("openstack-uicore-foundation",[],o):"object"==typeof exports?exports["openstack-uicore-foundation"]=o():e["openstack-uicore-foundation"]=o()}(this,(()=>(()=>{"use strict";var e={4341:(e,o,t)=>{t.d(o,{SET_LOGGED_USER:()=>n});t(4656),t(4054),t(6793),t(8576);const n="SET_LOGGED_USER"},8576:(e,o,t)=>{t.r(o),t.d(o,{ACCESS_TOKEN_SKEW_TIME:()=>E,RESPONSE_TYPE_CODE:()=>R,RESPONSE_TYPE_IMPLICIT:()=>L,clearAccessToken:()=>D,clearAuthInfo:()=>G,doLogin:()=>C,doLoginBasicLogin:()=>j,emitAccessToken:()=>N,getAccessToken:()=>F,getAuthInfo:()=>B,getAuthUrl:()=>v,getIdToken:()=>J,getLogoutUrl:()=>P,getOAuth2ClientId:()=>H,getOAuth2Flow:()=>V,getOAuth2IDPBaseUrl:()=>z,getOAuth2Scopes:()=>W,initLogOut:()=>Y,passwordlessLogin:()=>Z,passwordlessStart:()=>X,refreshAccessToken:()=>$,storeAuthInfo:()=>M,useOAuth2RefreshToken:()=>K,validateIdToken:()=>Q});var n=t(6793),r=t(4824),i=t.n(r);const s=require("browser-tabs-lock");var l=t.n(s),c=t(6530),d=t.n(c),u=t(3856),p=t.n(u),f=t(4341);const w=require("crypto-js/sha256");var g=t.n(w);const h=require("crypto-js/enc-base64url");var _=t.n(h);const y=require("crypto-js/enc-hex");var m=t.n(y);const k=65536,S="undefined"!=typeof window?window.crypto||window.msCrypto:null;let O=i();const T=new(l()),I="openstackuicore.lock.getTokenSilently",E=20,L="token id_token",R="code",U="authInfo",A="nonce",b="pkce",v=(e=null,o=null,t=null,r=null)=>{let i=H(),a=(0,n.getAuthCallback)(),s=z(),l=W(),c=V();null!=e&&(a+=`?BackUrl=${encodeURI(e)}`);let u=x(16);(0,n.putOnLocalStorage)(A,u);let p=d()(`${s}/oauth2/auth`),f={response_type:encodeURI(c),scope:encodeURI(l),nonce:u,response_mode:"fragment",client_id:encodeURI(i),redirect_uri:encodeURI(a)};if(c===R){const e=q();(0,n.putOnLocalStorage)(b,JSON.stringify(e)),f.code_challenge=e.codeChallenge,f.code_challenge_method="S256",f.approval_prompt="force"}return o&&(f.prompt=o),l&&l.includes("offline_access")&&(f.prompt="consent"),t&&(f.id_token_hint=t),r&&(f.provider=r),p=p.query(f),p},P=e=>{let o=z(),t=H(),r=d()(`${o}/oauth2/end-session`),i=x(16),a=(0,n.getOrigin)()+"/auth/logout";return(0,n.putOnLocalStorage)("post_logout_state",i),r.query({id_token_hint:e,post_logout_redirect_uri:encodeURI(a),client_id:encodeURI(t),state:i})},x=e=>{let o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="";for(let n=0;n<e;n++)t+=o.charAt(Math.floor(Math.random()*o.length));return t},C=(e=null,o=null,t=null)=>{let r=v(e,t,null,o);(0,n.getCurrentLocation)().replace(r.toString())},j=(e=null)=>{C(e,null,null)},q=()=>{const e=(0,n.base64URLEncode)((e=>{if(e>4294967295)throw new RangeError("requested too many random bytes");const o=Buffer.allocUnsafe(e);if(!S)return a;if(e>0)if(e>k)for(let t=0;t<e;t+=k)S.getRandomValues(o.slice(t,t+k));else S.getRandomValues(o);return o})(64));return{codeVerifier:e,codeChallenge:((e,o="hex")=>{let t=m();return"Base64url"===o&&(t=_()),g()(e).toString(t)})(e,"Base64url"),createdAt:new Date}},N=async(e,o=null)=>{let t=z(),r=H(),i=(0,n.getAuthCallback)(),a=JSON.parse((0,n.getFromLocalStorage)(b,!0));null!=o&&(i+=`?BackUrl=${encodeURI(o)}`);const s={code:e,grant_type:"authorization_code",code_verifier:a.codeVerifier,client_id:encodeURI(r),redirect_uri:encodeURI(i)};try{const e=await fetch(`${t}/oauth2/token`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(s)}).catch((function(e){console.log("Request failed:",e.message)})),o=await e.json();let{access_token:n,refresh_token:r,id_token:i,expires_in:a,error:l,error_description:c}=o;return{access_token:n,refresh_token:r,id_token:i,expires_in:a,error:l,error_description:c}}catch(e){console.log(e)}},D=async()=>{if(await(0,n.retryPromise)((()=>T.acquireLock(I,5e3)),10))try{let e=B();if(!e)throw Error("Missing Auth info.");let{accessToken:o,expiresIn:t,accessTokenUpdatedAt:n,refreshToken:r}=e;M(null,0,r)}finally{await T.releaseLock(I)}},F=async()=>{if(await(0,n.retryPromise)((()=>T.acquireLock(I,5e3)),10))try{let e=B();if(!e)throw Error("Missing Auth info.");let{accessToken:o,expiresIn:t,accessTokenUpdatedAt:n,refreshToken:r}=e,i=V(),a=Math.floor(Date.now()/1e3);if(t-=E,a-n>t||null==o){if(console.log("getAccessToken access token expired"),i===R&&K()){if(!r)throw G(),Error("missing Refresh Token");let e=await $(r),{access_token:o,expires_in:t,refresh_token:n}=e;return void 0===n&&(n=null),M(o,t,n),o}throw G(),Error("Access Token Expired.")}return o}finally{await T.releaseLock(I)}throw Error("Lock acquire error.")},$=async e=>{let o=z(),t=H();const r={grant_type:"refresh_token",client_id:encodeURI(t),refresh_token:e};try{const e=await fetch(`${o}/oauth2/token`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(r)}).then((e=>{if(400===e.status){(0,n.getCurrentPathName)();throw(0,n.setSessionClearingState)(!0),Error(`${e.status} - ${e.statusText}`)}return e})).catch((function(e){throw Error(`Request failed: ${e.message}`)})),t=await e.json();let{access_token:i,refresh_token:a,expires_in:s}=t;return{access_token:i,refresh_token:a,expires_in:s}}catch(e){throw console.log(e),e}},M=(e,o,t=null,r=null)=>{let i=B(),a={accessToken:e,expiresIn:o,accessTokenUpdatedAt:Math.floor(Date.now()/1e3)};null===t&&i&&(t=i.refreshToken),null===r&&i&&(r=i.idToken),t&&(a.refreshToken=t),r&&(a.idToken=r),(0,n.putOnLocalStorage)(U,JSON.stringify(a))},B=()=>{let e=(0,n.getFromLocalStorage)(U,!1);return null===e?null:JSON.parse(e)},G=()=>{if("undefined"!=typeof window)return(0,n.removeFromLocalStorage)(U),(0,n.removeFromLocalStorage)(A),void(0,n.removeFromLocalStorage)(b)},J=()=>{if("undefined"!=typeof window){const e=B();return e?e.idToken:null}return null},H=()=>"undefined"!=typeof window?window.OAUTH2_CLIENT_ID:null,V=()=>"undefined"!=typeof window&&window.OAUTH2_FLOW||"token id_token",K=()=>"undefined"==typeof window||new Boolean(window.OAUTH2_USE_REFRESH_TOKEN||!0),z=()=>"undefined"!=typeof window?window.IDP_BASE_URL:null,W=()=>"undefined"!=typeof window?window.SCOPES:null,Y=()=>{(0,n.getCurrentLocation)().replace(P(J()).toString())},Q=(e,o,t)=>{let r=new(p())({issuer:o,audience:t}),i=(0,n.getFromLocalStorage)(A,!0),a=r.decode(e),s=(a.header.alg,a.header.kid,a.payload.aud),l=a.payload.iss;a.payload.exp,a.payload.nbf;return(a.payload.nonce||null)==i&&s==t&&l==o},X=e=>{let o=H(),t=W(),r=x(16);(0,n.putOnLocalStorage)(A,r);let i=z(),a=d()(`${i}/oauth2/auth`),s={response_type:"otp",scope:encodeURI(t),nonce:r,client_id:encodeURI(o),connection:e.connection||"email",send:e.send||"code"};return e.hasOwnProperty("email")&&(s.email=encodeURIComponent(e.email)),e.hasOwnProperty("phone_number")&&(s.phone_number=encodeURIComponent(e.phone_number)),e.hasOwnProperty("redirect_uri")&&(s.redirect_uri=encodeURIComponent(e.redirect_uri)),O.post(a.toString()).send(s).then((e=>{let o=e.body;return Promise.resolve({response:o})})).catch((e=>Promise.reject(e)))},Z=e=>o=>{let t=H(),n=W(),r=z(),i=d()(`${r}/oauth2/token`);if(!e.hasOwnProperty("otp"))throw Error("otp param is mandatory.");let a={grant_type:"passwordless",connection:e.connection||"email",scope:encodeURI(n),client_id:encodeURI(t),otp:e.otp};return e.hasOwnProperty("email")&&(a.email=encodeURIComponent(e.email)),e.hasOwnProperty("phone_number")&&(a.phone_number=encodeURIComponent(e.phone_number)),O.post(i.toString()).send(a).then((e=>{try{let n=e.body,{access_token:i,expires_in:a,refresh_token:s,id_token:l}=n;if(void 0===s&&(s=null),void 0===l&&(l=null),l&&!Q(l,r,t))throw Error("id token is not valid.");return M(i,a,s,l),o&&o({type:f.SET_LOGGED_USER,payload:{sessionState:null}}),Promise.resolve({response:n})}catch(e){return console.log(e),Promise.reject(e)}})).catch((e=>Promise.reject(e)))}},4054:(e,o,t)=>{t(4824),t(6530),t(271),t(4656),t(6793),t(4341),t(8576);const n=e=>o=>({type:e,payload:o});n("RESET_LOADING"),n("START_LOADING"),n("STOP_LOADING")},6793:(e,o,t)=>{t.d(o,{base64URLEncode:()=>u,getAuthCallback:()=>n,getCurrentLocation:()=>r,getCurrentPathName:()=>a,getFromLocalStorage:()=>l,getOrigin:()=>i,putOnLocalStorage:()=>s,removeFromLocalStorage:()=>c,retryPromise:()=>p,setSessionClearingState:()=>d});t(8362),t(6530);const n=()=>"undefined"!=typeof window?`${window.location.origin}/auth/callback`:null,r=()=>{let e="";return"undefined"!=typeof window&&(e=window.location,window.top&&(e=window.top.location)),e},i=()=>"undefined"!=typeof window?window.location.origin:null,a=()=>"undefined"!=typeof window?window.location.pathname:null,s=(e,o)=>{"undefined"!=typeof window&&window.localStorage.setItem(e,o)},l=(e,o)=>{if("undefined"!=typeof window){let t=window.localStorage.getItem(e);return o&&(console.log(`getFromLocalStorage removing key ${e}`),c(e)),t}return null},c=e=>{"undefined"!=typeof window&&window.localStorage.removeItem(e)},d=e=>{"undefined"!=typeof window&&(window.clearing_session_state=e)},u=e=>e.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,""),p=async(e,o=3)=>{for(let t=0;t<o;t++)if(await e())return!0;return!1}},4656:e=>{e.exports=require("i18n-react/dist/i18n-react")},3856:e=>{e.exports=require("idtoken-verifier")},8362:e=>{e.exports=require("moment-timezone")},4824:e=>{e.exports=require("superagent")},271:e=>{e.exports=require("sweetalert2")},6530:e=>{e.exports=require("urijs")}},o={};function t(n){var r=o[n];if(void 0!==r)return r.exports;var i=o[n]={exports:{}};return e[n](i,i.exports,t),i.exports}return(()=>{t.n=e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return t.d(o,{a:o}),o}})(),(()=>{t.d=(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})}})(),(()=>{t.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o)})(),(()=>{t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})(),t(8576)})()));
|