No Description

criteria.blade.php 38KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  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. $('#'+select).trigger('change');
  221. }
  222. function numberOfAssoc(string, Scales) {
  223. var maximum = $('#assoc_maximum_score').val();
  224. var amountOfScale = parseInt($('#' + string).val());
  225. var dataValue = parseInt($('#' + Scales).attr('data-value'));
  226. var division = maximum/amountOfScale;
  227. //add
  228. fullDiv = '';
  229. if(division ==1){
  230. for (var i = dataValue; i < amountOfScale; i++) {
  231. div = '<div id="assoc_eval' + i.toString() + Scales + '">' +
  232. '<div class ="form-group">' +
  233. '<label for ="assoc_descripcion' + i.toString() + '">Scale Description ('+(i+1)+')</label>' +
  234. '<textarea class="form-control" rows="2" aria-labelledby="assoc_descripcion' + i.toString() + '" name="assoc_scales[]" cols="50" ></textarea></div></div>';
  235. fullDiv += div;
  236. }
  237. }
  238. else if(division == maximum){
  239. div = '<div id="assoc_eval' +0 + Scales + '">' +
  240. '<div class ="form-group">' +
  241. '<label for ="assoc_descripcion' + 0 + '">Scale Description ('+1+' - '+maximum+') </label>' +
  242. '<textarea class="form-control" rows="2" aria-labelledby="assoc_descripcion' + 0 + '" name="assoc_scales[]" cols="50" ></textarea></div></div>';
  243. fullDiv += div;
  244. }
  245. else{
  246. for (var i = 0; i < amountOfScale; i++) {
  247. div = '<div id="assoc_eval' + i.toString() + Scales + '">' +
  248. '<div class ="form-group">' +
  249. '<label for ="assoc_descripcion' + i.toString() + '">Scale Description ('+(1+(i*division))+' - '+((1+i)*division)+')</label>' +
  250. '<textarea class="form-control" rows="2" aria-labelledby="assoc_descripcion' + i.toString() + '" name="assoc_scales[]" cols="50" ></textarea></div></div>';
  251. fullDiv += div;
  252. }
  253. }
  254. $('#' + Scales).html(fullDiv);
  255. $('#' + Scales).attr('data-value', amountOfScale);
  256. }
  257. //add
  258. function numberOfScales(string, Scales) {
  259. var maximum = parseInt($('#maximum_score').val());
  260. var amountOfScale = parseInt($('#' + string).val());
  261. var dataValue = parseInt($('#' + Scales).attr('data-value'));
  262. var division = maximum/amountOfScale;
  263. //add
  264. fullDiv = '';
  265. if(division ==1){
  266. for (var i = 0; i < amountOfScale; i++) {
  267. div = '<div id="eval' + i.toString() + Scales + '">' +
  268. '<div class ="form-group">' +
  269. '<label id = "label_for_des'+i.toString()+'" for ="descripcion' + i.toString() + '">Scale Description ('+(i+1)+')</label>' +
  270. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="' + Scales + '[]" cols="50" ></textarea></div></div>';
  271. fullDiv += div;
  272. }
  273. }
  274. else if(division==maximum){
  275. div = '<div id="eval' + 0 + Scales + '">' +
  276. '<div class ="form-group">' +
  277. '<label id = "label_for_des'+0+'" for ="descripcion' + 0 + '">Scale Description ('+1+' - '+maximum+')</label>' +
  278. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + 0 + '" name="' + Scales + '[]" cols="50" ></textarea></div></div>';
  279. fullDiv += div;
  280. }
  281. else{
  282. for (var i = 0; i < amountOfScale; i++) {
  283. div = '<div id="eval' + i.toString() + Scales + '">' +
  284. '<div class ="form-group">' +
  285. '<label id = "label_for_des'+i.toString()+'" for ="descripcion' + i.toString() + '">Scale Description ('+(1+(i*division))+' - '+((1+i)*division)+')</label>' +
  286. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="' + Scales + '[]" cols="50" ></textarea></div></div>';
  287. fullDiv += div;
  288. }
  289. }
  290. $('#' + Scales).html(fullDiv);
  291. $('#' + Scales).attr('data-value', amountOfScale);
  292. }
  293. $('.filterSection').hide();
  294. $('.filterButton').on('click', function()
  295. {
  296. var span = $(this).find('span');
  297. if(span.attr('class') == 'glyphicon glyphicon-plus'){
  298. span.attr('class','glyphicon glyphicon-minus');
  299. } else{
  300. span.attr('class','glyphicon glyphicon-plus');
  301. }
  302. $('.filterSection').toggle(533);
  303. });
  304. //Add outcome Button
  305. function addOutcomeTest() {
  306. counter = parseInt($('#outcomeGroup').data("value"));
  307. var $select = $('<select/>', {
  308. 'class': "selectpicker form-control",
  309. 'name': "outcome[]",
  310. 'data-live-search': 'true',
  311. 'id': 'outcome' + counter.toString(),
  312. 'onchange': 'fetchObjectiveForSelect("outcomeGroup", "objectiveGroup")'
  313. });
  314. var $div = $('<div/>', {
  315. 'id': 'outcomeForm' + counter.toString(),
  316. 'class': 'form-group col-md-11'
  317. });
  318. var $divForButton = $('<div/>', {
  319. 'class': 'col-md-1',
  320. 'id': 'close' + counter.toString()
  321. });
  322. var $button = $('<button/>', {
  323. 'type': 'button',
  324. 'class': 'btn btn-primary',
  325. 'onclick': 'deleteLast("outcomeForm'+counter.toString()+'", "outcomeGroup", "close' + counter.toString() + '", "objectiveGroup")'
  326. });
  327. $button.append('X');
  328. $divForButton.append($button);
  329. $div.appendTo('#outcomeGroup')
  330. $select.append(selectOptions);
  331. $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
  332. $('#outcomeGroup').data("value", (counter +1));
  333. fetchObjectiveForSelect('outcomeGroup', "objectiveGroup");
  334. counter += 1;
  335. $divForButton.appendTo('#outcomeGroup');
  336. }
  337. //Delete Outcome and OptGroup associated
  338. function deleteLast(outcomeForm, outcomeDiv, closeButton, objectiveGroup) {
  339. $div = document.getElementById(outcomeForm );
  340. $div.remove();
  341. $div = document.getElementById(closeButton);
  342. $div.remove();
  343. if(outcomeDiv =='outcomeGroup'){
  344. $('#' + outcomeDiv).data('value',parseInt($('#' + outcomeDiv).data('value')) - 1);
  345. fetchObjectiveForSelect(outcomeDiv, objectiveGroup);}
  346. }
  347. //Delete Objective
  348. function deleteObjective(objectiveForm, closeObj, objectiveGroup) {
  349. $div = document.getElementById(objectiveForm);
  350. $div.remove();
  351. $div = document.getElementById(closeObj);
  352. $div.remove();
  353. counter = parseInt($('#'+objectiveGroup).data("value"));
  354. $('#'+objectiveGroup).data("value", counter-1);
  355. }
  356. //Add objective when editing
  357. function addAssocObjective() {
  358. selectObj = document.getElementById('assoc_objective_0').innerHTML;
  359. assocObjectiveCounter = parseInt($('#assoc_objectiveGroup').data('value'));
  360. var $select = $('<select/>', {
  361. 'class': "selectpicker form-control",
  362. 'name': "assoc_objective[]",
  363. 'data-live-search': 'true',
  364. 'id': 'assoc_objective_' + assocObjectiveCounter.toString(),
  365. });
  366. var $div = $('<div/>', {
  367. 'id': 'assoc_objectiveForm' + assocObjectiveCounter.toString(),
  368. 'class': 'form-group col-md-11'
  369. });
  370. var $divForButton = $('<div/>', {
  371. 'class': 'col-md-1',
  372. 'id': 'assoc_closeObj' + assocObjectiveCounter.toString()
  373. });
  374. var $button = $('<button/>', {
  375. 'type': 'button',
  376. 'class': 'btn btn-primary',
  377. 'onclick': 'deleteObjective("assoc_objectiveForm' + assocObjectiveCounter.toString() + '", "assoc_closeObj' + assocObjectiveCounter.toString() + ', "assoc_objectiveGroup")'
  378. });
  379. $button.append('X');
  380. $divForButton.append($button);
  381. $div.appendTo('#assoc_objectiveGroup')
  382. $select.append(selectObj);
  383. $select.appendTo('#assoc_objectiveForm' + assocObjectiveCounter.toString()).selectpicker('refresh');
  384. $('#assoc_objectiveGroup').data("value", assocObjectiveCounter +1);
  385. $divForButton.appendTo('#assoc_objectiveGroup');
  386. }
  387. //Add objective when creating a criteria
  388. function addObjectiveTest() {
  389. selectObj = document.getElementById('objective_0').innerHTML;
  390. counter = parseInt($("#objectiveGroup").data('value'));
  391. var $select = $('<select/>', {
  392. 'class': "selectpicker form-control",
  393. 'name': "objective[]",
  394. 'data-live-search': 'true',
  395. 'id': 'objective_' + counter.toString()
  396. });
  397. var $div = $('<div/>', {
  398. 'id': 'objectiveForm' + counter.toString(),
  399. 'class': 'form-group col-md-11'
  400. });
  401. var $divForButton = $('<div/>', {
  402. 'class': 'col-md-1',
  403. 'id': 'closeObj' + counter.toString()
  404. });
  405. var $button = $('<button/>', {
  406. 'type': 'button',
  407. 'class': 'btn btn-primary',
  408. 'onclick': 'deleteObjective("objectiveForm' + counter.toString() + '", "closeObj' + counter.toString() + '")'
  409. });
  410. $button.append('X');
  411. $divForButton.append($button);
  412. $div.appendTo('#objectiveGroup')
  413. $select.append(selectObj);
  414. $select.appendTo('#objectiveForm' + counter.toString()).selectpicker('refresh');
  415. $divForButton.appendTo('#objectiveGroup');
  416. $('#objectiveGroup').data('value', counter +1);
  417. }
  418. //Create outcome for editing
  419. var assocOutcomeCounter = 0;
  420. function addAssocOutcome() {
  421. assocOutcomeCounter = parseInt($('#assocOutcomeGroup').data('value'));
  422. var $select = $('<select/>', {
  423. 'class': "selectpicker form-control",
  424. 'name': "assoc_outcome[]",
  425. 'data-live-search': 'true',
  426. 'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
  427. 'onchange': 'fetchAssocObjective("assoc_outcome_' + assocOutcomeCounter.toString() + '")'
  428. });
  429. var $div = $('<div/>', {
  430. 'id': 'assoc_outcomeForm' + assocOutcomeCounter.toString(),
  431. 'class': 'form-group col-md-11'
  432. });
  433. var $divForButton = $('<div/>', {
  434. 'class': 'col-md-1',
  435. 'id': 'assoc_close' + assocOutcomeCounter.toString()
  436. });
  437. var $button = $('<button/>', {
  438. 'type': 'button',
  439. 'class': 'btn btn-primary',
  440. 'onclick': 'deleteLast("assoc_outcomeForm' + assocOutcomeCounter.toString() + '", "assocOutcomeGroup", "assoc_close' + assocOutcomeCounter.toString() + '","assoc_objectiveGroup")'
  441. });
  442. $button.append('X');
  443. $divForButton.append($button);
  444. $div.appendTo('#assocOutcomeGroup')
  445. $select.append(selectOptions);
  446. $select.appendTo('#assoc_outcomeForm' + assocOutcomeCounter.toString()).selectpicker('refresh');
  447. assocOutcomeCounter += 1;
  448. $divForButton.appendTo('#assocOutcomeGroup');
  449. $('#assocOutcomeGroup').data('value', assocOutcomeCounter);
  450. }
  451. //Fetch associated objective for editing
  452. var assocObjectiveCounter = 1;
  453. function fetchAssocObjective(outcomeDiv, objectiveGroup) {
  454. var count = $('#'+outcomeDiv).data('value');
  455. var allOutcomes =[];
  456. $("#" + outcomeDiv + ' select').each(function() {
  457. allOutcomes.push( this.value);
  458. })
  459. var allObjectives = [];
  460. $("#" + objectiveGroup + ' select').each(function() {
  461. var temp = {
  462. id: this.id,
  463. value: this.value
  464. }
  465. allObjectives.push(temp);
  466. })
  467. $.post(
  468. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  469. allOutcomes: allOutcomes
  470. },
  471. function(json) {
  472. optionName = '<option value ="0">Nothing Selected</option>';
  473. for(outcome in varArray.outcomes){
  474. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '">';
  475. var objectiveForOutcome = varArray.objectives;
  476. var objectives = objectiveForOutcome[outcome];
  477. for (objective in objectives) {
  478. var obj= objectives[objective];
  479. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  480. optionName += (option);
  481. }
  482. optionName += '</optgroup>';
  483. }
  484. $('#assoc_objective_0').html(optionName);
  485. $('#assoc_objective_0').selectpicker('refresh');
  486. if($("#assoc_objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  487. $("#assoc_objective_0").val(allObjectives[0].value);
  488. $('#assoc_objective_0').selectpicker('refresh');
  489. }
  490. for (var i = allObjectives.length - 1; i > 0; i--) {
  491. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup');
  492. }
  493. for(var i=1; i<allObjectives.length; i++){
  494. addAssocObjective();
  495. $('#assoc_objective_'+i.toString()).selectpicker('refresh');
  496. if($("#assoc_objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  497. $("#assoc_objective_"+i.toString()).val(allObjectives[i].value);
  498. $("#assoc_objective_"+i.toString()).selectpicker("refresh");
  499. }
  500. }
  501. },
  502. 'json'
  503. );
  504. }
  505. //Fetch objective at creating criteria
  506. counterForPost = 0;
  507. function fetchObjectiveForSelect(outcomeDiv, objectiveGroup) {
  508. var count = $("#" + outcomeDiv).data('value');
  509. var allOutcomes = [];
  510. $("#" + outcomeDiv + ' select').each(function() {
  511. allOutcomes.push( this.value);
  512. })
  513. var allObjectives = [];
  514. $("#" + objectiveGroup + ' select').each(function() {
  515. var temp = {
  516. id: this.id,
  517. value: this.value
  518. }
  519. allObjectives.push(temp);
  520. })
  521. $.post(
  522. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  523. allOutcomes: allOutcomes
  524. },
  525. function(varArray) {
  526. counterOutcome =0;
  527. optionName = '<option value ="0">Nothing Selected</option>';
  528. for(outcome in varArray.outcomes){
  529. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '">';
  530. var objectiveForOutcome = varArray.objectives;
  531. var objectives = objectiveForOutcome[outcome];
  532. for (objective in varArray.objectives[outcome]) {
  533. var obj= objectives[objective];
  534. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  535. optionName += (option);
  536. }
  537. optionName += "</optgroup>";
  538. }
  539. $('#objective_0').html(optionName);
  540. $('#objective_0').selectpicker('refresh');
  541. if($("#objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  542. $("#objective_0").val(allObjectives[0].value);
  543. $('#objective_0').selectpicker('refresh');
  544. }
  545. for (var i = allObjectives.length - 1; i > 0; i--) {
  546. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString(), 'objectiveGroup');
  547. }
  548. for(var i =1; i<allObjectives.length; i++){
  549. addObjectiveTest();
  550. $('#objective_'+i.toString()).selectpicker('refresh');
  551. if($("#objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  552. $("#objective_"+i.toString()).val(allObjectives[i].value);
  553. $("#objective_"+i.toString()).selectpicker("refresh");
  554. }
  555. }
  556. },
  557. 'json'
  558. );
  559. }
  560. //after post
  561. //For editing criterion
  562. function fetchAllCriterion(program, outcome) {
  563. var program_id_fetch = $('#' + program).find(':selected').val();
  564. var outcome_fetch = $('#' + outcome).find(':selected').val();
  565. $.post(
  566. "{{URL::action('CriteriaController@fetchAllCriterion')}}", {
  567. program_fetch: program_id_fetch,
  568. outcome_fetch: outcome_fetch
  569. },
  570. function(json) {
  571. json_length = (json.criterion.length);
  572. fullHTML = '';
  573. for (var i = 0; i < json_length; i++) {
  574. fullHTML += '<option value="' + json.criterion[i].id + '">' + json.criterion[i].name + '</option>';
  575. }
  576. $('#select-criterion').html(fullHTML);
  577. $('#select-criterion').selectpicker('refresh');
  578. fetchCriterionForEditing()
  579. },
  580. 'json'
  581. );
  582. }
  583. function deleteCriterion() {
  584. var id = $('#select-criterion').find(':selected').val()
  585. $.post(
  586. "{{ URL::action('CriteriaController@delete')}}", {
  587. id: id
  588. },
  589. function() {
  590. window.location.reload(true)
  591. }
  592. )
  593. }
  594. function fetchCriterionForEditing() {
  595. var id = $('#select-criterion').find(':selected').val();
  596. $.post(
  597. "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
  598. id: id
  599. },
  600. function(json) {
  601. if (!(json.activity_criterion.length)) {
  602. $('#DeleteButton').prop('enabled', true);
  603. } else {
  604. $('#DeleteButton').prop('disabled', true);
  605. }
  606. if (!(json.criteria.length)) {
  607. name = ' ';
  608. var subcriteria = '';
  609. copyright = null;
  610. notes = null;
  611. $('#status').val(0);
  612. maximum = 1;
  613. $('#assoc_maximum_score').val(1);
  614. } else {
  615. var name = json.criteria[0].name;
  616. if (json.criteria[0].subcriteria) {
  617. subcriteria = JSON.parse(json.criteria[0].subcriteria).join('\n');
  618. }else {
  619. subcriteria = "";
  620. }
  621. if (json.criteria[0].copyright) {
  622. var copyright = json.criteria[0].copyright;
  623. } else {
  624. var copyright = ''
  625. }
  626. if (json.criteria[0].notes) notes = json.criteria[0].notes;
  627. else notes = '';
  628. // Display info
  629. $('#criterion_name').val(name);
  630. $('#criterion_subcriteria').text(subcriteria);
  631. if (json.criteria[0].deleted_at)
  632. $('#status').val(0);
  633. else
  634. $('#status').val(1);
  635. $('#assoc_maximum_score').val(json.criteria[0].maximum_score);
  636. var maximum = json.criteria[0].maximum_score;
  637. // If copyright or notes aren't empty, load them
  638. }
  639. $('#criterion_copyright').text(copyright);
  640. $('#criterion_notes').text(notes);
  641. // Select associated outcome
  642. try {
  643. assocOutcomeCounter= parseInt($("#assocOutcomeGroup").data('value'));
  644. for (var i = assocOutcomeCounter - 1; i > 0; i--) {
  645. deleteLast("assoc_outcomeForm" + i.toString() , "assocOutcomeGroup", "assoc_close" + i.toString() ,"assoc_objectiveGroup");
  646. }
  647. } catch (err) {
  648. var Notran = true;
  649. }
  650. if (json.outcomes.length) {
  651. $('#assoc_outcome_0').val(json.outcomes[0].id);
  652. $('#assoc_outcome_0').selectpicker('refresh');
  653. } else {
  654. $('#assoc_outcome_0').val($('#assoc_outcomes_fetch').find(':selected').val());
  655. $('#assoc_outcome_0').selectpicker('refresh');
  656. }
  657. for (var i = 1; i < json.outcomes.length; i++) {
  658. addAssocOutcome();
  659. $('#assoc_outcome_' + i.toString()).val(json.outcomes[i].id);
  660. $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
  661. }
  662. counterObj =$('#assoc_objectiveGroup').data('value');
  663. try {
  664. for (var i = counterObj - 1; i > 0; i--) {
  665. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup')
  666. }
  667. } catch (err) {
  668. var noEntro = true;
  669. }
  670. $('#assoc_objectiveGroup').data('value', 1);
  671. assocOutcomeCounter = 0;
  672. var i = 0;
  673. optionName = '<option value ="0">Nothing Selected</option>';
  674. for(outcome in json.outcomes_assoc){
  675. optionName += '<optgroup label="' + json.outcomes_assoc[outcome][0].name + '">';
  676. var objectiveForOutcome = json.objectives_assoc;
  677. var objectives = objectiveForOutcome[outcome];
  678. for (objective in objectives) {
  679. var obj= objectives[objective];
  680. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  681. optionName += (option);
  682. }
  683. optionName+= '</optgroup>';
  684. }
  685. $('#assoc_objective_0').html(optionName);
  686. $('#assoc_objective_0').selectpicker('refresh');
  687. try {
  688. $('#assoc_objective_0').val(json.objectives[0].id);
  689. $('#assoc_objective_0').selectpicker('refresh');
  690. } catch (err) {
  691. if (!json.objectives.length) {
  692. $('#assoc_objective_0').val(0);
  693. $('#assoc_objective_0').selectpicker('refresh');
  694. }
  695. var thereIsNoObjective = true;
  696. }
  697. for (var i = 1; i < json.objectives.length; i++) {
  698. addAssocObjective();
  699. $('#assoc_objective_' + i.toString()).val(json.objectives[i].id);
  700. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  701. }
  702. $('assoc_objectiveGroup').data('value',json.objectives.length);
  703. // Select status
  704. },
  705. 'json'
  706. );
  707. }
  708. </script>
  709. @stop
  710. @section('javascript')
  711. // --------------------------------------------------------------------------
  712. // Page load
  713. // --------------------------------------------------------------------------
  714. // Hide accordion panel contents by default
  715. $('.panel-group .panel-body').hide();
  716. $('#outcome-display').parent().hide();
  717. fetchCriterionForEditing();
  718. fetchObjectiveForSelect('outcomeGroup', 'objectiveGroup');
  719. // setCriterionStatus();
  720. fetchAllCriterion("select-program", "assoc_outcomes_fetch");
  721. // --------------------------------------------------------------------------
  722. // Functions
  723. // --------------------------------------------------------------------------
  724. $('#button-add-outcome').on('click', function(e) {
  725. // Prevent the default action of the clicked item. In this case that is submit
  726. e.preventDefault();
  727. return false;
  728. });
  729. $('.filterButton').on('click', function(e) {
  730. // Prevent the default action of the clicked item. In this case that is submit
  731. e.preventDefault();
  732. return false;
  733. });
  734. $('#button-add-objective-assoc').on('click', function(e) {
  735. // Prevent the default action of the clicked item. In this case that is submit
  736. e.preventDefault();
  737. return false;
  738. });
  739. $('#button-add-outcome-assoc').on('click', function(e) {
  740. // Prevent the default action of the clicked item. In this case that is submit
  741. e.preventDefault();
  742. return false;
  743. });
  744. $('#button-add-objective').on('click', function(e) {
  745. // Prevent the default action of the clicked item. In this case that is submit
  746. e.preventDefault();
  747. return false;
  748. });
  749. // Fetch criterion info for editing
  750. // --------------------------------------------------------------------------
  751. // Events
  752. // --------------------------------------------------------------------------
  753. // When panel heading is clicked, toggle it
  754. $('.panel-group .panel-heading').on('click', function()
  755. {
  756. $(this).next().stop().slideToggle();
  757. })
  758. //$('#outcome[0]').on('change', function(){
  759. //$('.selectpicker').selectpicker('refresh');
  760. //})
  761. // When list item is clicked, load corresponding info
  762. // When list item is clicked, load corresponding info
  763. $('.selectpicker').on('change', function()
  764. {
  765. //alert($(this).find(':selected').val());
  766. $('.selectpicker').selectpicker('refresh');
  767. });
  768. @stop