No Description

criteria.blade.php 67KB

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