暫無描述

objectives.blade.php 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. @extends('layouts.master')
  2. @section('navigation')
  3. @include('local.managers.sCoords._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 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 Outcome
  36. </button>
  37. <!-- Associated Program -->
  38. <div class="form-group">
  39. {{ Form::label('program_id', 'Associated Program') }}<br>
  40. <br>
  41. @foreach ($programs as $program)
  42. <input type="checkbox" id="{{ $program->name }}" name="program_id[]"
  43. value="{{ $program->id }}">
  44. <label for="{{ $program->name }}"> {{ $program->name }}
  45. [{{ $program->school->name }}]</label><br>
  46. @endforeach
  47. </div>
  48. <div class="form-group">
  49. {{ Form::label('text', 'Text') }}
  50. {{ Form::text('text', '', ['class' => 'form-control']) }}
  51. </div>
  52. {{ Form::submit('Create', ['class' => 'btn btn-primary btn-block']) }}
  53. {{ Form::close() }}
  54. </div>
  55. </div>
  56. </div>
  57. <div class="col-md-6">
  58. <div class="panel panel-default panel-button">
  59. <div class="panel-heading">
  60. Edit
  61. </div>
  62. <div class="panel-body">
  63. <button class="btn btn-md btn-secondary filterButton">
  64. <span class="glyphicon glyphicon-plus">
  65. </span>
  66. Filters
  67. </button>
  68. <div class='filterSection'>
  69. {{ Form::open(['action' => 'Objective2Controller@update']) }}
  70. <div class="form-group">
  71. {{ Form::label('program_id2', 'Associated Program') }}
  72. <select id='select-program' class="form-control selectpicker"
  73. onchange='fetchAllObjectives("select-program", "assoc_outcomes_fetch")'>
  74. @foreach ($programs as $program)
  75. <option value='{{ $program->id }}' data-subtext="{{ $program->code }}">
  76. {{ $program->name }}</option>
  77. @endforeach
  78. </select>
  79. </div>
  80. <div class="form-group">
  81. <label>Associated Outcome</label>
  82. {{-- Form::select('assoc_outcome_fetch', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcomes_fetch', 'onchange'=>'fetchAllObjectives("select-program", "assoc_outcomes_fetch")']) --}}
  83. <select id="assoc_outcomes_fetch" name="assoc_outcome_fetch" class="form-control selectpicker"
  84. onchange="fetchAllObjectives('select-program', 'assoc_outcomes_fetch')">
  85. @foreach ($outcomes as $outcome)
  86. <option value="{{ $outcome->id }}">
  87. {{ $outcome->name }}
  88. </option>
  89. @endforeach
  90. </select>
  91. </div>
  92. </div>
  93. <hr>
  94. <div class="form-group">
  95. {{ Form::label('objective_id', 'Objectives') }}
  96. <select id="select-objective" name="id" class="form-control selectpicker">
  97. @foreach ($objectives as $objective)
  98. <option value="{{ $objective->id }}" data-subtext="
  99. @if ($objective->program)
  100. &nbsp;&nbsp;&nbsp;[{{ $objective->program->name }}]
  101. @endif
  102. ">
  103. {{ $objective->text }}
  104. </option>
  105. @endforeach
  106. </select>
  107. </div>
  108. <!-- Associated Outcome -->
  109. <div class="form-group">
  110. <div id='assocOutcomeGroup'>
  111. <label>Associated 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 Outcome
  125. </button>
  126. <!-- Associated Program -->
  127. <div class="form-group">
  128. {{ Form::label('program_id2', 'Associated Program') }}<br><br>
  129. @foreach ($programs as $program)
  130. <input type="checkbox" id="assoc_program_id_{{ $program->id }}" name="assoc_program_id[]"
  131. value="{{ $program->id }}">
  132. <label for="assoc_program_id_{{ $program->id }}"> {{ $program->name }}
  133. <sub>[{{ $program->school->name }}]</sub></label><br>
  134. @endforeach
  135. </div>
  136. <!-- Status -->
  137. <div class="form-group">
  138. {{ Form::label('status', 'Status') }}
  139. <span data-toggle="tooltip" data-placement="top"
  140. 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."
  141. class="glyphicon glyphicon-question-sign"></span>
  142. <select id="status" name="status" class="form-control">
  143. <option value="1">Active</option>
  144. <option value="0">Inactive</option>
  145. </select>
  146. </div>
  147. <div class="form-group">
  148. {{ Form::label('text', 'Text') }}
  149. {{ Form::text('text', Input::old('text'), ['class' => 'form-control', 'id' => 'objective-text']) }}
  150. </div>
  151. <div id="text">
  152. </div>
  153. {{ Form::submit('Update', ['class' => 'btn btn-primary btn-block', 'id' => 'update_button']) }}
  154. {{ Form::close() }}
  155. <form action="/deleteObjective" method="POST" id='deleteObj'>
  156. </form>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. <script>
  162. $('.filterSection').hide();
  163. $('.filterButton').on('click', function() {
  164. var span = $(this).find('span');
  165. if (span.attr('class') == 'glyphicon glyphicon-plus') {
  166. span.attr('class', 'glyphicon glyphicon-minus');
  167. } else {
  168. span.attr('class', 'glyphicon glyphicon-plus');
  169. }
  170. $('.filterSection').toggle(533);
  171. });
  172. var outcomeHTML = document.getElementById('outcomeGroup').innerHTML;
  173. var selectOptions = document.getElementById('outcome[0]').innerHTML;
  174. function fetchAllObjectives(program, outcome) {
  175. var program_id_fetch = $('#' + program).val();
  176. var outcome_fetch = $('#' + outcome).val();
  177. $.post(
  178. "{{ URL::action('Objective2Controller@fetchAllObjectives') }}", {
  179. program_fetch: program_id_fetch,
  180. outcome_fetch: outcome_fetch
  181. },
  182. function(json) {
  183. json_length = (json.objective.length);
  184. fullHTML = '';
  185. for (var i = 0; i < json_length; i++) {
  186. fullHTML += '<option value="' + json.objective[i].id + '">' + json.objective[i].text +
  187. '</option>';
  188. }
  189. $('#select-objective').html(fullHTML);
  190. $('#select-objective').selectpicker('refresh');
  191. fetchObjectiveForEditing();
  192. },
  193. 'json'
  194. );
  195. }
  196. var ran = false;
  197. var counter = 1;
  198. var counterAssoc = 1;
  199. //Add Another 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. ran = true;
  413. counterAssoc += 1;
  414. $('#counterAssoc').val(counterAssoc);
  415. }
  416. $('#update_button').on('click', function(e) {
  417. e.preventDefault();
  418. outcome_id = []
  419. program_id = [];
  420. status = $('#status').val();
  421. text = $('#objective-text').val();
  422. id = $('#select-objective').val();
  423. $('#assocOutcomeGroup').find('select').each(function() {
  424. outcome_id.push($(this).val())
  425. })
  426. $('input[name="assoc_program_id[]"]').each(function() {
  427. if (this.checked)
  428. program_id.push($(this).val())
  429. });
  430. $.post(
  431. "{{ URL::action('Objective2Controller@update') }}", {
  432. assoc_outcome: outcome_id,
  433. program_id: program_id,
  434. status: status,
  435. text: text,
  436. id: id
  437. },
  438. function($array) {
  439. div = $('<div/>', {
  440. 'class': 'alert alert-dismissible alert-' + $array.status,
  441. 'role': 'alert'
  442. })
  443. button = $('<button/>', {
  444. 'class': 'close',
  445. 'type': 'button',
  446. 'data-dismiss': 'alert',
  447. 'aria-label': 'Close'
  448. }).html('<span aria-hidden="true">&times;</span>');
  449. div.append(button);
  450. if ($array.status == 'danger') {
  451. span = $('<span/>', {
  452. 'class': 'glyphicon glyphicon-remove-sign'
  453. });
  454. } else {
  455. span = $('<span/>', {
  456. 'class': 'glyphicon glyphicon-ok-sign'
  457. });
  458. }
  459. div.append(span);
  460. div.append($array.message);
  461. div.appendTo('#message');
  462. }
  463. )
  464. })
  465. </script>
  466. @stop
  467. @section('javascript')
  468. // --------------------------------------------------------------------------
  469. // Page load
  470. // --------------------------------------------------------------------------
  471. // Hide accordion panel contents by default
  472. $('.panel-group .panel-body').hide();
  473. $('#outcome-display').parent().hide();
  474. fetchObjectiveForEditing();
  475. // setCriterionStatus();
  476. fetchAllObjectives("select-program", "assoc_outcomes_fetch")
  477. // --------------------------------------------------------------------------
  478. // Functions
  479. // --------------------------------------------------------------------------
  480. // Fetch criterion info for editing
  481. $('#button-add-outcome').on('click', function(e) {
  482. // Prevent the default action of the clicked item. In this case that is submit
  483. e.preventDefault();
  484. return false;
  485. });
  486. $('#button-add-assoc-outcome').on('click', function(e) {
  487. // Prevent the default action of the clicked item. In this case that is submit
  488. e.preventDefault();
  489. return false;
  490. });
  491. // --------------------------------------------------------------------------
  492. // Events
  493. // --------------------------------------------------------------------------
  494. // When panel heading is clicked, toggle it
  495. $('.panel-group .panel-heading').on('click', function()
  496. {
  497. $(this).next().stop().slideToggle();
  498. })
  499. // When list item is clicked, load corresponding info
  500. $('#select-objective').on('change', function()
  501. {
  502. fetchObjectiveForEditing();
  503. $('.selectpicker').selectpicker('refresh');
  504. });
  505. // When list item is clicked, load corresponding info
  506. $('.selectpicker').on('change', function()
  507. {
  508. //alert($(this).find(':selected').val());
  509. $('.selectpicker').selectpicker('refresh');
  510. });
  511. @stop