Brak opisu

view-objectives-criteria.blade.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. @extends('layouts.master')
  2. @section('navigation')
  3. @if (Auth::user()->role == 1)
  4. @include('local.managers.admins._new_navigation')
  5. @elseif(Auth::user()->role == 2)
  6. @include('local.managers.sCoords._new_navigation')
  7. @elseif(Auth::user()->role == 3)
  8. @include('local.managers.pCoords._new_navigation')
  9. @elseif(Auth::user()->role == 4)
  10. @include('local.professors._navigation')
  11. @endif
  12. @stop
  13. @section('main')
  14. {{-- TODO: look where to place this script.
  15. if placed inside .ready() or before it,
  16. an error that the function is not defined occurs. --}}
  17. {{-- TODO: no reconoce acentos --}}
  18. <script type="text/javascript">
  19. function filterObjectives() {
  20. // Declare variables
  21. var input, filter, div, li, i, objectiveText;
  22. input = document.getElementById('userInput');
  23. filter = input.value.toUpperCase();
  24. div = document.getElementById("list");
  25. li = div.getElementsByTagName('li');
  26. // Loop through all list items, and hide those who don't match the search query
  27. for (i = 0; i < li.length; i++) {
  28. objectiveText = li[i].textContent;
  29. if (objectiveText.toUpperCase().indexOf(filter) > -1) {
  30. li[i].style.display = "";
  31. } else {
  32. li[i].style.display = "none";
  33. }
  34. }
  35. }
  36. </script>
  37. <div class="row">
  38. <div class="col-md-3">
  39. <input class="form-control" type="text" id="userInput" onkeyup="filterObjectives()"
  40. placeholder="Search for Learning Outcomes..">
  41. <div class="list-group" id='list'>
  42. @foreach ($outcomes as $outcome)
  43. <li data-outcome-id="{{ $outcome->id }}" class="list-group-item">{{ $outcome->name }}</li>
  44. @endforeach
  45. </div>
  46. </div>
  47. <div class="col-md-9">
  48. <div id="objective-display" class="panel panel-default">
  49. <div class="panel-heading">
  50. <h4 class=" panel-title" style="cursor:auto!important;">
  51. </h4>
  52. </div>
  53. <div class="panel-body">
  54. <p class="objective-definition "></p>
  55. <div class="table-responsive table-responsive-0">
  56. <table class="table table-striped table-condensed datatable">
  57. <thead id="theHead">
  58. <th>Objective</th>
  59. <th>Program</th>
  60. <th>Match to Criteria</th>
  61. </thead>
  62. <tfoot>
  63. </tfoot>
  64. <tbody id="table_objectives">
  65. </tbody>
  66. </table>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="col-md-9">
  72. <div class="no-objective alert alert-info">
  73. <p>Select a Learning Objective to view its information</p>
  74. </div>
  75. </div>
  76. </div>
  77. <div id="match_criteria" class="modal fade" tabindex="-1" data-objective-id="0">
  78. <div class="modal-dialog">
  79. <div class="modal-content">
  80. <div class="modal-header">
  81. <h5 class="modal-title" id = 'match_criteria_title'></h5>
  82. <button type="button" class="close" data-dismiss="modal">&times;</button>
  83. </div>
  84. <div class="modal-body" id = "match_criteria_body">
  85. <p>The following criteria appear based on objective's programs and your available programs</p>
  86. <div class ='form-group col-md-12'>
  87. <select id="match_criteria_program" class ='form-control selectpicker select_program' onchange="changeCriteriaDisplayed('#match_criteria_program')">
  88. </select>
  89. </div>
  90. <hr>
  91. <div id="program_objectives">
  92. </div>
  93. </div>
  94. <div class="modal-footer">
  95. <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="$('#match_criteria').data('objective-id', '0');">Cancel</button>
  96. <button type="button" class="btn btn-primary" onclick = 'matchCriteriaToObjective("#match_criteria")'>Save</button>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <script>
  102. $(document).ready(function() {
  103. // --------------------------------------------------------------------------
  104. // Page load
  105. // --------------------------------------------------------------------------
  106. // Hide accordion panel contents by default
  107. $('.panel-group .panel-body').hide(); -
  108. $('#objective-display').parent().hide();
  109. // --------------------------------------------------------------------------
  110. // Functions
  111. // --------------------------------------------------------------------------
  112. /*
  113. */
  114. function fetchObjectives(li) {
  115. {
  116. var id = $(li).data('outcome-id');
  117. $.post(
  118. "{{ URL::action('Objective2Controller@fetchObjectivesForOutcome') }}", {
  119. id: id,
  120. },
  121. function(json) {
  122. // Retrieve datatable instance
  123. //var table = $('.table-responsive-0').;
  124. var name = $(li).html();
  125. //var definition = json.objective.program.name;
  126. //var criteria = json.objective.criteria;
  127. $('#objective-display').parent().show();
  128. $('.no-objective').parent().hide();
  129. //Display title and definition
  130. $('#objective-display .panel-title').html(name);
  131. // $('#objective-display .objective-definition').html(definition);
  132. //Empty table
  133. $('#table_objectives').empty();
  134. $.each(json, function(ind2, objective) {
  135. tr = $("<tr>");
  136. //objectives
  137. td_text = $("<td>",{
  138. 'id':"objective-"+objective.id
  139. }).html(objective.text);
  140. //programs
  141. td_programs = $("<td>");
  142. ol = $("<ol>");
  143. $.each(objective.programs, function(ind, prog) {
  144. li = $("<li>").html(prog.name);
  145. li.appendTo(ol);
  146. })
  147. ol.appendTo(td_programs);
  148. //link to criteria matching
  149. link_td = $("<td>");
  150. a = $('<a>',{
  151. 'onclick':'fetchCriteria(this)',
  152. 'data-objective-id': objective.id,
  153. 'data-outcome-id':id
  154. }).html("Change Associated Criteria");
  155. link_td.append(a)
  156. tr.append(td_text);
  157. tr.append(td_programs);
  158. tr.append(link_td)
  159. tr.appendTo($('#table_objectives'))
  160. })
  161. },
  162. 'json'
  163. );
  164. }
  165. }
  166. // --------------------------------------------------------------------------
  167. // Events
  168. // --------------------------------------------------------------------------
  169. // When list item is clicked, load corresponding info
  170. $('.list-group-item').on('click', function() {
  171. fetchObjectives(this);
  172. })
  173. });
  174. function createSelectForModal(options){
  175. div_master = $('<div>',{
  176. 'class':'removable_div'
  177. })
  178. div_select = $("<div>",{
  179. 'class':'form-group col-md-11',
  180. })
  181. select = $('<select>',{
  182. 'class':'selectpicker form-control criteria_select',
  183. 'name':'criteria[]'
  184. }).html(options);
  185. div_rem_button = $('<div>',
  186. {
  187. 'class':'col-md-1 remove-btn'
  188. })
  189. rem_button = $('<button>',{
  190. 'type':'button',
  191. 'class':'btn btn-primary',
  192. 'onclick':'$(this).parent().parent().remove()'
  193. }).html("<span class='glyphicon glyphicon-remove'></span>")
  194. div_select.append(select);
  195. div_rem_button.append(rem_button);
  196. div_master.append(div_select);
  197. div_master.append(div_rem_button);
  198. return div_master;
  199. }
  200. function fetchCriteria(a){
  201. objective_id = $(a).data('objective-id');
  202. objective_text = $("#objective-"+objective_id).html()
  203. outcome_id = $(a).data('outcome-id')
  204. $.post(
  205. "{{URL::action('Objective2Controller@fetchProgramCriteria')}}",
  206. {
  207. objective_id:objective_id,
  208. outcome_id:outcome_id
  209. },
  210. function(programs){
  211. //modal, and its subvariants
  212. mc = "#match_criteria";
  213. $(mc).data('objective-id', objective_id)
  214. title_h = $('<h5>',{
  215. 'class':'modal-title'
  216. }).html("Match "+ objective_text +" to Criteria")
  217. $(mc+"_title").html(title_h)
  218. $('.removable_div').remove();
  219. //select= $(".select_criteria").html(" ");
  220. program_select = $("#match_criteria_program").html(" ");
  221. $.each(programs, function(ind, program){
  222. prog_div = $("<div>",{
  223. "id":"program-"+program.id,
  224. "class": "program_divs removable_div",
  225. "style":"display: none"
  226. })
  227. program_option = $('<option>',{
  228. "value":program.id
  229. }).html(program.name)
  230. program_select.append(program_option);
  231. criteria = program.criteria
  232. options_html = '<option value="0">Nothing Selected</option>';
  233. more_than_one = false;
  234. selected_options = [];
  235. $.each(criteria, function(ind, cri){
  236. if(cri.objective_id == objective_id && cri.outcome_id == outcome_id){
  237. option = $("<option>",{
  238. 'value':cri.criterion_id,
  239. 'data-program-id':program.id,
  240. 'data-outcome-id':outcome_id,
  241. }).html(cri.name)
  242. // option.prop('selected', true);
  243. selected_options.push(cri.criterion_id);
  244. }
  245. else if (cri.outcome_id == outcome_id){
  246. option = $("<option>",{
  247. 'value':cri.criterion_id,
  248. 'data-program-id':program.id,
  249. 'data-outcome-id':outcome_id,
  250. }).html(cri.name)
  251. }
  252. options_html += option.prop('outerHTML');
  253. //$(select).selectpicker('refresh');
  254. //if(criteria)
  255. })
  256. //create multiple selects.
  257. // el query es , Si no esta en program id, objetivo es 0.
  258. //Si program id
  259. $('#program_objectives').append(prog_div);
  260. select = createSelectForModal(options_html)
  261. select.find('.remove_btn').hide()
  262. prog_div.append(select);
  263. $('select.criteria_select').selectpicker('refresh');
  264. $.each(selected_options, function(ind, cri_id){
  265. the_picker = select.find('select.criteria_select').first();
  266. the_picker.val(cri_id);
  267. select = createSelectForModal(options_html)
  268. prog_div.append(select)
  269. // $('.criteria_select').selectpicker('refresh');
  270. })
  271. //prog_div.append(select)
  272. // $('#program_objectives').append(prog_div);
  273. $('select.criteria_select').selectpicker('refresh');
  274. prog_div.append(createAddCriteriaButton("program-"+program.id))
  275. })
  276. program_select.selectpicker('refresh');
  277. program_select.trigger('change');
  278. $(mc).modal('show');
  279. }
  280. )
  281. }
  282. function createAddCriteriaButton(program_div_id){
  283. button = $("<button>", {
  284. 'class':'add_criteria btn btn-secondary',
  285. 'type':'button',
  286. 'onclick':'addSelect('+program_div_id+')'
  287. }).html("+ Add Criteria");
  288. }
  289. $('.view-scales').on('click', function() {
  290. var number_of_scales = this.value;
  291. $('.table-responsive').hide();
  292. $('.table-responsive-0').show();
  293. $('.table-' + number_of_scales).show();
  294. })
  295. function changeCriteriaDisplayed(select){
  296. select = $(select)
  297. program_id = select.val();
  298. $('.program_divs').hide();
  299. $("#program-"+program_id).show();
  300. }
  301. </script>
  302. @stop
  303. @section('included-js')
  304. @include('global._datatables_js')
  305. @stop
  306. @section('javascript')