Keine Beschreibung

objectives.blade.php 19KB

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