No Description

objectives.blade.php 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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. <div class="panel-body">
  51. {{ Form::open(array('action' => 'Objective2Controller@update')) }}
  52. <div class="form-group">
  53. {{ Form::label('objective_id', 'Objectives') }}
  54. <select id="select-objective" name="id" class="form-control selectpicker">
  55. @foreach ($objectives as $objective)
  56. <option value="{{ $objective->id }}" data-subtext="
  57. @if($objective->program)
  58. &nbsp;&nbsp;&nbsp;[{{ $objective->program->name }}]
  59. @endif
  60. ">
  61. {{ $objective->text }}
  62. </option>
  63. @endforeach
  64. </select>
  65. </div>
  66. <!-- Associated Outcome -->
  67. <div class="form-group">
  68. <div id='assocOutcomeGroup'>
  69. <label>Associated Outcome</label>
  70. {{ Form::select('assoc_outcome[]', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcome0']) }}
  71. </div>
  72. </div>
  73. <button id='button-add-assoc-outcome' class='btn btn-md btn-secondary' onclick='addAssoc()'>
  74. <span class='glyphicon glyphicon-plus'>
  75. </span>
  76. Add another Outcome
  77. </button>
  78. <!-- Associated Program -->
  79. <div class="form-group">
  80. {{ Form::label('program_id2', 'Associated Program') }}<br><br>
  81. @foreach ($programs as $program)
  82. <input type="checkbox" id="assoc_program_id_{{ $program->id }}" name="program_id[]" value="{{$program->id}}">
  83. <label for="assoc_program_id_{{ $program->id }}"> {{ $program->name }} <sub>[{{ $program->school->name }}]</sub></label><br>
  84. @endforeach
  85. </div>
  86. <!-- Status -->
  87. <div class="form-group">
  88. {{ Form::label('status', 'Status') }}
  89. <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>
  90. <select id="status" name="status" class="form-control">
  91. <option value="1">Active</option>
  92. <option value="0">Inactive</option>
  93. </select>
  94. </div>
  95. <div class="form-group">
  96. {{ Form::label('text', 'Text') }}
  97. {{ Form::text('text', Input::old('text'), array('class' => 'form-control', 'id'=>'objective-text')) }}
  98. </div>
  99. {{ Form::submit('Update', array('class' => 'btn btn-primary btn-block')) }}
  100. {{ Form::close() }}
  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 associated program
  208. var program_length = json.program.length;
  209. $('input[type=checkbox]').prop('checked', false);
  210. for (var i = 0; i < program_length; i++) {
  211. prog = json.program[i].program_id.toString();
  212. $('#assoc_program_id_' + prog).prop("checked", true);
  213. }
  214. // Select status
  215. if (json.objective[0].deleted_at)
  216. $('#status').val(0);
  217. else
  218. $('#status').val(1);
  219. if (json.assessment.length) {
  220. $('#deleteObj').html("<p>This objective is currently participating in an assessment, therefore it cannot be deleted</p>");
  221. } else if (json.assoc_criteria.length) {
  222. modal = '<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#delete">' +
  223. 'Delete' +
  224. '</button>' +
  225. '<input type="hidden" value =' + json.objective[0].id + ' name="deleteObj">' +
  226. '<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">' +
  227. '<div class="modal-dialog" role="document">' +
  228. '<div class="modal-content">' +
  229. ' <div class="modal-header">' +
  230. '<h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>' +
  231. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
  232. '<span aria-hidden="true">&times;</span>' +
  233. '</button>' +
  234. ' </div>' +
  235. '<div class="modal-body">' +
  236. "<p>This objective is associated to: <p>" +
  237. '<ul>';
  238. for (var i = 0; i < json.assoc_criteria.length; i++) {
  239. modal += "<li>" + json.assoc_criteria[i].name + '</li>';
  240. }
  241. modal += ' </ul>' +
  242. '<p>Do you still want to delete it?</p>' +
  243. '</div>' +
  244. '<div class="modal-footer">' +
  245. '<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>' +
  246. '<button type="submit" class="btn btn-primary">Delete</button>' +
  247. '</div>' +
  248. '</div>' +
  249. '</div>' +
  250. '</div>';
  251. $('#deleteObj').html(modal);
  252. } else {
  253. modal = '<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#delete">' +
  254. 'Delete' +
  255. '</button>' +
  256. '<input type="hidden" value =' + json.objective[0].id + ' name="deleteObj">' +
  257. '<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">' +
  258. '<div class="modal-dialog" role="document">' +
  259. '<div class="modal-content">' +
  260. ' <div class="modal-header">' +
  261. '<h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>' +
  262. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
  263. '<span aria-hidden="true">&times;</span>' +
  264. '</button>' +
  265. ' </div>' +
  266. '<div class="modal-body">' +
  267. "<p> Once deleted, there is no chance of getting it back.</p>";
  268. modal +=
  269. '<p>Do you still want to delete it?</p>' +
  270. '</div>' +
  271. '<div class="modal-footer">' +
  272. '<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>' +
  273. '<button type="submit" class="btn btn-primary">Delete</button>' +
  274. '</div>' +
  275. '</div>' +
  276. '</div>' +
  277. '</div>';
  278. $('#deleteObj').html(modal);
  279. }
  280. },
  281. 'json'
  282. );
  283. }
  284. function deleteLastAssoc() {
  285. div = document.getElementById('assocOutcomeForm' + (counterAssoc).toString());
  286. div.remove();
  287. button = document.getElementById('closeAssoc' + (counterAssoc).toString());
  288. button.remove();
  289. counterAssoc -= 1;
  290. }
  291. function addAssoc() {
  292. var $select = $('<select />', {
  293. 'class': "selectpicker form-control",
  294. 'name': "assoc_outcome[]",
  295. 'data-live-search': 'true',
  296. 'id': 'assoc_outcome' + counterAssoc.toString()
  297. });
  298. var $div = $('<div />', {
  299. 'id': 'assocOutcomeForm' + counterAssoc.toString(),
  300. 'class': 'form-group col-md-11'
  301. });
  302. var $divForButton = $('<div />', {
  303. 'class': 'col-md-1',
  304. 'id': 'closeAssoc' + counterAssoc.toString()
  305. });
  306. var $button = $('<button />', {
  307. 'type': 'button',
  308. 'class': 'btn btn-primary',
  309. 'onclick': 'deleteLastAssoc()'
  310. });
  311. $button.append('X');
  312. $divForButton.append($button);
  313. $div.appendTo('#assocOutcomeGroup')
  314. $select.append(selectOptions);
  315. $select.appendTo('#assocOutcomeForm' + counterAssoc.toString()).selectpicker('refresh');
  316. $divForButton.appendTo('#assocOutcomeGroup');
  317. ran = true;
  318. counterAssoc += 1;
  319. }
  320. </script>
  321. @stop
  322. @section('javascript')
  323. // --------------------------------------------------------------------------
  324. // Page load
  325. // --------------------------------------------------------------------------
  326. // Hide accordion panel contents by default
  327. $('.panel-group .panel-body').hide();
  328. $('#outcome-display').parent().hide();
  329. fetchObjectiveForEditing();
  330. // setCriterionStatus();
  331. // --------------------------------------------------------------------------
  332. // Functions
  333. // --------------------------------------------------------------------------
  334. // Fetch criterion info for editing
  335. $('#button-add-outcome').on('click', function(e) {
  336. // Prevent the default action of the clicked item. In this case that is submit
  337. e.preventDefault();
  338. return false;
  339. });
  340. $('#button-add-assoc-outcome').on('click', function(e) {
  341. // Prevent the default action of the clicked item. In this case that is submit
  342. e.preventDefault();
  343. return false;
  344. });
  345. // --------------------------------------------------------------------------
  346. // Events
  347. // --------------------------------------------------------------------------
  348. // When panel heading is clicked, toggle it
  349. $('.panel-group .panel-heading').on('click', function()
  350. {
  351. $(this).next().stop().slideToggle();
  352. })
  353. // When list item is clicked, load corresponding info
  354. $('#select-objective').on('change', function()
  355. {
  356. fetchObjectiveForEditing();
  357. $('.selectpicker').selectpicker('refresh');
  358. });
  359. // When list item is clicked, load corresponding info
  360. $('.selectpicker').on('change', function()
  361. {
  362. //alert($(this).find(':selected').val());
  363. $('.selectpicker').selectpicker('refresh');
  364. });
  365. @stop