Nessuna descrizione

new_criteria.blade.php 47KB

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