No Description

criteria.blade.php 71KB

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