From 9ddd6215f8100f5fc600e5657d84a650a395f29d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Feb 2013 20:15:30 +0100 Subject: [PATCH] Qual: Replace native code with jquery plugin treeview. --- htdocs/admin/menus/index.php | 6 +- htdocs/admin/menus/menu.js.php | 225 ------- htdocs/core/lib/treeview.lib.php | 97 ++- .../plugins/jquerytreeview/changelog.md | 36 ++ .../jquerytreeview/jquery.treeview.async.js | 108 ++++ .../jquerytreeview/jquery.treeview.css | 74 +++ .../jquerytreeview/jquery.treeview.edit.js | 37 ++ .../plugins/jquerytreeview/jquery.treeview.js | 251 ++++++++ .../jquery.treeview.sortable.js | 378 +++++++++++ .../jquery/plugins/jquerytreeview/readme.md | 47 ++ .../plugins/jquerytreeview/screenshot.png | Bin 0 -> 2387 bytes .../jquery/plugins/jstree/jquery.cookie.js | 50 -- .../jquery/plugins/jstree/jquery.hotkeys.js | 99 --- .../plugins/jstree/jquery.jstree.min.js | 596 ------------------ .../jquery/plugins/jstree/themes/apple/bg.jpg | Bin 331 -> 0 bytes .../jquery/plugins/jstree/themes/apple/d.png | Bin 7765 -> 0 bytes .../jstree/themes/apple/dot_for_ie.gif | Bin 43 -> 0 bytes .../plugins/jstree/themes/apple/style.css | 61 -- .../plugins/jstree/themes/apple/throbber.gif | Bin 1849 -> 0 bytes .../plugins/jstree/themes/classic/d.gif | Bin 3003 -> 0 bytes .../plugins/jstree/themes/classic/d.png | Bin 7535 -> 0 bytes .../jstree/themes/classic/dot_for_ie.gif | Bin 43 -> 0 bytes .../plugins/jstree/themes/classic/style.css | 77 --- .../jstree/themes/classic/throbber.gif | Bin 1849 -> 0 bytes .../plugins/jstree/themes/default-rtl/d.gif | Bin 2872 -> 0 bytes .../plugins/jstree/themes/default-rtl/d.png | Bin 7459 -> 0 bytes .../jstree/themes/default-rtl/dots.gif | Bin 132 -> 0 bytes .../jstree/themes/default-rtl/style.css | 84 --- .../jstree/themes/default-rtl/throbber.gif | Bin 1849 -> 0 bytes .../plugins/jstree/themes/default/d.gif | Bin 2944 -> 0 bytes .../plugins/jstree/themes/default/d.png | Bin 7635 -> 0 bytes .../plugins/jstree/themes/default/style.css | 74 --- .../jstree/themes/default/throbber.gif | Bin 1849 -> 0 bytes htdocs/theme/amarok/style.css.php | 2 +- htdocs/theme/auguria/style.css.php | 2 +- htdocs/theme/bureau2crea/style.css.php | 2 +- htdocs/theme/cameleo/style.css.php | 2 +- htdocs/theme/eldy/style.css.php | 111 +--- htdocs/user/hierarchy.php | 250 ++++++++ 39 files changed, 1230 insertions(+), 1439 deletions(-) delete mode 100644 htdocs/admin/menus/menu.js.php create mode 100644 htdocs/includes/jquery/plugins/jquerytreeview/changelog.md create mode 100644 htdocs/includes/jquery/plugins/jquerytreeview/jquery.treeview.async.js create mode 100644 htdocs/includes/jquery/plugins/jquerytreeview/jquery.treeview.css create mode 100644 htdocs/includes/jquery/plugins/jquerytreeview/jquery.treeview.edit.js create mode 100644 htdocs/includes/jquery/plugins/jquerytreeview/jquery.treeview.js create mode 100644 htdocs/includes/jquery/plugins/jquerytreeview/jquery.treeview.sortable.js create mode 100644 htdocs/includes/jquery/plugins/jquerytreeview/readme.md create mode 100644 htdocs/includes/jquery/plugins/jquerytreeview/screenshot.png delete mode 100644 htdocs/includes/jquery/plugins/jstree/jquery.cookie.js delete mode 100644 htdocs/includes/jquery/plugins/jstree/jquery.hotkeys.js delete mode 100644 htdocs/includes/jquery/plugins/jstree/jquery.jstree.min.js delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/apple/bg.jpg delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/apple/d.png delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/apple/dot_for_ie.gif delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/apple/style.css delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/apple/throbber.gif delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/classic/d.gif delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/classic/d.png delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/classic/dot_for_ie.gif delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/classic/style.css delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/classic/throbber.gif delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/default-rtl/d.gif delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/default-rtl/d.png delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/default-rtl/dots.gif delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/default-rtl/style.css delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/default-rtl/throbber.gif delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/default/d.gif delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/default/d.png delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/default/style.css delete mode 100644 htdocs/includes/jquery/plugins/jstree/themes/default/throbber.gif create mode 100644 htdocs/user/hierarchy.php diff --git a/htdocs/admin/menus/index.php b/htdocs/admin/menus/index.php index b31bf8b7afa..1fd5365e272 100644 --- a/htdocs/admin/menus/index.php +++ b/htdocs/admin/menus/index.php @@ -208,9 +208,11 @@ elseif ($action == 'confirm_delete' && $confirm == 'yes') $form=new Form($db); $formadmin=new FormAdmin($db); -$arrayofjs=array('/admin/menus/menu.js.php?lang='.$langs->defaultlang); -llxHeader('',$langs->trans("Menus"),'','',0,0,$arrayofjs); +$arrayofjs=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js?lang='.$langs->defaultlang); +$arrayofcss=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css?lang='.$langs->defaultlang); + +llxHeader('',$langs->trans("Menus"),'','',0,0,$arrayofjs,$arrayofcss); print_fiche_titre($langs->trans("Menus"),'','setup'); diff --git a/htdocs/admin/menus/menu.js.php b/htdocs/admin/menus/menu.js.php deleted file mode 100644 index f5790a81bdb..00000000000 --- a/htdocs/admin/menus/menu.js.php +++ /dev/null @@ -1,225 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/admin/menus/menu.js.php - * \brief File for js menu - */ - - -//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language -//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled to increase speed. Language code is found on url. -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); -//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); -if (! defined('NOLOGIN')) define('NOLOGIN',1); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1); -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); - -session_cache_limiter(FALSE); - -require_once '../../master.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; - -// Define css type -header('Content-type: application/javascript'); -// Important: Following code is to avoid page request by browser and PHP CPU at -// each Dolibarr page access. -if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate'); -else header('Cache-Control: no-cache'); - -// On the fly GZIP compression for all pages (if browser support it). Must set the bit 3 of constant to 1. -if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x04)) { ob_start("ob_gzhandler"); } - -if (GETPOST('lang')) $langs->setDefaultLang(GETPOST('lang')); // If language was forced on URL -if (GETPOST('theme')) $conf->theme=GETPOST('theme'); // If theme was forced on URL -$langs->load("main",0,0); -?> - - -// Tests pour navigateurs -var OPE = (window.opera) ? true : false; -var IE = (document.all && !OPE) ? true : false; -var MOZ = (!IE && !OPE) ? true : false; -// ----------------------------------------------------- -// Fonction d'initialisation de l'arbre -function arbre() { - // Choix de la balise contenant le texte. (strong par defaut). - balise = "STRONG"; - // Presentation de l'arbre au depart : deployee ('yes') ou fermee ('no') - extend = "no"; - // Textes du lien plier / deplier - plier_text = 'transnoentities("UndoExpandAll"); ?>'; - plier_title = 'Replier tous les noeuds de l\'arbre' - deplier_text = 'transnoentities("ExpandAll"); ?>'; - deplier_title = 'Deplier tous les noeuds de l\'arbre' - // Recuperation de tous les arbres de la page - uls = getElBy('ul','class','arbre'); - for (uli=0;uli < uls.length;uli++) - { - ul = uls[uli]; - linkSwitch(ul); - processULEL(ul); - plier(ul,'replier'); - } - -} - -// ------------------------------------------------------- -// Creation des liens plier /deplier tout -function linkSwitch(ul) { - var a=document.createElement('a'); - a.setAttribute('href','#'); - if (extend=='yes') { - a.appendChild(document.createTextNode(plier_text)); - a.setAttribute('title',plier_title); - } - else { - a.appendChild(document.createTextNode(deplier_text)); - a.setAttribute('title',deplier_title); - } - var parbre = document.createElement('p'); - parbre.setAttribute('class','arbre-switch'); - parbre.appendChild(a); - ul.parentNode.insertBefore(parbre,ul); - listenlink(ul); -} -// Gestion des Clics sur les liens plier / deplier tout -function listenlink(ul) { - var link = ul.previousSibling.childNodes[0]; - link.onclick = function() { - if (this.childNodes[0].nodeValue == plier_text) { - plier(ul,'replier'); - this.childNodes[0].nodeValue = deplier_text; - this.setAttribute('title',deplier_title); - } - else { - plier(ul,'deplier'); - this.childNodes[0].nodeValue = plier_text; - this.setAttribute('title',plier_title); - } - return false; - } -} -// Action Plier / deplier tout -function plier(ul,act) { - for (var i=0; i < ul.childNodes.length; i++) { - var li = ul.childNodes[i]; - if (li.nodeName == 'LI') { - for (var j=0; j < li.childNodes.length; j++) { - var child = li.childNodes[j]; - if (child.nodeName==balise) { - var strong = child; - } - if (child.nodeName=='UL') { - if (act=='replier') { - child.className='hide'; - strong.className='arbre-plier'; - } - else { - child.className=''; - strong.className='arbre-deplier'; - } - var sub = child; - plier(sub,act); - } - } - } - } -} -// --------------------------------------------------------- -// Analyse de l'arbre -function processULEL(ul) { - if (!ul.childNodes || ul.childNodes.length == 0) return; - // Iterate LIs - for (var itemi=0;itemi < ul.childNodes.length;itemi++) { - var item = ul.childNodes[itemi]; - if (item.nodeName == "LI") { - // Contenu des balises LI - var a; - var subul; - subul = ""; - for (var sitemi=0;sitemi < item.childNodes.length;sitemi++) { - // Uniquement pour moz-firefox - if (MOZ) {item.style.background = "";} - // Enfants des li : balise ou sous-ul - var sitem = item.childNodes[sitemi]; - switch (sitem.nodeName) { - case balise: - a = sitem; - break; - case "UL": - subul = sitem; - if (extend != "yes") {sitem.className = 'hide';} - processULEL(subul); - break; - } - } - if (subul) { - if (extend!="yes") { - a.className='arbre-plier'; - } - else { - a.className='arbre-deplier'; - subul.className=''; - - } - associateEL(a,subul); - } - } - } -} -// Swicth des noeuds -function associateEL(a,ul) { - a.onclick = function () { - this.className = (ul.className=='hide') ? 'arbre-deplier' : 'arbre-plier'; - ul.className = (ul.className=='hide') ? '' : 'hide'; - return false; - } -} -// ----------------------------------------------------- -// Nom : GetElBy(tag,attr,val) -// By : Rui Nibau -// Date : aout 2005 -// Func : Tableau des elements 'tag' dont l'attribut 'attr' a la valeur 'val'. -// ----------------------------------------------------- -function getElBy(tag,attr,val) { - var dbRes = []; - var dbEl = document.getElementsByTagName(tag); - for (e=0; e < dbEl.length; e++) { - if (attr == 'class') {if (dbEl[e].className==val) {dbRes.push(dbEl[e]);}} - else {if (dbEl[e].getAttribute(attr)==val) {dbRes.push(dbEl[e]);}} - } - return dbRes; -} -// ----------------------------------------------------- -// A l'affichage de la page, lancer la fonction arbre -window.onload = function() { - arbre(); -} - -function imgDel(id) -{ - var delId='del'+id; - - var imgDel = document.getElementById('del'+id); - if (imgDel != null) imgDel.style.display='block'; - - return true; -} diff --git a/htdocs/core/lib/treeview.lib.php b/htdocs/core/lib/treeview.lib.php index 1fc02206b26..7f8ed742fc6 100644 --- a/htdocs/core/lib/treeview.lib.php +++ b/htdocs/core/lib/treeview.lib.php @@ -1,6 +1,6 @@ - * Copyright (C) 2007-2008 Laurent Destailleur + * Copyright (C) 2007-2012 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,8 @@ */ +// ------------------------------- Used by category tree view ----------------- + /** * Return if a child id is in descendance of parentid * @@ -145,7 +147,7 @@ function tree_showpad(&$fulltree,$key,$silent=0) /** * Show an element with correct offset * - * @param array $tab Array of all elements + * @param array $tab Array of element * @param int $rang Level of offset * @return void */ @@ -153,62 +155,15 @@ function tree_showline($tab,$rang) { global $conf, $rangLast, $idLast, $menu_handler; - if ($conf->use_javascript_ajax) - { - if($rang == $rangLast) - { - print ''; - //print 'aa'; - } - elseif($rang > $rangLast) - { - - print '
    • '; - - } - elseif($rang < $rangLast) - { - print ''; - - for($i=$rang; $i < $rangLast; $i++) - { - print '
  • '; - echo "\n"; - } - - } - } - else - { - if($rang > $rangLast) - { - - print '
    • '; - - } - elseif($rang < $rangLast) - { - - for($i=$rang; $i < $rangLast; $i++) - { - print '
  • '; - echo "\n"; - } - - } - } - - print '
  • '; - // Content of line - print '  '.$tab['title'].''; - print ''; - print ''; - print ''; - print ''; - - print '
  • '; - echo "\n"; + print '
    '; + print '   '.$tab['title'].''; + print ''; + print ''.img_edit('default',0,'class="menuEdit" id="edit'.$tab['rowid'].'"').' '; + print ''.img_edit_add('default',0,'class="menuNew" id="new'.$tab['rowid'].'"').' '; + print ''.img_delete('default',0,'class="menuDel" id="del'.$tab['rowid'].'"').' '; + print ''.img_picto("Monter","1uparrow").''.img_picto("Descendre","1downarrow").''; + print '
    '; $rangLast = $rang; $idLast = $tab['rowid']; @@ -218,41 +173,63 @@ function tree_showline($tab,$rang) /** * Recursive function to output menu tree * - * @param array $tab Array of elements + * @param array $tab Array of all elements * @param int $pere Array with parent ids ('rowid'=>,'mainmenu'=>,'leftmenu'=>,'fk_mainmenu=>,'fk_leftmenu=>) * @param int $rang Level of element * @return void */ function tree_recur($tab,$pere,$rang) { - if (empty($pere['rowid'])) print ''; } diff --git a/htdocs/includes/jquery/plugins/jquerytreeview/changelog.md b/htdocs/includes/jquery/plugins/jquerytreeview/changelog.md new file mode 100644 index 00000000000..29c6e1975d2 --- /dev/null +++ b/htdocs/includes/jquery/plugins/jquerytreeview/changelog.md @@ -0,0 +1,36 @@ +1.4.1 +----- +* Fix for #2360 +* Added option cookieOptions: Passed through to $.cookie to set path, domain etc. +* Tested with jQuery 1.2.x and 1.4.3 +* Fixed combination of persist: "location" and prerendered: true + +1.4 +--- + +* Added changelog (this file) +* Fixed tree control to search only for anchors, allowing images or other elements inside the controls, while keeping the control usable with the keyboard +* Restructured folder layout: root contains plugin resources, lib contains script dependencies, demo contains demos and related files +* Added prerendered option: If set to true, assumes all hitarea divs and classes already rendered, speeding up initialization for big trees, but more obtrusive +* Added jquery.treeview.async.js for ajax-lazy-loading trees, see async.html demo +* Exposed $.fn.treeview.classes for custom classes if necessary +* Show treecontrol only when JavaScript is enabled +* Completely reworked themeing via CSS sprites, resulting in only two files per theme + * updated dotted, black, gray and red theme + * added famfamfam theme (no lines) +* Improved cookie persistence to allow multiple persisted trees per page via cookieId option +* Improved location persistence by making it case-insensitive +* Improved swapClass and replaceClass plugin implementations +* Added folder-closed.gif to filetree example + +1.3 +--- + +* Fixes for all outstanding bugs +* Added persistence features + * location based: click on a link in the treeview and reopen that link after the page loaded + * cookie based: save the state of the tree in a cookie on each click and load that on reload +* smoothed animations, fixing flickering in both IE and Opera +* Tested in Firefox 2, IE 6 & 7, Opera 9, Safari 3 +* Moved documentation to jQuery wiki +* Requires jQuery 1.2+ diff --git a/htdocs/includes/jquery/plugins/jquerytreeview/jquery.treeview.async.js b/htdocs/includes/jquery/plugins/jquerytreeview/jquery.treeview.async.js new file mode 100644 index 00000000000..36e368a0737 --- /dev/null +++ b/htdocs/includes/jquery/plugins/jquerytreeview/jquery.treeview.async.js @@ -0,0 +1,108 @@ +/* + * Async Treeview 0.1 - Lazy-loading extension for Treeview + * + * http://bassistance.de/jquery-plugins/jquery-plugin-treeview/ + * + * Copyright 2010 Jörn Zaefferer + * Released under the MIT license: + * http://www.opensource.org/licenses/mit-license.php + */ + +;(function($) { + +function load(settings, root, child, container) { + function createNode(parent) { + var current = $("
  • ").attr("id", this.id || "").html("" + this.text + "").appendTo(parent); + if (this.classes) { + current.children("span").addClass(this.classes); + } + if (this.expanded) { + current.addClass("open"); + } + if (this.hasChildren || this.children && this.children.length) { + var branch = $("