Нет описания

criteria.blade.php 40KB

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