暫無描述

create_five_year_plan.blade.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. @extends('layouts.master')
  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. @endif
  10. @stop
  11. @section('main')
  12. <div class="row">
  13. <div class="col-md-12">
  14. <div id="quinquennium" data-quinquennium-id="{{ $current_quinquennium->id }}"></div>
  15. <div id="program" data-program-id="{{ $program->id }}"></div>
  16. @for($i = date('Y', strtotime($current_quinquennium->start_date)); $i< date('Y', strtotime($current_quinquennium->end_date)) ; $i++)
  17. <div class="mini-plan">
  18. <table class="table table-bordered">
  19. <thead>
  20. <tr class="bg-danger text-center">
  21. <th class="text-center col-md-1">Academic Year</th>
  22. <th class="text-center col-md-3">Learning Outcome to be assessed</th>
  23. <th class="text-center col-md-4">Learning Objectives</th>
  24. <th class="text-center col-md-4">Courses to use for assessment</th>
  25. <th></th>
  26. </tr>
  27. </thead>
  28. <tbody>
  29. <tr>
  30. <th class="active academic-year text-center" rowspan ="1"><span class="year-start">{{ $i }}</span>-<span class="year-end">{{ $i+1 }}</span></th>
  31. <td class="outcome-cell">
  32. <select name="outcome" class="outcome form-control">
  33. @foreach($outcomes as $outcome)
  34. <option value="{{ $outcome->id }}">{{ $outcome->name }}</option>
  35. @endforeach
  36. </select>
  37. </td>
  38. <td class="objectives-cell">
  39. <div class="objective-select-wrapper">
  40. <select name="objectives[]" class="objective shortened-select form-control">
  41. </select>
  42. <span class="glyphicon glyphicon-remove text-danger icon-btn remove-objective"></span>
  43. <br><br>
  44. </div>
  45. <button class="add-objective btn btn-success pull-right btn-xs"><span class="glyphicon glyphicon-plus"></span></button>
  46. </td>
  47. <td>
  48. <div class="course-select-wrapper">
  49. <select name="courses[]" class="course shortened-select form-control">
  50. @foreach($courses as $course)
  51. <option value="{{ $course->id }}" data-course-code="{{ $course->code }}" data-course-number="{{ $course->number }}" data-course-name="{{ $course->name }}">{{ $course->code }}{{ $course->number }}: {{ $course->name }}</option>
  52. @endforeach
  53. </select>
  54. <span class="glyphicon glyphicon-remove text-danger icon-btn remove-course"></span>
  55. <br><br>
  56. </div>
  57. <button class="add-course btn btn-success pull-right btn-xs"><span class="glyphicon glyphicon-plus"></span></button>
  58. </td>
  59. <td></td>
  60. </tr>
  61. </tbody>
  62. </table>
  63. <div>
  64. <button class="add-outcome btn btn-success pull-right btn-sm"><span class="glyphicon glyphicon-plus"></span>Add Learning Outcome</button>
  65. <br><br><br>
  66. </div>
  67. </div>
  68. @endfor
  69. <div class="text-center">
  70. <button id="button-create-rubric" class="btn btn-lg btn-primary save">
  71. <span class="glyphicon glyphicon-floppy-disk"></span>
  72. Save
  73. </button>
  74. </div>
  75. </div>
  76. </div>
  77. @stop
  78. @section('included-js')
  79. @stop
  80. @section('javascript')
  81. // --------------------------------------------------------------------------
  82. // Page Load
  83. // --------------------------------------------------------------------------
  84. // Hide all 'x' buttons for courses and objectives
  85. $('.remove-course, .remove-objective').hide();
  86. $('.outcome').each(function()
  87. {
  88. fetchObjectives($(this));
  89. });
  90. // --------------------------------------------------------------------------
  91. // Events
  92. // --------------------------------------------------------------------------
  93. // On clicking a button to add outcome
  94. $('.add-outcome').on('click', function(e)
  95. {
  96. var table = $(this).closest('.mini-plan').find('table');
  97. addOutcome(table);
  98. });
  99. // On clicking a button to remove a course
  100. $('table').on('click', '.remove-objective', function(e)
  101. {
  102. removeObjective($(this));
  103. });
  104. // On clicking a button to remove a course
  105. $('table').on('click', '.remove-course', function(e)
  106. {
  107. removeCourse($(this));
  108. });
  109. // On clicking the x to remove an outcome from the plan
  110. $('table').on('click', '.remove-outcome', function(e)
  111. {
  112. var table = $(this).closest('.mini-plan').find('table');
  113. var row = $(this).closest('tr');
  114. removeOutcome(table, row);
  115. });
  116. // On clicking a button to add a objective
  117. $('.add-objective').on('click', function(e)
  118. {
  119. var table = $(this).closest('.mini-plan').find('table');
  120. var objective_select_wrapper = $(this).parent().find('.objective-select-wrapper:last');
  121. var select = $(this).parent().find('select:last');
  122. var selected_objective_id = select.find(':selected').val();
  123. var clone = objective_select_wrapper.clone();
  124. clone.insertAfter(objective_select_wrapper);
  125. objective_select_wrapper.parent().find('.remove-objective').show();
  126. });
  127. // On clicking a button to add a course
  128. $('.add-course').on('click', function(e)
  129. {
  130. var table = $(this).closest('.mini-plan').find('table');
  131. var course_select_wrapper = $(this).parent().find('.course-select-wrapper:last');
  132. var select = $(this).parent().find('select:last');
  133. var selected_course_id = select.find(':selected').val();
  134. var clone = course_select_wrapper.clone();
  135. clone.insertAfter(course_select_wrapper);
  136. course_select_wrapper.parent().find('.remove-course').show();
  137. });
  138. // When user selects another outcome
  139. $('.outcome').on('change', function(e)
  140. {
  141. fetchObjectives($(this));
  142. });
  143. // Gather, structure and send data to server for saving
  144. $('.save').on('click', function(e)
  145. {
  146. var five_year_plan = new Object();
  147. five_year_plan.quinquennium_id = $('#quinquennium').data('quinquennium-id');
  148. five_year_plan.program_id = $('#program').data('program-id');
  149. five_year_plan.mini_plans = new Array();
  150. $('.mini-plan').each(function(index){
  151. var mini_plan = new Object();
  152. mini_plan.year_start = $(this).find('.year-start').text();
  153. mini_plan.year_end = $(this).find('.year-end').text();
  154. // Array for outcome objects
  155. mini_plan.outcomes = new Array();
  156. $(this).find('.outcome').each(function(index){
  157. // Outcome object
  158. var outcome = new Object();
  159. outcome.id = $(this).find(':selected').val();
  160. outcome.objectives = new Array();
  161. outcome.courses = new Array();
  162. // Gather objective information
  163. $(this).closest('tr').find('.objective').each(function()
  164. {
  165. var objective = new Object();
  166. objective.original_id = $(this).find(':selected').val();
  167. objective.text = $(this).find(':selected').text();
  168. outcome.objectives.push(jQuery.extend({}, objective));
  169. objective = null;
  170. });
  171. // Gather course information
  172. $(this).closest('tr').find('.course').each(function()
  173. {
  174. var course = new Object();
  175. course.code = $(this).find(':selected').data('course-code');
  176. course.number = $(this).find(':selected').data('course-number');
  177. course.name = $(this).find(':selected').data('course-name');
  178. outcome.courses.push(jQuery.extend({}, course));
  179. course = null;
  180. });
  181. mini_plan.outcomes.push(jQuery.extend({}, outcome));
  182. outcome = null;
  183. });
  184. five_year_plan.mini_plans.push(jQuery.extend({}, mini_plan));
  185. mini_plan = null;
  186. });
  187. //console.log(five_year_plan);
  188. $.post(
  189. "{{ URL::action('FiveYearPlansController@store', array($program->id)) }}",
  190. {
  191. five_year_plan: JSON.stringify(five_year_plan)
  192. },
  193. function(data)
  194. {
  195. //console.log(data);
  196. var response = data;
  197. //console.log('status: '+response.status);
  198. if(response.status == 'success')
  199. {
  200. //console.log('success');
  201. window.location = response.redirect_url;
  202. }
  203. else
  204. {
  205. jsError(response.message);
  206. }
  207. },
  208. "json"
  209. )
  210. .fail( function(xhr, status, error) {
  211. //console.log('fail:'+error);
  212. // Always scroll to the top
  213. $(this).scrollTop(0);
  214. $('html').animate({scrollTop:0}, 1);
  215. $('body').animate({scrollTop:0}, 1);
  216. jsError(error);
  217. // Show js error with default message
  218. $('#js-error-row').fadeIn('slow', function () {
  219. $(this).delay(3000).fadeOut('slow');
  220. });
  221. }
  222. );
  223. });
  224. // --------------------------------------------------------------------------
  225. // Functions
  226. // --------------------------------------------------------------------------
  227. // Removes a objective
  228. function removeObjective(button)
  229. {
  230. var objective_select_wrapper = button.parent();
  231. // If only one objective will remain, hide 'x' button
  232. if(objective_select_wrapper.siblings('.objective-select-wrapper').length == 1)
  233. {
  234. objective_select_wrapper.siblings('.objective-select-wrapper').find('.remove-objective').hide();
  235. }
  236. // Remove objective
  237. objective_select_wrapper.remove();
  238. }
  239. // Removes a course
  240. function removeCourse(button)
  241. {
  242. var course_select_wrapper = button.parent();
  243. // If only one course will remain, hide 'x' button
  244. if(course_select_wrapper.siblings('.course-select-wrapper').length == 1)
  245. {
  246. course_select_wrapper.siblings('.course-select-wrapper').find('.remove-course').hide();
  247. }
  248. // Remove course
  249. course_select_wrapper.remove();
  250. }
  251. // Checks whether a mini plan has outcomes
  252. function hasOutcomes(table)
  253. {
  254. if(table.find('.outcome-cell').length > 0)
  255. return true;
  256. else
  257. return false;
  258. }
  259. // Add an outcome to a mini (annual) plan
  260. function addOutcome(table)
  261. {
  262. var header_rowspan = Number(table.find('.academic-year').attr('rowspan'));
  263. var clone = table.find('tbody tr:first').clone(true, true);
  264. // Remove academic year
  265. clone.children(':first').remove();
  266. // Remove all objectives and course except the first ones
  267. clone.find('.objective-select-wrapper').not(':first').remove();
  268. clone.find('.course-select-wrapper').not(':first').remove();
  269. // Add removal button
  270. clone.children(':last').append('<span class="glyphicon glyphicon-remove text-danger icon-btn remove-outcome"></span>');
  271. if(hasOutcomes(table))
  272. {
  273. table.find('tbody').append(clone);
  274. table.find('.academic-year').attr('rowspan', header_rowspan+1);
  275. }
  276. }
  277. // Remove an Outcome
  278. function removeOutcome(table, row)
  279. {
  280. var header_rowspan = Number(table.find('.academic-year').attr('rowspan'));
  281. row.remove();
  282. table.find('.academic-year').attr('rowspan', header_rowspan-1);
  283. }
  284. // Fetch objectives associated to an outcome and program
  285. function fetchObjectives(outcome)
  286. {
  287. var outcome_id = outcome.find(':selected').val();
  288. var program_id = $('#program').data('program-id');
  289. $.post(
  290. "{{ URL::action('ObjectivesController@fetch') }}",
  291. {
  292. outcome_id: outcome_id,
  293. program_id: program_id,
  294. format: 'select'
  295. },
  296. function(data)
  297. {
  298. var select = outcome.closest('tr').find('.objective');
  299. if(data == '')
  300. {
  301. select.prop('disabled', true);
  302. select.empty().append('<option value="0"><span class="glyphicon glyphicon-remove"></span> None</option>');
  303. }
  304. else
  305. {
  306. select.prop('disabled', false);
  307. select.empty().append(data);
  308. }
  309. if(select.length > 1) {
  310. select.first().parent().siblings('.objective-select-wrapper').remove();
  311. }
  312. }
  313. );
  314. }
  315. @stop