No Description

criteria.blade.php 48KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. @extends('layouts.master')
  2. @section('navigation')
  3. @include('local.managers.pCoords._navigation')
  4. @stop
  5. @section('main')
  6. <div class="row">
  7. <div id = "alert_placeholder">
  8. </div>
  9. <div class="col-md-6">
  10. <!-- Form to add a new criterion -->
  11. <div class="panel panel-default panel-button">
  12. <div class="panel-heading">
  13. Create
  14. </div>
  15. <div class="panel-body">
  16. {{ Form::open(array('action' => 'CriteriaController@create', 'id'=> 'create_criterion')) }}
  17. <div id='allOutcomes'>
  18. <div id='outcomeGroup0' data-value="1">
  19. <div class="form-group col-md-12">
  20. <label>Outcome 1</label>
  21. {{ Form::select('outcome[]', $outcomes, reset($outcomes), ['class'=>'form-control selectpicker', 'id' =>'outcome0', 'onchange'=>'fetchObjectiveForSelect("outcome0", "objectiveGroupFor0")']) }}
  22. </div>
  23. <div id='objectiveGroupFor0' data-value='1'>
  24. <div class="form-group col-md-11">
  25. <label>Associated Objectives for Outcome 1</label>
  26. <select id="objective_0_counter_1" name="objective[]" class="form-control selectpicker">
  27. </select>
  28. </div>
  29. <div class="col-md-1">
  30. </div>
  31. </div>
  32. <input type='hidden' name='counterObjective' id='counterObjective' value=1>
  33. <button class='btn btn-md btn-secondary button-add-objective' onclick='addObjectiveTest("objectiveGroupFor0", "objective_0")'>
  34. <span class='glyphicon glyphicon-plus'>
  35. </span>
  36. Add another Objective
  37. </button>
  38. <br>
  39. </div>
  40. <hr>
  41. </div>
  42. <input type='hidden' name='counterOutcome' id='counterOutcome' value=1>
  43. <button id='button-add-outcome' class='btn btn-md btn-secondary' onclick='addOutcomeTest()'>
  44. <span class='glyphicon glyphicon-plus'>
  45. </span>
  46. Add another Outcome
  47. </button>
  48. <!-- Associated Program -->
  49. <div class="form-group">
  50. {{ Form::label('program_id', 'Associated Program') }}<br>
  51. <br>
  52. <input type="hidden" id="{{ $programs[0]->name }}" name="program_id[]" value="{{$programs[0]->id}}">
  53. <input type="checkbox" id="{{ $programs[0]->name }}" name="program_id[]" value="{{$programs[0]->id}}" disabled checked>
  54. <label for="{{ $programs[0]->name }}"> {{ $programs[0]->name }} [{{ $programs[0]->school->name }}]</label><br>
  55. </div>
  56. <div class="form-group">
  57. {{ Form::label('name', 'Name') }}
  58. {{ Form::text('name', '', array('class' => 'form-control')) }}
  59. </div>
  60. <div class="form-group">
  61. {{ Form::label('subcriteria', 'Subcriteria') }}
  62. <p class="help-block"><strong>Manually add</strong> bullets or numbering.</p>
  63. {{ Form::textarea('subcriteria', '', array('class' => 'form-control', 'rows'=>3, 'aria-labelledby'=>'subcriteria')) }}
  64. </div>
  65. <div class="form-group">
  66. {{ Form::label('maximum_score', 'Maximum Score') }}
  67. {{ Form::text('maximum_score', '1', array('class' => 'form-control', 'id'=>'maximum_score', 'oninput'=>'addOptions("Num_scale", "maximum_score", "Scales")')) }}
  68. </div>
  69. <div class="form-group">
  70. {{ Form::label('scales', 'Number of Scales') }}
  71. <select id="Num_scale" name="scales" class="form-control selectpicker" onchange='numberOfScales("Num_scale", "Scales")'>
  72. </select>
  73. </div>
  74. <div id='Scales' data-value="0">
  75. </div>
  76. <div class="form-group">
  77. {{ Form::label('copyright', 'Copyright') }}
  78. {{ Form::textarea('copyright', '', array('class' => 'form-control', 'rows'=>2, 'placeholder'=>'(optional)', 'aria-labelledby'=>'copyright')) }}
  79. </div>
  80. <div class="form-group">
  81. {{ Form::label('notes', 'Notes') }}
  82. {{ Form::textarea('notes', '', array('class' => 'form-control', 'rows'=>2, 'placeholder'=>'(optional)', 'aria-labelledby'=>'notes')) }}
  83. </div>
  84. {{ Form::submit('Create', array('class' => 'btn btn-primary btn-block', 'id'=>'create_the_criterion')) }}
  85. {{ Form::close() }}
  86. </div>
  87. </div>
  88. </div>
  89. <div class="col-md-6">
  90. <div class="panel panel-default panel-button">
  91. <div class="panel-heading">
  92. Edit
  93. </div>
  94. <div class="panel-body">
  95. {{ Form::open(array('action' => 'CriteriaController@update', 'id'=>'update_criterion')) }}
  96. <button class="btn btn-md btn-secondary filterButton">
  97. <span class="glyphicon glyphicon-plus">
  98. </span>
  99. Filters
  100. </button>
  101. <div class="filterSection">
  102. <div class="form-group">
  103. {{ Form::label('program_id2', 'Associated Program')}}
  104. <select id='select-program' class="form-control selectpicker" onchange='fetchAllCriterion("select-program", "assoc_outcomes_fetch")'>
  105. <option value='{{$programs[0]->id}}' data-subtext="{{$programs[0]->code}}">{{$programs[0]->name}}</option>
  106. </select>
  107. </div>
  108. <div class="form-group">
  109. <label>Associated Outcome</label>
  110. {{ Form::select('assoc_outcome_fetch', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcomes_fetch', 'onchange'=>'fetchAllCriterion("select-program", "assoc_outcomes_fetch")']) }}
  111. </div>
  112. </div>
  113. <hr>
  114. <div class="form-group">
  115. {{ Form::label('criterion_id', 'Criterion') }}
  116. <select id="select-criterion" name="id" class="form-control selectpicker" onchange='fetchCriterionForEditing()'>
  117. @foreach ($criteria as $criterion)
  118. <option value="{{ $criterion->id }}" data-subtext="
  119. @if($criterion->program)
  120. &nbsp;&nbsp;&nbsp;[{{ $criterion->program->name }}]
  121. @endif
  122. ">
  123. {{ $criterion->name }}
  124. </option>
  125. @endforeach
  126. </select>
  127. </div>
  128. <div id='allAssocOutcomes'>
  129. <!-- Associated Outcome -->
  130. <div id='assocOutcomeGroup0' data-value="1">
  131. <div class="form-group col-md-12">
  132. <label>Outcome 1</label>
  133. {{ Form::select('outcome[]', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcome_0', 'onchange'=>'fetchAssocObjective("assoc_outcome_0")']) }}
  134. </div>
  135. <div id='assoc_objectiveGroupFor0' data-value="1">
  136. <div class="form-group col-md-11">
  137. <label>Associated Objectives for Outcome 1</label>
  138. <select id="assoc_objective_0_counter_1" name="objective[]" class="form-control selectpicker">
  139. <option value="0">No associated objectives</option>
  140. </select>
  141. </div>
  142. <div class='col-md-1'></div>
  143. </div>
  144. <button id='button-add-objective-assoc' class='btn btn-md btn-secondary' onclick='addAssocObjective("assoc_objectiveGroupFor0", "assoc_objective_0")'>
  145. <span class='glyphicon glyphicon-plus'>
  146. </span>
  147. Add another Objective
  148. </button>
  149. </div>
  150. <hr>
  151. </div>
  152. <button class='btn btn-md btn-secondary button-add-outcome-assoc' onclick='addAssocOutcome()'>
  153. <span class='glyphicon glyphicon-plus'>
  154. </span>
  155. Add another Outcome
  156. </button>
  157. <!-- Associated Program -->
  158. <div class="form-group">
  159. {{ Form::label('program_id2', 'Associated Program') }}<br><br>
  160. <input type="hidden" id="{{ $programs[0]->name }}" name="program_id[]" value="{{$programs[0]->id}}">
  161. <input type="checkbox" id="assoc_program_id_{{ $programs[0]->id }}" name="program_id[]" value="{{$programs[0]->id}}" disabled checked>
  162. <label for="assoc_program_id_{{ $programs[0]->id }}"> {{ $programs[0]->name }} <sub>[{{ $programs[0]->school->name }}]</sub></label><br>
  163. </div>
  164. <!-- Status -->
  165. <div class="form-group">
  166. {{ Form::label('status', 'Status') }}
  167. <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>
  168. <select id="status" name="status" class="form-control">
  169. <option value="1">Active</option>
  170. <option value="0">Inactive</option>
  171. </select>
  172. </div>
  173. <div class="form-group">
  174. {{ Form::label('name', 'Name') }}
  175. {{ Form::text('name', Input::old('name'), array('class' => 'form-control', 'id'=>'criterion_name')) }}
  176. </div>
  177. <div class="form-group">
  178. {{ Form::label('subcriteria', 'Subcriteria') }}
  179. <p class="help-block"><strong>Manually add</strong> bullets or numbering.</p>
  180. {{ Form::textarea('subcriteria', '', array('class' => 'form-control', 'rows'=>3, 'id' => 'criterion_subcriteria')) }}
  181. </div>
  182. <div class="form-group">
  183. {{ Form::label('maximum_score', 'Maximum Score') }}
  184. {{ Form::text('maximum_score', '', array('class' => 'form-control', 'id'=>'assoc_maximum_score', 'oninput'=>'addOptions("Num_assoc_scale", "assoc_maximum_score", "Assoc_Scales")')) }}
  185. </div>
  186. <div class="form-group">
  187. {{ Form::label('scales', 'Number of Scales') }}
  188. <select id="Num_assoc_scale" class="form-control selectpicker" onchange='numberOfAssoc("Num_assoc_scale", "Assoc_Scales")'>
  189. </select>
  190. </div>
  191. <div id='Assoc_Scales' data-value="0">
  192. </div>
  193. <div class="form-group">
  194. {{ Form::label('copyright', 'Copyright Information') }}
  195. {{ Form::textarea('copyright', Input::old('copyright'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_copyright', 'placeholder'=>'(optional)')) }}
  196. </div>
  197. <div class="form-group">
  198. {{ Form::label('notes', 'Additional Notes') }}
  199. {{ Form::textarea('notes', Input::old('notes'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_notes', 'placeholder'=>'(optional)')) }}
  200. </div>
  201. {{ Form::submit('Update', array('class' => 'btn btn-primary btn-block', 'id'=>'update_the_criterion')) }}
  202. {{ Form::close() }}
  203. {{ Form::open(array('action' => 'CriteriaController@delete')) }}
  204. <input type='hidden' name='criterion_delete' id='deleteCriteria'>
  205. {{Form::submit("Delete", array('class'=> 'btn btn-primary btn-block', 'id'=>"DeleteButton"))}}
  206. </div>
  207. </div>
  208. </div>
  209. </div>
  210. <script>
  211. var selectOptions = document.getElementById('outcome0').innerHTML;
  212. var counter = 1;
  213. var counterObj = 1;
  214. var outcomeString = 'OutcomeGroup_';
  215. $(document).ready(function() {
  216. addOptions('Num_scale', 'maximum_score', 'Scales');
  217. numberOfScales('Num_scale', 'Scales');
  218. });
  219. $(document).on('submit', '#create_criterion', function(e) {
  220. if (e.originalEvent.submitter.id != "create_the_criterion")
  221. e.preventDefault();
  222. })
  223. $(document).on('submit', '#update_criterion', function(e) {
  224. if (e.originalEvent.submitter.id != "update_the_criterion")
  225. e.preventDefault();
  226. })
  227. function addOptions(select, max, scaleDiv) {
  228. var maxscore = parseInt($('#' + max).val())
  229. options = '<option value = "1"> 1</option>';
  230. selectedValue = 1;
  231. valueBefore = 0;
  232. for (var i = 2; i <= 20; i++) {
  233. if (maxscore % i == 0) {
  234. options += '<option value="' + i.toString() + '">' + i.toString() + '</option>';
  235. }
  236. }
  237. var previousvalue = parseInt($('#' + select).val());
  238. $('#' + select).html(options);
  239. $('#' + select).val(previousvalue);
  240. $('#' + select).selectpicker('refresh');
  241. $('#' + select).trigger('change');
  242. }
  243. function numberOfAssoc(string, Scales) {
  244. var maximum = $('#assoc_maximum_score').val();
  245. var amountOfScale = parseInt($('#' + string).val());
  246. var dataValue = parseInt($('#' + Scales).attr('data-value'));
  247. var division = maximum / amountOfScale;
  248. //add
  249. fullDiv = '';
  250. if (division == 1) {
  251. for (var i = 0; i < amountOfScale; i++) {
  252. div = '<div id="assoc_eval' + i.toString() + Scales + '">' +
  253. '<div class ="form-group">' +
  254. '<label for ="assoc_descripcion' + i.toString() + '">Scale Description (' + (i + 1) + ')</label>' +
  255. '<textarea id = "assoc_scale_' + i + '" class="form-control" rows="2" aria-labelledby="assoc_descripcion' + i.toString() + '" name="Scales[]" cols="50" ></textarea></div></div>';
  256. fullDiv += div;
  257. }
  258. } else if (division == maximum) {
  259. div = '<div id="assoc_eval' + 0 + Scales + '">' +
  260. '<div class ="form-group">' +
  261. '<label for ="assoc_descripcion' + 0 + '">Scale Description (' + 1 + ' - ' + maximum + ') </label>' +
  262. '<textarea id = "assoc_scale_' + 0 + '" class="form-control" rows="2" aria-labelledby="assoc_descripcion' + 0 + '" name="Scales[]" cols="50" ></textarea></div></div>';
  263. fullDiv += div;
  264. } else {
  265. for (var i = 0; i < amountOfScale; i++) {
  266. div = '<div id="assoc_eval' + i.toString() + Scales + '">' +
  267. '<div class ="form-group">' +
  268. '<label for ="assoc_descripcion' + i.toString() + '">Scale Description (' + (1 + (i * division)) + ' - ' + ((1 + i) * division) + ')</label>' +
  269. '<textarea id = "assoc_scale_' + i + '" class="form-control" rows="2" aria-labelledby="assoc_descripcion' + i.toString() + '" name="Scales[]" cols="50" ></textarea></div></div>';
  270. fullDiv += div;
  271. }
  272. }
  273. $('#' + Scales).html(fullDiv);
  274. $('#' + Scales).attr('data-value', amountOfScale);
  275. }
  276. //add
  277. function numberOfScales(string, Scales) {
  278. var maximum = parseInt($('#maximum_score').val());
  279. var amountOfScale = parseInt($('#' + string).val());
  280. var dataValue = parseInt($('#' + Scales).attr('data-value'));
  281. var division = maximum / amountOfScale;
  282. //add
  283. fullDiv = '';
  284. if (division == 1) {
  285. for (var i = 0; i < amountOfScale; i++) {
  286. div = '<div id="eval' + i.toString() + Scales + '">' +
  287. '<div class ="form-group">' +
  288. '<label id = "label_for_des' + i.toString() + '" for ="descripcion' + i.toString() + '">Scale Description (' + (i + 1) + ')</label>' +
  289. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="' + Scales + '[]" cols="50" ></textarea></div></div>';
  290. fullDiv += div;
  291. }
  292. } else if (division == maximum) {
  293. div = '<div id="eval' + 0 + Scales + '">' +
  294. '<div class ="form-group">' +
  295. '<label id = "label_for_des' + 0 + '" for ="descripcion' + 0 + '">Scale Description (' + 1 + ' - ' + maximum + ')</label>' +
  296. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + 0 + '" name="' + Scales + '[]" cols="50" ></textarea></div></div>';
  297. fullDiv += div;
  298. } else {
  299. for (var i = 0; i < amountOfScale; i++) {
  300. div = '<div id="eval' + i.toString() + Scales + '">' +
  301. '<div class ="form-group">' +
  302. '<label id = "label_for_des' + i.toString() + '" for ="descripcion' + i.toString() + '">Scale Description (' + (1 + (i * division)) + ' - ' + ((1 + i) * division) + ')</label>' +
  303. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="' + Scales + '[]" cols="50" ></textarea></div></div>';
  304. fullDiv += div;
  305. }
  306. }
  307. $('#' + Scales).html(fullDiv);
  308. $('#' + Scales).attr('data-value', amountOfScale);
  309. }
  310. $('.filterSection').hide();
  311. $('.filterButton').on('click', function() {
  312. var span = $(this).find('span');
  313. if (span.attr('class') == 'glyphicon glyphicon-plus') {
  314. span.attr('class', 'glyphicon glyphicon-minus');
  315. } else {
  316. span.attr('class', 'glyphicon glyphicon-plus');
  317. }
  318. $('.filterSection').toggle(533);
  319. });
  320. //Add outcome Button
  321. function addOutcomeTest() {
  322. counter = parseInt($('#outcomeGroup0').data("value"));
  323. var $select = $('<select/>', {
  324. 'class': "selectpicker form-control",
  325. 'name': "outcome[]",
  326. 'data-live-search': 'true',
  327. 'id': 'outcome' + counter.toString(),
  328. 'onchange': 'fetchObjectiveForSelect("outcome' + counter + '", "objectiveGroupFor' + counter + '")'
  329. });
  330. var $div = $('<div/>', {
  331. 'id': 'outcomeForm' + counter.toString(),
  332. 'class': 'form-group col-md-11 '
  333. });
  334. var $divForButton = $('<div/>', {
  335. 'class': 'col-md-1',
  336. 'id': 'close' + counter.toString()
  337. });
  338. var $button = $('<button/>', {
  339. 'type': 'button',
  340. 'class': 'btn btn-primary',
  341. 'onclick': '$(this).parent().parent().remove();'
  342. });
  343. var divForGroup = $('<div/>', {
  344. 'id': 'outcomeGroup' + counter.toString(),
  345. }).html("<label>Outcome " + (counter + 1) + "</label>");
  346. var objectiveGroup = $('<div/>', {
  347. 'id': 'objectiveGroupFor' + counter,
  348. 'data-value': '1'
  349. });
  350. var form_group_for_objective = $('<div/>', {
  351. 'class': 'form-group col-md-11'
  352. }).html('<label>Associated Objectives for Outcome ' + (counter + 1) + '</label>');
  353. var $select_objective = $('<select/>', {
  354. 'class': "selectpicker form-control",
  355. 'name': "objective[]",
  356. 'data-live-search': 'true',
  357. 'id': 'objective_' + counter + '_counter_1'
  358. });
  359. var empty_div = $('<div/>', {
  360. 'class': 'col-md-1'
  361. });
  362. var button_for_add = $('<button/>', {
  363. 'class': 'btn btn-md btn-secondary button-add-objective',
  364. 'onclick': 'addObjectiveTest("objectiveGroupFor' + counter + '", "objective_' + counter + '")'
  365. }).html("<span class='glyphicon glyphicon-plus'></span>Add another Objective");
  366. divForGroup.append($div)
  367. $button.append('X');
  368. $divForButton.append($button);
  369. $('#allOutcomes').append(divForGroup);
  370. $select.append(selectOptions);
  371. $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
  372. $('#outcomeGroup0').data("value", (counter + 1));
  373. divForGroup.append($divForButton);
  374. form_group_for_objective.append($select_objective)
  375. objectiveGroup.append(form_group_for_objective);
  376. objectiveGroup.append(empty_div);
  377. //objectiveGroup.append(button_for_add);
  378. divForGroup.append(objectiveGroup);
  379. divForGroup.append(button_for_add);
  380. divForGroup.append('<hr>');
  381. fetchObjectiveForSelect('outcome' + counter, "objectiveGroupFor" + counter);
  382. $select_objective.selectpicker('refresh');
  383. }
  384. //Delete Outcome and OptGroup associated
  385. function deleteLast(outcomeForm, outcomeDiv, closeButton, objectiveGroup) {
  386. $div = document.getElementById(outcomeForm);
  387. $div.remove();
  388. $div = document.getElementById(closeButton);
  389. $div.remove();
  390. if (outcomeDiv == 'outcomeGroup') {
  391. $('#' + outcomeDiv).data('value', parseInt($('#' + outcomeDiv).data('value')) - 1);
  392. fetchObjectiveForSelect(outcomeDiv, objectiveGroup);
  393. }
  394. }
  395. //Delete Objective
  396. function deleteObjective(objectiveForm, closeObj, objectiveGroup) {
  397. $div = document.getElementById(objectiveForm);
  398. $div.remove();
  399. $div = document.getElementById(closeObj);
  400. $div.remove();
  401. //counter = parseInt($('#'+objectiveGroup).data("value"));
  402. // $('#'+objectiveGroup).data("value", counter-1);
  403. }
  404. //Add objective when editing
  405. function addAssocObjective(objForGroup, originalObjective) {
  406. counter = $("#" + objForGroup).data('value');
  407. selectObj = document.getElementById(originalObjective + '_counter_1').innerHTML;
  408. assocObjectiveCounter = parseInt($('#' + objForGroup).data('value'));
  409. var $select = $('<select/>', {
  410. 'class': "selectpicker form-control",
  411. 'name': "objective[]",
  412. 'data-live-search': 'true',
  413. 'id': originalObjective + '_counter_' + (assocObjectiveCounter + 1).toString(),
  414. });
  415. var $div = $('<div/>', {
  416. 'id': 'assoc_objectiveForm_' + objForGroup + '_' + assocObjectiveCounter.toString(),
  417. 'class': 'form-group col-md-10'
  418. });
  419. var $divForButton = $('<div/>', {
  420. 'class': 'col-md-2',
  421. 'id': 'assoc_closeObj_' + objForGroup + '_' + assocObjectiveCounter.toString()
  422. });
  423. var $button = $('<button/>', {
  424. 'type': 'button',
  425. 'class': 'btn btn-primary',
  426. 'onclick': 'deleteObjective("assoc_objectiveForm_' + objForGroup + '_' + assocObjectiveCounter.toString() + '", "assoc_closeObj_' + objForGroup + '_' + assocObjectiveCounter.toString() + '", "' + objForGroup + '")'
  427. });
  428. $button.append('X');
  429. $divForButton.append($button);
  430. $div.appendTo('#' + objForGroup)
  431. $select.append(selectObj);
  432. $select.appendTo($div).selectpicker('refresh');
  433. //$('#assoc_objectiveGroup').data("value", assocObjectiveCounter +1);
  434. $divForButton.appendTo('#' + objForGroup);
  435. $('#' + objForGroup).data('value', counter + 1);
  436. }
  437. //Add objective when creating a criteria
  438. function addObjectiveTest(objForGroup, originalObjective) {
  439. counter = $('#' + objForGroup).data('value');
  440. selectObj = document.getElementById(originalObjective + '_counter_1').innerHTML;
  441. var $select = $('<select/>', {
  442. 'class': "selectpicker form-control",
  443. 'name': "objective[]",
  444. 'data-live-search': 'true',
  445. 'id': originalObjective + '_counter_' + (counter + 1).toString()
  446. });
  447. var $div = $('<div/>', {
  448. 'id': 'objectiveForm_' + objForGroup + '_' + counter.toString(),
  449. 'class': 'form-group col-md-10'
  450. });
  451. var $divForButton = $('<div/>', {
  452. 'class': 'col-md-2',
  453. 'id': 'closeObj_' + objForGroup + '_' + counter.toString()
  454. });
  455. var $button = $('<button/>', {
  456. 'type': 'button',
  457. 'class': 'btn btn-primary',
  458. 'onclick': 'deleteObjective("objectiveForm_' + objForGroup + '_' + counter.toString() + '", "closeObj_' + objForGroup + '_' + counter.toString() + '", "' + objForGroup + '")'
  459. });
  460. $button.append('X');
  461. $divForButton.append($button);
  462. $div.appendTo('#' + objForGroup)
  463. $select.append(selectObj);
  464. $select.appendTo($div).selectpicker('refresh');
  465. $divForButton.appendTo('#' + objForGroup);
  466. $('#' + objForGroup).data('value', counter + 1);
  467. }
  468. //Create outcome for editing
  469. var assocOutcomeCounter = 0;
  470. function addAssocOutcome(depends = null) {
  471. assocOutcomeCounter = parseInt($('#assocOutcomeGroup0').data('value'));
  472. var $select = $('<select/>', {
  473. 'class': "selectpicker form-control",
  474. 'name': "outcome[]",
  475. 'data-live-search': 'true',
  476. 'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
  477. 'onchange': 'fetchAssocObjective("assoc_outcome_' + assocOutcomeCounter.toString() + '", "assoc_objectiveGroupFor' + assocOutcomeCounter + '")'
  478. });
  479. var $div = $('<div/>', {
  480. 'id': 'assoc_outcomeForm' + assocOutcomeCounter.toString(),
  481. 'class': 'form-group col-md-11'
  482. });
  483. var $divForButton = $('<div/>', {
  484. 'class': 'col-md-1',
  485. 'id': 'assoc_close' + assocOutcomeCounter.toString()
  486. });
  487. var $button = $('<button/>', {
  488. 'type': 'button',
  489. 'class': 'btn btn-primary',
  490. 'id': 'assoc_close_button' + assocOutcomeCounter,
  491. 'onclick': '$(this).parent().parent().remove()'
  492. });
  493. var divForGroup = $('<div/>', {
  494. 'id': 'assocOutcomeGroup' + assocOutcomeCounter.toString(),
  495. }).html("<label>Outcome " + (assocOutcomeCounter + 1) + "</label>");
  496. var objectiveGroup = $('<div/>', {
  497. 'id': 'assoc_objectiveGroupFor' + assocOutcomeCounter,
  498. 'data-value': '1'
  499. });
  500. var form_group_for_objective = $('<div/>', {
  501. 'class': 'form-group col-md-11'
  502. }).html('<label>Associated Objectives for Outcome ' + (assocOutcomeCounter + 1) + '</label>');
  503. var $select_objective = $('<select/>', {
  504. 'class': "selectpicker form-control",
  505. 'name': "objective[]",
  506. 'data-live-search': 'true',
  507. 'id': 'assoc_objective_' + assocOutcomeCounter + '_counter_1'
  508. });
  509. var empty_div = $('<div/>', {
  510. 'class': 'col-md-1'
  511. });
  512. var button_for_add = $('<button/>', {
  513. 'class': 'btn btn-md btn-secondary button-add-objective',
  514. 'onclick': 'addAssocObjective("assoc_objectiveGroupFor' + assocOutcomeCounter + '", "assoc_objective_' + assocOutcomeCounter + '")'
  515. }).html("<span class='glyphicon glyphicon-plus'></span>Add another Objective");
  516. divForGroup.append($div)
  517. $button.append('X');
  518. $divForButton.append($button);
  519. $('#allAssocOutcomes').append(divForGroup);
  520. //$div.appendTo('#assocOutcomeGroup')
  521. $select.append(selectOptions);
  522. $select.appendTo('#assoc_outcomeForm' + assocOutcomeCounter.toString()).selectpicker('refresh');
  523. //assocOutcomeCounter += 1;
  524. $('#assocOutcomeGroup0').data('value', assocOutcomeCounter + 1);
  525. //$divForButton.appendTo('#assocOutcomeGroup');
  526. divForGroup.append($divForButton);
  527. form_group_for_objective.append($select_objective)
  528. objectiveGroup.append(form_group_for_objective);
  529. objectiveGroup.append(empty_div);
  530. //objectiveGroup.append(button_for_add);
  531. divForGroup.append(objectiveGroup);
  532. divForGroup.append(button_for_add);
  533. divForGroup.append('<hr>');
  534. if (!depends) fetchObjectiveForSelect('assoc_outcome_' + assocOutcomeCounter, 'assoc_objectiveGroupFor' + assocOutcomeCounter);
  535. $select_objective.selectpicker('refresh');
  536. }
  537. //Fetch associated objective for editing
  538. var assocObjectiveCounter = 1;
  539. function fetchAssocObjective(outcomeDiv, objectiveGroup) {
  540. var count = $('#' + outcomeDiv).data('value');
  541. var allOutcomes = [];
  542. $("#" + outcomeDiv + ' select').each(function() {
  543. allOutcomes.push(this.value);
  544. })
  545. var allObjectives = [];
  546. $("#" + objectiveGroup + ' select').each(function() {
  547. var temp = {
  548. id: this.id,
  549. value: this.value
  550. }
  551. allObjectives.push(temp);
  552. })
  553. $.post(
  554. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  555. allOutcomes: allOutcomes
  556. },
  557. function(json) {
  558. optionName = '<option value ="0">Nothing Selected</option>';
  559. for (outcome in varArray.outcomes) {
  560. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '">';
  561. var objectiveForOutcome = varArray.objectives;
  562. var objectives = objectiveForOutcome[outcome];
  563. for (objective in objectives) {
  564. var obj = objectives[objective];
  565. var option = '<option value ="' + obj.id + '">' + obj.text + '</option>';
  566. optionName += (option);
  567. }
  568. optionName += '</optgroup>';
  569. }
  570. $('#assoc_objective_0').html(optionName);
  571. $('#assoc_objective_0').selectpicker('refresh');
  572. if ($("#assoc_objective_0 option[value='" + allObjectives[0].value + "']").length > 0) {
  573. $("#assoc_objective_0").val(allObjectives[0].value);
  574. $('#assoc_objective_0').selectpicker('refresh');
  575. }
  576. for (var i = allObjectives.length - 1; i > 0; i--) {
  577. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup');
  578. }
  579. for (var i = 1; i < allObjectives.length; i++) {
  580. addAssocObjective();
  581. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  582. if ($("#assoc_objective_" + i.toString() + " option[value='" + allObjectives[i].value + "']").length > 0) {
  583. $("#assoc_objective_" + i.toString()).val(allObjectives[i].value);
  584. $("#assoc_objective_" + i.toString()).selectpicker("refresh");
  585. }
  586. }
  587. },
  588. 'json'
  589. );
  590. }
  591. //Fetch objective at creating criteria
  592. counterForPost = 0;
  593. function fetchObjectiveForSelect(outcome, objectiveGroup) {
  594. outcomeID = $('#' + outcome).val();
  595. var allObjectives = [];
  596. $("#" + objectiveGroup + ' select').each(function() {
  597. var temp = {
  598. id: this.id,
  599. value: this.value
  600. }
  601. allObjectives.push(temp);
  602. })
  603. $.post(
  604. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  605. outcomeID: outcomeID
  606. },
  607. function(varArray) {
  608. counterOutcome = 0;
  609. optionName = '<option value ="0">Nothing Selected</option>';
  610. for (index in varArray) {
  611. objectiveObject = varArray[index];
  612. optionName += '<option value ="(' + objectiveObject.outcome_id + ',' + objectiveObject.objective_id + ')">' +
  613. objectiveObject.text + '</option>';
  614. }
  615. /*
  616. for(outcome in varArray.outcomes){
  617. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '">';
  618. var objectiveForOutcome = varArray.objectives;
  619. var objectives = objectiveForOutcome[outcome];
  620. for (objective in varArray.objectives[outcome]) {
  621. var obj= objectives[objective];
  622. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  623. optionName += (option);
  624. }
  625. optionName += "</optgroup>";
  626. }*/
  627. for (index in allObjectives) {
  628. id = allObjectives[index].id
  629. $('#' + id).html(optionName);
  630. $('#' + id).selectpicker('refresh');
  631. }
  632. /*$('#objective_0').html(optionName);
  633. $('#objective_0').selectpicker('refresh');
  634. if($("#objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  635. $("#objective_0").val(allObjectives[0].value);
  636. $('#objective_0').selectpicker('refresh');
  637. }
  638. for (var i = allObjectives.length - 1; i > 0; i--) {
  639. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString(), 'objectiveGroup');
  640. }
  641. for(var i =1; i<allObjectives.length; i++){
  642. addObjectiveTest();
  643. $('#objective_'+i.toString()).selectpicker('refresh');
  644. if($("#objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  645. $("#objective_"+i.toString()).val(allObjectives[i].value);
  646. $("#objective_"+i.toString()).selectpicker("refresh");
  647. }
  648. }*/
  649. },
  650. 'json'
  651. );
  652. }
  653. //after post
  654. //For editing criterion
  655. function fetchAllCriterion(program, outcome) {
  656. var program_id_fetch = $('#' + program).find(':selected').val();
  657. var outcome_fetch = $('#' + outcome).find(':selected').val();
  658. $.post(
  659. "{{URL::action('CriteriaController@fetchAllCriterion')}}", {
  660. program_fetch: program_id_fetch,
  661. outcome_fetch: outcome_fetch
  662. },
  663. function(json) {
  664. json_length = (json.criterion.length);
  665. fullHTML = '';
  666. for (var i = 0; i < json_length; i++) {
  667. fullHTML += '<option value="' + json.criterion[i].id + '">' + json.criterion[i].name + '</option>';
  668. }
  669. $('#select-criterion').html(fullHTML);
  670. $('#select-criterion').selectpicker('refresh');
  671. fetchCriterionForEditing()
  672. },
  673. 'json'
  674. );
  675. }
  676. function deleteCriterion() {
  677. var id = $('#select-criterion').find(':selected').val()
  678. $.post(
  679. "{{ URL::action('CriteriaController@delete')}}", {
  680. id: id
  681. },
  682. function() {
  683. window.location.reload(true)
  684. }
  685. )
  686. }
  687. function fetchCriterionForEditing() {
  688. var id = $('#select-criterion').find(':selected').val();
  689. $.post(
  690. "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
  691. id: id
  692. },
  693. function(json) {
  694. if (!(json.activity_criterion.length)) {
  695. $('#DeleteButton').prop('disabled', false);
  696. $("#update_the_criterion").val('Update');
  697. $("#update_criterion").attr('action', "{{ URL::action('CriteriaController@update')}}")
  698. } else {
  699. $('#DeleteButton').prop('disabled', true);
  700. $("#update_the_criterion").val("Create New")
  701. $("#update_criterion").attr('action', "{{ URL::action('CriteriaController@create')}}")
  702. $('#alert_placeholder').html('<div class="alert alert-danger alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button> <strong>Warning!</strong> The criterion is already used in assessments. Editting the criterion will actually create a new criterion </div>');
  703. }
  704. if (!(json.criteria.length)) {
  705. name = ' ';
  706. var subcriteria = '';
  707. copyright = null;
  708. notes = null;
  709. $('#status').val(0);
  710. maximum = 1;
  711. $('#assoc_maximum_score').val(1);
  712. } else {
  713. var name = json.criteria[0].name;
  714. if (json.criteria[0].subcriteria) {
  715. subcriteria = JSON.parse(json.criteria[0].subcriteria).join('\n');
  716. } else {
  717. subcriteria = "";
  718. }
  719. if (json.criteria[0].copyright) {
  720. var copyright = json.criteria[0].copyright;
  721. } else {
  722. var copyright = ''
  723. }
  724. if (json.criteria[0].notes) notes = json.criteria[0].notes;
  725. else notes = '';
  726. // Display info
  727. $('#criterion_name').val(name);
  728. $('#criterion_subcriteria').text(subcriteria);
  729. if (json.criteria[0].deleted_at)
  730. $('#status').val(0);
  731. else
  732. $('#status').val(1);
  733. $('#assoc_maximum_score').val(json.criteria[0].max_score);
  734. var maximum = json.criteria[0].max_score;
  735. addOptions("Num_assoc_scale", "assoc_maximum_score", "Assoc_Scales");
  736. $('#Num_assoc_scale').val(json.criteria[0].num_scales)
  737. $('#Num_assoc_scale').selectpicker('refresh');
  738. $('#Num_assoc_scale').trigger('change');
  739. for (i = 0; i < json.criteria[0].num_scales; i++) {
  740. $('#assoc_scale_' + i).val(json.scales[i].description);
  741. }
  742. // If copyright or notes aren't empty, load them
  743. }
  744. $('#criterion_copyright').text(copyright);
  745. $('#criterion_notes').text(notes);
  746. // Select associated outcome
  747. try {
  748. assocOutcomeCounter = parseInt($("#assocOutcomeGroup0").data('value'));
  749. for (var i = assocOutcomeCounter - 1; i > 0; i--) {
  750. $('#assoc_close_button' + i).click();
  751. }
  752. $('#assocOutcomeGroup0').data('value', 1);
  753. } catch (err) {
  754. var Notran = true;
  755. }
  756. if (json.outcomes.length) {
  757. $('#assoc_outcome_0').val(json.outcomes[0].id);
  758. $('#assoc_outcome_0').selectpicker('refresh');
  759. var first_outcome_id = json.outcomes[0].id;
  760. options = "<option value ='0'>Nothing Selected</option>";
  761. for (objective_index in json.objectives_assoc[first_outcome_id]) {
  762. objective = json.objectives_assoc[first_outcome_id][objective_index]
  763. options += '<option value ="(' + first_outcome_id + ',' + objective.objective_id + ')">' +
  764. objective.text + '</option>';
  765. }
  766. $('#assoc_objective_0_counter_1').html(options);
  767. $('#assoc_objective_0_counter_1').selectpicker('refresh');
  768. if (json.objectives[first_outcome_id].length) {
  769. objective_id = json.objectives[first_outcome_id][0].objective_id;
  770. value = '(' + first_outcome_id + ',' + objective_id + ')';
  771. $('#assoc_objective_0_counter_1').val(value);
  772. $('#assoc_objective_0_counter_1').selectpicker('refresh');
  773. }
  774. for (var i = 1; i < json.objectives[first_outcome_id].length; i++) {
  775. addAssocObjective("assoc_objectiveGroupFor0", "assoc_objective_0");
  776. objective_id = json.objectives[first_outcome_id][i].objective_id;
  777. value = "(" + first_outcome_id + "," + objective_id + ")";
  778. $('#assoc_objective_0_counter_' + (i + 1)).val(value);
  779. $('#assoc_objective_0_counter_' + (i + 1)).selectpicker('refresh');
  780. }
  781. } else {
  782. $('#assoc_outcome_0').val($('#assoc_outcomes_fetch').find(':selected').val());
  783. $('#assoc_outcome_0').selectpicker('refresh');
  784. }
  785. for (var i = 1; i < json.outcomes.length; i++) {
  786. addAssocOutcome(true);
  787. $('#assoc_outcome_' + i.toString()).val(json.outcomes[i].id);
  788. $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
  789. var outcome_id = json.outcomes[i].id;
  790. options = "<option value ='0'>Nothing Selected</option>";
  791. for (objective_index in json.objectives_assoc[outcome_id]) {
  792. objective = json.objectives_assoc[outcome_id][objective_index]
  793. options += '<option value ="(' + outcome_id + ',' + objective.objective_id + ')">' +
  794. objective.text + '</option>';
  795. }
  796. $('#assoc_objective_' + i + '_counter_1').html(options);
  797. $('#assoc_objective_' + i + '_counter_1').selectpicker('refresh');
  798. if (json.objectives[outcome_id].length) {
  799. objective_id = json.objectives[outcome_id][0].objective_id;
  800. value = "(" + outcome_id + "," + objective_id + ")"
  801. $('#assoc_objective_' + i + '_counter_1').val(value);
  802. $('#assoc_objective_' + i + '_counter_1').selectpicker('refresh')
  803. }
  804. for (var j = 1; i < json.objectives[outcome_id].length; i++) {
  805. addAssocObjective("assoc_objectiveGroupFor" + i, "assoc_objective_" + i);
  806. objective_id = json.objectives[outcome_id][j].objective_id;
  807. value = "(" + outcome_id + "," + objective_id + ")";
  808. $('#assoc_objective_' + i + '_counter_' + (j + 1)).val(value);
  809. $('#assoc_objective_' + i + '_counter_' + (j + 1)).selectpicker('refresh');
  810. }
  811. }
  812. /*try {
  813. for (var i = counterObj - 1; i > 0; i--) {
  814. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup')
  815. }
  816. } catch (err) {
  817. var noEntro = true;
  818. }*/
  819. //$('#assoc_objectiveGroup').data('value', 1);
  820. //counterObj =$('#assoc_objectiveGroup').data('value');
  821. /*
  822. assocOutcomeCounter = 0;
  823. var i = 0;
  824. optionName = '<option value ="0">Nothing Selected</option>';
  825. for(outcome in json.outcomes_assoc){
  826. optionName += '<optgroup label="' + json.outcomes_assoc[outcome][0].name + '">';
  827. var objectiveForOutcome = json.objectives_assoc;
  828. var objectives = objectiveForOutcome[outcome];
  829. for (objective in objectives) {
  830. var obj= objectives[objective];
  831. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  832. optionName += (option);
  833. }
  834. optionName+= '</optgroup>';
  835. }
  836. $('#assoc_objective_0').html(optionName);
  837. $('#assoc_objective_0').selectpicker('refresh');
  838. try {
  839. $('#assoc_objective_0').val(json.objectives[0].id);
  840. $('#assoc_objective_0').selectpicker('refresh');
  841. } catch (err) {
  842. if (!json.objectives.length) {
  843. $('#assoc_objective_0').val(0);
  844. $('#assoc_objective_0').selectpicker('refresh');
  845. }
  846. var thereIsNoObjective = true;
  847. }
  848. for (var i = 1; i < json.objectives.length; i++) {
  849. addAssocObjective();
  850. $('#assoc_objective_' + i.toString()).val(json.objectives[i].id);
  851. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  852. }
  853. $('assoc_objectiveGroup').data('value',json.objectives.length);
  854. */
  855. // Select status
  856. },
  857. 'json'
  858. );
  859. }
  860. </script>
  861. @stop
  862. @section('javascript')
  863. // --------------------------------------------------------------------------
  864. // Page load
  865. // --------------------------------------------------------------------------
  866. // Hide accordion panel contents by default
  867. $('.panel-group .panel-body').hide();
  868. $('#outcome-display').parent().hide();
  869. fetchCriterionForEditing();
  870. fetchObjectiveForSelect('outcome0', 'objectiveGroupFor0');
  871. // setCriterionStatus();
  872. fetchAllCriterion("select-program", "assoc_outcomes_fetch");
  873. // --------------------------------------------------------------------------
  874. // Functions
  875. // --------------------------------------------------------------------------
  876. $('#button-add-outcome').on('click', function(e) {
  877. // Prevent the default action of the clicked item. In this case that is submit
  878. e.preventDefault();
  879. return false;
  880. });
  881. $('.filterButton').on('click', function(e) {
  882. // Prevent the default action of the clicked item. In this case that is submit
  883. e.preventDefault();
  884. return false;
  885. });
  886. $('.button-add-objective-assoc').on('click', function(e) {
  887. // Prevent the default action of the clicked item. In this case that is submit
  888. e.preventDefault();
  889. return false;
  890. });
  891. $('#button-add-outcome-assoc').on('click', function(e) {
  892. // Prevent the default action of the clicked item. In this case that is submit
  893. e.preventDefault();
  894. return false;
  895. });
  896. $('.button-add-objective').on('click', function(e) {
  897. // Prevent the default action of the clicked item. In this case that is submit
  898. e.preventDefault();
  899. return false;
  900. });
  901. // Fetch criterion info for editing
  902. // --------------------------------------------------------------------------
  903. // Events
  904. // --------------------------------------------------------------------------
  905. // When panel heading is clicked, toggle it
  906. $('.panel-group .panel-heading').on('click', function()
  907. {
  908. $(this).next().stop().slideToggle();
  909. })
  910. //$('#outcome[0]').on('change', function(){
  911. //$('.selectpicker').selectpicker('refresh');
  912. //})
  913. // When list item is clicked, load corresponding info
  914. // When list item is clicked, load corresponding info
  915. $('.selectpicker').on('change', function()
  916. {
  917. //alert($(this).find(':selected').val());
  918. $('.selectpicker').selectpicker('refresh');
  919. });
  920. @stop