No Description

criteria.blade.php 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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 criterion -->
  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' => 'CriteriaController@create')) }}
  15. <div id='outcomeGroup' data-value = "1">
  16. <div class="form-group col-md-11">
  17. <label>Associated Outcomes</label>
  18. {{ Form::select('outcome[]', $outcomes, reset($outcomes), ['class'=>'form-control selectpicker', 'id' =>'outcome0', 'onchange'=>'fetchObjectiveForSelect("outcomeGroup", "objectiveGroup")']) }}
  19. </div>
  20. </div>
  21. <input type='hidden' name='counterOutcome' id='counterOutcome' 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. <div id='objectiveGroup' data-value = '1'>
  28. <div class="form-group">
  29. <label>Associated Objectives</label>
  30. <select id="objective_0" name="objective[]" class="form-control selectpicker">
  31. </select>
  32. </div>
  33. </div>
  34. <input type='hidden' name='counterObjective' id='counterObjective' value=1>
  35. <button id='button-add-objective' class='btn btn-md btn-secondary' onclick='addObjectiveTest()'>
  36. <span class='glyphicon glyphicon-plus'>
  37. </span>
  38. Add another Objective
  39. </button>
  40. <!-- Associated Program -->
  41. <div class="form-group">
  42. {{ Form::label('program_id', 'Associated Program') }}<br>
  43. <br>
  44. <input type = "hidden" id = "{{ $programs[0]->name }}" name="program_id[]" value="{{$programs[0]->id}}">
  45. <input type="checkbox" id="{{ $programs[0]->name }}" name="program_id[]" value="{{$programs[0]->id}}" disabled checked>
  46. <label for="{{ $programs[0]->name }}"> {{ $programs[0]->name }} [{{ $programs[0]->school->name }}]</label><br>
  47. </div>
  48. <div class="form-group">
  49. {{ Form::label('name', 'Name') }}
  50. {{ Form::text('name', '', array('class' => 'form-control')) }}
  51. </div>
  52. <div class="form-group">
  53. {{ Form::label('subcriteria', 'Subcriteria') }}
  54. <p class="help-block"><strong>Manually add</strong> bullets or numbering.</p>
  55. {{ Form::textarea('subcriteria', '', array('class' => 'form-control', 'rows'=>3, 'aria-labelledby'=>'subcriteria')) }}
  56. </div>
  57. <div class="form-group">
  58. {{ Form::label('maximum_score', 'Maximum Score') }}
  59. {{ Form::text('maximum_score', '1', array('class' => 'form-control', 'id'=>'maximum_score', 'oninput'=>'addOptions("Num_scale", "maximum_score", "Scales")')) }}
  60. </div>
  61. <div class="form-group">
  62. {{ Form::label('scales', 'Number of Scales') }}
  63. <select id="Num_scale" name="scales" class="form-control selectpicker" onchange='numberOfScales("Num_scale", "Scales")'>
  64. </select>
  65. </div>
  66. <div id='Scales' data-value="0">
  67. </div>
  68. <div class="form-group">
  69. {{ Form::label('copyright', 'Copyright') }}
  70. {{ Form::textarea('copyright', '', array('class' => 'form-control', 'rows'=>2, 'placeholder'=>'(optional)', 'aria-labelledby'=>'copyright')) }}
  71. </div>
  72. <div class="form-group">
  73. {{ Form::label('notes', 'Notes') }}
  74. {{ Form::textarea('notes', '', array('class' => 'form-control', 'rows'=>2, 'placeholder'=>'(optional)', 'aria-labelledby'=>'notes')) }}
  75. </div>
  76. {{ Form::submit('Create', array('class' => 'btn btn-primary btn-block')) }}
  77. {{ Form::close() }}
  78. </div>
  79. </div>
  80. </div>
  81. <div class="col-md-6">
  82. <div class="panel panel-default panel-button">
  83. <div class="panel-heading">
  84. Edit
  85. </div>
  86. <div class="panel-body">
  87. {{ Form::open(array('action' => 'CriteriaController@update')) }}
  88. <button class="btn btn-md btn-secondary filterButton">
  89. <span class="glyphicon glyphicon-plus">
  90. </span>
  91. Filters
  92. </button>
  93. <div class="filterSection">
  94. <div class="form-group">
  95. {{ Form::label('program_id2', 'Associated Program')}}
  96. <select id='select-program' class="form-control selectpicker" onchange='fetchAllCriterion("select-program", "assoc_outcomes_fetch")'>
  97. <option value='{{$programs[0]->id}}' data-subtext="{{$programs[0]->code}}">{{$programs[0]->name}}</option>
  98. </select>
  99. </div>
  100. <div class="form-group">
  101. <label>Associated Outcome</label>
  102. {{ Form::select('assoc_outcome_fetch', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcomes_fetch', 'onchange'=>'fetchAllCriterion("select-program", "assoc_outcomes_fetch")']) }}
  103. </div>
  104. </div>
  105. <div class="form-group">
  106. {{ Form::label('criterion_id', 'Criterion') }}
  107. <select id="select-criterion" name="id" class="form-control selectpicker" onchange='fetchCriterionForEditing()'>
  108. @foreach ($criteria as $criterion)
  109. <option value="{{ $criterion->id }}" data-subtext="
  110. @if($criterion->program)
  111. &nbsp;&nbsp;&nbsp;[{{ $criterion->program->name }}]
  112. @endif
  113. ">
  114. {{ $criterion->name }}
  115. </option>
  116. @endforeach
  117. </select>
  118. </div>
  119. <!-- Associated Outcome -->
  120. <div id='assocOutcomeGroup' data-value="1">
  121. <div class="form-group">
  122. <label>Associated Outcome</label>
  123. {{ Form::select('assoc_outcome[]', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcome_0', 'onchange'=>'fetchAssocObjective("assoc_outcome_0")']) }}
  124. </div>
  125. </div>
  126. <button id='button-add-objective-assoc' class='btn btn-md btn-secondary' onclick='addAssocOutcome()'>
  127. <span class='glyphicon glyphicon-plus'>
  128. </span>
  129. Add another Outcome
  130. </button>
  131. <div id='assoc_objectiveGroup' data-value="1">
  132. <div class="form-group">
  133. <label>Associated Objectives</label>
  134. <select id="assoc_objective_0" name="assoc_objective[]" class="form-control selectpicker">
  135. <option value="0">No associated objectives</option>
  136. </select>
  137. </div>
  138. </div>
  139. <button id='button-add-outcome-assoc' class='btn btn-md btn-secondary' onclick='addAssocObjective()'>
  140. <span class='glyphicon glyphicon-plus'>
  141. </span>
  142. Add another Objective
  143. </button>
  144. <!-- Associated Program -->
  145. <div class="form-group">
  146. {{ Form::label('program_id2', 'Associated Program') }}<br><br>
  147. <input type = "hidden" id = "{{ $programs[0]->name }}" name="program_id[]" value="{{$programs[0]->id}}">
  148. <input type="checkbox" id="assoc_program_id_{{ $programs[0]->id }}" name="program_id[]" value="{{$programs[0]->id}}" disabled checked>
  149. <label for="assoc_program_id_{{ $programs[0]->id }}"> {{ $programs[0]->name }} <sub>[{{ $programs[0]->school->name }}]</sub></label><br>
  150. </div>
  151. <!-- Status -->
  152. <div class="form-group">
  153. {{ Form::label('status', 'Status') }}
  154. <span data-toggle="tooltip" data-placement="top" title="Use this option to deactivate or reactivate criteria. Inactive criteria will stay in the system, but will not be available to use in new rubrics." class="glyphicon glyphicon-question-sign"></span>
  155. <select id="status" name="status" class="form-control">
  156. <option value="1">Active</option>
  157. <option value="0">Inactive</option>
  158. </select>
  159. </div>
  160. <div class="form-group">
  161. {{ Form::label('name', 'Name') }}
  162. {{ Form::text('name', Input::old('name'), array('class' => 'form-control', 'id'=>'criterion_name')) }}
  163. </div>
  164. <div class="form-group">
  165. {{ Form::label('subcriteria', 'Subcriteria') }}
  166. <p class="help-block"><strong>Manually add</strong> bullets or numbering.</p>
  167. {{ Form::textarea('subcriteria', '', array('class' => 'form-control', 'rows'=>3, 'id' => 'criterion_subcriteria')) }}
  168. </div>
  169. <div class="form-group">
  170. {{ Form::label('assoc_maximum_score', 'Maximum Score') }}
  171. {{ Form::text('assoc_maximum_score', '', array('class' => 'form-control', 'id'=>'assoc_maximum_score', 'oninput'=>'addOptions("Num_assoc_scale", "assoc_maximum_score", "Assoc_Scales")')) }}
  172. </div>
  173. <div class="form-group">
  174. {{ Form::label('scales', 'Number of Scales') }}
  175. <select id="Num_assoc_scale" class="form-control selectpicker" onchange='numberOfAssoc("Num_assoc_scale", "Assoc_Scales")'>
  176. </select>
  177. </div>
  178. <div id='Assoc_Scales' data-value="0">
  179. </div>
  180. <div class="form-group">
  181. {{ Form::label('copyright', 'Copyright Information') }}
  182. {{ Form::textarea('copyright', Input::old('copyright'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_copyright', 'placeholder'=>'(optional)')) }}
  183. </div>
  184. <div class="form-group">
  185. {{ Form::label('notes', 'Additional Notes') }}
  186. {{ Form::textarea('notes', Input::old('notes'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_notes', 'placeholder'=>'(optional)')) }}
  187. </div>
  188. {{ Form::submit('Update', array('class' => 'btn btn-primary btn-block')) }}
  189. {{ Form::close() }}
  190. {{ Form::open(array('action' => 'CriteriaController@delete')) }}
  191. <input type='hidden' name='criterion_delete' id='deleteCriteria'>
  192. {{Form::submit("Delete", array('class'=> 'btn btn-primary btn-block', 'id'=>"DeleteButton"))}}
  193. </div>
  194. </div>
  195. </div>
  196. </div>
  197. <script>
  198. var selectOptions = document.getElementById('outcome0').innerHTML;
  199. var counter = 1;
  200. var counterObj = 1;
  201. var outcomeString = 'OutcomeGroup_';
  202. $(document).ready(function() {
  203. addOptions('Num_scale', 'maximum_score', 'Scales');
  204. numberOfScales('Num_scale', 'Scales');
  205. });
  206. function addOptions(select, max, scaleDiv) {
  207. var maxscore = parseInt($('#' + max).val())
  208. options = '<option value = "1"> 1</option>';
  209. selectedValue = 1;
  210. valueBefore = 0;
  211. for (var i = 2; i <= 20; i++) {
  212. if(maxscore%i==0){
  213. options += '<option value="' + i.toString() + '">' + i.toString() + '</option>';
  214. }
  215. }
  216. var previousvalue = parseInt($('#' + select).val());
  217. $('#' + select).html(options);
  218. $('#' + select).val(previousvalue);
  219. $('#' + select).selectpicker('refresh');
  220. }
  221. function numberOfAssoc(string, Scales) {
  222. var maximum = $('#assoc_maximum_score').val();
  223. var amountOfScale = parseInt($('#' + string).val());
  224. var dataValue = parseInt($('#' + Scales).attr('data-value'));
  225. //add
  226. if (dataValue < amountOfScale) {
  227. fullDiv = '';
  228. for (var i = dataValue; i < amountOfScale; i++) {
  229. div = '<div id="assoc_eval' + i.toString() + Scales + '">' +
  230. '<div class ="form-group">' +
  231. '<label for ="descripcion' + i.toString() + '">Descripción de evaluación</label>' +
  232. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="assoc_scales[]" cols="50" ></textarea></div></div>';
  233. fullDiv += div;
  234. }
  235. $('#' + Scales).append(fullDiv);
  236. $('#' + Scales).attr('data-value', amountOfScale);
  237. } else {
  238. for (var i = dataValue; i > amountOfScale; i--) {
  239. $('#assoc_eval' + (i - 1).toString()).remove();
  240. }
  241. }
  242. $('#' + Scales).attr('data-value', amountOfScale);
  243. }
  244. function numberOfScales(string, Scales) {
  245. var maximum = parseInt($('#maximum_score').val());
  246. var amountOfScale = parseInt($('#' + string).val());
  247. var dataValue = parseInt($('#' + Scales).attr('data-value'));
  248. var division = maximum/amountOfScale;
  249. //add
  250. fullDiv = '';
  251. if(division ==1){
  252. for (var i = 0; i < amountOfScale; i++) {
  253. div = '<div id="eval' + i.toString() + Scales + '">' +
  254. '<div class ="form-group">' +
  255. '<label id = "label_for_des'+i.toString()+'" for ="descripcion' + i.toString() + '">Scale Description ('+(i+1)+')</label>' +
  256. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="' + Scales + '[]" cols="50" ></textarea></div></div>';
  257. fullDiv += div;
  258. }
  259. }
  260. else if(division==maximum){
  261. div = '<div id="eval' + 0 + Scales + '">' +
  262. '<div class ="form-group">' +
  263. '<label id = "label_for_des'+0+'" for ="descripcion' + 0 + '">Scale Description ('+1+' - '+maximum+')</label>' +
  264. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + 0 + '" name="' + Scales + '[]" cols="50" ></textarea></div></div>';
  265. fullDiv += div;
  266. }
  267. else{
  268. for (var i = 0; i < amountOfScale; i++) {
  269. div = '<div id="eval' + i.toString() + Scales + '">' +
  270. '<div class ="form-group">' +
  271. '<label id = "label_for_des'+i.toString()+'" for ="descripcion' + i.toString() + '">Scale Description ('+(1+(i*division))+' - '+((1+i)*division)+')</label>' +
  272. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="' + Scales + '[]" cols="50" ></textarea></div></div>';
  273. fullDiv += div;
  274. }
  275. }
  276. $('#' + Scales).html(fullDiv);
  277. $('#' + Scales).attr('data-value', amountOfScale);
  278. }
  279. $('.filterSection').hide();
  280. $('.filterButton').on('click', function()
  281. {
  282. var span = $(this).find('span');
  283. if(span.attr('class') == 'glyphicon glyphicon-plus'){
  284. span.attr('class','glyphicon glyphicon-minus');
  285. } else{
  286. span.attr('class','glyphicon glyphicon-plus');
  287. }
  288. $('.filterSection').toggle(533);
  289. });
  290. //Add outcome Button
  291. function addOutcomeTest() {
  292. counter = parseInt($('#outcomeGroup').data("value"));
  293. var $select = $('<select/>', {
  294. 'class': "selectpicker form-control",
  295. 'name': "outcome[]",
  296. 'data-live-search': 'true',
  297. 'id': 'outcome' + counter.toString(),
  298. 'onchange': 'fetchObjectiveForSelect("outcomeGroup", "objectiveGroup")'
  299. });
  300. var $div = $('<div/>', {
  301. 'id': 'outcomeForm' + counter.toString(),
  302. 'class': 'form-group col-md-11'
  303. });
  304. var $divForButton = $('<div/>', {
  305. 'class': 'col-md-1',
  306. 'id': 'close' + counter.toString()
  307. });
  308. var $button = $('<button/>', {
  309. 'type': 'button',
  310. 'class': 'btn btn-primary',
  311. 'onclick': 'deleteLast("outcomeForm'+counter.toString()+'", "outcomeGroup", "close' + counter.toString() + '", "objectiveGroup")'
  312. });
  313. $button.append('X');
  314. $divForButton.append($button);
  315. $div.appendTo('#outcomeGroup')
  316. $select.append(selectOptions);
  317. $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
  318. $('#outcomeGroup').data("value", (counter +1));
  319. fetchObjectiveForSelect('outcomeGroup', "objectiveGroup");
  320. counter += 1;
  321. $divForButton.appendTo('#outcomeGroup');
  322. }
  323. //Delete Outcome and OptGroup associated
  324. function deleteLast(outcomeForm, outcomeDiv, closeButton, objectiveGroup) {
  325. $div = document.getElementById(outcomeForm );
  326. $div.remove();
  327. $div = document.getElementById(closeButton);
  328. $div.remove();
  329. if(outcomeDiv =='outcomeGroup'){
  330. $('#' + outcomeDiv).data('value',parseInt($('#' + outcomeDiv).data('value')) - 1);
  331. fetchObjectiveForSelect(outcomeDiv, objectiveGroup);}
  332. }
  333. //Delete Objective
  334. function deleteObjective(objectiveForm, closeObj, objectiveGroup) {
  335. $div = document.getElementById(objectiveForm);
  336. $div.remove();
  337. $div = document.getElementById(closeObj);
  338. $div.remove();
  339. counter = parseInt($('#'+objectiveGroup).data("value"));
  340. $('#'+objectiveGroup).data("value", counter-1);
  341. }
  342. //Add objective when editing
  343. function addAssocObjective() {
  344. selectObj = document.getElementById('assoc_objective_0').innerHTML;
  345. assocObjectiveCounter = parseInt($('#assoc_objectiveGroup').data('value'));
  346. var $select = $('<select/>', {
  347. 'class': "selectpicker form-control",
  348. 'name': "assoc_objective[]",
  349. 'data-live-search': 'true',
  350. 'id': 'assoc_objective_' + assocObjectiveCounter.toString(),
  351. });
  352. var $div = $('<div/>', {
  353. 'id': 'assoc_objectiveForm' + assocObjectiveCounter.toString(),
  354. 'class': 'form-group col-md-11'
  355. });
  356. var $divForButton = $('<div/>', {
  357. 'class': 'col-md-1',
  358. 'id': 'assoc_closeObj' + assocObjectiveCounter.toString()
  359. });
  360. var $button = $('<button/>', {
  361. 'type': 'button',
  362. 'class': 'btn btn-primary',
  363. 'onclick': 'deleteObjective("assoc_objectiveForm' + assocObjectiveCounter.toString() + '", "assoc_closeObj' + assocObjectiveCounter.toString() + ', "assoc_objectiveGroup")'
  364. });
  365. $button.append('X');
  366. $divForButton.append($button);
  367. $div.appendTo('#assoc_objectiveGroup')
  368. $select.append(selectObj);
  369. $select.appendTo('#assoc_objectiveForm' + assocObjectiveCounter.toString()).selectpicker('refresh');
  370. $('#assoc_objectiveGroup').data("value", assocObjectiveCounter +1);
  371. $divForButton.appendTo('#assoc_objectiveGroup');
  372. }
  373. //Add objective when creating a criteria
  374. function addObjectiveTest() {
  375. selectObj = document.getElementById('objective_0').innerHTML;
  376. counter = parseInt($("#objectiveGroup").data('value'));
  377. var $select = $('<select/>', {
  378. 'class': "selectpicker form-control",
  379. 'name': "objective[]",
  380. 'data-live-search': 'true',
  381. 'id': 'objective_' + counter.toString()
  382. });
  383. var $div = $('<div/>', {
  384. 'id': 'objectiveForm' + counter.toString(),
  385. 'class': 'form-group col-md-11'
  386. });
  387. var $divForButton = $('<div/>', {
  388. 'class': 'col-md-1',
  389. 'id': 'closeObj' + counter.toString()
  390. });
  391. var $button = $('<button/>', {
  392. 'type': 'button',
  393. 'class': 'btn btn-primary',
  394. 'onclick': 'deleteObjective("objectiveForm' + counter.toString() + '", "closeObj' + counter.toString() + '")'
  395. });
  396. $button.append('X');
  397. $divForButton.append($button);
  398. $div.appendTo('#objectiveGroup')
  399. $select.append(selectObj);
  400. $select.appendTo('#objectiveForm' + counter.toString()).selectpicker('refresh');
  401. $divForButton.appendTo('#objectiveGroup');
  402. $('#objectiveGroup').data('value', counter +1);
  403. }
  404. //Create outcome for editing
  405. var assocOutcomeCounter = 0;
  406. function addAssocOutcome() {
  407. assocOutcomeCounter = parseInt($('#assocOutcomeGroup').data('value'));
  408. var $select = $('<select/>', {
  409. 'class': "selectpicker form-control",
  410. 'name': "assoc_outcome[]",
  411. 'data-live-search': 'true',
  412. 'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
  413. 'onchange': 'fetchAssocObjective("assoc_outcome_' + assocOutcomeCounter.toString() + '")'
  414. });
  415. var $div = $('<div/>', {
  416. 'id': 'assoc_outcomeForm' + assocOutcomeCounter.toString(),
  417. 'class': 'form-group col-md-11'
  418. });
  419. var $divForButton = $('<div/>', {
  420. 'class': 'col-md-1',
  421. 'id': 'assoc_close' + assocOutcomeCounter.toString()
  422. });
  423. var $button = $('<button/>', {
  424. 'type': 'button',
  425. 'class': 'btn btn-primary',
  426. 'onclick': 'deleteLast("assoc_outcomeForm' + assocOutcomeCounter.toString() + '", "assocOutcomeGroup", "assoc_close' + assocOutcomeCounter.toString() + '","assoc_objectiveGroup")'
  427. });
  428. $button.append('X');
  429. $divForButton.append($button);
  430. $div.appendTo('#assocOutcomeGroup')
  431. $select.append(selectOptions);
  432. $select.appendTo('#assoc_outcomeForm' + assocOutcomeCounter.toString()).selectpicker('refresh');
  433. assocOutcomeCounter += 1;
  434. $divForButton.appendTo('#assocOutcomeGroup');
  435. $('#assocOutcomeGroup').data('value', assocOutcomeCounter);
  436. }
  437. //Fetch associated objective for editing
  438. var assocObjectiveCounter = 1;
  439. function fetchAssocObjective(outcomeDiv, objectiveGroup) {
  440. var count = $('#'+outcomeDiv).data('value');
  441. var allOutcomes =[];
  442. $("#" + outcomeDiv + ' select').each(function() {
  443. allOutcomes.push( this.value);
  444. })
  445. var allObjectives = [];
  446. $("#" + objectiveGroup + ' select').each(function() {
  447. var temp = {
  448. id: this.id,
  449. value: this.value
  450. }
  451. allObjectives.push(temp);
  452. })
  453. $.post(
  454. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  455. allOutcomes: allOutcomes
  456. },
  457. function(json) {
  458. optionName = '<option value ="0">Nothing Selected</option>';
  459. for(outcome in varArray.outcomes){
  460. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '">';
  461. var objectiveForOutcome = varArray.objectives;
  462. var objectives = objectiveForOutcome[outcome];
  463. for (objective in objectives) {
  464. var obj= objectives[objective];
  465. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  466. optionName += (option);
  467. }
  468. optionName += '</optgroup>';
  469. }
  470. $('#assoc_objective_0').html(optionName);
  471. $('#assoc_objective_0').selectpicker('refresh');
  472. if($("#assoc_objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  473. $("#assoc_objective_0").val(allObjectives[0].value);
  474. $('#assoc_objective_0').selectpicker('refresh');
  475. }
  476. for (var i = allObjectives.length - 1; i > 0; i--) {
  477. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup');
  478. }
  479. for(var i=1; i<allObjectives.length; i++){
  480. addAssocObjective();
  481. $('#assoc_objective_'+i.toString()).selectpicker('refresh');
  482. if($("#assoc_objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  483. $("#assoc_objective_"+i.toString()).val(allObjectives[i].value);
  484. $("#assoc_objective_"+i.toString()).selectpicker("refresh");
  485. }
  486. }
  487. },
  488. 'json'
  489. );
  490. }
  491. //Fetch objective at creating criteria
  492. counterForPost = 0;
  493. function fetchObjectiveForSelect(outcomeDiv, objectiveGroup) {
  494. var count = $("#" + outcomeDiv).data('value');
  495. var allOutcomes = [];
  496. $("#" + outcomeDiv + ' select').each(function() {
  497. allOutcomes.push( this.value);
  498. })
  499. var allObjectives = [];
  500. $("#" + objectiveGroup + ' select').each(function() {
  501. var temp = {
  502. id: this.id,
  503. value: this.value
  504. }
  505. allObjectives.push(temp);
  506. })
  507. $.post(
  508. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  509. allOutcomes: allOutcomes
  510. },
  511. function(varArray) {
  512. counterOutcome =0;
  513. optionName = '<option value ="0">Nothing Selected</option>';
  514. for(outcome in varArray.outcomes){
  515. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '">';
  516. var objectiveForOutcome = varArray.objectives;
  517. var objectives = objectiveForOutcome[outcome];
  518. for (objective in varArray.objectives[outcome]) {
  519. var obj= objectives[objective];
  520. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  521. optionName += (option);
  522. }
  523. optionName += "</optgroup>";
  524. }
  525. $('#objective_0').html(optionName);
  526. $('#objective_0').selectpicker('refresh');
  527. if($("#objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  528. $("#objective_0").val(allObjectives[0].value);
  529. $('#objective_0').selectpicker('refresh');
  530. }
  531. for (var i = allObjectives.length - 1; i > 0; i--) {
  532. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString(), 'objectiveGroup');
  533. }
  534. for(var i =1; i<allObjectives.length; i++){
  535. addObjectiveTest();
  536. $('#objective_'+i.toString()).selectpicker('refresh');
  537. if($("#objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  538. $("#objective_"+i.toString()).val(allObjectives[i].value);
  539. $("#objective_"+i.toString()).selectpicker("refresh");
  540. }
  541. }
  542. },
  543. 'json'
  544. );
  545. }
  546. //after post
  547. //For editing criterion
  548. function fetchAllCriterion(program, outcome) {
  549. var program_id_fetch = $('#' + program).find(':selected').val();
  550. var outcome_fetch = $('#' + outcome).find(':selected').val();
  551. $.post(
  552. "{{URL::action('CriteriaController@fetchAllCriterion')}}", {
  553. program_fetch: program_id_fetch,
  554. outcome_fetch: outcome_fetch
  555. },
  556. function(json) {
  557. json_length = (json.criterion.length);
  558. fullHTML = '';
  559. for (var i = 0; i < json_length; i++) {
  560. fullHTML += '<option value="' + json.criterion[i].id + '">' + json.criterion[i].name + '</option>';
  561. }
  562. $('#select-criterion').html(fullHTML);
  563. $('#select-criterion').selectpicker('refresh');
  564. fetchCriterionForEditing()
  565. },
  566. 'json'
  567. );
  568. }
  569. function deleteCriterion() {
  570. var id = $('#select-criterion').find(':selected').val()
  571. $.post(
  572. "{{ URL::action('CriteriaController@delete')}}", {
  573. id: id
  574. },
  575. function() {
  576. window.location.reload(true)
  577. }
  578. )
  579. }
  580. function fetchCriterionForEditing() {
  581. var id = $('#select-criterion').find(':selected').val();
  582. $.post(
  583. "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
  584. id: id
  585. },
  586. function(json) {
  587. if (!(json.activity_criterion.length)) {
  588. $('#DeleteButton').prop('enabled', true);
  589. } else {
  590. $('#DeleteButton').prop('disabled', true);
  591. }
  592. if (!(json.criteria.length)) {
  593. name = ' ';
  594. var subcriteria = '';
  595. copyright = null;
  596. notes = null;
  597. $('#status').val(0);
  598. maximum = 1;
  599. $('#assoc_maximum_score').val(1);
  600. } else {
  601. var name = json.criteria[0].name;
  602. if (json.criteria[0].subcriteria) {
  603. subcriteria = JSON.parse(json.criteria[0].subcriteria).join('\n');
  604. }else {
  605. subcriteria = "";
  606. }
  607. if (json.criteria[0].copyright) {
  608. var copyright = json.criteria[0].copyright;
  609. } else {
  610. var copyright = ''
  611. }
  612. if (json.criteria[0].notes) notes = json.criteria[0].notes;
  613. else notes = '';
  614. // Display info
  615. $('#criterion_name').val(name);
  616. $('#criterion_subcriteria').text(subcriteria);
  617. if (json.criteria[0].deleted_at)
  618. $('#status').val(0);
  619. else
  620. $('#status').val(1);
  621. $('#assoc_maximum_score').val(json.criteria[0].maximum_score);
  622. var maximum = json.criteria[0].maximum_score;
  623. // If copyright or notes aren't empty, load them
  624. }
  625. $('#criterion_copyright').text(copyright);
  626. $('#criterion_notes').text(notes);
  627. // Select associated outcome
  628. try {
  629. assocOutcomeCounter= parseInt($("#assocOutcomeGroup").data('value'));
  630. for (var i = assocOutcomeCounter - 1; i > 0; i--) {
  631. deleteLast("assoc_outcomeForm" + i.toString() , "assocOutcomeGroup", "assoc_close" + i.toString() ,"assoc_objectiveGroup");
  632. }
  633. } catch (err) {
  634. var Notran = true;
  635. }
  636. if (json.outcomes.length) {
  637. $('#assoc_outcome_0').val(json.outcomes[0].id);
  638. $('#assoc_outcome_0').selectpicker('refresh');
  639. } else {
  640. $('#assoc_outcome_0').val($('#assoc_outcomes_fetch').find(':selected').val());
  641. $('#assoc_outcome_0').selectpicker('refresh');
  642. }
  643. for (var i = 1; i < json.outcomes.length; i++) {
  644. addAssocOutcome();
  645. $('#assoc_outcome_' + i.toString()).val(json.outcomes[i].id);
  646. $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
  647. }
  648. counterObj =$('#assoc_objectiveGroup').data('value');
  649. try {
  650. for (var i = counterObj - 1; i > 0; i--) {
  651. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup')
  652. }
  653. } catch (err) {
  654. var noEntro = true;
  655. }
  656. $('#assoc_objectiveGroup').data('value', 1);
  657. assocOutcomeCounter = 0;
  658. var i = 0;
  659. optionName = '<option value ="0">Nothing Selected</option>';
  660. for(outcome in json.outcomes_assoc){
  661. optionName += '<optgroup label="' + json.outcomes_assoc[outcome][0].name + '">';
  662. var objectiveForOutcome = json.objectives_assoc;
  663. var objectives = objectiveForOutcome[outcome];
  664. for (objective in objectives) {
  665. var obj= objectives[objective];
  666. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  667. optionName += (option);
  668. }
  669. optionName+= '</optgroup>';
  670. }
  671. $('#assoc_objective_0').html(optionName);
  672. $('#assoc_objective_0').selectpicker('refresh');
  673. try {
  674. $('#assoc_objective_0').val(json.objectives[0].id);
  675. $('#assoc_objective_0').selectpicker('refresh');
  676. } catch (err) {
  677. if (!json.objectives.length) {
  678. $('#assoc_objective_0').val(0);
  679. $('#assoc_objective_0').selectpicker('refresh');
  680. }
  681. var thereIsNoObjective = true;
  682. }
  683. for (var i = 1; i < json.objectives.length; i++) {
  684. addAssocObjective();
  685. $('#assoc_objective_' + i.toString()).val(json.objectives[i].id);
  686. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  687. }
  688. $('assoc_objectiveGroup').data('value',json.objectives.length);
  689. // Select status
  690. },
  691. 'json'
  692. );
  693. }
  694. </script>
  695. @stop
  696. @section('javascript')
  697. // --------------------------------------------------------------------------
  698. // Page load
  699. // --------------------------------------------------------------------------
  700. // Hide accordion panel contents by default
  701. $('.panel-group .panel-body').hide();
  702. $('#outcome-display').parent().hide();
  703. fetchCriterionForEditing();
  704. fetchObjectiveForSelect('outcomeGroup', 'objectiveGroup');
  705. // setCriterionStatus();
  706. fetchAllCriterion("select-program", "assoc_outcomes_fetch");
  707. // --------------------------------------------------------------------------
  708. // Functions
  709. // --------------------------------------------------------------------------
  710. $('#button-add-outcome').on('click', function(e) {
  711. // Prevent the default action of the clicked item. In this case that is submit
  712. e.preventDefault();
  713. return false;
  714. });
  715. $('.filterButton').on('click', function(e) {
  716. // Prevent the default action of the clicked item. In this case that is submit
  717. e.preventDefault();
  718. return false;
  719. });
  720. $('#button-add-objective-assoc').on('click', function(e) {
  721. // Prevent the default action of the clicked item. In this case that is submit
  722. e.preventDefault();
  723. return false;
  724. });
  725. $('#button-add-outcome-assoc').on('click', function(e) {
  726. // Prevent the default action of the clicked item. In this case that is submit
  727. e.preventDefault();
  728. return false;
  729. });
  730. $('#button-add-objective').on('click', function(e) {
  731. // Prevent the default action of the clicked item. In this case that is submit
  732. e.preventDefault();
  733. return false;
  734. });
  735. // Fetch criterion info for editing
  736. // --------------------------------------------------------------------------
  737. // Events
  738. // --------------------------------------------------------------------------
  739. // When panel heading is clicked, toggle it
  740. $('.panel-group .panel-heading').on('click', function()
  741. {
  742. $(this).next().stop().slideToggle();
  743. })
  744. //$('#outcome[0]').on('change', function(){
  745. //$('.selectpicker').selectpicker('refresh');
  746. //})
  747. // When list item is clicked, load corresponding info
  748. // When list item is clicked, load corresponding info
  749. $('.selectpicker').on('change', function()
  750. {
  751. //alert($(this).find(':selected').val());
  752. $('.selectpicker').selectpicker('refresh');
  753. });
  754. @stop