暂无描述

objectives.blade.php 21KB

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