No Description

objectives.blade.php 21KB

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