No Description

objectives.blade.php 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. @extends('layouts.master')
  2. @section('navigation')
  3. @include('local.managers.pCoords._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. <input type="hidden" id='assoc_program' name="program_id[]" value="{{ $programs[0]->id }}">
  42. <input type="checkbox" id="{{ $programs[0]->name }}" name="program_id[]"
  43. value="{{ $programs[0]->id }}" disabled checked>
  44. <label for="{{ $programs[0]->name }}"> {{ $programs[0]->name }}
  45. [{{ $programs[0]->school->name }}]</label><br>
  46. </div>
  47. <div class="form-group">
  48. {{ Form::label('text', 'Text') }}
  49. {{ Form::text('text', '', ['class' => 'form-control']) }}
  50. </div>
  51. {{ Form::submit('Create', ['class' => 'btn btn-primary btn-block']) }}
  52. {{ Form::close() }}
  53. </div>
  54. </div>
  55. </div>
  56. <div class="col-md-6">
  57. <div class="panel panel-default panel-button">
  58. <div class="panel-heading">
  59. Edit
  60. </div>
  61. <div class="panel-body">
  62. <button class="btn btn-md btn-secondary filterButton">
  63. <span class="glyphicon glyphicon-plus">
  64. </span>
  65. Filters
  66. </button>
  67. <div class='filterSection'>
  68. {{ Form::open(['action' => 'Objective2Controller@update']) }}
  69. <div class="form-group">
  70. {{ Form::label('program_id2', 'Associated Program') }}
  71. <select id='select-program' class="form-control selectpicker"
  72. onchange='fetchAllObjectives("select-program", "assoc_outcomes_fetch")'>
  73. @foreach ($programs as $program)
  74. <option value='{{ $program->id }}' data-subtext="{{ $program->code }}">
  75. {{ $program->name }}</option>
  76. @endforeach
  77. </select>
  78. </div>
  79. <div class="form-group">
  80. <label>Associated Outcome</label>
  81. {{-- Form::select('assoc_outcome_fetch', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcomes_fetch', 'onchange'=>'fetchAllObjectives("select-program", "assoc_outcomes_fetch")']) --}}
  82. <select id="assoc_outcomes_fetch" name="assoc_outcome_fetch" class="form-control selectpicker"
  83. onchange="fetchAllObjectives('select-program', 'assoc_outcomes_fetch')">
  84. @foreach ($outcomes as $outcome)
  85. <option value="{{ $outcome->id }}">
  86. {{ $outcome->name }}
  87. </option>
  88. @endforeach
  89. </select>
  90. </div>
  91. </div>
  92. <hr>
  93. <div class="form-group">
  94. {{ Form::label('objective_id', 'Objectives') }}
  95. <select id="select-objective" name='id' class="form-control selectpicker">
  96. @foreach ($objectives as $objective)
  97. <option value="{{ $objective->id }}" data-subtext="
  98. @if ($objective->program)
  99. &nbsp;&nbsp;&nbsp;[{{ $objective->program->name }}]
  100. @endif
  101. ">
  102. {{ $objective->text }}
  103. </option>
  104. @endforeach
  105. </select>
  106. </div>
  107. <!-- Associated Outcome -->
  108. <div class="form-group">
  109. <div id='assocOutcomeGroup'>
  110. <label>Associated Outcome</label>
  111. <select id="assoc_outcome0" name="assoc_outcome[]" class="form-control selectpicker">
  112. @foreach ($outcomes as $outcome)
  113. <option value="{{ $outcome->id }}">
  114. {{ $outcome->name }}
  115. </option>
  116. @endforeach
  117. </select>
  118. <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_id', 'Associated Program') }}<br>
  129. <br>
  130. <input type="hidden" id='assoc_program_id_{{ $programs[0]->id }}' name="assoc_program_id[]"
  131. value="{{ $programs[0]->id }}">
  132. <input type="checkbox" id="{{ $programs[0]->name }}"
  133. id="assoc_program_id_{{ $programs[0]->id }}" name="program_id[]"
  134. value="{{ $programs[0]->id }}" disabled checked>
  135. <label for="{{ $programs[0]->name }}"> {{ $programs[0]->name }}
  136. [{{ $programs[0]->school->name }}]</label><br>
  137. </div>
  138. <!-- Status -->
  139. <div class="form-group">
  140. {{ Form::label('status', 'Status') }}
  141. <span data-toggle="tooltip" data-placement="top"
  142. 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."
  143. class="glyphicon glyphicon-question-sign"></span>
  144. <select id="status" name="status" class="form-control">
  145. <option value="1">Active</option>
  146. <option value="0">Inactive</option>
  147. </select>
  148. </div>
  149. <div class="form-group">
  150. {{ Form::label('text', 'Text') }}
  151. {{ Form::text('text', Input::old('text'), ['class' => 'form-control', 'id' => 'objective-text']) }}
  152. </div>
  153. <div id="text">
  154. </div>
  155. {{ Form::submit('Update', ['class' => 'btn btn-primary btn-block', 'id' => 'update_button']) }}
  156. {{ Form::close() }}
  157. <form action="/deleteObjective" method="POST" id='deleteObj'>
  158. </form>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. <script>
  164. $('.filterSection').hide();
  165. $('.filterButton').on('click', function() {
  166. var span = $(this).find('span');
  167. if (span.attr('class') == 'glyphicon glyphicon-plus') {
  168. span.attr('class', 'glyphicon glyphicon-minus');
  169. } else {
  170. span.attr('class', 'glyphicon glyphicon-plus');
  171. }
  172. $('.filterSection').toggle(533);
  173. });
  174. var outcomeHTML = document.getElementById('outcomeGroup').innerHTML;
  175. var selectOptions = document.getElementById('outcome[0]').innerHTML;
  176. var ran = false;
  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. //holds both the select div and the button div
  223. var $containerdiv = $('<div/>', {
  224. 'id': 'outcomeContainer' + counter.toString(),
  225. });
  226. var $div = $('<div/>', {
  227. 'id': 'outcomeForm' + counter.toString(),
  228. 'class': 'form-group col-md-11'
  229. });
  230. var $divForButton = $('<div/>', {
  231. 'class': 'col-md-1',
  232. 'id': 'close' + counter.toString()
  233. });
  234. var $button = $('<button/>', {
  235. 'type': 'button',
  236. 'class': 'btn btn-primary',
  237. //send the counter to the function so it can tell which container to remove
  238. 'onclick': 'deleteLast(' + counter.toString() + ')',
  239. });
  240. $button.append('X');
  241. $divForButton.append($button);
  242. $containerdiv.appendTo('#outcomeGroup')
  243. $div.appendTo('#outcomeContainer' + counter.toString())
  244. $select.append(selectOptions);
  245. $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
  246. $divForButton.appendTo('#outcomeContainer' + counter.toString());
  247. counter += 1;
  248. $('#counter').val(counter);
  249. }
  250. //Recieves the counter variable so it can find the specific div and delete it
  251. function deleteLast(counter) {
  252. div = document.getElementById('outcomeContainer' + (counter).toString());
  253. div.remove();
  254. }
  255. function fetchObjectiveForEditing() {
  256. var id = $('#select-objective').find(':selected').val();
  257. $.post(
  258. "{{ URL::action('Objective2Controller@fetchObjectiveWithTrashed') }}", {
  259. id: id
  260. },
  261. function(json) {
  262. var text = json.objective[0].text;
  263. // Display info
  264. $('#objective-text').val(text);
  265. // Select associated outcome
  266. for (var i = counterAssoc; i != 1; i--) {
  267. deleteLastAssoc(i);
  268. }
  269. $('#assoc_outcome0').val(json.outcome[0].outcome_id);
  270. $('#assoc_outcome0').selectpicker('refresh');
  271. counterAssoc = 1;
  272. for (var i = 1; i < json.outcome.length; i++) {
  273. counterAssoc = i + 1;
  274. var $select = $('<select />', {
  275. 'class': "selectpicker form-control",
  276. 'name': "assoc_outcome[]",
  277. 'data-live-search': 'true',
  278. 'id': 'assoc_outcome' + i.toString()
  279. });
  280. var $div = $('<div />', {
  281. 'id': 'assocOutcomeForm' + i.toString(),
  282. 'class': 'form-group col-md-11'
  283. });
  284. var $divForButton = $('<div />', {
  285. 'class': 'col-md-1',
  286. 'id': 'closeAssoc' + i.toString()
  287. });
  288. var $button = $('<button />', {
  289. 'type': 'button',
  290. 'class': 'btn btn-primary',
  291. 'onclick': 'deleteLastAssoc()'
  292. });
  293. $button.append('X');
  294. $divForButton.append($button);
  295. $div.appendTo('#assocOutcomeGroup')
  296. $select.append(selectOptions);
  297. $select.appendTo('#assocOutcomeForm' + i.toString()).selectpicker('refresh');
  298. $divForButton.appendTo('#assocOutcomeGroup');
  299. $('#assoc_outcome' + i.toString()).val(json.outcome[i].outcome_id);
  300. $('#assoc_outcome' + i.toString()).selectpicker('refresh');
  301. }
  302. // Select status
  303. if (json.objective[0].deleted_at)
  304. $('#status').val(0);
  305. else
  306. $('#status').val(1);
  307. if (json.assessment.length) {
  308. $('#deleteObj').html(
  309. "<p>This objective is currently participating in an assessment, therefore it cannot be deleted</p>"
  310. );
  311. } else if (json.assoc_criteria.length) {
  312. modal =
  313. '<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#delete">' +
  314. 'Delete' +
  315. '</button>' +
  316. '<input type="hidden" value =' + json.objective[0].id + ' name="deleteObj">' +
  317. '<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">' +
  318. '<div class="modal-dialog" role="document">' +
  319. '<div class="modal-content">' +
  320. ' <div class="modal-header">' +
  321. '<h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>' +
  322. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
  323. '<span aria-hidden="true">&times;</span>' +
  324. '</button>' +
  325. ' </div>' +
  326. '<div class="modal-body">' +
  327. "<p>This objective is associated to: <p>" +
  328. '<ul>';
  329. for (var i = 0; i < json.assoc_criteria.length; i++) {
  330. modal += "<li>" + json.assoc_criteria[i].name + '</li>';
  331. }
  332. modal += ' </ul>' +
  333. '<p>Do you still want to delete it?</p>' +
  334. '</div>' +
  335. '<div class="modal-footer">' +
  336. '<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>' +
  337. '<button type="submit" class="btn btn-primary">Delete</button>' +
  338. '</div>' +
  339. '</div>' +
  340. '</div>' +
  341. '</div>';
  342. $('#deleteObj').html(modal);
  343. } else {
  344. modal =
  345. '<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#delete">' +
  346. 'Delete' +
  347. '</button>' +
  348. '<input type="hidden" value =' + json.objective[0].id + ' name="deleteObj">' +
  349. '<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">' +
  350. '<div class="modal-dialog" role="document">' +
  351. '<div class="modal-content">' +
  352. ' <div class="modal-header">' +
  353. '<h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>' +
  354. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
  355. '<span aria-hidden="true">&times;</span>' +
  356. '</button>' +
  357. ' </div>' +
  358. '<div class="modal-body">' +
  359. "<p> Once deleted, there is no chance of getting it back.</p>";
  360. modal +=
  361. '<p>Do you still want to delete it?</p>' +
  362. '</div>' +
  363. '<div class="modal-footer">' +
  364. '<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>' +
  365. '<button type="submit" class="btn btn-primary">Delete</button>' +
  366. '</div>' +
  367. '</div>' +
  368. '</div>' +
  369. '</div>';
  370. $('#deleteObj').html(modal);
  371. }
  372. },
  373. 'json'
  374. );
  375. }
  376. function deleteLastAssoc() {
  377. div = document.getElementById('assocOutcomeForm' + (counterAssoc - 1).toString());
  378. div.remove();
  379. button = document.getElementById('closeAssoc' + (counterAssoc - 1).toString());
  380. button.remove();
  381. counterAssoc -= 1;
  382. $('#counterAssoc').val(counterAssoc);
  383. }
  384. function addAssoc() {
  385. var $select = $('<select />', {
  386. 'class': "selectpicker form-control",
  387. 'name': "assoc_outcome[]",
  388. 'data-live-search': 'true',
  389. 'id': 'assoc_outcome' + counterAssoc.toString(),
  390. });
  391. var $div = $('<div />', {
  392. 'id': 'assocOutcomeForm' + counterAssoc.toString(),
  393. 'class': 'form-group col-md-11'
  394. });
  395. var $divForButton = $('<div />', {
  396. 'class': 'col-md-1',
  397. 'id': 'closeAssoc' + counterAssoc.toString()
  398. });
  399. var $button = $('<button />', {
  400. 'type': 'button',
  401. 'class': 'btn btn-primary',
  402. 'onclick': 'deleteLastAssoc()'
  403. });
  404. $button.append('X');
  405. $divForButton.append($button);
  406. $div.appendTo('#assocOutcomeGroup')
  407. $select.append(selectOptions);
  408. $select.appendTo('#assocOutcomeForm' + counterAssoc.toString()).selectpicker('refresh');
  409. $divForButton.appendTo('#assocOutcomeGroup');
  410. ran = true;
  411. counterAssoc += 1;
  412. $('#counterAssoc').val(counterAssoc);
  413. }
  414. $('#update_button').on('click', function(e) {
  415. e.preventDefault();
  416. outcome_id = []
  417. program_id = [];
  418. program_id.push($('#assoc_program').val());
  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. $.post(
  426. "{{ URL::action('Objective2Controller@update') }}", {
  427. assoc_outcome: outcome_id,
  428. program_id: program_id,
  429. status: status,
  430. text: text,
  431. id: id
  432. },
  433. function($array) {
  434. div = $('<div/>', {
  435. 'class': 'alert alert-dismissible alert-' + $array.status,
  436. 'role': 'alert'
  437. })
  438. button = $('<button/>', {
  439. 'class': 'close',
  440. 'type': 'button',
  441. 'data-dismiss': 'alert',
  442. 'aria-label': 'Close'
  443. }).html('<span aria-hidden="true">&times;</span>');
  444. div.append(button);
  445. if ($array.status == 'danger') {
  446. span = $('<span/>', {
  447. 'class': 'glyphicon glyphicon-remove-sign'
  448. });
  449. } else {
  450. span = $('<span/>', {
  451. 'class': 'glyphicon glyphicon-ok-sign'
  452. });
  453. }
  454. div.append(span);
  455. div.append($array.message);
  456. div.appendTo('#message');
  457. }
  458. )
  459. })
  460. </script>
  461. @stop
  462. @section('javascript')
  463. // --------------------------------------------------------------------------
  464. // Page load
  465. // --------------------------------------------------------------------------
  466. // Hide accordion panel contents by default
  467. $('.panel-group .panel-body').hide();
  468. $('#outcome-display').parent().hide();
  469. fetchObjectiveForEditing();
  470. // setCriterionStatus();
  471. fetchAllObjectives("select-program", "assoc_outcomes_fetch")
  472. // --------------------------------------------------------------------------
  473. // Functions
  474. // --------------------------------------------------------------------------
  475. // Fetch criterion info for editing
  476. $('#button-add-outcome').on('click', function(e) {
  477. // Prevent the default action of the clicked item. In this case that is submit
  478. e.preventDefault();
  479. return false;
  480. });
  481. $('#button-add-assoc-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. // --------------------------------------------------------------------------
  487. // Events
  488. // --------------------------------------------------------------------------
  489. // When panel heading is clicked, toggle it
  490. $('.panel-group .panel-heading').on('click', function()
  491. {
  492. $(this).next().stop().slideToggle();
  493. })
  494. // When list item is clicked, load corresponding info
  495. $('#select-objective').on('change', function()
  496. {
  497. fetchObjectiveForEditing();
  498. $('.selectpicker').selectpicker('refresh');
  499. });
  500. // When list item is clicked, load corresponding info
  501. $('.selectpicker').on('change', function()
  502. {
  503. //alert($(this).find(':selected').val());
  504. $('.selectpicker').selectpicker('refresh');
  505. });
  506. @stop