plugin-new.js

This commit is contained in:
zhengyingying 2014-03-17 15:48:24 +08:00
parent 478c964f56
commit 331f05c4e7
3 changed files with 192 additions and 14 deletions

View File

@ -7,23 +7,30 @@ import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.JAXBException;
import org.apache.log4j.Logger;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.plugin.MethodParamModel;
import org.bench4q.share.models.master.plugin.PluginResponseModel;
import org.bench4q.web.exception.CustomGenericException;
import org.bench4q.web.model.BaseResponseModel;
import org.bench4q.web.model.UploadBehaviorRequestModel;
import org.bench4q.web.service.BaseService;
import org.bench4q.web.service.CommunicateWithMaster;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
@Controller
@SessionAttributes("accessToken")
@SessionAttributes({"accessToken","loadMethod"})
public class PluginActionController {
private final String baseUrl = "plugin";
@ -59,7 +66,11 @@ public class PluginActionController {
PluginResponseModel pluginResponseModel = (PluginResponseModel) this
.getCommunicateWithMaster().getResponseModel(accessToken, url,
PluginResponseModel.class, null, caller);
try {
Logger.getLogger(PluginActionController.class).info(MarshalHelper.marshal(PluginResponseModel.class, pluginResponseModel));
} catch (JAXBException e) {
e.printStackTrace();
}
if (pluginResponseModel.isSuccess()) {
System.out.println("pluginResponseModel has been used");
List<String> pluginList = pluginResponseModel.getPluginList();
@ -90,6 +101,12 @@ public class PluginActionController {
.getCommunicateWithMaster().getResponseModel(accessToken, url,
PluginResponseModel.class, params, caller);
try {
Logger.getLogger(PluginActionController.class).info(MarshalHelper.marshal(PluginResponseModel.class, pluginResponseModel));
} catch (JAXBException e) {
e.printStackTrace();
}
if (pluginResponseModel.isSuccess()) {
System.out.println("pluginResponseModel has been used");
List<String> methodList = pluginResponseModel.getMethodList();
@ -140,4 +157,15 @@ public class PluginActionController {
}
@RequestMapping(value = "uploadBehavior", method = RequestMethod.POST)
@ResponseBody
public BaseResponseModel runTestPlan(
@ModelAttribute("accessToken") String accessToken, ModelMap model,
@RequestBody UploadBehaviorRequestModel uploadBehaviorRequestModel)
throws CustomGenericException {
return new BaseResponseModel(true);
}
}

View File

@ -0,0 +1,52 @@
package org.bench4q.web.model;
public class UploadBehaviorRequestModel {
private String tableList;
private String checkList;
private String fieldList;
private String multiList;
public UploadBehaviorRequestModel(String tableList, String checkList, String fieldList, String multiList){
this.tableList=tableList;
this.checkList=checkList;
this.fieldList=fieldList;
this.multiList=multiList;
}
public String getTableList() {
return tableList;
}
public void setTableList(String tableList) {
this.tableList = tableList;
}
public String getCheckList() {
return checkList;
}
public void setCheckList(String checkList) {
this.checkList = checkList;
}
public String getFieldList() {
return fieldList;
}
public void setFieldList(String fieldList) {
this.fieldList = fieldList;
}
public String getMultiList() {
return multiList;
}
public void setMultiList(String multiList) {
this.multiList = multiList;
}
}

View File

@ -19,8 +19,10 @@ function loadPluginList() {
return;
}
data = data.data;// List<String> pluginList
for (var i = 0; i < data.length; i++)
for (var i = 0; i < data.length; i++) {
pluginList.push(data[i]);
}
for (var j = 0; j < pluginList.length; j++) {
var textNode = document.createTextNode(pluginList[j]);
@ -34,7 +36,8 @@ function loadPluginList() {
divNode.appendChild(inputNode);
divNode.appendChild(textNode);
divNode.appendChild(brNode);
$('#choosePlugin').appendChild(divNode);
document.getElementById("choosePlugin").innerHTML = $(divNode)
.html();
}
});
}
@ -82,10 +85,12 @@ function showInsertPlugin(selectNode) {
getMethodList(methodData);
}
var methodList = new Array();
var html = "";
function getMethodList(methodData) {
var methodList = new Array();
var html = "";
// 得到_前的内容
var type = methodData.split("_");
var plugin = type[0];
@ -132,9 +137,9 @@ function showMethod(methodData, plugin, method) {
document.getElementById("showBehaviorsTable").appendChild(newTrNode);
}
var flag = false;
function showMethodDocument(behaviorData, plugin, method) {
function showMethodDocument(behaviorData, plugin, method) {
var flag = false;
var length = $('#showPluginMethod').children().length;
for (var j = 0; j < length; j++) {
if ($($('#showPluginMethod').children()[i]).attr("id") == behaviorData) {
@ -158,8 +163,6 @@ function showMethodDocument(behaviorData, plugin, method) {
if ($(behaviorData).Attr("class") == "hide") {
$(behaviorData).attr("class", "");
}
// 重新设置
flag = false;
}
// 创建一个MethodParamModel对象
@ -263,12 +266,97 @@ function loadMethodParams(behaviorData, plugin, method) {
+ boxHeader
+ "<div class='box-content'>"
+ fieldHTML
+ "</div><button id='' type='submit' onClick='uploadBehavior();'></button></div></div>";
+ "</div><button id='' type='submit' onClick='uploadBehavior(this);'></button></div></div>";
return html;
});
}
function uploadBehavior(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,
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) {
}
});
}
// 创建一个Table域
function createTable(methodParamModel) {
var name = methodParamModel.name;
@ -286,8 +374,10 @@ function createTable(methodParamModel) {
var nameNode = document.createTextNode(name);
// divNode.setAttribute("class","sample_frame");
divNode.setAttribute("class", "Table");
divNode.setAttribute("id", name);
div.setAttribute("class", "sample_sub_frame");
var tr = document.createElement("tr");
var th = document.createElement("th");
var tr_content = document.createElement("tr");
for (var i = 0; i < table_content.length; i++) {
var td = document.createElement("td");
@ -296,7 +386,7 @@ function createTable(methodParamModel) {
var text_content = document.createTextNode("");
td.appendChild(text);
tr.appendChild(td);
th.appendChild(td);
td.appendChild(text_content);
tr_content.appendChild(td_content);
}
@ -329,6 +419,8 @@ function createCheckBox(methodParamModel) {
var nameNode = document.createTextNode(name);
// divNode.setAttribute("class","sample_frame");
divNode.setAttribute("class", "CheckBox");
divNode.setAttribute("id", name);
div.setAttribute("class", "sample_sub_frame");
p.appendChild(labelNode);
div.appendChild(nameNode + ":");
@ -364,9 +456,12 @@ function createField(label, name, size) {
var nameNode = document.createTextNode(name);
// divNode.setAttribute("class","sample_frame");
divNode.setAttribute("class", "Field");
divNode.setAttribute("id", name);
div.setAttribute("class", "sample_sub_frame");
input.setAttribute("type", "text");
input.setAttribute("size", size);
input.setAttribute("id", name + "_input");
input.setAttribute("value", "");
p.appendChild(labelNode);
@ -394,6 +489,8 @@ function createMultiField(label, name, size) {
var addTextNode = document.createTextNode("Add Field");
var removeTextNode = document.createTextNode("RemoveAll");
divNode.setAttribute("class", "MultiField");
divNode.setAttribute("id", name);
div.setAttribute("class", "sample_sub_frame");
addField.setAttribute("type", "submit");
addField.setAttribute("onClick", "addField(" + size + ");");
@ -414,9 +511,10 @@ function createMultiField(label, name, size) {
return divNode;
}
var field = 0;
function addField(size) {
var field = 0;
var data = "field_" + field + ":";
field = field + 1;
var newTrNode = document.createElement("tr");