Nessuna descrizione

criteria.blade.php 71KB

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