No Description

create_annual_plan.blade.php 10KB

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