Brak opisu

objectives.blade.php 25KB

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