pastebin - collaborative debugging tool
kpaste.net RSS


whatever
Posted by Anonymous on Thu 19th Nov 2020 11:57
raw | new post

  1. var utilityFunctions = {
  2.   getFormProgressMeterContaineParent: function(){
  3.     var formProgressMeterContaineParent = document.querySelector("#form-progress-meter-container-parent");
  4.     if(!formProgressMeterContaineParent){
  5.       formProgressMeterContaineParent = document.createElement("div");
  6.       formProgressMeterContaineParent.id = "form-progress-meter-container-parent";
  7.       formProgressMeterContaineParent.innerHTML = `
  8.       <div id="form-progress-meter-container">
  9.         <div class="" id="form-progress-meter-bg"></div>
  10.         <svg id="form-progress-meter-svg">
  11.           <text _ngcontent-c11="" alignment-baseline="middle" id="form-progress-circle-text" style="font-size: 17px;" text-anchor="middle" x="50%" y="50%" stroke="#227a9f">0%</text>
  12.           <path _ngcontent-c11="" fill="none" id="percentage-arc-2" stroke="#e9eaec" stroke-width="4" d="M 70.31088913245536 57.5 A 35 35 0 1 0 9.689110867544649 57.5"></path>
  13.           <path _ngcontent-c11="" fill="none" id="form-progress-circle" stroke="#34768f" stroke-width="5" d="M 9.689110867544649 57.5 A 35 35 0 0 0 9.689110867544649 57.5"></path>
  14.         </svg>
  15.       </div>
  16.       <div id="form-progress-meter-infos-container">
  17.         <div id="form-progress-meter-infos-title1">Etape2 test</div>
  18.         <div id="form-progress-meter-infos-title2">Rattachement des documents</div>
  19.       </div>`;
  20.       document.body.insertBefore(formProgressMeterContaineParent, document.body.firstElementChild);
  21.     }
  22.     return formProgressMeterContaineParent;
  23.   },
  24.   generateUibStyleSheet: function(){
  25.     var uibStyleSheet = document.querySelector("#uib-stylesheet");
  26.     if(!uibStyleSheet){
  27.       uibStyleSheet = document.createElement("link");
  28.       uibStyleSheet.id = "uib-stylesheet";
  29.       uibStyleSheet.href="./styles/custom-login-styles/uib/style.css";
  30.       uibStyleSheet.setAttribute("rel", "stylesheet");
  31.       document.head.appendChild(uibStyleSheet);
  32.     }
  33.   },
  34.   drawProgressMeter: function(formProgressMeterContaineParent, progressPercentage, pageNumber) {
  35.     // function to draw an SVG percentage circle
  36.     function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
  37.       //function to convert polar coordinates to cartesian coordinates
  38.       let angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;
  39.  
  40.       return {
  41.         x: centerX + radius * Math.cos(angleInRadians),
  42.         y: centerY + radius * Math.sin(angleInRadians)
  43.       };
  44.     }
  45.  
  46.     function describeArc(x, y, radius, startAngle, endAngle) {
  47.       //function for drawing the SVG percentage Arc
  48.  
  49.       const start = polarToCartesian(x, y, radius, endAngle);
  50.       const end = polarToCartesian(x, y, radius, startAngle);
  51.  
  52.       const largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1";
  53.  
  54.       let d = [
  55.         "M",
  56.         start.x,
  57.         start.y,
  58.         "A",
  59.         radius,
  60.         radius,
  61.         0,
  62.         largeArcFlag,
  63.         0,
  64.         end.x,
  65.         end.y
  66.       ].join(" ");
  67.  
  68.       return d;
  69.     }
  70.     let percentageText = Math.round(progressPercentage);
  71.     let endAngle = ((240/100)*progressPercentage) - 120;
  72.     //console.log("endAngle = ", endAngle);
  73.     document.getElementById("form-progress-circle")
  74.     .setAttribute("d", describeArc(40, 40, 35, -120, endAngle));
  75.     document.getElementById("percentage-arc-2")
  76.     .setAttribute("d", describeArc(40, 40, 35, -120, 120));
  77.      document.getElementById("form-progress-circle-text").textContent = percentageText + "%";
  78.      document.getElementById("form-progress-circle").setAttribute("stroke", "#34768f");
  79.      formProgressMeterContaineParent.querySelector("#form-progress-meter-infos-title1").innerHTML = "&Eacute;TAPE "+pageNumber;
  80.      var pageTitle = formContainer.pages[formContainer.page].title;
  81.      formProgressMeterContaineParent.querySelector("#form-progress-meter-infos-title2").innerHTML = pageTitle;
  82.   }
  83. }
  84. var iframeHeight;
  85. /**
  86.  * General-purpose function to apply fixes on the DOM on form render
  87.  * @param {Object} formContainer Formio Object (a form wizard)
  88.  */
  89. function formioFixes(formContainer){
  90.   function callback1(domElement){
  91.     let textareaElements = domElement.querySelectorAll(".formio-component-datagrid td textarea");
  92.     //console.log("textareaElements = ", textareaElements);
  93.     for(let index = 0; index < textareaElements.length; index++){
  94.       let textareaElement = textareaElements[index];
  95.       textareaElement.style.height= '0px';
  96.       textareaElement.style.height = (textareaElement.scrollHeight + 1) + 'px';
  97.     }
  98.   }
  99.  
  100.   function callback2(){
  101.     window.addEventListener("resize", function(event){
  102.       let resizeId;
  103.       clearTimeout(resizeId);
  104.       resizeId = setTimeout(callback1(document, true), 750);  
  105.     });
  106.   }
  107.   function callback3(){
  108.     window['renderCount'] = ( (window['renderCount'] === undefined) ? 1 : (window['renderCount'] + 1) )
  109.     window['clientName'] = window.parent.window["clientName"];
  110.       if(window["clientName"]){
  111.         switch(window["clientName"]){
  112.           case("UIB"):
  113.           utilityFunctions.generateUibStyleSheet();
  114.           var subscriptionformtextcomponentElement = document.querySelector(".subscriptionformtextcomponent");
  115.           if(subscriptionformtextcomponentElement){
  116.             document.documentElement.classList.add("uib-subscribe-form");
  117.             console.log("adding uib form progress meter !");
  118.            
  119.             var formProgressMeterContaineParent = utilityFunctions.getFormProgressMeterContaineParent();
  120.             var pageNumber = formContainer.page + 1;
  121.             var pages = formContainer.pages.length;
  122.             var percentage = Math.round(pageNumber*(100/pages));
  123.             utilityFunctions.drawProgressMeter(formProgressMeterContaineParent, percentage, pageNumber);
  124.             break;
  125.           }
  126.         }
  127.       }
  128.       else{ //nothing yet..
  129.       }
  130.    
  131.   }
  132.   formContainer.on("render", function(ev){
  133.     callback1(document);
  134.     callback2();
  135.     callback3();
  136.     resizeIframe();
  137.   });
  138.   formContainer.on("change", function(ev){
  139.     resizeIframe();
  140.   });
  141.   formContainer.on("error", function(ev){
  142.     resizeIframe();
  143.   });
  144.   formContainer.on("submit", function(ev){
  145.     resizeIframe();
  146.   });
  147. }
  148. // Applying data to the form
  149. // ~applyDataDemo(requestExample.variables, formContainer, function() {
  150. //      console.log("post apply data callback");
  151. // })
  152. var applyDataDemo = function (data, formioObject, callback) {
  153.   extranet.applyData(data, formioObject, callback)
  154. };
  155.  
  156. // validating the form
  157. // ~validateFormDemo(formContainer)
  158. var validateFormDemo = function (formioObject) {
  159.   return extranet.validateForm(formioObject);
  160. };
  161.  
  162. // Test is The Form In The Last Page
  163. // ~isTheFormInTheLastPageDemo(formContainer)
  164. var isTheFormInTheLastPageDemo = function (formioObject) {
  165.   return extranet.isTheFormInTheLastPage(formioObject);
  166. };
  167.  
  168. // extracting the data from the form
  169. // ~getDataToSubmitDemo(formContainer, JSON.parse(requestExample.form), requestExample.prefix)
  170. var getDataToSubmitDemo = function (formioObject, formConfig, prefix) {
  171.   return
  172. };
  173.  
  174. var data;
  175.  
  176. var bootstrapStyle;
  177.  
  178. var requestId;
  179.  
  180. var language;
  181.  
  182. var connectedUsername;
  183.  
  184. var connectedUserRoles;
  185.  
  186. var connectedUserDetails;
  187.  
  188. var connectedNumCorrespondance;
  189.  
  190. var showSpinner
  191.  
  192. var hideSpinner
  193.  
  194. var recaptchaSiteKey;
  195.  
  196. var callbacks = window.parent.window.callbacks;
  197.  
  198. var form;
  199.  
  200. var platform;
  201.  
  202. var formContainer;
  203.  
  204. window.parent.window.isLastPage = function (prefix) {
  205.   if (isTheFormInTheLastPageDemo(formContainer) == 1)
  206.     return {
  207.       status: 200
  208.     }
  209.   else return {
  210.     status: 400
  211.   }
  212. }
  213.  
  214. window.parent.window.validate = function (prefix) {
  215.  
  216.   if (validateFormDemo(formContainer) == 1)
  217.     return {
  218.       status: 200,
  219.       body: extranet.getDataToSubmit(formContainer, JSON.parse(form), prefix)
  220.     }
  221.   else return {
  222.     status: 400
  223.   }
  224.  
  225. }
  226.  
  227. window.parent.window.saveTask = function (prefix) {
  228.     return {
  229.       body: extranet.getDataToSubmit(formContainer, JSON.parse(form), prefix)
  230.     }
  231. }
  232.  
  233. window.parent.window.render = function (params) {
  234.  
  235.   data = window.parent.window.data;
  236.   bootstrapStyle = window.parent.window.bootstrapStyle;
  237.   requestId = window.parent.window.requestId;
  238.   language = window.parent.window.language;
  239.   connectedUsername = window.parent.window.connectedUsername;
  240.   connectedUserRoles = window.parent.window.connectedUserRoles;
  241.   connectedUserDetails = window.parent.window.connectedUserDetails;
  242.   connectedNumCorrespondance = window.parent.window.connectedNumCorrespondance;
  243.   recaptchaSiteKey = window.parent.window.recaptchaSiteKey;
  244.   showSpinner =  window.parent.window.showSpinner;
  245.   hideSpinner =  window.parent.window.hideSpinner;
  246.   platform =  window.parent.window.platform;
  247.   window.isloading = true;
  248.  
  249.  
  250.   if(language == undefined){
  251.     language = localStorage.getItem('language');
  252.   }
  253.  
  254.   window.parent.window.Alfresco = { constants: { JS_LOCALE : language}};
  255.  
  256.   if(bootstrapStyle == null) {
  257.     bootstrapStyle = "bootstrap-default.css";
  258.   }
  259.  
  260.   if(bootstrapStyle == "bootstrap-default.css" && language == "ar"){
  261.     bootstrapStyle = "bootstrap-default-rtl.css"
  262.   }
  263.  
  264.   document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeend",'<link rel="stylesheet" type="text/css" href="styles/bootstrap/' + bootstrapStyle + '">');
  265.  
  266.   if(language == "ar"){
  267.     document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeend",'<link rel="stylesheet" type="text/css" href="styles/formio-rtl.full.css">');
  268.   } else {
  269.     document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeend",'<link rel="stylesheet" type="text/css" href="styles/formio.full.css">');
  270.   }
  271.  
  272.   form = data.form.replace(/\\n/g, "\\n");
  273.   form = form.replace(/\\'/g, "\\'");
  274.   form = form.replace(/\\&/g, "\\&");
  275.   form = form.replace(/\\r/g, "\\r");
  276.   form = form.replace(/\\t/g, "\\t");
  277.   form = form.replace(/\\b/g, "\\b");
  278.   form = form.replace(/\\f/g, "\\f");
  279.  
  280.  
  281.   formContainer = extranet.renderForm('formio', JSON.parse(form), data.readOnly,language);
  282.  
  283.   formioFixes(formContainer)
  284.  
  285.   formContainer.ready.then(function () {
  286.     applyDataDemo(JSON.parse(data.variables), formContainer, function () {
  287.       callbacks.ready();
  288.  
  289.       onFormioHeightChange(document.getElementById("formio"), function () {
  290.         //callbacks.resize();
  291.       window.isloading = false;
  292.       });
  293.       onWizardFormioScroll();
  294.     });
  295.     this.initMap();
  296.   });
  297.  
  298. }
  299. function resizeIframe(){ //resize parent frame correctly
  300.   /*window.frameElement.style.height = "0px";
  301.   var angularMainTag = window.parent.document.querySelector("body > app-root > main");
  302.   var angularFooter = window.parent.document.querySelector("body > app-root > footer");
  303.   //console.log("angularMainTag = ", angularMainTag);
  304.   if(angularMainTag){
  305.     window.frameElement.style.minHeight = (window.parent.innerHeight - window.frameElement.getBoundingClientRect().top - angularFooter.clientHeight - 29 + 3)+"px";
  306.   }
  307.   else{
  308.     window.frameElement.style.minHeight = "auto";
  309.   }
  310.  
  311.  
  312.  
  313.  
  314.   (window.parent.innerHeight - (window.frameElement.getBoundingClientRect().top
  315.     - angularMainTag.getBoundingClientRect().top) - parseInt(getComputedStyle(angularMainTag).paddingTop))+"px";
  316.   var newIframeHeight = (document.documentElement.scrollHeight) + 3;
  317.   if(newIframeHeight != iframeHeight){
  318.     iframeHeight = newIframeHeight;
  319.     window.frameElement.style.height = newIframeHeight + 'px';
  320.   }*/
  321. }
  322.  
  323. function onFormioHeightChange(elm, callback) {
  324.   var lastHeight = elm.clientHeight,
  325.     newHeight;
  326.   (function run() {
  327.     newHeight = elm.clientHeight;
  328.     if (lastHeight != newHeight)
  329.       callback();
  330.     lastHeight = newHeight;
  331.  
  332.     if (elm.onElementHeightChangeTimer)
  333.       clearTimeout(elm.onElementHeightChangeTimer);
  334.  
  335.     elm.onElementHeightChangeTimer = setTimeout(run, 200);
  336.   })();
  337. }
  338.  
  339. function onWizardFormioScroll() {
  340.   if(JSON.parse(form).display !== 'wizard') {
  341.     return;
  342.   }
  343.  
  344.   var lastScrollTop = 0;
  345.   /*window.addEventListener('scroll',function(e) {
  346.     var st = window.pageYOffset || document.documentElement.scrollTop;
  347.     if(st === 0) {
  348.       document.body.classList.remove("wizard-scroll-down");
  349.       document.body.classList.remove("wizard-scroll-up");
  350.     } else
  351.     if (st < lastScrollTop){
  352.       document.body.classList.add("wizard-scroll-down");
  353.       document.body.classList.remove("wizard-scroll-up");
  354.     } else {
  355.       document.body.classList.remove("wizard-scroll-down");
  356.       document.body.classList.add("wizard-scroll-up");
  357.     }
  358.     lastScrollTop = st <= 0 ? 0 : st;
  359.   });*/
  360. }
  361.  
  362. function initMap() {
  363.   if(formContainer != null) {
  364.     var geoVneuron = formContainer.data["var-geoVneuron"];
  365.     if(geoVneuron != null) {
  366.       // The map
  367.       var map = new google.maps.Map(document.getElementById('vneuronMap'));
  368.       // custom positions
  369.       var bounds = new google.maps.LatLngBounds();
  370.       var positions = geoVneuron.split('+');
  371.       positions.forEach(element => {
  372.         var mark = element.split(',');
  373.                
  374.                     var contentString = '<div id="content">'+
  375.             '<div id="siteNotice">'+
  376.             '</div>'+
  377.             '<h4 id="firstHeading" class="firstHeading">' + mark[2] + '</h4>'+
  378.             '<div id="bodyContent">'+
  379.             '<h5>' + mark[3] +'</H5>'+
  380.                   '<h5>' + mark[4] +'</H5>'+
  381.                   '<h5>' + mark[5] +'</H5>'+
  382.             '</div>'+
  383.             '</div>';
  384.  
  385.                     var infowindow = new google.maps.InfoWindow({
  386.                         content: contentString
  387.                     });
  388.      
  389.         var marker = new google.maps.Marker({position: {lat: Number(mark[0]), lng: Number(mark[1])},title: mark[2] , map: map});
  390.                     marker.addListener('mouseover', function() {
  391.           infowindow.open(map, marker);
  392.         });
  393.      
  394.         marker.addListener('mouseout', function() {
  395.           infowindow.close();
  396.         });
  397.      
  398.         bounds.extend(new google.maps.LatLng(Number(mark[0]), Number(mark[1])));
  399.       });
  400.       // map zoom
  401.       map.fitBounds(bounds);
  402.     }
  403.   }
  404. };
  405.  
  406. if(callbacks != null || callbacks != undefined){
  407.   callbacks.init();
  408. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at