No Description

criteria.blade.php 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  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'>
  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 = $("#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 = '';
  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. }
  370. $('#assoc_objective_0').html(optionName);
  371. $('#assoc_objective_0').selectpicker('refresh');
  372. if($("#assoc_objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  373. $("#assoc_objective_0").val(allObjectives[0].value);
  374. $('#assoc_objective_0').selectpicker('refresh');
  375. }
  376. for (var i = allObjectives.length - 1; i > 0; i--) {
  377. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup');
  378. }
  379. for(var i=1; i<allObjectives.length; i++){
  380. addAssocObjective();
  381. $('#assoc_objective_'+i.toString()).selectpicker('refresh');
  382. if($("#assoc_objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  383. $("#assoc_objective_"+i.toString()).val(allObjectives[i].value);
  384. $("#assoc_objective_"+i.toString()).selectpicker("refresh");
  385. }
  386. }
  387. },
  388. 'json'
  389. );
  390. }
  391. //Fetch objective at creating criteria
  392. counterForPost = 0;
  393. function fetchObjectiveForSelect(outcomeDiv, objectiveGroup) {
  394. var count = $("#" + outcomeDiv).data('value');
  395. var allOutcomes = [];
  396. $("#" + outcomeDiv + ' select').each(function() {
  397. allOutcomes.push( this.value);
  398. })
  399. var allObjectives = [];
  400. $("#" + objectiveGroup + ' select').each(function() {
  401. var temp = {
  402. id: this.id,
  403. value: this.value
  404. }
  405. allObjectives.push(temp);
  406. })
  407. $.post(
  408. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  409. allOutcomes: allOutcomes
  410. },
  411. function(varArray) {
  412. counterOutcome =0;
  413. optionName = '';
  414. for(outcome in varArray.outcomes){
  415. optionName += '<optgroup label="' + varArray.outcomes[outcome][0].name + '"';
  416. var objectiveForOutcome = varArray.objectives;
  417. var objectives = objectiveForOutcome[outcome];
  418. for (objective in varArray.objectives[outcome]) {
  419. var obj= objectives[objective];
  420. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  421. optionName += (option);
  422. }
  423. }
  424. $('#objective_0').html(optionName);
  425. $('#objective_0').selectpicker('refresh');
  426. if($("#objective_0 option[value='"+allObjectives[0].value+"']").length>0){
  427. $("#objective_0").val(allObjectives[0].value);
  428. $('#objective_0').selectpicker('refresh');
  429. }
  430. for (var i = allObjectives.length - 1; i > 0; i--) {
  431. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString(), 'objectiveGroup');
  432. }
  433. for(var i =1; i<allObjectives.length; i++){
  434. addObjectiveTest();
  435. $('#objective_'+i.toString()).selectpicker('refresh');
  436. if($("#objective_"+i.toString()+" option[value='"+allObjectives[i].value+"']").length>0){
  437. $("#objective_"+i.toString()).val(allObjectives[i].value);
  438. $("#objective_"+i.toString()).selectpicker("refresh");
  439. }
  440. }
  441. },
  442. 'json'
  443. );
  444. }
  445. //after post
  446. //For editing criterion
  447. function fetchAllCriterion(program, outcome) {
  448. var program_id_fetch = $('#' + program).find(':selected').val();
  449. var outcome_fetch = $('#' + outcome).find(':selected').val();
  450. $.post(
  451. "{{URL::action('CriteriaController@fetchAllCriterion')}}", {
  452. program_fetch: program_id_fetch,
  453. outcome_fetch: outcome_fetch
  454. },
  455. function(json) {
  456. json_length = (json.criterion.length);
  457. fullHTML = '';
  458. for (var i = 0; i < json_length; i++) {
  459. fullHTML += '<option value="' + json.criterion[i].id + '">' + json.criterion[i].name + '</option>';
  460. }
  461. $('#select-criterion').html(fullHTML);
  462. $('#select-criterion').selectpicker('refresh');
  463. fetchCriterionForEditing()
  464. },
  465. 'json'
  466. );
  467. }
  468. function deleteCriterion() {
  469. var id = $('#select-criterion').find(':selected').val()
  470. $.post(
  471. "{{ URL::action('CriteriaController@delete')}}", {
  472. id: id
  473. },
  474. function() {
  475. window.location.reload(true)
  476. }
  477. )
  478. }
  479. function fetchCriterionForEditing() {
  480. var id = $('#select-criterion').find(':selected').val();
  481. $.post(
  482. "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
  483. id: id
  484. },
  485. function(json) {
  486. if (!(json.activity_criterion.length)) {
  487. $('#DeleteButton').prop('enabled', true);
  488. } else {
  489. $('#DeleteButton').prop('disabled', true);
  490. }
  491. if (!(json.criteria.length)) {
  492. name = ' ';
  493. var subcriteria = '';
  494. copyright = null;
  495. notes = null;
  496. $('#status').val(0);
  497. maximum = 1;
  498. $('#assoc_maximum_score').val(1);
  499. } else {
  500. var name = json.criteria[0].name;
  501. if (json.criteria[0].subcriteria) {
  502. subcriteria = JSON.parse(json.criteria[0].subcriteria).join('\n');
  503. }else {
  504. subcriteria = "";
  505. }
  506. if (json.criteria[0].copyright) {
  507. var copyright = json.criteria[0].copyright;
  508. } else {
  509. var copyright = ''
  510. }
  511. if (json.criteria[0].notes) notes = json.criteria[0].notes;
  512. else notes = '';
  513. // Display info
  514. $('#criterion_name').val(name);
  515. $('#criterion_subcriteria').text(subcriteria);
  516. if (json.criteria[0].deleted_at)
  517. $('#status').val(0);
  518. else
  519. $('#status').val(1);
  520. $('#assoc_maximum_score').val(json.criteria[0].maximum_score);
  521. var maximum = json.criteria[0].maximum_score;
  522. // If copyright or notes aren't empty, load them
  523. }
  524. $('#criterion_copyright').text(copyright);
  525. $('#criterion_notes').text(notes);
  526. // Select associated outcome
  527. try {
  528. assocOutcomeCounter= parseInt($("#assocOutcomeGroup").data('value'));
  529. for (var i = assocOutcomeCounter - 1; i > 0; i--) {
  530. deleteLast("assoc_outcomeForm" + i.toString() , "assocOutcomeGroup", "assoc_close" + i.toString() ,"assoc_objectiveGroup");
  531. }
  532. } catch (err) {
  533. var Notran = true;
  534. }
  535. if (json.outcomes.length) {
  536. $('#assoc_outcome_0').val(json.outcomes[0].id);
  537. $('#assoc_outcome_0').selectpicker('refresh');
  538. } else {
  539. $('#assoc_outcome_0').val($('#assoc_outcomes_fetch').find(':selected').val());
  540. $('#assoc_outcome_0').selectpicker('refresh');
  541. }
  542. for (var i = 1; i < json.outcomes.length; i++) {
  543. addAssocOutcome();
  544. $('#assoc_outcome_' + i.toString()).val(json.outcomes[i].id);
  545. $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
  546. }
  547. counterObj =$('#assoc_objectiveGroup').data('value');
  548. try {
  549. for (var i = counterObj - 1; i > 0; i--) {
  550. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString(), 'assoc_objectiveGroup')
  551. }
  552. } catch (err) {
  553. var noEntro = true;
  554. }
  555. $('#assoc_objectiveGroup').data('value', 1);
  556. assocOutcomeCounter = 0;
  557. var i = 0;
  558. optionName = '';
  559. for(outcome in json.outcomes_assoc){
  560. optionName += '<optgroup label="' + json.outcomes_assoc[outcome][0].name + '"';
  561. var objectiveForOutcome = json.objectives_assoc;
  562. var objectives = objectiveForOutcome[outcome];
  563. for (objective in objectives) {
  564. var obj= objectives[objective];
  565. var option = '<option value ="' + obj.id + '">' +obj.text + '</option>';
  566. optionName += (option);
  567. }
  568. }
  569. $('#assoc_objective_0').html(optionName);
  570. $('#assoc_objective_0').selectpicker('refresh');
  571. try {
  572. $('#assoc_objective_0').val(json.objectives[0].id);
  573. $('#assoc_objective_0').selectpicker('refresh');
  574. } catch (err) {
  575. if (!json.objectives.length) {
  576. $('#assoc_objective_0').val(0);
  577. $('#assoc_objective_0').selectpicker('refresh');
  578. }
  579. var thereIsNoObjective = true;
  580. }
  581. for (var i = 1; i < json.objectives.length; i++) {
  582. addAssocObjective();
  583. $('#assoc_objective_' + i.toString()).val(json.objectives[i].id);
  584. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  585. }
  586. $('assoc_objectiveGroup').data('value',json.objectives.length);
  587. // Select status
  588. },
  589. 'json'
  590. );
  591. }
  592. </script>
  593. @stop
  594. @section('javascript')
  595. // --------------------------------------------------------------------------
  596. // Page load
  597. // --------------------------------------------------------------------------
  598. // Hide accordion panel contents by default
  599. $('.panel-group .panel-body').hide();
  600. $('#outcome-display').parent().hide();
  601. fetchCriterionForEditing();
  602. fetchObjectiveForSelect('outcomeGroup', 'objectiveGroup');
  603. // setCriterionStatus();
  604. fetchAllCriterion("select-program", "assoc_outcomes_fetch");
  605. // --------------------------------------------------------------------------
  606. // Functions
  607. // --------------------------------------------------------------------------
  608. $('#button-add-outcome').on('click', function(e) {
  609. // Prevent the default action of the clicked item. In this case that is submit
  610. e.preventDefault();
  611. return false;
  612. });
  613. $('.filterButton').on('click', function(e) {
  614. // Prevent the default action of the clicked item. In this case that is submit
  615. e.preventDefault();
  616. return false;
  617. });
  618. $('#button-add-objective-assoc').on('click', function(e) {
  619. // Prevent the default action of the clicked item. In this case that is submit
  620. e.preventDefault();
  621. return false;
  622. });
  623. $('#button-add-outcome-assoc').on('click', function(e) {
  624. // Prevent the default action of the clicked item. In this case that is submit
  625. e.preventDefault();
  626. return false;
  627. });
  628. $('#button-add-objective').on('click', function(e) {
  629. // Prevent the default action of the clicked item. In this case that is submit
  630. e.preventDefault();
  631. return false;
  632. });
  633. // Fetch criterion info for editing
  634. // --------------------------------------------------------------------------
  635. // Events
  636. // --------------------------------------------------------------------------
  637. // When panel heading is clicked, toggle it
  638. $('.panel-group .panel-heading').on('click', function()
  639. {
  640. $(this).next().stop().slideToggle();
  641. })
  642. //$('#outcome[0]').on('change', function(){
  643. //$('.selectpicker').selectpicker('refresh');
  644. //})
  645. // When list item is clicked, load corresponding info
  646. // When list item is clicked, load corresponding info
  647. $('.selectpicker').on('change', function()
  648. {
  649. //alert($(this).find(':selected').val());
  650. $('.selectpicker').selectpicker('refresh');
  651. });
  652. @stop