No Description

criteria.blade.php 47KB

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