Nav apraksta

objectives.blade.php 17KB

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