Keine Beschreibung

criteria.blade.php 67KB

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