No Description

objectives.blade.php 22KB

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