No Description

objectives.blade.php 22KB

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