No Description

new_criteria.blade.php 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  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'>
  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'>
  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. counter = parseInt($('#outcomeGroup').data("value"));
  304. var $select = $('<select/>', {
  305. 'class': "selectpicker form-control",
  306. 'name': "outcome[]",
  307. 'data-live-search': 'true',
  308. 'id': 'outcome' + counter.toString(),
  309. 'onchange': 'fetchObjectiveForSelect("outcomeGroup", "objectiveGroup")'
  310. });
  311. var $div = $('<div/>', {
  312. 'id': 'outcomeForm' + counter.toString(),
  313. 'class': 'form-group col-md-11'
  314. });
  315. var $divForButton = $('<div/>', {
  316. 'class': 'col-md-1',
  317. 'id': 'close' + counter.toString()
  318. });
  319. var $button = $('<button/>', {
  320. 'type': 'button',
  321. 'class': 'btn btn-primary',
  322. 'onclick': 'deleteLast("outcomeForm", "outcomeGroup", "close' + counter.toString() + '", "objectiveGroup")'
  323. });
  324. $button.append('X');
  325. $divForButton.append($button);
  326. $div.appendTo('#outcomeGroup')
  327. $select.append(selectOptions);
  328. $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
  329. $('#outcomeGroup').data("value") = parseInt($('#outcomeGroup').data("value")) + 1;
  330. fetchObjectiveForSelect('outcomeGroup', "objectiveGroup");
  331. counter += 1;
  332. $divForButton.appendTo('#outcomeGroup');
  333. $('#counterOutcome').val(counter)
  334. }
  335. $('.filterSection').hide();
  336. //Delete Outcome and OptGroup associated
  337. function deleteLast(outcomeForm, outcomeDiv, closeButton, objectiveGroup) {
  338. $div = document.getElementById(outcomeForm + counter);
  339. $div.remove();
  340. $div = document.getElementById(closeButton);
  341. $div.remove();
  342. $('#' + outcomeDiv).data('value') = parseInt($('#' + outcomeDiv).data('value')) - 1;
  343. fetchObjectiveForSelect(outcomeDiv, objectiveGroup);
  344. for (var i = 0; i < counterObj; i++) {
  345. $('#' + objective + i.toString()).selectpicker('refresh');
  346. }
  347. }
  348. //Delete Objective
  349. function deleteObjective(objectiveForm, closeObj) {
  350. $div = document.getElementById(objectiveForm);
  351. $div.remove();
  352. $div = document.getElementById(closeObj);
  353. $div.remove();
  354. }
  355. //Add objective when editing
  356. function addAssocObjective() {
  357. selectObj = document.getElementById('assoc_objective_0').innerHTML;
  358. var $select = $('<select/>', {
  359. 'class': "selectpicker form-control",
  360. 'name': "assoc_objective[]",
  361. 'data-live-search': 'true',
  362. 'id': 'assoc_objective_' + assocObjectiveCounter.toString(),
  363. });
  364. var $div = $('<div/>', {
  365. 'id': 'assoc_objectiveForm' + assocObjectiveCounter.toString(),
  366. 'class': 'form-group col-md-11'
  367. });
  368. var $divForButton = $('<div/>', {
  369. 'class': 'col-md-1',
  370. 'id': 'assoc_closeObj' + assocObjectiveCounter.toString()
  371. });
  372. var $button = $('<button/>', {
  373. 'type': 'button',
  374. 'class': 'btn btn-primary',
  375. 'onclick': 'deleteObjective("assoc_objectiveForm' + assocObjectiveCounter.toString() + '", "assoc_closeObj' + assocObjectiveCounter.toString() + '")'
  376. });
  377. $button.append('X');
  378. $divForButton.append($button);
  379. $div.appendTo('#assoc_objectiveGroup')
  380. $select.append(selectObj);
  381. $select.appendTo('#assoc_objectiveForm' + assocObjectiveCounter.toString()).selectpicker('refresh');
  382. counterObj += 1;
  383. $divForButton.appendTo('#assoc_objectiveGroup');
  384. }
  385. //Add objective when creating a criteria
  386. function addObjectiveTest() {
  387. selectObj = document.getElementById('objective_0').innerHTML;
  388. var $select = $('<select/>', {
  389. 'class': "selectpicker form-control",
  390. 'name': "objective[]",
  391. 'data-live-search': 'true',
  392. 'id': 'objective_' + counterObj.toString()
  393. });
  394. var $div = $('<div/>', {
  395. 'id': 'objectiveForm' + counterObj.toString(),
  396. 'class': 'form-group col-md-11'
  397. });
  398. var $divForButton = $('<div/>', {
  399. 'class': 'col-md-1',
  400. 'id': 'closeObj' + counterObj.toString()
  401. });
  402. var $button = $('<button/>', {
  403. 'type': 'button',
  404. 'class': 'btn btn-primary',
  405. 'onclick': 'deleteObjective("objectiveForm' + counterObj.toString() + '", "closeObj' + counterObj.toString() + '")'
  406. });
  407. $button.append('X');
  408. $divForButton.append($button);
  409. $div.appendTo('#objectiveGroup')
  410. $select.append(selectObj);
  411. $select.appendTo('#objectiveForm' + counterObj.toString()).selectpicker('refresh');
  412. counterObj += 1;
  413. $divForButton.appendTo('#objectiveGroup');
  414. $('#counterObjective').val(counterObj)
  415. }
  416. //Create outcome for editing
  417. var assocOutcomeCounter = 0;
  418. function addAssocOutcome() {
  419. var $select = $('<select/>', {
  420. 'class': "selectpicker form-control",
  421. 'name': "assoc_outcome[]",
  422. 'data-live-search': 'true',
  423. 'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
  424. 'onchange': 'fetchAssocObjective("assoc_outcome_' + assocOutcomeCounter.toString() + '")'
  425. });
  426. var $div = $('<div/>', {
  427. 'id': 'assoc_outcomeForm' + assocOutcomeCounter.toString(),
  428. 'class': 'form-group col-md-11'
  429. });
  430. var $divForButton = $('<div/>', {
  431. 'class': 'col-md-1',
  432. 'id': 'assoc_close' + assocOutcomeCounter.toString()
  433. });
  434. var $button = $('<button/>', {
  435. 'type': 'button',
  436. 'class': 'btn btn-primary',
  437. 'onclick': 'deleteLast("assoc_outcomeForm' + assocOutcomeCounter.toString() + '", "' + 'Associated_Outcome' + (assocOutcomeCounter).toString() + '", "assoc_close' + assocOutcomeCounter.toString() + '","assoc_objective_")'
  438. });
  439. $button.append('X');
  440. $divForButton.append($button);
  441. $div.appendTo('#assocOutcomeGroup')
  442. $select.append(selectOptions);
  443. $select.appendTo('#assoc_outcomeForm' + assocOutcomeCounter.toString()).selectpicker('refresh');
  444. //fetchAssocObjective('assoc_outcome_' + assocOutcomeCounter.toString());
  445. assocOutcomeCounter += 1;
  446. $divForButton.appendTo('#assocOutcomeGroup');
  447. }
  448. //Fetch associated objective for editing
  449. var assocObjectiveCounter = 1;
  450. function fetchAssocObjective(outcomeId) {
  451. var id = $('#' + outcomeId).find(':selected').val();
  452. $.post(
  453. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  454. id: id
  455. },
  456. function(json) {
  457. var optionName = '<optgroup id="' + 'Associated_Outcome' + (assocOutcomeCounter - 1).toString() + '"label="' + 'Associated Outcome' + (assocOutcomeCounter).toString() + '"';
  458. for (var i = 0; i < json.length; i++) {
  459. var option = '<option value ="' + json[i].id.toString() + '">' + json[i].text + '</option>'
  460. optionName += (option)
  461. }
  462. optGroup = document.getElementById('Associated_Outcome' + (assocOutcomeCounter - 1).toString());
  463. if (optGroup != null) {
  464. optGroup.remove()
  465. }
  466. $('#assoc_objective_0').append(optionName);
  467. $('#assoc_objective_0').selectpicker('refresh');
  468. for (var i = assocObjectiveCounter - 1; i > 0; i--) {
  469. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString())
  470. }
  471. assocObjectiveCounter = 1;
  472. },
  473. 'json'
  474. );
  475. }
  476. //Fetch objective at creating criteria
  477. counterForPost = 0;
  478. function fetchObjectiveForSelect(outcomeDiv, objectiveGroup) {
  479. var count = $("#" + outcomeDiv).data('value');
  480. var allOutcomes = [];
  481. $("#" + outcomeDiv + ' select').each(function() {
  482. array_push(allOutcomes, this.find(':selected').val());
  483. })
  484. var allObjectives = [];
  485. $("#" + objectiveGroup + ' select').each(function() {
  486. var temp = {
  487. id: this.attr('id'),
  488. value: this.val()
  489. }
  490. array_push(allObjectives, temp);
  491. })
  492. $.post(
  493. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  494. allOutcomes: allOutcomes
  495. },
  496. function(varArray) {
  497. var optionName = '<optgroup label="' + varArray[0].name + '"';
  498. for (var i = 0; i < varArray.length; i++) {
  499. var option = '<option value ="' + varArray[i].id.toString() + '">' + varArray[i].text + '</option>';
  500. optionName += (option);
  501. }
  502. $('#objective_0').append(optionName);
  503. $('#objective_0').selectpicker('refresh');
  504. for (var i = counterObj - 1; i > 0; i--) {
  505. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString())
  506. }
  507. counterObj = 1;
  508. },
  509. 'json'
  510. );
  511. }
  512. //after post
  513. fetchAllCriterion("select-program", "assoc_outcomes_fetch");
  514. //For editing criterion
  515. function fetchAllCriterion(program, outcome) {
  516. var program_id_fetch = $('#' + program).find(':selected').val();
  517. var outcome_fetch = $('#' + outcome).find(':selected').val();
  518. $.post(
  519. "{{URL::action('CriteriaController@fetchAllCriterion')}}", {
  520. program_fetch: program_id_fetch,
  521. outcome_fetch: outcome_fetch
  522. },
  523. function(json) {
  524. json_length = (json.criterion.length);
  525. fullHTML = '';
  526. for (var i = 0; i < json_length; i++) {
  527. fullHTML += '<option value="' + json.criterion[i].id + '">' + json.criterion[i].name + '</option>';
  528. }
  529. $('#select-criterion').html(fullHTML);
  530. $('#select-criterion').selectpicker('refresh');
  531. fetchCriterionForEditing()
  532. },
  533. 'json'
  534. );
  535. }
  536. function deleteCriterion() {
  537. var id = $('#select-criterion').find(':selected').val()
  538. $.post(
  539. "{{ URL::action('CriteriaController@delete')}}", {
  540. id: id
  541. },
  542. function() {
  543. window.location.reload(true)
  544. }
  545. )
  546. }
  547. function fetchCriterionForEditing() {
  548. var id = $('#select-criterion').find(':selected').val();
  549. $.post(
  550. "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
  551. id: id
  552. },
  553. function(json) {
  554. if (!(json.activity_criterion.length)) {
  555. $('#DeleteButton').prop('disabled', true);
  556. } else {
  557. $('#DeleteButton').prop('enabled', true);
  558. }
  559. if (!(json.criteria.length)) {
  560. name = ' ';
  561. var subcriteria = '';
  562. copyright = null;
  563. notes = null;
  564. $('#status').val(0);
  565. maximum = 1;
  566. $('#assoc_maximum_score').val(1);
  567. } else {
  568. var name = json.criteria[0].name;
  569. if (json.criteria[0].subcriteria) {
  570. subcriteria = JSON.parse(json.criteria[0].subcriteria).join('\n');
  571. } else {
  572. subcriteria = "";
  573. }
  574. if (json.criteria[0].copyright) {
  575. var copyright = json.criteria[0].copyright;
  576. } else {
  577. var copyright = ''
  578. }
  579. if (json.criteria[0].notes) notes = json.criteria[0].notes;
  580. else notes = '';
  581. // Display info
  582. $('#criterion_name').val(name);
  583. $('#criterion_subcriteria').text(subcriteria);
  584. if (json.criteria[0].deleted_at)
  585. $('#status').val(0);
  586. else
  587. $('#status').val(1);
  588. $('#assoc_maximum_score').val(json.criteria[0].maximum_score);
  589. var maximum = json.criteria[0].maximum_score;
  590. // If copyright or notes aren't empty, load them
  591. }
  592. $('#criterion_copyright').text(copyright);
  593. $('#criterion_notes').text(notes);
  594. // Select associated outcome
  595. try {
  596. for (var i = assocOutcomeCounter - 1; i > 0; i--) {
  597. deleteLast("assoc_outcomeForm" + (i).toString(), 'Associated_Outcome' + (i).toString(), "assoc_close" + (i).toString(), "assoc_objective_");
  598. }
  599. } catch (err) {
  600. var Notran = true;
  601. }
  602. if (json.outcomes.length) {
  603. $('#assoc_outcome_0').val(json.outcomes[0].id);
  604. $('#assoc_outcome_0').selectpicker('refresh');
  605. } else {
  606. $('#assoc_outcome_0').val($('#assoc_outcomes_fetch').find(':selected').val());
  607. $('#assoc_outcome_0').selectpicker('refresh');
  608. }
  609. for (var i = 1; i < json.outcomes.length; i++) {
  610. addAssocOutcome();
  611. $('#assoc_outcome_' + i.toString()).val(json.outcomes[i].id);
  612. $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
  613. }
  614. try {
  615. for (var i = counterObj - 1; i > 0; i--) {
  616. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString())
  617. }
  618. } catch (err) {
  619. var noEntro = true;
  620. }
  621. counterObj = 1;
  622. assocOutcomeCounter = 0;
  623. var i = 0;
  624. for (var j = 0; j < json.outcomes.length; j++) {
  625. assocOutcomeCounter += 1;
  626. var optionName = '<optgroup id="' + 'Associated_Outcome' + (assocOutcomeCounter - 1).toString() + '"label="' + json.outcomes[j].name + '"';
  627. for (; i < json.objectives_outcome.length; i++) {
  628. if (json.objectives_outcome[i].outcome_id != json.outcomes[j].id) break;
  629. var option = '<option value ="' + json.objectives_outcome[i].id.toString() + '">' + json.objectives_outcome[i].text + '</option>'
  630. optionName += (option)
  631. }
  632. optGroup = document.getElementById('Associated_Outcome' + (assocOutcomeCounter - 1).toString());
  633. if (optGroup != null) {
  634. optGroup.remove()
  635. }
  636. $('#assoc_objective_0').append(optionName);
  637. $('#assoc_objective_0').selectpicker('refresh');
  638. }
  639. for (var i = assocObjectiveCounter - 1; i > 0; i--) {
  640. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString())
  641. }
  642. assocObjectiveCounter = 1;
  643. try {
  644. $('#assoc_objective_0').val(json.objectives[0].id);
  645. $('#assoc_objective_0').selectpicker('refresh');
  646. } catch (err) {
  647. if (!json.objectives.length) {
  648. $('#assoc_objective_0').val(0);
  649. $('#assoc_objective_0').selectpicker('refresh');
  650. }
  651. var thereIsNoObjective = true;
  652. }
  653. for (var i = 1; i < json.objectives.length; i++) {
  654. addAssocObjective();
  655. $('#assoc_objective_' + i.toString()).val(json.objectives[i].id);
  656. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  657. }
  658. assocObjectiveCounter = json.objectives.length;
  659. // Select associated program
  660. var program_length = json.program.length;
  661. $('input[type=checkbox]').prop('checked', false);
  662. for (var i = 0; i < program_length; i++) {
  663. $('#assoc_program_id_' + json.program[i].program_id).prop("checked", true);
  664. }
  665. // Select status
  666. scaleLength = json.scales.length;
  667. fullDiv = '';
  668. if (!scaleLength) {
  669. div = '<div id="assoc_eval 0"">' +
  670. '<div class ="form-row">' +
  671. '<label for="header0">Evaluación 1</label><br><br>' +
  672. '<input type="hidden" id="header0">' +
  673. '<div class="form-group col-md-8" >' +
  674. '<label for="title0">Nombre de Evaluación 1</label>' +
  675. '<input class="form-control" name="assoc_title[]" value =" "type="text" id="title0" placeholder ="Nombre de evaluacion" ></div>' +
  676. '<div class ="form-group col-md-2">' +
  677. '<label for="min0">Mínimo </label>' +
  678. '<input class="form-control" type="number" id="assoc_min0" min="1" max = "1" value =" " name = "assoc_min[]"></div>' +
  679. '<div class ="form-group col-md-2">' +
  680. '<label for="max">Máximo </label>' +
  681. '<input class="form-control" type="number" id="assoc_max" min="1" max = "" value =" " name = "assoc_max[]"></div></div>' +
  682. '<div class ="form-group">' +
  683. '<label for ="descripcion">Descripción de evaluación</label>' +
  684. '<textarea class="form-control" rows="2" aria-labelledby="descripcion" name="assoc_scales[]" cols="50" ></textarea></div></div>';
  685. fullDiv += div;
  686. } else {
  687. var dataValue = parseInt($('#Assoc_Scales').attr('data-value'));
  688. $('#assoc_maximum_score').val(json.criteria[0].maximum_score);
  689. var maximum = json.criteria[0].maximum_score;
  690. $('#Assoc_Scales').html(' ');
  691. for (var i = 0; i < scaleLength; i++) {
  692. div = '<div id="assoc_eval' + i.toString() + '">' +
  693. '<div class ="form-row">' +
  694. '<label for="header' + (i).toString() + '">Evaluación ' + (i + 1).toString() + '</label><br><br>' +
  695. '<input type="hidden" id="header' + i.toString() + '">' +
  696. '<div class="form-group col-md-8" >' +
  697. '<label for="title' + i.toString() + '">Nombre de Evaluación ' + (i + 1).toString() + '</label>' +
  698. '<input class="form-control" name="assoc_title[]" value ="' + json.scales[i].title + '"type="text" id="title' + i.toString() + '" placeholder ="Nombre de evaluacion" ></div>' +
  699. '<div class ="form-group col-md-2">' +
  700. '<label for="min' + i.toString() + '">Mínimo </label>' +
  701. '<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>' +
  702. '<div class ="form-group col-md-2">' +
  703. '<label for="max' + i.toString() + '">Máximo </label>' +
  704. '<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>' +
  705. '<div class ="form-group">' +
  706. '<label for ="descripcion' + i.toString() + '">Descripción de evaluación</label>' +
  707. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="assoc_scales[]" cols="50" >' + json.scales[i].description + '</textarea></div></div>';
  708. fullDiv += div;
  709. }
  710. }
  711. addOptions('Num_assoc_scale', 'assoc_maximum_score');
  712. $('#Assoc_Scales').append(fullDiv);
  713. $('#Assoc_Scales').attr('data-value', scaleLength);
  714. $('#Num_assoc_scale').val(scaleLength);
  715. $('#Num_assoc_scale').selectpicker('refresh')
  716. },
  717. 'json'
  718. );
  719. }
  720. </script>
  721. @stop
  722. @section('javascript')
  723. // --------------------------------------------------------------------------
  724. // Page load
  725. // --------------------------------------------------------------------------
  726. // Hide accordion panel contents by default
  727. $('.panel-group .panel-body').hide();
  728. $('#outcome-display').parent().hide();
  729. fetchCriterionForEditing();
  730. fetchObjectiveForSelect('outcomeGroup', 'objectiveGroup');
  731. // setCriterionStatus();
  732. // --------------------------------------------------------------------------
  733. // Functions
  734. // --------------------------------------------------------------------------
  735. $('#button-add-outcome').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-assoc').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. $('#button-add-outcome-assoc').on('click', function(e) {
  746. // Prevent the default action of the clicked item. In this case that is submit
  747. e.preventDefault();
  748. return false;
  749. });
  750. $('#button-add-objective').on('click', function(e) {
  751. // Prevent the default action of the clicked item. In this case that is submit
  752. e.preventDefault();
  753. return false;
  754. });
  755. // Fetch criterion info for editing
  756. // --------------------------------------------------------------------------
  757. // Events
  758. // --------------------------------------------------------------------------
  759. // When panel heading is clicked, toggle it
  760. $('.panel-group .panel-heading').on('click', function()
  761. {
  762. $(this).next().stop().slideToggle();
  763. })
  764. //$('#outcome[0]').on('change', function(){
  765. //fetchObjectiveForSelect(0);
  766. //$('.selectpicker').selectpicker('refresh');
  767. //})
  768. // When list item is clicked, load corresponding info
  769. // When list item is clicked, load corresponding info
  770. $('.selectpicker').on('change', function()
  771. {
  772. //alert($(this).find(':selected').val());
  773. $('.selectpicker').selectpicker('refresh');
  774. });
  775. @stop