No Description

criteria.blade.php 66KB

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