function NoteObject(id)
{
this.m_expObj = g_dc.getElemFormID(id);
this.m_icnObj = this.CreateIcnObj(this.m_expObj);
this.m_expObj.style.position = 'absolute';
this.m_origxPos = this.m_xPos = toInt(this.m_expObj.getAttribute("X"))+g_dc.GetWorkAreaRC().m_left;
this.m_origyPos = this.m_yPos = toInt(this.m_expObj.getAttribute("Y"))+g_dc.GetWorkAreaRC().m_top;
this.m_origW = this.m_width = this.m_expObj.getAttribute("W");
this.m_origH = this.m_height = this.m_expObj.getAttribute("H");
this.m_noteID = this.m_expObj.getAttribute("noteID");
this.m_origIsIcn = this.m_isIcn = (this.m_expObj.getAttribute("isIcn")==0)?false:true;
this.m_expObj.style.fontSize=NOTE_FONT_SIZE;
this.m_expObj.style.fontFamily=NOTE_FONT_FAMILY;
this.m_expObj.style.fontWeight=NOTE_FONT_WEIGHT;
this.m_selected = true;
this.m_expObj.dragContainer = this.m_icnObj.dragContainer = this;
this.m_icnObj.onmousedown = g_eventRouter.OnIconMouseDown;
this.m_icnObj.onmouseup = g_eventRouter.OnIconMouseUp;
this.m_expObj.onmousedown = g_eventRouter.OnIconMouseDown;
this.m_expObj.ondblclick =g_eventRouter.OnHeaderDblClick;
this.m_deleted = false;
this.InitClipButton("IcnExpandBtn", "onExpandClick", this.m_icnObj);
g_dc.InitRegularTT("IcnExpandBtn",this.m_icnObj,"Expand note", this.m_noteID+"exp");
this.InitClipButton("IcnDeleteBtn", "onDeleteClick", this.m_icnObj);
g_dc.InitRegularTT("IcnDeleteBtn",this.m_icnObj,"Delete note", this.m_noteID+"del");
this.InitClipButton("clipButtonClose", "onDeleteClick", this.m_expObj);
g_dc.InitRegularTT("clipButtonClose",this.m_expObj,"Delete note", this.m_noteID+"delex");
this.InitClipButton("clipButtonIconize", "onIconizeClick", this.m_expObj);
g_dc.InitRegularTT("clipButtonIconize",this.m_expObj,"Switch to icon", this.m_noteID+"tic");
this.CreateResizeHandles();
this.ResizeTo(this.m_width, this.m_height);
this.MoveTo(this.m_xPos,this.m_yPos);
this.Show();
this.SetSelected(false);
this.ondblclick = g_eventRouter.OnHeaderDblClick;
this.m_origTxt = this.Edit_getText();
}
NoteObject.prototype.Delete = function()
{
try {
//g_dc.m_aElements[this.m_expObj.id]= null;
this.m_expObj.parentNode.removeChild(this.m_expObj);
this.m_icnObj.parentNode.removeChild(this.m_icnObj);
this.m_deleted = true;
g_dc.setDirty(true);
//delete this;
}
catch (err){
alert(err.description)
}
}
NoteObject.prototype.CreateIcnObj = function(expOb)
{
if (expOb==null){alert('error1');return;}
var div = document.createElement('div');
if (!(div) || div==null){alert('error3');return;}
g_dc.SetClass(div, "noteIconDiv");
div.innerHTML = "
"+
""+
""+
"
" +
"" +
"
";
div.setAttribute('id',expOb.getAttribute("id")+"_note");
g_dc.docBody.appendChild(div);
//div.ondblclick = g_eventRouter.OnIcnDblClick;
/////////////////////////////////////////////////////////////
// Tooltip Implementation
div.TTShow = function()
{
try{
var prnt = this.dragContainer;
var rc = prnt.GetCurrRC(this.m_icnObj);
var expndRc = prnt.CalcExpndRC(rc);
prnt.MoveTo(expndRc.m_left, expndRc.m_top,prnt.m_expObj, false);
prnt.ShowAsTT(true);
}
catch(err)
{alert(err);}
}
div.TTHide = function()
{
var prnt = this.dragContainer;
prnt.ShowAsTT(false);
}
div.TTGetID = function()
{
return (this.dragContainer.m_noteID);
}
div.TTIsSame = function(other)
{
return (this.TTGetID() == other.TTGetID());
}
div.TTInBounds = function(x,y)
{
var prnt = this.dragContainer;
var frmWrapTD = prnt.m_expObj;
var rc = new Rect(g_dc.getDocY(frmWrapTD),
g_dc.getDocX(frmWrapTD),
toInt(frmWrapTD.offsetWidth),
toInt(frmWrapTD.offsetHeight));
return rc.isPtWithin(x,y);
}
return div;
}
NoteObject.prototype.ShowAsTT = function(bShow)
{
if (bShow)
{
g_dc.showElem(this.m_expObj, true);
var bar = g_dc.GetObjInnerByName(this.m_expObj, "noteIconDivTop")[0];
var rz = g_dc.GetObjInnerByName(this.m_expObj, "resizeHandle")[0];
g_dc.showElem(bar, false);
g_dc.showElem(rz, false);
g_dc.maxZ(this.m_expObj);
}
else
{
g_dc.showElem(this.m_expObj,false);
var bar = g_dc.GetObjInnerByName(this.m_expObj, "noteIconDivTop")[0];
var rz = g_dc.GetObjInnerByName(this.m_expObj, "resizeHandle")[0];
g_dc.showElem(bar, true);
g_dc.showElem(rz, true);
}
}
NoteObject.prototype.CreateResizeHandles = function()
{
this.m_resizeHandle = g_dc.CreateResizeHandleObj();
this.m_expObj.appendChild(this.m_resizeHandle);
this.m_resizeHandle.dragContainer = this;
}
NoteObject.prototype.DragElem = function(diffX,diffY)
{
return this.MoveBy(diffX, diffY);
}
NoteObject.prototype.Show = function()
{
if (!this.m_isIcn)
{
g_dc.showElem(this.m_expObj, true);
g_dc.showElem(this.m_icnObj, false);
}
else
{
g_dc.showElem(this.m_expObj, false);
g_dc.showElem(this.m_icnObj, true);
}
}
NoteObject.prototype.GetXmlChanges = function()
{
var bNew = (this.m_noteID.indexOf("newNote")>=0);
if (bNew && this.m_deleted)
return "";
var str = "";
return str;
}
var bDirty = false;
if (this.m_origW!=this.m_width)
{
str+="width='"+ this.m_width +"' ";
bDirty=true;
this.m_origW = this.m_width;
}
if (this.m_origH!=this.m_height)
{
str+="height='"+ this.m_height +"' ";
bDirty=true;
this.m_origH = this.m_height;
}
var wa = g_dc.GetWorkAreaRC();
if (this.m_origxPos!=this.m_posX)
{
str+="xPos='"+ (this.m_posX-wa.m_left) +"' ";
bDirty=true;
this.m_origxPos = this.m_posX;
}
if (this.m_origyPos!=this.m_posY)
{
str+="yPos='"+ (this.m_posY-wa.m_top) +"' ";
bDirty=true;
this.m_origyPos = this.m_posY;
}
if (this.m_origIsIcn!=this.m_isIcn)
{
str+="isIcn='"+ (this.m_isIcn?'1':'0') +"' ";
bDirty=true;
this.m_origIsIcn = this.m_isIcn;
}
curTxt = this.Edit_getText();
if (this.m_origTxt!=curTxt)
{
str+="txt='"+ encodeURIComponent(HtmlEncode(curTxt)) +"' ";
bDirty=true;
this.m_origTxt = curTxt;
}
if (!bDirty)
return "";
str+="/>";
return str;
}
NoteObject.prototype.SetSelected = function(bSel)
{
if (this.m_selected==bSel)
return;
this.m_selected=bSel;
if (this.m_isIcn)
{
var btnDiv = g_dc.GetObjInnerByName(this.m_icnObj, "clipIconDivTop")[0];
btnDiv.style.visibility=bSel?"visible":"hidden";
this.maximizeZ();
}
else
{
var btnDiv = g_dc.GetObjInnerByName(this.m_expObj, "noteIconDivTop")[0];
btnDiv.style.visibility=bSel?"visible":"hidden";
var rz = g_dc.GetObjInnerByName(this.m_expObj, "resizeHandle")[0];
rz.style.visibility=bSel?"visible":"hidden";
this.maximizeZ();
}
}
NoteObject.prototype.maximizeZ = function()
{
try{
g_dc.maxZ(this.m_expObj);
g_dc.maxZ(this.m_icnObj);
}
catch(err){
alert(err.description);
}
}
NoteObject.prototype.ToIcon = function(bIcn)
{
rc = this.GetCurrRC();
this.m_isIcn = bIcn;
if (bIcn)
{
var icnrc = this.CalcIcnRC(rc);
this.MoveTo(icnrc.m_left, icnrc.m_top);
g_dc.Select(this);
}
else
{
var expndRc = this.CalcExpndRC(rc);
this.MoveTo(expndRc.m_left, expndRc.m_top);
//this.m_recalcIconPos = false;
g_dc.Select(this);
}
this.Show();
g_dc.setDirty(true);
}
NoteObject.prototype.CalcIcnRC = function(rc)
{
var incwidth = toInt(this.m_icnObj.style.width);
var incheight = toInt(this.m_icnObj.style.height);
var left = rc.m_left + Math.round((rc.m_width - incwidth)/2);
var top = rc.m_top + Math.round((rc.m_height - incheight)/2);
var rcret = new Rect(top, left, incwidth, incheight);
return rcret;
}
NoteObject.prototype.CalcExpndRC = function(rc)
{
var expdWidth = toInt(this.m_expObj.style.width);
var expdHeight = toInt(this.m_expObj.style.height);
var left = rc.m_left - Math.round((expdWidth - rc.m_width)/2);
var top = rc.m_top - Math.round((expdHeight - rc.m_height)/2);
top = Math.max(top,g_dc.getScrollY());
var rcret = new Rect(top, left, expdWidth, expdHeight);
return rcret;
}
NoteObject.prototype.InitClipButton = function(nm, hndlr, prnt)
{
var btn = g_dc.GetObjInnerByName(prnt, nm)[0];
btn.onclick = eval("g_eventRouter."+hndlr);
btn.onmousedown = g_eventRouter.onBtnMouseDown;
btn.onmouseup = g_eventRouter.onBtnMouseUp;
btn.dragContainer = this;
}
NoteObject.prototype.MoveBy = function(dx,dy)
{
var retarr = new Array();
retarr['xresidue']=0;
retarr['yresidue']=0;
if (!(this.m_expObj) || !(this.m_icnObj)) {alert('error11');return;}
var newLeft = (toInt(this.currObj().style.left)+dx);
var newTop = (toInt(this.currObj().style.top)+dy);
var pos = new Rect( newTop,
newLeft,
this.currObj().style.width,
this.currObj().style.height);
pos.SnapTopLeft(6, (dx<0), (dy<0));
this.FixPos(pos);
retarr['xresidue']=dx-(pos.m_left-toInt(this.currObj().style.left));
retarr['yresidue']=dy-(pos.m_top-toInt(this.currObj().style.top));
this.currObj().style.left = pos.m_left+'px';
this.currObj().style.top = pos.m_top+'px';
this.m_posX=pos.m_left;
this.m_posY=pos.m_top;
if (!this.m_isIcn)
this.m_recalcIconPos=true;
g_dc.setDirty(true);
return retarr;
}
NoteObject.prototype.currObj = function()
{
return (!this.m_isIcn)?this.m_expObj:this.m_icnObj;
}
NoteObject.prototype.GetCurrRC = function(obj)
{
tgObj = (typeof(obj)!=dd_u)?obj:this.currObj();
return new Rect(toInt(tgObj.style.top),
toInt(tgObj.style.left),
toInt(tgObj.style.width),
toInt(tgObj.style.height));
}
NoteObject.prototype.FixPos = function(rc, maxW, maxH, minW, minH)
{
return g_dc.FixPos(rc, "workingArea", maxW, maxH, minW, minH);
}
NoteObject.prototype.MoveTo = function(x,y, obj, bRecord)
{
if (!(this.m_expObj) || !(this.m_icnObj)) {alert('error10');return;}
currRC = this.GetCurrRC(obj);
currRC.m_left = x;
currRC.m_top = y;
this.FixPos(currRC);
tgObj = (typeof(obj)!=dd_u)?obj:this.currObj();
tgObj.style.left = currRC.m_left+'px';
tgObj.style.top = currRC.m_top+'px';
if (typeof(bRecord)==dd_u || bRecord==true)
{
this.m_posX=currRC.m_left;
this.m_posY=currRC.m_top;
}
}
NoteObject.prototype.c_maxWidth = 800;
NoteObject.prototype.c_minWidth = 100;
NoteObject.prototype.c_minHeight = 10;
NoteObject.prototype.c_maxWidth = 800;
NoteObject.prototype.c_maxHeight = 300;
NoteObject.prototype.ResizeTo = function(w,h)
{
//debugger;
//if (this.m_isIcn)
// return;
w = Math.min(w, this.c_maxWidth);
w = Math.max(w, this.c_minWidth);
h = Math.min(h, this.c_maxHeight);
h = Math.max(h,this.c_minHeight);
this.m_expObj.style.width = w +'px';
var prevDisp = this.m_expObj.style.display;
this.m_expObj.style.display='block';
var diff = toInt(this.m_expObj.offsetWidth)-w;
this.m_expObj.style.display=prevDisp;
this.m_expObj.style.width = (w-diff) +'px';
var prevDisp = this.m_expObj.style.display;
this.m_expObj.style.display='block';
var heightReal = toInt(this.m_expObj.offsetHeight);
this.m_expObj.style.display=prevDisp;
this.m_width = w;
this.m_height = heightReal;
this.m_resizeHandle.style.left = (this.m_width-RES_HANDLE_HEADER_OFFSET_W)+"px";
this.m_resizeHandle.style.top = (this.m_height-RES_HANDLE_HEADER_OFFSET_H)+"px";
g_dc.setDirty(true);
}
NoteObject.prototype.ResizeToDiff = function(dw, dh)
{
try{
if (!(this.m_expObj)) {alert('error120');return;}
var rc = this.GetCurrRC();
var w = rc.m_width+dw;
var h = rc.m_height+dh;
this.ResizeTo(w, h);
}
catch(err)
{
alert(err);
}
}
///////////////////////////////////////////////////////////////
/// Edit Interface
NoteObject.prototype.Edit_getEditPosition = function()
{
var ret = this.GetCurrRC();
ret.m_top+=20;
//if (ret.m_width<200) ret.m_width=200;
return ret;
}
NoteObject.prototype.Edit_getText = function()
{
if (this.m_expObj)
return HtmlDecode(this.m_expObj.getElementsByTagName('span')[0].innerHTML);
return "";
}
NoteObject.prototype.Edit_setText = function(txt)
{
if (this.m_expObj)
this.m_expObj.getElementsByTagName('span')[0].innerHTML = HtmlEncode(txt);
g_dc.setDirty(true);
}
NoteObject.prototype.Edit_getFontFamily = function()
{
if (this.m_expObj)
return this.m_expObj.style.fontFamily;
return "";
}
NoteObject.prototype.Edit_getFontSize = function()
{
if (this.m_expObj)
return this.m_expObj.style.fontSize;
return "";
}
NoteObject.prototype.Edit_getFontWeight = function()
{
if (this.m_expObj)
return this.m_expObj.style.fontWeight;
return "";
}
NoteObject.prototype.Edit_getMaxChars = function()
{
return "2000";
}
NoteObject.prototype.Edit_getTextAlign = function()
{
return "left";
}
NoteObject.prototype.Edit_getPadding = function()
{
return "6px 6px 6px 6px";
}
// end Edit interface
//////////////////////////////////////////////////////////////////////