Keine Beschreibung

objectives.blade.php 26KB

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