Nessuna descrizione

criteria.blade.php 73KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  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. 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. $('.filterButton').on('click', function() {
  602. var span = $(this).find('span');
  603. if (span.attr('class') == 'glyphicon glyphicon-plus') {
  604. span.attr('class', 'glyphicon glyphicon-minus');
  605. } else {
  606. span.attr('class', 'glyphicon glyphicon-plus');
  607. }
  608. $('.filterSection').toggle(533);
  609. });
  610. //Add outcome Button
  611. function addOutcomeTest() {
  612. counter = parseInt($('#outcomeGroup0').data("value"));
  613. var $select = $('<select/>', {
  614. 'class': "selectpicker form-control",
  615. 'name': "outcome[]",
  616. 'data-live-search': 'true',
  617. 'id': 'outcome' + counter.toString(),
  618. 'onchange': 'fetchObjectiveForSelect("outcome' + counter + '", "objectiveGroupFor' + counter + '")'
  619. });
  620. var $div = $('<div/>', {
  621. 'id': 'outcomeForm' + counter.toString(),
  622. 'class': 'form-group col-md-11 selectOutcome'
  623. }).html("<label>Outcome " + (counter + 1) + "</label>");
  624. var $divForButton = $('<div/>', {
  625. 'class': 'col-md-1',
  626. 'id': 'close' + counter.toString()
  627. });
  628. var $button = $('<button/>', {
  629. 'type': 'button',
  630. 'class': 'btn btn-primary',
  631. 'onclick': '$(this).parent().parent().remove();'
  632. });
  633. var divForGroup = $('<div/>', {
  634. 'id': 'outcomeGroup' + counter.toString(),
  635. 'class': 'createOutcome'
  636. });
  637. var objectiveGroup = $('<div/>', {
  638. 'id': 'objectiveGroupFor' + counter,
  639. 'class': 'createObjective',
  640. 'data-value': '1'
  641. });
  642. var form_group_for_objective = $('<div/>', {
  643. 'class': 'form-group col-md-11 selectObjective'
  644. }).html('<label>Associated Objectives for Outcome ' + (counter + 1) + '</label>');
  645. var $select_objective = $('<select/>', {
  646. 'class': "selectpicker form-control",
  647. 'name': "objective[]",
  648. 'data-live-search': 'true',
  649. 'id': 'objective_' + counter + '_counter_1',
  650. 'onchange': "visiblePrograms('allOutcomes')"
  651. });
  652. var empty_div = $('<div/>', {
  653. 'class': 'col-md-1'
  654. });
  655. var button_for_add = $('<button/>', {
  656. 'class': 'btn btn-md btn-secondary button-add-objective',
  657. 'onclick': 'addObjectiveTest("objectiveGroupFor' + counter + '", "objective_' + counter + '")'
  658. }).html("<span class='glyphicon glyphicon-plus'></span>Add another Objective");
  659. divForGroup.append($div)
  660. $button.append('X');
  661. $divForButton.append($button);
  662. $('#allOutcomes').append(divForGroup);
  663. $select.append(selectOptions);
  664. $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
  665. $('#outcomeGroup0').data("value", (counter + 1));
  666. divForGroup.append($divForButton);
  667. form_group_for_objective.append($select_objective)
  668. objectiveGroup.append(form_group_for_objective);
  669. objectiveGroup.append(empty_div);
  670. //objectiveGroup.append(button_for_add);
  671. divForGroup.append(objectiveGroup);
  672. divForGroup.append(button_for_add);
  673. divForGroup.append('<hr>');
  674. fetchObjectiveForSelect('outcome' + counter, "objectiveGroupFor" + counter);
  675. $select_objective.selectpicker('refresh');
  676. }
  677. //Delete Outcome and OptGroup associated
  678. function deleteLast(outcomeForm, outcomeDiv, closeButton, objectiveGroup) {
  679. $div = document.getElementById(outcomeForm);
  680. $div.remove();
  681. $div = document.getElementById(closeButton);
  682. $div.remove();
  683. if (outcomeDiv == 'outcomeGroup') {
  684. $('#' + outcomeDiv).data('value', parseInt($('#' + outcomeDiv).data('value')) - 1);
  685. fetchObjectiveForSelect(outcomeDiv, objectiveGroup);
  686. }
  687. }
  688. //Delete Objective
  689. function deleteObjective(objectiveForm, closeObj, objectiveGroup, allOutcomes) {
  690. $div = document.getElementById(objectiveForm);
  691. $div.remove();
  692. $div = document.getElementById(closeObj);
  693. $div.remove();
  694. counter = parseInt($('#' + objectiveGroup).data("value"));
  695. $('#' + objectiveGroup).data("value", counter - 1);
  696. visiblePrograms(allOutcomes);
  697. }
  698. //Add objective when editing
  699. function addAssocObjective(objForGroup, originalObjective) {
  700. counter = $("#" + objForGroup).data('value');
  701. selectObj = document.getElementById(originalObjective + '_counter_1').innerHTML;
  702. assocObjectiveCounter = parseInt($('#' + objForGroup).data('value'));
  703. var $select = $('<select/>', {
  704. 'class': "selectpicker form-control",
  705. 'name': "objective[]",
  706. 'data-live-search': 'true',
  707. 'id': originalObjective + '_counter_' + (assocObjectiveCounter + 1).toString(),
  708. 'onchange': "visiblePrograms('allAssocOutcomes')"
  709. });
  710. var $div = $('<div/>', {
  711. 'id': 'assoc_objectiveForm_' + objForGroup + '_' + assocObjectiveCounter.toString(),
  712. 'class': 'form-group col-md-10 selectObjective'
  713. });
  714. var $divForButton = $('<div/>', {
  715. 'class': 'col-md-2',
  716. 'id': 'assoc_closeObj_' + objForGroup + '_' + assocObjectiveCounter.toString()
  717. });
  718. var $button = $('<button/>', {
  719. 'type': 'button',
  720. 'class': 'btn btn-primary',
  721. 'onclick': 'deleteObjective("assoc_objectiveForm_' + objForGroup + '_' + assocObjectiveCounter
  722. .toString() + '", "assoc_closeObj_' + objForGroup + '_' + assocObjectiveCounter.toString() +
  723. '", "' + objForGroup + '", "allAssocOutcomes")'
  724. });
  725. $button.append('X');
  726. $divForButton.append($button);
  727. $div.appendTo('#' + objForGroup)
  728. $select.append(selectObj);
  729. $select.appendTo($div).selectpicker('refresh');
  730. //$('#assoc_objectiveGroup').data("value", assocObjectiveCounter +1);
  731. $divForButton.appendTo('#' + objForGroup);
  732. $('#' + objForGroup).data('value', counter + 1);
  733. }
  734. //Add objective when creating a criteria
  735. function addObjectiveTest(objForGroup, originalObjective) {
  736. counter = $('#' + objForGroup).data('value');
  737. selectObj = document.getElementById(originalObjective + '_counter_1').innerHTML;
  738. var $select = $('<select/>', {
  739. 'class': "selectpicker form-control",
  740. 'name': "objective[]",
  741. 'data-live-search': 'true',
  742. 'id': originalObjective + '_counter_' + (counter + 1).toString(),
  743. 'onchange': "visiblePrograms('allOutcomes')"
  744. });
  745. var $div = $('<div/>', {
  746. 'id': 'objectiveForm_' + objForGroup + '_' + counter.toString(),
  747. 'class': 'form-group col-md-10 selectObjective'
  748. });
  749. var $divForButton = $('<div/>', {
  750. 'class': 'col-md-2',
  751. 'id': 'closeObj_' + objForGroup + '_' + counter.toString()
  752. });
  753. var $button = $('<button/>', {
  754. 'type': 'button',
  755. 'class': 'btn btn-primary',
  756. 'onclick': 'deleteObjective("objectiveForm_' + objForGroup + '_' + counter.toString() +
  757. '", "closeObj_' + objForGroup + '_' + counter.toString() + '", "' + objForGroup +
  758. '", "allOutcomes")'
  759. });
  760. $button.append('X');
  761. $divForButton.append($button);
  762. $div.appendTo('#' + objForGroup)
  763. $select.append(selectObj);
  764. $select.appendTo($div).selectpicker('refresh');
  765. $divForButton.appendTo('#' + objForGroup);
  766. $('#' + objForGroup).data('value', counter + 1);
  767. }
  768. //Create outcome for editing
  769. var assocOutcomeCounter = 0;
  770. //if it was from a fetched criteria, dont fetch the outcome data
  771. function addAssocOutcome(fetchedCriterion = null) {
  772. assocOutcomeCounter = parseInt($('#assocOutcomeGroup0').data('value'));
  773. var $select = $('<select/>', {
  774. 'class': "selectpicker form-control",
  775. 'name': "outcome[]",
  776. 'data-live-search': 'true',
  777. 'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
  778. 'onchange': 'fetchObjectiveForSelect("assoc_outcome_' + assocOutcomeCounter.toString() +
  779. '", "assoc_objectiveGroupFor' + assocOutcomeCounter + '")'
  780. });
  781. var $div = $('<div/>', {
  782. 'id': 'assoc_outcomeForm' + assocOutcomeCounter.toString(),
  783. 'class': 'form-group col-md-11 selectOutcome'
  784. }).html("<label>Outcome " + (assocOutcomeCounter + 1) + "</label>");
  785. var $divForButton = $('<div/>', {
  786. 'class': 'col-md-1',
  787. 'id': 'assoc_close' + assocOutcomeCounter.toString()
  788. });
  789. var $button = $('<button/>', {
  790. 'type': 'button',
  791. 'class': 'btn btn-primary',
  792. 'id': 'assoc_close_button' + assocOutcomeCounter,
  793. 'onclick': '$(this).parent().parent().remove(); visiblePrograms("allAssocOutcomes")'
  794. });
  795. var divForGroup = $('<div/>', {
  796. 'id': 'assocOutcomeGroup' + assocOutcomeCounter.toString(),
  797. 'class': 'createOutcome'
  798. });
  799. var objectiveGroup = $('<div/>', {
  800. 'id': 'assoc_objectiveGroupFor' + assocOutcomeCounter,
  801. 'class': 'createObjective',
  802. 'data-value': '1'
  803. });
  804. var form_group_for_objective = $('<div/>', {
  805. 'class': 'form-group col-md-11 selectObjective'
  806. }).html('<label>Associated Objectives for Outcome ' + (assocOutcomeCounter + 1) + '</label>');
  807. var $select_objective = $('<select/>', {
  808. 'class': "selectpicker form-control",
  809. 'name': "objective[]",
  810. 'data-live-search': 'true',
  811. 'id': 'assoc_objective_' + assocOutcomeCounter + '_counter_1',
  812. 'onchange': "visiblePrograms('allAssocOutcomes')"
  813. });
  814. var empty_div = $('<div/>', {
  815. 'class': 'col-md-1'
  816. });
  817. var button_for_add = $('<button/>', {
  818. 'class': 'btn btn-md btn-secondary button-add-objective',
  819. 'onclick': 'addAssocObjective("assoc_objectiveGroupFor' + assocOutcomeCounter +
  820. '", "assoc_objective_' + assocOutcomeCounter + '")'
  821. }).html("<span class='glyphicon glyphicon-plus'></span>Add another Objective");
  822. divForGroup.append($div)
  823. $button.append('X');
  824. $divForButton.append($button);
  825. $('#allAssocOutcomes').append(divForGroup);
  826. //$div.appendTo('#assocOutcomeGroup')
  827. $select.append(selectOptions);
  828. $select.appendTo('#assoc_outcomeForm' + assocOutcomeCounter.toString()).selectpicker('refresh');
  829. //assocOutcomeCounter += 1;
  830. $('#assocOutcomeGroup0').data('value', assocOutcomeCounter + 1);
  831. //$divForButton.appendTo('#assocOutcomeGroup');
  832. divForGroup.append($divForButton);
  833. form_group_for_objective.append($select_objective)
  834. objectiveGroup.append(form_group_for_objective);
  835. objectiveGroup.append(empty_div);
  836. //objectiveGroup.append(button_for_add);
  837. divForGroup.append(objectiveGroup);
  838. divForGroup.append(button_for_add);
  839. divForGroup.append('<hr>');
  840. if (!fetchedCriterion) fetchObjectiveForSelect('assoc_outcome_' + assocOutcomeCounter,
  841. 'assoc_objectiveGroupFor' +
  842. assocOutcomeCounter);
  843. $select_objective.selectpicker('refresh');
  844. }
  845. //Fetch associated objective for editing
  846. var assocObjectiveCounter = 1;
  847. var assocObjectiveCounter = 1;
  848. /* function fetchAssocObjective(outcomeDiv, objectiveGroup) {
  849. var count = $('#'+outcomeDiv).data('value');
  850. var allOutcomes =[];
  851. $("#" + outcomeDiv + ' select').each(function() {
  852. allOutcomes.push( this.value);
  853. })
  854. var allObjectives = [];
  855. $("#" + objectiveGroup + ' select').each(function() {
  856. var temp = {
  857. id: this.id,
  858. value: this.value
  859. }
  860. allObjectives.push(temp);
  861. })
  862. $.post(
  863. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  864. allOutcomes: allOutcomes
  865. },
  866. function(varArray) {
  867. optionName = '<option value ="0">Nothing Selected</option>';
  868. for(outcome in varArray.outcomes){
  869. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '">';
  870. var objectiveForOutcome = varArray.objectives;
  871. var objectives = objectiveForOutcome[outcome];
  872. for (objective in objectives) {
  873. var obj= objectives[objective];
  874. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  875. optionName += (option);
  876. }
  877. optionName += '</optgroup>';
  878. }
  879. $('#assoc_objective_0').html(optionName);
  880. $('#assoc_objective_0').selectpicker('refresh');
  881. if($("#assoc_objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  882. $("#assoc_objective_0").val(allObjectives[0].value);
  883. $('#assoc_objective_0').selectpicker('refresh');
  884. }
  885. for (var i = allObjectives.length - 1; i > 0; i--) {
  886. deleteObjective('assoc_objectiveForm_' + objectiveGroup +'_'+i, 'assoc_closeObj_'+objectiveGroup+'_' + i.toString(), objectiveGroup);
  887. }
  888. for(var i=1; i<allObjectives.length; i++){
  889. addAssocObjective();
  890. $('#assoc_objective_'+i.toString()).selectpicker('refresh');
  891. if($("#assoc_objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  892. $("#assoc_objective_"+i.toString()).val(allObjectives[i].value);
  893. $("#assoc_objective_"+i.toString()).selectpicker("refresh");
  894. }
  895. }
  896. },
  897. 'json'
  898. );
  899. }*/
  900. //Fetch objective at creating criteria
  901. counterForPost = 0;
  902. function fetchObjectiveForSelect(outcome, objectiveGroup) {
  903. outcomeID = $('#' + outcome).val();
  904. var allObjectives = [];
  905. $("#" + objectiveGroup + ' select').each(function() {
  906. var temp = {
  907. id: this.id,
  908. value: this.value
  909. }
  910. allObjectives.push(temp);
  911. })
  912. $.post(
  913. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  914. outcomeID: outcomeID
  915. },
  916. function(varArray) {
  917. counterOutcome = 0;
  918. optionName = '<option value ="0">Nothing Selected</option>';
  919. for (index in varArray) {
  920. objectiveObject = varArray[index];
  921. optionName += '<option data-program-ids = "' + objectiveObject.program_ids + '" value ="(' +
  922. objectiveObject.outcome_id + ',' + objectiveObject.objective_id + ')">' +
  923. objectiveObject.text + '</option>';
  924. }
  925. /*
  926. for(outcome in varArray.outcomes){
  927. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '">';
  928. var objectiveForOutcome = varArray.objectives;
  929. var objectives = objectiveForOutcome[outcome];
  930. for (objective in varArray.objectives[outcome]) {
  931. var obj= objectives[objective];
  932. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  933. optionName += (option);
  934. }
  935. optionName += "</optgroup>";
  936. }*/
  937. for (index in allObjectives) {
  938. id = allObjectives[index].id
  939. $('#' + id).html(optionName);
  940. $('#' + id).selectpicker('refresh');
  941. }
  942. /*$('#objective_0').html(optionName);
  943. $('#objective_0').selectpicker('refresh');
  944. if($("#objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  945. $("#objective_0").val(allObjectives[0].value);
  946. $('#objective_0').selectpicker('refresh');
  947. }
  948. for (var i = allObjectives.length - 1; i > 0; i--) {
  949. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString(), 'objectiveGroup');
  950. }
  951. for(var i =1; i<allObjectives.length; i++){
  952. addObjectiveTest();
  953. $('#objective_'+i.toString()).selectpicker('refresh');
  954. if($("#objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  955. $("#objective_"+i.toString()).val(allObjectives[i].value);
  956. $("#objective_"+i.toString()).selectpicker("refresh");
  957. }
  958. }*/
  959. },
  960. 'json'
  961. );
  962. }
  963. //after post
  964. //For editing criterion
  965. function fetchAllCriterion(program, outcome) {
  966. var program_id_fetch = $('#' + program).find(':selected').val();
  967. var outcome_fetch = $('#' + outcome).find(':selected').val();
  968. $.post(
  969. "{{ URL::action('CriteriaController@fetchAllCriterion') }}", {
  970. program_fetch: program_id_fetch,
  971. outcome_fetch: outcome_fetch
  972. },
  973. function(json) {
  974. json_length = (json.criterion.length);
  975. fullHTML = '';
  976. for (var i = 0; i < json_length; i++) {
  977. fullHTML += '<option value="' + json.criterion[i].id + '">' + json.criterion[i].name +
  978. '</option>';
  979. }
  980. $('#select-criterion').html(fullHTML);
  981. $('#select-criterion').selectpicker('refresh');
  982. fetchCriterionForEditing()
  983. },
  984. 'json'
  985. );
  986. }
  987. function deleteCriterion() {
  988. var id = $('#select-criterion').find(':selected').val()
  989. $.post(
  990. "{{ URL::action('CriteriaController@delete') }}", {
  991. id: id
  992. },
  993. function() {
  994. window.location.reload(true)
  995. }
  996. )
  997. }
  998. function fetchCriterionForEditing() {
  999. var id = $('#select-criterion').find(':selected').val();
  1000. $.post(
  1001. "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
  1002. id: id
  1003. },
  1004. function(criterion) {
  1005. if (!(criterion.length)) {
  1006. name = ' ';
  1007. var subcriteria = '';
  1008. copyright = null;
  1009. notes = null;
  1010. $('#status').val(0);
  1011. maximum = 1;
  1012. $('#assoc_maximum_score').val(1);
  1013. } else {
  1014. criterion = criterion[0];
  1015. if (!(criterion.activity_criterion.length)) {
  1016. $('#DeleteButton').prop('disabled', false);
  1017. $("#update_the_criterion_button").val('Update');
  1018. $("#update_criterion").attr('action', "{{ URL::action('CriteriaController@update') }}")
  1019. } else {
  1020. $('#DeleteButton').prop('disabled', true);
  1021. $("#update_the_criterion_button").val("Create New")
  1022. $("#update_criterion").attr('action', "{{ URL::action('CriteriaController@create') }}")
  1023. $('#alert_placeholder').html(
  1024. '<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>'
  1025. );
  1026. }
  1027. var name = criterion.name;
  1028. if (criterion.subcriteria) {
  1029. subcriteria = JSON.parse(criterion.subcriteria).join('\n');
  1030. } else {
  1031. subcriteria = "";
  1032. }
  1033. if (criterion.copyright) {
  1034. var copyright = criterion.copyright;
  1035. } else {
  1036. var copyright = ''
  1037. }
  1038. if (criterion.notes) notes = criterion.notes;
  1039. else notes = '';
  1040. // Display info
  1041. $('#criterion_name').val(name);
  1042. $('#criterion_subcriteria').text(subcriteria);
  1043. if (criterion.deleted_at)
  1044. $('#status').val(0);
  1045. else
  1046. $('#status').val(1);
  1047. $('#assoc_maximum_score').val(criterion.max_score);
  1048. var maximum = criterion.max_score;
  1049. addOptions("Num_assoc_scale", "assoc_maximum_score", "Assoc_Scales");
  1050. $('#Num_assoc_scale').val(criterion.num_scales)
  1051. $('#Num_assoc_scale').selectpicker('refresh');
  1052. $('#Num_assoc_scale').trigger('change');
  1053. for (i = 0; i < criterion.num_scales; i++) {
  1054. $('#assoc_scale_' + i).val(criterion.scales[i].description);
  1055. }
  1056. // If copyright or notes aren't empty, load them
  1057. }
  1058. $('#criterion_copyright').text(copyright);
  1059. $('#criterion_notes').text(notes);
  1060. // Select associated outcome
  1061. try {
  1062. assocOutcomeCounter = parseInt($("#assocOutcomeGroup0").data('value'));
  1063. for (var i = assocOutcomeCounter - 1; i > 0; i--) {
  1064. $('#assoc_close_button' + i).click();
  1065. }
  1066. $('#assocOutcomeGroup0').data('value', 1);
  1067. } catch (err) {
  1068. var Notran = true;
  1069. }
  1070. if (criterion.outcomes.length) {
  1071. $('#assoc_outcome_0').val(criterion.outcomes[0].id);
  1072. $('#assoc_outcome_0').selectpicker('refresh');
  1073. var first_outcome = criterion.outcomes[0];
  1074. options = "<option value ='0'>Nothing Selected</option>";
  1075. $(first_outcome.assoc_objectives).each(function(index, objective) {
  1076. options += '<option data-program-ids = "' + objective.program_ids + '" value ="(' +
  1077. first_outcome.id + ',' + objective.objective_id + ')">' +
  1078. objective.text + '</option>';
  1079. })
  1080. /*for(objective_index in json.objectives_assoc[first_outcome_id]){
  1081. objective = json.objectives_assoc[first_outcome_id][objective_index]
  1082. options += '<option value ="('+first_outcome_id+','+objective.objective_id+')">'+
  1083. objective.text+'</option>';
  1084. }*/
  1085. $('#assoc_objective_0_counter_1').html(options);
  1086. $('#assoc_objective_0_counter_1').selectpicker('refresh');
  1087. if (first_outcome.objectives_criteria.length) {
  1088. objective_id = first_outcome.objectives_criteria[0].objective_id;
  1089. value = '(' + first_outcome.id + ',' + objective_id + ')';
  1090. $('#assoc_objective_0_counter_1').val(value);
  1091. $('#assoc_objective_0_counter_1').selectpicker('refresh');
  1092. }
  1093. if ($("#assoc_objectiveGroupFor0").find(".btn-primary").length > 0) {
  1094. $("#assoc_objectiveGroupFor0").find(".btn-primary").each(function() {
  1095. $(this).click()
  1096. })
  1097. }
  1098. for (var i = 1; i < first_outcome.objectives_criteria.length; i++) {
  1099. addAssocObjective("assoc_objectiveGroupFor0", "assoc_objective_0");
  1100. objective_id = first_outcome.objectives_criteria[i].objective_id;
  1101. value = "(" + first_outcome.id + "," + objective_id + ")";
  1102. $('#assoc_objective_0_counter_' + (i + 1)).val(value);
  1103. $('#assoc_objective_0_counter_' + (i + 1)).selectpicker('refresh');
  1104. }
  1105. } else {
  1106. $('#assoc_outcome_0').val($('#assoc_outcomes_fetch').find(':selected').val());
  1107. $('#assoc_outcome_0').selectpicker('refresh');
  1108. }
  1109. for (var i = 1; i < criterion.outcomes.length; i++) {
  1110. addAssocOutcome(true);
  1111. $('#assoc_outcome_' + i.toString()).val(criterion.outcomes[i].id);
  1112. $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
  1113. var outcome = criterion.outcomes[i];
  1114. options = "<option value ='0'>Nothing Selected</option>";
  1115. $(outcome.assoc_objectives).each(function(index, objective) {
  1116. options += '<option value ="(' + outcome.id + ',' + objective.objective_id + ')">' +
  1117. objective.text + '</option>';
  1118. })
  1119. //for(objective_index in json.objectives_assoc[outcome_id]){
  1120. // objective = json.objectives_assoc[outcome_id][objective_index]
  1121. // options += '<option value ="('+outcome_id+','+objective.objective_id+')">'+
  1122. // objective.text+'</option>';
  1123. // }
  1124. $('#assoc_objective_' + i + '_counter_1').html(options);
  1125. $('#assoc_objective_' + i + '_counter_1').selectpicker('refresh');
  1126. if (outcome.objectives_criteria.length) {
  1127. objective_id = outcome.objectives_criteria[0].objective_id;
  1128. value = "(" + outcome.id + "," + objective_id + ")"
  1129. $('#assoc_objective_' + i + '_counter_1').val(value);
  1130. $('#assoc_objective_' + i + '_counter_1').selectpicker('refresh')
  1131. }
  1132. for (var j = 1; j < outcome.objectives_criteria.length; j++) {
  1133. addAssocObjective("assoc_objectiveGroupFor" + i, "assoc_objective_" + i);
  1134. objective_id = outcome.objectives_criteria[j].objective_id;
  1135. value = "(" + outcome.id + "," + objective_id + ")";
  1136. $('#assoc_objective_' + i + '_counter_' + (j + 1)).val(value);
  1137. $('#assoc_objective_' + i + '_counter_' + (j + 1)).selectpicker('refresh');
  1138. }
  1139. }
  1140. visiblePrograms('allAssocOutcomes');
  1141. //counterObj =$('#assoc_objectiveGroup').data('value');
  1142. /*try {
  1143. for (var i = counterObj - 1; i > 0; i--) {
  1144. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup')
  1145. }
  1146. } catch (err) {
  1147. var noEntro = true;
  1148. }*/
  1149. //$('#assoc_objectiveGroup').data('value', 1);
  1150. /*
  1151. assocOutcomeCounter = 0;
  1152. var i = 0;
  1153. optionName = '<option value ="0">Nothing Selected</option>';
  1154. for(outcome in criterion.outcomes_assoc){
  1155. optionName += '<optgroup label="' + criterion.outcomes_assoc[outcome][0].name + '">';
  1156. var objectiveForOutcome = json.objectives_assoc;
  1157. var objectives = objectiveForOutcome[outcome];
  1158. for (objective in objectives) {
  1159. var obj= objectives[objective];
  1160. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  1161. optionName += (option);
  1162. }
  1163. optionName += "</optgroup>";
  1164. }
  1165. $('#assoc_objective_0').html(optionName);
  1166. $('#assoc_objective_0').selectpicker('refresh');
  1167. try {
  1168. $('#assoc_objective_0').val(json.objectives[0].id);
  1169. $('#assoc_objective_0').selectpicker('refresh');
  1170. } catch (err) {
  1171. if (!json.objectives.length) {
  1172. $('#assoc_objective_0').val(0);
  1173. $('#assoc_objective_0').selectpicker('refresh');
  1174. }
  1175. }
  1176. for (var i = 1; i < json.objectives.length; i++) {
  1177. addAssocObjective();
  1178. $('#assoc_objective_' + i.toString()).val(json.objectives[i].id);
  1179. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  1180. }
  1181. $('assoc_objectiveGroup').data('value',json.objectives.length);
  1182. */
  1183. // Select associated program
  1184. var program_length = criterion.program.length;
  1185. $('input[type=checkbox]').prop('checked', false);
  1186. for (var i = 0; i < program_length; i++) {
  1187. $('#assoc_program-' + criterion.program[i].program_id).prop("checked", true);
  1188. }
  1189. // Select status
  1190. }
  1191. );
  1192. }
  1193. </script>@stop
  1194. @section('javascript')
  1195. // --------------------------------------------------------------------------
  1196. // Page load
  1197. // --------------------------------------------------------------------------
  1198. // Hide accordion panel contents by default
  1199. $('.panel-group .panel-body').hide();
  1200. $('#outcome-display').parent().hide();
  1201. fetchCriterionForEditing();
  1202. fetchObjectiveForSelect('outcome0', 'objectiveGroupFor0');
  1203. // setCriterionStatus();
  1204. fetchAllCriterion("select-program", "assoc_outcomes_fetch");
  1205. visiblePrograms('allOutcomes');
  1206. // --------------------------------------------------------------------------
  1207. // Functions
  1208. // --------------------------------------------------------------------------
  1209. $('#button-add-outcome').on('click', function(e) {
  1210. // Prevent the default action of the clicked item. In this case that is submit
  1211. e.preventDefault();
  1212. return false;
  1213. });
  1214. $('.filterButton').on('click', function(e) {
  1215. // Prevent the default action of the clicked item. In this case that is submit
  1216. e.preventDefault();
  1217. return false;
  1218. });
  1219. $('.button-add-objective-assoc').on('click', function(e) {
  1220. // Prevent the default action of the clicked item. In this case that is submit
  1221. e.preventDefault();
  1222. return false;
  1223. });
  1224. $('#button-add-outcome-assoc').on('click', function(e) {
  1225. // Prevent the default action of the clicked item. In this case that is submit
  1226. e.preventDefault();
  1227. return false;
  1228. });
  1229. $('.button-add-objective').on('click', function(e) {
  1230. // Prevent the default action of the clicked item. In this case that is submit
  1231. e.preventDefault();
  1232. return false;
  1233. });
  1234. // Fetch criterion info for editing
  1235. // --------------------------------------------------------------------------
  1236. // Events
  1237. // --------------------------------------------------------------------------
  1238. // When panel heading is clicked, toggle it
  1239. $('.panel-group .panel-heading').on('click', function()
  1240. {
  1241. $(this).next().stop().slideToggle();
  1242. })
  1243. //$('#outcome[0]').on('change', function(){
  1244. //$('.selectpicker').selectpicker('refresh');
  1245. //})
  1246. // When list item is clicked, load corresponding info
  1247. // When list item is clicked, load corresponding info
  1248. $('.selectpicker').on('change', function()
  1249. {
  1250. //alert($(this).find(':selected').val());
  1251. $('.selectpicker').selectpicker('refresh');
  1252. });
  1253. @stop