No Description

criteria.blade.php 71KB

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