No Description

objectives.blade.php 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. @extends('layouts.master')
  2. @section('navigation')
  3. @include('local.managers.admins._new_navigation')
  4. @stop
  5. @section('main')
  6. <div class="row">
  7. <div class="col-md-12" id='message'>
  8. </div>
  9. </div>
  10. <div class="row">
  11. <div class="col-md-6">
  12. <!-- Form to add a new objective -->
  13. <div class="panel panel-default panel-button">
  14. <div class="panel-heading">
  15. Create
  16. </div>
  17. <div class="panel-body">
  18. {{ Form::open(['action' => 'Objective2Controller@create']) }}
  19. <div id='outcomeGroup'>
  20. <label> Associated Learning Outcome</label>
  21. <div class="form-group col-md-11" id='outcomeForm'>
  22. <select id="outcome[0]" name="outcome[0]" class="form-control selectpicker">
  23. @foreach ($outcomes as $outcome)
  24. <option value="{{ $outcome->id }}">
  25. {{ $outcome->name }}
  26. </option>
  27. @endforeach
  28. </select>
  29. </div>
  30. </div>
  31. <input type='hidden' name='counter' id='counter' value=1>
  32. <button id='button-add-outcome' class='btn btn-md btn-secondary' onclick='addOutcomeTest()'>
  33. <span class='glyphicon glyphicon-plus'>
  34. </span>
  35. Add another Learning Outcome
  36. </button>
  37. <!-- Associated Program -->
  38. <!-- Associated Program -->
  39. <div class="form-group">
  40. {{ Form::label('program_id', 'Associated Program') }}<br>
  41. <br>
  42. @foreach ($programs as $program)
  43. <input type="checkbox" id="{{ $program->name }}" name="program_id[]"
  44. value="{{ $program->id }}">
  45. <label for="{{ $program->name }}"> {{ $program->name }}
  46. [{{ $program->school->name }}]</label><br>
  47. @endforeach
  48. </div>
  49. <div class="form-group">
  50. {{ Form::label('text', 'Text') }}
  51. {{ Form::text('text', '', ['class' => 'form-control']) }}
  52. </div>
  53. {{ Form::submit('Create', ['class' => 'btn btn-primary btn-block']) }}
  54. {{ Form::close() }}
  55. </div>
  56. </div>
  57. </div>
  58. <div class="col-md-6">
  59. <div class="panel panel-default panel-button">
  60. <div class="panel-heading">
  61. Edit
  62. </div>
  63. <div class="panel-body">
  64. <button class="btn btn-md btn-secondary filterButton">
  65. <span class="glyphicon glyphicon-minus">
  66. </span>
  67. Filters
  68. </button>
  69. <div class='filterSection'>
  70. {{ Form::open(['action' => 'Objective2Controller@update']) }}
  71. <div class="form-group">
  72. {{ Form::label('program_id2', 'Associated Program') }}
  73. <select id='select-program' class="form-control selectpicker"
  74. onchange='fetchAllObjectives("select-program", "assoc_outcomes_fetch")'>
  75. @foreach ($programs as $program)
  76. <option value='{{ $program->id }}' data-subtext="{{ $program->code }}">
  77. {{ $program->name }}</option>
  78. @endforeach
  79. </select>
  80. </div>
  81. <div class="form-group">
  82. <label>Associated Learning Outcome</label>
  83. {{-- Form::select('assoc_outcome_fetch', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcomes_fetch', 'onchange'=>'fetchAllObjectives("select-program", "assoc_outcomes_fetch")']) --}}
  84. <select id="assoc_outcomes_fetch" name="assoc_outcome_fetch" class="form-control selectpicker"
  85. onchange="fetchAllObjectives('select-program', 'assoc_outcomes_fetch')">
  86. @foreach ($outcomes as $outcome)
  87. <option value="{{ $outcome->id }}">
  88. {{ $outcome->name }}
  89. </option>
  90. @endforeach
  91. </select>
  92. </div>
  93. </div>
  94. <hr>
  95. <div class="form-group">
  96. {{ Form::label('objective_id', 'Objectives') }}
  97. <select id="select-objective" name="id" class="form-control selectpicker">
  98. @foreach ($objectives as $objective)
  99. <option value="{{ $objective->id }}" data-subtext="
  100. @if ($objective->program) &nbsp;&nbsp;&nbsp;[{{ $objective->program->name }}] @endif
  101. ">
  102. {{ $objective->text }}
  103. </option>
  104. @endforeach
  105. </select>
  106. </div>
  107. <hr>
  108. <!-- Associated Learning Outcome -->
  109. <div class="form-group">
  110. <div id='assocOutcomeGroup'>
  111. <label>Associated Learning Outcome</label>
  112. <select id="assoc_outcome0" name="assoc_outcome[]" class="form-control selectpicker">
  113. @foreach ($outcomes as $outcome)
  114. <option value="{{ $outcome->id }}">
  115. {{ $outcome->name }}
  116. </option>
  117. @endforeach
  118. </select><br><br>
  119. </div>
  120. </div>
  121. <button id='button-add-assoc-outcome' class='btn btn-md btn-secondary' onclick='addAssoc()'>
  122. <span class='glyphicon glyphicon-plus'>
  123. </span>
  124. Add another Learning Outcome
  125. </button>
  126. <!-- Associated Program -->
  127. <!-- Associated Program -->
  128. <div class="form-group">
  129. {{ Form::label('program_id2', 'Associated Program') }}<br><br>
  130. @foreach ($programs as $program)
  131. <input type="checkbox" id="assoc_program_id_{{ $program->id }}" name="assoc_program_id[]"
  132. value="{{ $program->id }}">
  133. <label for="assoc_program_id_{{ $program->id }}"> {{ $program->name }}
  134. <sub>[{{ $program->school->name }}]</sub></label><br>
  135. @endforeach
  136. </div>
  137. <!-- Status -->
  138. <div class="form-group">
  139. {{ Form::label('status', 'Status') }}
  140. <span data-toggle="tooltip" data-placement="top"
  141. title="Use this option to deactivate or reactivate objectives. Inactive objective will stay in the system, but will not be available to use in new rubrics."
  142. class="glyphicon glyphicon-question-sign"></span>
  143. <select id="status" name="status" class="form-control">
  144. <option value="1">Active</option>
  145. <option value="0">Inactive</option>
  146. </select>
  147. </div>
  148. <div class="form-group">
  149. {{ Form::label('text', 'Text') }}
  150. {{ Form::text('text', Input::old('text'), ['class' => 'form-control', 'id' => 'objective-text']) }}
  151. </div>
  152. <div id="text">
  153. </div>
  154. {{ Form::submit('Update', ['class' => 'btn btn-primary btn-block', 'id' => 'update_button']) }}
  155. {{ Form::close() }}
  156. <form action="/deleteObjective" method="POST" id='deleteObj'>
  157. </form>
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. <script>
  163. $('.filterSection').show();
  164. $('.filterButton').on('click', function() {
  165. var span = $(this).find('span');
  166. if (span.attr('class') == 'glyphicon glyphicon-plus') {
  167. span.attr('class', 'glyphicon glyphicon-minus');
  168. } else {
  169. span.attr('class', 'glyphicon glyphicon-plus');
  170. }
  171. $('.filterSection').toggle(533);
  172. });
  173. var outcomeHTML = document.getElementById('outcomeGroup').innerHTML;
  174. var selectOptions = document.getElementById('outcome[0]').innerHTML;
  175. function fetchAllObjectives(program, outcome) {
  176. var program_id_fetch = $('#' + program).find(':selected').val();
  177. var outcome_fetch = $('#' + outcome).find(':selected').val();
  178. $.post(
  179. "{{ URL::action('Objective2Controller@fetchAllObjectives') }}", {
  180. program_fetch: program_id_fetch,
  181. outcome_fetch: outcome_fetch
  182. },
  183. function(json) {
  184. json_length = (json.objective.length);
  185. fullHTML = '';
  186. for (var i = 0; i < json_length; i++) {
  187. fullHTML += '<option value="' + json.objective[i].id + '">' + json.objective[i].text +
  188. '</option>';
  189. }
  190. $('#select-objective').html(fullHTML);
  191. $('#select-objective').selectpicker('refresh');
  192. fetchObjectiveForEditing();
  193. },
  194. 'json'
  195. );
  196. }
  197. var counter = 1;
  198. var counterAssoc = 1;
  199. //Add Another Learning Outcome
  200. function changeOutcomeHtml() {
  201. var outcomeHTML = document.getElementById('outcomeGroup').innerHTML;
  202. outcomeHTML = outcomeHTML.replace('outcome[' + counter.toString() + ']', 'outcome[' + (counter + 1).toString() +
  203. ']');
  204. counter += 1;
  205. document.getElementById("outcomeGroup").innerHTML += outcomeHTML;
  206. document.getElementById('button-add-outcome').onclick = addOutcome;
  207. }
  208. function addOutcome() {
  209. outcomeHTML = outcomeHTML.replace('outcome[' + counter.toString() + ']', 'outcome[' + (counter + 1).toString() +
  210. ']');
  211. counter += 1;
  212. document.getElementById("outcomeGroup").innerHTML += outcomeHTML;
  213. }
  214. function addOutcomeTest() {
  215. var $select = $('<select/>', {
  216. 'class': "selectpicker form-control",
  217. 'name': "outcome[" + counter.toString() + "]",
  218. 'data-live-search': 'true'
  219. });
  220. var $div = $('<div/>', {
  221. 'id': 'outcomeForm' + counter.toString(),
  222. 'class': 'form-group col-md-11'
  223. });
  224. var $divForButton = $('<div/>', {
  225. 'class': 'col-md-1',
  226. 'id': 'close' + counter.toString()
  227. });
  228. var $button = $('<button/>', {
  229. 'type': 'button',
  230. 'class': 'btn btn-primary',
  231. 'onclick': 'deleteLast()'
  232. });
  233. $button.append('X');
  234. $divForButton.append($button);
  235. $div.appendTo('#outcomeGroup')
  236. $select.append(selectOptions);
  237. $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
  238. $divForButton.appendTo('#outcomeGroup');
  239. counter += 1;
  240. $('#counter').val(counter);
  241. }
  242. function deleteLast() {
  243. div = document.getElementById('outcomeForm' + (counter - 1).toString());
  244. div.remove();
  245. button = document.getElementById('close' + (counter - 1).toString());
  246. button.remove();
  247. counter -= 1;
  248. $('#counter').val(counter);
  249. }
  250. function fetchObjectiveForEditing() {
  251. var id = $('#select-objective').find(':selected').val();
  252. $.post(
  253. "{{ URL::action('Objective2Controller@fetchObjectiveWithTrashed') }}", {
  254. id: id
  255. },
  256. function(json) {
  257. var text = json.objective[0].text;
  258. // Display info
  259. $('#objective-text').val(text);
  260. // Select associated outcome
  261. for (var i = counterAssoc; i != 1; i--) {
  262. deleteLastAssoc(i);
  263. }
  264. $('#assoc_outcome0').val(json.outcome[0].outcome_id);
  265. $('#assoc_outcome0').selectpicker('refresh');
  266. counterAssoc = 1;
  267. for (var i = 1; i < json.outcome.length; i++) {
  268. counterAssoc = i + 1;
  269. var $select = $('<select />', {
  270. 'class': "selectpicker form-control",
  271. 'name': "assoc_outcome[]",
  272. 'data-live-search': 'true',
  273. 'id': 'assoc_outcome' + i.toString()
  274. });
  275. var $div = $('<div />', {
  276. 'id': 'assocOutcomeForm' + i.toString(),
  277. 'class': 'form-group col-md-11'
  278. });
  279. var $divForButton = $('<div />', {
  280. 'class': 'col-md-1',
  281. 'id': 'closeAssoc' + i.toString()
  282. });
  283. var $button = $('<button />', {
  284. 'type': 'button',
  285. 'class': 'btn btn-primary',
  286. 'onclick': 'deleteLastAssoc()'
  287. });
  288. $button.append('X');
  289. $divForButton.append($button);
  290. $div.appendTo('#assocOutcomeGroup')
  291. $select.append(selectOptions);
  292. $select.appendTo('#assocOutcomeForm' + i.toString()).selectpicker('refresh');
  293. $divForButton.appendTo('#assocOutcomeGroup');
  294. $('#assoc_outcome' + i.toString()).val(json.outcome[i].outcome_id);
  295. $('#assoc_outcome' + i.toString()).selectpicker('refresh');
  296. }
  297. // Select associated program
  298. var program_length = json.program.length;
  299. $('input[type=checkbox]').prop('checked', false);
  300. for (var i = 0; i < program_length; i++) {
  301. prog = json.program[i].program_id.toString();
  302. $('#assoc_program_id_' + prog).prop("checked", true);
  303. }
  304. // Select status
  305. if (json.objective[0].deleted_at)
  306. $('#status').val(0);
  307. else
  308. $('#status').val(1);
  309. if (json.assessment.length) {
  310. $('#deleteObj').html(
  311. "<p>This objective is currently participating in an assessment, therefore it cannot be deleted</p>"
  312. );
  313. } else if (json.assoc_criteria.length) {
  314. modal =
  315. '<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#delete">' +
  316. 'Delete' +
  317. '</button>' +
  318. '<input type="hidden" value =' + json.objective[0].id + ' name="deleteObj">' +
  319. '<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">' +
  320. '<div class="modal-dialog" role="document">' +
  321. '<div class="modal-content">' +
  322. ' <div class="modal-header">' +
  323. '<h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>' +
  324. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
  325. '<span aria-hidden="true">&times;</span>' +
  326. '</button>' +
  327. ' </div>' +
  328. '<div class="modal-body">' +
  329. "<p>This objective is associated to: <p>" +
  330. '<ul>';
  331. for (var i = 0; i < json.assoc_criteria.length; i++) {
  332. modal += "<li>" + json.assoc_criteria[i].name + '</li>';
  333. }
  334. modal += ' </ul>' +
  335. '<p>Do you still want to delete it?</p>' +
  336. '</div>' +
  337. '<div class="modal-footer">' +
  338. '<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>' +
  339. '<button type="submit" class="btn btn-primary">Delete</button>' +
  340. '</div>' +
  341. '</div>' +
  342. '</div>' +
  343. '</div>';
  344. $('#deleteObj').html(modal);
  345. } else {
  346. modal =
  347. '<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#delete">' +
  348. 'Delete' +
  349. '</button>' +
  350. '<input type="hidden" value =' + json.objective[0].id + ' name="deleteObj">' +
  351. '<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">' +
  352. '<div class="modal-dialog" role="document">' +
  353. '<div class="modal-content">' +
  354. ' <div class="modal-header">' +
  355. '<h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>' +
  356. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
  357. '<span aria-hidden="true">&times;</span>' +
  358. '</button>' +
  359. ' </div>' +
  360. '<div class="modal-body">' +
  361. "<p> Once deleted, there is no chance of getting it back.</p>";
  362. modal +=
  363. '<p>Do you still want to delete it?</p>' +
  364. '</div>' +
  365. '<div class="modal-footer">' +
  366. '<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>' +
  367. '<button type="submit" class="btn btn-primary">Delete</button>' +
  368. '</div>' +
  369. '</div>' +
  370. '</div>' +
  371. '</div>';
  372. $('#deleteObj').html(modal);
  373. }
  374. },
  375. 'json'
  376. );
  377. }
  378. function deleteLastAssoc() {
  379. div = document.getElementById('assocOutcomeForm' + (counterAssoc - 1).toString());
  380. div.remove();
  381. button = document.getElementById('closeAssoc' + (counterAssoc - 1).toString());
  382. button.remove();
  383. counterAssoc -= 1;
  384. $('#counterAssoc').val(counterAssoc);
  385. }
  386. function addAssoc() {
  387. var $select = $('<select />', {
  388. 'class': "selectpicker form-control",
  389. 'name': "assoc_outcome[]",
  390. 'data-live-search': 'true',
  391. 'id': 'assoc_outcome' + counterAssoc.toString()
  392. });
  393. var $div = $('<div />', {
  394. 'id': 'assocOutcomeForm' + counterAssoc.toString(),
  395. 'class': 'form-group col-md-11'
  396. });
  397. var $divForButton = $('<div />', {
  398. 'class': 'col-md-1',
  399. 'id': 'closeAssoc' + counterAssoc.toString()
  400. });
  401. var $button = $('<button />', {
  402. 'type': 'button',
  403. 'class': 'btn btn-primary',
  404. 'onclick': 'deleteLastAssoc()'
  405. });
  406. $button.append('X');
  407. $divForButton.append($button);
  408. $div.appendTo('#assocOutcomeGroup')
  409. $select.append(selectOptions);
  410. $select.appendTo('#assocOutcomeForm' + counterAssoc.toString()).selectpicker('refresh');
  411. $divForButton.appendTo('#assocOutcomeGroup');
  412. counterAssoc += 1;
  413. $('#counterAssoc').val(counterAssoc);
  414. }
  415. $('#update_button').on('click', function(e) {
  416. e.preventDefault();
  417. outcome_id = []
  418. program_id = [];
  419. status = $('#status').val();
  420. text = $('#objective-text').val();
  421. id = $('#select-objective').val();
  422. $('#assocOutcomeGroup').find('select').each(function() {
  423. outcome_id.push($(this).val())
  424. })
  425. $('input[name="assoc_program_id[]"]').each(function() {
  426. if (this.checked)
  427. program_id.push($(this).val())
  428. });
  429. $.post(
  430. "{{ URL::action('Objective2Controller@update') }}", {
  431. assoc_outcome: outcome_id,
  432. program_id: program_id,
  433. status: status,
  434. text: text,
  435. id: id
  436. },
  437. function($array) {
  438. div = $('<div/>', {
  439. 'class': 'alert alert-dismissible alert-' + $array.status,
  440. 'role': 'alert'
  441. })
  442. button = $('<button/>', {
  443. 'class': 'close',
  444. 'type': 'button',
  445. 'data-dismiss': 'alert',
  446. 'aria-label': 'Close'
  447. }).html('<span aria-hidden="true">&times;</span>');
  448. div.append(button);
  449. if ($array.status == 'danger') {
  450. span = $('<span/>', {
  451. 'class': 'glyphicon glyphicon-remove-sign'
  452. });
  453. } else {
  454. span = $('<span/>', {
  455. 'class': 'glyphicon glyphicon-ok-sign'
  456. });
  457. }
  458. div.append(span);
  459. div.append($array.message);
  460. div.appendTo('#message');
  461. }
  462. )
  463. })
  464. </script>
  465. @stop
  466. @section('javascript')
  467. // --------------------------------------------------------------------------
  468. // Page load
  469. // --------------------------------------------------------------------------
  470. // Hide accordion panel contents by default
  471. $('.panel-group .panel-body').hide();
  472. $('#outcome-display').parent().hide();
  473. fetchObjectiveForEditing();
  474. // setCriterionStatus();
  475. fetchAllObjectives("select-program", "assoc_outcomes_fetch")
  476. // --------------------------------------------------------------------------
  477. // Functions
  478. // --------------------------------------------------------------------------
  479. // Fetch criterion info for editing
  480. $('#button-add-outcome').on('click', function(e) {
  481. // Prevent the default action of the clicked item. In this case that is submit
  482. e.preventDefault();
  483. return false;
  484. });
  485. $('#button-add-assoc-outcome').on('click', function(e) {
  486. // Prevent the default action of the clicked item. In this case that is submit
  487. e.preventDefault();
  488. return false;
  489. });
  490. // --------------------------------------------------------------------------
  491. // Events
  492. // --------------------------------------------------------------------------
  493. // When panel heading is clicked, toggle it
  494. $('.panel-group .panel-heading').on('click', function()
  495. {
  496. $(this).next().stop().slideToggle();
  497. })
  498. // When list item is clicked, load corresponding info
  499. $('#select-objective').on('change', function()
  500. {
  501. fetchObjectiveForEditing();
  502. $('.selectpicker').selectpicker('refresh');
  503. });
  504. // When list item is clicked, load corresponding info
  505. $('.selectpicker').on('change', function()
  506. {
  507. //alert($(this).find(':selected').val());
  508. $('.selectpicker').selectpicker('refresh');
  509. });
  510. @stop