Няма описание

criteria.blade.php 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  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'>
  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("outcome0")']) }}
  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'>
  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') }}
  43. <select id="program_id" name="program_id" class="form-control selectpicker">
  44. <option value="0">All</option>
  45. @foreach ($programs as $program)
  46. <option value="{{ $program->id }}">{{ $program->name }} [{{ $program->school->name }}]</option>
  47. @endforeach
  48. </select>
  49. </div>
  50. <div class="form-group">
  51. {{ Form::label('name', 'Name') }}
  52. {{ Form::text('name', '', array('class' => 'form-control')) }}
  53. </div>
  54. <div class="form-group">
  55. {{ Form::label('subcriteria', 'Subcriteria') }}
  56. <p class="help-block"><strong>Manually add</strong> bullets or numbering.</p>
  57. {{ Form::textarea('subcriteria', '', array('class' => 'form-control', 'rows'=>3, 'aria-labelledby'=>'subcriteria')) }}
  58. </div>
  59. <div class="form-group">
  60. {{ Form::label('description12', 'Beginning (1-2)') }}
  61. {{ Form::textarea('description12', '', array('class' => 'form-control', 'rows'=>2, 'aria-labelledby'=>'description12')) }}
  62. </div>
  63. <div class="form-group">
  64. {{ Form::label('description34', 'In Progress (3-4)') }}
  65. {{ Form::textarea('description34', '', array('class' => 'form-control', 'rows'=>2, 'aria-labelledby'=>'description34')) }}
  66. </div>
  67. <div class="form-group">
  68. {{ Form::label('description56', 'Satisfactory (5-6)') }}
  69. {{ Form::textarea('description56', '', array('class' => 'form-control', 'rows'=>2, 'aria-labelledby'=>'description56')) }}
  70. </div>
  71. <div class="form-group">
  72. {{ Form::label('description78', 'Excellent (7-8)') }}
  73. {{ Form::textarea('description78', '', array('class' => 'form-control', 'rows'=>2, 'aria-labelledby'=>'description78')) }}
  74. </div>
  75. <div class="form-group">
  76. {{ Form::label('copyright', 'Copyright') }}
  77. {{ Form::textarea('copyright', '', array('class' => 'form-control', 'rows'=>2, 'placeholder'=>'(optional)', 'aria-labelledby'=>'copyright')) }}
  78. </div>
  79. <div class="form-group">
  80. {{ Form::label('notes', 'Notes') }}
  81. {{ Form::textarea('notes', '', array('class' => 'form-control', 'rows'=>2, 'placeholder'=>'(optional)', 'aria-labelledby'=>'notes')) }}
  82. </div>
  83. {{ Form::submit('Create', array('class' => 'btn btn-primary btn-block')) }}
  84. {{ Form::close() }}
  85. </div>
  86. </div>
  87. </div>
  88. <div class="col-md-6">
  89. <div class="panel panel-default panel-button">
  90. <div class="panel-heading">
  91. Edit
  92. </div>
  93. <div class="panel-body">
  94. {{ Form::open(array('action' => 'CriteriaController@update')) }}
  95. <div class="form-group">
  96. {{ Form::label('criterion_id', 'Criterion') }}
  97. <select id="select-criterion" name="id" class="form-control selectpicker" onchange='fetchCriterionForEditing()'>
  98. @foreach ($criteria as $criterion)
  99. <option value="{{ $criterion->id }}" data-subtext="
  100. @if($criterion->program)
  101. &nbsp;&nbsp;&nbsp;[{{ $criterion->program->name }}]
  102. @endif
  103. ">
  104. {{ $criterion->name }}
  105. </option>
  106. @endforeach
  107. </select>
  108. </div>
  109. <!-- Associated Outcome -->
  110. <div id='assocOutcomeGroup'>
  111. <div class="form-group">
  112. <label>Associated Outcome</label>
  113. {{ Form::select('assoc_outcome[]', $outcomes, null, ['class'=>'form-control selectpicker', 'id'=>'assoc_outcome_0', 'onchange'=>'fetchAssocObjective("assoc_outcome_0")']) }}
  114. </div>
  115. </div>
  116. <button id='button-add-objective-assoc' class='btn btn-md btn-secondary' onclick='addAssocOutcome()'>
  117. <span class='glyphicon glyphicon-plus'>
  118. </span>
  119. Add another Outcome
  120. </button>
  121. <div id='assoc_objectiveGroup'>
  122. <div class="form-group">
  123. <label>Associated Objectives</label>
  124. <select id="assoc_objective_0" name="assoc_objective[]" class="form-control selectpicker">
  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') }}
  136. <select id="program_id2" name="program_id" class="form-control selectpicker">
  137. <option value="0">All</option>
  138. @foreach ($programs as $program)
  139. <option value="{{ $program->id }}">{{ $program->name }} [{{ $program->school->name }}]</option>
  140. @endforeach
  141. </select>
  142. </div>
  143. <!-- Status -->
  144. <div class="form-group">
  145. {{ Form::label('status', 'Status') }}
  146. <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>
  147. <select id="status" name="status" class="form-control">
  148. <option value="1">Active</option>
  149. <option value="0">Inactive</option>
  150. </select>
  151. </div>
  152. <div class="form-group">
  153. {{ Form::label('name', 'Name') }}
  154. {{ Form::text('name', Input::old('name'), array('class' => 'form-control', 'id'=>'criterion_name')) }}
  155. </div>
  156. <div class="form-group">
  157. {{ Form::label('subcriteria', 'Subcriteria') }}
  158. <p class="help-block"><strong>Manually add</strong> bullets or numbering.</p>
  159. {{ Form::textarea('subcriteria', '', array('class' => 'form-control', 'rows'=>3, 'id' => 'criterion_subcriteria')) }}
  160. </div>
  161. <div class="form-group">
  162. {{ Form::label('description12', 'Beginning (1-2)') }}
  163. {{ Form::textarea('description12', Input::old('description12'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_description12')) }}
  164. </div>
  165. <div class="form-group">
  166. {{ Form::label('description34', 'In Progress (3-4)') }}
  167. {{ Form::textarea('description34', Input::old('description34'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_description34')) }}
  168. </div>
  169. <div class="form-group">
  170. {{ Form::label('description56', 'Satisfactory (5-6)') }}
  171. {{ Form::textarea('description56', Input::old('description56'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_description56')) }}
  172. </div>
  173. <div class="form-group">
  174. {{ Form::label('description78', 'Excellent (7-8)') }}
  175. {{ Form::textarea('description78', Input::old('description78'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_description78')) }}
  176. </div>
  177. <div class="form-group">
  178. {{ Form::label('copyright', 'Copyright Information') }}
  179. {{ Form::textarea('copyright', Input::old('copyright'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_copyright', 'placeholder'=>'(optional)')) }}
  180. </div>
  181. <div class="form-group">
  182. {{ Form::label('notes', 'Additional Notes') }}
  183. {{ Form::textarea('notes', Input::old('notes'), array('class' => 'form-control', 'rows'=>2, 'id'=>'criterion_notes', 'placeholder'=>'(optional)')) }}
  184. </div>
  185. {{ Form::submit('Update', array('class' => 'btn btn-primary btn-block')) }}
  186. {{ Form::close() }}
  187. </div>
  188. </div>
  189. </div>
  190. </div>
  191. <script>
  192. var selectOptions = document.getElementById('outcome0').innerHTML;
  193. var counter = 1;
  194. var counterObj = 1;
  195. var outcomeString = 'OutcomeGroup_';
  196. //Add outcome Button
  197. function addOutcomeTest() {
  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("outcome' + counter.toString() + '")'
  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() + '", "' + outcomeString + (counter).toString() + '", "close' + counter.toString() + '","objective_")'
  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. fetchObjectiveForSelect('outcome' + counter.toString());
  224. counter += 1;
  225. $divForButton.appendTo('#outcomeGroup');
  226. $('#counterOutcome').val(counter)
  227. }
  228. //Delete Outcome and OptGroup associated
  229. function deleteLast(outcomeForm, outcomeOptGroup, closeButton, objective) {
  230. $div = document.getElementById(outcomeForm);
  231. $div.remove();
  232. $div = document.getElementById(outcomeOptGroup);
  233. $div.remove();
  234. $div = document.getElementById(closeButton)
  235. $div.remove();
  236. for (var i = 0; i < counterObj; i++) {
  237. $('#' + objective + i.toString()).selectpicker('refresh');
  238. }
  239. }
  240. //Delete Objective
  241. function deleteObjective(objectiveForm, closeObj) {
  242. $div = document.getElementById(objectiveForm);
  243. $div.remove();
  244. $div = document.getElementById(closeObj);
  245. $div.remove();
  246. }
  247. //Add objective when editing
  248. function addAssocObjective() {
  249. selectObj = document.getElementById('assoc_objective_0').innerHTML;
  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() + '")'
  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. counterObj += 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. var $select = $('<select/>', {
  281. 'class': "selectpicker form-control",
  282. 'name': "objective[]",
  283. 'data-live-search': 'true',
  284. 'id': 'objective_' + counterObj.toString()
  285. });
  286. var $div = $('<div/>', {
  287. 'id': 'objectiveForm' + counterObj.toString(),
  288. 'class': 'form-group col-md-11'
  289. });
  290. var $divForButton = $('<div/>', {
  291. 'class': 'col-md-1',
  292. 'id': 'closeObj' + counterObj.toString()
  293. });
  294. var $button = $('<button/>', {
  295. 'type': 'button',
  296. 'class': 'btn btn-primary',
  297. 'onclick': 'deleteObjective("objectiveForm' + counterObj.toString() + '", "closeObj' + counterObj.toString() + '")'
  298. });
  299. $button.append('X');
  300. $divForButton.append($button);
  301. $div.appendTo('#objectiveGroup')
  302. $select.append(selectObj);
  303. $select.appendTo('#objectiveForm' + counterObj.toString()).selectpicker('refresh');
  304. counterObj += 1;
  305. $divForButton.appendTo('#objectiveGroup');
  306. $('#counterObjective').val(counterObj)
  307. }
  308. //Create outcome for editing
  309. var assocOutcomeCounter = 0;
  310. function addAssocOutcome() {
  311. var $select = $('<select/>', {
  312. 'class': "selectpicker form-control",
  313. 'name': "assoc_outcome[]",
  314. 'data-live-search': 'true',
  315. 'id': 'assoc_outcome_' + assocOutcomeCounter.toString(),
  316. 'onchange': 'fetchAssocObjective("assoc_outcome_' + assocOutcomeCounter.toString() + '")'
  317. });
  318. var $div = $('<div/>', {
  319. 'id': 'assoc_outcomeForm' + assocOutcomeCounter.toString(),
  320. 'class': 'form-group col-md-11'
  321. });
  322. var $divForButton = $('<div/>', {
  323. 'class': 'col-md-1',
  324. 'id': 'assoc_close' + assocOutcomeCounter.toString()
  325. });
  326. var $button = $('<button/>', {
  327. 'type': 'button',
  328. 'class': 'btn btn-primary',
  329. 'onclick': 'deleteLast("assoc_outcomeForm' + assocOutcomeCounter.toString() + '", "' + 'Associated_Outcome' + (assocOutcomeCounter).toString() + '", "assoc_close' + assocOutcomeCounter.toString() + '","assoc_objective_")'
  330. });
  331. $button.append('X');
  332. $divForButton.append($button);
  333. $div.appendTo('#assocOutcomeGroup')
  334. $select.append(selectOptions);
  335. $select.appendTo('#assoc_outcomeForm' + assocOutcomeCounter.toString()).selectpicker('refresh');
  336. //fetchAssocObjective('assoc_outcome_' + assocOutcomeCounter.toString());
  337. assocOutcomeCounter += 1;
  338. $divForButton.appendTo('#assocOutcomeGroup');
  339. }
  340. //Fetch associated objective for editing
  341. var assocObjectiveCounter = 1;
  342. function fetchAssocObjective(outcomeId) {
  343. var id = $('#' + outcomeId).find(':selected').val();
  344. $.post(
  345. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  346. id: id
  347. },
  348. function(json) {
  349. var optionName = '<optgroup id="' + 'Associated_Outcome' + (assocOutcomeCounter - 1).toString() + '"label="' + 'Associated Outcome' + (assocOutcomeCounter).toString() + '"';
  350. for (var i = 0; i < json.length; i++) {
  351. var option = '<option value ="' + json[i].id.toString() + '">' + json[i].text + '</option>'
  352. optionName += (option)
  353. }
  354. optGroup = document.getElementById('Associated_Outcome' + (assocOutcomeCounter - 1).toString());
  355. if (optGroup != null) {
  356. optGroup.remove()
  357. }
  358. $('#assoc_objective_0').append(optionName);
  359. $('#assoc_objective_0').selectpicker('refresh');
  360. for (var i = assocObjectiveCounter - 1; i > 0; i--) {
  361. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString())
  362. }
  363. assocObjectiveCounter = 1;
  364. },
  365. 'json'
  366. );
  367. }
  368. //Fetch objective at creating criteria
  369. counterForPost = 0;
  370. function fetchObjectiveForSelect(outcomeInput) {
  371. var id = $('#' + outcomeInput).find(':selected').val();
  372. $.post(
  373. "{{ URL::action('CriteriaController@fetchObjectivesForSelect') }}", {
  374. id: id
  375. },
  376. function(varArray) {
  377. var optionName = '<optgroup id="' + outcomeString + (counter - 1).toString() + '"label="' + outcomeString + (counter).toString() + '"';
  378. for (var i = 0; i < varArray.length; i++) {
  379. var option = '<option value ="' + varArray[i].id.toString() + '">' + varArray[i].text + '</option>'
  380. optionName += (option)
  381. }
  382. optGroup = document.getElementById(outcomeString + (counter - 1).toString());
  383. if (optGroup != null) {
  384. optGroup.remove()
  385. }
  386. $('#objective_0').append(optionName);
  387. $('#objective_0').selectpicker('refresh');
  388. for (var i = counterObj - 1; i > 0; i--) {
  389. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString())
  390. }
  391. counterObj = 1;
  392. },
  393. 'json'
  394. );
  395. }
  396. //after post
  397. //For editing criterion
  398. function fetchCriterionForEditing() {
  399. var id = $('#select-criterion').find(':selected').val();
  400. $.post(
  401. "{{ URL::action('CriteriaController@fetchCriterionWithTrashed') }}", {
  402. id: id
  403. },
  404. function(json) {
  405. var name = json.criteria[0].name;
  406. var subcriteria = '';
  407. if (json.criteria[0].subcriteria) {
  408. subcriteria = JSON.parse(json.criteria[0].subcriteria).join('\n');
  409. }
  410. var description12 = json.criteria[0].description12;
  411. var description34 = json.criteria[0].description34;
  412. var description56 = json.criteria[0].description56;
  413. var description78 = json.criteria[0].description78;
  414. var copyright = json.criteria[0].copyright;
  415. var notes = json.criteria[0].notes;
  416. // Display info
  417. $('#criterion_name').val(name);
  418. $('#criterion_subcriteria').text(subcriteria);
  419. $('#criterion_description12').text(description12);
  420. $('#criterion_description34').text(description34);
  421. $('#criterion_description56').text(description56);
  422. $('#criterion_description78').text(description78);
  423. // If copyright or notes aren't empty, load them
  424. if (copyright) {
  425. $('#criterion_copyright').text(copyright);
  426. } else {
  427. $('#criterion_copyright').text('');
  428. }
  429. if (notes) {
  430. $('#criterion_notes').text(notes);
  431. } else {
  432. $('#criterion_notes').text('');
  433. }
  434. // Select associated outcome
  435. try {
  436. for (var i = assocOutcomeCounter - 1; i > 0; i--) {
  437. deleteLast("assoc_outcomeForm" + (i).toString(), 'Associated_Outcome' + (i).toString(), "assoc_close" + (i).toString(), "assoc_objective_");
  438. }
  439. } catch (err) {
  440. var Notran = true;
  441. }
  442. $('#assoc_outcome_0').val(json.outcomes[0].id);
  443. $('#assoc_outcome_0').selectpicker('refresh');
  444. for (var i = 1; i < json.outcomes.length; i++) {
  445. addAssocOutcome();
  446. $('#assoc_outcome_' + i.toString()).val(json.outcomes[i].id);
  447. $('#assoc_outcome_' + i.toString()).selectpicker('refresh');
  448. }
  449. try {
  450. for (var i = counterObj - 1; i > 0; i--) {
  451. deleteObjective('objectiveForm' + i.toString(), 'closeObj' + i.toString())
  452. }
  453. } catch (err) {
  454. var noEntro = true;
  455. }
  456. counterObj = 1;
  457. assocOutcomeCounter = 0;
  458. var i = 0;
  459. for (var j = 0; j < json.outcomes.length; j++) {
  460. assocOutcomeCounter += 1;
  461. var optionName = '<optgroup id="' + 'Associated_Outcome' + (assocOutcomeCounter - 1).toString() + '"label="' + 'Associated Outcome' + (assocOutcomeCounter).toString() + '"';
  462. for (; i < json.objectives_outcome.length; i++) {
  463. if (json.objectives_outcome[i].outcome_id != json.outcomes[j].id) break;
  464. var option = '<option value ="' + json.objectives_outcome[i].id.toString() + '">' + json.objectives_outcome[i].text + '</option>'
  465. optionName += (option)
  466. }
  467. optGroup = document.getElementById('Associated_Outcome' + (assocOutcomeCounter - 1).toString());
  468. if (optGroup != null) {
  469. optGroup.remove()
  470. }
  471. $('#assoc_objective_0').append(optionName);
  472. $('#assoc_objective_0').selectpicker('refresh');
  473. }
  474. for (var i = assocObjectiveCounter - 1; i > 0; i--) {
  475. deleteObjective('assoc_objectiveForm' + i.toString(), 'assoc_closeObj' + i.toString())
  476. }
  477. assocObjectiveCounter = 1;
  478. try {
  479. $('#assoc_objective_0').val(json.objectives[0].id);
  480. $('#assoc_objective_0').selectpicker('refresh');
  481. } catch (err) {
  482. var thereIsNoObjective = true;
  483. }
  484. for (var i = 1; i < json.objectives.length; i++) {
  485. addAssocObjective();
  486. $('#assoc_objective_' + i.toString()).val(json.objectives[i].id);
  487. $('#assoc_objective_' + i.toString()).selectpicker('refresh');
  488. }
  489. assocObjectiveCounter = json.objectives.length;
  490. // Select associated program
  491. if (json.criteria[0].program_id) {
  492. $('#program_id2').val(json.criteria[0].program_id);
  493. } else {
  494. $('#program_id2').val(0);
  495. }
  496. $('#program_id2').selectpicker('refresh');
  497. // Select status
  498. if (json.criteria[0].deleted_at)
  499. $('#status').val(0);
  500. else
  501. $('#status').val(1);
  502. },
  503. 'json'
  504. );
  505. }
  506. </script>
  507. @stop
  508. @section('javascript')
  509. // --------------------------------------------------------------------------
  510. // Page load
  511. // --------------------------------------------------------------------------
  512. // Hide accordion panel contents by default
  513. $('.panel-group .panel-body').hide();
  514. $('#outcome-display').parent().hide();
  515. fetchCriterionForEditing();
  516. fetchObjectiveForSelect('outcome0');
  517. // setCriterionStatus();
  518. // --------------------------------------------------------------------------
  519. // Functions
  520. // --------------------------------------------------------------------------
  521. $('#button-add-outcome').on('click', function(e) {
  522. // Prevent the default action of the clicked item. In this case that is submit
  523. e.preventDefault();
  524. return false;
  525. });
  526. $('#button-add-objective-assoc').on('click', function(e) {
  527. // Prevent the default action of the clicked item. In this case that is submit
  528. e.preventDefault();
  529. return false;
  530. });
  531. $('#button-add-outcome-assoc').on('click', function(e) {
  532. // Prevent the default action of the clicked item. In this case that is submit
  533. e.preventDefault();
  534. return false;
  535. });
  536. $('#button-add-objective').on('click', function(e) {
  537. // Prevent the default action of the clicked item. In this case that is submit
  538. e.preventDefault();
  539. return false;
  540. });
  541. // Fetch criterion info for editing
  542. // --------------------------------------------------------------------------
  543. // Events
  544. // --------------------------------------------------------------------------
  545. // When panel heading is clicked, toggle it
  546. $('.panel-group .panel-heading').on('click', function()
  547. {
  548. $(this).next().stop().slideToggle();
  549. })
  550. $('#outcome[0]').on('change', function(){
  551. fetchObjectiveForSelect(0);
  552. $('.selectpicker').selectpicker('refresh');
  553. })
  554. // When list item is clicked, load corresponding info
  555. // When list item is clicked, load corresponding info
  556. $('.selectpicker').on('change', function()
  557. {
  558. //alert($(this).find(':selected').val());
  559. $('.selectpicker').selectpicker('refresh');
  560. });
  561. @stop