Aucune description

criteria.blade.php 32KB

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