Няма описание

view-objectives-criteria.blade.php 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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" id = 'theTable'>
  57. <thead id="theHead">
  58. <th style="width: 20%">Objective</th>
  59. <th style="width: 20%">Program</th>
  60. <th style="width: 20%">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. <label for="match_criteria_program">Program</label>
  88. <select id="match_criteria_program" class ='form-control selectpicker select_program' onchange="changeCriteriaDisplayed('#match_criteria_program')">
  89. </select>
  90. </div>
  91. <hr>
  92. <label>Criteria associated to program</label>
  93. <div id="program_objectives" class ='form-group col-md-12' >
  94. </div>
  95. </div>
  96. <div class="modal-footer">
  97. <hr>
  98. <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="">Close</button>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. <div id="warning" class="modal fade" tabindex="-1" data-objective-id="0">
  104. <div class="modal-dialog">
  105. <div class="modal-content">
  106. <div class="modal-header">
  107. <h5 class="modal-title" id = 'warning_title'></h5>
  108. <button type="button" class="close" data-dismiss="modal">&times;</button>
  109. </div>
  110. <div class="modal-body" id = "warning_body">
  111. </div>
  112. <div class="modal-footer">
  113. <hr>
  114. <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="$('#match_criteria').data('objective-id', '0');">Cancel</button>
  115. <button id='warning_delete' type="button" class="btn btn-primary" onclick = ''>Delete</button>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. <script>
  121. $(document).ready(function() {
  122. // --------------------------------------------------------------------------
  123. // Page load
  124. // --------------------------------------------------------------------------
  125. // Hide accordion panel contents by default
  126. $('.panel-group .panel-body').hide(); -
  127. $('#objective-display').parent().hide();
  128. // --------------------------------------------------------------------------
  129. // Functions
  130. // --------------------------------------------------------------------------
  131. /*
  132. */
  133. function fetchObjectives(li) {
  134. {
  135. var id = $(li).data('outcome-id');
  136. $.post(
  137. "{{ URL::action('Objective2Controller@fetchObjectivesForOutcome') }}", {
  138. id: id,
  139. },
  140. function(json) {
  141. // Retrieve datatable instance
  142. //var table = $('.table-responsive-0').;
  143. var name = $(li).html();
  144. //var definition = json.objective.program.name;
  145. //var criteria = json.objective.criteria;
  146. $('#objective-display').parent().show();
  147. $('.no-objective').parent().hide();
  148. //Display title and definition
  149. $('#objective-display .panel-title').html(name);
  150. // $('#objective-display .objective-definition').html(definition);
  151. //Empty table
  152. table = $('#theTable').DataTable(
  153. );
  154. table.clear();
  155. $.each(json, function(ind2, objective) {
  156. tr = $("<tr>");
  157. //objectives
  158. td_text = $("<td>",{
  159. 'id':"objective-"+objective.id
  160. }).html(objective.text);
  161. //programs
  162. td_programs = $("<td>");
  163. ol = $("<ol>");
  164. $.each(objective.programs, function(ind, prog) {
  165. li = $("<li>").html(prog.name);
  166. li.appendTo(ol);
  167. })
  168. ol.appendTo(td_programs);
  169. //link to criteria matching
  170. link_td = $("<td>");
  171. a = $('<a>',{
  172. 'onclick':'fetchCriteria(this)',
  173. 'data-objective-id': objective.id,
  174. 'data-outcome-id':id
  175. }).html("Change Associated Criteria");
  176. link_td.append(a)
  177. table.row.add([
  178. td_text.html(),
  179. td_programs.html(),
  180. link_td.html()
  181. ])
  182. //tr.append(td_text);
  183. //tr.append(td_programs);
  184. //tr.append(link_td)
  185. //tr.appendTo($('#table_objectives'))
  186. })
  187. table.columns.adjust().draw();
  188. },
  189. 'json'
  190. );
  191. }
  192. }
  193. // --------------------------------------------------------------------------
  194. // Events
  195. // --------------------------------------------------------------------------
  196. // When list item is clicked, load corresponding info
  197. $('.list-group-item').on('click', function() {
  198. fetchObjectives(this);
  199. })
  200. });
  201. function postDeleteCrit(criterion_id ,program_id ,outcome_id ,objective_id ,cobo_id ,pcobo_id){
  202. $.post(
  203. "{{URL::action('Objective2Controller@deletePCOBO')}}",
  204. {
  205. criterion_id:criterion_id,
  206. program_id:program_id,
  207. outcome_id:outcome_id,
  208. objective_id:objective_id,
  209. cobo_id:cobo_id,
  210. pcobo_id:pcobo_id
  211. },
  212. function (status){
  213. if(status == 200){
  214. button = ".selected_criteria_to_delete"
  215. program_div = $(button).parent().parent().parent();
  216. options = program_div.find('select.selectpicker').html();
  217. $(button).parent().parent().remove();
  218. if(program_div.children('.removable_div').length === 0){
  219. program_div.prepend(addSelect('#'+ program_div.attr('id'), options));
  220. }
  221. //$('.selected_criteria_to_delete').parent().parent().remove();
  222. }
  223. else{
  224. alert("something went wrong, try again later.");
  225. }
  226. }
  227. )
  228. }
  229. function createSelectForModal(options){
  230. div_master = $('<div>',{
  231. 'class':'removable_div'
  232. })
  233. div_select = $("<div>",{
  234. 'class':'form-group col-md-11',
  235. })
  236. select = $('<select>',{
  237. 'class':'selectpicker form-control criteria_select',
  238. 'name':'criteria[]',
  239. 'onchange':'saveChanges(this)'
  240. }).html(options);
  241. div_rem_button = $('<div>',
  242. {
  243. 'class':'col-md-1 remove-btn'
  244. })
  245. rem_button = $('<button>',{
  246. 'type':'button',
  247. 'class':'btn btn-primary',
  248. 'onclick':'deleteCriterion(this);'
  249. }).html("<span class='glyphicon glyphicon-remove'></span>")
  250. div_select.append(select);
  251. div_rem_button.append(rem_button);
  252. div_master.append(div_select);
  253. div_master.append(div_rem_button);
  254. return div_master;
  255. }
  256. function saveChanges(select){
  257. //Create if old-cobo doesnt exist
  258. option = $(select).find(':selected');
  259. criterion_id = option.val()
  260. if(criterion_id ==0){
  261. return;
  262. }
  263. pcobo_id = option.data('pcobo-id')
  264. cobo_id = option.data('cobo-id');
  265. objective_id = option.data('objective-id')
  266. outcome_id = option.data('outcome-id');
  267. program_id = option.data('program-id')
  268. dict_to_send = {};
  269. if($(select).data('old-pcobo') ===undefined){
  270. dict_to_send= {
  271. criterion_id:criterion_id,
  272. pcobo_id:pcobo_id,
  273. cobo_id:cobo_id,
  274. objective_id:objective_id,
  275. outcome_id:outcome_id,
  276. program_id:program_id
  277. }
  278. url = "{{URL::action('Objective2Controller@insertPCOBO')}}";
  279. }
  280. else{
  281. url= "{{URL::action('Objective2Controller@updatePCOBO')}}";
  282. old_crit = $(select).data('old-criterion')
  283. old_outcome= $(select).data('old-outcome')
  284. old_cobo = $(select).data('old-cobo')
  285. old_pcobo = $(select).data('old-pcobo')
  286. dict_to_send ={
  287. criterion_id:criterion_id,
  288. pcobo_id:pcobo_id,
  289. cobo_id:cobo_id,
  290. objective_id:objective_id,
  291. outcome_id:outcome_id,
  292. program_id:program_id,
  293. old_crit:old_crit,
  294. old_outcome:old_outcome,
  295. old_cobo:old_cobo,
  296. old_pcobo:old_pcobo
  297. }
  298. }
  299. $.post(
  300. url,
  301. dict_to_send,
  302. function(code){
  303. if(code == "DUPLICATE"){
  304. alert("This criteria is already paired to this objective")
  305. $(select).val(0)
  306. $(select).selectpicker('refresh');
  307. }
  308. else if (code==200){
  309. $(select).attr('data-old-pcobo', pcobo_id)
  310. $(select).attr('data-old-cobo', cobo_id)
  311. $(select).attr('data-old-criterion', criterion_id)
  312. $(select).attr('data-old-outcome', outcome_id)
  313. $(select).attr('data-old-objective', objective_id)
  314. }
  315. }
  316. )
  317. }
  318. function fetchCriteria(a){
  319. objective_id = $(a).data('objective-id');
  320. objective_text = $(a).parent().parent().children().first().html();//$("#objective-"+objective_id).html()
  321. outcome_id = $(a).data('outcome-id')
  322. $.post(
  323. "{{URL::action('Objective2Controller@fetchProgramCriteria')}}",
  324. {
  325. objective_id:objective_id,
  326. outcome_id:outcome_id
  327. },
  328. function(programs){
  329. //modal, and its subvariants
  330. mc = "#match_criteria";
  331. $(mc).data('objective-id', objective_id)
  332. title_h = $('<h5>',{
  333. 'class':'modal-title'
  334. }).html("Match "+ objective_text +" to Criteria")
  335. $(mc+"_title").html(title_h)
  336. $('.removable_div').remove();
  337. //select= $(".select_criteria").html(" ");
  338. program_select = $("#match_criteria_program").html(" ");
  339. $.each(programs, function(ind, program){
  340. prog_div = $("<div>",{
  341. "id":"program-"+program.id,
  342. "class": "program_divs removable_div",
  343. "style":"display: none"
  344. })
  345. program_option = $('<option>',{
  346. "value":program.id
  347. }).html(program.name)
  348. program_select.append(program_option);
  349. criteria = program.criteria
  350. options_html = '<option value="0">Nothing Selected</option>';
  351. more_than_one = false;
  352. selected_options = [];
  353. $.each(criteria, function(ind, cri){
  354. if(cri.objective_id == objective_id && cri.outcome_id == outcome_id){
  355. dictionary_to_keep = {
  356. 'value':cri.criterion_id,
  357. 'data-program-id':program.id,
  358. 'data-outcome-id':outcome_id,
  359. 'data-objective-id':objective_id,
  360. 'data-cobo-id':cri.cobo_id,
  361. 'data-pcobo-id':cri.pcobo_id
  362. }
  363. option = $("<option>",{
  364. 'value':cri.criterion_id,
  365. 'data-program-id':program.id,
  366. 'data-outcome-id':outcome_id,
  367. 'data-objective-id':objective_id,
  368. 'data-cobo-id':cri.cobo_id,
  369. 'data-pcobo-id':cri.pcobo_id
  370. }).html(cri.name)
  371. // option.prop('selected', true);
  372. selected_options.push(dictionary_to_keep);
  373. }
  374. else if (cri.outcome_id == outcome_id){
  375. option = $("<option>",{
  376. 'value':cri.criterion_id,
  377. 'data-program-id':program.id,
  378. 'data-outcome-id':outcome_id,
  379. 'data-objective-id':objective_id,
  380. 'data-cobo-id':cri.cobo_id,
  381. 'data-pcobo-id':cri.pcobo_id
  382. }).html(cri.name)
  383. }
  384. options_html += option.prop('outerHTML');
  385. //$(select).selectpicker('refresh');
  386. //if(criteria)
  387. })
  388. //create multiple selects.
  389. // el query es , Si no esta en program id, objetivo es 0.
  390. //Si program id
  391. $('#program_objectives').append(prog_div);
  392. select = createSelectForModal(options_html)
  393. //select.find('div.remove-btn').hide()
  394. prog_div.append(select);
  395. $('select.criteria_select').selectpicker('refresh');
  396. if(selected_options.length>0){
  397. $.each(selected_options, function(ind, cri){
  398. the_picker = select.find('select.criteria_select').first();
  399. the_picker.val(cri['value']);
  400. the_picker.attr('data-old-pcobo', cri['data-pcobo-id'])
  401. the_picker.attr('data-old-cobo', cri['data-cobo-id'])
  402. the_picker.attr('data-old-criterion', cri['value'])
  403. the_picker.attr('data-old-outcome', cri['data-outcome-id'])
  404. the_picker.attr('data-old-objective', cri['data-objective-id'])
  405. select = createSelectForModal(options_html)
  406. prog_div.append(select)
  407. // $('.criteria_select').selectpicker('refresh');
  408. })
  409. // to remove the last one
  410. select.remove();
  411. }
  412. //prog_div.append(select)
  413. // $('#program_objectives').append(prog_div);
  414. $('select.criteria_select').selectpicker('refresh');
  415. prog_div.append(createAddCriteriaButton("program-"+program.id))
  416. })
  417. program_select.selectpicker('refresh');
  418. program_select.trigger('change');
  419. $(mc).modal('show');
  420. }
  421. )
  422. }
  423. wr = "#warning"
  424. function deleteCriterion(button){
  425. select = $(button).parent().parent().find('select.criteria_select');
  426. options = $(select).html();
  427. $('.selected_criteria_to_delete').removeClass('selected_criteria_to_delete');
  428. $(button).addClass('selected_criteria_to_delete');
  429. criterion_id = $(select).val()
  430. if(criterion_id ==0){
  431. program_div = $(button).parent().parent().parent();
  432. removable_div = $(button).parent().parent().clone();
  433. $(button).parent().parent().remove();
  434. if(program_div.children('.removable_div').length === 0){
  435. addSelect('#'+program_div.attr('id'), options);
  436. }
  437. //createSelectForModal(options);
  438. return
  439. }
  440. option = $(select).find(':selected');
  441. name = $(select).find(':selected').html();
  442. program_id = $(option).data('program-id')
  443. outcome_id = $(option).data('outcome-id')
  444. objective_id = $(option).data('objective-id')
  445. cobo_id = $(option).data('cobo-id')
  446. pcobo_id = $(option).data('pcobo-id')
  447. $(wr+'_title').html("Are you sure you want to remove this Criterion?")
  448. $(wr+"_delete").attr('onclick', 'postDeleteCrit('+criterion_id+' ,'+program_id+' ,'+outcome_id+' ,'+objective_id+' ,'+cobo_id+' ,'+pcobo_id+'); $("'+wr+'").modal("hide") ');
  449. $(wr+'_body').html("<p>You are about to detach <strong>"+ name+"</strong> </p>")
  450. $(wr).modal('show');
  451. }
  452. function createAddCriteriaButton(program_div_id){
  453. div= $("<div>",{
  454. 'class':'col-md-12'
  455. });
  456. button = $("<button>", {
  457. 'class':'add_criteria btn btn-secondary',
  458. 'type':'button',
  459. 'onclick':'addSelect("#'+program_div_id+'", )',
  460. 'style':'float: right'
  461. }).html(" <span class = 'glyphicon glyphicon-plus'></span> Add Criteria");
  462. div.append(button)
  463. div.append('<br><br>')
  464. return div;
  465. }
  466. // options = null;
  467. function addSelect(program_div_id, last_options=null){
  468. if(last_options == null){
  469. options = $(program_div_id).children('.removable_div').first().find('select.criteria_select').html();
  470. $(program_div_id).children(".removable_div").last().after(createSelectForModal(options));
  471. }
  472. else{
  473. $(program_div_id).prepend(createSelectForModal(last_options))
  474. }
  475. options = $(program_div_id).children('.removable_div').first().find('select.criteria_select').html();
  476. $('select.criteria_select').selectpicker('refresh');
  477. }
  478. $('.view-scales').on('click', function() {
  479. var number_of_scales = this.value;
  480. $('.table-responsive').hide();
  481. $('.table-responsive-0').show();
  482. $('.table-' + number_of_scales).show();
  483. })
  484. function changeCriteriaDisplayed(select){
  485. select = $(select)
  486. program_id = select.val();
  487. $('.program_divs').hide();
  488. $("#program-"+program_id).show();
  489. }
  490. </script>
  491. @stop
  492. @section('included-js')
  493. @include('global._datatables_js')
  494. @stop
  495. @section('javascript')