add UploadBehaviorRequestModel in pluginModel.js add uploadBehavior

function in pluin-new.js
This commit is contained in:
zhengyingying 2014-03-24 13:39:52 +08:00
parent 86ae689d2b
commit 23fb96dafd
2 changed files with 131 additions and 204 deletions

View File

@ -178,10 +178,7 @@ function showMethodDocument(selectedNode) {
$(div[behaviorIndex]).attr("class", "show");
$(div[behaviorIndex]).show();
for (var i = 0; i < length; i++) {
// alert("i is "+i);
// alert("id is "+div[i].getAttribute("id"));
if (div[i].getAttribute("id") != behaviorIndex) {
// alert(div[i].getAttribute("id")+"!="+behaviorIndex);
$(div[i]).hide();
}
}
@ -220,10 +217,13 @@ function loadMethodParams(behaviorData, behaviorIndex) {
methodParams[j].fieldSeperator,
methodParams[j].paramType,
methodParams[j].methodParamProperties);
var methodParamProperties=new Array();
for(var q=0;q<methodParamModel.methodParamProperties.length;q++){
var methodParamPropertyModel=new MethodParamPropertyModel(methodParamModel.methodParamProperties[q].key,methodParamModel.methodParamProperties[q].value);
methodParamProperties.push(methodParamPropertyModel);
var methodParamProperties = new Array();
for (var q = 0; q < methodParamModel.methodParamProperties.length; q++) {
var methodParamPropertyModel = new MethodParamPropertyModel(
methodParamModel.methodParamProperties[q].key,
methodParamModel.methodParamProperties[q].value);
methodParamProperties
.push(methodParamPropertyModel);
}
var type = methodParamModel.paramType;
var size = 0, cols = "", rows = "";
@ -254,7 +254,7 @@ function loadMethodParams(behaviorData, behaviorIndex) {
fieldHTML += createCheckBox(methodParamModel,
rows, behaviorIndex);
}
//alert(fieldHTML);
// alert(fieldHTML);
}
boxHeader = "<div class='box-header well ' data-original-title> "
@ -283,7 +283,7 @@ function createField(label, name, size, behaviorIndex) {
if (size == 0) {
size = 20;
}
var result=document.createElement("div");
var result = document.createElement("div");
var divNode = document.createElement("div");
var p = document.createElement("p");
var labelNode = document.createTextNode(label);
@ -293,10 +293,10 @@ function createField(label, name, size, behaviorIndex) {
$(divNode).attr("class", "Field sample_frame");
$(divNode).attr("id", behaviorIndex + "_" + name);
$(div).attr("class","sample_sub_frame");
$(input).attr("type","text");
$(input).attr("size",size);
$(input).attr("id",name+"_input");
$(div).attr("class", "sample_sub_frame");
$(input).attr("type", "text");
$(input).attr("size", size);
$(input).attr("id", name + "_input");
p.appendChild(labelNode);
div.appendChild(nameNode);
@ -312,26 +312,27 @@ function createMultiField(label, name, size, behaviorIndex) {
if (size == 0) {
size = 20;
}
var result=document.createElement("div");
var divNode=document.createElement("div");
var p=document.createElement("p");
var labelNode=document.createTextNode(name+":"+label);
var div=document.createElement("div");
var addFieldButton=document.createElement("button");
var addFieldNode=document.createTextNode("Add Field");
var removeFieldButton=document.createElement("button");
var removeFieldNode=document.createTextNode("RemoveAll");
var br=document.createElement("br");
var table=document.createElement("table");
var result = document.createElement("div");
var divNode = document.createElement("div");
var p = document.createElement("p");
var labelNode = document.createTextNode(name + ":" + label);
var div = document.createElement("div");
var addFieldButton = document.createElement("button");
var addFieldNode = document.createTextNode("Add Field");
var removeFieldButton = document.createElement("button");
var removeFieldNode = document.createTextNode("RemoveAll");
var br = document.createElement("br");
var table = document.createElement("table");
$(divNode).attr("class","MultiField sample_frame");
$(divNode).attr("id", behaviorIndex+ "_"+ name);
$(div).attr("class","sample_sub_frame");
$(addFieldButton).attr("type","submit");
$(addFieldButton).attr("onClick","addField("+ size+ ","+ behaviorIndex+ ");");
$(removeFieldButton).attr("type","submit");
$(removeFieldButton).attr("onClick","removeField()");
$(table).attr("id","addFieldTable_"+behaviorIndex);
$(divNode).attr("class", "MultiField sample_frame");
$(divNode).attr("id", behaviorIndex + "_" + name);
$(div).attr("class", "sample_sub_frame");
$(addFieldButton).attr("type", "submit");
$(addFieldButton).attr("onClick",
"addField(" + size + "," + behaviorIndex + ");");
$(removeFieldButton).attr("type", "submit");
$(removeFieldButton).attr("onClick", "removeField(this)");
$(table).attr("id", "addFieldTable_" + behaviorIndex);
p.appendChild(labelNode);
addFieldButton.appendChild(addFieldNode);
@ -385,13 +386,19 @@ function deleteField(selectedNode) {
parentNode.removeChild(deletedNode);
}
function removeField(selectedNode) {
var table = selectedNode.nextSibling.nextSibling;
var tableId = $(table).attr("id");
document.getElementById(tableId).innerHTML = "";
}
// 创建一个Table域
function createTable(methodParamModel, cols, behaviorIndex) {
var name = methodParamModel.name;
var label = methodParamModel.lable;
var valueSeperator = methodParamModel.valueSeperator;
var table_content = cols.split(valueSeperator);
//创建Table head
// 创建Table head
var tr = document.createElement("tr");
for (var i = 0; i < table_content.length; i++) {
var th = document.createElement("th");
@ -399,40 +406,39 @@ function createTable(methodParamModel, cols, behaviorIndex) {
th.appendChild(text);
tr.appendChild(th);
}
//创建一行
// 创建一行
var tr_content = document.createElement("tr");
for(var j=0;j<table_content.length;j++){
for (var j = 0; j < table_content.length; j++) {
var td_content = document.createElement("td");
var text_content = document.createElement("input");
text_content.setAttribute("type", "text");
td_content.appendChild(text_content);
tr_content.appendChild(td_content);
}
var result=document.createElement("div");
var divNode=document.createElement("div");
var p=document.createElement("p");
var labelNode=document.createTextNode(label);
var div=document.createElement("div");
var nameNode=document.createTextNode(name+":");
var br1=document.createElement("br");
var br2=document.createElement("br");
var addColButton=document.createElement("button");
var addColNode=document.createTextNode("addCol");
var removeColButton=document.createElement("button");
var removeColNode=document.createTextNode("removeCol");
var table=document.createElement("table");
var thead=document.createElement("thead");
var tbody=document.createElement("tbody");
var result = document.createElement("div");
var divNode = document.createElement("div");
var p = document.createElement("p");
var labelNode = document.createTextNode(label);
var div = document.createElement("div");
var nameNode = document.createTextNode(name + ":");
var br1 = document.createElement("br");
var br2 = document.createElement("br");
var addColButton = document.createElement("button");
var addColNode = document.createTextNode("addCol");
var removeColButton = document.createElement("button");
var removeColNode = document.createTextNode("removeCol");
var table = document.createElement("table");
var thead = document.createElement("thead");
var tbody = document.createElement("tbody");
divNode.setAttribute("class", "Table sample_frame");
divNode.setAttribute("id", behaviorIndex+ "_"+ name);
divNode.setAttribute("id", behaviorIndex + "_" + name);
div.setAttribute("class", "sample_sub_frame");
addColButton.setAttribute("type", "submit");
addColButton.setAttribute("onClick", "addCol(this)");
removeColButton.setAttribute("type", "submit");
removeColButton.setAttribute("onClick", "removeCol(this)");
table.setAttribute("class", behaviorIndex+"_operateTableCols");
table.setAttribute("class", behaviorIndex + "_operateTableCols");
p.appendChild(labelNode);
addColButton.appendChild(addColNode);
@ -455,8 +461,8 @@ function createTable(methodParamModel, cols, behaviorIndex) {
}
function addCol(selectedNode) {
var tbody=selectedNode.nextSibling.nextSibling.nextSibling.lastChild;
var length=tbody.previousSibling.firstChild.childNodes.length;
var tbody = selectedNode.nextSibling.nextSibling.nextSibling.lastChild;
var length = tbody.previousSibling.firstChild.childNodes.length;
var tr = document.createElement("tr");
for (var i = 0; i < length; i++) {
var td = document.createElement("td");
@ -468,8 +474,8 @@ function addCol(selectedNode) {
}
function removeCol(selectedNode) {
var tbody=selectedNode.nextSibling.nextSibling.lastChild;
var removeNode=tbody.lastChild;
var tbody = selectedNode.nextSibling.nextSibling.lastChild;
var removeNode = tbody.lastChild;
tbody.removeChild(removeNode);
}
@ -480,30 +486,34 @@ function createCheckBox(methodParamModel, rows, behaviorIndex) {
var valueSeperator = methodParamModel.valueSeperator;
var cb_content = rows.split(valueSeperator);
var result=document.createElement("div");
var result = document.createElement("div");
var divNode = document.createElement("div");
var p = document.createElement("p");
var div = document.createElement("div");
var br = document.createElement("br");
var divInput = document.createElement("div");
var labelNode = document.createTextNode(label);
var nameNode = document.createTextNode(name+":");
var nameNode = document.createTextNode(name + ":");
divNode.setAttribute("class", "CheckBox sample_frame");
divNode.setAttribute("id", behaviorIndex + "_" + name);
divNode.setAttribute("id", "checkbox_" + name + "_" + behaviorIndex);
div.setAttribute("class", "sample_sub_frame");
p.appendChild(labelNode);
div.appendChild(nameNode);
div.appendChild(br);
for (var i = 0; i < cb_content.length; i++) {
var checkBoxNode = document.createElement("input");
var brInput = document.createElement("br");
checkBoxNode.setAttribute("type", "checkbox");
checkBoxNode.setAttribute("name", "checkbox_" + name);
checkBoxNode.setAttribute("name", "checkbox_" + name + "_"
+ behaviorIndex);
checkBoxNode.setAttribute("value", cb_content[i]);
var checkBoxValue = document.createTextNode(cb_content[i]);
div.appendChild(checkBoxNode);
div.appendChild(checkBoxValue);
divInput.appendChild(checkBoxNode);
divInput.appendChild(checkBoxValue);
divInput.appendChild(brInput);
}
div.appendChild(nameNode);
div.appendChild(br);
div.appendChild(divInput);
divNode.appendChild(p);
divNode.appendChild(div);
result.appendChild(divNode);
@ -511,10 +521,6 @@ function createCheckBox(methodParamModel, rows, behaviorIndex) {
}
function removeField() {
$('#addFieldTable').empty();
}
$('#removeAllPlugin').click(function() {
document.getElementById('pluginArea').innerHTML = "";
});
@ -532,7 +538,7 @@ $('#behaviorCancel').click(function() {
});
function uploadBehavior(selectedNode) {
var uploadNode = selectNode.parentNode.previousSibling;
var uploadNode = selectedNode.parentNode.previousSibling;
var div = uploadNode.childNodes;
var length = div.length;
@ -543,107 +549,58 @@ function uploadBehavior(selectedNode) {
for (var i = 0; i < length; i++) {
var node = div[i];
if (node.Attr("class") == "Field sample_frame") {
alert("node=" + $(node).attr("class"));
if ($(node).attr("class") == "Field sample_frame") {
fieldList += $(node).find("input").val() + ",";
} else if (node.Attr("class") == "multiField sample_frame") {
var fieldNode = $(node.lastNode).find("table").children();
var fieldLength = fieldNode.length;
} else if ($(node).attr("class") == "MultiField sample_frame") {
var fieldNode = $(node).find("table").children();
var fieldLength = $(fieldNode).length;
for (var j = 0; j < fieldLength; j++) {
multiFieldList += $(fieldNode[j]).find("input").val() + ",";
}
// 多个multiField如何解决
} else if (node.Attr("class") == "Table sample_frame") {
} else if (node.Attr("class") == "CheckBox sample_frame") {
} else if ($(node).attr("class") == "Table sample_frame") {
var table = $(node).find("table");
var col = table.find("th").length;
var row = table.find("tbody").children().length;
alert("col=" + col + ",row=" + row);
var tbody = $(node).find("tbody");
for (var m = 0; m < row; m++) {
for (var n = 0; n < col; n++) {
var rowNode = $(tbody).children()[m];
var colNode = $(rowNode).children()[n];
var value = $(colNode).find("input").val();
tableList += value + ";";
}
}
var uploadBehavior = new UploadBehaviorRequestModel(tableList, checkList,
fieldList, multiFieldList);
upload(uploadBehavior);
}
function uploadBehavior1(selectNode) {
var uploadNode = selectNode.parentNode.parentNode;
var tableNum = 0;
var tableList = "";
var tableNode = new Array();
var checkList = "";
var fieldList = "";
var multiField = new Array();
var multiFieldList = "";
var multiFieldNum = 0;
var temp;
var childNode = new Array();
var length = uploadNode.children().length;
for (var i = 0; i < length; i++) {
childNode[i] = uploadNode.children()[i];
}
for (var j = 0; j < length; j++) {
var child = childNode[i];
if (child.Attr("class") == "Table") {
var table = child.find("div").find("table");
var col = table.find("tr");
var row = table.find("th").find("td");
tableNode[tableNum] = "";
for (var p = 1; p <= col; p++) {
for (var q = 0; q < row; q++) {
tableNode[tableNum] += $(table.children()[p].children()[q])
.val()
+ ",";
}
}
tableList += tableNode[tableNum] + ";";
tableNum++;
} else if (child.Attr("class") == "CheckBox") {
var chk_value = [];
$('input[name="checkbox_"' + child.attr("id") + ']:checked').each(
function() {
chk_value.push($(this).val());
} else if ($(node).attr("class") == "CheckBox sample_frame") {
var id = $(node).attr("id");
$('input[name=' + id + ']:checked').each(function() {
checkList += $(this).val() + ";";
});
var length = chk_value.length;
for (var p = 0; p < length; p++) {
checkList += chk_value[p] + ",";
}
}
} else if (child.Attr("class") == "Field") {
var input = child.find("div").find("input");
var value = $(input).val();
fieldList += value + ";";
} else if (child.Attr("class") == "MultiField") {
var table = child.find("div").find("table");
var length = table.children().length;
multiField[multiFieldNum] = "";
for (var p = 0; p < length; p++) {
temp = $(table.children()[p].children()[1]).val();
multiField[multiFieldNum] += temp + ";";
}
multiFieldList += multiField[multiFieldNum] + ";";
multiFieldNum++;
}
}
var uploadBehavior = new UploadBehaviorRequestModel(tableList, checkList,
fieldList, multiFieldList);
upload(uploadBehavior);
}
// 未完待续
function upload(uploadBehavior) {
$.ajax({
type : "POST",
url : "uploadBehavior",
contentType : "application/json",
data : JSON.stringify(uploadBehavior),
success : function(data) {
if (data.success)
alert("Congratulations! You have upload this behavior!");
else
alert(data.failedMessage);
},
error : function(request, status, error) {
}
});
var tableList = uploadBehavior.tableList;
var checkList = uploadBehavior.checkList;
var fieldList = uploadBehavior.fieldList;
var multiList = uploadBehavior.multiList;
alert("talbeList=" + tableList);
alert("checkList=" + checkList);
alert("fieldList=" + fieldList);
alert("multiList=" + multiList);
/*
* $.ajax({ type : "POST", url : "uploadBehavior", contentType :
* "application/json", data : JSON.stringify(uploadBehavior), success :
* function(data) { if (data.success) alert("Congratulations! You have
* upload this behavior!"); else alert(data.failedMessage); }, error :
* function(request, status, error) { } });
*/
}

View File

@ -13,40 +13,10 @@ function MethodParamPropertyModel(key,value){
this.key=key;
this.value=value;
}
// 创建一个ParamTypeModel对象
function ParamTypeModel(type, valueSeperator, fieldSeperator, size, rows, cols) {
this.type = type;
this.valueSeperator = valueSeperator;
this.fieldSeparator = fieldSeperator;
this.size = size;
this.rows = rows;
this.cols = cols;
}
// 创建一个Field对象
function Field(size, type, valueSeperator, fieldSeperator) {
this.size = size;
this.type = type;
this.valueSeperator = valueSeperator;
this.fieldSeparator = fieldSeperator;
}
// 创建一个MultiField对象
function MultiField(size, type, valueSeperator, fieldSeperator) {
this.size = size;
this.type = type;
this.valueSeperator = valueSeperator;
this.fieldSeparator = fieldSeperator;
}
// 创建一个Table对象
function Table(cols, type, valueSeperator, fieldSeperator) {
this.cols = cols;
this.type = type;
this.valueSeperator = valueSeperator;
this.fieldSeparator = fieldSeperator;
}
// 创建一个CheckBox对象
function CheckBox(rows, type, valueSeperator, fieldSeperator) {
this.rows = rows;
this.type = type;
this.valueSeperator = valueSeperator;
this.fieldSeparator = fieldSeperator;
//创建一个UploadBehaviorRequestModel对象
function UploadBehaviorRequestModel(tableList,checkList,fieldList,multiList){
this.tableList=tableList;
this.checkList=checkList;
this.fieldList=fieldList;
this.multiList=multiList;
}