No Description

criteria.blade.php 32KB

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