No Description

criteria.blade.php 71KB

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