No Description

objectives.blade.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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') }}
  30. <select id="program_id" name="program_id" class="form-control selectpicker">
  31. <option value="{{ $programs[0]->id }}">{{ $programs[0]->name }} [{{ $programs[0]->school->name }}]</option>
  32. </select>
  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_id2', 'Associated Program') }}
  79. <select id="program_id2" name="program_id" class="form-control selectpicker">
  80. <option value="{{ $programs[0]->id }}">{{ $programs[0]->name }} [{{ $programs[0]->school->name }}]</option>
  81. </select>
  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>
  100. </div>
  101. </div>
  102. <script>
  103. var outcomeHTML = document.getElementById('outcomeGroup').innerHTML;
  104. var selectOptions = document.getElementById('outcome[0]').innerHTML;
  105. var ran = false;
  106. var counter = 1;
  107. var counterAssoc = 1;
  108. //Add Another Outcome
  109. function changeOutcomeHtml() {
  110. var outcomeHTML = document.getElementById('outcomeGroup').innerHTML;
  111. outcomeHTML = outcomeHTML.replace('outcome[' + counter.toString() + ']', 'outcome[' + (counter + 1).toString() + ']');
  112. counter += 1;
  113. document.getElementById("outcomeGroup").innerHTML += outcomeHTML;
  114. document.getElementById('button-add-outcome').onclick = addOutcome;
  115. }
  116. function addOutcome() {
  117. outcomeHTML = outcomeHTML.replace('outcome[' + counter.toString() + ']', 'outcome[' + (counter + 1).toString() + ']');
  118. counter += 1;
  119. document.getElementById("outcomeGroup").innerHTML += outcomeHTML;
  120. }
  121. function addOutcomeTest() {
  122. var $select = $('<select/>', {
  123. 'class': "selectpicker form-control",
  124. 'name': "outcome[" + counter.toString() + "]",
  125. 'data-live-search': 'true'
  126. });
  127. var $div = $('<div/>', {
  128. 'id': 'outcomeForm' + counter.toString(),
  129. 'class': 'form-group col-md-11'
  130. });
  131. var $divForButton = $('<div/>', {
  132. 'class': 'col-md-1',
  133. 'id': 'close' + counter.toString()
  134. });
  135. var $button = $('<button/>', {
  136. 'type': 'button',
  137. 'class': 'btn btn-primary',
  138. 'onclick': 'deleteLast()'
  139. });
  140. $button.append('X');
  141. $divForButton.append($button);
  142. $div.appendTo('#outcomeGroup')
  143. $select.append(selectOptions);
  144. $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
  145. $divForButton.appendTo('#outcomeGroup');
  146. counter += 1;
  147. $('#counter').val(counter);
  148. }
  149. function deleteLast() {
  150. div = document.getElementById('outcomeForm' + (counter - 1).toString());
  151. div.remove();
  152. button = document.getElementById('close' + (counter - 1).toString());
  153. button.remove();
  154. counter -= 1;
  155. $('#counter').val(counter);
  156. }
  157. function fetchObjectiveForEditing() {
  158. var id = $('#select-objective').find(':selected').val();
  159. $.post(
  160. "{{ URL::action('Objective2Controller@fetchObjectiveWithTrashed') }}", {
  161. id: id
  162. },
  163. function(json) {
  164. var text = json[0].text;
  165. // Display info
  166. $('#objective-text').val(text);
  167. // Select associated outcome
  168. var outcome_id = json[0].outcome_id;
  169. $('#assoc_outcome0').val(outcome_id);
  170. $('#assoc_outcome0').selectpicker('refresh');
  171. var length = json.length;
  172. if (ran == true) {
  173. for (var i = counterAssoc; i != 0; i--) {
  174. deleteLastAssoc(i);
  175. }
  176. counterAssoc = 1
  177. }
  178. for (var i = 1; i < length; i++) {
  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[i].outcome_id);
  205. $('#assoc_outcome' + i.toString()).selectpicker('refresh');
  206. counterAssoc = i;
  207. ran = true;
  208. }
  209. // Select associated program
  210. if (json[0].program_id) {
  211. $('#program_id2').val(json[0].program_id);
  212. } else {
  213. $('#program_id2').val(0);
  214. }
  215. $('#program_id2').selectpicker('refresh');
  216. // Select status
  217. if (json[0].deleted_at)
  218. $('#status').val(0);
  219. else
  220. $('#status').val(1);
  221. },
  222. 'json'
  223. );
  224. }
  225. function deleteLastAssoc() {
  226. div = document.getElementById('assocOutcomeForm' + (counterAssoc).toString());
  227. div.remove();
  228. button = document.getElementById('closeAssoc' + (counterAssoc).toString());
  229. button.remove();
  230. counterAssoc -= 1;
  231. }
  232. function addAssoc() {
  233. var $select = $('<select />', {
  234. 'class': "selectpicker form-control",
  235. 'name': "assoc_outcome[]",
  236. 'data-live-search': 'true',
  237. 'id': 'assoc_outcome' + counterAssoc.toString()
  238. });
  239. var $div = $('<div />', {
  240. 'id': 'assocOutcomeForm' + counterAssoc.toString(),
  241. 'class': 'form-group col-md-11'
  242. });
  243. var $divForButton = $('<div />', {
  244. 'class': 'col-md-1',
  245. 'id': 'closeAssoc' + counterAssoc.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' + counterAssoc.toString()).selectpicker('refresh');
  257. $divForButton.appendTo('#assocOutcomeGroup');
  258. ran = true;
  259. counterAssoc += 1;
  260. }
  261. </script>
  262. @stop
  263. @section('javascript')
  264. // --------------------------------------------------------------------------
  265. // Page load
  266. // --------------------------------------------------------------------------
  267. // Hide accordion panel contents by default
  268. $('.panel-group .panel-body').hide();
  269. $('#outcome-display').parent().hide();
  270. fetchObjectiveForEditing();
  271. // setCriterionStatus();
  272. // --------------------------------------------------------------------------
  273. // Functions
  274. // --------------------------------------------------------------------------
  275. // Fetch criterion info for editing
  276. $('#button-add-outcome').on('click', function(e) {
  277. // Prevent the default action of the clicked item. In this case that is submit
  278. e.preventDefault();
  279. return false;
  280. });
  281. $('#button-add-assoc-outcome').on('click', function(e) {
  282. // Prevent the default action of the clicked item. In this case that is submit
  283. e.preventDefault();
  284. return false;
  285. });
  286. // --------------------------------------------------------------------------
  287. // Events
  288. // --------------------------------------------------------------------------
  289. // When panel heading is clicked, toggle it
  290. $('.panel-group .panel-heading').on('click', function()
  291. {
  292. $(this).next().stop().slideToggle();
  293. })
  294. // When list item is clicked, load corresponding info
  295. $('#select-objective').on('change', function()
  296. {
  297. fetchObjectiveForEditing();
  298. $('.selectpicker').selectpicker('refresh');
  299. });
  300. // When list item is clicked, load corresponding info
  301. $('.selectpicker').on('change', function()
  302. {
  303. //alert($(this).find(':selected').val());
  304. $('.selectpicker').selectpicker('refresh');
  305. });
  306. @stop