Bez popisu

criteria.blade.php 48KB

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