Brak opisu

criteria.blade.php 73KB

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