Няма описание

criteria.blade.php 47KB

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