No Description

criteria.blade.php 42KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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'>
  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("outcome0")']) }}
  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'>
  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'>
  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'>
  132. <div class="form-group">
  133. <label>Associated Objectives</label>
  134. <select id="assoc_objective_0" name="assoc_objective[]" class="form-control selectpicker">
  135. </select>
  136. </div>
  137. </div>
  138. <button id='button-add-outcome-assoc' class='btn btn-md btn-secondary' onclick='addAssocObjective()'>
  139. <span class='glyphicon glyphicon-plus'>
  140. </span>
  141. Add another Objective
  142. </button>
  143. <!-- Associated Program -->
  144. <div class="form-group">
  145. {{ Form::label('program_id2', 'Associated Program') }}<br><br>
  146. <input type = "hidden" id = "{{ $programs[0]->name }}" name="program_id[]" value="{{$programs[0]->id}}">
  147. <input type="checkbox" id="assoc_program_id_{{ $programs[0]->id }}" name="program_id[]" value="{{$programs[0]->id}}" disabled checked>
  148. <label for="assoc_program_id_{{ $programs[0]->id }}"> {{ $programs[0]->name }} <sub>[{{ $programs[0]->school->name }}]</sub></label><br>
  149. </div>
  150. <!-- Status -->
  151. <div class="form-group">
  152. {{ Form::label('status', 'Status') }}
  153. <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>
  154. <select id="status" name="status" class="form-control">
  155. <option value="1">Active</option>
  156. <option value="0">Inactive</option>
  157. </select>
  158. </div>
  159. <div class="form-group">
  160. {{ Form::label('name', 'Name') }}
  161. {{ Form::text('name', Input::old('name'), array('class' => 'form-control', 'id'=>'criterion_name')) }}
  162. </div>
  163. <div class="form-group">
  164. {{ Form::label('subcriteria', 'Subcriteria') }}
  165. <p class="help-block"><strong>Manually add</strong> bullets or numbering.</p>
  166. {{ Form::textarea('subcriteria', '', array('class' => 'form-control', 'rows'=>3, 'id' => 'criterion_subcriteria')) }}
  167. </div>
  168. <div class="form-group">
  169. {{ Form::label('assoc_maximum_score', 'Maximum Score') }}
  170. {{ Form::text('assoc_maximum_score', '', array('class' => 'form-control', 'id'=>'assoc_maximum_score', 'oninput'=>'addOptions("Num_assoc_scale", "assoc_maximum_score", "Assoc_Scales")')) }}
  171. </div>
  172. <div class="form-group">
  173. {{ Form::label('scales', 'Number of Scales') }}
  174. <select id="Num_assoc_scale" class="form-control selectpicker" onchange='numberOfAssoc("Num_assoc_scale", "Assoc_Scales")'>
  175. </select>
  176. </div>
  177. <div id='Assoc_Scales' data-value="0">
  178. </div>
  179. <div class="form-group">
  180. {{ Form::label('copyright', 'Copyright Information') }}
  181. {{ Form::textarea('copyright', Input::old('copyright'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_copyright', 'placeholder'=>'(optional)')) }}
  182. </div>
  183. <div class="form-group">
  184. {{ Form::label('notes', 'Additional Notes') }}
  185. {{ Form::textarea('notes', Input::old('notes'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_notes', 'placeholder'=>'(optional)')) }}
  186. </div>
  187. {{ Form::submit('Update', array('class' => 'btn btn-primary btn-block')) }}
  188. {{ Form::close() }}
  189. <div id='delete'>
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. </div>
  195. <script>
  196. var selectOptions = document.getElementById('outcome0').innerHTML;
  197. var counter = 1;
  198. var counterObj = 1;
  199. var outcomeString = 'OutcomeGroup_';
  200. $(document).ready(function() {
  201. addOptions('Num_scale', 'maximum_score', 'Scales');
  202. numberOfScales('Num_scale', 'Scales');
  203. });
  204. function numberOfAssoc(string, Scales) {
  205. var maximum = $('#assoc_maximum_score').val();
  206. var amountOfScale = parseInt($('#' + string).val());
  207. var dataValue = parseInt($('#' + Scales).attr('data-value'));
  208. //add
  209. if (dataValue < amountOfScale) {
  210. fullDiv = '';
  211. for (var i = dataValue; i < amountOfScale; i++) {
  212. div = '<div id="assoc_eval' + i.toString() + Scales + '">' +
  213. '<div class ="form-row">' +
  214. '<label for="header' + (i).toString() + '">Evaluación ' + (i + 1).toString() + '</label><br><br>' +
  215. '<input type="hidden" id="header' + i.toString() + '">' +
  216. '<div class="form-group col-md-8" >' +
  217. '<label for="title' + i.toString() + '">Nombre de Evaluación ' + (i + 1).toString() + '</label>' +
  218. '<input class="form-control" name="assoc_title[]" type="text" id="title' + i.toString() + '" placeholder ="Nombre de evaluacion" ></div>' +
  219. '<div class ="form-group col-md-2">' +
  220. '<label for="min' + i.toString() + '">Mínimo </label>' +
  221. '<input class="form-control" type="number" id="assoc_min' + i.toString() + '" min="1" max = "' + maximum + '" oninput ="changedMin(' + "'assoc_min" + i.toString() + "', '" + i.toString() + "', 'Assoc_Scales' " + ')" name = "assoc_min[]"></div>' +
  222. '<div class ="form-group col-md-2">' +
  223. '<label for="max' + i.toString() + '">Máximo </label>' +
  224. '<input class="form-control" type="number" id="assoc_max' + i.toString() + '" min="1" max = "' + maximum + '" oninput ="changedMax(' + "'assoc_max" + i.toString() + "', '" + i.toString() + "', 'Assoc_Scales' " + ')" name = "assoc_max[]"></div></div>' +
  225. '<div class ="form-group">' +
  226. '<label for ="descripcion' + i.toString() + '">Descripción de evaluación</label>' +
  227. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="assoc_scales[]" cols="50" ></textarea></div></div>';
  228. fullDiv += div;
  229. }
  230. $('#' + Scales).append(fullDiv);
  231. $('#' + Scales).attr('data-value', amountOfScale);
  232. } else {
  233. for (var i = dataValue; i > amountOfScale; i--) {
  234. $('#assoc_eval' + (i - 1).toString()).remove();
  235. }
  236. }
  237. $('#' + Scales).attr('data-value', amountOfScale);
  238. }
  239. function addOptions(select, max, scaleDiv) {
  240. var maxscore = parseInt($('#' + max).val())
  241. options = '';
  242. for (var i = 1; i <= maxscore; i++) {
  243. options += '<option value="' + i.toString() + '">' + i.toString() + '</option>';
  244. }
  245. var previousvalue = parseInt($('#' + select).val());
  246. $('#' + select).html(options);
  247. $('#' + select).val(previousvalue);
  248. $('#' + select).selectpicker('refresh');
  249. var attribute = parseInt($('#' + scaleDiv).attr('data-value'));
  250. for (var i = 0; i < attribute; i++) {
  251. $('#max' + i.toString()).attr('max', maxscore);
  252. $('#min' + i.toString()).attr('max', maxscore);
  253. }
  254. }
  255. $('.filterSection').hide();
  256. $('.filterButton').on('click', function()
  257. {
  258. var span = $(this).find('span');
  259. if(span.attr('class') == 'glyphicon glyphicon-plus'){
  260. span.attr('class','glyphicon glyphicon-minus');
  261. } else{
  262. span.attr('class','glyphicon glyphicon-plus');
  263. }
  264. $('.filterSection').toggle(533);
  265. });
  266. function numberOfScales(string, Scales) {
  267. var maximum = $('#maximum_score').val();
  268. var amountOfScale = parseInt($('#' + string).val());
  269. var dataValue = parseInt($('#' + Scales).attr('data-value'));
  270. //add
  271. if (dataValue < amountOfScale) {
  272. fullDiv = '';
  273. for (var i = dataValue; i < amountOfScale; i++) {
  274. div = '<div id="eval' + i.toString() + Scales + '">' +
  275. '<div class ="form-row">' +
  276. '<label for="header' + (i).toString() + '">Evaluación ' + (i + 1).toString() + '</label><br><br>' +
  277. '<input type="hidden" id="header' + i.toString() + '">' +
  278. '<div class="form-group col-md-8" >' +
  279. '<label for="title' + i.toString() + '">Nombre de Evaluación ' + (i + 1).toString() + '</label>' +
  280. '<input class="form-control" name="title[]" type="text" id="title' + i.toString() + '" placeholder ="Nombre de evaluacion" ></div>' +
  281. '<div class ="form-group col-md-2">' +
  282. '<label for="min' + i.toString() + '">Mínimo </label>' +
  283. '<input class="form-control" type="number" id="min' + i.toString() + '" min="1" max = "' + maximum + '" oninput ="changedMin(' + "'min" + i.toString() + "', '" + i.toString() + "', 'Scales' " + ')" name = "min[]"></div>' +
  284. '<div class ="form-group col-md-2">' +
  285. '<label for="max' + i.toString() + '">Máximo </label>' +
  286. '<input class="form-control" type="number" id="max' + i.toString() + '" min="1" max = "' + maximum + '" oninput ="changedMax(' + "'max" + i.toString() + "', '" + i.toString() + "', 'Scales' " + ')" name = "max[]"></div></div>' +
  287. '<div class ="form-group">' +
  288. '<label for ="descripcion' + i.toString() + '">Descripción de evaluación</label>' +
  289. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="' + Scales + '[]" cols="50" ></textarea></div></div>';
  290. fullDiv += div;
  291. }
  292. $('#' + Scales).append(fullDiv);
  293. } else {
  294. for (var i = dataValue; i > amountOfScale; i--) {
  295. $('#eval' + (i - 1).toString() + Scales).remove();
  296. }
  297. }
  298. $('#' + Scales).attr('data-value', amountOfScale);
  299. }
  300. function changedMin(min, index, scaleDiv) {
  301. var maximum = parseInt($('#' + min).val()) + 1;
  302. var maxScaleScore = parseInt($('#' + scaleDiv).attr('data-value'));
  303. for (var i = parseInt(index); i < maxScaleScore; i++) {
  304. $('#max' + i).attr('min', maximum);
  305. }
  306. }
  307. function changedMax(max, index, scaleDiv) {
  308. var maximum = parseInt($('#' + max).val()) + 1;
  309. var maxScaleScore = parseInt($('#' + scaleDiv).attr('data-value'));
  310. for (var i = parseInt(index) + 1; i < maxScaleScore; i++) {
  311. $('#min' + i).attr('min', maximum)
  312. }
  313. }
  314. //Add outcome Button
  315. function addOutcomeTest() {
  316. var $select = $('<select/>', {
  317. 'class': "selectpicker form-control",
  318. 'name': "outcome[]",
  319. 'data-live-search': 'true',
  320. 'id': 'outcome' + counter.toString(),
  321. 'onchange': 'fetchObjectiveForSelect("outcomeGroup", "objectiveGroup")'
  322. });
  323. var $div = $('<div/>', {
  324. 'id': 'outcomeForm' + counter.toString(),
  325. 'class': 'form-group col-md-11'
  326. });
  327. var $divForButton = $('<div/>', {
  328. 'class': 'col-md-1',
  329. 'id': 'close' + counter.toString()
  330. });
  331. var $button = $('<button/>', {
  332. 'type': 'button',
  333. 'class': 'btn btn-primary',
  334. 'onclick': 'deleteLast("outcomeForm'+counter.toString()+'", "outcomeGroup", "close' + counter.toString() + '", "objectiveGroup")'
  335. });
  336. $button.append('X');
  337. $divForButton.append($button);
  338. $div.appendTo('#outcomeGroup')
  339. $select.append(selectOptions);
  340. $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
  341. fetchObjectiveForSelect('outcomeGroup', "objectiveGroup");
  342. counter += 1;
  343. $divForButton.appendTo('#outcomeGroup');
  344. $('#counterOutcome').val(counter)
  345. }
  346. //Delete Outcome and OptGroup associated
  347. function deleteLast(outcomeForm, outcomeDiv, closeButton, objectiveGroup) {
  348. $div = document.getElementById(outcomeForm );
  349. $div.remove();
  350. $div = document.getElementById(closeButton);
  351. $div.remove();
  352. if(outcomeDiv =='outcomeGroup'){
  353. $('#' + outcomeDiv).data('value',parseInt($('#' + outcomeDiv).data('value')) - 1);
  354. fetchObjectiveForSelect(outcomeDiv, objectiveGroup);}
  355. }
  356. //Delete Objective
  357. function deleteObjective(objectiveForm, closeObj) {
  358. $div = document.getElementById(objectiveForm);
  359. $div.remove();
  360. $div = document.getElementById(closeObj);
  361. $div.remove();
  362. }
  363. //Add objective when editing
  364. function addAssocObjective() {
  365. selectObj = document.getElementById('assoc_objective_0').innerHTML;
  366. var $select = $('<select/>', {
  367. 'class': "selectpicker form-control",
  368. 'name': "assoc_objective[]",
  369. 'data-live-search': 'true',
  370. 'id': 'assoc_objective_' + assocObjectiveCounter.toString(),
  371. });
  372. var $div = $('<div/>', {
  373. 'id': 'assoc_objectiveForm' + assocObjectiveCounter.toString(),
  374. 'class': 'form-group col-md-11'
  375. });
  376. var $divForButton = $('<div/>', {
  377. 'class': 'col-md-1',
  378. 'id': 'assoc_closeObj' + assocObjectiveCounter.toString()
  379. });
  380. var $button = $('<button/>', {
  381. 'type': 'button',
  382. 'class': 'btn btn-primary',
  383. 'onclick': 'deleteObjective("assoc_objectiveForm' + assocObjectiveCounter.toString() + '", "assoc_closeObj' + assocObjectiveCounter.toString() + '")'
  384. });
  385. $button.append('X');
  386. $divForButton.append($button);
  387. $div.appendTo('#assoc_objectiveGroup')
  388. $select.append(selectObj);
  389. $select.appendTo('#assoc_objectiveForm' + assocObjectiveCounter.toString()).selectpicker('refresh');
  390. counterObj += 1;
  391. $divForButton.appendTo('#assoc_objectiveGroup');
  392. }
  393. //Add objective when creating a criteria
  394. function addObjectiveTest() {
  395. selectObj = document.getElementById('objective_0').innerHTML;
  396. var $select = $('<select/>', {
  397. 'class': "selectpicker form-control",
  398. 'name': "objective[]",
  399. 'data-live-search': 'true',
  400. 'id': 'objective_' + counterObj.toString()
  401. });
  402. var $div = $('<div/>', {
  403. 'id': 'objectiveForm' + counterObj.toString(),
  404. 'class': 'form-group col-md-11'
  405. });
  406. var $divForButton = $('<div/>', {
  407. 'class': 'col-md-1',
  408. 'id': 'closeObj' + counterObj.toString()
  409. });
  410. var $button = $('<button/>', {
  411. 'type': 'button',
  412. 'class': 'btn btn-primary',
  413. 'onclick': 'deleteObjective("objectiveForm' + counterObj.toString() + '", "closeObj' + counterObj.toString() + '")'
  414. });
  415. $button.append('X');
  416. $divForButton.append($button);
  417. $div.appendTo('#objectiveGroup')
  418. $select.append(selectObj);
  419. $select.appendTo('#objectiveForm' + counterObj.toString()).selectpicker('refresh');
  420. counterObj += 1;
  421. $divForButton.appendTo('#objectiveGroup');
  422. $('#counterObjective').val(counterObj)
  423. }
  424. //Create outcome for editing
  425. var assocOutcomeCounter = 0;
  426. function addAssocOutcome() {
  427. var $select = $('<select/>', {
  428. 'class': "selectpicker form-control",
  429. 'name': "assoc_outcome[]",
  430. 'data-live-search': 'true',
  431. 'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
  432. 'onchange': 'fetchAssocObjective("assoc_outcome_' + assocOutcomeCounter.toString() + '")'
  433. });
  434. var $div = $('<div/>', {
  435. 'id': 'assoc_outcomeForm' + assocOutcomeCounter.toString(),
  436. 'class': 'form-group col-md-11'
  437. });
  438. var $divForButton = $('<div/>', {
  439. 'class': 'col-md-1',
  440. 'id': 'assoc_close' + assocOutcomeCounter.toString()
  441. });
  442. var $button = $('<button/>', {
  443. 'type': 'button',
  444. 'class': 'btn btn-primary',
  445. 'onclick': 'deleteLast("assoc_outcomeForm' + assocOutcomeCounter.toString() + '", "assocOutcomeGroup", "assoc_close' + assocOutcomeCounter.toString() + '","assoc_objectiveGroup")'
  446. });
  447. $button.append('X');
  448. $divForButton.append($button);
  449. $div.appendTo('#assocOutcomeGroup')
  450. $select.append(selectOptions);
  451. $select.appendTo('#assoc_outcomeForm' + assocOutcomeCounter.toString()).selectpicker('refresh');
  452. //fetchAssocObjective('assoc_outcome_' + assocOutcomeCounter.toString());
  453. assocOutcomeCounter += 1;
  454. $divForButton.appendTo('#assocOutcomeGroup');
  455. }
  456. //Fetch associated objective for editing
  457. var assocObjectiveCounter = 1;
  458. function fetchAssocObjective(outcomeId) {
  459. var id = $('#' + outcomeId).find(':selected').val();
  460. $.post(
  461. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  462. id: id
  463. },
  464. function(json) {
  465. var optionName = '<optgroup id="' + 'Associated_Outcome' + (assocOutcomeCounter - 1).toString() + '"label="' + 'Associated Outcome' + (assocOutcomeCounter).toString() + '"';
  466. for (var i = 0; i < json.length; i++) {
  467. var option = '<option value ="' + json[i].id.toString() + '">' + json[i].text + '</option>'
  468. optionName += (option)
  469. }
  470. optGroup = document.getElementById('Associated_Outcome' + (assocOutcomeCounter - 1).toString());
  471. if (optGroup != null) {
  472. optGroup.remove()
  473. }
  474. $('#assoc_objective_0').append(optionName);
  475. $('#assoc_objective_0').selectpicker('refresh');
  476. for (var i = assocObjectiveCounter - 1; i > 0; i--) {
  477. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString())
  478. }
  479. assocObjectiveCounter = 1;
  480. },
  481. 'json'
  482. );
  483. }
  484. //Fetch objective at creating criteria
  485. counterForPost = 0;
  486. function fetchObjectiveForSelect(outcomeDiv, objectiveGroup) {
  487. var count = $("#" + outcomeDiv).data('value');
  488. var allOutcomes = [];
  489. $("#" + outcomeDiv + ' select').each(function() {
  490. allOutcomes.push( this.value);
  491. })
  492. var allObjectives = [];
  493. $("#" + objectiveGroup + ' select').each(function() {
  494. var temp = {
  495. id: this.id,
  496. value: this.value
  497. }
  498. allObjectives.push(temp);
  499. })
  500. $.post(
  501. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  502. allOutcomes: allOutcomes
  503. },
  504. function(varArray) {
  505. counterOutcome =0;
  506. optionName = '';
  507. for(outcome in varArray.outcomes){
  508. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '"';
  509. var objectiveForOutcome = varArray.objectives;
  510. var objectives = objectiveForOutcome[outcome];
  511. for (objective in varArray.objectives[outcome]) {
  512. var obj= objectives[objective];
  513. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  514. optionName += (option);
  515. }
  516. }
  517. $('#objective_0').html(optionName);
  518. $('#objective_0').selectpicker('refresh');
  519. if($("#objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  520. $("#objective_0").val(allObjectives[0].value);
  521. $('#objective_0').selectpicker('refresh');
  522. }
  523. for (var i = allObjectives.length - 1; i > 0; i--) {
  524. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString(), 'objectiveGroup');
  525. }
  526. for(var i =1; i<allObjectives.length; i++){
  527. addObjectiveTest();
  528. $('#objective_'+i.toString()).selectpicker('refresh');
  529. if($("#objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  530. $("#objective_"+i.toString()).val(allObjectives[i].value);
  531. $("#objective_"+i.toString()).selectpicker("refresh");
  532. }
  533. }
  534. },
  535. 'json'
  536. );
  537. }
  538. //after post
  539. fetchAllCriterion("select-program", "assoc_outcomes_fetch");
  540. //For editing criterion
  541. function fetchAllCriterion(program, outcome) {
  542. var program_id_fetch = $('#' + program).find(':selected').val();
  543. var outcome_fetch = $('#' + outcome).find(':selected').val();
  544. $.post(
  545. "{{URL::action('CriteriaController@fetchAllCriterion')}}", {
  546. program_fetch: program_id_fetch,
  547. outcome_fetch: outcome_fetch
  548. },
  549. function(json) {
  550. json_length = (json.criterion.length);
  551. fullHTML = '';
  552. for (var i = 0; i < json_length; i++) {
  553. fullHTML += '<option value="' + json.criterion[i].id + '">' + json.criterion[i].name + '</option>';
  554. }
  555. $('#select-criterion').html(fullHTML);
  556. $('#select-criterion').selectpicker('refresh');
  557. fetchCriterionForEditing()
  558. },
  559. 'json'
  560. );
  561. }
  562. function deleteCriterion() {
  563. var id = $('#select-criterion').find(':selected').val()
  564. $.post(
  565. "{{ URL::action('CriteriaController@delete')}}", {
  566. id: id
  567. },
  568. function() {
  569. window.location.reload(true)
  570. }
  571. )
  572. }
  573. function fetchCriterionForEditing() {
  574. var id = $('#select-criterion').find(':selected').val();
  575. $.post(
  576. "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
  577. id: id
  578. },
  579. function(json) {
  580. if (!(json.activity_criterion.length)) {
  581. var button = "<button type='button' class ='btn btn-primary btn-block' onclick ='deleteCriterion()'>Delete Criterion</button><br><br>"
  582. $('#delete').html(button)
  583. }
  584. if (!(json.criteria.length)) {
  585. name = ' ';
  586. var subcriteria = '';
  587. copyright = null;
  588. notes = null;
  589. $('#status').val(0);
  590. maximum = 1;
  591. $('#assoc_maximum_score').val(1);
  592. } else {
  593. var name = json.criteria[0].name;
  594. if (json.criteria[0].subcriteria) {
  595. subcriteria = JSON.parse(json.criteria[0].subcriteria).join('\n');
  596. }
  597. var copyright = json.criteria[0].copyright;
  598. var notes = json.criteria[0].notes;
  599. // Display info
  600. $('#criterion_name').val(name);
  601. $('#criterion_subcriteria').text(subcriteria);
  602. if (json.criteria[0].deleted_at)
  603. $('#status').val(0);
  604. else
  605. $('#status').val(1);
  606. $('#assoc_maximum_score').val(json.criteria[0].maximum_score);
  607. var maximum = json.criteria[0].maximum_score;
  608. // If copyright or notes aren't empty, load them
  609. }
  610. if (copyright) {
  611. $('#criterion_copyright').text(copyright);
  612. } else {
  613. $('#criterion_copyright').text('');
  614. }
  615. if (notes) {
  616. $('#criterion_notes').text(notes);
  617. } else {
  618. $('#criterion_notes').text('');
  619. }
  620. // Select associated outcome
  621. try {
  622. for (var i = assocOutcomeCounter - 1; i > 0; i--) {
  623. deleteLast("assoc_outcomeForm" + i.toString() , "assocOutcomeGroup", "assoc_close" + i.toString() ,"assoc_objectiveGroup");
  624. }
  625. } catch (err) {
  626. var Notran = true;
  627. }
  628. if (json.outcomes.length) {
  629. $('#assoc_outcome_0').val(json.outcomes[0].id);
  630. $('#assoc_outcome_0').selectpicker('refresh');
  631. } else {
  632. $('#assoc_outcome_0').val($('#assoc_outcomes_fetch').find(':selected').val());
  633. $('#assoc_outcome_0').selectpicker('refresh');
  634. }
  635. for (var i = 1; i < json.outcomes.length; i++) {
  636. addAssocOutcome();
  637. $('#assoc_outcome_' + i.toString()).val(json.outcomes[i].id);
  638. $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
  639. }
  640. try {
  641. for (var i = counterObj - 1; i > 0; i--) {
  642. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString())
  643. }
  644. } catch (err) {
  645. var noEntro = true;
  646. }
  647. counterObj = 1;
  648. assocOutcomeCounter = 0;
  649. var i = 0;
  650. for (var j = 0; j < json.outcomes.length; j++) {
  651. assocOutcomeCounter += 1;
  652. var optionName = '<optgroup id="' + 'Associated_Outcome' + (assocOutcomeCounter - 1).toString() + '"label="' + json.outcomes[j].name + '"';
  653. for (; i < json.objectives_outcome.length; i++) {
  654. if (json.objectives_outcome[i].outcome_id != json.outcomes[j].id) break;
  655. var option = '<option value ="' + json.objectives_outcome[i].id.toString() + '">' + json.objectives_outcome[i].text + '</option>'
  656. optionName += (option)
  657. }
  658. optGroup = document.getElementById('Associated_Outcome' + (assocOutcomeCounter - 1).toString());
  659. if (optGroup != null) {
  660. optGroup.remove()
  661. }
  662. $('#assoc_objective_0').append(optionName);
  663. $('#assoc_objective_0').selectpicker('refresh');
  664. }
  665. for (var i = assocObjectiveCounter - 1; i > 0; i--) {
  666. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString())
  667. }
  668. assocObjectiveCounter = 1;
  669. try {
  670. $('#assoc_objective_0').val(json.objectives[0].id);
  671. $('#assoc_objective_0').selectpicker('refresh');
  672. } catch (err) {
  673. if (!json.objectives.length) {
  674. $('#assoc_objective_0').val(0);
  675. $('#assoc_objective_0').selectpicker('refresh');
  676. }
  677. var thereIsNoObjective = true;
  678. }
  679. for (var i = 1; i < json.objectives.length; i++) {
  680. addAssocObjective();
  681. $('#assoc_objective_' + i.toString()).val(json.objectives[i].id);
  682. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  683. }
  684. assocObjectiveCounter = json.objectives.length;
  685. // Select status
  686. scaleLength = json.scales.length;
  687. fullDiv = '';
  688. if (!scaleLength) {
  689. div = '<div id="assoc_eval 0"">' +
  690. '<div class ="form-row">' +
  691. '<label for="header0">Evaluación 1</label><br><br>' +
  692. '<input type="hidden" id="header0">' +
  693. '<div class="form-group col-md-8" >' +
  694. '<label for="title0">Nombre de Evaluación 1</label>' +
  695. '<input class="form-control" name="assoc_title[]" value =" "type="text" id="title0" placeholder ="Nombre de evaluacion" ></div>' +
  696. '<div class ="form-group col-md-2">' +
  697. '<label for="min0">Mínimo </label>' +
  698. '<input class="form-control" type="number" id="assoc_min0" min="1" max = "1" value =" " name = "assoc_min[]"></div>' +
  699. '<div class ="form-group col-md-2">' +
  700. '<label for="max">Máximo </label>' +
  701. '<input class="form-control" type="number" id="assoc_max" min="1" max = "" value =" " name = "assoc_max[]"></div></div>' +
  702. '<div class ="form-group">' +
  703. '<label for ="descripcion">Descripción de evaluación</label>' +
  704. '<textarea class="form-control" rows="2" aria-labelledby="descripcion" name="assoc_scales[]" cols="50" ></textarea></div></div>';
  705. fullDiv += div;
  706. } else {
  707. var dataValue = parseInt($('#Assoc_Scales').attr('data-value'));
  708. $('#assoc_maximum_score').val(json.criteria[0].maximum_score);
  709. var maximum = json.criteria[0].maximum_score;
  710. $('#Assoc_Scales').html(' ');
  711. for (var i = 0; i < scaleLength; i++) {
  712. div = '<div id="assoc_eval' + i.toString() + '">' +
  713. '<div class ="form-row">' +
  714. '<label for="header' + (i).toString() + '">Evaluación ' + (i + 1).toString() + '</label><br><br>' +
  715. '<input type="hidden" id="header' + i.toString() + '">' +
  716. '<div class="form-group col-md-8" >' +
  717. '<label for="title' + i.toString() + '">Nombre de Evaluación ' + (i + 1).toString() + '</label>' +
  718. '<input class="form-control" name="assoc_title[]" value ="' + json.scales[i].title + '"type="text" id="title' + i.toString() + '" placeholder ="Nombre de evaluacion" ></div>' +
  719. '<div class ="form-group col-md-2">' +
  720. '<label for="min' + i.toString() + '">Mínimo </label>' +
  721. '<input class="form-control" type="number" id="assoc_min' + i.toString() + '" min="1" max = "' + maximum + '" value ="' + json.scales[i].min_score + '"oninput ="changedMin(' + "'assoc_min" + i.toString() + "', '" + i.toString() + "', 'Assoc_Scales' " + ')" name = "assoc_min[]"></div>' +
  722. '<div class ="form-group col-md-2">' +
  723. '<label for="max' + i.toString() + '">Máximo </label>' +
  724. '<input class="form-control" type="number" id="assoc_max' + i.toString() + '" min="1" max = "' + maximum + '" value ="' + json.scales[i].max_score + '"oninput ="changedMax(' + "'assoc_max" + i.toString() + "', '" + i.toString() + "', 'Assoc_Scales' " + ')" name = "assoc_max[]"></div></div>' +
  725. '<div class ="form-group">' +
  726. '<label for ="descripcion' + i.toString() + '">Descripción de evaluación</label>' +
  727. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="assoc_scales[]" cols="50" >' + json.scales[i].description + '</textarea></div></div>';
  728. fullDiv += div;
  729. }
  730. }
  731. addOptions('Num_assoc_scale', 'assoc_maximum_score');
  732. $('#Assoc_Scales').append(fullDiv);
  733. $('#Assoc_Scales').attr('data-value', scaleLength);
  734. $('#Num_assoc_scale').val(scaleLength);
  735. $('#Num_assoc_scale').selectpicker('refresh')
  736. },
  737. 'json'
  738. );
  739. }
  740. </script>
  741. @stop
  742. @section('javascript')
  743. // --------------------------------------------------------------------------
  744. // Page load
  745. // --------------------------------------------------------------------------
  746. // Hide accordion panel contents by default
  747. $('.panel-group .panel-body').hide();
  748. $('#outcome-display').parent().hide();
  749. fetchCriterionForEditing();
  750. fetchObjectiveForSelect('outcomeGroup', 'objectiveGroup');
  751. // setCriterionStatus();
  752. // --------------------------------------------------------------------------
  753. // Functions
  754. // --------------------------------------------------------------------------
  755. $('#button-add-outcome').on('click', function(e) {
  756. // Prevent the default action of the clicked item. In this case that is submit
  757. e.preventDefault();
  758. return false;
  759. });
  760. $('.filterButton').on('click', function(e) {
  761. // Prevent the default action of the clicked item. In this case that is submit
  762. e.preventDefault();
  763. return false;
  764. });
  765. $('#button-add-objective-assoc').on('click', function(e) {
  766. // Prevent the default action of the clicked item. In this case that is submit
  767. e.preventDefault();
  768. return false;
  769. });
  770. $('#button-add-outcome-assoc').on('click', function(e) {
  771. // Prevent the default action of the clicked item. In this case that is submit
  772. e.preventDefault();
  773. return false;
  774. });
  775. $('#button-add-objective').on('click', function(e) {
  776. // Prevent the default action of the clicked item. In this case that is submit
  777. e.preventDefault();
  778. return false;
  779. });
  780. // Fetch criterion info for editing
  781. // --------------------------------------------------------------------------
  782. // Events
  783. // --------------------------------------------------------------------------
  784. // When panel heading is clicked, toggle it
  785. $('.panel-group .panel-heading').on('click', function()
  786. {
  787. $(this).next().stop().slideToggle();
  788. })
  789. $('#outcome[0]').on('change', function(){
  790. $('.selectpicker').selectpicker('refresh');
  791. })
  792. // When list item is clicked, load corresponding info
  793. // When list item is clicked, load corresponding info
  794. $('.selectpicker').on('change', function()
  795. {
  796. //alert($(this).find(':selected').val());
  797. $('.selectpicker').selectpicker('refresh');
  798. });
  799. @stop