Bez popisu

objectives.blade.php 20KB

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