No Description

objectives.blade.php 17KB

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