UNPKG

openstack-uicore-foundation

Version:

ui reactjs components for openstack marketing site

2 lines 5.41 kB
!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={9558:(e,t,s)=>{s.d(t,{toSlug:()=>i});s(5812),s(8041);const i=e=>(e=e.toLowerCase()).replace(/[^a-zA-Z0-9]+/g,"_")},1116:e=>{e.exports=require("@babel/runtime/helpers/defineProperty")},5812:e=>{e.exports=require("moment-timezone")},8041:e=>{e.exports=require("urijs")}},t={};function s(i){var o=t[i];if(void 0!==o)return o.exports;var r=t[i]={exports:{}};return e[i](r,r.exports,s),r.exports}(()=>{s.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return s.d(t,{a:t}),t}})(),(()=>{s.d=(e,t)=>{for(var i in t)s.o(t,i)&&!s.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})}})(),(()=>{s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})();var i={};s.r(i),s.d(i,{AllowedMultipleValueQuestionType:()=>c,AnswerValuesOperator_And:()=>f,AnswerValuesOperator_Or:()=>d,CheckBoxListQuestionType:()=>h,CheckBoxQuestionType:()=>l,ComboBoxQuestionType:()=>p,MainQuestionClassType:()=>m,RadioButtonListQuestionType:()=>_,VisibilityCondition_Equal:()=>y,VisibilityCondition_NotEqual:()=>b,Visibility_Visible:()=>w,default:()=>v});var o=s(1116),r=s.n(o),n=s(9558);function u(e,t){var s=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),s.push.apply(s,i)}return s}function a(e){for(var t=1;t<arguments.length;t++){var s=null!=arguments[t]?arguments[t]:{};t%2?u(Object(s),!0).forEach((function(t){r()(e,t,s[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(s)):u(Object(s)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(s,t))}))}return e}const l="CheckBox",p="ComboBox",h="CheckBoxList",_="RadioButtonList",c=[p,h,_],f="And",d="Or",y="Equal",b="NotEqual",w="Visible",m="MainQuestion";class v{constructor(e,t=[]){r()(this,"_parseQuestion",(e=>{if(this.questionByName[(0,n.toSlug)(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)})),r()(this,"_parseQuestions",(()=>{for(let e of this.questions)this._parseQuestion(e)})),r()(this,"_allowsValues",(e=>c.includes(e.type))),r()(this,"_allowsValue",((e,t)=>{let s=t.value.split(",").map((e=>parseInt(e)));for(let t of s)if(!e.values.map((e=>e.id)).includes(t))return!1;return!0})),r()(this,"_getAnswerFor",(e=>{let t=Number.isInteger(e)?e:e.id,s=this.answers[t]||null;return s||null})),r()(this,"_hasValue",(e=>""!==e.value)),r()(this,"_answerContains",((e,t)=>e.value.split(",").includes(t))),r()(this,"_isSubQuestionVisible",(e=>{let t=e.answer_values_operator===f;const s=this._getAnswerFor(e.parent_question_id);if(s)switch(e.visibility_condition){case y:for(let i of e.answer_values)t=e.answer_values_operator===f?t&&this._answerContains(s,i):t||this._answerContains(s,i);break;case b:for(let i of e.answer_values)t=e.answer_values_operator===f?t&&!this._answerContains(s,i):t||!this._answerContains(s,i)}else t=e.visibility_condition!==y;return e.visibility===w?t:!t})),r()(this,"_isAnswered",(e=>{const t=this._getAnswerFor(e);if(e.class===m)return!e.mandatory||!!t&&(!!this._hasValue(t)&&!(this._allowsValues(e)&&!this._allowsValue(e,t)));for(let s of e.parent_rules)if(this._isSubQuestionVisible(this.rules[s]))return!e.mandatory||!!t&&(!!this._hasValue(t)&&!(this._allowsValues(e)&&!this._allowsValue(e,t)));return!0})),r()(this,"_checkQuestion",(e=>{let t=this._isAnswered(e);if(e.hasOwnProperty("sub_question_rules"))for(let s of e.sub_question_rules)t=t&&this._checkQuestion(s.sub_question);return t})),r()(this,"_formatQuestionAnswer",(e=>{var t,s;let i={};const o=(0,n.toSlug)(e.name);let r=null===(t=this.originalAnswers.find((t=>t.question_id===e.id)))||void 0===t?void 0:t.value;if(!r&&(null==e||null===(s=e.values)||void 0===s?void 0:s.length)>0){const t=e.values.find((e=>e.is_default));t&&(r=t.id.toString())}if(r&&(e.type===l&&(r="false"!==r&&!!r),e.type!==_&&e.type!==p||(r=parseInt(r)),e.type===h&&(r=r.split(",").map((e=>parseInt(e)))||[])),i[o]=r||"",e.type===h&&""===i[o]&&(i[o]=[]),e.hasOwnProperty("sub_question_rules"))for(let t of e.sub_question_rules){let e=this._formatQuestionAnswer(t.sub_question);i=a(a({},i),e)}return i})),r()(this,"formatAnswers",(()=>{let e={};return this.questions.forEach((t=>{let s=this._formatQuestionAnswer(t);e=a(a({},e),s)})),e})),r()(this,"completed",(()=>{let e=!0;for(let t of this.questions)e=e&&this._checkQuestion(t);return e})),r()(this,"getQuestionByName",(e=>{const t=(0,n.toSlug)(e);return this.questionByName[e]||this.questionByName[t]||null})),r()(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()}}return i})())); //# sourceMappingURL=questions-set.js.map