OSDN Git Service

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@1020 1ca29b6e-896d...
[nucleus-jp/nucleus-plugins.git] / NP_TrackBack / branches / DOM-branch / trackback / js / rico / ricoSimpleGrid.js
1 /**
2   *  (c) 2005-2007 Richard Cowin (http://openrico.org)
3   *  (c) 2005-2007 Matt Brown (http://dowdybrown.com)
4   *
5   *  Rico is licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6   *  file except in compliance with the License. You may obtain a copy of the License at
7   *   http://www.apache.org/licenses/LICENSE-2.0
8   **/
9
10
11 if(typeof Rico=='undefined') throw("SimpleGrid requires the Rico JavaScript framework");
12 if(typeof RicoUtil=='undefined') throw("SimpleGrid requires the RicoUtil Library");
13 if(typeof RicoTranslate=='undefined') throw("SimpleGrid requires the RicoTranslate Library");
14
15 Rico.SimpleGrid = Class.create();
16
17 Rico.SimpleGrid.prototype = {
18
19   initialize: function( tableId, options ) {
20     Object.extend(this, new Rico.GridCommon);
21     this.baseInit(tableId);
22     Rico.setDebugArea(tableId+"_debugmsgs");    // if used, this should be a textarea
23     Object.extend(this.options, options || {});
24     this.tableId = tableId;
25     this.createDivs();
26     this.hdrTabs=new Array(2);
27     for (var i=0; i<2; i++) {
28       this.tabs[i]=$(tableId+'_tab'+i);
29       this.hdrTabs[i]=$(tableId+'_tab'+i+'h');
30       if (i==0) this.tabs[i].style.position='absolute';
31       if (i==0) this.tabs[i].style.left='0px';
32       this.hdrTabs[i].style.position='absolute';
33       this.hdrTabs[i].style.top='0px';
34       this.hdrTabs[i].style.zIndex=1;
35       this.thead[i]=this.hdrTabs[i];
36       this.tbody[i]=this.tabs[i];
37       this.headerColCnt = this.getColumnInfo(this.hdrTabs[i].rows);
38       if (i==0) this.options.frozenColumns=this.headerColCnt;
39     }
40     if (this.headerColCnt==0) {
41       alert('ERROR: no columns found in "'+this.tableId+'"');
42       return;
43     }
44     this.hdrHt=Math.max(RicoUtil.nan2zero(this.hdrTabs[0].offsetHeight),this.hdrTabs[1].offsetHeight);
45     for (var i=0; i<2; i++)
46       if (i==0) this.tabs[i].style.top=this.hdrHt+'px';
47     this.createColumnArray();
48     this.pageSize=this.columns[0].dataColDiv.childNodes.length;
49     this.sizeDivs();
50     this.attachMenuEvents();
51     this.scrollEventFunc=this.handleScroll.bindAsEventListener(this);
52     this.pluginScroll();
53     if (this.options.windowResize)
54       Event.observe(window,"resize", this.sizeDivs.bindAsEventListener(this), false);
55   },
56
57   /**
58    * Register a menu that will only be used in the scrolling part of the grid.
59    * If submenus are used, they must be registered after the main menu.
60    */
61   registerScrollMenu: function(menu) {
62     if (!this.menu) this.menu=menu;
63     menu.grid=this;
64     menu.showmenu=menu.showSimpleMenu;
65     menu.showSubMenu=menu.showSimpleSubMenu;
66     menu.createDiv(this.scrollDiv);
67   },
68   
69   handleMenuClick: function(e) {
70     this.cancelMenu();
71     this.menuCell=RicoUtil.getParentByTagName(Event.element(e),'div');
72     this.highlightEnabled=false;
73     if (this.hideScroll) this.scrollDiv.style.overflow="hidden";
74     if (this.menu.buildGridMenu) this.menu.buildGridMenu(this.menuCell);
75     this.menu.showmenu(e,this.closeMenu.bind(this));
76   },
77
78   closeMenu: function() {
79     if (this.hideScroll) this.scrollDiv.style.overflow="";
80     this.highlightEnabled=true;
81   },
82
83   sizeDivs: function() {
84     if (this.outerDiv.offsetParent.style.display=='none') return;
85     this.baseSizeDivs();
86     var maxHt=Math.max(this.options.maxHt || this.availHt(), 50);
87     var totHt=Math.min(this.hdrHt+this.dataHt, maxHt);
88     Rico.writeDebugMsg('sizeDivs '+this.tableId+': hdrHt='+this.hdrHt+' dataHt='+this.dataHt);
89     this.dataHt=totHt-this.hdrHt;
90     if (this.scrWi>0) this.dataHt+=this.options.scrollBarWidth;
91     this.scrollDiv.style.height=this.dataHt+'px';
92     var divAdjust=2;
93     this.innerDiv.style.width=(this.scrWi-this.options.scrollBarWidth+divAdjust)+'px';
94     this.innerDiv.style.height=this.hdrHt+'px';
95     totHt+=divAdjust;
96     this.resizeDiv.style.height=this.frozenTabs.style.height=totHt+'px';
97     this.outerDiv.style.height=(totHt+this.options.scrollBarWidth)+'px';
98     this.setHorizontalScroll();
99   }
100
101 };
102
103 if (Rico.Menu) {
104 Object.extend(Rico.Menu.prototype, {
105
106 showSimpleMenu: function(e,hideFunc) {
107   Event.stop(e);
108   this.hideFunc=hideFunc;
109   if (this.div.childNodes.length==0) {
110     this.cancelmenu();
111     return false;
112   }
113   this.clientX=Event.pointerX(e);
114   this.clientY=Event.pointerY(e);
115   var elem=Event.element(e);
116   while (elem && !Element.hasClassName(elem,'ricoLG_cell'))
117     elem=elem.parentNode;
118   if (!elem) return false;
119   var td=RicoUtil.getParentByTagName(elem,'td');
120
121   var newLeft=Math.floor(td.offsetLeft+td.offsetWidth/2);
122   if (this.direction == 'rtl') {
123     if (newLeft > this.width) newLeft-=this.width;
124   } else {
125     if (newLeft+this.width+this.options.margin > this.grid.scrollDiv.scrollLeft+this.grid.scrollDiv.clientWidth) newLeft-=this.width;
126   }
127   this.div.style.visibility="hidden";
128   this.div.style.display="block";
129   var contentHt=this.div.offsetHeight;
130   var newTop=Math.floor(elem.offsetTop+elem.offsetHeight/2);
131   if (newTop+contentHt+this.options.margin > this.grid.scrollDiv.scrollTop+this.grid.scrollDiv.clientHeight)
132     newTop=Math.max(newTop-contentHt,0);
133   this.openPopup(newLeft,newTop);
134   this.div.style.visibility ="visible";
135   return elem;
136 },
137
138 showSimpleSubMenu: function(a,submenu) {
139   if (this.openSubMenu) this.hideSubMenu();
140   this.openSubMenu=submenu;
141   this.openMenuAnchor=a;
142   if (a.className=='ricoSubMenu') a.className='ricoSubMenuOpen';
143   var top=parseInt(this.div.style.top);
144   var left=parseInt(this.div.style.left);
145   submenu.openPopup(left+a.offsetWidth,top+a.offsetTop);
146   submenu.div.style.visibility ="visible";
147 }
148     
149 });
150 }
151
152 Object.extend(Rico.TableColumn.prototype, {
153
154 initialize: function(grid,colIdx,hdrInfo,tabIdx) {
155   this.baseInit(grid,colIdx,hdrInfo,tabIdx);
156 }
157
158 });
159
160 Rico.includeLoaded('ricoSimpleGrid.js');