No Description

objectives.blade.php 23KB

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