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