No Description

criteria.blade.php 47KB

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