No Description

criteria.blade.php 71KB

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