No Description

criteria.blade.php 51KB

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