Aucune description

criteria.blade.php 71KB

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