Bez popisu

criteria.blade.php 72KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745
  1. @extends('layouts.master')
  2. @section('navigation')
  3. @if(Auth::user()->role == 1)
  4. @include('local.managers.admins._navigation')
  5. @elseif(Auth::user()->role == 2)
  6. @include('local.managers.sCoords._new_navigation')
  7. @elseif(Auth::user()->role == 3)
  8. @include('local.managers.pCoords._new_navigation')
  9. @endif
  10. @stop
  11. @section('main')
  12. <div class="row">
  13. <div class="col-md-6">
  14. <!-- Form to add a new criterion -->
  15. <div class="panel panel-default panel-button">
  16. <div class="panel-heading">
  17. Create
  18. </div>
  19. <div class="panel-body">
  20. {{ Form::open(['action' => 'CriteriaController@create', 'id' => 'create_criterion']) }}
  21. <div id='allOutcomes' class='form_validation outcome_form'>
  22. <div id='outcomeGroup0' class='createOutcome' data-value="1">
  23. <div class="form-group col-md-12 selectOutcome">
  24. <label>Outcome 1</label>
  25. {{ Form::select('outcome[]', $outcomes, reset($outcomes), ['class' => 'form-control selectpicker', 'id' => 'outcome0', 'onchange' => 'fetchObjectiveForSelect("outcome0", "objectiveGroupFor0")']) }}
  26. </div>
  27. <div id='objectiveGroupFor0' class='createObjective' data-value='1'>
  28. <div class="form-group col-md-11 selectObjective">
  29. <label>Associated Objectives for Outcome 1</label>
  30. <select id="objective_0_counter_1" name="objective[]" class="form-control selectpicker"
  31. onchange="visiblePrograms('allOutcomes')">
  32. </select>
  33. </div>
  34. <div class="col-md-1">
  35. </div>
  36. </div>
  37. <input type='hidden' name='counterObjective' id='counterObjective' value=1>
  38. <button class='btn btn-md btn-secondary button-add-objective'
  39. onclick='addObjectiveTest("objectiveGroupFor0", "objective_0")'>
  40. <span class='glyphicon glyphicon-plus'>
  41. </span>
  42. Add another Objective
  43. </button>
  44. <br>
  45. <hr>
  46. </div>
  47. </div>
  48. <input type='hidden' name='counterOutcome' id='counterOutcome' value=1>
  49. <button id='button-add-outcome' class='btn btn-md btn-secondary' onclick='addOutcomeTest()'>
  50. <span class='glyphicon glyphicon-plus'>
  51. </span>
  52. Add another Outcome
  53. </button>
  54. <!-- Associated Program -->
  55. <div class="form-group form_validation program_form" id='program-checkboxes'>
  56. {{ Form::label('program_id', 'Associated Program') }}<br>
  57. <br>
  58. @if(count($programs) ==1)
  59. <input type="checkbox" id="program-{{ $programs[0]->name }}" name="program_id[]"
  60. value="{{ $programs[0]->id }}" checked>
  61. <label for="program-{{ $programs[0]->name }}"> {{ $programs[0]->name }}
  62. [{{ $programs[0]->school->name }}]</label><br>
  63. <input type="hidden" id="{{ $programs[0]->name }}" name="program_id[]"
  64. value="{{ $programs[0]->id }}">
  65. @else
  66. @foreach ($programs as $program)
  67. <input type="checkbox" id="program-{{ $program->id }}" name="program_id[]"
  68. value="{{ $program->id }}">
  69. <label for="program-{{ $program->id }}"> {{ $program->name }}
  70. [{{ $program->school->name }}]</label><br>
  71. @endforeach
  72. @endif
  73. </div>
  74. <div class="form-group form_validation name_form">
  75. {{ Form::label('name', 'Name') }}
  76. {{ Form::text('name', '', ['class' => 'form-control']) }}
  77. </div>
  78. <div class="form-group">
  79. {{ Form::label('subcriteria', 'Subcriteria') }}
  80. <p class="help-block"><strong>Manually add</strong> bullets or numbering.</p>
  81. {{ Form::textarea('subcriteria', '', ['class' => 'form-control', 'rows' => 3, 'aria-labelledby' => 'subcriteria']) }}
  82. </div>
  83. <div class="form-group form_validation maximum_form">
  84. {{ Form::label('maximum_score', 'Maximum Score') }}
  85. {{ Form::text('maximum_score', '8', ['class' => 'form-control', 'id' => 'maximum_score', 'oninput' => 'addOptions("Num_scale", "maximum_score", "Scales")']) }}
  86. </div>
  87. <div class="form-group form_validation number_of_scales">
  88. {{ Form::label('scales', 'Number of Scales') }}
  89. <select id="Num_scale" name="scales" class="form-control selectpicker"
  90. onchange='numberOfScales("Num_scale", "Scales")'>
  91. </select>
  92. </div>
  93. <div id='Scales' class='form_validation scales_form' data-value="0">
  94. </div>
  95. <div class="form-group">
  96. {{ Form::label('copyright', 'Copyright') }}
  97. {{ Form::textarea('copyright', '', ['class' => 'form-control', 'rows' => 2, 'placeholder' => '(optional)', 'aria-labelledby' => 'copyright']) }}
  98. </div>
  99. <div class="form-group">
  100. {{ Form::label('notes', 'Notes') }}
  101. {{ Form::textarea('notes', '', ['class' => 'form-control', 'rows' => 2, 'placeholder' => '(optional)', 'aria-labelledby' => 'notes']) }}
  102. </div>
  103. {{ Form::submit('Create', ['class' => 'btn btn-primary btn-block', 'id' => 'create_the_criterion_button', 'data-form-id' => 'create_criterion']) }}
  104. {{ Form::close() }}
  105. </div>
  106. </div>
  107. </div>
  108. <div class="col-md-6">
  109. <div class="panel panel-default panel-button">
  110. <div class="panel-heading">
  111. Edit
  112. </div>
  113. <div class="panel-body">
  114. {{ Form::open(['action' => 'CriteriaController@update', 'id' => 'update_criterion', 'data-form-id' => 'update_criterion']) }}
  115. <button class="btn btn-md btn-secondary filterButton">
  116. <span class="glyphicon glyphicon-minus">
  117. </span>
  118. Filters
  119. </button>
  120. <div class="filterSection">
  121. <div class="form-group">
  122. {{ Form::label('program_id2', 'Associated Program') }}
  123. <select id='select-program' class="form-control selectpicker"
  124. onchange='fetchAllCriterion("select-program", "assoc_outcomes_fetch")'>
  125. @foreach ($programs as $program)
  126. <option value='{{ $program->id }}' data-subtext="{{ $program->code }}">
  127. {{ $program->name }}</option>
  128. @endforeach
  129. </select>
  130. </div>
  131. <div class="form-group">
  132. <label>Associated Outcome</label>
  133. {{ Form::select('assoc_outcome_fetch', $outcomes, null, ['class' => 'form-control selectpicker', 'id' => 'assoc_outcomes_fetch', 'onchange' => 'fetchAllCriterion("select-program", "assoc_outcomes_fetch")']) }}
  134. </div>
  135. </div>
  136. <hr>
  137. <div class="form-group">
  138. {{ Form::label('criterion_id', 'Criterion') }}
  139. <select id="select-criterion" name="id" class="form-control selectpicker"
  140. onchange='fetchCriterionForEditing()'>
  141. </select>
  142. </div>
  143. <div id='allAssocOutcomes' class='form_validation outcome_form'>
  144. <!-- Associated Outcome -->
  145. <div id='assocOutcomeGroup0' class='createOutcome' data-value="1">
  146. <div class="form-group col-md-12 selectOutcome">
  147. <label>Outcome 1</label>
  148. {{ Form::select('outcome[]', $outcomes, null, ['class' => 'form-control selectpicker', 'id' => 'assoc_outcome_0', 'onchange' => 'fetchObjectiveForSelect("assoc_outcome_0", "assoc_objectiveGroupFor0")']) }}
  149. </div>
  150. <div id='assoc_objectiveGroupFor0' class='createObjective' data-value="1">
  151. <div class="form-group col-md-11 selectObjective">
  152. <label>Associated Objectives for Outcome 1</label>
  153. <select id="assoc_objective_0_counter_1" name="objective[]"
  154. class="form-control selectpicker" onchange="visiblePrograms('allAssocOutcomes')">
  155. <option value="0">No associated objectives</option>
  156. </select>
  157. </div>
  158. <div class='col-md-1'></div>
  159. </div>
  160. <button id='button-add-objective-assoc' class='btn btn-md btn-secondary'
  161. onclick='addAssocObjective("assoc_objectiveGroupFor0", "assoc_objective_0")'>
  162. <span class='glyphicon glyphicon-plus'>
  163. </span>
  164. Add another Objective
  165. </button>
  166. <hr>
  167. </div>
  168. </div>
  169. <button class='btn btn-md btn-secondary button-add-outcome-assoc' onclick='addAssocOutcome()'>
  170. <span class='glyphicon glyphicon-plus'>
  171. </span>
  172. Add another Outcome
  173. </button>
  174. <!-- Associated Program -->
  175. <div class="form-group form_validation program_form" id = 'assoc-program-checkboxes'>
  176. {{ Form::label('program_id2', 'Associated Program') }}<br><br>
  177. @if(count($programs) ==1)
  178. <input type="hidden" id="{{ $programs[0]->name }}" name="program_id[]"
  179. value="{{ $programs[0]->id }}">
  180. <input type="checkbox" id="assoc_program-{{ $programs[0]->id }}" name="program_id[]"
  181. value="{{ $programs[0]->id }}" checked>
  182. <label for="assoc_program-{{ $programs[0]->id }}"> {{ $programs[0]->name }}
  183. <sub>[{{ $programs[0]->school->name }}]</sub></label><br>
  184. @else
  185. @foreach ($programs as $program)
  186. <input type="checkbox" id="assoc_program-{{ $program->id }}" name="program_id[]"
  187. value="{{ $program->id }}">
  188. <label for="assoc_program-{{ $program->id }}"> {{ $program->name }}
  189. <sub>[{{ $program->school->name }}]</sub></label><br>
  190. @endforeach
  191. @endif
  192. </div>
  193. <!-- Status -->
  194. <div class="form-group form_validation status_form">
  195. {{ Form::label('status', 'Status') }}
  196. <span data-toggle="tooltip" data-placement="top"
  197. 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."
  198. class="glyphicon glyphicon-question-sign"></span>
  199. <select id="status" name="status" class="form-control">
  200. <option value="1">Active</option>
  201. <option value="0">Inactive</option>
  202. </select>
  203. </div>
  204. <div class="form-group form_validation name_form">
  205. {{ Form::label('name', 'Name') }}
  206. {{ Form::text('name', Input::old('name'), ['class' => 'form-control', 'id' => 'criterion_name']) }}
  207. </div>
  208. <div class="form-group">
  209. {{ Form::label('subcriteria', 'Subcriteria') }}
  210. <p class="help-block"><strong>Manually add</strong> bullets or numbering.</p>
  211. {{ Form::textarea('subcriteria', '', ['class' => 'form-control', 'rows' => 3, 'id' => 'criterion_subcriteria']) }}
  212. </div>
  213. <div class="form-group form_validation maximum_form">
  214. {{ Form::label('maximum_score', 'Maximum Score') }}
  215. {{ Form::text('maximum_score', '', ['class' => 'form-control', 'id' => 'assoc_maximum_score', 'oninput' => 'addOptions("Num_assoc_scale", "assoc_maximum_score", "Assoc_Scales")']) }}
  216. </div>
  217. <div class="form-group form_validation number_of_scales">
  218. {{ Form::label('scales', 'Number of Scales') }}
  219. <select id="Num_assoc_scale" class="form-control selectpicker"
  220. onchange='numberOfAssoc("Num_assoc_scale", "Assoc_Scales")'>
  221. </select>
  222. </div>
  223. <div id='Assoc_Scales' class=' form_validation scales_form' data-value="0">
  224. </div>
  225. <div class="form-group">
  226. {{ Form::label('copyright', 'Copyright Information') }}
  227. {{ Form::textarea('copyright', Input::old('copyright'), ['class' => 'form-control', 'rows' => 2, 'id' => 'criterion_copyright', 'placeholder' => '(optional)']) }}
  228. </div>
  229. <div class="form-group">
  230. {{ Form::label('notes', 'Additional Notes') }}
  231. {{ Form::textarea('notes', Input::old('notes'), ['class' => 'form-control', 'rows' => 2, 'id' => 'criterion_notes', 'placeholder' => '(optional)']) }}
  232. </div>
  233. {{ Form::submit('Update', ['class' => 'btn btn-primary btn-block', 'id' => 'update_the_criterion_button', 'data-form-id' => 'update_criterion']) }}
  234. {{ Form::close() }}
  235. {{ Form::open(['action' => 'CriteriaController@delete']) }}
  236. <input type='hidden' name='criterion_delete' id='deleteCriteria'>
  237. {{ Form::submit('Delete', ['class' => 'btn btn-primary btn-block', 'id' => 'DeleteButton']) }}
  238. </div>
  239. </div>
  240. </div>
  241. </div>
  242. <script>
  243. var selectOptions = document.getElementById('outcome0').innerHTML;
  244. var counter = 1;
  245. var counterObj = 1;
  246. var outcomeString = 'OutcomeGroup_';
  247. $(document).ready(function() {
  248. addOptions('Num_scale', 'maximum_score', 'Scales');
  249. $('#Num_scale').val('4');
  250. numberOfScales('Num_scale', 'Scales');
  251. $('.selectpicker').selectpicker('refresh');
  252. });
  253. function checkIfNewCriterion(scaleBox){
  254. if ( $(scaleBox).val() == $(scaleBox).data('old-scale') ){
  255. $('#DeleteButton').prop('disabled', false);
  256. $("#update_the_criterion_button").val('Update');
  257. $("#update_criterion").attr('action', "{{ URL::action('CriteriaController@update') }}")
  258. $(scaleBox).parent().children('.alert-placeholder').remove();
  259. }
  260. else {
  261. if( $(scaleBox).parent().children('.alert-placeholder').length===0){
  262. div_placeholder = $('<div>',{
  263. 'class':'alert-placeholder'
  264. });
  265. $(div_placeholder).html(
  266. '<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> If a criterion is already used in assessments, editting it will actually create a new one </div>'
  267. );
  268. $(scaleBox).parent().prepend(div_placeholder);
  269. }
  270. $('#DeleteButton').prop('disabled', true);
  271. $("#update_the_criterion_button").val("Create New")
  272. $("#update_criterion").attr('action', "{{ URL::action('CriteriaController@create') }}")
  273. }
  274. }
  275. function fetchCriterionForEditing() {
  276. var id = $('#select-criterion').find(':selected').val();
  277. $.post(
  278. "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
  279. id: id
  280. },
  281. function(criterion) {
  282. if (!(criterion.length)) {
  283. name = ' ';
  284. var subcriteria = '';
  285. copyright = null;
  286. notes = null;
  287. $('#status').val(0);
  288. maximum = 1;
  289. $('#assoc_maximum_score').val(1);
  290. } else {
  291. criterion = criterion[0];
  292. var name = criterion.name;
  293. if (criterion.subcriteria) {
  294. subcriteria = JSON.parse(criterion.subcriteria).join('\n');
  295. } else {
  296. subcriteria = "";
  297. }
  298. if (criterion.copyright) {
  299. var copyright = criterion.copyright;
  300. } else {
  301. var copyright = ''
  302. }
  303. if (criterion.notes) notes = criterion.notes;
  304. else notes = '';
  305. // Display info
  306. $('#criterion_name').val(name);
  307. $('#criterion_subcriteria').text(subcriteria);
  308. if (criterion.deleted_at)
  309. $('#status').val(0);
  310. else
  311. $('#status').val(1);
  312. $('#assoc_maximum_score').val(criterion.max_score);
  313. var maximum = criterion.max_score;
  314. addOptions("Num_assoc_scale", "assoc_maximum_score", "Assoc_Scales");
  315. $('#Num_assoc_scale').val(criterion.num_scales)
  316. $('#Num_assoc_scale').selectpicker('refresh');
  317. $('#Num_assoc_scale').trigger('change');
  318. for (i = 0; i < criterion.num_scales; i++) {
  319. $('#assoc_scale_' + i).val(criterion.scales[i].description);
  320. }
  321. if ((criterion.activity_criterion.length)) {
  322. for(i = 0; i<criterion.num_scales; i++){
  323. $("#assoc_scale_"+i).attr('oninput','checkIfNewCriterion(this)')
  324. $("#assoc_scale_"+i).data('old-scale', $('#assoc_scale_'+i).val())
  325. }
  326. }
  327. // If copyright or notes aren't empty, load them
  328. }
  329. $('#criterion_copyright').text(copyright);
  330. $('#criterion_notes').text(notes);
  331. // Select associated outcome
  332. try {
  333. assocOutcomeCounter = parseInt($("#assocOutcomeGroup0").data('value'));
  334. for (var i = assocOutcomeCounter - 1; i > 0; i--) {
  335. $('#assoc_close_button' + i).click();
  336. }
  337. $('#assocOutcomeGroup0').data('value', 1);
  338. } catch (err) {
  339. var Notran = true;
  340. }
  341. if (criterion.outcomes.length) {
  342. $('#assoc_outcome_0').val(criterion.outcomes[0].id);
  343. $('#assoc_outcome_0').selectpicker('refresh');
  344. var first_outcome = criterion.outcomes[0];
  345. options = "<option value ='0'>Nothing Selected</option>";
  346. $(first_outcome.assoc_objectives).each(function(index, objective) {
  347. options += '<option data-program-ids = "' + objective.program_ids + '" value ="(' +
  348. first_outcome.id + ',' + objective.objective_id + ')">' +
  349. objective.text + '</option>';
  350. })
  351. /*for (objective_index in json.objectives_assoc[first_outcome_id]) {
  352. objective = json.objectives_assoc[first_outcome_id][objective_index]
  353. options += '<option value ="(' + first_outcome_id + ',' + objective.objective_id + ')">' +
  354. objective.text + '</option>';
  355. }*/
  356. $('#assoc_objective_0_counter_1').html(options);
  357. $('#assoc_objective_0_counter_1').selectpicker('refresh');
  358. if (first_outcome.objectives_criteria.length) {
  359. objective_id = first_outcome.objectives_criteria[0].objective_id;
  360. value = '(' + first_outcome.id + ',' + objective_id + ')';
  361. $('#assoc_objective_0_counter_1').val(value);
  362. $('#assoc_objective_0_counter_1').selectpicker('refresh');
  363. }
  364. if ($("#assoc_objectiveGroupFor0").find(".btn-primary").length > 0) {
  365. $("#assoc_objectiveGroupFor0").find(".btn-primary").each(function() {
  366. $(this).click()
  367. })
  368. }
  369. for (var i = 1; i < first_outcome.objectives_criteria.length; i++) {
  370. addAssocObjective("assoc_objectiveGroupFor0", "assoc_objective_0");
  371. objective_id = first_outcome.objectives_criteria[i].objective_id;
  372. value = "(" + first_outcome.id + "," + objective_id + ")";
  373. $('#assoc_objective_0_counter_' + (i + 1)).val(value);
  374. $('#assoc_objective_0_counter_' + (i + 1)).selectpicker('refresh');
  375. }
  376. } else {
  377. $('#assoc_outcome_0').val($('#assoc_outcomes_fetch').find(':selected').val());
  378. $('#assoc_outcome_0').selectpicker('refresh');
  379. }
  380. for (var i = 1; i < criterion.outcomes.length; i++) {
  381. addAssocOutcome(true);
  382. $('#assoc_outcome_' + i.toString()).val(criterion.outcomes[i].id);
  383. $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
  384. var outcome = criterion.outcomes[i];
  385. options = "<option value ='0'>Nothing Selected</option>";
  386. $(outcome.assoc_objectives).each(function(index, objective) {
  387. options += '<option value ="(' + outcome.id + ',' + objective.objective_id + ')">' +
  388. objective.text + '</option>';
  389. })
  390. /*for (objective_index in json.objectives_assoc[outcome_id]) {
  391. objective = json.objectives_assoc[outcome_id][objective_index]
  392. options += '<option value ="(' + outcome_id + ',' + objective.objective_id + ')">' +
  393. objective.text + '</option>';
  394. }*/
  395. $('#assoc_objective_' + i + '_counter_1').html(options);
  396. $('#assoc_objective_' + i + '_counter_1').selectpicker('refresh');
  397. if (outcome.objectives_criteria.length) {
  398. objective_id = outcome.objectives_criteria[0].objective_id;
  399. value = "(" + outcome.id + "," + objective_id + ")"
  400. $('#assoc_objective_' + i + '_counter_1').val(value);
  401. $('#assoc_objective_' + i + '_counter_1').selectpicker('refresh')
  402. }
  403. for (var j = 1; j < outcome.objectives_criteria.length; j++) {
  404. addAssocObjective("assoc_objectiveGroupFor" + i, "assoc_objective_" + i);
  405. objective_id = outcome.objectives_criteria[j].objective_id;
  406. value = "(" + outcome.id + "," + objective_id + ")";
  407. $('#assoc_objective_' + i + '_counter_' + (j + 1)).val(value);
  408. $('#assoc_objective_' + i + '_counter_' + (j + 1)).selectpicker('refresh');
  409. }
  410. }
  411. /*try {
  412. for (var i = counterObj - 1; i > 0; i--) {
  413. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup')
  414. }
  415. } catch (err) {
  416. var noEntro = true;
  417. }*/
  418. //$('#assoc_objectiveGroup').data('value', 1);
  419. //counterObj =$('#assoc_objectiveGroup').data('value');
  420. /*
  421. assocOutcomeCounter = 0;
  422. var i = 0;
  423. optionName = '<option value ="0">Nothing Selected</option>';
  424. for(outcome in json.outcomes_assoc){
  425. optionName += '<optgroup label="' + json.outcomes_assoc[outcome][0].name + '">';
  426. var objectiveForOutcome = json.objectives_assoc;
  427. var objectives = objectiveForOutcome[outcome];
  428. for (objective in objectives) {
  429. var obj= objectives[objective];
  430. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  431. optionName += (option);
  432. }
  433. optionName+= '</optgroup>';
  434. }
  435. $('#assoc_objective_0').html(optionName);
  436. $('#assoc_objective_0').selectpicker('refresh');
  437. try {
  438. $('#assoc_objective_0').val(json.objectives[0].id);
  439. $('#assoc_objective_0').selectpicker('refresh');
  440. } catch (err) {
  441. if (!json.objectives.length) {
  442. $('#assoc_objective_0').val(0);
  443. $('#assoc_objective_0').selectpicker('refresh');
  444. }
  445. var thereIsNoObjective = true;
  446. }
  447. for (var i = 1; i < json.objectives.length; i++) {
  448. addAssocObjective();
  449. $('#assoc_objective_' + i.toString()).val(json.objectives[i].id);
  450. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  451. }
  452. $('assoc_objectiveGroup').data('value',json.objectives.length);
  453. */
  454. visiblePrograms('allAssocOutcomes');
  455. var program_length = criterion.program.length;
  456. $('input[type=checkbox]').prop('checked', false);
  457. for (var i = 0; i < program_length; i++) {
  458. $('#assoc_program-' + criterion.program[i].program_id).prop("checked", true);
  459. }
  460. },
  461. 'json'
  462. );
  463. }
  464. //Input Validation function to client side
  465. $(document).on('submit', function(e) {
  466. isEverythingOkay = true;
  467. $('.alert-dismissible').remove();
  468. if (e.originalEvent.submitter.id == "create_the_criterion_button" || e.originalEvent.submitter.id ==
  469. "update_the_criterion_button") {
  470. submitter = e.originalEvent.submitter;
  471. // Input Validation
  472. children = $(submitter).children();
  473. what = $(submitter).data('form-id');
  474. form_id = $(submitter).data('form-id');
  475. form = $("#" + form_id)
  476. form = $("#" + form_id).children('div');
  477. $("#" + form_id).children('.form_validation').each(function(index) {
  478. //alert($(this).attr('id') + ' ' + index);
  479. //id_from_this_object = $(this).attr('id');
  480. if ($(this).hasClass('outcome_form')) {
  481. $.each($(this).children('.createOutcome'), function() {
  482. selectOutcomeDiv = $(this).children('.selectOutcome')[0];
  483. div_bootstrap_select = $(selectOutcomeDiv).children('div')[0];
  484. div_button = $(selectOutcomeDiv).children('button')[0];
  485. select = $(div_bootstrap_select).children('select')[0];
  486. value = $(select).val();
  487. if (isNaN(value)) {
  488. var timer;
  489. alert = $('<div/>', {
  490. 'class': 'alert alert-danger alert-dismissible',
  491. 'role': 'alert'
  492. })
  493. button = $('<button/>', {
  494. 'type': 'button',
  495. 'class': 'close',
  496. 'data-dismiss': 'alert',
  497. 'alert-label': 'close'
  498. }).html('<span aria-hidden="true">×</span>');
  499. alert.append(button);
  500. alert.append('<strong>Select a valid Outcome</strong>')
  501. $(selectOutcomeDiv).prepend(alert);
  502. isEverythingOkay = false;
  503. $('html, body').animate({
  504. scrollTop: $(alert).offset().top
  505. }, 2000);
  506. $(alert).focus();
  507. //$(div_bootstrap_select).css('border')
  508. }
  509. divContainsObjectives = $(this).children('.createObjective')[0];
  510. $.each($(divContainsObjectives).children('.selectObjective'),
  511. function() {
  512. divGroup = $(this).children('.btn-group')[0];
  513. select = $(divGroup).children('select')[0];
  514. if (parseInt($(select).val()) == 0) {
  515. var timer;
  516. alert = $('<div/>', {
  517. 'class': 'alert alert-danger alert-dismissible',
  518. 'role': 'alert'
  519. })
  520. button = $('<button/>', {
  521. 'type': 'button',
  522. 'class': 'close',
  523. 'data-dismiss': 'alert',
  524. 'alert-label': 'close'
  525. }).html('<span aria-hidden="true">×</span>');
  526. alert.append(button);
  527. alert.append('<strong>Select an objective</strong>')
  528. $(this).prepend(alert);
  529. $('html, body').animate({
  530. scrollTop: $(alert).offset().top
  531. }, 1000);
  532. $(divGroup).focus();
  533. isEverythingOkay = false;
  534. }
  535. })
  536. })
  537. } else if ($(this).hasClass('program_form')) {
  538. checkedboxes = $(this).children('input[type="checkbox"]:checked').length;
  539. if (!checkedboxes) {
  540. alert = $('<div/>', {
  541. 'class': 'alert alert-danger alert-dismissible',
  542. 'role': 'alert'
  543. })
  544. button = $('<button/>', {
  545. 'type': 'button',
  546. 'class': 'close',
  547. 'data-dismiss': 'alert',
  548. 'alert-label': 'close'
  549. }).html('<span aria-hidden="true">×</span>');
  550. alert.append(button);
  551. alert.append('<strong>Check at least one program</strong>')
  552. $(this).prepend(alert);
  553. $('html, body').animate({
  554. scrollTop: $(alert).offset().top
  555. }, 300);
  556. //$(divGroup).focus();
  557. isEverythingOkay = false;
  558. }
  559. } else if ($(this).hasClass('name_form')) {
  560. input = $(this).children('input')[0];
  561. if ($(input).val() == '') {
  562. var timer;
  563. alert = $('<div/>', {
  564. 'class': 'alert alert-danger alert-dismissible',
  565. 'role': 'alert'
  566. })
  567. button = $('<button/>', {
  568. 'type': 'button',
  569. 'class': 'close',
  570. 'data-dismiss': 'alert',
  571. 'alert-label': 'close'
  572. }).html('<span aria-hidden="true">×</span>');
  573. alert.append(button);
  574. alert.append('<strong>Write a name for the criterion</strong>')
  575. $(this).prepend(alert);
  576. $('html, body').animate({
  577. scrollTop: $(alert).offset().top
  578. }, 300);
  579. //$(divGroup).focus();
  580. isEverythingOkay = false;
  581. }
  582. } else if ($(this).hasClass('maximum_form')) {
  583. input = $(this).children('input')[0];
  584. if (isNaN($(input).val())) {
  585. alert = $('<div/>', {
  586. 'class': 'alert alert-danger alert-dismissible',
  587. 'role': 'alert'
  588. })
  589. button = $('<button/>', {
  590. 'type': 'button',
  591. 'class': 'close',
  592. 'data-dismiss': 'alert',
  593. 'alert-label': 'close'
  594. }).html('<span aria-hidden="true">×</span>');
  595. alert.append(button);
  596. alert.append('<strong>Write a valid number for maximum score</strong>')
  597. $(this).prepend(alert);
  598. $('html, body').animate({
  599. scrollTop: $(alert).offset().top
  600. }, 300);
  601. //$(divGroup).focus();
  602. isEverythingOkay = false;
  603. }
  604. } else if ($(this).hasClass('number_of_scales')) {
  605. btn_group = $(this).children('div.btn-group')[0];
  606. select = $(btn_group).children('select')[0];
  607. if (isNaN($(select).val())) {
  608. alert = $('<div/>', {
  609. 'class': 'alert alert-danger alert-dismissible',
  610. 'role': 'alert'
  611. })
  612. button = $('<button/>', {
  613. 'type': 'button',
  614. 'class': 'close',
  615. 'data-dismiss': 'alert',
  616. 'alert-label': 'close'
  617. }).html('<span aria-hidden="true">×</span>');
  618. alert.append(button);
  619. alert.append('<strong>Select a valid number</strong>')
  620. $(this).prepend(alert);
  621. $('html, body').animate({
  622. scrollTop: $(alert).offset().top
  623. }, 300);
  624. //$(divGroup).focus();
  625. isEverythingOkay = false;
  626. }
  627. } else if ($(this).hasClass('scales_form')) {
  628. //amount_of_scales = parseInt($(this).data('value'));
  629. $.each($(this).children('div'), function() {
  630. form_group = $(this).children('div.form-group')[0];
  631. textarea = $(form_group).children('textarea')[0];
  632. if ($(textarea).val() == '') {
  633. alert = $('<div/>', {
  634. 'class': 'alert alert-danger alert-dismissible',
  635. 'role': 'alert'
  636. })
  637. button = $('<button/>', {
  638. 'type': 'button',
  639. 'class': 'close',
  640. 'data-dismiss': 'alert',
  641. 'alert-label': 'close'
  642. }).html('<span aria-hidden="true">×</span>');
  643. alert.append(button);
  644. alert.append('<strong>Make sure to fill this scale</strong>')
  645. $(form_group).prepend(alert);
  646. $('html, body').animate({
  647. scrollTop: $(alert).offset().top
  648. }, 300);
  649. //$(divGroup).focus();
  650. isEverythingOkay = false;
  651. }
  652. })
  653. } else return;
  654. })
  655. if (!isEverythingOkay)
  656. e.preventDefault();
  657. } else e.preventDefault();
  658. })
  659. /*$(document).on('submit', '#update_criterion', function(e) {
  660. if (e.originalEvent.submitter.id != "update_the_criterion_button")
  661. e.preventDefault();
  662. })*/
  663. visibleProgram = {};
  664. visibleProgram["allAssocOutcomes"] = {}
  665. visibleProgram["allOutcomes"] = {}
  666. function visiblePrograms(allOutcomesDiv) {
  667. checkedPrograms = {}
  668. $('#' + allOutcomesDiv).parent().find('input:checkbox').each(function(index) {
  669. id = $(this).attr('id');
  670. if ($(this).is(':checked')) {
  671. checkedPrograms[$(this).attr('id')] = 1;
  672. $(this).prop("checked", false);
  673. }
  674. program_id = $(this).val();
  675. if (!(program_id in visibleProgram[allOutcomesDiv])) {
  676. visibleProgram[allOutcomesDiv][program_id] = {};
  677. }
  678. visibleProgram[allOutcomesDiv][program_id]["checkbox"] = $(this).detach();
  679. $("label[for='" + id + "']").next('br').remove();
  680. visibleProgram[allOutcomesDiv][program_id]["label"] = $("label[for='" + id + "']").detach();
  681. })
  682. if (allOutcomesDiv == "allOutcomes") {
  683. $('#' + allOutcomesDiv).parent().find("select[name='objective[]']").each(function(index) {
  684. //program_ids in objective
  685. var the_programs = $(this).find(':selected').data('program-ids');
  686. if (!the_programs) return;
  687. for (index in the_programs) {
  688. program_id = the_programs[index];
  689. //if the program_id is inside the visibleProgram scope
  690. //and the checkbox isnt alread present
  691. if (program_id in visibleProgram[allOutcomesDiv] &&
  692. !($('#program-checkboxes').find('#' + visibleProgram[allOutcomesDiv][program_id][
  693. 'checkbox'
  694. ].attr('id')).val())) {
  695. //if it was checked, check it again
  696. id = visibleProgram[allOutcomesDiv][program_id]['checkbox'].attr('id');
  697. if (checkedPrograms[id]) {
  698. visibleProgram[allOutcomesDiv][program_id]['checkbox'].prop('checked', true);
  699. }
  700. visibleProgram[allOutcomesDiv][program_id]['checkbox'].appendTo('#program-checkboxes');
  701. visibleProgram[allOutcomesDiv][program_id]['label'].appendTo("#program-checkboxes");
  702. $('#program-checkboxes').append('<br>');
  703. }
  704. }
  705. })
  706. } else {
  707. $('#' + allOutcomesDiv).find("select[name='objective[]']").each(function(index) {
  708. var the_programs = $(this).find(':selected').data('program-ids');
  709. if (!the_programs) return;
  710. for (index in the_programs) {
  711. program_id = the_programs[index];
  712. if (program_id in visibleProgram[allOutcomesDiv] &&
  713. !($('#assoc-program-checkboxes').find('#' + visibleProgram[allOutcomesDiv][program_id][
  714. 'checkbox'
  715. ].attr('id')).val())) {
  716. id = visibleProgram[allOutcomesDiv][program_id]['checkbox'].attr('id');
  717. if (checkedPrograms[id]) {
  718. visibleProgram[allOutcomesDiv][program_id]['checkbox'].prop('checked', true);
  719. }
  720. visibleProgram[allOutcomesDiv][program_id]['checkbox'].appendTo(
  721. '#assoc-program-checkboxes');
  722. visibleProgram[allOutcomesDiv][program_id]['label'].appendTo(
  723. "#assoc-program-checkboxes");
  724. $('#assoc-program-checkboxes').append('<br>');
  725. }
  726. }
  727. })
  728. }
  729. }
  730. function addOptions(select, max, scaleDiv) {
  731. var maxscore = parseInt($('#' + max).val())
  732. options = '<option value = "1"> 1</option>';
  733. selectedValue = 1;
  734. valueBefore = 0;
  735. for (var i = 2; i <= 20; i++) {
  736. if (maxscore % i == 0) {
  737. options += '<option value="' + i.toString() + '">' + i.toString() + '</option>';
  738. }
  739. }
  740. var previousvalue = parseInt($('#' + select).val());
  741. $('#' + select).html(options);
  742. $('#' + select).val(previousvalue);
  743. $('#' + select).selectpicker('refresh');
  744. $('#' + select).trigger('change');
  745. }
  746. function numberOfAssoc(string, Scales) {
  747. var maximum = $('#assoc_maximum_score').val();
  748. var amountOfScale = parseInt($('#' + string).val());
  749. var dataValue = parseInt($('#' + Scales).attr('data-value'));
  750. var division = maximum / amountOfScale;
  751. //add
  752. fullDiv = '';
  753. if (division == 1) {
  754. for (var i = 0; i < amountOfScale; i++) {
  755. div = '<div id="assoc_eval' + i.toString() + Scales + '">' +
  756. '<div class ="form-group">' +
  757. '<label for ="assoc_descripcion' + i.toString() + '">Scale Description (' + (i + 1) + ')</label>' +
  758. '<textarea id = "assoc_scale_' + i +
  759. '" class="form-control" rows="2" aria-labelledby="assoc_descripcion' + i.toString() +
  760. '" name="Scales[]" cols="50" ></textarea></div></div>';
  761. fullDiv += div;
  762. }
  763. } else if (division == maximum) {
  764. div = '<div id="assoc_eval' + 0 + Scales + '">' +
  765. '<div class ="form-group">' +
  766. '<label for ="assoc_descripcion' + 0 + '">Scale Description (' + 1 + ' - ' + maximum + ') </label>' +
  767. '<textarea id = "assoc_scale_' + 0 +
  768. '" class="form-control" rows="2" aria-labelledby="assoc_descripcion' + 0 +
  769. '" name="Scales[]" cols="50" ></textarea></div></div>';
  770. fullDiv += div;
  771. } else {
  772. for (var i = 0; i < amountOfScale; i++) {
  773. div = '<div id="assoc_eval' + i.toString() + Scales + '">' +
  774. '<div class ="form-group">' +
  775. '<label for ="assoc_descripcion' + i.toString() + '">Scale Description (' + (1 + (i * division)) +
  776. ' - ' + ((1 + i) * division) + ')</label>' +
  777. '<textarea id = "assoc_scale_' + i +
  778. '" class="form-control" rows="2" aria-labelledby="assoc_descripcion' + i.toString() +
  779. '" name="Scales[]" cols="50" ></textarea></div></div>';
  780. fullDiv += div;
  781. }
  782. }
  783. $('#' + Scales).html(fullDiv);
  784. $('#' + Scales).attr('data-value', amountOfScale);
  785. }
  786. //add
  787. function numberOfScales(string, Scales) {
  788. var maximum = parseInt($('#maximum_score').val());
  789. var amountOfScale = parseInt($('#' + string).val());
  790. var dataValue = parseInt($('#' + Scales).attr('data-value'));
  791. var division = maximum / amountOfScale;
  792. //add
  793. fullDiv = '';
  794. if (division == 1) {
  795. for (var i = 0; i < amountOfScale; i++) {
  796. div = '<div id="eval' + i.toString() + Scales + '">' +
  797. '<div class ="form-group">' +
  798. '<label id = "label_for_des' + i.toString() + '" for ="descripcion' + i.toString() +
  799. '">Scale Description (' + (i + 1) + ')</label>' +
  800. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="' +
  801. Scales + '[]" cols="50" ></textarea></div></div>';
  802. fullDiv += div;
  803. }
  804. } else if (division == maximum) {
  805. div = '<div id="eval' + 0 + Scales + '">' +
  806. '<div class ="form-group">' +
  807. '<label id = "label_for_des' + 0 + '" for ="descripcion' + 0 + '">Scale Description (' + 1 + ' - ' +
  808. maximum + ')</label>' +
  809. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + 0 + '" name="' + Scales +
  810. '[]" cols="50" ></textarea></div></div>';
  811. fullDiv += div;
  812. } else {
  813. for (var i = 0; i < amountOfScale; i++) {
  814. div = '<div id="eval' + i.toString() + Scales + '">' +
  815. '<div class ="form-group">' +
  816. '<label id = "label_for_des' + i.toString() + '" for ="descripcion' + i.toString() +
  817. '">Scale Description (' + (1 + (i * division)) + ' - ' + ((1 + i) * division) + ')</label>' +
  818. '<textarea class="form-control" rows="2" aria-labelledby="descripcion' + i.toString() + '" name="' +
  819. Scales + '[]" cols="50" ></textarea></div></div>';
  820. fullDiv += div;
  821. }
  822. }
  823. $('#' + Scales).html(fullDiv);
  824. $('#' + Scales).attr('data-value', amountOfScale);
  825. }
  826. $('.filterSection').show();
  827. $('.filterButton').on('click', function() {
  828. var span = $(this).find('span');
  829. if (span.attr('class') == 'glyphicon glyphicon-plus') {
  830. span.attr('class', 'glyphicon glyphicon-minus');
  831. } else {
  832. span.attr('class', 'glyphicon glyphicon-plus');
  833. }
  834. $('.filterSection').toggle(533);
  835. });
  836. //Add outcome Button
  837. function addOutcomeTest() {
  838. counter = parseInt($('#outcomeGroup0').data("value"));
  839. var $select = $('<select/>', {
  840. 'class': "selectpicker form-control",
  841. 'name': "outcome[]",
  842. 'data-live-search': 'true',
  843. 'id': 'outcome' + counter.toString(),
  844. 'onchange': 'fetchObjectiveForSelect("outcome' + counter + '", "objectiveGroupFor' + counter + '")'
  845. });
  846. var $div = $('<div/>', {
  847. 'id': 'outcomeForm' + counter.toString(),
  848. 'class': 'form-group col-md-11 selectOutcome'
  849. }).html("<label>Outcome " + (counter + 1) + "</label>");
  850. var $divForButton = $('<div/>', {
  851. 'class': 'col-md-1',
  852. 'id': 'close' + counter.toString()
  853. });
  854. var $button = $('<button/>', {
  855. 'type': 'button',
  856. 'class': 'btn btn-primary',
  857. 'onclick': '$(this).parent().parent().remove();'
  858. });
  859. var divForGroup = $('<div/>', {
  860. 'id': 'outcomeGroup' + counter.toString(),
  861. 'class': 'createOutcome'
  862. });
  863. var objectiveGroup = $('<div/>', {
  864. 'id': 'objectiveGroupFor' + counter,
  865. 'class': 'createObjective',
  866. 'data-value': '1'
  867. });
  868. var form_group_for_objective = $('<div/>', {
  869. 'class': 'form-group col-md-11 selectObjective'
  870. }).html('<label>Associated Objectives for Outcome ' + (counter + 1) + '</label>');
  871. var $select_objective = $('<select/>', {
  872. 'class': "selectpicker form-control",
  873. 'name': "objective[]",
  874. 'data-live-search': 'true',
  875. 'id': 'objective_' + counter + '_counter_1',
  876. 'onchange': "visiblePrograms('allOutcomes')"
  877. });
  878. var empty_div = $('<div/>', {
  879. 'class': 'col-md-1'
  880. });
  881. var button_for_add = $('<button/>', {
  882. 'class': 'btn btn-md btn-secondary button-add-objective',
  883. 'onclick': 'addObjectiveTest("objectiveGroupFor' + counter + '", "objective_' + counter + '")'
  884. }).html("<span class='glyphicon glyphicon-plus'></span>Add another Objective");
  885. divForGroup.append($div)
  886. $button.append('X');
  887. $divForButton.append($button);
  888. $('#allOutcomes').append(divForGroup);
  889. $select.append(selectOptions);
  890. $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
  891. $('#outcomeGroup0').data("value", (counter + 1));
  892. divForGroup.append($divForButton);
  893. form_group_for_objective.append($select_objective)
  894. objectiveGroup.append(form_group_for_objective);
  895. objectiveGroup.append(empty_div);
  896. //objectiveGroup.append(button_for_add);
  897. divForGroup.append(objectiveGroup);
  898. divForGroup.append(button_for_add);
  899. divForGroup.append('<hr>');
  900. fetchObjectiveForSelect('outcome' + counter, "objectiveGroupFor" + counter);
  901. $select_objective.selectpicker('refresh');
  902. }
  903. //Delete Outcome and OptGroup associated
  904. function deleteLast(outcomeForm, outcomeDiv, closeButton, objectiveGroup) {
  905. $div = document.getElementById(outcomeForm);
  906. $div.remove();
  907. $div = document.getElementById(closeButton);
  908. $div.remove();
  909. if (outcomeDiv == 'outcomeGroup') {
  910. $('#' + outcomeDiv).data('value', parseInt($('#' + outcomeDiv).data('value')) - 1);
  911. fetchObjectiveForSelect(outcomeDiv, objectiveGroup);
  912. }
  913. }
  914. //Delete Objective
  915. function deleteObjective(objectiveForm, closeObj, objectiveGroup, allOutcomes) {
  916. $div = document.getElementById(objectiveForm);
  917. $div.remove();
  918. $div = document.getElementById(closeObj);
  919. $div.remove();
  920. counter = parseInt($('#' + objectiveGroup).data("value"));
  921. $('#' + objectiveGroup).data("value", counter - 1);
  922. visiblePrograms(allOutcomes);
  923. }
  924. //Add objective when editing
  925. function addAssocObjective(objForGroup, originalObjective) {
  926. counter = $("#" + objForGroup).data('value');
  927. selectObj = document.getElementById(originalObjective + '_counter_1').innerHTML;
  928. assocObjectiveCounter = parseInt($('#' + objForGroup).data('value'));
  929. var $select = $('<select/>', {
  930. 'class': "selectpicker form-control",
  931. 'name': "objective[]",
  932. 'data-live-search': 'true',
  933. 'id': originalObjective + '_counter_' + (assocObjectiveCounter + 1).toString(),
  934. 'onchange': "visiblePrograms('allAssocOutcomes')"
  935. });
  936. var $div = $('<div/>', {
  937. 'id': 'assoc_objectiveForm_' + objForGroup + '_' + assocObjectiveCounter.toString(),
  938. 'class': 'form-group col-md-10 selectObjective'
  939. });
  940. var $divForButton = $('<div/>', {
  941. 'class': 'col-md-2',
  942. 'id': 'assoc_closeObj_' + objForGroup + '_' + assocObjectiveCounter.toString()
  943. });
  944. var $button = $('<button/>', {
  945. 'type': 'button',
  946. 'class': 'btn btn-primary',
  947. 'onclick': 'deleteObjective("assoc_objectiveForm_' + objForGroup + '_' + assocObjectiveCounter
  948. .toString() + '", "assoc_closeObj_' + objForGroup + '_' + assocObjectiveCounter.toString() +
  949. '", "' + objForGroup + '", "allAssocOutcomes")'
  950. });
  951. $button.append('X');
  952. $divForButton.append($button);
  953. $div.appendTo('#' + objForGroup)
  954. $select.append(selectObj);
  955. $select.appendTo($div).selectpicker('refresh');
  956. //$('#assoc_objectiveGroup').data("value", assocObjectiveCounter +1);
  957. $divForButton.appendTo('#' + objForGroup);
  958. $('#' + objForGroup).data('value', counter + 1);
  959. }
  960. //Add objective when creating a criteria
  961. function addObjectiveTest(objForGroup, originalObjective) {
  962. counter = $('#' + objForGroup).data('value');
  963. selectObj = document.getElementById(originalObjective + '_counter_1').innerHTML;
  964. var $select = $('<select/>', {
  965. 'class': "selectpicker form-control",
  966. 'name': "objective[]",
  967. 'data-live-search': 'true',
  968. 'id': originalObjective + '_counter_' + (counter + 1).toString(),
  969. 'onchange': "visiblePrograms('allOutcomes')"
  970. });
  971. var $div = $('<div/>', {
  972. 'id': 'objectiveForm_' + objForGroup + '_' + counter.toString(),
  973. 'class': 'form-group col-md-10 selectObjective'
  974. });
  975. var $divForButton = $('<div/>', {
  976. 'class': 'col-md-2',
  977. 'id': 'closeObj_' + objForGroup + '_' + counter.toString()
  978. });
  979. var $button = $('<button/>', {
  980. 'type': 'button',
  981. 'class': 'btn btn-primary',
  982. 'onclick': 'deleteObjective("objectiveForm_' + objForGroup + '_' + counter.toString() +
  983. '", "closeObj_' + objForGroup + '_' + counter.toString() + '", "' + objForGroup +
  984. '", "allOutcomes")'
  985. });
  986. $button.append('X');
  987. $divForButton.append($button);
  988. $div.appendTo('#' + objForGroup)
  989. $select.append(selectObj);
  990. $select.appendTo($div).selectpicker('refresh');
  991. $divForButton.appendTo('#' + objForGroup);
  992. $('#' + objForGroup).data('value', counter + 1);
  993. }
  994. //Create outcome for editing
  995. var assocOutcomeCounter = 0;
  996. //if it was from a fetched criteria, dont fetch the outcome data
  997. function addAssocOutcome(fetchedCriterion = null) {
  998. assocOutcomeCounter = parseInt($('#assocOutcomeGroup0').data('value'));
  999. var $select = $('<select/>', {
  1000. 'class': "selectpicker form-control",
  1001. 'name': "outcome[]",
  1002. 'data-live-search': 'true',
  1003. 'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
  1004. 'onchange': 'fetchObjectiveForSelect("assoc_outcome_' + assocOutcomeCounter.toString() +
  1005. '", "assoc_objectiveGroupFor' + assocOutcomeCounter + '")'
  1006. });
  1007. var $div = $('<div/>', {
  1008. 'id': 'assoc_outcomeForm' + assocOutcomeCounter.toString(),
  1009. 'class': 'form-group col-md-11 selectOutcome'
  1010. }).html("<label>Outcome " + (assocOutcomeCounter + 1) + "</label>");
  1011. var $divForButton = $('<div/>', {
  1012. 'class': 'col-md-1',
  1013. 'id': 'assoc_close' + assocOutcomeCounter.toString()
  1014. });
  1015. var $button = $('<button/>', {
  1016. 'type': 'button',
  1017. 'class': 'btn btn-primary',
  1018. 'id': 'assoc_close_button' + assocOutcomeCounter,
  1019. 'onclick': '$(this).parent().parent().remove(); visiblePrograms("allAssocOutcomes")'
  1020. });
  1021. var divForGroup = $('<div/>', {
  1022. 'id': 'assocOutcomeGroup' + assocOutcomeCounter.toString(),
  1023. 'class': 'createOutcome'
  1024. });
  1025. var objectiveGroup = $('<div/>', {
  1026. 'id': 'assoc_objectiveGroupFor' + assocOutcomeCounter,
  1027. 'class': 'createObjective',
  1028. 'data-value': '1'
  1029. });
  1030. var form_group_for_objective = $('<div/>', {
  1031. 'class': 'form-group col-md-11 selectObjective'
  1032. }).html('<label>Associated Objectives for Outcome ' + (assocOutcomeCounter + 1) + '</label>');
  1033. var $select_objective = $('<select/>', {
  1034. 'class': "selectpicker form-control",
  1035. 'name': "objective[]",
  1036. 'data-live-search': 'true',
  1037. 'id': 'assoc_objective_' + assocOutcomeCounter + '_counter_1',
  1038. 'onchange': "visiblePrograms('allAssocOutcomes')"
  1039. });
  1040. var empty_div = $('<div/>', {
  1041. 'class': 'col-md-1'
  1042. });
  1043. var button_for_add = $('<button/>', {
  1044. 'class': 'btn btn-md btn-secondary button-add-objective',
  1045. 'onclick': 'addAssocObjective("assoc_objectiveGroupFor' + assocOutcomeCounter +
  1046. '", "assoc_objective_' + assocOutcomeCounter + '")'
  1047. }).html("<span class='glyphicon glyphicon-plus'></span>Add another Objective");
  1048. divForGroup.append($div)
  1049. $button.append('X');
  1050. $divForButton.append($button);
  1051. $('#allAssocOutcomes').append(divForGroup);
  1052. //$div.appendTo('#assocOutcomeGroup')
  1053. $select.append(selectOptions);
  1054. $select.appendTo('#assoc_outcomeForm' + assocOutcomeCounter.toString()).selectpicker('refresh');
  1055. //assocOutcomeCounter += 1;
  1056. $('#assocOutcomeGroup0').data('value', assocOutcomeCounter + 1);
  1057. //$divForButton.appendTo('#assocOutcomeGroup');
  1058. divForGroup.append($divForButton);
  1059. form_group_for_objective.append($select_objective)
  1060. objectiveGroup.append(form_group_for_objective);
  1061. objectiveGroup.append(empty_div);
  1062. //objectiveGroup.append(button_for_add);
  1063. divForGroup.append(objectiveGroup);
  1064. divForGroup.append(button_for_add);
  1065. divForGroup.append('<hr>');
  1066. if (!fetchedCriterion) fetchObjectiveForSelect('assoc_outcome_' + assocOutcomeCounter,
  1067. 'assoc_objectiveGroupFor' +
  1068. assocOutcomeCounter);
  1069. $select_objective.selectpicker('refresh');
  1070. }
  1071. //Fetch associated objective for editing
  1072. var assocObjectiveCounter = 1;
  1073. /* function fetchAssocObjective(outcomeDiv, objectiveGroup) {
  1074. var count = $('#' + outcomeDiv).data('value');
  1075. var allOutcomes = [];
  1076. $("#" + outcomeDiv + ' select').each(function() {
  1077. allOutcomes.push(this.value);
  1078. })
  1079. var allObjectives = [];
  1080. $("#" + objectiveGroup + ' select').each(function() {
  1081. var temp = {
  1082. id: this.id,
  1083. value: this.value
  1084. }
  1085. allObjectives.push(temp);
  1086. })
  1087. $.post(
  1088. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  1089. allOutcomes: allOutcomes
  1090. },
  1091. function(varArray) {
  1092. optionName = '<option value ="0">Nothing Selected</option>';
  1093. for (outcome in varArray.outcomes) {
  1094. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '">';
  1095. var objectiveForOutcome = varArray.objectives;
  1096. var objectives = objectiveForOutcome[outcome];
  1097. for (objective in objectives) {
  1098. var obj = objectives[objective];
  1099. var option = '<option value ="' + obj.id + '">' + obj.text + '</option>';
  1100. optionName += (option);
  1101. }
  1102. optionName += '</optgroup>';
  1103. }
  1104. $('#assoc_objective_0').html(optionName);
  1105. $('#assoc_objective_0').selectpicker('refresh');
  1106. if ($("#assoc_objective_0 option[value='" + allObjectives[0].value + "']").length > 0) {
  1107. $("#assoc_objective_0").val(allObjectives[0].value);
  1108. $('#assoc_objective_0').selectpicker('refresh');
  1109. }
  1110. for (var i = allObjectives.length - 1; i > 0; i--) {
  1111. deleteObjective('assoc_objectiveForm_' + objectiveGroup +'_'+i, 'assoc_closeObj_'+objectiveGroup+'_' + i.toString(), objectiveGroup);
  1112. }
  1113. /*for (var i = 1; i < allObjectives.length; i++) {
  1114. addAssocObjective();
  1115. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  1116. if ($("#assoc_objective_" + i.toString() + " option[value='" + allObjectives[i].value + "']").length > 0) {
  1117. $("#assoc_objective_" + i.toString()).val(allObjectives[i].value);
  1118. $("#assoc_objective_" + i.toString()).selectpicker("refresh");
  1119. }
  1120. }
  1121. },
  1122. 'json'
  1123. );
  1124. }*/
  1125. //Fetch objective at creating criteria
  1126. counterForPost = 0;
  1127. function fetchObjectiveForSelect(outcome, objectiveGroup) {
  1128. outcomeID = $('#' + outcome).val();
  1129. var allObjectives = [];
  1130. $("#" + objectiveGroup + ' select').each(function() {
  1131. var temp = {
  1132. id: this.id,
  1133. value: this.value
  1134. }
  1135. allObjectives.push(temp);
  1136. })
  1137. $.post(
  1138. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  1139. outcomeID: outcomeID
  1140. },
  1141. function(varArray) {
  1142. counterOutcome = 0;
  1143. optionName = '<option value ="0">Nothing Selected</option>';
  1144. for (index in varArray) {
  1145. objectiveObject = varArray[index];
  1146. optionName += '<option data-program-ids = "' + objectiveObject.program_ids + '" value ="(' +
  1147. objectiveObject.outcome_id + ',' + objectiveObject.objective_id + ')">' +
  1148. objectiveObject.text + '</option>';
  1149. }
  1150. /*
  1151. for(outcome in varArray.outcomes){
  1152. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '">';
  1153. var objectiveForOutcome = varArray.objectives;
  1154. var objectives = objectiveForOutcome[outcome];
  1155. for (objective in varArray.objectives[outcome]) {
  1156. var obj= objectives[objective];
  1157. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  1158. optionName += (option);
  1159. }
  1160. optionName += "</optgroup>";
  1161. }*/
  1162. for (index in allObjectives) {
  1163. id = allObjectives[index].id
  1164. $('#' + id).html(optionName);
  1165. $('#' + id).selectpicker('refresh');
  1166. }
  1167. /*$('#objective_0').html(optionName);
  1168. $('#objective_0').selectpicker('refresh');
  1169. if($("#objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  1170. $("#objective_0").val(allObjectives[0].value);
  1171. $('#objective_0').selectpicker('refresh');
  1172. }
  1173. for (var i = allObjectives.length - 1; i > 0; i--) {
  1174. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString(), 'objectiveGroup');
  1175. }
  1176. for(var i =1; i<allObjectives.length; i++){
  1177. addObjectiveTest();
  1178. $('#objective_'+i.toString()).selectpicker('refresh');
  1179. if($("#objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  1180. $("#objective_"+i.toString()).val(allObjectives[i].value);
  1181. $("#objective_"+i.toString()).selectpicker("refresh");
  1182. }
  1183. }*/
  1184. },
  1185. 'json'
  1186. );
  1187. }
  1188. //after post
  1189. //For editing criterion
  1190. function fetchAllCriterion(program, outcome) {
  1191. var program_id_fetch = $('#' + program).find(':selected').val();
  1192. var outcome_fetch = $('#' + outcome).find(':selected').val();
  1193. $.post(
  1194. "{{ URL::action('CriteriaController@fetchAllCriterion') }}", {
  1195. program_fetch: program_id_fetch,
  1196. outcome_fetch: outcome_fetch
  1197. },
  1198. function(json) {
  1199. json_length = (json.criterion.length);
  1200. fullHTML = '';
  1201. for (var i = 0; i < json_length; i++) {
  1202. fullHTML += '<option value="' + json.criterion[i].id + '">' + json.criterion[i].name +
  1203. '</option>';
  1204. }
  1205. $('#select-criterion').html(fullHTML);
  1206. $('#select-criterion').selectpicker('refresh');
  1207. fetchCriterionForEditing()
  1208. },
  1209. 'json'
  1210. );
  1211. }
  1212. function deleteCriterion() {
  1213. var id = $('#select-criterion').find(':selected').val()
  1214. $.post(
  1215. "{{ URL::action('CriteriaController@delete') }}", {
  1216. id: id
  1217. },
  1218. function() {
  1219. window.location.reload(true)
  1220. }
  1221. )
  1222. }
  1223. </script>
  1224. @stop
  1225. @section('javascript')
  1226. // --------------------------------------------------------------------------
  1227. // Page load
  1228. // --------------------------------------------------------------------------
  1229. // Hide accordion panel contents by default
  1230. $('.panel-group .panel-body').hide();
  1231. $('#outcome-display').parent().hide();
  1232. fetchCriterionForEditing();
  1233. fetchObjectiveForSelect('outcome0', 'objectiveGroupFor0');
  1234. // setCriterionStatus();
  1235. fetchAllCriterion("select-program", "assoc_outcomes_fetch");
  1236. visiblePrograms('allOutcomes');
  1237. // --------------------------------------------------------------------------
  1238. // Functions
  1239. // --------------------------------------------------------------------------
  1240. $('#button-add-outcome').on('click', function(e) {
  1241. // Prevent the default action of the clicked item. In this case that is submit
  1242. e.preventDefault();
  1243. return false;
  1244. });
  1245. $('.filterButton').on('click', function(e) {
  1246. // Prevent the default action of the clicked item. In this case that is submit
  1247. e.preventDefault();
  1248. return false;
  1249. });
  1250. $('.button-add-objective-assoc').on('click', function(e) {
  1251. // Prevent the default action of the clicked item. In this case that is submit
  1252. e.preventDefault();
  1253. return false;
  1254. });
  1255. $('#button-add-outcome-assoc').on('click', function(e) {
  1256. // Prevent the default action of the clicked item. In this case that is submit
  1257. e.preventDefault();
  1258. return false;
  1259. });
  1260. $('.button-add-objective').on('click', function(e) {
  1261. // Prevent the default action of the clicked item. In this case that is submit
  1262. e.preventDefault();
  1263. return false;
  1264. });
  1265. // Fetch criterion info for editing
  1266. // --------------------------------------------------------------------------
  1267. // Events
  1268. // --------------------------------------------------------------------------
  1269. // When panel heading is clicked, toggle it
  1270. $('.panel-group .panel-heading').on('click', function()
  1271. {
  1272. $(this).next().stop().slideToggle();
  1273. })
  1274. //$('#outcome[0]').on('change', function(){
  1275. //$('.selectpicker').selectpicker('refresh');
  1276. //})
  1277. // When list item is clicked, load corresponding info
  1278. // When list item is clicked, load corresponding info
  1279. $('.selectpicker').on('change', function()
  1280. {
  1281. //alert($(this).find(':selected').val());
  1282. $('.selectpicker').selectpicker('refresh');
  1283. });
  1284. @stop