menu.js.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/admin/menus/menu.js.php
  19. * \brief File for js menu
  20. */
  21. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  22. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled to increase speed. Language code is found on url.
  23. if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  24. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
  25. if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1);
  26. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1);
  27. if (! defined('NOLOGIN')) define('NOLOGIN',1);
  28. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1);
  29. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
  30. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  31. session_cache_limiter( FALSE );
  32. require_once("../../master.inc.php");
  33. require_once(DOL_DOCUMENT_ROOT."/lib/functions.lib.php");
  34. // Define css type
  35. header('Content-type: application/javascript');
  36. // Important: Following code is to avoid page request by browser and PHP CPU at
  37. // each Dolibarr page access.
  38. if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate');
  39. else header('Cache-Control: no-cache');
  40. // On the fly GZIP compression for all pages (if browser support it). Must set the bit 3 of constant to 1.
  41. if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x04)) { ob_start("ob_gzhandler"); }
  42. if (GETPOST('lang')) $langs->setDefaultLang(GETPOST('lang')); // If language was forced on URL
  43. if (GETPOST('theme')) $conf->theme=GETPOST('theme'); // If theme was forced on URL
  44. $langs->load("main",0,0);
  45. ?>
  46. // Tests pour navigateurs
  47. var OPE = (window.opera) ? true : false;
  48. var IE = (document.all && !OPE) ? true : false;
  49. var MOZ = (!IE && !OPE) ? true : false;
  50. // -----------------------------------------------------
  51. // Fonction d'initialisation de l'arbre
  52. function arbre() {
  53. // Choix de la balise contenant le texte. (strong par defaut).
  54. balise = "STRONG";
  55. // Presentation de l'arbre au depart : deployee ('yes') ou fermee ('no')
  56. extend = "no";
  57. // Textes du lien plier / deplier
  58. plier_text = '<?php echo $langs->transnoentities("UndoExpandAll"); ?>';
  59. plier_title = 'Replier tous les noeuds de l\'arbre'
  60. deplier_text = '<?php echo $langs->transnoentities("ExpandAll"); ?>';
  61. deplier_title = 'Deplier tous les noeuds de l\'arbre'
  62. // Recuperation de tous les arbres de la page
  63. uls = getElBy('ul','class','arbre');
  64. for (uli=0;uli < uls.length;uli++)
  65. {
  66. ul = uls[uli];
  67. linkSwitch(ul);
  68. processULEL(ul);
  69. plier(ul,'replier');
  70. }
  71. }
  72. // -------------------------------------------------------
  73. // Creation des liens plier /deplier tout
  74. function linkSwitch(ul) {
  75. var a=document.createElement('a');
  76. a.setAttribute('href','#');
  77. if (extend=='yes') {
  78. a.appendChild(document.createTextNode(plier_text));
  79. a.setAttribute('title',plier_title);
  80. }
  81. else {
  82. a.appendChild(document.createTextNode(deplier_text));
  83. a.setAttribute('title',deplier_title);
  84. }
  85. var parbre = document.createElement('p');
  86. parbre.setAttribute('class','arbre-switch');
  87. parbre.appendChild(a);
  88. ul.parentNode.insertBefore(parbre,ul);
  89. listenlink(ul);
  90. }
  91. // Gestion des Clics sur les liens plier / deplier tout
  92. function listenlink(ul) {
  93. var link = ul.previousSibling.childNodes[0];
  94. link.onclick = function() {
  95. if (this.childNodes[0].nodeValue == plier_text) {
  96. plier(ul,'replier');
  97. this.childNodes[0].nodeValue = deplier_text;
  98. this.setAttribute('title',deplier_title);
  99. }
  100. else {
  101. plier(ul,'deplier');
  102. this.childNodes[0].nodeValue = plier_text;
  103. this.setAttribute('title',plier_title);
  104. }
  105. return false;
  106. }
  107. }
  108. // Action Plier / deplier tout
  109. function plier(ul,act) {
  110. for (var i=0; i < ul.childNodes.length; i++) {
  111. var li = ul.childNodes[i];
  112. if (li.nodeName == 'LI') {
  113. for (var j=0; j < li.childNodes.length; j++) {
  114. var child = li.childNodes[j];
  115. if (child.nodeName==balise) {
  116. var strong = child;
  117. }
  118. if (child.nodeName=='UL') {
  119. if (act=='replier') {
  120. child.className='hide';
  121. strong.className='arbre-plier';
  122. }
  123. else {
  124. child.className='';
  125. strong.className='arbre-deplier';
  126. }
  127. var sub = child;
  128. plier(sub,act);
  129. }
  130. }
  131. }
  132. }
  133. }
  134. // ---------------------------------------------------------
  135. // Analyse de l'arbre
  136. function processULEL(ul) {
  137. if (!ul.childNodes || ul.childNodes.length == 0) return;
  138. // Iterate LIs
  139. for (var itemi=0;itemi < ul.childNodes.length;itemi++) {
  140. var item = ul.childNodes[itemi];
  141. if (item.nodeName == "LI") {
  142. // Contenu des balises LI
  143. var a;
  144. var subul;
  145. subul = "";
  146. for (var sitemi=0;sitemi < item.childNodes.length;sitemi++) {
  147. // Uniquement pour moz-firefox
  148. if (MOZ) {item.style.background = "";}
  149. // Enfants des li : balise ou sous-ul
  150. var sitem = item.childNodes[sitemi];
  151. switch (sitem.nodeName) {
  152. case balise:
  153. a = sitem;
  154. break;
  155. case "UL":
  156. subul = sitem;
  157. if (extend != "yes") {sitem.className = 'hide';}
  158. processULEL(subul);
  159. break;
  160. }
  161. }
  162. if (subul) {
  163. if (extend!="yes") {
  164. a.className='arbre-plier';
  165. }
  166. else {
  167. a.className='arbre-deplier';
  168. subul.className='';
  169. }
  170. associateEL(a,subul);
  171. }
  172. }
  173. }
  174. }
  175. // Swicth des noeuds
  176. function associateEL(a,ul) {
  177. a.onclick = function () {
  178. this.className = (ul.className=='hide') ? 'arbre-deplier' : 'arbre-plier';
  179. ul.className = (ul.className=='hide') ? '' : 'hide';
  180. return false;
  181. }
  182. }
  183. // -----------------------------------------------------
  184. // Nom : GetElBy(tag,attr,val)
  185. // By : Rui Nibau
  186. // Date : aout 2005
  187. // Func : Tableau des elements 'tag' dont l'attribut 'attr' a la valeur 'val'.
  188. // -----------------------------------------------------
  189. function getElBy(tag,attr,val) {
  190. var dbRes = [];
  191. var dbEl = document.getElementsByTagName(tag);
  192. for (e=0; e < dbEl.length; e++) {
  193. if (attr == 'class') {if (dbEl[e].className==val) {dbRes.push(dbEl[e]);}}
  194. else {if (dbEl[e].getAttribute(attr)==val) {dbRes.push(dbEl[e]);}}
  195. }
  196. return dbRes;
  197. }
  198. // -----------------------------------------------------
  199. // A l'affichage de la page, lancer la fonction arbre
  200. window.onload = function() {
  201. arbre();
  202. }
  203. function imgDel(id)
  204. {
  205. var delId='del'+id;
  206. var imgDel = document.getElementById('del'+id);
  207. if (imgDel != null) imgDel.style.display='block';
  208. return true;
  209. }