Keine Beschreibung

objectives.blade.php 20KB

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