No Description

objectives.blade.php 20KB

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