설명 없음

criteria.blade.php 73KB

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