MWF.xApplication.process.FormDesigner.widget = MWF.xApplication.process.FormDesigner.widget || {};
MWF.require("MWF.widget.UUID", null, false);
MWF.xApplication.process.FormDesigner.widget.ValidationEditor = new Class({
Implements: [Options, Events],
Extends: MWF.widget.Common,
options: {
"style": "default",
"maxObj": document.body
},
initialize: function(node, designer, options){
this.setOptions(options);
this.node = $(node);
this.designer = designer;
this.path = "../x_component_process_FormDesigner/widget/$ValidationEditor/";
this.cssPath = "../x_component_process_FormDesigner/widget/$ValidationEditor/"+this.options.style+"/css.wcss";
this._loadCss();
this.items = [];
},
load: function(data){
this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.designer.lp.validation.validation}).inject(this.node);
this.editorNode = new Element("div", {"styles": this.css.editorNode}).inject(this.node);
this.actionNode = new Element("div", {"styles": this.css.actionNode}).inject(this.node);
this.listNode = new Element("div", {"styles": this.css.listNode}).inject(this.node);
this.loadEditorNode();
this.loadActionNode();
this.loadListNode(data);
},
loadEditorNode: function(){
//this.statusNode = new Element("div", {"styles": this.css.statusNode}).inject(this.editorNode);
//this.conditionNode = new Element("div", {"styles": this.css.conditionNode}).inject(this.editorNode);
//this.valueNode = new Element("div", {"styles": this.css.valueNode}).inject(this.editorNode);
//this.promptNode = new Element("div", {"styles": this.css.promptNode}).inject(this.editorNode);
var html = "
";
this.editorNode.set("html", html);
var tds = this.editorNode.getElements("td").setStyles(this.css.editTableTdValue);
this.loadStatus(tds);
this.loadConditions(tds);
this.loadPrompt(tds);
},
loadStatus: function(tds){
var html = "";
tds[0].set("html", html);
var inputs = tds[0].getElements("input");
var randomId = new MWF.widget.UUID().toString();
inputs[0].set("name", "condition"+randomId);
inputs[1].set("name", "condition"+randomId);
inputs[2].setStyles(this.css.decisionNameInput);
this.decisionInputNode = inputs[2];
this.statusRadioNodes = inputs;
this.statusRadioNodes.pop();
this.decisionInputNode.addEvents({
"focus": function(){
if (this.decisionInputNode.get("value")==this.designer.lp.validation.decisionName) this.decisionInputNode.set("value", "");
}.bind(this),
"blur": function(){
if (!this.decisionInputNode.get("value")) this.decisionInputNode.set("value", this.designer.lp.validation.decisionName);
}.bind(this)
});
},
loadConditions: function(tds){
var html = "";
tds[1].set("html", html);
var selects = tds[1].getElements("select");
selects.setStyles(this.css.valueSelect);
this.valueTypeSelectNode = selects[0];
this.operateorSelectNode = selects[1];
this.valueInputNode = tds[1].getElement("input").setStyles(this.css.valueInput);
this.operateorSelectNode.addEvent("change", function(){
var v = this.operateorSelectNode.options[this.operateorSelectNode.selectedIndex].value;
if (v && (v!="isnull") && (v!="notnull")){
this.valueInputNode.setStyle("display", "inline");
}else{
this.valueInputNode.setStyle("display", "none");
}
}.bind(this));
this.valueInputNode.addEvents({
"focus": function(){
if (this.valueInputNode.get("value")==this.designer.lp.validation.valueInput) this.valueInputNode.set("value", "");
}.bind(this),
"blur": function(){
if (!this.valueInputNode.get("value")) this.valueInputNode.set("value", this.designer.lp.validation.valueInput);
}.bind(this)
});
},
loadPrompt: function(tds){
var html = "";
tds[2].set("html", html);
tds[2].getElements("td")[0].setStyles(this.css.titleTd);
this.promptInputNode = tds[2].getElement("input").setStyles(this.css.promptInput);
},
loadActionNode: function(){
this.actionAreaNode = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.actionNode);
this.addAction = new Element("div", {"styles": this.css.addAction, "text": this.designer.lp.validation.add}).inject(this.actionAreaNode);
this.modifyAction = new Element("div", {"styles": this.css.modifyAction_disabled, "text": this.designer.lp.validation.modify}).inject(this.actionAreaNode);
this.addAction.addEvent("click", function(){
this.addValidation();
}.bind(this));
this.modifyAction.addEvent("click", function(){
this.modifyValidation();
}.bind(this));
},
getData: function(){
var status = this.getStatusValue();
var decision = this.decisionInputNode.get("value");
var valueType = this.valueTypeSelectNode.options[this.valueTypeSelectNode.selectedIndex].value;
var operateor = this.operateorSelectNode.options[this.operateorSelectNode.selectedIndex].value;
var value = this.valueInputNode.get("value");
var prompt = this.promptInputNode.get("value");
if (decision == this.designer.lp.validation.decisionName) decision = "";
if (value == this.designer.lp.validation.valueInput) value = "";
return {
"status": status,
"decision": decision,
"valueType": valueType,
"operateor": operateor,
"value": value,
"prompt": prompt
};
},
addValidation: function(){
this.hideErrorNode();
var data = this.getData();
if (data.status!="all"){
if (!data.decision || data.decision==this.designer.lp.validation.decisionName){
this.showErrorNode(this.designer.lp.validation.inputDecisionName);
return false;
}
}
if (data.operateor!="isnull" && data.operateor!="notnull"){
if (!data.value || data.value==this.designer.lp.validation.valueInput){
this.showErrorNode(this.designer.lp.validation.inputValue);
return false;
}
}
if (!data.prompt){
this.showErrorNode(this.designer.lp.validation.inputPrompt);
return false;
}
var item = new MWF.xApplication.process.FormDesigner.widget.ValidationEditor.Item(data, this);
this.items.push(item);
item.selected();
this.fireEvent("change");
},
showErrorNode: function(text){
this.errorNode = new Element("div", {"styles": this.css.errorNode}).inject(this.actionNode, "before");
this.errorTextNode = new Element("div", {"styles": this.css.errorTextNode}).inject(this.errorNode);
this.errorTextNode.set("text", text);
this.errorNode.addEvent("click", function(){this.hideErrorNode();}.bind(this));
},
hideErrorNode: function(){
if (this.errorNode) this.errorNode.destroy();
},
getStatusValue: function(){
for (var i=0; i