No Description

criteria.blade.php 66KB

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