Bez popisu

criteria.blade.php 67KB

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