No Description

objectives.blade.php 25KB

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