Brak opisu

criteria.blade.php 48KB

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