No Description

criteria.blade.php 71KB

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