Brak opisu

criteria.blade.php 51KB

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