Без опису

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