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