Bez popisu

objectives.blade.php 22KB

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