cellHandle=Class.create();
cellHandle.prototype={initialize:function(_1,_2){
this.cjson=_2;
if(!_1){
parent.debug("CellHandle.initialize failed. Cell element undefined.");
return;
}else{
if(_1==null){
parent.debug("CellHandle.initialize failed. Cell element is null.");
return;
}
}
this.readonly=false;
this.cell=Element.extend(_1);
this.cellAddress=_1.getAttribute("id");
this.dt=null;
this.spanningCell=false;
this.rowCol=null;
this.validationMessage==null;
this.wordWrap=false;
this.DateValue=null;
if(_2){
this.updateInternal(_2);
return;
}
this.formattedValue=_1.innerHTML;
try{
this.dataContainer=_1.childNodes[0];
}
catch(e){
}
this.href=_1.getAttribute("HRef");
if(this.href!=null){
parent.showStatus("ctrl+click to open: "+this.href);
}
if(_1.getAttribute("fs")!=null){
this.value=_1.getAttribute("fs");
}else{
if(_1.getAttribute("val")!=null){
this.value=_1.getAttribute("val");
}else{
if(this.dataContainer){
this.value=this.dataContainer.innerHTML;
}else{
this.value=_1.innerHTML;
}
}
}
if(_1.getAttribute("spanning")=="true"){
this.spanningCell=true;
}
if(_1.getAttribute("vmsg")!=null){
this.validationMessage=_1.getAttribute("vmsg");
}
this.rowCol=null;
this.locked=false;
this.formulahidden=false;
},toString:function(){
return "<td>"+this.value+"</td>";
},getVal:function(){
return this.value;
},getFormattedVal:function(){
return this.formattedVal();
},setVal:function(_3){
var _4="";
if(this.cell==null){
return;
}
_4=this.value;
if(_4==null){
_4="";
}
this.cell.value=_3;
this.cell.formattedValue=_3;
this.value=_3;
this.setDisplayValue(_3);
var _5=this;
var _6="/workbook/"+book.loadby+"/"+book.selectedSheet.getMemeId()+"/json/cell/add/"+book.selectedSheet.getSheetName()+"!"+this.cellAddress+"/"+_3;
new Ajax.Request(_6,{method:"get",onSuccess:function(_7){
book.selectedSheet.updateCellsFromJSON(_7.responseText);
},onFailure:function(_8){
var _9=_8.responseText||"failure";
try{
var _a=_9.evalJSON();
parent.showError("Unable to set server cell value: "+_a.errorMessage);
if(_5.cell!=null){
_5.setDisplayValue(_4);
}
}
catch(e){
parent.showError("Unable to set server cell value:"+_5.newValue);
}
}});
this.expandCell();
},setDisplayValue:function(_b){
var rc=this.getRowCol();
var _d=toolkit.ALPHAS[rc[1]];
if(!this.dataContainer){
this.dataContainer=Element.extend(document.createElement("div"));
this.dataContainer.setAttribute("id","cont"+this.cellAddress);
this.cell.appendChild(this.dataContainer);
this.dataContainer.className+=(this.dataContainer.className?" ":"")+"datacell";
this.dataContainer.className+=(this.dataContainer.className?" ":"")+"colwidth"+_d;
if(_d=="A"){
this.dataContainer.className+=(this.dataContainer.className?" ":"")+"rowheight"+(rc[0]+1);
}
}else{
this.dataContainer.addClassName("colwidth"+_d);
if(_d=="A"){
this.dataContainer.addClassName("rowheight"+(rc[0]+1));
}
}
if(this.cell.colSpan>1){
toolkit.setFixedWidth(this.dataContainer);
this.dataContainer.addClassName("mergedcell");
}
if(this.cell.rowSpan>1&&_d=="A"){
toolkit.setFixedHeight(this.dataContainer);
this.dataContainer.addClassName("mergedcell");
}
if(this.wordWrap){
this.dataContainer.setStyle({whiteSpace:"normal"});
}
this.dataContainer.innerHTML=_b;
this.value=_b;
},isLocked:function(){
if(sheet.cellProtection){
if(this.cell.getAttribute("locked")==null){
return true;
}
if(this.cell.getAttribute("locked")=="true"){
return true;
}
}
return false;
},updateInternal:function(_e){
this.cjson=_e;
this.cell.removeAttribute("fs");
this.cell.removeAttribute("val");
this.cell.removeAttribute("href");
this.cell.removeAttribute("dt");
this.DateValue=null;
this.cell.setAttribute("id",_e.loc);
this.cellAddress=_e.loc;
if(_e.fm!=null){
if(_e.fhd==null){
this.cell.setAttribute("fs",_e.fm);
}else{
this.formulahidden=true;
this.cell.setAttribute("formulahidden","true");
}
this.value=_e.fm;
}
if(_e.sid!=null){
book.selectedSheet.styleHandle.updateAttachedCSS("s"+_e.sid,this.cell);
}
if(_e.vm!=null){
this.validationMessage=_e.vm;
this.cell.setAttribute("vmsg",_e.vm);
}
if(_e.wrap!=null){
this.wordWrap=true;
}
if(_e.d.DateValue!=null){
this.cell.setAttribute("dt",_e.d.DateValue);
this.cell.setAttribute("title","ctrl+click for date picker");
this.DateValue=_e.d.DateValue;
}
if(_e.lck!=null){
this.cell.setAttribute("locked",_e.lck);
}
if(_e.HRef!=null){
this.href=_e.HRef;
this.cell.setAttribute("href",_e.HRef);
this.cell.setAttribute("title","ctrl+click to open: "+_e.HRef);
this.cell.setStyle({color:"blue",textDecoration:"underline"});
if(this.href.indexOf("pop-in-grid")>-1){
if((this.href.indexOf(".swf")>-1)||(this.href.indexOf("youtube.com")>-1)){
createDialogWindow(this.value,"/uimodules/docs/docs_flash_viewer.jsp?url="+escape(this.href),"imageembed");
}else{
createDialogWindow(this.value,this.href,book.theme);
}
}
}
if(_e.sid!=null){
this.cell.addClassName("s"+_e.sid);
}
if(_e.negRed!=null){
this.cell.addClassName("negativeNumber");
}else{
this.cell.removeClassName("negativeNumber");
}
if(_e.MergeChild!=null&&_e.MergeChild){
this.cell.remove();
return;
}
if(_e.MergeParent!=null&&_e.MergeParent){
this.cell.setAttribute("MergeParent",true);
}
var _f=_e.MergeAcross;
if(_f!=null){
if(_f>0){
this.cell.colSpan=(_f+1);
}
var rc=this.getRowCol();
for(var i=1;i<=_f;i++){
if(rc!=null){
rc[1]+=i;
var _12=$(toolkit.formatLocation(rc));
try{
if(_12!=null){
_12.remove();
}
}
catch(e){
}
}
}
}else{
if(!this.spanningCell){
this.cell.colSpan=1;
}
}
var _13=_e.MergeDown;
if(_13!=null){
if(_13>0){
this.cell.rowSpan=(_13+1);
var rc=this.getRowCol();
for(var i=1;i<=_13;i++){
if(rc!=null){
rc[0]+=i;
var _12=$(toolkit.formatLocation(rc));
try{
if(_12!=null){
_12.remove();
}
}
catch(e){
}
}
}
}
}else{
if(this.cell.getAttribute("rowspan")!=1){
this.cell.rowSpan=1;
}
}
if(_e.d.fv!=null){
try{
this.formattedValue=_e.d.fv;
this.setDisplayValue(_e.d.fv);
this.cell.setAttribute("val",_e.d.v);
}
catch(e){
parent.showError("cellHandle.init value failed:"+e.toString());
}
}else{
this.formattedValue=_e.d.v;
this.setDisplayValue(_e.d.v);
}
},getAddress:function(_14){
if(_14){
return parent.uiWindowing.getActiveSheet().getSheetName()+"!"+this.cellAddress;
}
return this.cellAddress;
},getRowCol:function(_15){
if(this.rowCol){
return this.rowCol;
}
this.rowCol=toolkit.getRowColFromString(this.cellAddress);
return this.rowCol;
},getColHandle:function(){
var _16=this.getRowCol()[1];
var _17=new colHandle(toolkit.ALPHAS[_16]);
return _17;
},getRowHandle:function(){
var _18=this.getRowCol()[0];
var _19=new rowHandle(_18);
return _19;
},getClasses:function(){
var _1a=this.cell.classNames();
return _1a;
},setClasses:function(_1b){
var _1c=this.cellAddress;
_1b.each(function(s){
$(_1c).addClassName(s);
});
},getStyleString:function(){
return this.cell.getStyle();
},switchStyle:function(_1e,_1f,_20){
var cr=new cellRange(this.cellAddress+":"+this.cellAddress,book.selectedSheet.sheetName);
cr.switchStyle(_1e,_1f,_20);
},getCellElement:function(){
return this.cell;
},popHyperlinkDialog:function(){
_this=this;
Dialog.confirm($("hlink_form").innerHTML,{className:book.theme,width:300,height:100,zIndex:100,okLabel:"set link",cancelLabel:"cancel",cancel:function(win){
parent.showStatus("set hyperlink canceled.");
return false;
},onOk:function(win){
var _24=$("hlink_input").getValue();
var _25=$("pop-in-grid").getValue();
var _26=(_24=="");
var url="/workbook/"+book.loadby+"/"+book.selectedSheet.memeId+"/json/cell/setlink/"+cursor.liveCell.getAddress(true)+"/"+_24;
if(_25=="on"){
if(url.indexOf("?")>-1){
url+="&pop-in-grid=true";
}else{
url+="?pop-in-grid=true";
}
}
_cursor=cursor;
_sheet=uiWindowing.getActiveSheet();
_removelink=_26;
new Ajax.Request(url,{method:"get",onSuccess:function(_28){
_sheet.updateCellsFromJSON(_28.responseText);
if(_removelink){
_cursor.liveCell.cell.setStyle({color:"black",textDecoration:"none"});
_cursor.liveCell.cell.removeAttribute("href");
_cursor.liveCell.cell.removeAttribute("title");
parent.showStatus("Removed hyperlink: "+_28.responseText);
}
},onFailure:function(_29){
var _2a=_29.responseText||"failure";
parent.showError("Set hyperlink failed: "+_2a);
}});
return true;
}});
},shouldExpand:function(_2b,_2c){
var _2d=1;
if(this.cell.getAttribute("colspan")!=null&&this.cell.getAttribute("colspan")!=1){
if(this.cell.getAttribute("spanning")!="true"){
return false;
}else{
_2d=parseInt(this.cell.getAttribute("colspan"));
}
}
var rc=this.getRowCol();
if(rc!=null){
rc[1]+=_2d;
if(_2c){
if(rc[1]>=_2c){
return false;
}
}else{
var _2f=$("cont"+toolkit.formatLocation(rc));
if(_2f!=null){
if(_2f.innerHTML!=""){
return false;
}
}
}
}
var _30=_2b.clientWidth;
var _31=this.cell.clientWidth;
if(_30>_31){
return true;
}
return false;
},shouldShrink:function(_32){
if(!this.spanningCell){
return false;
}
var _33=_32.clientWidth;
var _34=this.cell.getWidth();
if(_32.getWidth()<this.cell.getWidth()){
return true;
}
return false;
},initWidthChecker:function(){
var _35=sheet.widthChecker;
var _36=$w(_35.className);
for(var i=0;i<_36.size();i++){
_35.removeClassName(_36[i]);
}
this.getClasses().each(function(s){
_35.className+=(_35.className?" ":"")+s;
});
_35.innerHTML=this.getVal();
return _35;
},shrinkCell:function(){
var _39=this.initWidthChecker();
if(this.shouldShrink(_39)){
this.spanningCell=false;
this.cell.setAttribute("spanning","false");
toolkit.removeFixedWidth(this.dataContainer);
this.unmerge();
}
},expandCell:function(){
var _3a=this.initWidthChecker();
var _3b=1;
if(this.cell.colSpan<=1){
return _3b;
}
while(this.shouldExpand(_3a)){
_3b++;
this.spanningCell=true;
this.cell.setAttribute("spanning","true");
var _3c=1;
if(this.cell.getAttribute("colspan")!=null){
_3c=this.cell.getAttribute("colspan");
}
_3c=parseInt(_3c);
_3c++;
this.cell.colSpan=_3c;
var rc=this.getRowCol();
for(var i=1;i<_3c;i++){
if(rc!=null){
rc[1]+=i;
var _3f=this.cell.next();
try{
if(_3f!=null){
_3f.remove();
}
}
catch(e){
}
}
}
}
var _40=toolkit.ALPHAS[this.getRowCol()[1]];
this.dataContainer.addClassName("colwidth"+_40);
if(_3c>1){
toolkit.setFixedWidth(this.dataContainer);
this.dataContainer.addClassName("mergedcell");
}
return _3b;
},automerge:function(_41){
var _42=1;
if(this.cell.colSpan<=1){
return _42;
}
if(this.value.length>sheet.automergelimit){
var _43=this.initWidthChecker();
var _44=1;
while(this.shouldExpand(_43,_41)){
_42++;
this.spanningCell=true;
this.cell.setAttribute("spanning","true");
if(this.cell.getAttribute("colspan")!=null){
_44=this.cell.getAttribute("colspan");
}
_44=parseInt(_44);
_44++;
this.cell.colSpan=_44;
var rc=this.getRowCol();
for(var i=1;i<_44;i++){
if(rc!=null){
rc[1]+=i;
var _47=this.cell.next();
try{
if(_47!=null){
_47.remove();
}
}
catch(e){
}
}
}
}
if(_44>1){
var _48=toolkit.ALPHAS[this.getRowCol()[1]];
this.dataContainer.addClassName("colwidth"+_48);
toolkit.setFixedWidth(this.dataContainer);
this.dataContainer.addClassName("mergedcell");
}
}
return _42;
},unmerge:function(){
var rc=this.getRowCol();
var _4a=1;
if(this.cell.getAttribute("colspan")!=null){
_4a=parseInt(this.cell.getAttribute("colspan"));
}
if(_4a>1){
this.cell.colSpan=1;
var _4b=$("Rw"+(rc[0]));
var _4c=new Array();
_4c[0]=rc[0];
for(var x=_4a;x>1;x--){
var _4e=rc[1]+(x-1);
var _4f=_4b.insertCell(rc[1]+1);
_4c[1]=_4e;
var _50=toolkit.formatLocation(_4c);
try{
_4f.setAttribute("id",toolkit.formatLocation(_4c));
}
catch(e){
}
}
}
var _51=1;
if(this.cell.getAttribute("rowspan")!=null){
_51=parseInt(this.cell.getAttribute("rowspan"));
}
if(_51>1){
this.cell.rowSpan=1;
var _4c=new Array();
_4c[1]=rc[1];
for(var i=1;i<_51;i++){
var _4b=$("Rw"+(rc[0]+i));
var _4f=_4b.insertCell(rc[1]);
_4c[0]=(rc[0]+i);
var _50=toolkit.formatLocation(_4c);
try{
_4f.setAttribute("id",toolkit.formatLocation(_4c));
}
catch(e){
}
}
}
},eventInMainCell:function(evt){
var rc=this.getRowCol();
var _55=$(toolkit.ALPHAS[rc[1]+1]+"0").positionedOffset()[0]+30;
if(evt.clientX>_55){
return false;
}
return true;
},hasVerticalBorders:function(){
var _56=$w(this.cell.className);
for(var i=0;i<_56.length;i++){
if(_56[i].indexOf("s")==0){
var _58=toolkit.getExternalRule("."+_56[i],0);
if(_58.cssText.indexOf("border-right")>-1||_58.cssText.indexOf("border-left")>-1||_58.cssText.indexOf("border:")>-1){
return true;
}
}
}
return false;
},hasHorizontalBorders:function(){
var _59=$w(this.cell.className);
for(var i=0;i<_59.length;i++){
if(_59[i].indexOf("s")==0){
var _5b=toolkit.getExternalRule("."+_59[i],0);
if(_5b.cssText.indexOf("border-top")>-1||_5b.cssText.indexOf("border-bottom")>-1||_5b.cssText.indexOf("border:")>-1){
return true;
}
}
}
return false;
},promptDate:function(){
_this=this;
datetoolkit.setCell(this);
datetoolkit.showCalendar();
try{
var dvz=_this.cell.getAttribute("dt");
datetoolkit.initCalendar(dvz);
}
catch(e){
showError("cellHandle.promptDate failed: "+e.toString());
}
}};
