No Description

criteria.blade.php 51KB

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