No Description

rubrics_new.blade.php 58KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627
  1. @extends('layouts.master')
  2. @section('navigation')
  3. @if(Auth::user()->role==1)
  4. @include('local.managers.admins._new_navigation')
  5. @elseif(Auth::user()->role==2)
  6. @include('local.managers.sCoords._new_navigation')
  7. @elseif(Auth::user()->role==3)
  8. @include('local.managers.pCoords._new_navigation')
  9. @elseif(Auth::user()->role==4)
  10. @include('local.professors._navigation')
  11. @endif
  12. @stop
  13. @section('main')
  14. <!-- Update Rubric Modal -->
  15. <div class="modal fade" id="modal-confirm-update">
  16. <div class="modal-dialog modal-sm">
  17. <div class="modal-content">
  18. <div class="modal-header">
  19. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  20. <h4 class="modal-title">Update Rubric</h4>
  21. </div>
  22. <div class="modal-body">
  23. <p>Speak to any coordinators and/or professors in your School or
  24. Program that may be affected when you update this rubric. <strong>Professors
  25. that have already used this rubric will keep a copy of it as
  26. they used it, not an updated one.</strong></p>
  27. <p>Do you want to update this rubric?</p>
  28. </div>
  29. <div class="modal-footer">
  30. <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
  31. <button id="button-update-rubric" class="btn btn-primary save">Update</button>
  32. </div>
  33. </div><!-- /.modal-content -->
  34. </div><!-- /.modal-dialog -->
  35. </div><!-- /.modal -->
  36. <!-- Delete Rubric Modal -->
  37. <div class="modal fade" id="modal-confirm-delete">
  38. <div class="modal-dialog modal-sm">
  39. <div class="modal-content">
  40. <div class="modal-header">
  41. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  42. <h4 class="modal-title">Delete Rubric</h4>
  43. </div>
  44. <div class="modal-body">
  45. <p>Please note: By deleting this rubric, it will no longer be available
  46. to your school's or program's professors. However, professors that
  47. have already used it will keep a copy in their activities. Speak to
  48. any coordinators and/or professors in your School or Program that may be affected.</p>
  49. <p>Are you sure you want to delete this rubric?</p>
  50. </div>
  51. <div class="modal-footer">
  52. <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
  53. <button id="button-delete-rubric" class="btn btn-primary">Delete</button>
  54. </div>
  55. </div><!-- /.modal-content -->
  56. </div><!-- /.modal-dialog -->
  57. </div><!-- /.modal -->
  58. <div class="row">
  59. <div class="col-md-12">
  60. <div class="panel panel-default">
  61. <div class="panel-heading">
  62. <span class="glyphicon glyphicon-triangle-bottom"></span>
  63. General Information
  64. </div>
  65. <div class="panel-body">
  66. <form>
  67. <div class="form-group">
  68. <label>Select a template, or create your own rubric</label>
  69. <select id="select-template" class="form-control selectpicker">
  70. <option data-template-id="0">Custom</option>
  71. @foreach ($templates_dentro as $template)
  72. @if($template->school_id==NULL && $template->program_id==NULL)
  73. <option
  74. data-template-id="{{ $template->id }}"
  75. data-template-program-id="{{ $template->program_id }}"
  76. data-admin="1"
  77. >
  78. {{{ $template->name }}}
  79. </option>
  80. @else
  81. <option
  82. data-template-id="{{ $template->id }}"
  83. data-template-program-id="{{ $template->program_id }}"
  84. >
  85. {{{ $template->name }}}
  86. </option>
  87. @endif
  88. @endforeach
  89. @foreach ($templates_fuera as $template)
  90. @if($template->school_id==NULL && $template->program_id==NULL)
  91. <option
  92. data-template-id="{{ $template->id }}"
  93. data-template-program-id="{{ $template->program_id }}"
  94. data-admin="1"
  95. data-unmatch-criteria="1"
  96. >
  97. ## {{{ $template->name }}}
  98. </option>
  99. @else
  100. <option
  101. data-template-id="{{ $template->id }}"
  102. data-template-program-id="{{ $template->program_id }}"
  103. data-unmatch-criteria="1"
  104. >
  105. ## {{{ $template->name }}}
  106. </option>
  107. @endif
  108. @endforeach
  109. </select>
  110. <!--
  111. <span style="color: red;">Rubrics with "##" at the beginning contain criteria that are not associated with your program or school. You will not be able to use them until your criteria is matched with your program or school.
  112. </span>
  113. -->
  114. </div>
  115. <!-- If user is admin s/he can pick which schools can view the rubric -->
  116. @if(Auth::user()->role==1)
  117. <div class="form-group">
  118. <label>Select the School this rubric will be visible from</label>
  119. <select id="select-school" class="form-control selectpicker">
  120. <option data-school-id="0">All</option>
  121. @foreach ($schools as $school)
  122. <option data-school-id="{{ $school->id }}">
  123. {{ $school->name }}
  124. </option>
  125. @endforeach
  126. </select>
  127. </div>
  128. @endif
  129. <!-- If user is admin or school coordinator, s/he can pick which programs -->
  130. @if(Auth::user()->role==1 || Auth::user()->role==2 || Auth::user()->role==3)
  131. <div class="form-group">
  132. <label>Select the Program this rubric belongs to</label>
  133. <select id="select-program" class="form-control selectpicker">
  134. @if(Auth::user()->role != 3)
  135. <option data-program-id="0">All</option>
  136. @endif
  137. @foreach ($programs as $program)
  138. <option
  139. data-program-id="{{ $program->id }}"
  140. data-program-program-id="{{ $program->program_id }}"
  141. >
  142. {{ $program->name }}
  143. </option>
  144. @endforeach
  145. </select>
  146. </div>
  147. @endif
  148. </form>
  149. <label for="">Select the lower bound for passing criteria</label>
  150. <form class="form-inline">
  151. <div class="form-group">
  152. <!-- Select percentage. If there is a rubric, select the saved value -->
  153. <select id="expected_percentage" class="form-control selectpicker">
  154. @for($i = 50; $i <= 100; $i++)
  155. @if($i==70)
  156. <option selected="selected" value="{{ $i }}">{{ $i }}</option>
  157. @else
  158. <option value="{{ $i }}">{{ $i }}</option>
  159. @endif
  160. @endfor
  161. </select>
  162. % of all students must score at least
  163. <!-- Select points. If there is a rubric, select the saved value -->
  164. <select id="expected_points" class="form-control selectpicker">
  165. @for($i = 0; $i <= 8; $i++)
  166. @if($i==5)
  167. <option selected="selected" value="{{ $i }}">{{ $i }}</option>
  168. @else
  169. <option value="{{ $i }}">{{ $i }}</option>
  170. @endif
  171. @endfor
  172. </select>
  173. point(s) in a criterion for it to pass.
  174. </div>
  175. </form>
  176. <br>
  177. <form>
  178. <div class="form-group">
  179. <label>Select Status (you can change this later)</label>
  180. <div class="radio">
  181. <label>
  182. <input type="radio" name="is_visible" id="is_visible0" value="0" checked>
  183. This rubric is <strong>not complete</strong> yet and will not be available to professors.
  184. </label>
  185. </div>
  186. <div class="radio">
  187. <label>
  188. <input type="radio" name="is_visible" id="is_visible1" value="1">
  189. This rubric is <strong>complete</strong> and will be available to professors.
  190. </label>
  191. </div>
  192. </div>
  193. </form>
  194. <div>
  195. <p class="small">Note: You can hide or show this section by clicking on its heading. You may want to hide it to have more space. </p>
  196. </div>
  197. </div>
  198. </div>
  199. <div class="well">
  200. <form>
  201. <div class="form-group">
  202. <label>Select a Learning Outcome</label>
  203. <select id="select-outcome" class="form-control selectpicker" >
  204. @foreach ($outcomes as $outcome)
  205. <option data-outcome-id="{{ $outcome->id }}">{{ $outcome->name }}</option>
  206. @endforeach
  207. </select>
  208. </div>
  209. <div class="form-group">
  210. <label>Select an Objective</label>
  211. <select id="select-objective" class="form-control selectpicker" >
  212. </select>
  213. </div>
  214. <div class="form-group">
  215. <label>Select the Maximum Score</label>
  216. <select id="max_score" class="form-control selectpicker">
  217. @for($i = 1; $i <= 100; $i++)
  218. @if($i==8)
  219. <option selected="selected" value="{{ $i }}">{{ $i }}</option>
  220. @else
  221. <option value="{{ $i }}">{{ $i }}</option>
  222. @endif
  223. @endfor
  224. </select>
  225. </div>
  226. <div class="form-group">
  227. <label>Select the Type of Rubric</label>
  228. <select id="number_of_scales" class="form-control selectpicker" >
  229. @for($i = 1; $i <= 20; $i++)
  230. @if(8%$i == 0)
  231. @if($i==1)
  232. <option value="{{ $i }}">Cuantitative Rubric</option>
  233. @elseif($i==4)
  234. <option selected="selected" value="{{ $i }}">{{ $i }}-Scale Rubric</option>
  235. @else
  236. <option value="{{ $i }}">{{ $i }}-Scale Rubric</option>
  237. @endif
  238. @endif
  239. @endfor
  240. </select>
  241. <div>
  242. @if(Auth::user()->role != '1')
  243. <label>Filter Criteria</label>
  244. <div class="form-group">
  245. <label class="radio-inline">
  246. <input type="radio" checked name="criteria-filter" id="criteria-all" value="all"> All Criteria
  247. </label>
  248. <label class="radio-inline">
  249. <input type="radio" name="criteria-filter" id="criteria-school" value="school"> Criteria from my School
  250. </label>
  251. @if(Auth::user()->role == '3')
  252. <label class="radio-inline">
  253. <input type="radio" name="criteria-filter" id="criteria-program" value="program"> Criteria from my Program(s)
  254. </label>
  255. @endif
  256. </div>
  257. @endif
  258. <div class="form-group">
  259. <label>Select a Criterion</label><span id="updated-text" class="text-success small"> updated</span>
  260. <select id="select-criterion" class="form-control selectpicker">
  261. </select>
  262. </div>
  263. <button id="button-add-criterion" class="btn btn-md btn-primary center-block"> <span class="glyphicon glyphicon-plus"></span> Add Criterion to Rubric</button>
  264. </form>
  265. </div>
  266. </div>
  267. </div>
  268. <div id="rubric-container" class="row">
  269. <div class="col-md-12">
  270. <table class="table table-striped table-condensed" style="table-layout: fixed">
  271. <thead id="theHead"><tr><th colspan="7 "><input id="rubric-name" type="text" class="form-control input-lg" placeholder="Rubric Name"></th></tr></thead>
  272. <thead id = "theScaleTitles">
  273. </thead>
  274. <thead>
  275. <tr id ="criterion-header">
  276. <th></th>
  277. <th></th>
  278. </tr>
  279. </thead>
  280. <tbody id = "allCriteria">
  281. </tbody>
  282. </table>
  283. <div id="copyright-info">
  284. <hr>
  285. <p class="small"><strong>Copyright</strong></p>
  286. <ul id="copyright-list" class="list-unstyled small">
  287. </ul>
  288. <hr>
  289. </div>
  290. <div class="text-center">
  291. <div class="btn-group" role="group" aria-label="...">
  292. <button id="button-create-rubric" class="btn btn-lg btn-primary save">
  293. <span class="glyphicon glyphicon-floppy-disk"></span>
  294. Create
  295. </button>
  296. <button id="button-confirm-update-rubric" data-toggle="modal" data-target="#modal-confirm-update" class="btn btn-lg btn-primary">
  297. <span class="glyphicon glyphicon-pencil"></span>
  298. Update
  299. </button>
  300. <button id="button-confirm-delete-rubric" data-toggle="modal" data-target="#modal-confirm-delete" class="btn btn-lg btn-primary">
  301. <span class="glyphicon glyphicon-remove"></span>
  302. Delete
  303. </button>
  304. <button id="button-print-rubric" class="btn btn-lg btn-primary"><span class="glyphicon glyphicon-print"></span> Print <span class="small">(saved version)</span></button>
  305. <button id = "button-get-criteria-objectives" class = "btn btn-lg btn-primary" onclick = 'fetchObjectivesForTemplate("#allCriteria")'><span class='glyphicon glyphicon-eye-open'></span> View Objectives</button>
  306. </div>
  307. </div>
  308. </div>
  309. </div>
  310. <div class="modal fade" id="rubric-modal">
  311. <div class="modal-dialog modal-md">
  312. <div class="modal-content">
  313. <div class="modal-header">
  314. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  315. <h4 class="modal-title text-center" id ="modal-title-rubric">You are adding criteria to your program</h4>
  316. </div>
  317. <div class="modal-body" id ="modal-body-rubric">
  318. </div>
  319. <div class="modal-footer">
  320. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  321. <button type="button" class="btn btn-primary" id ="saveButton" data-button-id = '' value="Save" type="button" onclick = "saveTemplate()" >Save</button>
  322. </div>
  323. </div><!-- /.modal-content -->
  324. </div><!-- /.modal-dialog -->
  325. </div>
  326. <div class="modal fade" id="objectives-crit-modal">
  327. <div class="modal-dialog modal-md">
  328. <div class="modal-content">
  329. <div class="modal-header">
  330. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  331. <h4 class="modal-title text-center" id ="modal-title-rubric">These are the objectives in each Criterion in this Rubric</h4>
  332. </div>
  333. <div class="modal-body" id ="objectives-crit-modal-body">
  334. </div>
  335. <div class="modal-footer">
  336. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  337. </div>
  338. </div><!-- /.modal-content -->
  339. </div><!-- /.modal-dialog -->
  340. </div>
  341. <script>
  342. </script>
  343. @stop
  344. @section('included-js')
  345. <!-- jQuery Sortable Tables -->
  346. <script src="{{ asset('vendor/jQuerySortable/jquery-sortable-min.js') }}"></script>
  347. <script>
  348. function fetchObjectivesForTemplate(tbody){
  349. allCriteria = [];
  350. $(tbody).children('tr').each(function (index){
  351. allCriteria.push($(this).data('criterion-id'));
  352. })
  353. $.post(
  354. "{{URL::action('TemplatesController@fetchObjectivesForTemplate')}}",
  355. {
  356. allCriteria:allCriteria
  357. },
  358. function(crit){
  359. modal_name = '#objectives-crit-modal';
  360. $(modal_name+'-body').html(' ');
  361. ol_crit = $("<ol>")
  362. $(modal_name+'-body').append(ol_crit);
  363. $.each(crit, function(index, cri){
  364. li = $("<li>").html("<strong>"+cri.name+"</strong>");
  365. ul_for_ob = $("<ul>");
  366. $.each(cri.all_objectives, function(ind, obj){
  367. li2 = $("<li>").html(obj.text)
  368. ul_for_ob.append(li2);
  369. })
  370. li.append(ul_for_ob);
  371. ol_crit.append(li);
  372. })
  373. $(modal_name).modal('show');
  374. }
  375. )
  376. }
  377. function saveTemplate()
  378. {
  379. //Prevent page refresh
  380. var criterionObject = new Object();
  381. var criteriaArray = new Array();
  382. var criteria = [];
  383. var titles = [];
  384. var amount_of_scales =parseInt($('#number_of_scales').find(':selected').val())+2;
  385. var max = parseInt($('#max_score').find(':selected').val());
  386. // For each criterion in the rubric, get its value and put it into an array
  387. $('tbody tr').each(function( index )
  388. {
  389. criteria.push($(this).data('criterion-id'));
  390. });
  391. $('.editable').each(function(index){
  392. titles.push($(this).text());
  393. })
  394. button_id = $("#saveButton").data('button-id');
  395. //console.log('school', $('#select-school').find(':selected').data('school-id') );
  396. //console.log('program', $('#select-program').find(':selected').data('program-id') );
  397. if(button_id=='button-create-rubric')
  398. {
  399. // Create
  400. $.post
  401. (
  402. "{{ URL::to('saveTemplate') }}",
  403. {
  404. name: $('#rubric-name').val(),
  405. school_id: $('#select-school').find(':selected').data('school-id'),
  406. program_id: $('#select-program').find(':selected').data('program-id'),
  407. expected_percentage: $('#expected_percentage').find(':selected').val(),
  408. expected_points: $('#expected_points').find(':selected').val(),
  409. is_visible: $('input[name=is_visible]:checked').val(),
  410. criteria : criteria,
  411. //scales: scales,
  412. max_score : max,
  413. /*copyright : copyright,
  414. notes :notes*/
  415. titles: titles
  416. },
  417. function(data)
  418. {
  419. location.reload(true);
  420. }
  421. );
  422. }
  423. else
  424. {
  425. console.log('school', $('#select-school').find(':selected').data('school-id') );
  426. console.log('program', $('#select-program').find(':selected').data('program-id') );
  427. // Update database
  428. $.post
  429. (
  430. "{{ URL::to('updateTemplate') }}",
  431. {
  432. id: $('#select-template').find(':selected').data('template-id'),
  433. name: $('#rubric-name').val(),
  434. school_id: $('#select-school').find(':selected').data('school-id'),
  435. program_id: $('#select-program').find(':selected').data('program-id'),
  436. expected_percentage: $('#expected_percentage').find(':selected').val(),
  437. expected_points: $('#expected_points').find(':selected').val(),
  438. is_visible: $('input[name=is_visible]:checked').val(),
  439. criteria : criteria,
  440. //scales: scales,
  441. max_score : max,
  442. /*copyright : copyright,
  443. notes :notes*/
  444. titles: titles
  445. },
  446. function(data)
  447. {
  448. location.reload(true);
  449. }
  450. );
  451. }
  452. }
  453. </script>
  454. <!-- X-Editable js -->
  455. <script src="{{ asset('vendor/xeditable/bootstrap-editable.min.js') }}"></script>
  456. @stop
  457. @section('javascript')
  458. $('#select-outcome').on('change',function(){
  459. fetchObjective(this);
  460. })
  461. // --------------------------------------------------------------------------
  462. // Functions
  463. // --------------------------------------------------------------------------
  464. function fetchObjective(outcome){
  465. $.post(
  466. "{{URL::route('fetchObjectivesForSelect')}}",
  467. {
  468. outcomeID:$(outcome).find(':selected').data('outcome-id'),
  469. },
  470. function(data){
  471. options = '';
  472. for(objective_index in data){
  473. options += '<option value = "'+data[objective_index].objective_id+'">'+data[objective_index].text+'</option>';
  474. }
  475. $('#select-objective').html(options);
  476. $('#select-objective').selectpicker('refresh');
  477. fetchCriteria($('#select-outcome'), $('#select-objective'));
  478. }, 'json',
  479. );
  480. }
  481. // Fetch criteria associated to a specific learning outcome
  482. function fetchCriteria(outcome, objective)
  483. {
  484. amount_of_scales = parseInt($('#number_of_scales').find(':selected').val());
  485. maximum = parseInt($('#max_score').find(":selected").val());
  486. $.post
  487. (
  488. "{{ URL::route('fetchCriteria') }}",
  489. {
  490. outcome_id: outcome.find(':selected').data('outcome-id'),
  491. objective_id: objective.find(':selected').val(),
  492. num_scales: amount_of_scales,
  493. maximum: maximum,
  494. filter: $('input[name=criteria-filter]:checked').val()
  495. },
  496. function(data)
  497. {
  498. $('#select-criterion').empty();
  499. console.log(data);
  500. // Append criteria
  501. data.forEach( function (arrayItem)
  502. {
  503. objectives = JSON.stringify(arrayItem.objectives);
  504. $('#select-criterion')
  505. .append('<option data-criterion-id="'+arrayItem.id+'" data-program-ids = '+"'"+arrayItem.program_ids+"'"+' data-assoc-objectives= '+"'"+objectives+"'"+'>'+arrayItem.name+'</option>');
  506. });
  507. // If there are no criteria assigned to the selected outcome, disable the
  508. // input and the button used to add criteria.
  509. if(!$('#select-criterion').children().length)
  510. {
  511. $('#select-criterion').prop('disabled', true);
  512. $('#button-add-criterion').prop('disabled', true);
  513. }
  514. // Otherwise, enable both the input and the button
  515. else
  516. {
  517. $('#select-criterion').prop('disabled', false);
  518. $('#button-add-criterion').prop('disabled', false);
  519. }
  520. $('#updated-text').fadeIn('slow').fadeOut('slow');
  521. refreshSelects();
  522. }
  523. );
  524. }
  525. // Add a new criterion to the rubric
  526. function addCriterion()
  527. {
  528. // Show the rubric container
  529. if(!$('tbody').children().length)
  530. {
  531. $('#rubric-container').show();
  532. }
  533. // Get the selected criterion's id
  534. var id= parseInt($('#select-criterion').find(':selected').data('criterion-id'));
  535. var program_ids = $('#select-criterion').find(':selected').data('program-ids');
  536. var objectives = $('#select-criterion').find(':selected').data('assoc-objectives');
  537. // Check for duplicates
  538. var duplicates=false;
  539. numberOfScale = $('#number_of_scales').find(':selected').val();
  540. $('tbody tr').each(function()
  541. {
  542. if ($(this).data('criterion-id') == id)
  543. {
  544. duplicates=true;
  545. }
  546. });
  547. // If there are any, display an error
  548. if(duplicates)
  549. {
  550. $('#js-error-row').show();
  551. $('#js-error-row').find('#error-message').text('Error: The selected criterion was already added.');
  552. return;
  553. }
  554. // Otherwise, hide the error container
  555. else
  556. {
  557. $('#js-error-row').hide();
  558. }
  559. // Fetch information of the criterion selected
  560. $.post
  561. (
  562. "{{ URL::route('fetchCriterionWithTemplate') }}",
  563. { id: id,
  564. },
  565. function(data)
  566. {
  567. // Append the fetched data
  568. copyright = null;
  569. notes = null;
  570. if(data.criterion.copyright){
  571. copyright = data.criterion.copyright;
  572. }
  573. if(data.criterion.notes){
  574. notes = data.criterion.notes;
  575. }
  576. objectives = JSON.stringify(objectives);
  577. var str ='<tr data-criterion-name ="'+data.criterion.name+'" data-program-ids = "['+program_ids+']" data-assoc-objectives = '+"'"+objectives+"'"+' data-criterion-id="'+data.criterion.id+'" data-criterion-copyright="'+copyright+'" data-criterion-notes="'+notes+'" data-outcomes = "'+data.outcomes+'"><th><span class="glyphicon glyphicon-move"></span></th><td>';
  578. // console.log(str);
  579. var subcriteria = '';
  580. if(data.criterion.subcriteria){
  581. var subcriteria_array = JSON.parse(data.criterion.subcriteria);
  582. subcriteria = '<ul class="subcriteria list-unstyled">';
  583. subcriteria_array.forEach(function (value) {
  584. subcriteria += '<li>'+value+'</li>';
  585. });
  586. subcriteria += '</ul>';
  587. }
  588. if(notes)
  589. {
  590. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+notes+'">'+data.criterion.name+'</em></span><sup></sup>'+subcriteria+'</td>';
  591. }
  592. else
  593. {
  594. str+='<span>'+data.criterion.name+'</span><sup></sup>'+subcriteria+'</td>';
  595. }
  596. numberOfScale = $('#number_of_scales').find(':selected').val();
  597. for(i=0; i<numberOfScale; i++){
  598. str+='<td>'+data.scales[i].description+'</td>';
  599. }
  600. str+= '<td>'+data.outcomes+'</td>'
  601. str +='<th><span class="glyphicon glyphicon-remove icon-btn" aria-hidden="true"></span></th></tr>';
  602. console.log(str);
  603. $('table tbody').append(str);
  604. // Build copyright list
  605. buildCopyrightList();
  606. // Enable X-Edtable on this new row
  607. $('.editable').editable({
  608. unsavedclass: null,
  609. rows: 4
  610. });
  611. // Turn on tooltips again (because content is dynamic)
  612. $('[data-toggle="tooltip"]').tooltip();
  613. // Sortable rows
  614. $('.table').sortable({
  615. handle: 'span.glyphicon.glyphicon-move',
  616. containerSelector: 'table',
  617. itemPath: '> tbody',
  618. itemSelector: 'tr',
  619. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  620. });
  621. },
  622. 'json',
  623. );
  624. }
  625. // Fetch single criterion
  626. function fetchCriterion(criterion)
  627. {
  628. $.post
  629. (
  630. "{{ URL::route('fetchCriterion') }}",
  631. { id: outcome.find(':selected').data('outcome-id')},
  632. function(data)
  633. {
  634. $('#select-criterion').empty();
  635. data.forEach( function (arrayItem)
  636. {
  637. $('#select-criterion')
  638. .append('<option data-criterion-id="'+arrayItem.id+'" >'+arrayItem.name+'</option>');
  639. });
  640. $('#select-criterion').append('<option data-criterion-id="0">Custom</option>');
  641. refreshSelects();
  642. }
  643. );
  644. }
  645. // Build list from copyright info in rubric
  646. function buildCopyrightList()
  647. {
  648. // Empty the copyright list
  649. $('#copyright-list').empty();
  650. $('tbody tr').each(function( index )
  651. {
  652. var criterion = $(this);
  653. // If there's copyright info
  654. if(criterion.data('criterion-copyright')!=null){
  655. var copyright = criterion.data('criterion-copyright');
  656. if($('#copyright-list li').length>0)
  657. {
  658. var found = false;
  659. $('#copyright-list li').each(function()
  660. {
  661. // If found, give the string its number
  662. if(copyright==$(this).find('span').text())
  663. {
  664. copyrightNumber = Number.parseInt($(this).find('sup').text());
  665. console.log('a: '+copyrightNumber);
  666. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  667. found =true;
  668. //to break
  669. return false;
  670. }
  671. });
  672. // Otherwise, give it the next number and append a new item to the
  673. // list
  674. if(!found)
  675. {
  676. var copyrightNumber = $('#copyright-list li').length+1;
  677. console.log('b: '+copyrightNumber);
  678. console.log(criterion.children('td:nth-child(2)').find('sup').length);
  679. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  680. $('#copyright-list').append('<li><sup>'+copyrightNumber+' </sup><span>'+copyright+'<span></li>');
  681. }
  682. }
  683. else
  684. {
  685. criterion.children('td:nth-child(2)').find('sup').text('1');
  686. $('#copyright-list').append('<li><sup>1 </sup><span>'+copyright+'<span></li>');
  687. }
  688. }
  689. });
  690. if($('#copyright-info li').length>0)
  691. {
  692. $('#copyright-info').show();
  693. }
  694. else
  695. {
  696. $('#copyright-info').hide();
  697. }}
  698. /* if(criterion.data('criterion-copyright')!=null)
  699. {
  700. var copyright = criterion.data('criterion-copyright');
  701. // If there is anything in the copyright list
  702. if($('#copyright-list li').length>0)
  703. {
  704. // Check copyright list for the same copyright text
  705. var found = false;
  706. $('#copyright-list li').each(function()
  707. {
  708. // If found, give the string its number
  709. if(copyright==$(this).find('span').text())
  710. {
  711. copyrightNumber = Number.parseInt($(this).find('sup').text());
  712. console.log('a: '+copyrightNumber);
  713. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  714. found =true;
  715. //to break
  716. return false;
  717. }
  718. });
  719. // Otherwise, give it the next number and append a new item to the
  720. // list
  721. if(!found)
  722. {
  723. var copyrightNumber = $('#copyright-list li').length+1;
  724. console.log('b: '+copyrightNumber);
  725. console.log(criterion.children('td:nth-child(2)').find('sup').length);
  726. criterion.children('td:nth-child(2)').find('sup').text(copyrightNumber);
  727. $('#copyright-list').append('<li><sup>'+copyrightNumber+' </sup><span>'+copyright+'<span></li>');
  728. }
  729. }
  730. // Otherwise, give it number 1 and append it
  731. else
  732. {
  733. criterion.children('td:nth-child(2)').find('sup').text('1');
  734. $('#copyright-list').append('<li><sup>1 </sup><span>'+copyright+'<span></li>');
  735. }
  736. }
  737. });
  738. if($('#copyright-info li').length>0)
  739. {
  740. $('#copyright-info').show();
  741. }
  742. else
  743. {
  744. $('#copyright-info').hide();
  745. }
  746. }
  747. */
  748. function refreshSelects()
  749. {
  750. $('#select-template').selectpicker('refresh');
  751. $('#select-school').selectpicker('refresh');
  752. $('#select-program').selectpicker('refresh');
  753. $('#select-outcome').selectpicker('refresh');
  754. $('#select-criterion').selectpicker('refresh');
  755. $('#expected_percentage').selectpicker('refresh');
  756. $('#expected_points').selectpicker('refresh');
  757. $('#number_of_scales').selectpicker('refresh');
  758. $('#select-objective').selectpicker('refresh');
  759. }
  760. // Fetch programs associated to a specific school
  761. function fetchPrograms(school)
  762. {
  763. $.ajax({
  764. type: 'POST',
  765. url: "{{ URL::action('ProgramsController@fetch') }}",
  766. data: { id: school.find(':selected').data('school-id')},
  767. success: function(data)
  768. {
  769. $('#select-program').empty();
  770. $('#select-program').append('<option data-program-id="0">All</option>');
  771. data.forEach( function (program)
  772. {
  773. $('#select-program')
  774. .append('<option data-program-id="'+program.id+'" >'+program.name+'</option>');
  775. });
  776. },
  777. async:false
  778. });
  779. if($('#select-school').find(':selected').data('school-id')!=0)
  780. $('#select-program').prop('disabled', false);
  781. else
  782. $('#select-program').prop('disabled', true);
  783. refreshSelects();
  784. }
  785. // Load a template. This function is different from the one for professors
  786. function loadTemplate()
  787. {
  788. $.post
  789. (
  790. "{{ URL::to('loadTemplate') }}",
  791. { id: $('#select-template').find(':selected').data('template-id')},
  792. function(data)
  793. {
  794. // Show the container and empty all rows
  795. $('#rubric-container').show();
  796. $('tbody').empty();
  797. //Set the name of the rubric
  798. $('#rubric-name').val(data.template.name);
  799. console.log(data.template.school_id);
  800. console.log($('#select-school'));
  801. // Set school id to 0, then to the saved value if it exists
  802. $('#select-school option[data-school-id="0"]').prop('selected', true);
  803. $('#select-school option[data-school-id="'+data.template.school_id+'"]').prop('selected', true);
  804. console.log($('#select-school'));
  805. // Fetch programs associated to that school
  806. fetchPrograms($('#select-school'));
  807. // Set program id to 0, then to the saved value if it exists
  808. $('#select-program option[data-program-id="0"]').prop('selected', true);
  809. $('#select-program option[data-program-id="'+data.template.program_id+'"]').prop('selected', true);
  810. // Set expected values
  811. console.log(data.template.expected_percentage);
  812. console.log(data.template.expected_points);
  813. console.log(data.template.max_score);
  814. $('#max_score').val(data.template.max_score);
  815. $('#max_score').trigger("change");
  816. $('#expected_percentage').val(data.template.expected_percentage);
  817. $('#expected_points').val(data.template.expected_points);
  818. $('#number_of_scales').val(data.template.num_scales);
  819. refreshSelects();
  820. changeTable();
  821. // Set visibility
  822. var is_visible = data.template.is_visible;
  823. if(is_visible)
  824. {
  825. $('#is_visible0').prop('checked', false);
  826. $('#is_visible1').prop('checked', true);
  827. }
  828. else
  829. {
  830. $('#is_visible1').prop('checked', false);
  831. $('#is_visible0').prop('checked', true);
  832. }
  833. // Set the contents of the rubric
  834. var temp_criterion = data.criterion;
  835. console.log(temp_criterion);
  836. for(temp_c in temp_criterion){
  837. current_criterion = temp_criterion[temp_c]
  838. console.log(current_criterion.program_ids);
  839. objectives = JSON.stringify(current_criterion.objectives);
  840. //var str = '<tr data-assoc-objectives= '+"'"+objectives+"'"+' data-program_ids = "'+current_criterion.program_ids+'" data-criterion-name = "'+current_criterion.name+'" data-criterion-id="'+temp_criterion[temp_c].criterion_id+'" data-criterion-copyright="'+temp_criterion[temp_c].copyright+'" data-criterion-notes="'+temp_criterion[temp_c].notes+'" data-outcomes = "'+temp_criterion[temp_c].outcomes+'"><th><span class="glyphicon glyphicon-move"></span></th><td>';
  841. var str = "<tr data-assoc-objectives= "+"'"+objectives+"'"+" data-program_ids = '"+current_criterion.program_ids+"' data-criterion-name = '"+current_criterion.name+"' data-criterion-id='"+temp_criterion[temp_c].criterion_id+"' data-criterion-copyright='"+temp_criterion[temp_c].copyright+"' data-criterion-notes='"+temp_criterion[temp_c].notes+"' data-outcomes = '"+temp_criterion[temp_c].outcomes+"'><th><span class='glyphicon glyphicon-move'></span></th><td>";
  842. console.log(str);
  843. var subcriteria ='';
  844. if(current_criterion.subcriteria){
  845. var subcriteria_array = JSON.parse(current_criterion.subcriteria);
  846. subcriteria = '<ul class="subcriteria list-unstyled">';
  847. subcriteria_array.forEach(function (value) {
  848. subcriteria += '<li>'+value+'</li>';
  849. });
  850. subcriteria += '</ul>';
  851. }
  852. if(current_criterion.notes)
  853. {
  854. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+current_criterion.notes+'">'+current_criterion.name+'</em></span><sup></sup>'+subcriteria;
  855. }
  856. else
  857. {
  858. str+='<span>'+current_criterion.name+'</span><sup></sup>'+subcriteria;
  859. }
  860. str+= '</td>';
  861. for(scaleIndex in current_criterion.scales){
  862. scale = current_criterion.scales[scaleIndex];
  863. str+='<td>'+scale.description+'</td>';
  864. }
  865. str+= '<td>'+current_criterion.outcomes+'</td>'
  866. str+='<th><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th></tr>';
  867. console.log(str);
  868. $('table tbody').append(str);
  869. // Enable X-Edtable on this new row
  870. $('.editable').editable({
  871. unsavedclass: null,
  872. rows: 4
  873. });
  874. // Turn on tooltips again (because content is dynamic)
  875. $('[data-toggle="tooltip"]').tooltip();
  876. refreshSelects();
  877. }
  878. /*
  879. var contents = JSON.parse(data.contents);
  880. contents.forEach(function (data)
  881. {
  882. // Append the fetched data
  883. var str ='<tr data-criterion-id="'+data.id+'" data-criterion-copyright="'+data.copyright+'" data-criterion-notes="'+data.notes+'"><th><span class="glyphicon glyphicon-move"></span></th><td>';
  884. var subcriteria = '';
  885. if(data.subcriteria){
  886. var subcriteria_array = data.subcriteria;
  887. subcriteria = '<ul class="subcriteria list-unstyled">';
  888. subcriteria_array.forEach(function (value) {
  889. subcriteria += '<li>'+value+'</li>';
  890. });
  891. subcriteria += '</ul>';
  892. }
  893. if(data.notes)
  894. {
  895. str+='<span><em data-toggle="tooltip" data-placement="top" title="'+data.notes+'">'+data.name+'</em></span><sup></sup>'+subcriteria;
  896. }
  897. else
  898. {
  899. str+='<span>'+data.name+'</span><sup></sup>'+subcriteria;
  900. }
  901. str+='</td><td class="editable" data-type="textarea">'+data.description12+'</td>'
  902. +'<td class="editable" data-type="textarea">'+data.description34+'</td>'
  903. +'<td class="editable" data-type="textarea">'+data.description56+'</td>'
  904. +'<td class="editable" data-type="textarea">'+data.description78+'</td>'
  905. +'<th><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th></tr>';
  906. $('table tbody').append(str);
  907. // Build copyright list
  908. buildCopyrightList();
  909. // Enable X-Edtable on this new row
  910. $('.editable').editable({
  911. unsavedclass: null,
  912. rows: 4
  913. });
  914. // Turn on tooltips again (because content is dynamic)
  915. $('[data-toggle="tooltip"]').tooltip();
  916. refreshSelects();
  917. }); */
  918. // Sortable rows
  919. $('.table').sortable({
  920. handle: 'span.glyphicon.glyphicon-move',
  921. containerSelector: 'table',
  922. itemPath: '> tbody',
  923. itemSelector: 'tr',
  924. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  925. });
  926. // Build Copyright List
  927. buildCopyrightList();
  928. $('.editable').each(function (index){
  929. $(this).text(data.titles[index].text);
  930. })
  931. var selected = $('#select-template').find(':selected');
  932. var programs = {{ json_encode(Auth::user()->programs->lists('id')) }};
  933. var template_program = selected.data('template-program-id');
  934. // console.log(selected.data('template-program-id'));
  935. // console.log(programs.includes(selected.data('template-program-id').toString()));
  936. if(
  937. {{ Auth::user()->role }}==1
  938. || ({{ Auth::user()->role }}==2 && selected.data('admin')!=1)
  939. || ({{ Auth::user()->role }}==3
  940. && programs.includes(selected.data('template-program-id'))
  941. && selected.data('admin')!=1
  942. )
  943. )
  944. {
  945. $('#button-confirm-delete-rubric').prop('disabled', false);
  946. $('#button-confirm-update-rubric').prop('disabled', false);
  947. }
  948. else
  949. {
  950. // Disable update and edit
  951. $('#button-confirm-delete-rubric').prop('disabled', true);
  952. $('#button-confirm-update-rubric').prop('disabled', true);
  953. }
  954. // Enable print button
  955. $('#button-print-rubric').prop('disabled', false);
  956. fetchCriteria($('#select-outcome'), $('#select-objective'));
  957. },
  958. 'json',
  959. );
  960. }
  961. // Checks whether the user wants to save a rubric with a name that already exists
  962. function nameExists()
  963. {
  964. var duplicates = false;
  965. $('#select-template option').each(function()
  966. {
  967. var optionName = $(this).text().trim();
  968. if($('#rubric-name').val().trim()===optionName)
  969. {
  970. duplicates = true;
  971. }
  972. });
  973. refreshSelects();
  974. return duplicates;
  975. }
  976. //Enable disable program select
  977. function toggleProgramSelect(school)
  978. {
  979. if(school.find(':selected').data('school-id') <1)
  980. {
  981. $('#select-program option[data-program-id="0"]').prop('selected', true);
  982. $('#select-program').prop('disabled', true);
  983. }
  984. else
  985. {
  986. console.log(school);
  987. fetchPrograms(school);
  988. $('#select-program').prop('disabled', false);
  989. }
  990. refreshSelects();
  991. }
  992. fetchObjective($('#select-outcome'));
  993. // --------------------------------------------------------------------------
  994. // Events
  995. // --------------------------------------------------------------------------
  996. // Toggle visibility for accordion panels
  997. $('.panel-heading').on('click', function()
  998. {
  999. if($(this).find('.glyphicon').hasClass('glyphicon-triangle-right'))
  1000. {
  1001. $(this).find('.glyphicon').removeClass('glyphicon-triangle-right');
  1002. $(this).find('.glyphicon').addClass('glyphicon-triangle-bottom');
  1003. }
  1004. else if($(this).find('.glyphicon').hasClass('glyphicon-triangle-bottom'))
  1005. {
  1006. $(this).find('.glyphicon').removeClass('glyphicon-triangle-bottom');
  1007. $(this).find('.glyphicon').addClass('glyphicon-triangle-right');
  1008. }
  1009. $(this).siblings('.panel-body').stop().slideToggle();
  1010. });
  1011. // Fetch criteria everytime something changes
  1012. $('#select-objective').on('change', function(){
  1013. fetchCriteria($('#select-outcome'), $('#select-objective'));
  1014. })
  1015. $("#number_of_scales").on('change', function(){
  1016. fetchCriteria($('#select-outcome'), $('#select-objective'));
  1017. })
  1018. // When trying to change the template, ask the user to confirm and reset the
  1019. // rubric if s/he does
  1020. $('#select-template').on('change', function()
  1021. {
  1022. // If changing to custom template, reset
  1023. if($('#select-template').find(':selected').data('template-id')=='0')
  1024. {
  1025. $('#rubric-container').hide();
  1026. $('#rubric-name').val('');
  1027. $('tbody').empty();
  1028. // Disable delete, update and print buttons
  1029. $('#button-confirm-delete-rubric').prop('disabled', true);
  1030. $('#button-confirm-update-rubric').prop('disabled', true);
  1031. $('#button-print-rubric').prop('disabled', true);
  1032. }
  1033. // Otherwise, load the selected template
  1034. else
  1035. {
  1036. loadTemplate();
  1037. //If user is admin, or the templates id matches user's, or the template
  1038. // id's school matches user, allow editing
  1039. var selected = $('#select-template').find(':selected');
  1040. var programs = {{ json_encode(Auth::user()->programs->lists('id')) }};
  1041. var template_program = selected.data('template-program-id');
  1042. <!-- var dataset = selected.dataSet.templateProgramId; -->
  1043. if(
  1044. {{ Auth::user()->role }}==1
  1045. || ({{ Auth::user()->role }}==2 && selected.data('admin')!=1)
  1046. || ({{ Auth::user()->role }}==3
  1047. && programs.includes(selected.data('template-program-id'))
  1048. && selected.data('admin')!=1
  1049. )
  1050. )
  1051. {
  1052. $('#button-confirm-delete-rubric').prop('disabled', false);
  1053. $('#button-confirm-update-rubric').prop('disabled', false);
  1054. }
  1055. else
  1056. {
  1057. // Disable update and edit
  1058. $('#button-confirm-delete-rubric').prop('disabled', true);
  1059. $('#button-confirm-update-rubric').prop('disabled', true);
  1060. }
  1061. if($('#select-template').find(':selected').data('unmatch-criteria')=='1')
  1062. {
  1063. $('#button-confirm-delete-rubric').prop('disabled', true);
  1064. $('#button-confirm-update-rubric').prop('disabled', true);
  1065. $('#button-create-rubric').prop('disabled', true);
  1066. }
  1067. else
  1068. {
  1069. $('#button-create-rubric').prop('disabled', false);
  1070. }
  1071. // Enable print button
  1072. $('#button-print-rubric').prop('disabled', false);
  1073. }
  1074. });
  1075. function changeTable(){
  1076. amount_of_scales = parseInt($('#number_of_scales').find(':selected').val());
  1077. counter2 = 0;
  1078. maximum = parseInt($('#max_score').find(":selected").val());
  1079. newScaleHeaders = '<th></th><th>Criterion</th>';
  1080. editableTitles = '<th></th><th></th>';
  1081. counter = 0;
  1082. division = maximum/amount_of_scales;
  1083. if(amount_of_scales==1){
  1084. newScaleHeaders+= "<th>Score (1 - "+maximum+")</th>";
  1085. editableTitles += "<th class = 'editable' data-type = 'textarea'>Click to edit Title </th>"
  1086. }
  1087. else if(maximum!= amount_of_scales){
  1088. while(counter <amount_of_scales){
  1089. minimumScore = 1+(counter*division);
  1090. maximumScore = (1+counter)*division;
  1091. newScaleHeaders+= "<th>Scale "+ (counter +1) + " ("+minimumScore+" - "+maximumScore+")</th>";
  1092. editableTitles+="<th class = 'editable' data-type = 'textarea'>Click to edit Title "+(counter+1)+"</th>"
  1093. counter++;
  1094. }
  1095. }else{
  1096. while(counter <amount_of_scales){
  1097. newScaleHeaders+= "<th>Scale "+ (counter +1) + " </th>";
  1098. editableTitles+="<th class = 'editable' data-type = 'textarea'>Click to edit Title "+(counter+1)+"</th>"
  1099. counter++;
  1100. }
  1101. }
  1102. newScaleHeaders += '<th>Outcomes</th><th></th>';
  1103. editableTitles += '<th></th><th></th>';
  1104. $('#theScaleTitles').html(editableTitles);
  1105. $("#criterion-header").html(newScaleHeaders);
  1106. $('#allCriteria').html(' ');
  1107. }
  1108. // When a school changes, update its programs. If all is selected, disable
  1109. $('#select-school').on('change', function()
  1110. {
  1111. toggleProgramSelect($(this));
  1112. });
  1113. $('#max_score').on('change', function(){
  1114. var max = parseInt($('#max_score').find(':selected').val());
  1115. var stringToScales = "<option value= '1'>Cuantitative Rubric </option>";
  1116. selectedValue = 1;
  1117. valueBefore = 0;
  1118. for(i=2; i<=20; i++){
  1119. if(max%i==0){
  1120. stringToScales += "<option value= '"+i+"'>"+i+"-Scale Rubric</option>";
  1121. selectedValue = i - valueBefore;
  1122. valueBefore = i;
  1123. }
  1124. }
  1125. $('#number_of_scales').html(stringToScales);
  1126. $('#number_of_scales').selectpicker('refresh');
  1127. $('#number_of_scales').val(selectedValue);
  1128. $('#number_of_scales').selectpicker('refresh');
  1129. var expected_points = Math.floor(max *0.7);
  1130. var expected_points_html = '';
  1131. for(i=1; i<max; i++){
  1132. expected_points_html += '<option value="'+i+'"> '+i+'</option>';
  1133. }
  1134. $('#expected_points').html(expected_points_html);
  1135. refreshSelects();
  1136. $('#expected_points').val(expected_points);
  1137. refreshSelects();
  1138. changeTable();
  1139. fetchCriteria($('#select-outcome'), $('#select-objective'))
  1140. })
  1141. $('#number_of_scales').on('change', function(){
  1142. changeTable();
  1143. $('#rubric-container').hide();
  1144. $('#rubric-name').val('');
  1145. $('tbody').empty();
  1146. })
  1147. // When a learning outcome changes, update its criteria
  1148. /*$('#select-outcome, input[name=criteria-filter]').on('change', function()
  1149. {
  1150. fetchCriteria($('#select-outcome'));
  1151. });
  1152. */
  1153. // When the add button is clicked
  1154. $('#button-add-criterion').on('click', function(e)
  1155. {
  1156. //Prevent page refresh
  1157. e.preventDefault();
  1158. //Add new criterion
  1159. addCriterion();
  1160. });
  1161. // When the create or update buttons are clicked (.save)
  1162. $('.save').on('click', function(e)
  1163. {
  1164. //Prevent page refresh
  1165. e.preventDefault();
  1166. var emptyFields=false;
  1167. $('#allCriteria').children('td').each(function()
  1168. {
  1169. if (($(this).text() == "" || $(this).text() == "Empty") && !($(this).hasClass('nullable')) )
  1170. {
  1171. emptyFields=true;
  1172. }
  1173. });
  1174. // If any fields are empty, display error
  1175. if(emptyFields || $.trim($('#rubric-name').val())=='')
  1176. {
  1177. $('#js-error-row').show();
  1178. $('#js-error-row').find('#error-message').text('Error: Please fill all the fields. Make sure your rubric has a name and all scale scores are filled.');
  1179. return;
  1180. }
  1181. else
  1182. {
  1183. $('#js-error-row').hide();
  1184. }
  1185. // Check whether a rubric with the written name already exists
  1186. if($(this).attr('id')=='button-create-rubric' && nameExists())
  1187. {
  1188. $('#js-error-row').show();
  1189. $('#js-error-row').find('#error-message').text('Error: A template with that name already exists.');
  1190. return;
  1191. }
  1192. else
  1193. {
  1194. $('#js-error-row').hide();
  1195. }
  1196. /*
  1197. program_id = $('#select-program').find(':selected').data('program-id')
  1198. if(program_id == 0){
  1199. $('#modal-title-rubric').html("All criteria will be associated with this school's programs");
  1200. htmlString = "<h5>The following criteria and objectives will be matched with all programs</h5>"
  1201. htmlString += "<ol style='list-style-position: inside'>"
  1202. $('tbody tr').each(function( index )
  1203. {
  1204. objectives = $(this).data('assoc-objectives');
  1205. htmlString += "<li>" +$(this).data('criterion-name');
  1206. htmlString += "<br><h5>This criterion is associated with these objectives</h5>"
  1207. htmlString +="<ul style='padding-left: 5%; list-style-position: inside'>"
  1208. for(index in objectives){
  1209. objective_string = objectives[index];
  1210. htmlString +="<li>"+objective_string+"</li>";
  1211. }
  1212. htmlString += "</ul>"
  1213. htmlString +="</li>"
  1214. htmlString+= "<br>";
  1215. });
  1216. htmlString +='</ol>';
  1217. $("#modal-body-rubric").html(htmlString);
  1218. }
  1219. else{
  1220. $('#modal-title-rubric').html('Some criteria will be associated with this program');
  1221. $('tbody tr').each(function( index )
  1222. {
  1223. htmlString = '';
  1224. console.log($(this));
  1225. if(typeof $(this).data('program_ids')!== 'undefined')
  1226. {
  1227. program_ids = $(this).data('program_ids');
  1228. console.log("ids"+program_ids);
  1229. console.log("ids"+$(this).data('program_ids'));
  1230. }
  1231. else if(typeof $(this).data('program-ids')!== 'undefined')
  1232. {
  1233. program_ids = $(this).data('program-ids')
  1234. console.log("Ids"+program_ids);
  1235. }
  1236. else
  1237. {
  1238. program_ids = [];
  1239. console.log(" "+program_ids);
  1240. }
  1241. console.log(program_ids);
  1242. // program_ids = $(this).data('program_ids')
  1243. if(!program_ids.includes(program_id) ){
  1244. title = "<h6>The following criteria and objectives will be matched with this program</h6>"
  1245. htmlString += "<ol style='list-style-position: inside'>"
  1246. objectives = $(this).data('assoc-objectives');
  1247. //objectives = objectives.split(',');
  1248. htmlString += "<li>" +$(this).data('criterion-name');
  1249. htmlString += "<br><h6>This criterion is associated with these objectives</h6>"
  1250. htmlString +="<ul style='padding-left: 5%; list-style-position: inside'>"
  1251. for(index in objectives){
  1252. objective_string = objectives[index];
  1253. htmlString +="<li>"+objective_string+"</li>";
  1254. }
  1255. htmlString += "</ul>"
  1256. htmlString +="</li>"
  1257. htmlString+= "<br>";
  1258. }
  1259. if(htmlString != ''){
  1260. $("#modal-body-rubric").html(title);
  1261. $("#modal-body-rubric").append(htmlString);
  1262. }
  1263. });
  1264. }
  1265. $('#rubric-modal').modal('toggle');*/
  1266. $('#saveButton').data('button-id',$(this).attr('id'));
  1267. saveTemplate();
  1268. });
  1269. // When the confirm delete button is clicked
  1270. $('#button-delete-rubric').on('click', function(e)
  1271. {
  1272. $('#modal-confirm-delete').modal('hide');
  1273. // Delete from database
  1274. $.post
  1275. (
  1276. "{{ URL::to('deleteTemplate') }}",
  1277. {
  1278. id: $('#select-template').find(':selected').data('template-id')
  1279. },
  1280. function(data)
  1281. {
  1282. location.reload();
  1283. }
  1284. );
  1285. });
  1286. // Remove a criterion and hide the table if it was the only one
  1287. $('table').on('click', 'span.glyphicon-remove', function(e)
  1288. {
  1289. $(this).closest('tr').remove();
  1290. if(!$('tbody').children().length)
  1291. {
  1292. $('#rubric-container').hide();
  1293. }
  1294. buildCopyrightList();
  1295. });
  1296. // When print button is clicked, redirect to print page
  1297. $('#button-print-rubric').on('click', function(e)
  1298. {
  1299. e.preventDefault();
  1300. window.location = "printRubric/"+$('#select-template').find(':selected').data('template-id');
  1301. });
  1302. // --------------------------------------------------------------------------
  1303. // Page load
  1304. // --------------------------------------------------------------------------
  1305. $('#updated-text').hide();
  1306. // Enable/disable program selection depending on school selection if user is
  1307. // admin
  1308. if({{Auth::user()->role}}==1)
  1309. toggleProgramSelect($('#select-school'));
  1310. // Fetch criteria of first outcome
  1311. fetchCriteria($('#select-outcome'), $('#select-objective'));
  1312. changeTable();
  1313. // Hide table
  1314. $('#rubric-container').hide();
  1315. // Disable Update and Delete Buttons by default
  1316. $('#button-confirm-update-rubric').prop('disabled', true);
  1317. $('#button-confirm-delete-rubric').prop('disabled', true);
  1318. $('#button-print-rubric').prop('disabled', true);
  1319. // Sortable rows
  1320. $('.table').sortable({
  1321. handle: 'span.glyphicon.glyphicon-move',
  1322. containerSelector: 'table',
  1323. itemPath: '> tbody',
  1324. itemSelector: 'tr',
  1325. placeholder: '<tr class="placeholder"><th><span class="glyphicon glyphicon-arrow-right"></span></th></tr>'
  1326. });
  1327. @stop