listview.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. // or see http://www.gnu.org/
  16. //
  17. // \file htdocs/core/js/listview.js
  18. // \brief File that include javascript functions for lists
  19. //
  20. var Listview_include = true;
  21. function Listview_OrderDown(idListe, column) {
  22. var base_url = document.location.href;
  23. base_url = Listview_recup_form_param(idListe,base_url);
  24. base_url = Listview_removeParam(base_url,'Listview['+encodeURIComponent(idListe)+'][orderBy]');
  25. base_url = Listview_removeParam(base_url,'get-all-for-export');
  26. document.location.href=Listview_modifyUrl(base_url,"Listview["+encodeURIComponent(idListe)+"][orderBy]["+encodeURIComponent(column)+"]","DESC");
  27. }
  28. function Listview_OrderUp(idListe, column) {
  29. var base_url = document.location.href;
  30. base_url = Listview_recup_form_param(idListe,base_url);
  31. base_url = Listview_removeParam(base_url,'Listview['+encodeURIComponent(idListe)+'][orderBy]');
  32. base_url = Listview_removeParam(base_url,'get-all-for-export');
  33. document.location.href=Listview_modifyUrl(base_url,"Listview["+encodeURIComponent(idListe)+"][orderBy]["+encodeURIComponent(column)+"]","ASC");
  34. }
  35. function Listview_modifyUrl(strURL,paramName,paramNewValue){
  36. if (strURL.indexOf(paramName+'=')!=-1){
  37. var strFirstPart=strURL.substring(0,strURL.indexOf(paramName+'=',0))+paramName+'=';
  38. var strLastPart="";
  39. if (strURL.indexOf('&',strFirstPart.length-1)>0)
  40. strLastPart=strURL.substring(strURL.indexOf('&',strFirstPart.length-1),strURL.length);
  41. strURL=strFirstPart+paramNewValue+strLastPart;
  42. }
  43. else{
  44. if (strURL.search('=')!=-1) // permet de verifier s'il y a dej� des param�tres dans l'URL
  45. strURL+='&'+paramName+'='+paramNewValue;
  46. else
  47. strURL+='?'+paramName+'='+paramNewValue;
  48. }
  49. return strURL;
  50. }
  51. function Listview_removeParam(strURL, paramMask) {
  52. var cpt=0;
  53. var url = '';
  54. while(strURL.indexOf(paramMask)!=-1 && cpt++ <50){
  55. var strFirstPart= strURL.substring(0,strURL.indexOf(paramMask)-1);
  56. var strLastPart='';
  57. if (strURL.indexOf('&',strFirstPart.length+1)>0) {
  58. strLastPart = strURL.substring(strURL.indexOf('&',strFirstPart.length+1),strURL.length);
  59. }
  60. url = strFirstPart+strLastPart;
  61. }
  62. if(url=='')url = strURL;
  63. return url;
  64. }
  65. function Listview_recup_form_param(idListe,base_url) {
  66. $('#'+idListe+' tr.barre-recherche [listviewtbs],#'+idListe+' tr.barre-recherche-head input,#'+idListe+' tr.barre-recherche-head select,#'+idListe+' div.tabsAction input[listviewtbs]').each(function(i,item) {
  67. if($(item).attr("name")) {
  68. base_url = Listview_modifyUrl(base_url, $(item).attr("name") , $(item).val());
  69. }
  70. });
  71. return base_url;
  72. }
  73. function Listview_GoToPage(idListe,pageNumber){
  74. var base_url = document.location.href;
  75. base_url = Listview_recup_form_param(idListe,base_url);
  76. base_url =Listview_modifyUrl(base_url,"Listview["+encodeURIComponent(idListe)+"][page]",pageNumber);
  77. base_url = Listview_removeParam(base_url,'get-all-for-export');
  78. document.location.href=base_url;
  79. }
  80. function Listview_submitSearch(obj) {
  81. $form = $(obj).closest('form');
  82. console.log($form);
  83. if($form.length>0){
  84. $form.submit();
  85. }
  86. }
  87. function Listview_launch_downloadAs(mode,url,token,session_name) {
  88. $('#listviewdAS_export_form').remove();
  89. $form = $('<form action="'+url+'" method="post" name="listviewdAS_export_form" id="listTBSdAS_export_form"></form>');
  90. $form.append('<input type="hidden" name="mode" value="'+mode+'" />');
  91. $form.append('<input type="hidden" name="token" value="'+token+'" />');
  92. $form.append('<input type="hidden" name="session_name" value="'+session_name+'" />');
  93. $('body').append($form);
  94. $('#listviewdAS_export_form').submit();
  95. }
  96. function Listview_downloadAs(obj, mode,url,token,session_name) {
  97. $form = $(obj).closest('form');
  98. $div = $form.find('div.tabsAction');
  99. $div.append('<input type="hidden" listviewtbs="hidden" name="token" value="'+token+'" />');
  100. $div.append('<input type="hidden" listviewtbs="hidden" name="mode" value="'+mode+'" />');
  101. $div.append('<input type="hidden" listviewtbs="hidden" name="url" value="'+url+'" />');
  102. $div.append('<input type="hidden" listviewtbs="hidden" name="session_name" value="'+session_name+'" />');
  103. $div.append('<input type="hidden" listviewtbs="hidden" name="get-all-for-export" value="1" />');
  104. Listview_submitSearch(obj);
  105. }
  106. $(document).ready(function() {
  107. $('tr.barre-recherche input').keypress(function(e) {
  108. if(e.which == 13) {
  109. var id_list = $(this).closest('table').attr('id');
  110. $('#'+id_list+' .list-search-link').click();
  111. }
  112. });
  113. var $_GET = {};
  114. document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
  115. function decode(s) {
  116. return decodeURIComponent(s.split("+").join(" "));
  117. }
  118. $_GET[decode(arguments[1])] = decode(arguments[2]);
  119. });
  120. if(typeof $_GET["get-all-for-export"] != "undefined") {
  121. Listview_launch_downloadAs($_GET['mode'],$_GET['url'],$_GET['token'],$_GET['session_name']);
  122. }
  123. });