Nav apraksta

criteria.blade.php 40KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. @extends('layouts.master')
  2. @section('navigation')
  3. @include('local.managers.admins._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. {{ Form::submit('Update', array('class' => 'btn btn-primary btn-block')) }}
  185. {{ Form::close() }}
  186. {{ Form::open(array('action' => 'CriteriaController@delete')) }}
  187. <input type='hidden' name='criterion_delete' id='deleteCriteria'>
  188. {{Form::submit("Delete", array('class'=> 'btn btn-primary btn-block', 'id'=>"DeleteButton"))}}
  189. </div>
  190. </div>
  191. </div>
  192. </div>
  193. <script>
  194. var selectOptions = document.getElementById('outcome0').innerHTML;
  195. var counter = 1;
  196. var counterObj = 1;
  197. var outcomeString = 'OutcomeGroup_';
  198. $(document).ready(function() {
  199. addOptions('Num_scale', 'maximum_score', 'Scales');
  200. numberOfScales('Num_scale', 'Scales');
  201. });
  202. function numberOfAssoc(string, Scales) {
  203. var maximum = $('#assoc_maximum_score').val();
  204. var amountOfScale = parseInt($('#' + string).val());
  205. var dataValue = parseInt($('#' + Scales).attr('data-value'));
  206. //add
  207. if (dataValue < amountOfScale) {
  208. fullDiv = '';
  209. for (var i = dataValue; i < amountOfScale; i++) {
  210. div = '<div id="assoc_eval' + i.toString() + Scales + '">' +
  211. '<div class ="form-row">' +
  212. '<label for="header' + (i).toString() + '">Evaluación ' + (i + 1).toString() + '</label><br><br>' +
  213. '<input type="hidden" id="header' + i.toString() + '">' +
  214. '<div class="form-group col-md-8" >' +
  215. '<label for="title' + i.toString() + '">Nombre de Evaluación ' + (i + 1).toString() + '</label>' +
  216. '<input class="form-control" name="assoc_title[]" type="text" id="title' + i.toString() + '" placeholder ="Nombre de evaluacion" ></div>' +
  217. '<div class ="form-group col-md-2">' +
  218. '<label for="min' + i.toString() + '">Mínimo </label>' +
  219. '<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>' +
  220. '<div class ="form-group col-md-2">' +
  221. '<label for="max' + i.toString() + '">Máximo </label>' +
  222. '<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>' +
  223. '<div class ="form-group">' +
  224. '<label for ="descripcion' + i.toString() + '">Descripción de evaluación</label>' +
  225. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="assoc_scales[]" cols="50" ></textarea></div></div>';
  226. fullDiv += div;
  227. }
  228. $('#' + Scales).append(fullDiv);
  229. $('#' + Scales).attr('data-value', amountOfScale);
  230. } else {
  231. for (var i = dataValue; i > amountOfScale; i--) {
  232. $('#assoc_eval' + (i - 1).toString()).remove();
  233. }
  234. }
  235. $('#' + Scales).attr('data-value', amountOfScale);
  236. }
  237. function addOptions(select, max, scaleDiv) {
  238. var maxscore = parseInt($('#' + max).val())
  239. options = '';
  240. for (var i = 1; i <= maxscore; i++) {
  241. options += '<option value="' + i.toString() + '">' + i.toString() + '</option>';
  242. }
  243. var previousvalue = parseInt($('#' + select).val());
  244. $('#' + select).html(options);
  245. $('#' + select).val(previousvalue);
  246. $('#' + select).selectpicker('refresh');
  247. var attribute = parseInt($('#' + scaleDiv).attr('data-value'));
  248. for (var i = 0; i < attribute; i++) {
  249. $('#max' + i.toString()).attr('max', maxscore);
  250. $('#min' + i.toString()).attr('max', maxscore);
  251. }
  252. }
  253. function numberOfScales(string, Scales) {
  254. var maximum = $('#maximum_score').val();
  255. var amountOfScale = parseInt($('#' + string).val());
  256. var dataValue = parseInt($('#' + Scales).attr('data-value'));
  257. //add
  258. if (dataValue < amountOfScale) {
  259. fullDiv = '';
  260. for (var i = dataValue; i < amountOfScale; i++) {
  261. div = '<div id="eval' + i.toString() + Scales + '">' +
  262. '<div class ="form-row">' +
  263. '<label for="header' + (i).toString() + '">Evaluación ' + (i + 1).toString() + '</label><br><br>' +
  264. '<input type="hidden" id="header' + i.toString() + '">' +
  265. '<div class="form-group col-md-8" >' +
  266. '<label for="title' + i.toString() + '">Nombre de Evaluación ' + (i + 1).toString() + '</label>' +
  267. '<input class="form-control" name="title[]" type="text" id="title' + i.toString() + '" placeholder ="Nombre de evaluacion" ></div>' +
  268. '<div class ="form-group col-md-2">' +
  269. '<label for="min' + i.toString() + '">Mínimo </label>' +
  270. '<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>' +
  271. '<div class ="form-group col-md-2">' +
  272. '<label for="max' + i.toString() + '">Máximo </label>' +
  273. '<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>' +
  274. '<div class ="form-group">' +
  275. '<label for ="descripcion' + i.toString() + '">Descripción de evaluación</label>' +
  276. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="' + Scales + '[]" cols="50" ></textarea></div></div>';
  277. fullDiv += div;
  278. }
  279. $('#' + Scales).append(fullDiv);
  280. } else {
  281. for (var i = dataValue; i > amountOfScale; i--) {
  282. $('#eval' + (i - 1).toString() + Scales).remove();
  283. }
  284. }
  285. $('#' + Scales).attr('data-value', amountOfScale);
  286. }
  287. function changedMin(min, index, scaleDiv) {
  288. var maximum = parseInt($('#' + min).val()) + 1;
  289. var maxScaleScore = parseInt($('#' + scaleDiv).attr('data-value'));
  290. for (var i = parseInt(index); i < maxScaleScore; i++) {
  291. $('#max' + i).attr('min', maximum);
  292. }
  293. }
  294. function changedMax(max, index, scaleDiv) {
  295. var maximum = parseInt($('#' + max).val()) + 1;
  296. var maxScaleScore = parseInt($('#' + scaleDiv).attr('data-value'));
  297. for (var i = parseInt(index) + 1; i < maxScaleScore; i++) {
  298. $('#min' + i).attr('min', maximum)
  299. }
  300. }
  301. //Add outcome Button
  302. function addOutcomeTest() {
  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("outcome' + counter.toString() + '")'
  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() + '", "' + outcomeString + (counter).toString() + '", "close' + counter.toString() + '","objective_")'
  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. fetchObjectiveForSelect('outcome' + counter.toString());
  329. counter += 1;
  330. $divForButton.appendTo('#outcomeGroup');
  331. $('#counterOutcome').val(counter)
  332. }
  333. //Delete Outcome and OptGroup associated
  334. function deleteLast(outcomeForm, outcomeOptGroup, closeButton, objective) {
  335. $div = document.getElementById(outcomeForm);
  336. $div.remove();
  337. $div = document.getElementById(outcomeOptGroup);
  338. $div.remove();
  339. $div = document.getElementById(closeButton)
  340. $div.remove();
  341. for (var i = 0; i < counterObj; i++) {
  342. $('#' + objective + i.toString()).selectpicker('refresh');
  343. }
  344. }
  345. //Delete Objective
  346. function deleteObjective(objectiveForm, closeObj) {
  347. $div = document.getElementById(objectiveForm);
  348. $div.remove();
  349. $div = document.getElementById(closeObj);
  350. $div.remove();
  351. }
  352. //Add objective when editing
  353. function addAssocObjective() {
  354. selectObj = document.getElementById('assoc_objective_0').innerHTML;
  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() + '")'
  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. counterObj += 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. var $select = $('<select/>', {
  386. 'class': "selectpicker form-control",
  387. 'name': "objective[]",
  388. 'data-live-search': 'true',
  389. 'id': 'objective_' + counterObj.toString()
  390. });
  391. var $div = $('<div/>', {
  392. 'id': 'objectiveForm' + counterObj.toString(),
  393. 'class': 'form-group col-md-11'
  394. });
  395. var $divForButton = $('<div/>', {
  396. 'class': 'col-md-1',
  397. 'id': 'closeObj' + counterObj.toString()
  398. });
  399. var $button = $('<button/>', {
  400. 'type': 'button',
  401. 'class': 'btn btn-primary',
  402. 'onclick': 'deleteObjective("objectiveForm' + counterObj.toString() + '", "closeObj' + counterObj.toString() + '")'
  403. });
  404. $button.append('X');
  405. $divForButton.append($button);
  406. $div.appendTo('#objectiveGroup')
  407. $select.append(selectObj);
  408. $select.appendTo('#objectiveForm' + counterObj.toString()).selectpicker('refresh');
  409. counterObj += 1;
  410. $divForButton.appendTo('#objectiveGroup');
  411. $('#counterObjective').val(counterObj)
  412. }
  413. //Create outcome for editing
  414. var assocOutcomeCounter = 0;
  415. function addAssocOutcome() {
  416. var $select = $('<select/>', {
  417. 'class': "selectpicker form-control",
  418. 'name': "assoc_outcome[]",
  419. 'data-live-search': 'true',
  420. 'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
  421. 'onchange': 'fetchAssocObjective("assoc_outcome_' + assocOutcomeCounter.toString() + '")'
  422. });
  423. var $div = $('<div/>', {
  424. 'id': 'assoc_outcomeForm' + assocOutcomeCounter.toString(),
  425. 'class': 'form-group col-md-11'
  426. });
  427. var $divForButton = $('<div/>', {
  428. 'class': 'col-md-1',
  429. 'id': 'assoc_close' + assocOutcomeCounter.toString()
  430. });
  431. var $button = $('<button/>', {
  432. 'type': 'button',
  433. 'class': 'btn btn-primary',
  434. 'onclick': 'deleteLast("assoc_outcomeForm' + assocOutcomeCounter.toString() + '", "' + 'Associated_Outcome' + (assocOutcomeCounter).toString() + '", "assoc_close' + assocOutcomeCounter.toString() + '","assoc_objective_")'
  435. });
  436. $button.append('X');
  437. $divForButton.append($button);
  438. $div.appendTo('#assocOutcomeGroup')
  439. $select.append(selectOptions);
  440. $select.appendTo('#assoc_outcomeForm' + assocOutcomeCounter.toString()).selectpicker('refresh');
  441. //fetchAssocObjective('assoc_outcome_' + assocOutcomeCounter.toString());
  442. assocOutcomeCounter += 1;
  443. $divForButton.appendTo('#assocOutcomeGroup');
  444. }
  445. //Fetch associated objective for editing
  446. var assocObjectiveCounter = 1;
  447. function fetchAssocObjective(outcomeId) {
  448. var id = $('#' + outcomeId).find(':selected').val();
  449. $.post(
  450. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  451. id: id
  452. },
  453. function(json) {
  454. var optionName = '<optgroup id="' + 'Associated_Outcome' + (assocOutcomeCounter - 1).toString() + '"label="' + 'Associated Outcome' + (assocOutcomeCounter).toString() + '"';
  455. for (var i = 0; i < json.length; i++) {
  456. var option = '<option value ="' + json[i].id.toString() + '">' + json[i].text + '</option>'
  457. optionName += (option)
  458. }
  459. optGroup = document.getElementById('Associated_Outcome' + (assocOutcomeCounter - 1).toString());
  460. if (optGroup != null) {
  461. optGroup.remove()
  462. }
  463. $('#assoc_objective_0').append(optionName);
  464. $('#assoc_objective_0').selectpicker('refresh');
  465. for (var i = assocObjectiveCounter - 1; i > 0; i--) {
  466. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString())
  467. }
  468. assocObjectiveCounter = 1;
  469. },
  470. 'json'
  471. );
  472. }
  473. //Fetch objective at creating criteria
  474. counterForPost = 0;
  475. function fetchObjectiveForSelect(outcomeInput) {
  476. var id = $('#' + outcomeInput).find(':selected').val();
  477. $.post(
  478. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  479. id: id
  480. },
  481. function(varArray) {
  482. var optionName = '<optgroup id="' + outcomeString + (counter - 1).toString() + '"label="' + varArray[0].name + '"';
  483. for (var i = 0; i < varArray.length; i++) {
  484. var option = '<option value ="' + varArray[i].id.toString() + '">' + varArray[i].text + '</option>'
  485. optionName += (option)
  486. }
  487. optGroup = document.getElementById(outcomeString + (counter - 1).toString());
  488. if (optGroup != null) {
  489. optGroup.remove()
  490. }
  491. $('#objective_0').append(optionName);
  492. $('#objective_0').selectpicker('refresh');
  493. for (var i = counterObj - 1; i > 0; i--) {
  494. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString())
  495. }
  496. counterObj = 1;
  497. },
  498. 'json'
  499. );
  500. }
  501. //after post
  502. fetchAllCriterion("select-program", "assoc_outcomes_fetch");
  503. //For editing criterion
  504. function fetchAllCriterion(program, outcome) {
  505. var program_id_fetch = $('#' + program).find(':selected').val();
  506. var outcome_fetch = $('#' + outcome).find(':selected').val();
  507. $.post(
  508. "{{URL::action('CriteriaController@fetchAllCriterion')}}", {
  509. program_fetch: program_id_fetch,
  510. outcome_fetch: outcome_fetch
  511. },
  512. function(json) {
  513. json_length = (json.criterion.length);
  514. fullHTML = '';
  515. for (var i = 0; i < json_length; i++) {
  516. fullHTML += '<option value="' + json.criterion[i].id + '">' + json.criterion[i].name + '</option>';
  517. }
  518. $('#select-criterion').html(fullHTML);
  519. $('#select-criterion').selectpicker('refresh');
  520. fetchCriterionForEditing()
  521. },
  522. 'json'
  523. );
  524. }
  525. function deleteCriterion() {
  526. var id = $('#select-criterion').find(':selected').val()
  527. $.post(
  528. "{{ URL::action('CriteriaController@delete')}}", {
  529. id: id
  530. },
  531. function() {
  532. window.location.reload(true)
  533. }
  534. )
  535. }
  536. function fetchCriterionForEditing() {
  537. var id = $('#select-criterion').find(':selected').val();
  538. $.post(
  539. "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
  540. id: id
  541. },
  542. function(json) {
  543. if (!(json.activity_criterion.length)) {
  544. $('#DeleteButton').prop('enabled', true);
  545. } else {
  546. $('#DeleteButton').prop('disabled', true);
  547. }
  548. if (!(json.criteria.length)) {
  549. name = ' ';
  550. var subcriteria = '';
  551. copyright = null;
  552. notes = null;
  553. $('#status').val(0);
  554. maximum = 1;
  555. $('#assoc_maximum_score').val(1);
  556. } else {
  557. var name = json.criteria[0].name;
  558. if (json.criteria[0].subcriteria) {
  559. subcriteria = JSON.parse(json.criteria[0].subcriteria).join('\n');
  560. }
  561. var copyright = json.criteria[0].copyright;
  562. var notes = json.criteria[0].notes;
  563. // Display info
  564. $('#criterion_name').val(name);
  565. $('#criterion_subcriteria').text(subcriteria);
  566. if (json.criteria[0].deleted_at)
  567. $('#status').val(0);
  568. else
  569. $('#status').val(1);
  570. $('#assoc_maximum_score').val(json.criteria[0].maximum_score);
  571. var maximum = json.criteria[0].maximum_score;
  572. // If copyright or notes aren't empty, load them
  573. }
  574. if (copyright) {
  575. $('#criterion_copyright').text(copyright);
  576. } else {
  577. $('#criterion_copyright').text('');
  578. }
  579. if (notes) {
  580. $('#criterion_notes').text(notes);
  581. } else {
  582. $('#criterion_notes').text('');
  583. }
  584. // Select associated outcome
  585. try {
  586. for (var i = assocOutcomeCounter - 1; i > 0; i--) {
  587. deleteLast("assoc_outcomeForm" + (i).toString(), 'Associated_Outcome' + (i).toString(), "assoc_close" + (i).toString(), "assoc_objective_");
  588. }
  589. } catch (err) {
  590. var Notran = true;
  591. }
  592. if (json.outcomes.length) {
  593. $('#assoc_outcome_0').val(json.outcomes[0].id);
  594. $('#assoc_outcome_0').selectpicker('refresh');
  595. } else {
  596. $('#assoc_outcome_0').val($('#assoc_outcomes_fetch').find(':selected').val());
  597. $('#assoc_outcome_0').selectpicker('refresh');
  598. }
  599. for (var i = 1; i < json.outcomes.length; i++) {
  600. addAssocOutcome();
  601. $('#assoc_outcome_' + i.toString()).val(json.outcomes[i].id);
  602. $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
  603. }
  604. try {
  605. for (var i = counterObj - 1; i > 0; i--) {
  606. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString())
  607. }
  608. } catch (err) {
  609. var noEntro = true;
  610. }
  611. counterObj = 1;
  612. assocOutcomeCounter = 0;
  613. var i = 0;
  614. for (var j = 0; j < json.outcomes.length; j++) {
  615. assocOutcomeCounter += 1;
  616. var optionName = '<optgroup id="' + 'Associated_Outcome' + (assocOutcomeCounter - 1).toString() + '"label="' + json.outcomes[j].name + '"';
  617. for (; i < json.objectives_outcome.length; i++) {
  618. if (json.objectives_outcome[i].outcome_id != json.outcomes[j].id) break;
  619. var option = '<option value ="' + json.objectives_outcome[i].id.toString() + '">' + json.objectives_outcome[i].text + '</option>'
  620. optionName += (option)
  621. }
  622. optGroup = document.getElementById('Associated_Outcome' + (assocOutcomeCounter - 1).toString());
  623. if (optGroup != null) {
  624. optGroup.remove()
  625. }
  626. $('#assoc_objective_0').append(optionName);
  627. $('#assoc_objective_0').selectpicker('refresh');
  628. }
  629. for (var i = assocObjectiveCounter - 1; i > 0; i--) {
  630. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString())
  631. }
  632. assocObjectiveCounter = 1;
  633. try {
  634. $('#assoc_objective_0').val(json.objectives[0].id);
  635. $('#assoc_objective_0').selectpicker('refresh');
  636. } catch (err) {
  637. if (!json.objectives.length) {
  638. $('#assoc_objective_0').val(0);
  639. $('#assoc_objective_0').selectpicker('refresh');
  640. }
  641. var thereIsNoObjective = true;
  642. }
  643. for (var i = 1; i < json.objectives.length; i++) {
  644. addAssocObjective();
  645. $('#assoc_objective_' + i.toString()).val(json.objectives[i].id);
  646. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  647. }
  648. assocObjectiveCounter = json.objectives.length;
  649. // Select associated program
  650. var program_length = json.program.length;
  651. $('input[type=checkbox]').prop('checked', false);
  652. for (var i = 0; i < program_length; i++) {
  653. $('#assoc_program_id_' + json.program[i].program_id).prop("checked", true);
  654. }
  655. // Select status
  656. scaleLength = json.scales.length;
  657. fullDiv = '';
  658. if (!scaleLength) {
  659. div = '<div id="assoc_eval 0"">' +
  660. '<div class ="form-row">' +
  661. '<label for="header0">Evaluación 1</label><br><br>' +
  662. '<input type="hidden" id="header0">' +
  663. '<div class="form-group col-md-8" >' +
  664. '<label for="title0">Nombre de Evaluación 1</label>' +
  665. '<input class="form-control" name="assoc_title[]" value =" "type="text" id="title0" placeholder ="Nombre de evaluacion" ></div>' +
  666. '<div class ="form-group col-md-2">' +
  667. '<label for="min0">Mínimo </label>' +
  668. '<input class="form-control" type="number" id="assoc_min0" min="1" max = "1" value =" " name = "assoc_min[]"></div>' +
  669. '<div class ="form-group col-md-2">' +
  670. '<label for="max">Máximo </label>' +
  671. '<input class="form-control" type="number" id="assoc_max" min="1" max = "" value =" " name = "assoc_max[]"></div></div>' +
  672. '<div class ="form-group">' +
  673. '<label for ="descripcion">Descripción de evaluación</label>' +
  674. '<textarea class="form-control" rows="2" aria-labelledby="descripcion" name="assoc_scales[]" cols="50" ></textarea></div></div>';
  675. fullDiv += div;
  676. } else {
  677. var dataValue = parseInt($('#Assoc_Scales').attr('data-value'));
  678. $('#assoc_maximum_score').val(json.criteria[0].maximum_score);
  679. var maximum = json.criteria[0].maximum_score;
  680. $('#Assoc_Scales').html(' ');
  681. for (var i = 0; i < scaleLength; i++) {
  682. div = '<div id="assoc_eval' + i.toString() + '">' +
  683. '<div class ="form-row">' +
  684. '<label for="header' + (i).toString() + '">Evaluación ' + (i + 1).toString() + '</label><br><br>' +
  685. '<input type="hidden" id="header' + i.toString() + '">' +
  686. '<div class="form-group col-md-8" >' +
  687. '<label for="title' + i.toString() + '">Nombre de Evaluación ' + (i + 1).toString() + '</label>' +
  688. '<input class="form-control" name="assoc_title[]" value ="' + json.scales[i].title + '"type="text" id="title' + i.toString() + '" placeholder ="Nombre de evaluacion" ></div>' +
  689. '<div class ="form-group col-md-2">' +
  690. '<label for="min' + i.toString() + '">Mínimo </label>' +
  691. '<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>' +
  692. '<div class ="form-group col-md-2">' +
  693. '<label for="max' + i.toString() + '">Máximo </label>' +
  694. '<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>' +
  695. '<div class ="form-group">' +
  696. '<label for ="descripcion' + i.toString() + '">Descripción de evaluación</label>' +
  697. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="assoc_scales[]" cols="50" >' + json.scales[i].description + '</textarea></div></div>';
  698. fullDiv += div;
  699. }
  700. }
  701. addOptions('Num_assoc_scale', 'assoc_maximum_score');
  702. $('#Assoc_Scales').append(fullDiv);
  703. $('#Assoc_Scales').attr('data-value', scaleLength);
  704. $('#Num_assoc_scale').val(scaleLength);
  705. $('#Num_assoc_scale').selectpicker('refresh')
  706. },
  707. 'json'
  708. );
  709. }
  710. </script>
  711. @stop
  712. @section('javascript')
  713. // --------------------------------------------------------------------------
  714. // Page load
  715. // --------------------------------------------------------------------------
  716. // Hide accordion panel contents by default
  717. $('.panel-group .panel-body').hide();
  718. $('#outcome-display').parent().hide();
  719. fetchCriterionForEditing();
  720. fetchObjectiveForSelect('outcome0');
  721. // setCriterionStatus();
  722. // --------------------------------------------------------------------------
  723. // Functions
  724. // --------------------------------------------------------------------------
  725. $('#button-add-outcome').on('click', function(e) {
  726. // Prevent the default action of the clicked item. In this case that is submit
  727. e.preventDefault();
  728. return false;
  729. });
  730. $('#button-add-objective-assoc').on('click', function(e) {
  731. // Prevent the default action of the clicked item. In this case that is submit
  732. e.preventDefault();
  733. return false;
  734. });
  735. $('#button-add-outcome-assoc').on('click', function(e) {
  736. // Prevent the default action of the clicked item. In this case that is submit
  737. e.preventDefault();
  738. return false;
  739. });
  740. $('#button-add-objective').on('click', function(e) {
  741. // Prevent the default action of the clicked item. In this case that is submit
  742. e.preventDefault();
  743. return false;
  744. });
  745. // Fetch criterion info for editing
  746. // --------------------------------------------------------------------------
  747. // Events
  748. // --------------------------------------------------------------------------
  749. // When panel heading is clicked, toggle it
  750. $('.panel-group .panel-heading').on('click', function()
  751. {
  752. $(this).next().stop().slideToggle();
  753. })
  754. $('#outcome[0]').on('change', function(){
  755. fetchObjectiveForSelect(0);
  756. $('.selectpicker').selectpicker('refresh');
  757. })
  758. // When list item is clicked, load corresponding info
  759. // When list item is clicked, load corresponding info
  760. $('.selectpicker').on('change', function()
  761. {
  762. //alert($(this).find(':selected').val());
  763. $('.selectpicker').selectpicker('refresh');
  764. });
  765. @stop