Keine Beschreibung

view-objectives-criteria.blade.php 28KB

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