No Description

viewExperience.js 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. ///// !!! viewExperience.php !!! /////
  2. // Get tab links and tab panes
  3. let tabLinks = document.querySelectorAll('#view-experience-tabs a');
  4. let tabPanes = document.querySelectorAll('.main-content-box');
  5. // Add event listener to all tab links
  6. // tabLinks.forEach(tabLink => {
  7. // tabLink.addEventListener('click', tabChange);
  8. // });
  9. window.onload = tabChange;
  10. window.onhashchange = tabChange;
  11. // Add selected link style and remove those who were not selected
  12. function tabChange() {
  13. let hash = document.location.hash;
  14. validHashes = ['#calendar', '#questionnaires', '#moments', '#milestones'];
  15. if(!validHashes.includes(hash)) {
  16. hash = '#calendar';
  17. }
  18. // Change the style of the links
  19. tabLinks.forEach(tabLink => {
  20. if(tabLink.hash === hash) {//tabLink === e.target
  21. tabLink.classList.add('active');
  22. } else {
  23. tabLink.classList.remove('active');
  24. }
  25. });
  26. // Change the opacity of each of the panes
  27. tabPanes.forEach(tabPane => {
  28. if(tabPane.id === hash.substring(1)) {// tabPane.id === e.target.hash.substring(1)
  29. tabPane.classList.add('show');
  30. } else {
  31. tabPane.classList.remove('show');
  32. }
  33. });
  34. // Re-render calendar
  35. if(calendar && hash === '#calendar') {
  36. calendar.render();
  37. }
  38. }
  39. function newThing(e) {
  40. let type = e.currentTarget.value;
  41. let range = e.currentTarget.parentNode.parentNode.parentNode.nextElementSibling; // get the 4 (optional) inputs for scaled-type questions
  42. range.style.display = (type === "1") ? 'block' : 'none'; // "1" corresponds to scaled questions
  43. }
  44. // Add Question to Questionnaire
  45. var Questions = 1;
  46. function addQuestion() {
  47. // We add a linebreak so that there is space between each dropdown list
  48. var br = document.createElement("br");
  49. document.querySelector('#q'+Questions).parentElement.lastElementChild.previousElementSibling.previousElementSibling.insertAdjacentElement('afterend', br);
  50. // We create a copy of the dropdown list we already have, so multiple questions can be added at the same time.
  51. var newQuestion = document.getElementById("q"+Questions);
  52. var clone = newQuestion.cloneNode(true);
  53. //The clones will have the same name as the original but with a number that will distinguish them
  54. var newName = 'q' + Number(Questions + 1);
  55. clone.id = newName;
  56. document.querySelector('#q'+Questions).parentElement.lastElementChild.previousElementSibling.previousElementSibling.insertAdjacentElement('afterend', clone);
  57. document.querySelector('#'+newName+' h4').innerHTML = 'Question '+Number(Questions+1);
  58. document.querySelector('#'+newName+' #q_premise'+Questions).name = 'q_premise'+Number(Questions+1);
  59. document.querySelector('#'+newName+' #q_premise'+Questions).id = 'q_premise'+Number(Questions+1);
  60. // Get the question type before changing it's name/id (for some reason it doesn't pass it on)
  61. let type = $(newQuestion).find("#q_type"+Questions).val();
  62. document.querySelector('#'+newName+' #q_type'+Questions).value = type;
  63. document.querySelector('#'+newName+' #q_type'+Questions).name = 'q_type'+Number(Questions+1);
  64. document.querySelector('#'+newName+' #q_type'+Questions).id = 'q_type'+Number(Questions+1);
  65. // Depending on the question type, display or hide min/max values/labels
  66. if(type == "1") {
  67. document.querySelector('#'+newName+' #range'+Questions).style.display = "block";
  68. } else if(type == "2") {
  69. document.querySelector('#'+newName+' #range'+Questions).style.display = "none";
  70. }
  71. document.querySelector('#'+newName+' #range'+Questions).id = 'range'+Number(Questions+1);
  72. document.querySelector('#'+newName+' #min_val'+Questions).name = 'min_val'+Number(Questions+1);
  73. document.querySelector('#'+newName+' #min_val'+Questions).id = 'min_val'+Number(Questions+1);
  74. document.querySelector('#'+newName+' #min_text'+Questions).name = 'min_text'+Number(Questions+1);
  75. document.querySelector('#'+newName+' #min_text'+Questions).id = 'min_text'+Number(Questions+1);
  76. document.querySelector('#'+newName+' #max_val'+Questions).name = 'max_val'+Number(Questions+1);
  77. document.querySelector('#'+newName+' #max_val'+Questions).id = 'max_val'+Number(Questions+1);
  78. document.querySelector('#'+newName+' #max_text'+Questions).name = 'max_text'+Number(Questions+1);
  79. document.querySelector('#'+newName+' #max_text'+Questions).id = 'max_text'+Number(Questions+1);
  80. // Get the question type before changing it's name/id (for some reason it doesn't pass it on)
  81. let category = $(newQuestion).find("#q_category"+Questions).val();
  82. document.querySelector('#'+newName+' #q_category'+Questions).value = category;
  83. document.querySelector('#'+newName+' #q_category'+Questions).name = 'q_category'+Number(Questions+1);
  84. document.querySelector('#'+newName+' #q_category'+Questions).id = 'q_category'+Number(Questions+1);
  85. // Get the question type before changing it's name/id (for some reason it doesn't pass it on)
  86. let subcategory = $(newQuestion).find("#q_subcategory"+Questions).val();
  87. document.querySelector('#'+newName+' #q_subcategory'+Questions).value = subcategory;
  88. document.querySelector('#'+newName+' #q_subcategory'+Questions).name = 'q_subcategory'+Number(Questions+1);
  89. document.querySelector('#'+newName+' #q_subcategory'+Questions).id = 'q_subcategory'+Number(Questions+1);
  90. Questions++;
  91. // $('[form]:not(button[form])').keypress(function(event){if (event.which == '13') { event.preventDefault(); } } );
  92. }
  93. // For new questionnaires, create the dropdown for category selection
  94. let categoriesString = document.querySelector('#q_categories_tentative');
  95. categoriesString.addEventListener('change', function() {
  96. // split input by commas
  97. let x = document.getElementById('q_categories_tentative').value.split(',');
  98. let y;// = '<option disabled selected>Category</option>';
  99. // clear any whitespace from each word in the split input
  100. for(let i = 0; i < x.length; i++) {
  101. x[i] = x[i].trim();
  102. // if string not empty and not whitespace, insert as category option
  103. if(/\S/.test(x[i])) {
  104. y += '<option value="'+x[i]+'">'+x[i]+'</option>';
  105. }
  106. }
  107. // change the selectable categories
  108. $("[id^=q_category]").html(y);
  109. });
  110. // For new questionnaires, create the dropdowns for subcategory selection
  111. let subcategoriesString = document.querySelector('#q_subcategories_tentative');
  112. subcategoriesString.addEventListener('change', function() {
  113. // split input by commas
  114. let x = document.getElementById('q_subcategories_tentative').value.split(',');
  115. let y;// = '<option disabled selected>Subcategory</option>';
  116. // clear any whitespace from each word in the split input
  117. for(let i = 0; i < x.length; i++) {
  118. x[i] = x[i].trim();
  119. // if string not empty and not whitespace, insert as category option
  120. if(/\S/.test(x[i])) {
  121. y += '<option value="'+x[i]+'">'+x[i]+'</option>';
  122. }
  123. }
  124. // change the selectable categories
  125. $("[id^=q_subcategory]").html(y);
  126. });
  127. // For new moments, create the dropdowns for question selection
  128. let correspondingQuestionnaire = document.querySelector('select#m_questionnaire');
  129. // User may not have a questionnaire yet, thus correspondingQuestionnaire might be null
  130. if(correspondingQuestionnaire) {
  131. correspondingQuestionnaire.addEventListener('change', function() {
  132. $.post(document.location.protocol + "//tania.uprrp.edu/admin_nuevo/special.php",
  133. {
  134. id_questionnaire: correspondingQuestionnaire.value
  135. },
  136. function(data, status) {
  137. $("select[id^=m_question_]").html(data);
  138. }
  139. );
  140. });
  141. }
  142. // Target the input fields to be updated
  143. let newStartDate = document.querySelector('input[name=newStart]');
  144. let newEndDate = document.querySelector('input[name=newEnd]');
  145. let newDuration = document.querySelector('input[name=newDuration]');
  146. var selectableQuestions = 1;
  147. function addSelectableQuestion() {
  148. var br = document.createElement("br");
  149. document.querySelector('#qq'+selectableQuestions).parentElement.lastElementChild.previousElementSibling.previousElementSibling.insertAdjacentElement('afterend', br);
  150. // We create a copy of the dropdown list we already have, so multiple questions can be added at the same time.
  151. var newQuestion = document.getElementById("qq"+selectableQuestions);
  152. var clone = newQuestion.cloneNode(true);
  153. //The clones will have the same name as the original but with a number that will distinguish them
  154. var newName = 'qq' + Number(selectableQuestions + 1);
  155. clone.id = newName;
  156. document.querySelector('#qq'+selectableQuestions).parentElement.lastElementChild.previousElementSibling.previousElementSibling.insertAdjacentElement('afterend', clone);
  157. document.querySelector('#'+newName+' h4').innerHTML = 'Question '+Number(selectableQuestions+1);
  158. document.querySelector('#'+newName+' #m_question_'+selectableQuestions).name = 'm_question_'+Number(selectableQuestions+1);
  159. document.querySelector('#'+newName+' #m_question_'+selectableQuestions).id = 'm_question_'+Number(selectableQuestions+1);
  160. selectableQuestions++;
  161. // $('[form]:not(button[form])').keypress(function(event){if (event.which == '13') { event.preventDefault(); } } );
  162. }