No Description

objectives.blade.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. {
  133. var span = $(this).find('span');
  134. if(span.attr('class') == 'glyphicon glyphicon-plus'){
  135. span.attr('class','glyphicon glyphicon-minus');
  136. } else{
  137. span.attr('class','glyphicon glyphicon-plus');
  138. }
  139. $('.filterSection').toggle(533);
  140. });
  141. var outcomeHTML = document.getElementById('outcomeGroup').innerHTML;
  142. var selectOptions = document.getElementById('outcome[0]').innerHTML;
  143. var ran = false;
  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);
  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': "assoc_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()'
  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 status
  264. if (json.objective[0].deleted_at)
  265. $('#status').val(0);
  266. else
  267. $('#status').val(1);
  268. if (json.assessment.length) {
  269. $('#deleteObj').html("<p>This objective is currently participating in an assessment, therefore it cannot be deleted</p>");
  270. } else if (json.assoc_criteria.length) {
  271. modal = '<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#delete">' +
  272. 'Delete' +
  273. '</button>' +
  274. '<input type="hidden" value =' + json.objective[0].id + ' name="deleteObj">' +
  275. '<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">' +
  276. '<div class="modal-dialog" role="document">' +
  277. '<div class="modal-content">' +
  278. ' <div class="modal-header">' +
  279. '<h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>' +
  280. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
  281. '<span aria-hidden="true">&times;</span>' +
  282. '</button>' +
  283. ' </div>' +
  284. '<div class="modal-body">' +
  285. "<p>This objective is associated to: <p>" +
  286. '<ul>';
  287. for (var i = 0; i < json.assoc_criteria.length; i++) {
  288. modal += "<li>" + json.assoc_criteria[i].name + '</li>';
  289. }
  290. modal += ' </ul>' +
  291. '<p>Do you still want to delete it?</p>' +
  292. '</div>' +
  293. '<div class="modal-footer">' +
  294. '<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>' +
  295. '<button type="submit" class="btn btn-primary">Delete</button>' +
  296. '</div>' +
  297. '</div>' +
  298. '</div>' +
  299. '</div>';
  300. $('#deleteObj').html(modal);
  301. } else {
  302. modal = '<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#delete">' +
  303. 'Delete' +
  304. '</button>' +
  305. '<input type="hidden" value =' + json.objective[0].id + ' name="deleteObj">' +
  306. '<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">' +
  307. '<div class="modal-dialog" role="document">' +
  308. '<div class="modal-content">' +
  309. ' <div class="modal-header">' +
  310. '<h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>' +
  311. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
  312. '<span aria-hidden="true">&times;</span>' +
  313. '</button>' +
  314. ' </div>' +
  315. '<div class="modal-body">' +
  316. "<p> Once deleted, there is no chance of getting it back.</p>";
  317. modal +=
  318. '<p>Do you still want to delete it?</p>' +
  319. '</div>' +
  320. '<div class="modal-footer">' +
  321. '<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>' +
  322. '<button type="submit" class="btn btn-primary">Delete</button>' +
  323. '</div>' +
  324. '</div>' +
  325. '</div>' +
  326. '</div>';
  327. $('#deleteObj').html(modal);
  328. }
  329. },
  330. 'json'
  331. );
  332. }
  333. function deleteLastAssoc() {
  334. div = document.getElementById('assocOutcomeForm' + (i).toString());
  335. div.remove();
  336. button = document.getElementById('closeAssoc' + (i).toString());
  337. button.remove();
  338. counterAssoc -= 1;
  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. });
  347. var $div = $('<div />', {
  348. 'id': 'assocOutcomeForm' + counterAssoc.toString(),
  349. 'class': 'form-group col-md-11'
  350. });
  351. var $divForButton = $('<div />', {
  352. 'class': 'col-md-1',
  353. 'id': 'closeAssoc' + counterAssoc.toString()
  354. });
  355. var $button = $('<button />', {
  356. 'type': 'button',
  357. 'class': 'btn btn-primary',
  358. 'onclick': 'deleteLastAssoc()'
  359. });
  360. $button.append('X');
  361. $divForButton.append($button);
  362. $div.appendTo('#assocOutcomeGroup')
  363. $select.append(selectOptions);
  364. $select.appendTo('#assocOutcomeForm' + counterAssoc.toString()).selectpicker('refresh');
  365. $divForButton.appendTo('#assocOutcomeGroup');
  366. ran = true;
  367. counterAssoc += 1;
  368. }
  369. </script>
  370. @stop
  371. @section('javascript')
  372. // --------------------------------------------------------------------------
  373. // Page load
  374. // --------------------------------------------------------------------------
  375. // Hide accordion panel contents by default
  376. $('.panel-group .panel-body').hide();
  377. $('#outcome-display').parent().hide();
  378. fetchObjectiveForEditing();
  379. // setCriterionStatus();
  380. fetchAllObjectives("select-program", "assoc_outcomes_fetch")
  381. // --------------------------------------------------------------------------
  382. // Functions
  383. // --------------------------------------------------------------------------
  384. // Fetch criterion info for editing
  385. $('#button-add-outcome').on('click', function(e) {
  386. // Prevent the default action of the clicked item. In this case that is submit
  387. e.preventDefault();
  388. return false;
  389. });
  390. $('#button-add-assoc-outcome').on('click', function(e) {
  391. // Prevent the default action of the clicked item. In this case that is submit
  392. e.preventDefault();
  393. return false;
  394. });
  395. // --------------------------------------------------------------------------
  396. // Events
  397. // --------------------------------------------------------------------------
  398. // When panel heading is clicked, toggle it
  399. $('.panel-group .panel-heading').on('click', function()
  400. {
  401. $(this).next().stop().slideToggle();
  402. })
  403. // When list item is clicked, load corresponding info
  404. $('#select-objective').on('change', function()
  405. {
  406. fetchObjectiveForEditing();
  407. $('.selectpicker').selectpicker('refresh');
  408. });
  409. // When list item is clicked, load corresponding info
  410. $('.selectpicker').on('change', function()
  411. {
  412. //alert($(this).find(':selected').val());
  413. $('.selectpicker').selectpicker('refresh');
  414. });
  415. @stop