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();
} }
} }
@ -222,8 +219,11 @@ function loadMethodParams(behaviorData, behaviorIndex) {
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 = "";
@ -328,9 +328,10 @@ function createMultiField(label, name, size, behaviorIndex) {
$(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",
"addField(" + size + "," + behaviorIndex + ");");
$(removeFieldButton).attr("type", "submit"); $(removeFieldButton).attr("type", "submit");
$(removeFieldButton).attr("onClick","removeField()"); $(removeFieldButton).attr("onClick", "removeField(this)");
$(table).attr("id", "addFieldTable_" + behaviorIndex); $(table).attr("id", "addFieldTable_" + behaviorIndex);
p.appendChild(labelNode); p.appendChild(labelNode);
@ -385,6 +386,12 @@ 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;
@ -424,7 +431,6 @@ function createTable(methodParamModel, cols, behaviorIndex) {
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");
@ -485,25 +491,29 @@ function createCheckBox(methodParamModel, rows, behaviorIndex) {
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 rowNode = $(tbody).children()[m];
var colNode = $(rowNode).children()[n];
var value = $(colNode).find("input").val();
tableList += value + ";";
} }
} }
} else if ($(node).attr("class") == "CheckBox sample_frame") {
var uploadBehavior = new UploadBehaviorRequestModel(tableList, checkList, var id = $(node).attr("id");
fieldList, multiFieldList); $('input[name=' + id + ']:checked').each(function() {
upload(uploadBehavior); checkList += $(this).val() + ";";
}
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());
}); });
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;
} }