No Description

objectives.blade.php 20KB

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