Ei kuvausta

criteria.blade.php 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. @extends('layouts.master')
  2. @section('navigation')
  3. @include('local.managers.admins._navigation')
  4. @stop
  5. @section('main')
  6. <div class="row">
  7. <div class="col-md-6">
  8. <!-- Form to add a new criterion -->
  9. <div class="panel panel-default panel-button">
  10. <div class="panel-heading">
  11. Create
  12. </div>
  13. <div class="panel-body">
  14. {{ Form::open(array('action' => 'CriteriaController@create')) }}
  15. <div id='outcomeGroup' data-value="1">
  16. <div class="form-group col-md-11">
  17. <label>Associated Outcomes</label>
  18. {{ Form::select('outcome[]', $outcomes, reset($outcomes), ['class'=>'form-control selectpicker', 'id' =>'outcome0', 'onchange'=>'fetchObjectiveForSelect("outcomeGroup", "objectiveGroup")']) }}
  19. </div>
  20. </div>
  21. <input type='hidden' name='counterOutcome' id='counterOutcome' value=1>
  22. <button id='button-add-outcome' class='btn btn-md btn-secondary' onclick='addOutcomeTest()'>
  23. <span class='glyphicon glyphicon-plus'>
  24. </span>
  25. Add another Outcome
  26. </button>
  27. <div id='objectiveGroup' data-value = '1'>
  28. <div class="form-group">
  29. <label>Associated Objectives</label>
  30. <select id="objective_0" name="objective[]" class="form-control selectpicker">
  31. </select>
  32. </div>
  33. </div>
  34. <input type='hidden' name='counterObjective' id='counterObjective' value=1>
  35. <button id='button-add-objective' class='btn btn-md btn-secondary' onclick='addObjectiveTest()'>
  36. <span class='glyphicon glyphicon-plus'>
  37. </span>
  38. Add another Objective
  39. </button>
  40. <!-- Associated Program -->
  41. <div class="form-group">
  42. {{ Form::label('program_id', 'Associated Program') }}<br>
  43. <br>
  44. @foreach ($programs as $program)
  45. <input type="checkbox" id="{{ $program->name }}" name="program_id[]" value="{{$program->id}}">
  46. <label for="{{ $program->name }}"> {{ $program->name }} [{{ $program->school->name }}]</label><br>
  47. @endforeach
  48. </div>
  49. <div class="form-group">
  50. {{ Form::label('name', 'Name') }}
  51. {{ Form::text('name', '', array('class' => 'form-control')) }}
  52. </div>
  53. <div class="form-group">
  54. {{ Form::label('subcriteria', 'Subcriteria') }}
  55. <p class="help-block"><strong>Manually add</strong> bullets or numbering.</p>
  56. {{ Form::textarea('subcriteria', '', array('class' => 'form-control', 'rows'=>3, 'aria-labelledby'=>'subcriteria')) }}
  57. </div>
  58. <div class="form-group">
  59. {{ Form::label('copyright', 'Copyright') }}
  60. {{ Form::textarea('copyright', '', array('class' => 'form-control', 'rows'=>2, 'placeholder'=>'(optional)', 'aria-labelledby'=>'copyright')) }}
  61. </div>
  62. <div class="form-group">
  63. {{ Form::label('notes', 'Notes') }}
  64. {{ Form::textarea('notes', '', array('class' => 'form-control', 'rows'=>2, 'placeholder'=>'(optional)', 'aria-labelledby'=>'notes')) }}
  65. </div>
  66. {{ Form::submit('Create', array('class' => 'btn btn-primary btn-block')) }}
  67. {{ Form::close() }}
  68. </div>
  69. </div>
  70. </div>
  71. <div class="col-md-6">
  72. <div class="panel panel-default panel-button">
  73. <div class="panel-heading">
  74. Edit
  75. </div>
  76. <div class="panel-body">
  77. {{ Form::open(array('action' => 'CriteriaController@update')) }}
  78. <button class="btn btn-md btn-secondary filterButton">
  79. <span class="glyphicon glyphicon-plus">
  80. </span>
  81. Filters
  82. </button>
  83. <div class ="filterSection">
  84. <div class="form-group">
  85. {{ Form::label('program_id2', 'Associated Program')}}
  86. <select id='select-program' class="form-control selectpicker" onchange='fetchAllCriterion("select-program", "assoc_outcomes_fetch")'>
  87. @foreach ($programs as $program)
  88. <option value='{{$program->id}}' data-subtext="{{$program->code}}">{{$program->name}}</option>
  89. @endforeach
  90. </select>
  91. </div>
  92. <div class="form-group">
  93. <label>Associated Outcome</label>
  94. {{ Form::select('assoc_outcome_fetch', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcomes_fetch', 'onchange'=>'fetchAllCriterion("select-program", "assoc_outcomes_fetch")']) }}
  95. </div>
  96. </div>
  97. <div class="form-group">
  98. {{ Form::label('criterion_id', 'Criterion') }}
  99. <select id="select-criterion" name="id" class="form-control selectpicker" onchange='fetchCriterionForEditing()'>
  100. @foreach ($criteria as $criterion)
  101. <option value="{{ $criterion->id }}" data-subtext="
  102. @if($criterion->program)
  103. &nbsp;&nbsp;&nbsp;[{{ $criterion->program->name }}]
  104. @endif
  105. ">
  106. {{ $criterion->name }}
  107. </option>
  108. @endforeach
  109. </select>
  110. </div>
  111. <!-- Associated Outcome -->
  112. <div id='assocOutcomeGroup' data-value="1">
  113. <div class="form-group">
  114. <label>Associated Outcome</label>
  115. {{ Form::select('assoc_outcome[]', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcome_0', 'onchange'=>'fetchAssocObjective("assoc_outcome_0")']) }}
  116. </div>
  117. </div>
  118. <button id='button-add-objective-assoc' class='btn btn-md btn-secondary' onclick='addAssocOutcome()'>
  119. <span class='glyphicon glyphicon-plus'>
  120. </span>
  121. Add another Outcome
  122. </button>
  123. <div id='assoc_objectiveGroup' data-value ='1'>
  124. <div class="form-group">
  125. <label>Associated Objectives</label>
  126. <select id="assoc_objective_0" name="assoc_objective[]" class="form-control selectpicker">
  127. <option value="0">No associated objectives</option>
  128. </select>
  129. </div>
  130. </div>
  131. <button id='button-add-outcome-assoc' class='btn btn-md btn-secondary' onclick='addAssocObjective()'>
  132. <span class='glyphicon glyphicon-plus'>
  133. </span>
  134. Add another Objective
  135. </button>
  136. <!-- Associated Program -->
  137. <div class="form-group">
  138. {{ Form::label('program_id2', 'Associated Program') }}<br><br>
  139. @foreach ($programs as $program)
  140. <input type="checkbox" id="assoc_program_id_{{ $program->id }}" name="program_id[]" value="{{$program->id}}">
  141. <label for="assoc_program_id_{{ $program->id }}"> {{ $program->name }} <sub>[{{ $program->school->name }}]</sub></label><br>
  142. @endforeach
  143. </div>
  144. <!-- Status -->
  145. <div class="form-group">
  146. {{ Form::label('status', 'Status') }}
  147. <span data-toggle="tooltip" data-placement="top" 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." class="glyphicon glyphicon-question-sign"></span>
  148. <select id="status" name="status" class="form-control">
  149. <option value="1">Active</option>
  150. <option value="0">Inactive</option>
  151. </select>
  152. </div>
  153. <div class="form-group">
  154. {{ Form::label('name', 'Name') }}
  155. {{ Form::text('name', Input::old('name'), array('class' => 'form-control', 'id'=>'criterion_name')) }}
  156. </div>
  157. <div class="form-group">
  158. {{ Form::label('subcriteria', 'Subcriteria') }}
  159. <p class="help-block"><strong>Manually add</strong> bullets or numbering.</p>
  160. {{ Form::textarea('subcriteria', '', array('class' => 'form-control', 'rows'=>3, 'id' => 'criterion_subcriteria')) }}
  161. </div>
  162. <div class="form-group">
  163. {{ Form::label('copyright', 'Copyright Information') }}
  164. {{ Form::textarea('copyright', Input::old('copyright'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_copyright', 'placeholder'=>'(optional)')) }}
  165. </div>
  166. <div class="form-group">
  167. {{ Form::label('notes', 'Additional Notes') }}
  168. {{ Form::textarea('notes', Input::old('notes'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_notes', 'placeholder'=>'(optional)')) }}
  169. </div>
  170. {{ Form::submit('Update', array('class' => 'btn btn-primary btn-block')) }}
  171. {{ Form::close() }}
  172. {{ Form::open(array('action' => 'CriteriaController@delete')) }}
  173. <input type='hidden' name='criterion_delete' id='deleteCriteria'>
  174. {{Form::submit("Delete", array('class'=> 'btn btn-primary btn-block', 'id'=>"DeleteButton"))}}
  175. </div>
  176. </div>
  177. </div>
  178. </div>
  179. <script>
  180. var selectOptions = document.getElementById('outcome0').innerHTML;
  181. var counter = 1;
  182. var counterObj = 1;
  183. var outcomeString = 'OutcomeGroup_';
  184. $('.filterSection').hide();
  185. $('.filterButton').on('click', function()
  186. {
  187. var span = $(this).find('span');
  188. if(span.attr('class') == 'glyphicon glyphicon-plus'){
  189. span.attr('class','glyphicon glyphicon-minus');
  190. } else{
  191. span.attr('class','glyphicon glyphicon-plus');
  192. }
  193. $('.filterSection').toggle(533);
  194. });
  195. //Add outcome Button
  196. function addOutcomeTest() {
  197. counter = parseInt($('#outcomeGroup').data("value"));
  198. var $select = $('<select/>', {
  199. 'class': "selectpicker form-control",
  200. 'name': "outcome[]",
  201. 'data-live-search': 'true',
  202. 'id': 'outcome' + counter.toString(),
  203. 'onchange': 'fetchObjectiveForSelect("outcomeGroup", "objectiveGroup")'
  204. });
  205. var $div = $('<div/>', {
  206. 'id': 'outcomeForm' + counter.toString(),
  207. 'class': 'form-group col-md-11'
  208. });
  209. var $divForButton = $('<div/>', {
  210. 'class': 'col-md-1',
  211. 'id': 'close' + counter.toString()
  212. });
  213. var $button = $('<button/>', {
  214. 'type': 'button',
  215. 'class': 'btn btn-primary',
  216. 'onclick': 'deleteLast("outcomeForm'+counter.toString()+'", "outcomeGroup", "close' + counter.toString() + '", "objectiveGroup")'
  217. });
  218. $button.append('X');
  219. $divForButton.append($button);
  220. $div.appendTo('#outcomeGroup')
  221. $select.append(selectOptions);
  222. $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
  223. $('#outcomeGroup').data("value", counter +1);
  224. fetchObjectiveForSelect('outcomeGroup', "objectiveGroup");
  225. $divForButton.appendTo('#outcomeGroup');
  226. }
  227. //Delete Outcome and OptGroup associated
  228. function deleteLast(outcomeForm, outcomeDiv, closeButton, objectiveGroup) {
  229. $div = document.getElementById(outcomeForm );
  230. $div.remove();
  231. $div = document.getElementById(closeButton);
  232. $div.remove();
  233. if(outcomeDiv =='outcomeGroup'){
  234. $('#' + outcomeDiv).data('value',parseInt($('#' + outcomeDiv).data('value')) - 1);
  235. fetchObjectiveForSelect(outcomeDiv, objectiveGroup);}
  236. }
  237. //Delete Objective
  238. function deleteObjective(objectiveForm, closeObj, objectiveGroup) {
  239. $div = document.getElementById(objectiveForm);
  240. $div.remove();
  241. $div = document.getElementById(closeObj);
  242. $div.remove();
  243. counter = parseInt($('#'+objectiveGroup).data("value"));
  244. $('#'+objectiveGroup).data("value", counter-1);
  245. }
  246. //Add objective when editing
  247. function addAssocObjective() {
  248. selectObj = document.getElementById('assoc_objective_0').innerHTML;
  249. assocObjectiveCounter = parseInt($('#assoc_objectiveGroup').data('value'));
  250. var $select = $('<select/>', {
  251. 'class': "selectpicker form-control",
  252. 'name': "assoc_objective[]",
  253. 'data-live-search': 'true',
  254. 'id': 'assoc_objective_' + assocObjectiveCounter.toString(),
  255. });
  256. var $div = $('<div/>', {
  257. 'id': 'assoc_objectiveForm' + assocObjectiveCounter.toString(),
  258. 'class': 'form-group col-md-11'
  259. });
  260. var $divForButton = $('<div/>', {
  261. 'class': 'col-md-1',
  262. 'id': 'assoc_closeObj' + assocObjectiveCounter.toString()
  263. });
  264. var $button = $('<button/>', {
  265. 'type': 'button',
  266. 'class': 'btn btn-primary',
  267. 'onclick': 'deleteObjective("assoc_objectiveForm' + assocObjectiveCounter.toString() + '", "assoc_closeObj' + assocObjectiveCounter.toString() + ', "assoc_objectiveGroup")'
  268. });
  269. $button.append('X');
  270. $divForButton.append($button);
  271. $div.appendTo('#assoc_objectiveGroup')
  272. $select.append(selectObj);
  273. $select.appendTo('#assoc_objectiveForm' + assocObjectiveCounter.toString()).selectpicker('refresh');
  274. $('#assoc_objectiveGroup').data("value", assocObjectiveCounter +1);
  275. $divForButton.appendTo('#assoc_objectiveGroup');
  276. }
  277. //Add objective when creating a criteria
  278. function addObjectiveTest() {
  279. selectObj = document.getElementById('objective_0').innerHTML;
  280. counter = $("#objectiveGroup").data('value');
  281. var $select = $('<select/>', {
  282. 'class': "selectpicker form-control",
  283. 'name': "objective[]",
  284. 'data-live-search': 'true',
  285. 'id': 'objective_' + counter.toString()
  286. });
  287. var $div = $('<div/>', {
  288. 'id': 'objectiveForm' + counter.toString(),
  289. 'class': 'form-group col-md-11'
  290. });
  291. var $divForButton = $('<div/>', {
  292. 'class': 'col-md-1',
  293. 'id': 'closeObj' + counter.toString()
  294. });
  295. var $button = $('<button/>', {
  296. 'type': 'button',
  297. 'class': 'btn btn-primary',
  298. 'onclick': 'deleteObjective("objectiveForm' + counter.toString() + '", "closeObj' + counter.toString() + '","objectiveGroup")'
  299. });
  300. $button.append('X');
  301. $divForButton.append($button);
  302. $div.appendTo('#objectiveGroup')
  303. $select.append(selectObj);
  304. $select.appendTo('#objectiveForm' + counter.toString()).selectpicker('refresh');
  305. $divForButton.appendTo('#objectiveGroup');
  306. $('#objectiveGroup').data('value', counter +1);
  307. }
  308. //Create outcome for editing
  309. var assocOutcomeCounter = 0;
  310. function addAssocOutcome() {
  311. assocOutcomeCounter = parseInt($('#assocOutcomeGroup').data('value'));
  312. var $select = $('<select/>', {
  313. 'class': "selectpicker form-control",
  314. 'name': "assoc_outcome[]",
  315. 'data-live-search': 'true',
  316. 'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
  317. 'onchange': 'fetchAssocObjective("assoc_outcome_' + assocOutcomeCounter.toString() + '")'
  318. });
  319. var $div = $('<div/>', {
  320. 'id': 'assoc_outcomeForm' + assocOutcomeCounter.toString(),
  321. 'class': 'form-group col-md-11'
  322. });
  323. var $divForButton = $('<div/>', {
  324. 'class': 'col-md-1',
  325. 'id': 'assoc_close' + assocOutcomeCounter.toString()
  326. });
  327. var $button = $('<button/>', {
  328. 'type': 'button',
  329. 'class': 'btn btn-primary',
  330. 'onclick': 'deleteLast("assoc_outcomeForm' + assocOutcomeCounter.toString() + '", "assocOutcomeGroup", "assoc_close' + assocOutcomeCounter.toString() + '","assoc_objectiveGroup")'
  331. });
  332. $button.append('X');
  333. $divForButton.append($button);
  334. $div.appendTo('#assocOutcomeGroup')
  335. $select.append(selectOptions);
  336. $select.appendTo('#assoc_outcomeForm' + assocOutcomeCounter.toString()).selectpicker('refresh');
  337. assocOutcomeCounter += 1;
  338. $('#assocOutcomeGroup').data('value', assocOutcomeCounter);
  339. $divForButton.appendTo('#assocOutcomeGroup');
  340. }
  341. //Fetch associated objective for editing
  342. var assocObjectiveCounter = 1;
  343. function fetchAssocObjective(outcomeDiv, objectiveGroup) {
  344. var count = $('#'+outcomeDiv).data('value');
  345. var allOutcomes =[];
  346. $("#" + outcomeDiv + ' select').each(function() {
  347. allOutcomes.push( this.value);
  348. })
  349. var allObjectives = [];
  350. $("#" + objectiveGroup + ' select').each(function() {
  351. var temp = {
  352. id: this.id,
  353. value: this.value
  354. }
  355. allObjectives.push(temp);
  356. })
  357. $.post(
  358. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  359. allOutcomes: allOutcomes
  360. },
  361. function(json) {
  362. optionName = '<option value ="0">Nothing Selected</option>';
  363. for(outcome in varArray.outcomes){
  364. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '">';
  365. var objectiveForOutcome = varArray.objectives;
  366. var objectives = objectiveForOutcome[outcome];
  367. for (objective in objectives) {
  368. var obj= objectives[objective];
  369. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  370. optionName += (option);
  371. }
  372. optionName += '</optgroup>';
  373. }
  374. $('#assoc_objective_0').html(optionName);
  375. $('#assoc_objective_0').selectpicker('refresh');
  376. if($("#assoc_objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  377. $("#assoc_objective_0").val(allObjectives[0].value);
  378. $('#assoc_objective_0').selectpicker('refresh');
  379. }
  380. for (var i = allObjectives.length - 1; i > 0; i--) {
  381. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup');
  382. }
  383. for(var i=1; i<allObjectives.length; i++){
  384. addAssocObjective();
  385. $('#assoc_objective_'+i.toString()).selectpicker('refresh');
  386. if($("#assoc_objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  387. $("#assoc_objective_"+i.toString()).val(allObjectives[i].value);
  388. $("#assoc_objective_"+i.toString()).selectpicker("refresh");
  389. }
  390. }
  391. },
  392. 'json'
  393. );
  394. }
  395. //Fetch objective at creating criteria
  396. counterForPost = 0;
  397. function fetchObjectiveForSelect(outcomeDiv, objectiveGroup) {
  398. var count = $("#" + outcomeDiv).data('value');
  399. var allOutcomes = [];
  400. $("#" + outcomeDiv + ' select').each(function() {
  401. allOutcomes.push( this.value);
  402. })
  403. var allObjectives = [];
  404. $("#" + objectiveGroup + ' select').each(function() {
  405. var temp = {
  406. id: this.id,
  407. value: this.value
  408. }
  409. allObjectives.push(temp);
  410. })
  411. $.post(
  412. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  413. allOutcomes: allOutcomes
  414. },
  415. function(varArray) {
  416. counterOutcome =0;
  417. optionName = '<option value ="0">Nothing Selected</option>';
  418. for(outcome in varArray.outcomes){
  419. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '">';
  420. var objectiveForOutcome = varArray.objectives;
  421. var objectives = objectiveForOutcome[outcome];
  422. for (objective in varArray.objectives[outcome]) {
  423. var obj= objectives[objective];
  424. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  425. optionName += (option);
  426. }
  427. optionName += '</optgroup>';
  428. }
  429. $('#objective_0').html(optionName);
  430. $('#objective_0').selectpicker('refresh');
  431. if($("#objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  432. $("#objective_0").val(allObjectives[0].value);
  433. $('#objective_0').selectpicker('refresh');
  434. }
  435. for (var i = allObjectives.length - 1; i > 0; i--) {
  436. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString(), 'objectiveGroup');
  437. }
  438. for(var i =1; i<allObjectives.length; i++){
  439. addObjectiveTest();
  440. $('#objective_'+i.toString()).selectpicker('refresh');
  441. if($("#objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  442. $("#objective_"+i.toString()).val(allObjectives[i].value);
  443. $("#objective_"+i.toString()).selectpicker("refresh");
  444. }
  445. }
  446. },
  447. 'json'
  448. );
  449. }
  450. //after post
  451. //For editing criterion
  452. function fetchAllCriterion(program, outcome) {
  453. var program_id_fetch = $('#' + program).find(':selected').val();
  454. var outcome_fetch = $('#' + outcome).find(':selected').val();
  455. $.post(
  456. "{{URL::action('CriteriaController@fetchAllCriterion')}}", {
  457. program_fetch: program_id_fetch,
  458. outcome_fetch: outcome_fetch
  459. },
  460. function(json) {
  461. json_length = (json.criterion.length);
  462. fullHTML = '';
  463. for (var i = 0; i < json_length; i++) {
  464. fullHTML += '<option value="' + json.criterion[i].id + '">' + json.criterion[i].name + '</option>';
  465. }
  466. $('#select-criterion').html(fullHTML);
  467. $('#select-criterion').selectpicker('refresh');
  468. fetchCriterionForEditing()
  469. },
  470. 'json'
  471. );
  472. }
  473. function deleteCriterion() {
  474. var id = $('#select-criterion').find(':selected').val()
  475. $.post(
  476. "{{ URL::action('CriteriaController@delete')}}", {
  477. id: id
  478. },
  479. function() {
  480. window.location.reload(true)
  481. }
  482. )
  483. }
  484. function fetchCriterionForEditing() {
  485. var id = $('#select-criterion').find(':selected').val();
  486. $.post(
  487. "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
  488. id: id
  489. },
  490. function(json) {
  491. if (!(json.activity_criterion.length)) {
  492. $('#DeleteButton').prop('enabled', true);
  493. } else {
  494. $('#DeleteButton').prop('disabled', true);
  495. }
  496. if (!(json.criteria.length)) {
  497. name = ' ';
  498. var subcriteria = '';
  499. copyright = null;
  500. notes = null;
  501. $('#status').val(0);
  502. maximum = 1;
  503. $('#assoc_maximum_score').val(1);
  504. } else {
  505. var name = json.criteria[0].name;
  506. if (json.criteria[0].subcriteria) {
  507. subcriteria = JSON.parse(json.criteria[0].subcriteria).join('\n');
  508. } else {
  509. subcriteria = "";
  510. }
  511. if (json.criteria[0].copyright) {
  512. var copyright = json.criteria[0].copyright;
  513. } else {
  514. var copyright = ''
  515. }
  516. if (json.criteria[0].notes) notes = json.criteria[0].notes;
  517. else notes = '';
  518. // Display info
  519. $('#criterion_name').val(name);
  520. $('#criterion_subcriteria').text(subcriteria);
  521. if (json.criteria[0].deleted_at)
  522. $('#status').val(0);
  523. else
  524. $('#status').val(1);
  525. $('#assoc_maximum_score').val(json.criteria[0].maximum_score);
  526. var maximum = json.criteria[0].maximum_score;
  527. // If copyright or notes aren't empty, load them
  528. }
  529. $('#criterion_copyright').text(copyright);
  530. $('#criterion_notes').text(notes);
  531. // Select associated outcome
  532. try {
  533. assocOutcomeCounter= parseInt($("#assocOutcomeGroup").data('value'));
  534. for (var i = assocOutcomeCounter - 1; i > 0; i--) {
  535. deleteLast("assoc_outcomeForm" + i.toString() , "assocOutcomeGroup", "assoc_close" + i.toString() ,"assoc_objectiveGroup");
  536. }
  537. } catch (err) {
  538. var Notran = true;
  539. }
  540. if (json.outcomes.length) {
  541. $('#assoc_outcome_0').val(json.outcomes[0].id);
  542. $('#assoc_outcome_0').selectpicker('refresh');
  543. } else {
  544. $('#assoc_outcome_0').val($('#assoc_outcomes_fetch').find(':selected').val());
  545. $('#assoc_outcome_0').selectpicker('refresh');
  546. }
  547. for (var i = 1; i < json.outcomes.length; i++) {
  548. addAssocOutcome();
  549. $('#assoc_outcome_' + i.toString()).val(json.outcomes[i].id);
  550. $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
  551. }
  552. counterObj =$('#assoc_objectiveGroup').data('value');
  553. try {
  554. for (var i = counterObj - 1; i > 0; i--) {
  555. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup')
  556. }
  557. } catch (err) {
  558. var noEntro = true;
  559. }
  560. $('#assoc_objectiveGroup').data('value', 1);
  561. assocOutcomeCounter = 0;
  562. var i = 0;
  563. optionName = '<option value ="0">Nothing Selected</option>';
  564. for(outcome in json.outcomes_assoc){
  565. optionName += '<optgroup label="' + json.outcomes_assoc[outcome][0].name + '">';
  566. var objectiveForOutcome = json.objectives_assoc;
  567. var objectives = objectiveForOutcome[outcome];
  568. for (objective in objectives) {
  569. var obj= objectives[objective];
  570. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  571. optionName += (option);
  572. }
  573. optionName += "</optgroup>";
  574. }
  575. $('#assoc_objective_0').html(optionName);
  576. $('#assoc_objective_0').selectpicker('refresh');
  577. try {
  578. $('#assoc_objective_0').val(json.objectives[0].id);
  579. $('#assoc_objective_0').selectpicker('refresh');
  580. } catch (err) {
  581. if (!json.objectives.length) {
  582. $('#assoc_objective_0').val(0);
  583. $('#assoc_objective_0').selectpicker('refresh');
  584. }
  585. }
  586. for (var i = 1; i < json.objectives.length; i++) {
  587. addAssocObjective();
  588. $('#assoc_objective_' + i.toString()).val(json.objectives[i].id);
  589. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  590. }
  591. $('assoc_objectiveGroup').data('value',json.objectives.length);
  592. // Select associated program
  593. var program_length = json.program.length;
  594. $('input[type=checkbox]').prop('checked', false);
  595. for (var i = 0; i < program_length; i++) {
  596. $('#assoc_program_id_' + json.program[i].program_id).prop("checked", true);
  597. }
  598. // Select status
  599. },
  600. 'json'
  601. );
  602. }
  603. </script>
  604. @stop
  605. @section('javascript')
  606. // --------------------------------------------------------------------------
  607. // Page load
  608. // --------------------------------------------------------------------------
  609. // Hide accordion panel contents by default
  610. $('.panel-group .panel-body').hide();
  611. $('#outcome-display').parent().hide();
  612. fetchCriterionForEditing();
  613. fetchObjectiveForSelect('outcomeGroup', 'objectiveGroup');
  614. // setCriterionStatus();
  615. fetchAllCriterion("select-program", "assoc_outcomes_fetch");
  616. // --------------------------------------------------------------------------
  617. // Functions
  618. // --------------------------------------------------------------------------
  619. $('#button-add-outcome').on('click', function(e) {
  620. // Prevent the default action of the clicked item. In this case that is submit
  621. e.preventDefault();
  622. return false;
  623. });
  624. $('#button-add-objective-assoc').on('click', function(e) {
  625. // Prevent the default action of the clicked item. In this case that is submit
  626. e.preventDefault();
  627. return false;
  628. });
  629. $('#button-add-outcome-assoc').on('click', function(e) {
  630. // Prevent the default action of the clicked item. In this case that is submit
  631. e.preventDefault();
  632. return false;
  633. });
  634. $('#button-add-objective').on('click', function(e) {
  635. // Prevent the default action of the clicked item. In this case that is submit
  636. e.preventDefault();
  637. return false;
  638. });
  639. $('.filterButton').on('click', function(e) {
  640. // Prevent the default action of the clicked item. In this case that is submit
  641. e.preventDefault();
  642. return false;
  643. });
  644. // Fetch criterion info for editing
  645. // --------------------------------------------------------------------------
  646. // Events
  647. // --------------------------------------------------------------------------
  648. // When panel heading is clicked, toggle it
  649. $('.panel-group .panel-heading').on('click', function()
  650. {
  651. $(this).next().stop().slideToggle();
  652. })
  653. //$('#outcome[0]').on('change', function(){
  654. //fetchObjectiveForSelect(0);
  655. //$('.selectpicker').selectpicker('refresh');
  656. //})
  657. // When list item is clicked, load corresponding info
  658. // When list item is clicked, load corresponding info
  659. $('.selectpicker').on('change', function()
  660. {
  661. //alert($(this).find(':selected').val());
  662. $('.selectpicker').selectpicker('refresh');
  663. });
  664. @stop