No Description

criteria.blade.php 42KB

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