123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602 |
- XFormsBind.prototype = new XFormsElement;
- function XFormsBind (strParentId, strId, strTag, strRef, strCalculate, strConstraint, strReadonly, strRelevant, strRequired, strType, strScript)
- {
- if (!strId)
- {
- return;
- }
- XFormsElement.call(this, strParentId, strId, strTag);
-
- /**
- * Attribute
- */
- this.attribute["ref"] = strRef;
- this.attribute["calculate"] = strCalculate;
- this.attribute["constraint"] = strConstraint;
- this.attribute["readonly"] = strReadonly;
- this.attribute["relevant"] = strRelevant;
- this.attribute["required"] = strRequired;
- this.attribute["type"] = strType;
- this.attribute["script"] = strScript;
-
- this.bindExecute();
- };
- /**
- * bind 수식을 실행한다
- * @return
- */
- XFormsBind.prototype.bindExecute = function ()
- {
- if ("" != this.attribute["ref"])
- {
- var strBaseRef = this.attribute["ref"];
- var xlRefNode = model.getInstancePart(null, strBaseRef);
- if (null != xlRefNode)
- {
- for (var i=0; i<xlRefNode.length; i++)
- {
- if ("" != this.attribute["calculate"]) // calculate
- {
- if(1 == xlRefNode.length)
- {
- model.setValue(this.attribute["ref"], String(this.bindCalculate(this.transRefDot("calculate"))));
- }
- else
- {
- XmlLib.setTextValue(xlRefNode.item(i), String(this.bindCalculate(this.attribute["calculate"], xlRefNode.item(i))));
- }
- }
-
- if ("" != this.attribute["constraint"]) // constraint
- {
- var nConstraintValue;
- if( 1 == xlRefNode.length)
- {
- var nConstraintValue = this.bindCalculate(this.transRefDot("calculate"));
- }
- else
- {
- var nConstraintValue = this.bindCalculate(this.attribute["calculate"], xlRefNode.item(i));
- }
- var bBindBoolValue = ("0" != nConstraintValue && "false" != nConstraintValue && "" != nReadonlyValue) ? true : false;
- if (bBindBoolValue)
- {
- var arKeyset = document.allElement.keys();
- for (var j=0; j<arKeyset; j++)
- {
- var strChildName = arKeyset[j];
- var objChild = document.allElement.item(strChildName);
- if (!(objChild instanceof XFormsBind))
- {
- if (this.attribute["ref"] == objChild.attribute["ref"])
- {
- if (this.booleanCheckType(this.attribute["type"], this.attribute["ref"]))
- {
- objChild.dispatch("xforms-valid");
- }
- else
- {
- objChild.dispatch("xforms-invalid");
- }
- }
- }
- }
- }
- else
- {
- var arKeyset = document.allElement.keys();
- for (var j=0; j<arKeyset.length; j++)
- {
- var strChildName = arKeyset[j];
- var objChild = document.allElement.item(strChildName);
- if (!(objChild instanceof XFormsBind))
- {
- if (this.attribute["ref"] == objChild.attribute["ref"])
- {
- objChild.dispatch("xforms-invalid");
- }
- }
- }
- }
- }
-
- if ("" != this.attribute["readonly"]) // readonly
- {
- var nReadonlyValue;
- if( 1 == xlRefNode.length)
- {
- var nReadonlyValue = this.bindCalculate(this.transRefDot("readonly"));
- }
- else
- {
- var nReadonlyValue = this.bindCalculate(this.attribute["readonly"], xlRefNode.item(i));
- }
- if ("0" != nReadonlyValue && "false" != nReadonlyValue && "" != nReadonlyValue)
- {
- var arKeyset = document.allElement.keys();
- for (var j=0; j<arKeyset.length; j++)
- {
- var strChildName = arKeyset[j];
- var objChild = document.allElement.item(strChildName);
- if (!(objChild instanceof XFormsBind))
- {
- if (this.attribute["ref"] == objChild.attribute["ref"])
- {
- objChild.dispatch("xforms-readonly");
- objChild.setDisabled(true);
- }
- }
- }
- }
- else
- {
- var arKeyset = document.allElement.keys();
- for (var j=0; j<arKeyset.length; j++)
- {
- var strChildName = arKeyset[j];
- var objChild = document.allElement.item(strChildName);
- if (!(objChild instanceof XFormsBind))
- {
- if (this.attribute["ref"] == objChild.attribute["ref"])
- {
- objChild.dispatch("xforms-readwrite");
- objChild.setDisabled(false);
- }
- }
- }
- }
- }
-
- if ("" != this.attribute["relevant"]) //relevant
- {
- var nRelevantValue;
- if( 1 == xlRefNode.length)
- {
- var nRelevantValue = this.bindCalculate(this.transRefDot("relevant"));
- }
- else
- {
- var nRelevantValue = this.bindCalculate(this.attribute["relevant"], xlRefNode.item(i));
- }
- if ("0" != nRelevantValue && "false" != nRelevantValue && "" != nReadonlyValue)
- {
- var arKeyset = document.allElement.keys();
- for (var j=0; j<arKeyset.length; j++)
- {
- var strChildName = arKeyset[j];
- var objChild = document.allElement.item(strChildName);
- if (!(objChild instanceof XFormsBind))
- {
- if (this.attribute["ref"] == objChild.attribute["ref"])
- {
- objChild.setVisible(true);
- }
- }
- }
- }
- else
- {
- var arKeyset = document.allElement.keys();
- for (var j=0; j<arKeyset.length; j++)
- {
- var strChildName = arKeyset[j];
- var objChild = document.allElement.item(strChildName);
- if (!(objChild instanceof XFormsBind))
- {
- if (this.attribute["ref"] == objChild.attribute["ref"])
- {
- objChild.setVisible(false);
- }
- }
- }
- }
- }
-
- if ("" != this.attribute["required"]) // required
- {
- var nRequiredValue;
- if( 1 == xlRefNode.length)
- {
- var nRequiredValue = this.bindCalculate(this.transRefDot("required"));
- }
- else
- {
- var nRequiredValue = this.bindCalculate(this.attribute["required"], xlRefNode.item(i));
- }
- var bBindBoolValue = ("0" != nRequiredValue && "false" != nRequiredValue && "" != nReadonlyValue) ? true : false;
- if (bBindBoolValue)
- {
- var arKeyset = document.allElement.keys();
- for (var j=0; j<arKeyset.length; j++)
- {
- var strChildName = arKeyset[j];
- var objChild = document.allElement.item(strChildName);
- if (!(objChild instanceof XFormsBind))
- {
- if (this.attribute["ref"] == objChild.attribute["ref"])
- {
- if (null != objChild.attribute["required"] && objChild.attribute["required"])
- {
- objChild.dispatch("xforms-required");
- }
- else if (null != objChild.attribute["required"] && !objChild.attribute["required"])
- {
- objChild.dispatch("xforms-optional");
- }
- }
- }
- }
- }
- }
- }
- }
- this.attribute["ref"] = strBaseRef;
- if ("" != this.attribute["script"]) //script
- {
- try
- {
- window.eval(this.attribute["script"]);
- }
- catch (e)
- {
- return ;
- }
- }
- }
- };
- XFormsBind.prototype.transRefDot = function (strBindAttribute)
- {
- var strRef = this.attribute["ref"];
- var strBindValue = this.attribute[strBindAttribute];
- strRef = strRef.substring(0, strRef.lastIndexOf("/")+1);
- strBindValue = strBindValue.replace(/\.\.\//g, strRef);
- return strBindValue;
- };
- /**
- * Calculate 함수 구현
- * @return
- */
- XFormsBind.prototype.bindCalculate = function (strBindAttribute, xnNode)
- {
- return xPathOperation(strBindAttribute, xnNode);
- };
- XFormsBind.prototype.booleanCheckType = function (strType, strRef)
- {
- var strValue = model.getValue(strRef);
- switch (strType)
- {
- case "xsd:anyURI":
- {
- return true;
- break;
- }
- case "xsd:base64Binary":
- {
- break;
- }
- case "xsd:boolean":
- {
- if ("true" == strValue || "1" == strValue)
- {
- return true;
- }
- else
- {
- return false;
- }
- break;
- }
- case "xsd:byte":
- {
- if ("" != strValue)
- {
- return true;
- }
- else
- {
- return false;
- }
- break;
- }
- case "xsd:date":
- {
- break;
- }
- case "xsd:dateTime":
- {
- break;
- }
- case "xsd:decimal":
- {
- break;
- }
- case "xsd:double":
- {
- if (Number (strValue))
- {
- return true;
- }
- else
- {
- return false;
- }
- break;
- }
- case "xsd:float":
- {
- if (Number (strValue))
- {
- return true;
- }
- else
- {
- return false;
- }
- break;
- }
- case "xsd:gDay":
- {
- break;
- }
- case "xsd:gMonth":
- {
- break;
- }
- case "xsd:gMonthDay":
- {
- break;
- }
- case "xsd:gYear":
- {
- break;
- }
- case "xsd:gYearMonth":
- {
- break;
- }
- case "xsd:hexBinary":
- {
- break;
- }
- case "xsd:int":
- {
- if (Number (strValue))
- {
- return true;
- }
- else
- {
- return false;
- }
- break;
- }
- case "xsd:integer":
- {
- if (Number (strValue))
- {
- return true;
- }
- else
- {
- return false;
- }
- break;
- }
- case "xsd:long":
- {
- if (Number (strValue))
- {
- return true;
- }
- else
- {
- return false;
- }
- break;
- }
- case "xsd:negativeInteger":
- {
- break;
- }
- case "xsd:nonNegativeInteger":
- {
- break;
- }
- case "xsd:nonPositiveInteger":
- {
- break;
- }
- case "xsd:positiveInteger":
- {
- break;
- }
- case "xsd:short":
- {
- break;
- }
- case "xsd:string":
- {
- if ("" != String(strValue))
- {
- if (!Number (strValue))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- break;
- }
- case "xsd:time":
- {
- break;
- }
- case "xsd:unsignedByte":
- {
- break;
- }
- case "xsd:unsignedInt":
- {
- break;
- }
- case "xsd:unsignedLong":
- {
- break;
- }
- case "xsd:unsignedShort":
- {
- break;
- }
- default :
- {
- return true;
- break;
- }
- }
- };
- XFormsBind.prototype.setAttribute = function (strName, objValue)
- {
- XFormsElement.prototype.setAttribute.call(this, strName, objValue);
- switch (strName)
- {
- case "ref":
- {
- this.attribute["ref"] = objValue;
- break;
- }
- case "calculate":
- {
- this.attribute["calculate"] = objValue;
- break;
- }
- case "constraint":
- {
- this.attribute["constraint"] = objValue;
- break;
- }
- case "readonly":
- {
- this.attribute["readonly"] = objValue;
- break;
- }
- case "relevant":
- {
- this.attribute["relevant"] = objValue;
- break;
- }
- case "required":
- {
- this.attribute["required"] = objValue;
- break;
- }
- case "type":
- {
- this.attribute["type"] = objValue;
- break;
- }
- case "script":
- {
- this.attribute["script"] = objValue;
- break;
- }
- }
- };
- // TODO createChild 구현중 2011. 03. 15. 박현우 /////////////////////////////////////////////////////////////////////////////////////
- XFormsBind.create = function (strParentId, clAttribute, strStyle)
- {
- // // 메인노드 생성
- // var objBind = XFormsModel.createMainNode(clAttribute);
- // var xnParent = document.getElementById("HE_"+strParentId);
- // xnParent.appendChild(objBind);
- //
- // objBind = XFormsModel.createSubNodes(objBind, clAttribute);
- // // object 생성
- var xnBind = null;
- return XFormsBind.createObject(strParentId, xnBind, clAttribute, strStyle);
- };
- XFormsBind.createObject = function (strParentId, xnBind, clAttribute, strStyle)
- {
- var strId = "";
- var strTag = "xforms:bind";
- var strCalculate = "";
- var strConstraint = "";
- var strReadOnly = "";
- var strRef = "";
- var strRelevant = "";
- var strType = "";
- var strScript = "";
- var strUserDefineAttrib = "";
-
- for (var i=0; i<clAttribute.count(); i++)
- {
- var strAttributeName = clAttribute.keys()[i];
- switch (strAttributeName)
- {
- case "id" :
- {
- strId = clAttribute.item(strAttributeName);
- break;
- }
- case "calculate" :
- {
- strCalculate = clAttribute.item(strAttributeName);
- break;
- }
- case "constraint" :
- {
- strConstraint = clAttribute.item(strAttributeName);
- break;
- }
- case "readonly" :
- {
- strReadOnly = clAttribute.item(strAttributeName);
- break;
- }
- case "ref" :
- {
- strRef = clAttribute.item(strAttributeName);
- break;
- }
- case "relevant" :
- {
- strRelevant = clAttribute.item(strAttributeName);
- break;
- }
- case "type" :
- {
- strType = clAttribute.item(strAttributeName);
- break;
- }
- case "script" :
- {
- strScript = clAttribute.item(strAttributeName);
- break;
- }
- default :
- {
- if (!STYLE_LIST[strAttributeName])
- {
- strUserDefineAttrib += strAttributeName + ":" + clAttribute.item(strAttributeName) + "; ";
- }
- break;
- }
- }
- }
- var objBind = new XFormsBind(strParentId, strId, strTag, strRef, strCalculate, strConstraint, strReadOnly, strRelevant, strRequired, strType, strScript, strUserDefineAttrib);
- return objBind;
- };
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|