Le repo des sources pour le site web des JM2L
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

117 lignes
3.7 KiB

  1. # -*- coding: utf-8 -*-
  2. <%inherit file="jm2l:templates/layout.mako"/>
  3. <%def name="cssAddOn()">
  4. <style>
  5. .data {
  6. display:none;
  7. }
  8. .table thead th {
  9. background-color: lightblue;
  10. vertical-align:middle;
  11. text-align:center;
  12. }
  13. th.SortUp {
  14. background: url("/static/img/up.gif") right center no-repeat;
  15. }
  16. th.SortDown {
  17. background: url("/static/img/down.gif") right center no-repeat;
  18. }
  19. </style>
  20. </%def>
  21. <script src="/vendor/jquery.min.js"></script>
  22. <script>
  23. $(function () {
  24. $('th').click(function(){
  25. var table = $(this).parents('table').eq(0)
  26. var rows = table.find("tr:not(:has('th'))").toArray().sort(comparer($(this).index(),this.asc))
  27. this.asc = !this.asc
  28. table.find('th').removeClass( "SortDown SortUp" );
  29. if (!this.asc){
  30. rows = rows.reverse();
  31. table.find('th:eq('+$(this).index()+')').toggleClass('SortDown');
  32. } else {
  33. table.find('th:eq('+$(this).index()+')').toggleClass('SortUp');
  34. }
  35. for (var i = 0; i < rows.length; i++){table.append(rows[i])}
  36. })
  37. function comparer(index, order) {
  38. if (index==3 || index==7)
  39. return function(a, b) {
  40. var dateA = new Date(getCellValue(a, index)).getTime();
  41. var dateB = new Date(getCellValue(b, index)).getTime();
  42. if (isNaN(dateA) && isNaN(dateB)) return 0
  43. if (isNaN(dateA)) return order ? -1 : 1
  44. if (isNaN(dateB)) return order ? 1 : -1
  45. return dateA > dateB ? 1 : -1;
  46. }
  47. else
  48. return function(a, b) {
  49. var valA = getCellValue(a, index), valB = getCellValue(b, index)
  50. if (valA==="" && valB==="") return 0
  51. if (valA==="") return order ? -1 : 1
  52. if (valB==="") return order ? 1 : -1
  53. return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB : valA.localeCompare(valB)
  54. }
  55. }
  56. function no_accent(my_string) {
  57. var new_string = "";
  58. var pattern_accent = new Array("é", "è", "ê", "ë", "ç", "à", "â", "ä", "î", "ï", "ù", "ô", "ó", "ö");
  59. var pattern_replace_accent = new Array("e", "e", "e", "e", "c", "a", "a", "a", "i", "i", "u", "o", "o", "o");
  60. if (my_string && my_string!= "") {
  61. for(var i = 0; i < pattern_accent.length; i++){
  62. my_string = my_string.replace(pattern_accent[i], pattern_replace_accent[i]);
  63. }
  64. }
  65. return my_string;
  66. }
  67. function getCellValue(row, index){
  68. switch (index) {
  69. case 0: // Name
  70. return no_accent( $(row).children('td').eq(index).children('a').text().toLowerCase() );
  71. break;
  72. default:
  73. return no_accent( $(row).children('td').eq(index).children('span').text() );
  74. //return $(row).children('td').eq(index).html();
  75. }
  76. }
  77. // additional code to apply a filter
  78. $('table').each(function(){
  79. var table = $(this)
  80. var headers = table.find('th').length;
  81. var filterrow = table.find('th:first()').prepend($('<div>').attr('class','input-append').click(function(){return false;}));
  82. filterrow.find('div').append($('<input>').attr('type','text').keyup(function(){
  83. table.find('tr').show()
  84. filterrow.find('input[type=text]').each(function(){
  85. var index = $(this).parent().index() + 1;
  86. var filter = $(this).val() != '';
  87. $(this).toggleClass('filtered', filter);
  88. if (filter){
  89. var el = 'td:nth-child('+index+') > span.data';
  90. var criteria = ":contains('"+$(this).val().toLowerCase()+"')";
  91. table.find(el+':not('+no_accent(criteria)+')').parent().parent().hide();
  92. }
  93. });
  94. }));
  95. filterrow.find('div').append($('<span>').attr('class','btn').attr('type','button').text('C').click(function(){
  96. $(this).parent().parent().find('input[type=text]').val('').toggleClass('filtered', false)
  97. table.find('tr').show()
  98. }))
  99. })
  100. });
  101. </script>
  102. ${next.body()}