tree.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.grid.cells.tree"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.grid.cells.tree"] = true;
  8. dojo.provide("dojox.grid.cells.tree");
  9. dojo.require("dojox.grid.cells");
  10. dojox.grid.cells.TreeCell = {
  11. formatAggregate: function(inItem, level, inRowIndexes){
  12. var f, g=this.grid, i=g.edit.info,
  13. d=g.aggregator ? g.aggregator.getForCell(this, level, inItem, level === this.level ? "cnt" : this.parentCell.aggregate) : (this.value || this.defaultValue);
  14. return this._defaultFormat(d, [d, level - this.level, inRowIndexes, this]);
  15. },
  16. formatIndexes: function(inRowIndexes, inItem){
  17. var f, g=this.grid, i=g.edit.info,
  18. d=this.get ? this.get(inRowIndexes[0], inItem, inRowIndexes) : (this.value || this.defaultValue);
  19. if(this.editable && (this.alwaysEditing || (i.rowIndex==inRowIndexes[0] && i.cell==this))){
  20. return this.formatEditing(d, inRowIndexes[0], inRowIndexes);
  21. }else{
  22. return this._defaultFormat(d, [d, inRowIndexes[0], inRowIndexes, this]);
  23. }
  24. },
  25. getOpenState: function(itemId){
  26. var grid = this.grid, store = grid.store, itm = null;
  27. if(store.isItem(itemId)){
  28. itm = itemId;
  29. itemId = store.getIdentity(itemId);
  30. }
  31. if(!this.openStates){ this.openStates = {}; }
  32. if(typeof itemId != "string" || !(itemId in this.openStates)){
  33. this.openStates[itemId] = grid.getDefaultOpenState(this, itm);
  34. }
  35. return this.openStates[itemId];
  36. },
  37. formatAtLevel: function(inRowIndexes, inItem, level, summaryRow, toggleClass, cellClasses){
  38. if(!dojo.isArray(inRowIndexes)){
  39. inRowIndexes = [inRowIndexes];
  40. }
  41. var result = "";
  42. if(level > this.level || (level === this.level && summaryRow)){
  43. cellClasses.push("dojoxGridSpacerCell");
  44. if(level === this.level){
  45. cellClasses.push("dojoxGridTotalCell");
  46. }
  47. result = '<span></span>';
  48. }else if(level < this.level){
  49. cellClasses.push("dojoxGridSummaryCell");
  50. result = '<span class="dojoxGridSummarySpan">' + this.formatAggregate(inItem, level, inRowIndexes) + '</span>';
  51. }else{
  52. var ret = "";
  53. if(this.isCollapsable){
  54. var store = this.grid.store, id = "";
  55. if(store.isItem(inItem)){
  56. id = store.getIdentity(inItem);
  57. }
  58. cellClasses.push("dojoxGridExpandoCell");
  59. ret = '<span dojoType="dojox.grid._Expando" level="' + level + '" class="dojoxGridExpando"' +
  60. '" toggleClass="' + toggleClass + '" itemId="' + id + '" cellIdx="' + this.index + '"></span>';
  61. }
  62. result = ret + this.formatIndexes(inRowIndexes, inItem);
  63. }
  64. if(this.grid.focus.cell && this.index == this.grid.focus.cell.index &&
  65. inRowIndexes.join('/') == this.grid.focus.rowIndex){
  66. cellClasses.push(this.grid.focus.focusClass);
  67. }
  68. return result;
  69. }
  70. };
  71. }