/branches/jsdoc_tk_gui/setup/workingDirectory/Webeo/gui/table/Table.js

http://jsdoc-toolkit.googlecode.com/ · JavaScript · 1300 lines · 791 code · 202 blank · 307 comment · 144 complexity · 0949952f137d7061e92d7ac645e2916d MD5 · raw file

  1. ek.require("gui.window.Wait");
  2. ek.require("ao.data.Json");
  3. ek.require("ao.ajax.Ajax");
  4. ek.require("gui.button.Button");
  5. ek.require("gui.event.KeyListener");
  6. ek.register("gui.table.Table");
  7. ek.requireCSS("css.gui.table.Table", "table.Table");
  8. /**
  9. *@require "wait.js"
  10. *@require "button.js"
  11. *@require "json.js"
  12. *@require "sarissa.js"
  13. *
  14. * Copyright 2006 Emuki-Group for Emukina.fr
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
  17. * file except in compliance with the License. You may obtain a copy of the License at
  18. *
  19. * http://www.apache.org/licenses/LICENSE-2.0
  20. *
  21. * Unless required by applicable law or agreed to in writing, software distributed under the
  22. * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  23. * either express or implied. See the License for the specific language governing permissions
  24. * and limitations under the License.
  25. **/
  26. /** Instance Manager */
  27. var manager = new Array();
  28. var ajax = new Array();
  29. /** AJAX Manager */
  30. //var xmlhttp;
  31. /** Determine si le navigateur est IE */
  32. var isIE = (navigator.userAgent.toLowerCase().indexOf("msie")>-1);
  33. //var isIE = (navigator.appName == "Microsoft Internet Explorer");
  34. /**
  35. * Gestion des combinaisons de touches du clavier
  36. * avec redirection de l'event vers le bon tableau
  37. * grace ? l'instance manager
  38. *//*
  39. document.onkeyup = function(e){
  40. var model = getCurrentTable();
  41. var isCtrlPressed;
  42. var key;
  43. if(isIE){
  44. isCtrlPressed = window.event.ctrlKey;
  45. key = window.event.keyCode;
  46. }else{
  47. isCtrlPressed = e.ctrlKey;
  48. key = e.which;
  49. }
  50. if(isCtrlPressed){
  51. switch (key){
  52. //Gauche
  53. case 37: model.pageCourante = (model.pageCourante-1 >1) ? model.pageCourante-1 : 1 ;
  54. break;
  55. //Haut
  56. case 38: model.pageCourante = 1;
  57. break;
  58. //Droite
  59. case 39: model.pageCourante = (model.pageCourante+1 < model.nbPages) ? model.pageCourante+1 : model.nbPages;
  60. break;
  61. //Bas
  62. case 40: model.pageCourante = model.nbPages;
  63. break;
  64. case 49: model.sortAgain(0,(model.sens == 0)?1:0); break;
  65. case 50: model.sortAgain(1,(model.sens == 0)?1:0); break;
  66. case 51: model.sortAgain(2,(model.sens == 0)?1:0); break;
  67. case 52: model.sortAgain(3,(model.sens == 0)?1:0); break;
  68. case 53: model.sortAgain(4,(model.sens == 0)?1:0); break;
  69. case 54: model.sortAgain(5,(model.sens == 0)?1:0); break;
  70. case 55: model.sortAgain(6,(model.sens == 0)?1:0); break;
  71. case 56: model.sortAgain(7,(model.sens == 0)?1:0); break;
  72. case 57: model.sortAgain(8,(model.sens == 0)?1:0); break;
  73. default:break;
  74. }
  75. model.rebuild();
  76. }
  77. }*/
  78. /**
  79. * @return la table qui poss?de le focus
  80. */
  81. function getCurrentTable(){
  82. for(i = 0 ; i < manager.length ; i++){
  83. if(manager[i].hasFocus){
  84. return manager[i];
  85. }
  86. }
  87. }
  88. /**
  89. * Définition de l'objet métier Column
  90. * @param name Nom de la colonne
  91. * @param type Type de la colonne (String, Number)
  92. *@param isSorted Booléen indiquant si on peut trié la colonne
  93. * @param filter Type du filtre ? utilisé '', input, select, number
  94. * @param width Largeur de la colonne en px ou %
  95. * @param compare Méthode de caomparaison ? utiliser
  96. */
  97. function column(name, type, isSorted, filter, width, compare){
  98. this.name = name;
  99. this.type = type;
  100. this.isSorted = isSorted;
  101. this.filter = filter;
  102. this.width = width;
  103. this.compare = compare;
  104. }
  105. /**
  106. * Définition de l'objet métier row
  107. * @param cols Tableau contenant les valeurs pour chaque colonne
  108. * @param children Tableau contenant les lignes enfants
  109. */
  110. function row(cols, children){
  111. //Array
  112. this.cols = cols;
  113. this.expanded = false;//Par defaut false
  114. this.children = children;
  115. }
  116. row.prototype.getValueAt = function(i){
  117. return (this.cols[i]!= undefined)?this.cols[i]:"";
  118. }
  119. row.prototype.getSortValue = function(){
  120. return this.getValueAt(this.sortIdx);
  121. }
  122. //-----------------------------------------------------------------------------
  123. //Gestion du TreeTableFilteredPagedSorted
  124. //-----------------------------------------------------------------------------
  125. /**
  126. * Construction d'un nouveau TreeTable dans le conteneur passé en param?tre
  127. * @param divId l'id du div contenant le tableau
  128. */
  129. function TreeTable(divId){
  130. this.divName = divId;
  131. this.divDOM = document.getElementById(this.divName);
  132. this.divDOM.model = this;
  133. this.divDOM.innerHTML = "<h4><b><i>Tableau en cours d'initialisation</i></b></h4>";
  134. this.info = 'info'+ this.divName;
  135. this.cbb;
  136. this.hasFocus = false;
  137. //Tableau source contenat toutes les lignes
  138. this.rows = new Array();
  139. //Tableau filtré ne contenant que les lignes corespondant aux crit?res
  140. this.filteredContent = new Array();
  141. //Tableau stockant les filtres en cours d'utilisation
  142. this.filtreCourant = new Array();
  143. //-----------------------------------------------------------------------------
  144. //Definition des constantes du TreeTableFilteredPagedSorted
  145. //-----------------------------------------------------------------------------
  146. this.size = 0 ;
  147. this.MAX_LINES = 10;
  148. this.pageCourante= 1;
  149. this.nbPages ;
  150. this.sens = 0;
  151. this.sortCol = 0;
  152. // DEBUT DU PARAMETRAGE
  153. this.waitActive = true;
  154. this.alt_bgcolor1 = "white";
  155. this.alt_bgcolor2 = "grey";
  156. this.repImg = "img/table/"
  157. this.displayDisabledIcon = true;
  158. //Images du tri
  159. this.asc_on = "asc.gif";
  160. this.asc_press = "asc_p.gif";
  161. this.asc_over = "asc_h.gif";
  162. this.desc_on = "desc.gif";
  163. this.desc_press = "desc_p.gif";
  164. this.desc_over = "desc_h.gif";
  165. //Image de la pagination
  166. this.first = "first.gif";
  167. this.first_o= "first.gif";
  168. this.first_p= "first.gif";
  169. this.first_d= "first_d.gif";
  170. this.prev = "prevt.gif";
  171. this.prev_o = "prev.gif";
  172. this.prev_p = "prev.gif";
  173. this.prev_d = "prev_d.gif";
  174. this.next = "next.gif";
  175. this.next_o = "next.gif";
  176. this.next_p = "next.gif";
  177. this.next_d = "next_d.gif";
  178. this.last = "last.gif";
  179. this.last_o = "last.gif";
  180. this.last_p = "last.gif";
  181. this.last_d = "last_d.gif";
  182. //Image de l'arbre
  183. this.tree_closed= "plus.gif";
  184. this.tree_open = "plus.gif";
  185. this.one_leaf = "minus.gif";
  186. this.last_leaf = "minus.gif";
  187. // FIN DU PARAMETRAGE
  188. //Manage hte keyboard shortcuts
  189. getKeyListener().add(37, "getCurrentTable().pageCourante = (getCurrentTable().pageCourante-1 >1) ? getCurrentTable().pageCourante-1 : 1 ;getCurrentTable().rebuild();", false, true, false);//Ctrl + Gauche
  190. getKeyListener().add(38, "getCurrentTable().pageCourante = 1; getCurrentTable().rebuild();", false, true, false);//Ctrl + Haut
  191. getKeyListener().add(39, "getCurrentTable().pageCourante = (getCurrentTable().pageCourante+1 < getCurrentTable().nbPages) ? getCurrentTable().pageCourante+1 : getCurrentTable().nbPages;getCurrentTable().rebuild();", false, true, false);//Ctrl+ Droite
  192. getKeyListener().add(40, "getCurrentTable().pageCourante = getCurrentTable().nbPages;getCurrentTable().rebuild();", false, true, false);//Ctrl + Bas
  193. getKeyListener().add(49, "getCurrentTable().sortAgain(0,(getCurrentTable().sens == 0)?1:0); getCurrentTable().rebuild();", false, true, false);
  194. getKeyListener().add(50, "getCurrentTable().sortAgain(1,(getCurrentTable().sens == 0)?1:0); getCurrentTable().rebuild();", false, true, false);
  195. getKeyListener().add(51, "getCurrentTable().sortAgain(2,(getCurrentTable().sens == 0)?1:0); getCurrentTable().rebuild();", false, true, false);
  196. getKeyListener().add(52, "getCurrentTable().sortAgain(3,(getCurrentTable().sens == 0)?1:0); getCurrentTable().rebuild();", false, true, false);
  197. getKeyListener().add(53, "getCurrentTable().sortAgain(4,(getCurrentTable().sens == 0)?1:0); getCurrentTable().rebuild();", false, true, false);
  198. getKeyListener().add(54, "getCurrentTable().sortAgain(5,(getCurrentTable().sens == 0)?1:0); getCurrentTable().rebuild();", false, true, false);
  199. getKeyListener().add(55, "getCurrentTable().sortAgain(6,(getCurrentTable().sens == 0)?1:0); getCurrentTable().rebuild();", false, true, false);
  200. getKeyListener().add(56, "getCurrentTable().sortAgain(7,(getCurrentTable().sens == 0)?1:0); getCurrentTable().rebuild();", false, true, false);
  201. getKeyListener().add(57, "getCurrentTable().sortAgain(8,(getCurrentTable().sens == 0)?1:0); getCurrentTable().rebuild();", false, true, false);
  202. this.divDOM.onmouseover = function(){
  203. this.model.hasFocus = true;
  204. for(var i = 0 ; i < manager.length; i++){
  205. if(manager[i]==this.model){
  206. manager[i].hasFocus = true;
  207. manager[i].divDOM.className = 'container hasFocus';
  208. }else{
  209. manager[i].hasFocus = false;
  210. manager[i].divDOM.className = 'container';
  211. }
  212. }
  213. };
  214. manager[manager.length] = this;
  215. ajax[this.divName] = new XMLHttpRequest();
  216. ajax[this.divName].model = this;
  217. ajax[this.divName].onreadystatechange= this.readyToLoad;
  218. }
  219. TreeTable.prototype.drawWaitInitWindow = function(){
  220. return '<h4><i>Tableau en cours d\'initialisation</i></h4>';
  221. }
  222. TreeTable.prototype.initWaitDiv = function(){
  223. this.wait = new Wait(this.divName+'_TABLE', 'Tableau en cours de rafraichissement', 'wait',0 ,200);
  224. }
  225. TreeTable.prototype.build = function(){
  226. this.getLogger().trace("build");
  227. //Déclaration HTML du tableau
  228. this.domTable = document.createElement("table");
  229. this.domTable.setAttribute("id", this.divName+"_TABLE");
  230. this.domTable.setAttribute("class", "treetable");
  231. this.drawHeaders();
  232. this.drawBody();
  233. this.drawFooters();
  234. this.divDOM.appendChild(this.domTable);
  235. //Init du wait
  236. this.initWaitDiv();
  237. //On init les gestionnaires d'evennements
  238. this.initSortButtons();//on init les boutons de tri
  239. this.refreshNavigateButtons(); // on init les boutons de navigations
  240. this.refreshDisplayBy(this.MAX_LINES);
  241. //TODO new Tooltip (this.gotoPage, true, 'Entrez un numéro de page');
  242. }
  243. TreeTable.prototype.rebuild = function(){
  244. this.getLogger().trace("rebuild");
  245. if(this.waitActive)
  246. this.wait.mayShow();
  247. var deb = new Date();
  248. //On reinitialise le div contenant le tableau
  249. var tbody = this.divDOM.getElementsByTagName('tbody')[0];
  250. tbody.innerHTML = '';
  251. this.drawRows();
  252. //On reinit les gestionnaires d'evennements
  253. this.refreshSortButtons();
  254. this.refreshNavigateButtons();
  255. this.refreshListPages();
  256. this.refreshDisplayBy(this.MAX_LINES);
  257. //alert(new Date() - deb);
  258. if(this.waitActive)
  259. this.wait.mayHide();
  260. }
  261. /**
  262. * Crée l'ent?te du tableau permettant le tri et la ligne de filtrage
  263. * @param tab la liste des colonnes
  264. */
  265. TreeTable.prototype.drawHeaders = function(){
  266. var domTHead = this.domTable.createTHead();
  267. var titleRow = document.createElement("tr");
  268. for(i = 0 ; i < this.columns.length ; i++){
  269. var titleCell = document.createElement("td");
  270. titleCell.setAttribute("class", "footer");
  271. if(this.columns[i].isSorted)
  272. titleCell.appendChild(this.drawOneSortButton("asc", i));
  273. titleCell.appendChild(document.createTextNode(this.columns[i].name)) ;
  274. if(this.columns[i].isSorted)
  275. titleCell.appendChild(this.drawOneSortButton("desc", i));
  276. titleRow.appendChild(titleCell) ;
  277. }
  278. domTHead.appendChild(titleRow);
  279. var filterRow = document.createElement("tr");
  280. for(i = 0 ; i < this.columns.length ; i++){
  281. var filterCell = document.createElement("td");
  282. filterCell.setAttribute("class", "footer");
  283. if(this.columns[i].filter != '' ){
  284. if(this.filtreCourant[i]== undefined)
  285. this.filtreCourant[i] = "";
  286. var filter = document.createElement("input");
  287. filter.addAttributes([["name","Filter-"+this.columns[i].name],["id","Filter-"+this.columns[i].name],["type","text"],["length","20"],["value",this.filtreCourant[i]]]);
  288. filter.model = this;
  289. filter.colNumber = i;
  290. filter.onkeypress = this.filterValidate;
  291. filter.onblur = this.filterAgain;
  292. filterCell.appendChild(filter);
  293. }else{
  294. filterCell.appendChild(document.createTextNode("")) ;
  295. }
  296. filterRow.appendChild(filterCell) ;
  297. }
  298. domTHead.appendChild(filterRow);
  299. }
  300. TreeTable.prototype.drawFooters = function(){
  301. var domTFoot = this.domTable.createTFoot();
  302. var infoRow = document.createElement("tr");
  303. var bigCell = infoRow.insertCell(0);
  304. bigCell.setAttribute("colspan", this.columns.length);
  305. bigCell.innerHTML=/*appendChild(document.createTextNode(*/this.rows.length+' lignes <div id="'+this.info+'"></div>'/*))*/;//TODO
  306. domTFoot.appendChild(infoRow);
  307. var footRow = document.createElement("tr");
  308. var firstCell = footRow.insertCell(0);
  309. firstCell.setAttribute("class", "footer");
  310. firstCell.setAttribute("colspan", this.columns.length-3);
  311. firstCell.appendChild(this.drawListPages());
  312. var secondCell = footRow.insertCell(1);
  313. secondCell.setAttribute("class", "footer");
  314. secondCell.appendChild(this.drawNavigateButtons());
  315. var thirdCell = footRow.insertCell(2);
  316. thirdCell.setAttribute("class", "footer");
  317. thirdCell.setAttribute("colspan", this.columns.length-3);
  318. thirdCell.appendChild(this.getAfficheParComboBox());
  319. domTFoot.appendChild(footRow);
  320. }
  321. TreeTable.prototype.drawOneSortButton = function(sens, col){
  322. var b;
  323. if(sens == "desc" ){
  324. b = new PictureButton('desc_'+i+'_'+this.divName, this.repImg+'desc', 'gif', "Ctrl + "+(col+1), true, this, this.sortByButton);
  325. }else{
  326. b = new PictureButton('asc_'+i+'_'+this.divName, this.repImg+'asc', 'gif', "Ctrl + "+(col+1), true, this, this.sortByButton);
  327. }
  328. b.domBT.setAttribute("class", "sortButton");
  329. return b.getDom();
  330. //TODO TOOLTIP <div class="tooltip" style="display:none;" id="TT_'+sens+'_'+col+'_'+this.divName+'"></div>';
  331. }
  332. TreeTable.prototype.initSortButtons = function(){
  333. this.descSortButtons = new Array();
  334. this.ascSortButtons = new Array();
  335. for(var i = 0 ; i < this.columns.length ; i++){
  336. if(this.columns[i].isSorted){
  337. this.descSortButtons[i] = document.getElementById('desc_'+i+'_'+this.divName).buttonModel;
  338. this.ascSortButtons[i] = document.getElementById('asc_'+i+'_'+this.divName).buttonModel;
  339. }
  340. }
  341. this.refreshSortButtons(); //TODO TO IMPROVE
  342. }
  343. TreeTable.prototype.refreshSortButtons = function(){
  344. for(var i = 0 ; i < this.descSortButtons.length ; i++){
  345. if(this.sens==0){
  346. if(this.sortCol != i)
  347. this.descSortButtons[i].unselect();
  348. else
  349. this.descSortButtons[i].select();
  350. this.ascSortButtons[i].unselect();
  351. }
  352. if(this.sens==1){
  353. if(this.sortCol != i)
  354. this.ascSortButtons[i].unselect();
  355. else
  356. this.ascSortButtons[i].select();
  357. this.descSortButtons[i].unselect();
  358. }
  359. }
  360. }
  361. TreeTable.prototype.drawBody = function(){
  362. this.getLogger().trace("drawBody");
  363. this.domTableBody = document.createElement("tBody");
  364. this.drawRows();
  365. this.domTable.appendChild(this.domTableBody);
  366. }
  367. /**
  368. *
  369. */
  370. TreeTable.prototype.drawRows = function(){
  371. res = "";
  372. //Flush le tableau filtré
  373. this.filteredContent = new Array();
  374. //Boucle filtrant le tableau
  375. for(j = 0; j< this.rows.length ; j++){
  376. if(this.isFiltreOK(this.rows[j])){
  377. this.filteredContent[this.filteredContent.length] = this.rows[j];
  378. }
  379. }
  380. this.size = this.filteredContent.length;
  381. if(this.pageCourante > 1 && this.pageCourante > Math.ceil( this.size / this.MAX_LINES )){
  382. this.pageCourante = Math.ceil( this.size / this.MAX_LINES );
  383. }
  384. start = (this.pageCourante*this.MAX_LINES) - this.MAX_LINES;
  385. //On ecrit les lignes du tableau
  386. writed = 0;
  387. for(k= start; k < this.size; k++){
  388. //Gestion de l'alternate background
  389. bgcolor = (writed%2 == 1)? this.alt_bgcolor2 : this.alt_bgcolor1 ;
  390. if( writed < this.MAX_LINES){
  391. //Write the first level row
  392. res += this.drawARow(this.filteredContent[k], k, bgcolor);
  393. //Write the first childs rows
  394. res += this.drawChildRows(this.filteredContent[k], k, bgcolor, this.filteredContent[k].expanded);
  395. writed++;
  396. }
  397. }
  398. if(writed==0){ //TODO columns length
  399. res += '<tr><td colspan="4">Aucunes lignes pour cette combinaison de filtre</td></tr>';
  400. }
  401. return res;
  402. }
  403. TreeTable.prototype.drawARow = function(row, idx, bgcolor){
  404. var domRow = document.createElement("tr");
  405. domRow.setAttribute("id", this.divName+'_row_'+idx);
  406. domRow.setAttribute("class", bgcolor);
  407. domRow.setAttribute("style", "cursor:pointer;");
  408. //domRow.onclick = this.toggleRow(domRow);
  409. domRow.onmouseover = this.toggleOver ;//Color(domRow, true);
  410. domRow.onmouseout = this.toggleOut ;//Color(domRow, false);
  411. for(var i = 0 ; i < this.columns.length ; i++){
  412. this.drawACell(domRow, row.getValueAt(i));
  413. }
  414. this.domTableBody.appendChild(domRow);
  415. }
  416. /**
  417. * Recursive method
  418. */
  419. TreeTable.prototype.drawChildRows = function(row, idRoot, bgcolor, rootExpanded){
  420. var res = '';
  421. for(r=0 ; r < row.children.length ; r++ ){
  422. //res += this.drawAChildRow(row.children[r],this.divName+'_row_'+idRoot, r, bgcolor, row.expanded && rootExpanded);
  423. //TODOres += this.drawChildRows(row.children[r], idRoot+'_'+r, bgcolor, (row.children[r].expanded && rootExpanded) );
  424. }
  425. return res;
  426. }
  427. TreeTable.prototype.drawAChildRow = function(row, idxRoot, idx, bgcolor, visible){
  428. var display = (visible) ? '' : 'display:none;' ;
  429. var res = '<tr id='+idxRoot+'_'+idx+' class="'+bgcolor+'" style="cursor:pointer;'+display+'" ';
  430. res += 'onClick="document.getElementById(\''+this.divName+'\').model.toggleRow(this.id)" onMouseOver="document.getElementById(\''+this.divName+'\').model.toggleColor(this.id, true)" onMouseOut="document.getElementById(\''+this.divName+'\').model.toggleColor(this.id, false)">\n';
  431. for(var i = 0 ; i < this.columns.length ; i++){
  432. res += this.drawACell(row.getValueAt(i));
  433. }
  434. res +="\n</tr>\n";
  435. return res;
  436. }
  437. TreeTable.prototype.drawACell = function(domRow, value){
  438. //TODO <td><img src="'+this.repImg+this.tree_closed+'" ><a>'+this.filteredContent[k].nom+'</a></td>
  439. //return "<td>"+ value +"</td>";
  440. var domCell = document.createElement("td");
  441. domCell.appendChild(document.createTextNode(value));
  442. if(domRow instanceof HTMLTableRowElement && domRow.appendChild)
  443. domRow.appendChild(domCell);
  444. }
  445. TreeTable.prototype.updateMessage = function(message){
  446. document.getElementById(this.info).innerHTML = message;
  447. }
  448. //-----------------------------------------------------------------------------
  449. //Gestion de l'affichage du TreeTable
  450. //-----------------------------------------------------------------------------
  451. /**
  452. *
  453. *@param rowId Id long avec prefixe ex ==> table1_row_0_0_1_0
  454. */
  455. TreeTable.prototype.getRowFromRowId = function(rowId){
  456. //rowId == this.divName_row_0_0_0
  457. var firstId = rowId.substring(5+this.divName.length); // == 0_0_0
  458. firstId = firstId.substring(0, (firstId.indexOf('_')>0) ? firstId.indexOf('_') : firstId.length );
  459. //firstId == 0
  460. var childId = rowId.substr(5+this.divName.length+firstId.length+1 );
  461. //childId == 0_0
  462. var firstRow = this.filteredContent[parseInt(firstId)];
  463. return this.getRowFromId(firstRow, childId);
  464. }
  465. /**
  466. *@param row Ligne courante
  467. *@param childId Id court sans prefixe ex ==> 0_1_0
  468. */
  469. TreeTable.prototype.getRowFromId = function(row, childId){
  470. if(childId.length == 0){
  471. return row;
  472. }
  473. //childId == 0_0
  474. var firstChildId = childId.substring(0, (childId.indexOf('_')>0)?childId.indexOf('_'):childId.length );
  475. var nextChildId = childId.substr(firstChildId.length+1);
  476. //firstChildId == 0 && nextChildId == 0
  477. if(row.children.length>0){
  478. var childRow = row.children[parseInt(firstChildId)];
  479. return this.getRowFromId(childRow, nextChildId);
  480. }
  481. return;
  482. }
  483. TreeTable.prototype.toggleRow = function(rowToToggle){
  484. //alert(rowId);
  485. //var rowToToggle = this.getRowFromRowId(rowId);
  486. for(i = 0 ; i<rowToToggle.children.length ;i++){
  487. if(document.getElementById(rowId+'_'+i).style.display == ''){
  488. document.getElementById(rowId+'_'+i).style.display = 'none';
  489. rowToToggle.expanded = false;
  490. }else{
  491. document.getElementById(rowId+'_'+i).style.display = '';
  492. rowToToggle.expanded = true;
  493. }
  494. this.revealChildren(rowToToggle.children[i], rowId+'_'+i, rowToToggle.expanded);
  495. }
  496. }
  497. TreeTable.prototype.revealChildren = function(row, rowId, visible){
  498. for(var i = 0 ; i < row.children.length; i++ ){
  499. if(visible && row.expanded){
  500. document.getElementById(rowId+'_'+i).style.display = '';
  501. }else{
  502. document.getElementById(rowId+'_'+i).style.display = 'none';
  503. }
  504. this.revealChildren(row.children[i], rowId+'_'+i, visible)
  505. }
  506. }
  507. TreeTable.prototype.toggleAllVisibleRow = function(expand){
  508. //TODO Optimize only visible
  509. for(i = 0 ; i<this.filteredContent.length ;i++){
  510. for(j = 0 ; j<this.filteredContent[i].children.length ;j++){
  511. if(expand){
  512. document.getElementById(i+'_'+j).style.display = '';
  513. this.filteredContent[i].expanded = true;
  514. }else{
  515. document.getElementById(i+'_'+j).style.display = 'none';
  516. this.filteredContent[i].expanded = false;
  517. }
  518. }
  519. }
  520. }
  521. TreeTable.prototype.toggleAllRow = function(expand){
  522. row.prototype.expanded = expand;
  523. this.rebuild();
  524. }
  525. TreeTable.prototype.toggleColor = function(tr, mouseOver){
  526. if(mouseOver){
  527. tr.oldClassName = tr.className;
  528. tr.className = 'highlighted';
  529. }else{
  530. tr.className = tr.oldClassName;
  531. }
  532. }
  533. TreeTable.prototype.toggleOver = function(){
  534. this.oldClassName = this.className;
  535. this.className = 'highlighted';
  536. }
  537. TreeTable.prototype.toggleOut = function(){
  538. this.className = this.oldClassName;
  539. }
  540. //-----------------------------------------------------------------------------
  541. //Gestion du Tri
  542. //-----------------------------------------------------------------------------
  543. /**
  544. *
  545. * @param col numéo de la colonne ? trier
  546. * @param sens type du tri asc=0 desc=1
  547. */
  548. TreeTable.prototype.sortByButton = function(){
  549. var infos = this.id.split("_");
  550. var sens = (infos[0]== "asc") ? 1 : 0;
  551. var col = infos[1];
  552. this.mainModel.sortAgain(col, sens);
  553. }
  554. /**
  555. *
  556. * @param col numéo de la colonne ? trier
  557. * @param sens type du tri asc=0 desc=1
  558. */
  559. TreeTable.prototype.sortAgain = function(col , sens){
  560. if(col>=this.columns.length)
  561. return;
  562. begin = new Date();
  563. this.sens = sens;
  564. this.sortCol = col;
  565. row.prototype.sortIdx = col;
  566. this.rows.sort(this.columns[col].compare);
  567. //On inverse le tableau si le tri est de type desc
  568. if(this.sens == 1){
  569. this.rows.reverse()
  570. }
  571. this.rebuild();
  572. this.updateMessage('Tableau trié en '+ (new Date()- begin)/1000 +' s' );
  573. }
  574. //-----------------------------------------------------------------------------
  575. //Gestion du Filtrage
  576. //-----------------------------------------------------------------------------
  577. TreeTable.prototype.filterValidate = function(e){
  578. if(navigator.appName == "Microsoft Internet Explorer"){
  579. if(window.event.keyCode == 13){
  580. this.model.filtreCourant[this.colNumber] = this.value;
  581. this.model.rebuild();
  582. //On remet le focus sur le filtre
  583. document.getElementById(this.id).focus();
  584. }else if(window.event.keyCode == 0) {
  585. this.model.filtreCourant[this.colNumber] = this.value;
  586. this.model.rebuild();
  587. //On met le focus sur le filtre suivant
  588. if(e.shiftKey){
  589. tabCol = (this.colNumber-1 < 0) ? this.model.columns.length-1: this.colNumber-1;
  590. }else{
  591. tabCol = (this.colNumber+2 > this.model.columns.length) ? 0: this.colNumber+1;
  592. }
  593. document.getElementById('Filter-'+this.model.columns[tabCol].name).focus();
  594. }
  595. }else{
  596. if(e.which == 13){
  597. this.model.filtreCourant[this.colNumber] = this.value;
  598. this.model.rebuild();
  599. //On remet le focus sur le filtre
  600. document.getElementById(this.id).focus();
  601. }else if(e.which == 0) {
  602. this.model.filtreCourant[this.colNumber] = this.value;
  603. this.model.rebuild();
  604. //On met le focus sur le filtre suivant
  605. if(e.shiftKey){
  606. tabCol = (this.colNumber-1 < 0) ? this.model.columns.length-1: this.colNumber-1;
  607. }else{
  608. tabCol = (this.colNumber+2 > this.model.columns.length) ? 0: this.colNumber+1;
  609. }
  610. document.getElementById('Filter-'+this.model.columns[tabCol].name).focus();
  611. }
  612. }
  613. }
  614. /**
  615. *
  616. */
  617. TreeTable.prototype.filterAgain = function(e){
  618. begin = new Date();
  619. //On stocke le filtre courant
  620. if(this.value != this.model.filtreCourant[this.colNumber]){
  621. this.model.filtreCourant[this.colNumber] = this.value;
  622. //On reconstruit le tableau
  623. this.model.rebuild();
  624. this.model.updateMessage('Tableau filtré en '+ (new Date()- begin)/1000 +' s' );
  625. //On remet le focus sur le filtre
  626. document.getElementById(this.id).focus();
  627. }
  628. }
  629. /**
  630. *
  631. */
  632. TreeTable.prototype.isFiltreOK = function(row){
  633. //Pour chaque colonne
  634. for(var i = 0 ; i < this.columns.length ; i++ ){
  635. if(this.filtreCourant[i] == undefined){
  636. this.filtreCourant[i] = "";
  637. }
  638. if(this.columns[i].type == "String"){
  639. if( !( this.filtreCourant[i] == ""
  640. || row.cols[i].toLowerCase().indexOf(this.filtreCourant[i].toLowerCase())>-1 ) ){
  641. return false;
  642. }
  643. }else if(this.columns[i].type == "Number"){
  644. filtreEgal = (this.filtreCourant[i].substring(0,1) == "=" )? "="+this.filtreCourant[i] : this.filtreCourant[i] ;
  645. if( this.isSupInfEgalOK(this.filtreCourant[i])
  646. || this.startWihtSupInfEgal(filtreEgal) && eval(row.cols[i]+filtreEgal) ){
  647. //return true;
  648. }else{
  649. return false;
  650. }
  651. }
  652. }
  653. return true;
  654. }
  655. /**
  656. * Gestion des tris spécifique au nombre
  657. * @return true si le filtre commencer par '=' , '>' ou'<'
  658. */
  659. TreeTable.prototype.startWihtSupInfEgal = function(filter){
  660. if(filter.substring(0,1) == "="
  661. || filter.substring(0,1) == "<"
  662. || filter.substring(0,1) == ">")
  663. return true;
  664. return false;
  665. }
  666. /**
  667. *
  668. */
  669. TreeTable.prototype.isSupInfEgalOK = function(filter){
  670. if(filter=="" || filter==">" || filter=="<" || filter==">=" || filter=="<=" || filter=="=")
  671. return true;
  672. else
  673. return false;
  674. }
  675. //-----------------------------------------------------------------------------
  676. //Gestion de la pagination
  677. //-----------------------------------------------------------------------------
  678. /**
  679. *
  680. */
  681. TreeTable.prototype.pagineAgain= function(e){
  682. //Si le bouton est grisé on ne fait rien
  683. if(this.src.indexOf("_d") > 0 )
  684. return;
  685. begin = new Date();
  686. switch(this.id){
  687. case "first_"+ this.mainModel.divName : this.mainModel.pageCourante = 1; break;
  688. case "prev_"+ this.mainModel.divName : this.mainModel.pageCourante = this.mainModel.pageCourante-1; break;
  689. case "next_"+ this.mainModel.divName : this.mainModel.pageCourante = this.mainModel.pageCourante+1; break;
  690. case "last_"+ this.mainModel.divName : this.mainModel.pageCourante = this.mainModel.nbPages; break;
  691. case "goto_"+ this.mainModel.divName : this.mainModel.pageCourante = (parseInt(this.value)>0
  692. && parseInt(this.value) <= this.mainModel.nbPages)?parseInt(this.value):1; break;
  693. }
  694. //On reconstruit le tableau
  695. this.mainModel.rebuild();
  696. if(this.id == "goto_"+ this.mainModel.divName){
  697. this.select();
  698. }
  699. this.mainModel.updateMessage('Page affiché en '+ (new Date()- begin)/1000 +' s' );
  700. }
  701. /**
  702. * Retourne le text permettant de chosir une page
  703. */
  704. TreeTable.prototype.drawListPages = function(){
  705. this.listPages = document.createElement("div");
  706. //On recupere le plus petit entier supérieur au rapport nombre/maxParPage
  707. this.nbPages = Math.ceil( this.size / this.MAX_LINES );
  708. this.listPages.setAttribute("id","pages_"+this.divName);
  709. this.listPages.setAttribute("style","text-align:left;display:inline");
  710. this.listPages.appendChild(document.createTextNode("Page Courante "+this.pageCourante+ "/"+this.nbPages));
  711. return this.listPages;
  712. }
  713. /**
  714. *
  715. */
  716. TreeTable.prototype.refreshListPages = function(){
  717. //On recupere le plus petit entier supérieur au rapport nombre/maxParPage
  718. this.nbPages = Math.ceil( this.size / this.MAX_LINES );
  719. this.listPages.innerHTML = 'Page Courante '+this.pageCourante+ '/'+this.nbPages ;
  720. }
  721. TreeTable.prototype.drawNavigateButtons = function(){
  722. var res = document.createElement("div");
  723. res.setAttribute("id", "navigateButtons");
  724. res.appendChild(this.drawOneNavigateButton("first"));
  725. res.appendChild(this.drawOneNavigateButton("prev"));
  726. this.gotoPage = document.createElement("input");
  727. this.gotoPage.addAttributes([["type","text"],["size",1],["maxlength",4],["class","gotoInput"],["id","goto_"+ this.divName],["value",this.pageCourante]]);
  728. //vis = (this.nbPages>1)? '': 'disabled';
  729. //res += '" value="'+this.pageCourante+'" '+vis+'>';
  730. this.gotoPage.mainModel = this;
  731. this.gotoPage.onchange = this.pagineAgain;
  732. this.gotoPage.onkeypress = function(){
  733. if(isIE){
  734. if(window.event.keyCode == 13)
  735. this.blur();
  736. }
  737. }
  738. this.gotoPage.onfocus = function(){
  739. this.select();
  740. }
  741. res.appendChild(this.gotoPage);
  742. res.appendChild(this.drawOneNavigateButton("next"));
  743. res.appendChild(this.drawOneNavigateButton("last"));
  744. return res;
  745. }
  746. TreeTable.prototype.drawOneNavigateButton = function(name){
  747. var b;
  748. switch(name){
  749. case "first":
  750. this.first = new PictureButton('first_'+ this.divName, this.repImg+'first', 'gif', "Ctrl + Haut", false, this, this.pagineAgain);
  751. b = this.first;
  752. break;
  753. case "prev":
  754. this.prev = new PictureButton('prev_'+ this.divName, this.repImg+'prev', 'gif', "Ctrl + Gauche", false, this, this.pagineAgain );
  755. b = this.prev;
  756. break;
  757. case "next":
  758. this.next = new PictureButton('next_'+ this.divName, this.repImg+'next', 'gif', "Ctrl + Droite", false, this, this.pagineAgain);
  759. b = this.next;
  760. break;
  761. case "last":
  762. this.last = new PictureButton('last_'+ this.divName, this.repImg+'last', 'gif', "Ctrl + Bas", false, this, this.pagineAgain);
  763. b = this.last;
  764. break;
  765. }
  766. b.domBT.setAttribute("class", "navButton");
  767. return b.domBT;
  768. }
  769. /**
  770. *
  771. */
  772. TreeTable.prototype.refreshNavigateButtons = function (){
  773. this.first.changeVisibility(this.pageCourante>2, this.displayDisabledIcon) ;
  774. this.prev.changeVisibility(this.pageCourante>1 , this.displayDisabledIcon) ;
  775. this.next.changeVisibility(this.pageCourante<this.nbPages, this.displayDisabledIcon) ;
  776. this.last.changeVisibility(this.pageCourante<this.nbPages-1, this.displayDisabledIcon) ;
  777. this.gotoPage.value = this.pageCourante;
  778. this.gotoPage.disabled = !(this.nbPages>1);
  779. }
  780. TreeTable.prototype.getAfficheParComboBox = function(){
  781. var content = document.createElement("div");
  782. content.appendChild(document.createTextNode("Affiché par "));
  783. this.cbb = document.createElement("select");
  784. this.cbb.setAttribute("id", 'displayBy' + this.divName);
  785. this.cbb.addOption([["value",2]],2);
  786. this.cbb.addOption([["value",5]],5);
  787. this.cbb.addOption([["value",10]],10);
  788. this.cbb.addOption([["value",25]],25);
  789. this.cbb.addOption([["value",50]],50);
  790. this.cbb.addOption([["value",100]],100);
  791. this.cbb.addOption([["value",200]],200);
  792. this.cbb.addOption([["value",500]],500);
  793. this.cbb.addOption([["value",1000]],1000);
  794. this.cbb.model = this;
  795. this.cbb.onchange = this.displayBy;
  796. content.appendChild(this.cbb);
  797. return content;
  798. }
  799. TreeTable.prototype.displayBy = function (){
  800. //var cbb = document.getElementById('displayBy'+ cbb.model.divName);
  801. //this == this.cbb
  802. this.model.MAX_LINES = this.options[this.selectedIndex].value;
  803. this.model.rebuild();
  804. }
  805. /**
  806. * This method will select the parameterized value in the parameterized combobox
  807. */
  808. TreeTable.prototype.refreshDisplayBy = function (value){
  809. for(i = 0 ;i < this.cbb.options.length ; i++){
  810. if(this.cbb.options[i].value == value ){
  811. this.cbb.selectedIndex =i;
  812. break;
  813. }
  814. }
  815. }
  816. /**
  817. *
  818. */
  819. TreeTable.prototype.getSortMethodByName = function(name){
  820. switch(name){
  821. case 'loweredString': return this.compareLoweredString;
  822. case 'caseSensitiveString': return this.compareCaseSensitiveString;
  823. case 'number': ;
  824. default: return this.compareNumber ;
  825. }
  826. }
  827. /**
  828. *
  829. */
  830. TreeTable.prototype.compareLoweredString = function(a,b){
  831. if(typeof(a.getSortValue()) == "string" && typeof(b.getSortValue()) == "string" ){
  832. if(a.getSortValue().toLowerCase() < b.getSortValue().toLowerCase()) return -1;
  833. if(a.getSortValue().toLowerCase() > b.getSortValue().toLowerCase()) return 1;
  834. return 0;
  835. }
  836. }
  837. /**
  838. *
  839. */
  840. TreeTable.prototype.compareCaseSensitiveString = function(a,b){
  841. if(typeof(a.getSortValue()) == "string" && typeof(b.getSortValue()) == "string" ){
  842. if(a.getSortValue() < b.getSortValue()) return -1;
  843. if(a.getSortValue() > b.getSortValue()) return 1;
  844. return 0;
  845. }
  846. }
  847. /**
  848. *
  849. */
  850. TreeTable.prototype.compareNumber = function(a,b){
  851. if(isFinite(a.getSortValue()) && isFinite(b.getSortValue())){
  852. return b.getSortValue() - a.getSortValue();
  853. }
  854. }
  855. /**
  856. * CHARGEMENT DES DONNES
  857. */
  858. /**
  859. * Get an external File
  860. */
  861. TreeTable.prototype.loadXMLFile = function(url){
  862. /*var xmlDoc;
  863. // code for IE
  864. if (window.ActiveXObject){
  865. xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  866. xmlDoc.async=false;
  867. xmlDoc.load("data.xml");
  868. this.loadXML(xmlDoc);
  869. }else if (document.implementation && document.implementation.createDocument){
  870. // code for Mozilla, etc.
  871. xmlDoc= document.implementation.createDocument("","",null);
  872. xmlDoc.load(file);
  873. this.loadXML(xmlDoc);
  874. }else{
  875. alert('Your browser cannot handle this script');
  876. } */
  877. /*var oDomDoc = Sarissa.getDomDocument("","");
  878. oDomDoc.load(file);
  879. this.loadXML(oDomDoc);*/
  880. /*xmlhttp = new XMLHttpRequest();
  881. xmlhttp.onreadystatechange= this.readyToLoad;*/
  882. ajax[this.divName].open("GET", url, true);
  883. ajax[this.divName].send(null);
  884. /*xmlhttp.open("GET", url, true);
  885. xmlhttp.send(null);*/
  886. }
  887. TreeTable.prototype.readyToLoad = function() {
  888. var xmlhttp
  889. for(var id in ajax){
  890. xmlhttp = ajax[id];
  891. if (xmlhttp.readyState==4) {
  892. if (xmlhttp.status==200) {
  893. //if(xmlhttp.responseXML != null && xmlhttp.responseXML != undefined){
  894. xmlhttp.model.loadXML(xmlhttp.responseXML);
  895. //}
  896. }
  897. }
  898. }//end for
  899. }
  900. TreeTable.prototype.loadXML = function(xml){
  901. var root = xml.getElementsByTagName("treetable")[0];
  902. var treetable = document.getElementById(root.getAttribute("id")).model;
  903. if(root.getAttribute("loadingMethod") == "xml" ){
  904. treetable.loadXMLData(root);
  905. }else if(root.getAttribute("loadingMethod") == "JSON" ){
  906. treetable.loadJSON(root.textContent);
  907. }else{
  908. alert('Error while retrieving AJAX data');
  909. }
  910. }
  911. /**
  912. * Load an xml object
  913. *@param xml an XML Object
  914. */
  915. TreeTable.prototype.loadXMLData = function(xml){
  916. begin = new Date();
  917. //Parse Options
  918. var opts = new Array();
  919. var optNode = xml.getElementsByTagName("options")[0];
  920. for(var i = 0 ; i < optNode.getElementsByTagName("option").length ; i++){
  921. opts[optNode.getElementsByTagName("option")[i].getAttribute("name")] = optNode.getElementsByTagName("option")[i].getAttribute("value");
  922. }
  923. this.loadOptions(opts);
  924. //Parse Columns
  925. var cols = new Array();
  926. var colNode = xml.getElementsByTagName("cols")[0];
  927. for(var i = 0 ; i < colNode.getElementsByTagName("col").length ; i++){
  928. var c = colNode.getElementsByTagName("col")[i];
  929. cols[i] = new column(c.getAttribute("name"),c.getAttribute("type"), true, "input","10%" ,this.getSortMethodByName('loweredString'));
  930. }
  931. this.columns = cols;
  932. //Parse Rows
  933. var rows = new Array();
  934. var rowNode = xml.getElementsByTagName("rows")[0];
  935. for(var i = 0 ; i < rowNode.getElementsByTagName("row").length ; i++){
  936. var r = rowNode.getElementsByTagName("row")[i];
  937. var values = new Array();
  938. for(var j = 0 ; j < cols.length ; j++){
  939. values[j] = r.getAttribute(cols[j].name.toLowerCase());
  940. }
  941. rows[i] = new row(values, new Array());
  942. }
  943. this.rows = rows;
  944. this.build();
  945. this.updateMessage('Tableau généré en '+ (new Date()- begin)/1000 +' s' );
  946. }
  947. /**
  948. * Parse and load a JSON text
  949. *@param jsonTxt JSON text
  950. */
  951. TreeTable.prototype.loadJSON = function(jsonTxt){
  952. begin = new Date();
  953. //Call the string method parseJSON added in the json.js file
  954. this.loadJSONVar(eval('(' + jsonTxt + ')'));
  955. //this.loadJSONVar(jsonTxt.parseJSON());
  956. this.updateMessage('Tableau généré en '+ (new Date()- begin)/1000 +' s' );
  957. }
  958. /**
  959. * Load a JSON var
  960. *@param jsonVar JSON var
  961. */
  962. TreeTable.prototype.loadJSONVar = function(jsonVar){
  963. if(jsonVar["options"] != null)
  964. this.loadOptions(jsonVar["options"]);
  965. if(jsonVar["columns"] != null)
  966. this.loadColumns(jsonVar["columns"]);
  967. if(jsonVar["rows"] != null)
  968. this.loadRows(jsonVar["rows"]);
  969. this.build();
  970. }
  971. /**
  972. * Load options of the table
  973. *@param options associative array
  974. */
  975. TreeTable.prototype.loadOptions = function(options){
  976. for (var key in options) {
  977. this[key] = options[key];
  978. }
  979. }
  980. /**
  981. * Load columns of the table
  982. *@param columns associative array
  983. */
  984. TreeTable.prototype.loadColumns = function(columns){
  985. this.columns = new Array();
  986. for(i = 0 ; i < columns.length ; i++){
  987. this.columns.push(this.objectToColumn(columns[i]));
  988. }
  989. }
  990. /**
  991. * Convert an object to a column
  992. */
  993. TreeTable.prototype.objectToColumn = function(obj){
  994. return new column(obj.name, obj.type, obj.isSorted, obj.filter,obj.width, this.getSortMethodByName(obj.sort));
  995. }
  996. /**
  997. * Load rows of the table
  998. *@param rows associative array
  999. */
  1000. TreeTable.prototype.loadRows = function(rows){
  1001. this.rows = new Array();
  1002. for(i = 0 ; i < rows.length ; i++){
  1003. this.rows.push(this.objectToRow(rows[i]));
  1004. }
  1005. }
  1006. /**
  1007. * Convert an object to a row
  1008. */
  1009. TreeTable.prototype.objectToRow = function(obj){
  1010. return new row(obj.cols,this.childrenToRows(obj.children));
  1011. }
  1012. /**
  1013. * Convert an array of children into an array of rows and call recursively the objectToRow method
  1014. */
  1015. TreeTable.prototype.childrenToRows = function(children){
  1016. var rows = new Array();
  1017. for(var i = 0 ; i < children.length ; i ++){
  1018. rows[i] = this.objectToRow(children[i]);
  1019. }
  1020. return rows;
  1021. }
  1022. /**
  1023. * Load JSON var example to make a model of which text you may code
  1024. */
  1025. TreeTable.prototype.loadJSONExample = function(){
  1026. begin = new Date();
  1027. jsonVar = {"columns":[{"name":"Colonne1","type":"String","isSorted":true,"filter":"input","width":"25%"},{"name":"Colonne2","type":"Number","isSorted":true,"filter":"select","width":"25%"},{"name":"Colonne3","type":"Number","isSorted":true,"filter":"number","width":"25%"},{"name":"Colonne4","type":"Number","isSorted":true,"filter":"","width":"25%"}],"rows":[{"cols":["POzzle Bubble",3,6,8],"expanded":false,"children":[{"cols":[" pbub",3,6,8],"expanded":false,"children":[],"sortIdx":0}],"sortIdx":0},{"cols":["Kid Bubble",356,20,1],"expanded":false,"children":[],"sortIdx":0},{"cols":["Daika Chi",36,20,1],"expanded":false,"children":[],"sortIdx":0},{"cols":["Super mario",6,2,41],"expanded":false,"children":[],"sortIdx":0},{"cols":["Pong",85,220,1],"expanded":false,"children":[],"sortIdx":0},{"cols":["Brexac",7,98,1],"expanded":false,"children":[],"sortIdx":0},{"cols":["Road rash",9,20,1],"expanded":false,"children":[],"sortIdx":0}]};
  1028. this.loadJSONVar(jsonVar);
  1029. this.updateMessage('Tableau généré en '+ (new Date()- begin)/1000 +' s' );
  1030. }
  1031. /**
  1032. * Load example to test the render of the table
  1033. */
  1034. TreeTable.prototype.loadExample = function(){
  1035. begin = new Date();
  1036. this.columns = new Array(
  1037. new column("Nom", "String", true, 'input','100px',this.compareLoweredString),
  1038. new column("Genre", "String", true, 'input','100px',this.compareCaseSensitiveString),
  1039. new column("Taille", "Number", true, 'input','100px',this.compareNumber),
  1040. new column("Note", "Number", true, 'input','100px',this.compareNumber)
  1041. ,new column("", "String", false, '', '100px',this.compareNumber)
  1042. );
  1043. this.rows = new Array(
  1044. new row(["Blob","volley", 12 , 14 ,"<a>Get It</a>"],[new row(["|_lev2","volley1", 12 , 14 ],[]),new row(["|_lev2","volley2", 12 , 14 ],[new row([" |_lev3","", 12 , 14 ],[new row([" |_lev4","", 12 , 14 ],[])])])]),
  1045. new row(["MK4","baston 2D",54 , 19,"<a>Get It</a>"],[]),
  1046. new row(["AVP2","shoot",650,17,"<a>Get It</a>"],[]),
  1047. new row(["CS","shoot",1400,10,"<a>Get It</a>"],[]),
  1048. new row(["Mario kart","course",100,18,"<a>Get It</a>"],[]),
  1049. new row(["BF2","shoot",2500,19,"<a>Get It</a>"],[]),
  1050. new row(["NFS","course",400,14,"<a>Get It</a>"],[]),
  1051. new row(["Trackmania","course",500,16,"<a>Get It</a>"],[])
  1052. );
  1053. for(i=0 ;i<=1000 ;i++){
  1054. this.rows.push(new row(["jeu"+i,"course",10*i,16,"<a>Get It</a>"],[]));
  1055. }
  1056. row.prototype.sortIdx = 0;
  1057. this.rows.sort(this.columns[0].compare);
  1058. this.build();
  1059. this.updateMessage('Tableau généré en '+ (new Date()- begin)/1000 +' s' );
  1060. }
  1061. TreeTable.prototype.exportJSON = function(){
  1062. var o = new Object();
  1063. o["options"] = this.options;
  1064. o["columns"] = this.columns;
  1065. o["rows"] = this.rows;
  1066. document.getElementById('debug').innerHTML = o.toJSONString();
  1067. }
  1068. TreeTable.prototype.exportXML = function(){
  1069. //todo FOR BENCHMARK
  1070. var res = '';
  1071. res +='<treetable id="table5" loadingMethod="xml">';
  1072. res +="<options>";
  1073. //<option name="displayBy" value="25" />
  1074. res +="</options><cols>";
  1075. for(var i = 0 ; i < this.columns.length ; i++){
  1076. res +='<col name="'+this.columns[i].name+'" type="'+this.columns[i].type+'" />';
  1077. }
  1078. res +="</cols><rows>";
  1079. for(var i = 0 ; i < this.rows.length ; i++){
  1080. res +='<row ';
  1081. for(var j =0 ; j < this.columns.length ; j++){
  1082. res += this.columns[j].name.toLowerCase()+'="'+this.rows[i].cols[j]+'" ';
  1083. }
  1084. res += '/>';
  1085. }
  1086. res +='</rows></treetable>';
  1087. document.getElementById('toto').innerHTML = escape(res);
  1088. }
  1089. TreeTable.prototype.getLogger = function (){
  1090. if(!this.logger){
  1091. this.logger = getLogger("TREETABLE");
  1092. this.logger.setLevel(Logger.LEVEL_ALL);
  1093. }
  1094. this.logger.setCurrentID(this.divName);
  1095. return this.logger;
  1096. }