No Description

annual-plans.blade.php 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. @extends('layouts.master-2')
  2. @section('navigation')
  3. @if(Auth::user()->role==1)
  4. @include('local.managers.admins._navigation')
  5. @elseif(Auth::user()->role==2)
  6. @include('local.managers.sCoords._navigation')
  7. @elseif(Auth::user()->role==3)
  8. @include('local.managers.pCoords._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. <div class="row">
  19. <div class="col-md-3">
  20. <a role ="button" class="btn btn-secondary" href="{{URL::action("AnnualPlansController@viewAllPlans", array($program->id))}}">View Plans</a>
  21. <select class = "form-control selectpicker" id = "annual_plan" onchange="fetchInfo('annual_plan')">
  22. <option value = '0'> Nothing Selected</option>
  23. @foreach ($annual_plans as $an_plan)
  24. <option value={{$an_plan->id}}>Plan {{$an_plan->academic_year}}</option>
  25. @endforeach
  26. </select>
  27. <br>
  28. <div id='allOutcomes'>
  29. </div>
  30. </div>
  31. <div class="col-md-9">
  32. <div id="expected-outcome" class="panel panel-default" data-semester-id ="">
  33. <div class="panel-heading">
  34. <h3 class="panel-title">
  35. Expected Target Outcomes
  36. </h3>
  37. <input style="width: 150px;" min="0" class="form-control" type="number" >
  38. </div>
  39. </div>
  40. <div id="outcome-display" class="panel panel-default">
  41. <div class="panel-heading">
  42. <h4 class=" panel-title" >
  43. Primer Semestre 2019-2020
  44. </h4>
  45. </div>
  46. <div class="panel-body">
  47. <p class="outcome-definition "></p>
  48. <div class="table-responsive">
  49. <table class="table table-striped table-condensed datatable" style="table-layout: fixed ; width : 100%">
  50. <thead><tr><th>Objectives for courses</th><th>Criteria per Course</th><th>Transformative Actions</th></tr></thead>
  51. <tbody>
  52. </tbody>
  53. </table>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. <div class="col-md-9">
  59. <div class="no-outcome alert alert-info">
  60. <p>Select a Learning Outcome to view its information</p>
  61. </div>
  62. </div>
  63. </div>
  64. <script>
  65. function nextChar(c) {
  66. return String.fromCharCode(c.charCodeAt(0) + 1);
  67. }
  68. changed = false;
  69. $(document).ready(function()
  70. {
  71. // --------------------------------------------------------------------------
  72. // Page load
  73. // --------------------------------------------------------------------------
  74. // Hide accordion panel contents by default
  75. // $('.panel-group .panel-body').hide();
  76. $('.panel-group .panel-body').hide();
  77. // $('#outcome-display').parent().hide();
  78. // --------------------------------------------------------------------------
  79. // Functions
  80. // --------------------------------------------------------------------------
  81. // --------------------------------------------------------------------------
  82. // Events
  83. // --------------------------------------------------------------------------
  84. // When list item is clicked, load corresponding info
  85. $('#expected-outcome .form-control').on('change', function(){
  86. //create the expected target in the database
  87. program_id = {{$program->id}};
  88. semester_id = $('#expected-outcome').data('semester-id');
  89. $.post(
  90. "../annual-plan-CreateOrEdit/{{$program->id}}",
  91. {
  92. program_id: program_id,
  93. semester_id: semester_id,
  94. expected_target: $('#expected-outcome .form-control').val(),
  95. },
  96. )
  97. });
  98. });
  99. // function CreateOrEdit(id){
  100. // //send data to the database
  101. // console.log(id);
  102. // annual_id = $("#"+id);
  103. // console.log(console.log(annual_id));
  104. // }
  105. function fetchEverything(li)
  106. {
  107. var id = $(li).data('outcome-id');
  108. var name = $(li).data('outcome-name');
  109. var semester = $(li).data('semester-id');
  110. var annual_plan = $(li).data('annual-plan');
  111. $('#expected-outcome').data('semester-id', semester);
  112. $('#theChange').data('annual-plan', annual_plan);
  113. $.post(
  114. "../annual-plan-fetchTYP/{{$program->id}}",
  115. { id: id,
  116. semester: semester
  117. },
  118. function(json)
  119. {
  120. var table = $('.datatable').DataTable();
  121. table.clear();
  122. var optionsForTADict ={};
  123. var objectives = json.objectives;
  124. var courses = json.courses;
  125. var criteria = json.criteria;
  126. var selected_criteria = json.selected_criteria;
  127. var nextLetter ="A";
  128. if(courses)
  129. {
  130. $('table').show();
  131. $('#outcome-display').parent().show();
  132. $('.no-outcome').parent().hide();
  133. //Display title and definition
  134. $('#outcome-display .panel-title').html(name);
  135. var expected_target = json.expected_target;
  136. //check the data type of the expected target
  137. // console.log(expected_target);
  138. //if the expected_target var is an empty array, set default value
  139. var created_at = new Date();
  140. created_at = created_at.getFullYear()+"-"+created_at.getMonth()+"-"+created_at.getDate()
  141. + " " + created_at.getHours() + ":" + created_at.getMinutes() + ":" + created_at.getSeconds();
  142. if(expected_target.length == 0)
  143. {
  144. $('#expected-outcome .form-control').val(0);
  145. }
  146. else
  147. {
  148. $('#expected-outcome .form-control').val(expected_target[0].expected_target);
  149. }
  150. //Empty table
  151. table.clear();
  152. var annual_plan = json.annual_plan.id;
  153. for(objective in objectives){
  154. var objectivesHTML = '';
  155. var courseshtml = '';
  156. var courseTAhtml = '';
  157. var criteriaHTML = '';
  158. objectivesHTML += '<strong>' + nextLetter +'. '+objectives[objective].text+'</strong>';
  159. // courseshtml += "<strong>Objective "+nextLetter+"</strong>";
  160. // courseshtml += '<ul>';
  161. criteriaHTML +="<strong>Objective "+nextLetter+"</strong>";
  162. //criteriaHTML+= '<ol>';
  163. var typ_objective_id = json.typ_objective_id[objectives[objective].id].id;
  164. nextLetter= nextChar(nextLetter);
  165. for(course in courses[objectives[objective].id]){
  166. courseshtml += ' &#8226; '+courses[objectives[objective].id][course].code+' '+courses[objectives[objective].id][course].name+'<br>'
  167. courseTAhtml += ' &#8226; '+courses[objectives[objective].id][course].code+' '+courses[objectives[objective].id][course].name+'<br>'
  168. $divForEach =$('<div/>',{
  169. 'id':'objective-'+objectives[objective].id
  170. });
  171. $divForSelects = $('<div/>', {
  172. 'id' : 'forObjective-'+objectives[objective].id+'-course-'+courses[objectives[objective].id][course].typ_course_id,
  173. 'data-amount-select':'0',
  174. 'class':'form-group',
  175. 'data-annual-plan': json.annual_plan.id
  176. });
  177. options = "<option value = '0' >Nothing Selected</option>"
  178. for (criterion in criteria[objectives[objective].id]){
  179. options += "<option value='"+criteria[objectives[objective].id][criterion].id+"'>"+criteria[objectives[objective].id][criterion].name+"</option>";
  180. }
  181. var $button = $('<button/>', {
  182. 'type': 'button',
  183. 'class': 'btn btn-secondary',
  184. 'onclick': 'addCriteriaTest("forObjective-'+objectives[objective].id+"-course-"+courses[objectives[objective].id][course].typ_course_id+'", "'+objectives[objective].id+"-course-"+courses[objectives[objective].id][course].typ_course_id+'", '+courses[objectives[objective].id][course].typ_course_id+', null, "'+options+'")'
  185. });
  186. $button.append("+ Add criteria");
  187. $divForEach.append($divForSelects);
  188. $divForEach.append("<br>")
  189. $divForEach.append($button);
  190. $divForTA = $('<div/>',{
  191. 'id':'objectiveTA-'+objectives[objective].id
  192. });
  193. $divForTASelects = $('<div/>', {
  194. 'id': 'forTA-objective-'+objectives[objective].id+'-course-'+courses[objectives[objective].id][course].typ_course_id,
  195. 'class':'form-group',
  196. 'data-amount-ta':'0'
  197. });
  198. var optionsForTa = "<option value = '0'>Nothing Selected</option>";
  199. transformativeDefault = json.transformative_actions;
  200. optionsForTa+= "<optgroup label='Default'>";
  201. for(trans in transformativeDefault){
  202. optionsForTa+= "<option value='"+transformativeDefault[trans].id+"'>"+transformativeDefault[trans].at_text+"</option> ";
  203. }
  204. optionsForTa+='</optgroup>';
  205. course_id = courses[objectives[objective].id][course].id
  206. transformativeDefault = json.custom_transformative[objectives[objective].id][course_id];
  207. if(transformativeDefault!= undefined){
  208. optionsForTa+="<optgroup label = 'Custom'>";
  209. for(trans in transformativeDefault){
  210. optionsForTa+= "<option value='"+transformativeDefault[trans].ta_id+"'>"+transformativeDefault[trans].at_text+"</option> ";
  211. }
  212. }
  213. typ_course_id = courses[objectives[objective].id][course].typ_course_id
  214. var $buttonTA = $('<button/>', {
  215. 'type': 'button',
  216. 'class': 'btn btn-secondary',
  217. 'onclick': 'addTAselect("'+optionsForTa+'", "forTA-objective-'+objectives[objective].id+'-course-'+courses[objectives[objective].id][course].typ_course_id+'", '+annual_plan+', '+objectives[objective].id+', '+typ_course_id+', 0)'
  218. });
  219. $buttonTA.append("+ Add TA");
  220. typ_course_id = courses[objectives[objective].id][course].typ_course_id
  221. optionsForTADict[typ_course_id] = optionsForTa;
  222. $divForTA.append($divForTASelects);
  223. $divForTA.append('<br>');
  224. $divForTA.append($buttonTA)
  225. courseshtml += $divForEach[0].innerHTML +"<br><br>";
  226. courseTAhtml += $divForTA[0].innerHTML +"<br><br>";
  227. }
  228. /*$divForTA = $('<div/>',{
  229. 'id':'objectiveTA-'+objectives[objective].id
  230. });
  231. $divForTASelects = $('<div/>', {
  232. 'id': 'forTA-objective-'+objectives[objective].id,
  233. 'class':'form-group',
  234. 'data-amount-ta':'0'
  235. });
  236. var optionsForTa = "<option value = '0'>Nothing Selected</option>";
  237. transformativeDefault = json.transformative_actions;
  238. optionsForTa+= "<optgroup label='Default'>";
  239. for(trans in transformativeDefault){
  240. optionsForTa+= "<option value='"+transformativeDefault[trans].id+"'>"+transformativeDefault[trans].at_text+"</option> ";
  241. }
  242. optionsForTa+='</optgroup>';
  243. transformativeDefault = json.custom_transformative[objectives[objective].id];
  244. if(transformativeDefault!= undefined){
  245. optionsForTa+="<optgroup label = 'Custom'>";
  246. for(trans in transformativeDefault){
  247. optionsForTa+= "<option value='"+transformativeDefault[trans].id+"'>"+transformativeDefault[trans].at_text+"</option> ";
  248. }
  249. }
  250. var $buttonTA = $('<button/>', {
  251. 'type': 'button',
  252. 'class': 'btn btn-secondary',
  253. 'onclick': 'addTAselect("'+optionsForTa+'", "forTA-objective-'+objectives[objective].id+'", '+annual_plan+', '+objectives[objective].id+', '+typ_objective_id+', 0)'
  254. });
  255. $buttonTA.append("+ Add TA");
  256. $divForTA.append($divForTASelects);
  257. $divForTA.append('<br>');
  258. $divForTA.append($buttonTA)
  259. */
  260. table.row.add([
  261. objectivesHTML,
  262. courseshtml,
  263. courseTAhtml
  264. ]);
  265. table.draw();
  266. for(course in courses[objectives[objective].id]){
  267. typ_course_id = courses[objectives[objective].id][course].typ_course_id
  268. if(json.annual_plans_transformative[objectives[objective].id][typ_course_id].length){
  269. for(i=0; i<json.annual_plans_transformative[objectives[objective].id][typ_course_id].length; i++){
  270. selected_ta = json.annual_plans_transformative[objectives[objective].id][typ_course_id][i].trans_id;
  271. addTAselect(optionsForTADict[typ_course_id], "forTA-objective-"+objectives[objective].id+'-course-'+typ_course_id, annual_plan, objectives[objective].id, typ_course_id, selected_ta);
  272. }
  273. }
  274. else{
  275. $('#')
  276. addTAselect(optionsForTADict[typ_course_id], "forTA-objective-"+objectives[objective].id+'-course-'+typ_course_id, annual_plan, objectives[objective].id, typ_course_id, 0);
  277. }
  278. if(json.selected_criteria[objectives[objective].id][typ_course_id].length){
  279. for(i =0; i<json.selected_criteria[objectives[objective].id][typ_course_id].length; i++){
  280. addCriteriaTest("forObjective-"+objectives[objective].id+"-course-"+typ_course_id, ""+objectives[objective].id+"-course-"+typ_course_id, ""+json.selected_criteria[objectives[objective].id][typ_course_id][i].typ_course_id+"", i, options);
  281. $('#criteriaFor'+objectives[objective].id+"-course-"+typ_course_id+'_'+i).val(json.selected_criteria[objectives[objective].id][typ_course_id][i].criteria_id);
  282. $('#criteriaFor'+objectives[objective].id+"-course-"+typ_course_id+'_'+i).data('old-criteria', json.selected_criteria[objectives[objective].id][typ_course_id][i].criteria_id);
  283. $('#criteriaFor'+objectives[objective].id+"-course-"+typ_course_id+'_'+i).selectpicker('refresh');
  284. } // Update display
  285. }
  286. else{
  287. addCriteriaTest("forObjective-"+objectives[objective].id+"-course-"+typ_course_id, ""+objectives[objective].id+"-course-"+typ_course_id+"", ""+typ_course_id+"", 0, options);
  288. $('#criteriaFor'+objectives[objective].id+"-course-"+typ_course_id+'_0').val(0);
  289. $('#criteriaFor'+objectives[objective].id+"-course-"+typ_course_id+'_0').data('old-criteria', 0);
  290. $('#criteriaFor'+objectives[objective].id+"-course-"+typ_course_id+'_0').selectpicker('refresh');
  291. }
  292. }
  293. }
  294. table.draw();
  295. }
  296. else
  297. {
  298. $('table').hide();
  299. }
  300. },
  301. 'json'
  302. );
  303. }
  304. function posttoTransAnnual(annual_id, selectTransId, typ_course_id){
  305. ta = $("#"+selectTransId).val();
  306. old_ta = $("#"+selectTransId).data('old-TA');
  307. if(ta == "0")return;
  308. $.post("../annual-plan-postTA",
  309. {annual_id : annual_id,
  310. TA_id:ta,
  311. typ_course_id : typ_course_id,
  312. old_ta:old_ta
  313. },
  314. function(message){
  315. $("#"+selectTransId).data('old-TA', ta);
  316. }
  317. )
  318. }
  319. function addTAselect(options, master_div, annual_plan_id, objective_id, typ_course_id, selected_ta){
  320. var $div = $('<div/>', {
  321. 'class': 'form-group '
  322. });
  323. counter = parseInt($('#'+master_div).data('amount-ta'));
  324. var selectTA = $('<select/>',{
  325. 'class': "selectpicker form-control",
  326. 'data-live-search':'true',
  327. 'data-old-TA' :'0',
  328. 'data-width': '180px',
  329. 'id': 'transformativeForObjective'+master_div+'_'+counter,
  330. 'onchange':'posttoTransAnnual('+annual_plan_id+', "transformativeForObjective'+master_div+'_'+counter+'", '+typ_course_id+')'
  331. });
  332. selectTA.append(options);
  333. selectTA.appendTo($div);
  334. selectTA.val(selected_ta);
  335. selectTA.data('old-TA', selected_ta);
  336. selectTA.selectpicker('refresh');
  337. $span = $('<span/>', {
  338. 'id':'close',
  339. 'onclick':' postDeleteTA('+annual_plan_id+', "transformativeForObjective'+master_div+'_'+counter+'", '+typ_course_id+'); this.parentNode.parentNode.removeChild(this.parentNode);return false;'
  340. }).html('x');
  341. $span.appendTo($div);
  342. $div.append("<br><br>");
  343. $('#'+master_div).append("<br>");
  344. $div.appendTo($('#'+master_div));
  345. $('#'+master_div).data('amount-ta', counter+1);
  346. }
  347. function postDeleteTA(annual_id, selectTransId, typ_course_id){
  348. ta = $("#"+selectTransId).val();
  349. if(ta == "0")return;
  350. $.post("../annual-plan-deleteTA",
  351. {annual_id : annual_id,
  352. TA_id:ta,
  353. typ_id : typ_course_id,
  354. }
  355. );
  356. parent = $("#"+selectTransId).parent().parent().parent();
  357. counter = parseInt(parent.data('amount-ta'));
  358. parent.data('amount-ta', counter-1);
  359. }
  360. function postToAnnualPlans(typ_course_id, criteria_select){
  361. var criteria = $('#'+criteria_select).val();
  362. var oldCriteria = $('#'+criteria_select).data('old-criteria');
  363. var criteriaNode = document.getElementById(criteria_select).parentNode.parentNode.parentNode;
  364. var annual = criteriaNode.dataset.annualPlan;
  365. $.post("../annual-plan-postOnChange",
  366. {criteria : criteria,
  367. typ_course_id : typ_course_id,
  368. annual_plan : annual,
  369. old_criteria :oldCriteria
  370. },
  371. function(message){
  372. if(message =="Duplicate entry, please choose another criteria."){
  373. alert(message)
  374. }
  375. else{
  376. $('#'+criteria_select).data('old-criteria', criteria);
  377. changed = true;
  378. }
  379. })
  380. }
  381. function addCriteriaTest(div, new_id_for_select, typ_course_id, i=null, options) {
  382. if(!i) amount_select = $('#'+div).data("amount-select");
  383. else amount_select = i;
  384. $select = $('<select/>',{
  385. 'class': "selectpicker form-control",
  386. 'data-live-search':'true',
  387. 'data-old-criteria' :'0',
  388. 'data-width': '180px',
  389. 'id': 'criteriaFor'+new_id_for_select+'_'+amount_select,
  390. 'onchange':'postToAnnualPlans('+typ_course_id+', "criteriaFor'+new_id_for_select+'_'+amount_select+'")'
  391. })
  392. var $div = $('<div/>', {
  393. 'id': 'courseSelect_' + new_id_for_select +'_'+amount_select,
  394. 'class': 'form-group '
  395. });
  396. $select.append(options);
  397. $select.appendTo($div);
  398. $span = $('<span/>', {
  399. 'id':'close',
  400. 'onclick':' postDelete('+typ_course_id+', "criteriaFor'+new_id_for_select+'_'+amount_select+'"); this.parentNode.parentNode.removeChild(this.parentNode);return false;'
  401. }).html('x');
  402. $div.append($span);
  403. $div.append("<br><br>")
  404. $('#'+div).append("<br>");
  405. $div.appendTo($("#"+div));
  406. $select.selectpicker('refresh');
  407. $("#"+div).data("amount-select", amount_select+1);
  408. }
  409. $('#allOutcomes').hide();
  410. function postDelete(typ_course_id, criteria_select){
  411. var criteria = $('#'+criteria_select).val();
  412. var oldCriteria = $('#'+criteria_select).data('old-criteria');
  413. var criteriaNode = document.getElementById(criteria_select).parentNode.parentNode.parentNode;
  414. var annual = criteriaNode.dataset.annualPlan;
  415. $.post("../annual-plan-deleteCriteria",
  416. {criteria : criteria,
  417. typ_course_id : typ_course_id,
  418. annual_plan : annual,
  419. old_criteria :oldCriteria
  420. });
  421. }
  422. function fetchInfo(id){
  423. annual_id = $("#"+id).val();
  424. program_id = {{$program->id}};
  425. $.post("{{URL::action('AnnualPlansController@fetchInfo')}}",
  426. {
  427. id:annual_id,
  428. program_id:program_id
  429. },
  430. function(json){
  431. div = $('<div/>', {
  432. 'class':'list-group',
  433. 'id':'list'
  434. });
  435. header5 = $('<h5/>', {
  436. 'style':"padding-left: 10px"
  437. }).html("First Semester");
  438. div.append(header5);
  439. list = '';
  440. for(outcome in json.outcomes.first){
  441. list+= "<li style='padding-left: 25px' onclick = 'fetchEverything(this)' data-annual-plan = '"+json.annual_plans.id+"' data-semester-id = '"+json.allSemesterOrder.first.id+"' data-outcome-id='"+json.outcomes.first[outcome].id+"' data-outcome-name ='"+json.outcomes.first[outcome].name+"' class='list-group-item' >"+json.outcomes.first[outcome].name+" </li>";
  442. }
  443. div.append(list);
  444. header4 = $('<h5/>', {
  445. 'style':"padding-left: 10px"
  446. }).html("Second Semester");
  447. div.append(header4);
  448. list = '';
  449. for(outcome in json.outcomes.second){
  450. list+= "<li style='padding-left: 25px' onclick = 'fetchEverything(this)' data-annual-plan = '"+json.annual_plans.id+"' data-semester-id = '"+json.allSemesterOrder.second.id+"' data-outcome-id='"+json.outcomes.second[outcome].id+"' data-outcome-name ='"+json.outcomes.second[outcome].name+"' class='list-group-item' >"+json.outcomes.second[outcome].name+" </li>";
  451. }
  452. div.append(list);
  453. html = div[0].innerHTML;
  454. $("#allOutcomes").html(div[0].innerHTML);
  455. $("#allOutcomes").show();
  456. },
  457. "json",
  458. );
  459. }
  460. function deleteObjective(objectiveSelectDiv, closeObj){
  461. $('#'+objectiveSelectDiv).remove();
  462. $('#'+closeObj).remove();
  463. $('#'+div).data("amount-select", $('#'+div).data("amount-select")-1);
  464. }
  465. </script>
  466. @stop
  467. @section('included-js')
  468. @include('global._datatables_js')
  469. @stop