No Description

view-objectives-criteria.blade.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. <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_objectives').empty();
  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. tr.append(td_text);
  176. tr.append(td_programs);
  177. tr.append(link_td)
  178. tr.appendTo($('#table_objectives'))
  179. })
  180. },
  181. 'json'
  182. );
  183. }
  184. }
  185. // --------------------------------------------------------------------------
  186. // Events
  187. // --------------------------------------------------------------------------
  188. // When list item is clicked, load corresponding info
  189. $('.list-group-item').on('click', function() {
  190. fetchObjectives(this);
  191. })
  192. });
  193. function postDeleteCrit(criterion_id ,program_id ,outcome_id ,objective_id ,cobo_id ,pcobo_id){
  194. $.post(
  195. "{{URL::action('Objective2Controller@deletePCOBO')}}",
  196. {
  197. criterion_id:criterion_id,
  198. program_id:program_id,
  199. outcome_id:outcome_id,
  200. objective_id:objective_id,
  201. cobo_id:cobo_id,
  202. pcobo_id:pcobo_id
  203. },
  204. function (status){
  205. if(status == 200){
  206. $('.selected_criteria_to_delete').parent().parent().remove();
  207. }
  208. else{
  209. alert("something went wrong, try again later.");
  210. }
  211. }
  212. )
  213. }
  214. function createSelectForModal(options){
  215. div_master = $('<div>',{
  216. 'class':'removable_div'
  217. })
  218. div_select = $("<div>",{
  219. 'class':'form-group col-md-11',
  220. })
  221. select = $('<select>',{
  222. 'class':'selectpicker form-control criteria_select',
  223. 'name':'criteria[]',
  224. 'onchange':'saveChanges(this)'
  225. }).html(options);
  226. div_rem_button = $('<div>',
  227. {
  228. 'class':'col-md-1 remove-btn'
  229. })
  230. rem_button = $('<button>',{
  231. 'type':'button',
  232. 'class':'btn btn-primary',
  233. 'onclick':'deleteCriterion(this);'
  234. }).html("<span class='glyphicon glyphicon-remove'></span>")
  235. div_select.append(select);
  236. div_rem_button.append(rem_button);
  237. div_master.append(div_select);
  238. div_master.append(div_rem_button);
  239. return div_master;
  240. }
  241. function saveChanges(select){
  242. //Create if old-cobo doesnt exist
  243. option = $(select).find(':selected');
  244. criterion_id = option.val()
  245. if(criterion_id ==0){
  246. return;
  247. }
  248. pcobo_id = option.data('pcobo-id')
  249. cobo_id = option.data('cobo-id');
  250. objective_id = option.data('objective-id')
  251. outcome_id = option.data('outcome-id');
  252. program_id = option.data('program-id')
  253. dict_to_send = {};
  254. if($(select).data('old-pcobo') ===undefined){
  255. dict_to_send= {
  256. criterion_id:criterion_id,
  257. pcobo_id:pcobo_id,
  258. cobo_id:cobo_id,
  259. objective_id:objective_id,
  260. outcome_id:outcome_id,
  261. program_id:program_id
  262. }
  263. url = "{{URL::action('Objective2Controller@insertPCOBO')}}";
  264. }
  265. else{
  266. url= "{{URL::action('Objective2Controller@updatePCOBO')}}";
  267. old_crit = $(select).data('old-criterion')
  268. old_outcome= $(select).data('old-outcome')
  269. old_cobo = $(select).data('old-cobo')
  270. old_pcobo = $(select).data('old-pcobo')
  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. old_crit:old_crit,
  279. old_outcome:old_outcome,
  280. old_cobo:old_cobo,
  281. old_pcobo:old_pcobo
  282. }
  283. }
  284. $.post(
  285. url,
  286. dict_to_send,
  287. function(code){
  288. if(code == "DUPLICATE"){
  289. alert("This criteria is already paired to this objective")
  290. $(select).val(0)
  291. $(select).selectpicker('refresh');
  292. }
  293. else if (code==200){
  294. $(select).attr('data-old-pcobo', pcobo_id)
  295. $(select).attr('data-old-cobo', cobo_id)
  296. $(select).attr('data-old-criterion', criterion_id)
  297. $(select).attr('data-old-outcome', outcome_id)
  298. $(select).attr('data-old-objective', objective_id)
  299. }
  300. }
  301. )
  302. }
  303. function fetchCriteria(a){
  304. objective_id = $(a).data('objective-id');
  305. objective_text = $("#objective-"+objective_id).html()
  306. outcome_id = $(a).data('outcome-id')
  307. $.post(
  308. "{{URL::action('Objective2Controller@fetchProgramCriteria')}}",
  309. {
  310. objective_id:objective_id,
  311. outcome_id:outcome_id
  312. },
  313. function(programs){
  314. //modal, and its subvariants
  315. mc = "#match_criteria";
  316. $(mc).data('objective-id', objective_id)
  317. title_h = $('<h5>',{
  318. 'class':'modal-title'
  319. }).html("Match "+ objective_text +" to Criteria")
  320. $(mc+"_title").html(title_h)
  321. $('.removable_div').remove();
  322. //select= $(".select_criteria").html(" ");
  323. program_select = $("#match_criteria_program").html(" ");
  324. $.each(programs, function(ind, program){
  325. prog_div = $("<div>",{
  326. "id":"program-"+program.id,
  327. "class": "program_divs removable_div",
  328. "style":"display: none"
  329. })
  330. program_option = $('<option>',{
  331. "value":program.id
  332. }).html(program.name)
  333. program_select.append(program_option);
  334. criteria = program.criteria
  335. options_html = '<option value="0">Nothing Selected</option>';
  336. more_than_one = false;
  337. selected_options = [];
  338. $.each(criteria, function(ind, cri){
  339. if(cri.objective_id == objective_id && cri.outcome_id == outcome_id){
  340. dictionary_to_keep = {
  341. 'value':cri.criterion_id,
  342. 'data-program-id':program.id,
  343. 'data-outcome-id':outcome_id,
  344. 'data-objective-id':objective_id,
  345. 'data-cobo-id':cri.cobo_id,
  346. 'data-pcobo-id':cri.pcobo_id
  347. }
  348. option = $("<option>",{
  349. 'value':cri.criterion_id,
  350. 'data-program-id':program.id,
  351. 'data-outcome-id':outcome_id,
  352. 'data-objective-id':objective_id,
  353. 'data-cobo-id':cri.cobo_id,
  354. 'data-pcobo-id':cri.pcobo_id
  355. }).html(cri.name)
  356. // option.prop('selected', true);
  357. selected_options.push(dictionary_to_keep);
  358. }
  359. else if (cri.outcome_id == outcome_id){
  360. option = $("<option>",{
  361. 'value':cri.criterion_id,
  362. 'data-program-id':program.id,
  363. 'data-outcome-id':outcome_id,
  364. 'data-objective-id':objective_id,
  365. 'data-cobo-id':cri.cobo_id,
  366. 'data-pcobo-id':cri.pcobo_id
  367. }).html(cri.name)
  368. }
  369. options_html += option.prop('outerHTML');
  370. //$(select).selectpicker('refresh');
  371. //if(criteria)
  372. })
  373. //create multiple selects.
  374. // el query es , Si no esta en program id, objetivo es 0.
  375. //Si program id
  376. $('#program_objectives').append(prog_div);
  377. select = createSelectForModal(options_html)
  378. select.find('div.remove-btn').hide()
  379. prog_div.append(select);
  380. $('select.criteria_select').selectpicker('refresh');
  381. if(selected_options){
  382. $.each(selected_options, function(ind, cri){
  383. the_picker = select.find('select.criteria_select').first();
  384. the_picker.val(cri['value']);
  385. the_picker.attr('data-old-pcobo', cri['data-pcobo-id'])
  386. the_picker.attr('data-old-cobo', cri['data-cobo-id'])
  387. the_picker.attr('data-old-criterion', cri['value'])
  388. the_picker.attr('data-old-outcome', cri['data-outcome-id'])
  389. the_picker.attr('data-old-objective', cri['data-objective-id'])
  390. select = createSelectForModal(options_html)
  391. prog_div.append(select)
  392. // $('.criteria_select').selectpicker('refresh');
  393. })
  394. // to remove the last one
  395. select.remove();
  396. }
  397. //prog_div.append(select)
  398. // $('#program_objectives').append(prog_div);
  399. $('select.criteria_select').selectpicker('refresh');
  400. prog_div.append(createAddCriteriaButton("program-"+program.id))
  401. })
  402. program_select.selectpicker('refresh');
  403. program_select.trigger('change');
  404. $(mc).modal('show');
  405. }
  406. )
  407. }
  408. wr = "#warning"
  409. function deleteCriterion(button){
  410. select = $(button).parent().parent().find('select.criteria_select');
  411. $('.selected_criteria_to_delete').removeClass('selected_criteria_to_delete');
  412. $(button).addClass('selected_criteria_to_delete');
  413. criterion_id = $(select).val()
  414. if(criterion_id ==0){
  415. $(button).parent().parent().remove()
  416. return
  417. }
  418. option = $(select).find(':selected');
  419. name = $(select).find(':selected').html();
  420. program_id = $(option).data('program-id')
  421. outcome_id = $(option).data('outcome-id')
  422. objective_id = $(option).data('objective-id')
  423. cobo_id = $(option).data('cobo-id')
  424. pcobo_id = $(option).data('pcobo-id')
  425. $(wr+'_title').html("Are you sure you want to remove this Criterion?")
  426. $(wr+"_delete").attr('onclick', 'postDeleteCrit('+criterion_id+' ,'+program_id+' ,'+outcome_id+' ,'+objective_id+' ,'+cobo_id+' ,'+pcobo_id+'); $("'+wr+'").modal("hide") ');
  427. $(wr+'_body').html("<p>You are about to detach <strong>"+ name+"</strong> </p>")
  428. $(wr).modal('show');
  429. }
  430. function createAddCriteriaButton(program_div_id){
  431. div= $("<div>",{
  432. 'class':'col-md-12'
  433. });
  434. button = $("<button>", {
  435. 'class':'add_criteria btn btn-secondary',
  436. 'type':'button',
  437. 'onclick':'addSelect("#'+program_div_id+'")',
  438. 'style':'float: right'
  439. }).html(" <span class = 'glyphicon glyphicon-plus'></span> Add Criteria");
  440. div.append(button)
  441. div.append('<br><br>')
  442. return div;
  443. }
  444. function addSelect(program_div_id){
  445. options = $(program_div_id).children('.removable_div').first().find('select.criteria_select').html();
  446. $(program_div_id).children(".removable_div").last().after(createSelectForModal(options));
  447. $('select.criteria_select').selectpicker('refresh');
  448. }
  449. $('.view-scales').on('click', function() {
  450. var number_of_scales = this.value;
  451. $('.table-responsive').hide();
  452. $('.table-responsive-0').show();
  453. $('.table-' + number_of_scales).show();
  454. })
  455. function changeCriteriaDisplayed(select){
  456. select = $(select)
  457. program_id = select.val();
  458. $('.program_divs').hide();
  459. $("#program-"+program_id).show();
  460. }
  461. </script>
  462. @stop
  463. @section('included-js')
  464. @include('global._datatables_js')
  465. @stop
  466. @section('javascript')