file upload

This commit is contained in:
zhengyingying 2014-04-25 18:13:41 +08:00
parent b65a47523b
commit 1eb2c7d352
21 changed files with 1636 additions and 1073 deletions

View File

@ -9,6 +9,7 @@ import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.List;
@ -47,6 +48,7 @@ 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;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.xml.sax.SAXException;
@ -396,11 +398,13 @@ public class ScriptActionController {
@ResponseBody
public BaseResponseModel uploadEditScript(
@ModelAttribute("accessToken") String accessToken,
@RequestBody String content, List<File> paramFiles)
@RequestParam String content, @RequestParam File file)
throws CustomGenericException {
System.out.println("uploadEditScript");
ScenarioModel scenarioModel = null;
Gson gson = new Gson();
List<File> paramFiles=new LinkedList<File>();
paramFiles.add(file);
try {
scenarioModel = gson.fromJson(content, ScenarioModel.class);
} catch (Exception e) {
@ -417,6 +421,7 @@ public class ScriptActionController {
try {
ObjectXmlExchange.toXml(RunScenarioModel.class,
runScenarioModel);
HttpResponse httpResponse = this.getCommunicateWithMaster()
.uploadScriptWithParamFiles(accessToken, scriptName,
runScenarioModel, paramFiles);

View File

@ -24,6 +24,7 @@ import org.bench4q.web.extractObjectFromXml.ObjectXmlExchange;
import org.eclipse.jetty.http.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
@Component
public class CommunicateWithMaster {
@ -80,7 +81,6 @@ public class CommunicateWithMaster {
String url = masterAddress + "RecordScript/uploadScript/" + scriptName;
List<String> stringPart = new LinkedList<String>();
stringPart.add(MarshalHelper.tryMarshal(runScenarioModel));
return this.getHttpRequester().postFiles(
makeAccessTockenMap(accessToken), url, "paramFiles[]",
paramFiles, "scenarioModel", stringPart);

View File

@ -0,0 +1,278 @@
<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<meta charset="utf-8">
<title>Bench4Q</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description"
content="Bench4Q, a new method for QOS benchmarking.">
<link id="bs-css" href="lib/chrisma/css/bootstrap-cerulean.css"
rel="stylesheet">
<link href="lib/chrisma/css/opa-icons.css" rel="stylesheet">
<link
href="http://ajax.aspnetcdn.com/ajax/bootstrap/2.3.2/css/bootstrap-responsive.css"
rel="stylesheet">
<link href="lib/chrisma/css/charisma-app.css" rel="stylesheet">
<style type="text/css">
body {
padding-bottom: 40px;
}
.sidebar-nav {
padding: 9px 0;
}
</style>
<link href="lib/chrisma/css/charisma-app.css" rel="stylesheet">
<link href="css/bench4q.css" rel="stylesheet">
<link href='css/plugin.css' rel='stylesheet'>
<link rel="shortcut icon" href="images/bench4q.png">
<!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- The fav icon -->
<link rel="shortcut icon" href="img/favicon.ico">
</head>
<body>
<fmt:bundle basename="i18n">
<!-- topbar starts -->
<jsp:include page="publiccontrol/navigatebar.jsp"></jsp:include>
<!-- topbar ends -->
<div class="container-fluid">
<div class="row-fluid">
<jsp:include page="publiccontrol/leftmenubar.jsp"></jsp:include>
<noscript>
<div class="alert alert-block span10">
<h4 class="alert-heading">
<fmt:message key="warning" />
!
</h4>
<p>
<fmt:message key="warningcontent1" />
<a href="http://en.wikipedia.org/wiki/JavaScript" target="_blank">JavaScript</a>
<fmt:message key="warningcontent2" />
.
</p>
</div>
</noscript>
<div id="content" class="span10">
<!-- content starts -->
<ul class="breadcrumb">
<li><a href="homepage.jsp"><fmt:message key="home" /></a> <span
class="divider">/</span></li>
<li><a href="script.jsp"><fmt:message
key="scriptmanagement" /></a><span class="divider">/</span></li>
<li><a href="plugin.jsp"><fmt:message
key="script_jsp_makeScript" /></a></li>
</ul>
<div class="tab">
<ul style="cursor: pointer" class="nav nav-tabs">
<li id="tow1" onclick='setTab("tow",1,2);' class="on"><a
href="#"><fmt:message key="plugin_jsp_plugins" />(usePlugins)</a></li>
<!-- <li id="tow2" onclick='setTab("tow",2,3);'><a href="#">参数化(Parameters)</a></li> -->
<li id="tow2" onclick='setTab("tow",2,2);'><a href="#"><fmt:message
key="plugin_jsp_behavior" /> (behaviors)</a></li>
</ul>
</div>
<div class="tabContent">
<div class="span12">
<div id="cont_tow_1" class="one block">
<div class="box span6">
<div class="box-header well" data-original-title>
<i class="icon-pencil left"></i>
<h2>
<span><fmt:message key="plugin_jsp_plugins" />(usePlugins)</span>
</h2>
<div class="box-icon">
<a href="#" class="btn btn-minimize btn-round"><i
class="icon-chevron-up"></i></a>
</div>
</div>
<div class="box-content row-fluid">
<div id="pluginArea" class="listArea span8"></div>
<div class=" span4 button-div">
<div>
<button type="submit" class="btn btn-primary btn-width"
id="addPlugin" onClick="addPlugin();">
<fmt:message key="plugin_jsp_add" />
</button>
</div>
<div>
<button type="submit" class="btn btn-primary btn-width"
id="removePlugin" onClick="removePluginByClicked();">
<fmt:message key="plugin_jsp_remove" />
</button>
</div>
<div>
<button type="submit" class="btn btn-primary btn-width"
id="removeAllPlugin" onClick="clearPluginChoosedList();">
<fmt:message key="plugin_jsp_clear" />
</button>
</div>
</div>
</div>
</div>
<div class="span6" id="pluginParams"></div>
</div>
<!-- <div id="cont_tow_2" class="one " style="display: none"></div> -->
<div id="cont_tow_2" class="one " style="display: none">
<div class="box span6">
<div class="box-header well" data-original-title>
<i class="icon-pencil left"></i>
<h2>
<i></i>
<fmt:message key="plugin_jsp_behavior" />
(behaviors)
</h2>
<div class="box-icon">
<a href="#" class="btn btn-minimize btn-round"><i
class="icon-chevron-up"></i></a>
</div>
</div>
<div class="box-content row-fluid">
<div id="behaviorArea" class="listArea span8"></div>
<div class="span4 button-div">
<div class="hide" id="insertBefore">
<button type="submit" class="btn btn-primary btn-width"
onClick="insert();">
<fmt:message key="plugin_jsp_insertBefore" />
</button>
</div>
<div>
<button type="submit" class="btn btn-primary btn-width"
onClick="insertAfter();">
<fmt:message key="plugin_jsp_insertAfter" />
</button>
</div>
<div>
<button type="submit" class="btn btn-primary btn-width"
id="removeBehavior_Plugin"
onClick="removeInsertPluginByClicked();">
<fmt:message key="plugin_jsp_remove" />
</button>
</div>
<div>
<button type="submit" class="btn btn-primary btn-width"
onClick="clearPluginMethodList();">
<fmt:message key="plugin_jsp_clear" />
</button>
</div>
</div>
</div>
</div>
<div class="span6">
<div id="showPluginMethod" class="showPluginMethod"></div>
<div class="hide" id="submitBehaviors">
<p>
<fmt:message key="plugin_jsp_scriptName"></fmt:message>
<input id="writeAScriptName" type="text" name="scriptName"
size=20></input>
</p>
<p>
<button class='btn-large' onClick="submit(this);">
<fmt:message key="plugin_jsp_submit" />
</button>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!--/#content.span10-->
</div>
<hr>
<div class="modal hide fade " id="myModal_Plugin">
<div class="modal-header">
<button type="button" id="myModal-close" class="close"
data-dismiss="modal">×</button>
<h3>
<fmt:message key="plugin_jsp_addNewPlugin" />
</h3>
</div>
<div class="modal-body" style="height: 260px;">
<div class="inset scroll" id="choosePlugin"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-width"
id="pluginFinish" onClick="pluginFinish();">
<fmt:message key="plugin_jsp_finish" />
</button>
<button type="button" class="btn btn-primary btn-width"
onClick="pluginCancel();" id="pluginCancel">
<fmt:message key="plugin_jsp_cancel" />
</button>
</div>
</div>
<div class="modal hide fade " id="myModal_Behavior">
<div class="modal-header">
<button type="button" id="myModal-close" class="close"
data-dismiss="modal">×</button>
<h3>
<fmt:message key="plugin_jsp_chooseBehaviors" />
</h3>
</div>
<div class="modal-body">
<div class="row-fluid">
<div class="span6 behavior-box scroll">
<div id="insertPluginAreaPlugins"></div>
</div>
<div class="span6 behavior-box scroll">
<div id="pluginMethod"></div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-width"
onClick="behaviorFinish();" id="behaviorFinish">
<fmt:message key="plugin_jsp_finish" />
</button>
<button type="button" class="btn btn-primary btn-width" onClick=""
id="behaviorCancel">
<fmt:message key="plugin_jsp_cancel" />
</button>
</div>
</div>
<jsp:include page="publiccontrol/footer.jsp"></jsp:include>
</div>
<!--/.fluid-container-->
<!-- external javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- jQuery -->
<script
src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.min.js"></script>
<script
src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.4/jquery-ui.min.js"></script>
<script src="lib/jqueryi18n/jquery.i18n.properties-1.0.9.js"></script>
<script src="lib/bootstrap/js/bootstrap-modal.js"></script>
<script
src='http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.js'></script>
<script src="lib/chrisma/js/jquery.cookie.js"></script>
<script src="lib/chrisma/js/theme.js"></script>
<script src="script/base.js"></script>
<script src="script/pluginModel.js"></script>
<script src="script/plugin-new.js"></script>
<script src="script/submitPluginMessage.js"></script>
<script src="script/behaviorsForm.js"></script>
</fmt:bundle>
</body>
</html>

View File

@ -106,13 +106,13 @@ body {
</div>
<div>
<button type="submit" class="btn btn-primary btn-width"
id="removePlugin" onClick="removePluginByClicked();">
id="removePlugin" >
<fmt:message key="plugin_jsp_remove" />
</button>
</div>
<div>
<button type="submit" class="btn btn-primary btn-width"
id="removeAllPlugin" onClick="clearPluginChoosedList();">
id="removeAllPlugin" >
<fmt:message key="plugin_jsp_clear" />
</button>
</div>
@ -147,7 +147,7 @@ body {
</div>
<div>
<button type="submit" class="btn btn-primary btn-width"
onClick="insertAfter();">
id="insertAfter">
<fmt:message key="plugin_jsp_insertAfter" />
</button>
</div>
@ -269,6 +269,7 @@ body {
<script src="lib/chrisma/js/jquery.cookie.js"></script>
<script src="lib/chrisma/js/theme.js"></script>
<script src="script/base.js"></script>
<script src="script/plugin.js"></script>
<script src="script/ScriptEditor/ContainerManager.js"></script>
<script src="script/ScriptEditor/usePluginEditor.js"></script>
<script src="script/ScriptEditor/scriptEditor.js"></script>

View File

@ -42,7 +42,7 @@
<ul style="cursor: pointer" class="nav nav-tabs">
<li id="tow1" class="on" onclick='refresh();setTab("tow",1,3);'><a
href="#">View</a></li>
<li id="tow2" onclick='setTab("tow",2,3);showUsePlugins();'><a
<li id="tow2" onclick='setTab("tow",2,3);'><a
href="#">EditBehaviors</a></li>
<li id="tow3" onclick='setTab("tow",3,3);editPlugin();'><a
href="#">EditPlugins</a></li>

View File

@ -13,7 +13,6 @@ var ListContainer=function(container){
};
Container.prototype.createLineWithRadio=function(lineText, nameAttr) {
var textNode = document.createTextNode(lineText);
var divNode = document.createElement("div");
@ -33,7 +32,7 @@ Container.prototype. createALine=function(name, index, list) {
var p = document.createElement("p");
var i = document.createElement("i");
var textNode = document.createTextNode(name);
div.setAttribute("id", index);
div.setAttribute("id", name);
i.setAttribute("class", "icon-hand-right");
p.setAttribute("id", index);
p.setAttribute("class", "");

View File

@ -1,24 +1,49 @@
var container = new Container();
var plugin = new Plugin(container);
$(document).ready(function() {
pluginEditor();
function pluginEditor() {
var container=new Container();
var plugin = new Plugin(container);
pluginEditorInit();
$("#addPlugin").click(function(e) {
$("#myModal_Plugin").modal('show');
});
$("#pluginFinish").click(function(e) {
var usePluginContainer = $("#pluginArea");
plugin.addUsePlugin();
plugin.usePluginContainerInit(usePluginContainer);
$("#myModal_Plugin").modal('hide');
});
function pluginEditorInit() {
var pluginListContainer = $("#choosePlugin");
});
function pluginEditor() {
pluginEditorInit();
$("#addPlugin").click(function(e) {
$("#myModal_Plugin").modal('show');
});
plugin.pluginListContainerInit(pluginListContainer);
}
}
});
$("#pluginFinish").click(function(e) {
$('#pluginArea').html("");
plugin.addUsePlugin();
plugin.usePluginContainerInit(container.usePluginContainer);
$("#myModal_Plugin").modal('hide');
});
}
function pluginEditorInit() {
plugin.pluginListContainerInit(container.pluginListContainer);
}
function choosePlugin(selectedNode) {
plugin.setClickPluginChoosedNodeIndex(selectedNode);
plugin.setClickPluginChoosedNodeName(selectedNode);
alert(plugin.clickPluginChoosedNodeName);
plugin.showChoosedPluginLine(container.usePluginContainer);
plugin.showChoosedPluginParamInfos(container.pluginParamConfigContainer);
}
$('#removePlugin').click(function() {
plugin.deleteUsePlugin(plugin.clickPluginChoosedNodeName);
plugin.usePluginContainerInit(container.usePluginContainer);
});
$('#removeAllPlugin').click(function() {
plugin.clearUsePluginContainer(container.usePluginContainer);
});
function behaviorEditor() {
var behavior = new Behavior(container, plugin);
$('#insertAfter').click(function(e) {
container.behaviorListForPlugin.html("");
$('#myModal_Behavior').modal('show');
behavior.insertAUsePlugin("after", co);
});
}

View File

@ -0,0 +1,205 @@
var Behavior = function(containerManager, plugin) {
this.containerManager = containerManager;
this.plugin = plugin;
this.clickPluginBehaviorNode = -1;
};
Behavior.prototype.insertAUsePlugin = function(insertLocation, container) {
var chooesedPluginHtml = "";
for (var i = 0; i < this.plugin.usePluginList.length; i++) {
chooesedPluginHtml += this.containerManager.createLineWithRadio(
this.plugin.usePluginList[i], "plugin");
}
container.html(chooesedPluginHtml);// insertPluginAreaPlugins
};
function insert() {
place = "before";
insertPlugin();
}
function insertAfter() {
place = "after";
insertPlugin();
}
function insertPlugin() {
document.getElementById("pluginMethod").innerHTML = "";
$('#myModal_Behavior').modal('show');
}
$('#insertPluginAreaPlugins').click(function() {
var pluginName = $("input[type='radio']:checked").val();
getBehaviorList(pluginName);
});
function loadBehaviorList(plugin) {
var behaviors = null;
$.ajax({
type : "POST",
url : "loadBehaviorList",
data : "pluginName=" + plugin,
dataType : "json",
async : false,
success : function(response) {
if (!response.success) {
alert(response.failedMessage);
return;
}
behaviors = response.data;
}
});
return behaviors;
}
function getBehaviorList(pluginName) {
var methodHtml = "";
var type = pluginName.split("_");
var plugin = type[0];
behaviorList.splice(0, behaviorList.length);
var behaviors = loadBehaviorList(plugin);
for (var i = 0; i < behaviors.length; i++) {
behaviorList.push(behaviors[i].name);
behaviorList[behaviors[i].name] = behaviors[i].paramInfoModels;
methodHtml += createLineWithRadio(behaviors[i].name, "method");
}
document.getElementById("pluginMethod").innerHTML = methodHtml;
}
function behaviorFinish() {
var plugin = $("input[name='plugin']:checked").val();
var method = $("input[name='method']:checked").val();
if (plugin != null && plugin != "" && method != null && method != "") {
showPluginMethodLine(plugin, method);
} else {
alert("The plugin or the method shouldn't be null!");
$('#myModal_Behavior').modal('hide');
}
}
var mark;
function showPluginMethodLine(plugin, method) {
var behaviorData = plugin + "." + method;
var length = pluginMethodList.length;
var documentChild = document.getElementById("showPluginMethod").childNodes;
if (place == "before") {
for (var j = length - 1; j >= clickPluginMethodNode; j--) {
pluginMethodList[j + 1] = pluginMethodList[j];
$(documentChild[j]).attr("id", parseInt(j + 1));
}
mark = clickPluginMethodNode;
clickPluginMethodNode = parseInt(clickPluginMethodNode + 1);
pluginMethodList[mark] = behaviorData;
} else if (place == "after") {
mark = parseInt(clickPluginMethodNode + 1);
if (clickPluginMethodNode == parseInt(length - 1)
&& clickPluginMethodNode != -1) {
pluginMethodList.push(behaviorData);
} else {
for (var j = parseInt(length - 1); j >= mark; j--) {
pluginMethodList[j + 1] = pluginMethodList[j];
$(documentChild[j]).attr("id", parseInt(j + 1));
}
pluginMethodList[mark] = behaviorData;
}
}
$('#insertBefore').attr("class", "show");
$('#myModal_Behavior').modal('hide');
createPluginMethodLines();
}
function createPluginMethodLines() {
document.getElementById("showPluginMethod").innerHTML = "";
document.getElementById('behaviorArea').innerHTML = "";
for (var j = 0; j < pluginMethodList.length; j++) {
var div = createALine(pluginMethodList[j], j, "pluginMethodList");
if (j == clickPluginMethodNode) {
$(div).find("p").attr("class", "visited");
}
document.getElementById('behaviorArea').appendChild(div);
loadMethodParams(pluginMethodList[j], j);
}
}
function showMethodDocument(selectedNode) {
clickPluginMethodNode = parseInt($(selectedNode).attr("id"));
var length = $("#showPluginMethod").children().length;
var behaviorAreaChild = $('#behaviorArea').children();
var div = $("#showPluginMethod").children();
for (var i = 0; i < length; i++) {
if (behaviorAreaChild[i].getAttribute("id") != clickPluginMethodNode) {
$(behaviorAreaChild[i]).find("p").attr("class", "");
} else {
$(behaviorAreaChild[i]).find("p").attr("class", "visited");
}
}
for (var j = 0; j < length; j++) {
if (div[j].getAttribute("id") == clickPluginMethodNode) {
$(div[j]).show();
} else {
$(div[j]).hide();
}
}
$('#submitBehaviors').attr("class", "show");
}
function removeInsertPluginByClicked() {
var length = $('#behaviorArea').children().length;
var removeDocumentNode = document.getElementById("showPluginMethod").childNodes;
for (var i = parseInt(clickPluginMethodNode + 1); i < length; i++) {
pluginMethodList[i - 1] = pluginMethodList[i];
}
pluginMethodList.splice(length - 1, 1);// js Array remove element
createPluginMethodLines();
for (var j = 0; j < length; j++) {
if ($(removeDocumentNode[j]).attr("id") == clickPluginMethodNode) {
document.getElementById("showPluginMethod").removeChild(
removeDocumentNode[j]);
}
}
}
function clearPluginMethodList() {
pluginMethodList.splice(0, pluginMethodList.length);
document.getElementById('behaviorArea').innerHTML = "";
document.getElementById("showPluginMethod").innerHTML = "";
$('#submitBehaviors').attr("class", "hide");
}
function loadMethodParams(behaviorData, behaviorIndex) {
var temp = behaviorData.split('.');
var method = temp[1];
var data = behaviorList[method];// data 为List<ParamInfoModel>
document.getElementById("showPluginMethod").innerHTML += createAEditText(
data, behaviorData, behaviorIndex);
}
// 生成页面显示
function createAEditText(data, name, index) {
var documentHtml = "";
var boxHeader = "";
var fieldHTML = "";
boxHeader = "<div class='box-header well' data-original-title> "
+ "<i class='icon-pencil left'></i>" + "<h2>sample:<i>" + name
+ "</i></h2></div>";
if (data != null) {
fieldHTML = createPluginsOrBehaviorsForm(data, index);
}
documentHtml = "<div id='" + index + "' class='hide'><p class='hide'>"
+ name + "</p><div class='span12 box' style='margin-left:-2px;'>"
+ boxHeader + "<div class='box-content'>" + fieldHTML + "</div>"
+ "</div></div>";
return documentHtml;
}
function cancelBehavior(selectedNode) {
var divNode = selectedNode.parentNode.parentNode.parentNode;
$(divNode).hide();
}
$('#pluginCancel').click(function() {
$('#myModal_Plugin').modal('hide');
});
$('#behaviorCancel').click(function() {
$('#myModal_Behavior').modal('hide');
});

View File

@ -25,7 +25,7 @@ function createPluginsOrBehaviorsForm(data, behaviorIndex) {
} else if (type == "table") {
var cols = paramTypeModel.cols;
fieldHTML += createTable(methodParamModel.lable,
methodParamModel.name, cols,null, behaviorIndex);
methodParamModel.name, cols, null, behaviorIndex);
} else if (type == "checkBox") {
var rows = paramTypeModel.choiceModels;
fieldHTML += createCheckBox(methodParamModel.lable,
@ -33,74 +33,34 @@ function createPluginsOrBehaviorsForm(data, behaviorIndex) {
} else if (type == "radioButton") {
var rows = paramTypeModel.choiceModels;// List<ChoiceModel>
fieldHTML += createRadioButton(methodParamModel.lable,
methodParamModel.name, rows,null, behaviorIndex);
}else if(type=="file"){
var text=paramTypeModel.text;
fieldHTML+=createFile(methodParamModel.lable,
methodParamModel.name, rows, null, behaviorIndex);
} else if (type == "file") {
var text = paramTypeModel.text;
fieldHTML += createFile(methodParamModel.lable,
methodParamModel.name, text, behaviorIndex);
}
}
return fieldHTML;
}
function createFile(label,name,text,behaviorIndex){
}
function createForm(behaviorIndex) {
var formNode = document.getElementById(behaviorIndex);
var contents = formNode.lastChild.lastChild.childNodes;
var contentLength = contents.length;
for (var j = 0; j < contentLength; j++) {
var type = $(contents[j]).attr("class");
if (type == "Field sample_frame") {
var key = contents[j].lastChild.firstChild.nodeValue;
var value = parameters[key];
if (value != "" && value != null) {
$(contents[j].lastChild.lastChild).val(value);
}
} else if (type == "NField sample_frame") {
var key = contents[j].firstChild.firstChild.nodeValue.split(":")[0];
var value = parameters[key];
if (value == null) {
addField(20, behaviorIndex);
} else {
value = value.split(";");
var fieldLength = value.length;
for (var t = 0; t < fieldLength; t++) {
addField(20, behaviorIndex);
$($(contents[j]).find("table").children()[t]).find("input")
.val(value[t]);
}
}
} else if (type == "Table sample_frame") {
var key = contents[j].lastChild.firstChild.nodeValue;
var value = parameters[key];
if (value != "" && value != null) {
value = parameters[key].split("|;");
var table = $(contents[j]).find("table");
var col = table.find("th").length;
var row = value.length - 1;
var tbody = $(contents[j]).find("tbody");
for (var m = 0; m < row; m++) {
var input = value[m].split("|");
if (m != 0) {
var selectedNode = contents[j].lastChild.firstChild.nextSibling.nextSibling;
addCol(selectedNode);
}
for (var n = 0; n < col; n++) {
var rowNode = $(tbody).children()[m];
var colNode = $(rowNode).children()[n];
$(colNode).find("input").val(input[n]);
}
}
}
} else if (type == "CheckBox sample_frame") {
} else if (type = "RadioButton sample_frame") {
}
}
function createFile(label, name, text, behaviorIndex) {
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 input=$(document.createElement("input"));
$(divNode).attr("class", "File sample_frame");
$(divNode).attr("id", behaviorIndex + "_" + name);
$(div).attr("class", "sample_sub_frame");
input.attr("type","file");
input.attr("id","file"+behaviorIndex);
p.appendChild(labelNode);
div.appendChild(nameNode);
$(div).append(input);
divNode.appendChild(p);
divNode.appendChild(div);
return divNode.outerHTML;
}
function createField(label, name, size, text, behaviorIndex) {
@ -120,7 +80,7 @@ function createField(label, name, size, text, behaviorIndex) {
$(input).attr("type", "text");
$(input).attr("size", size);
$(input).attr("id", name + "_input");
if(text!=null){
if (text != null) {
$(input).attr("value", text);
}
@ -136,7 +96,7 @@ function createMultiField(label, name, size, text, behaviorIndex) {
if (size == 0) {
size = 10;
}
var divNode = document.createElement("div");
var p = document.createElement("p");
var labelNode = document.createTextNode(name + ":" + label);
@ -154,16 +114,16 @@ function createMultiField(label, name, size, text, behaviorIndex) {
$(addFieldButton).attr("type", "submit");
$(addFieldButton).attr("class", "btn-large");
$(addFieldButton).attr("onClick",
"addField(" + size + "," + behaviorIndex +","+ null+");");
"addField(" + size + "," + behaviorIndex + "," + null + ");");
$(removeFieldButton).attr("type", "submit");
$(removeFieldButton).attr("class", "btn-large");
$(removeFieldButton).attr("onClick", "removeField(this)");
$(table).attr("id", "addFieldTable_" + behaviorIndex);
$(table).attr("class", "table-margin");
if (text != null) {
var content=text.split(";");
var content = text.split(";");
for (var i = 0; i < content.length; i++) {
addField(10,behaviorIndex,content[i]);
createAFieldLine(10, i, behaviorIndex, content[i]);
}
}
p.appendChild(labelNode);
@ -178,11 +138,12 @@ function createMultiField(label, name, size, text, behaviorIndex) {
return divNode.outerHTML;
}
var field;
function addField(size, addId,value) {
field = $("#addFieldTable_" + addId).children().length;
function getFieldCount(addId) {
return $("#addFieldTable_" + addId).children().length;
}
function createAFieldLine(size, field, addId, value) {
var data = "field_" + field + ":";
field = field + 1;
var newTrNode = document.createElement("tr");
var newTdNode1 = document.createElement("td");
var newTdNode2 = document.createElement("td");
@ -191,13 +152,19 @@ function addField(size, addId,value) {
var inputNode = document.createElement("input");
inputNode.setAttribute("type", "text");
inputNode.setAttribute("size", size);
if(value!=null){
if (value != null) {
inputNode.setAttribute("value", value);
}
newTdNode1.appendChild(textNode);
newTdNode2.appendChild(inputNode);
newTrNode.appendChild(newTdNode1);
newTrNode.appendChild(newTdNode2);
return newTrNode;
}
function addField(size, addId, value) {
var field = getFieldCount(addId);
var newTrNode = createAFieldLine(size, field, addId, value);
document.getElementById("addFieldTable_" + addId).appendChild(newTrNode);
}
@ -207,10 +174,10 @@ function removeField(selectedNode) {
table.removeChild(deletedNode);
}
function createTable(label, name, cols,value, behaviorIndex) {
function createTable(label, name, cols, value, behaviorIndex) {
var table_content = cols.split(";");// table分隔符
var col=table_content.length;
var tableWidth=400/col;
var col = table_content.length;
var tableWidth = 300 / col;
var tr = document.createElement("tr");
for (var i = 0; i < col; i++) {
var th = document.createElement("th");
@ -218,16 +185,6 @@ function createTable(label, name, cols,value, behaviorIndex) {
th.appendChild(text);
tr.appendChild(th);
}
// var tr_content = document.createElement("tr");
// for (var j = 0; j < table_content.length; j++) {
// var td_content = document.createElement("td");
// var text_content = document.createElement("input");
// text_content.setAttribute("size", 10);
// text_content.setAttribute("type", "text");
// text_content.setAttribute("style", "width:"+tableWidth+"px;");
// td_content.appendChild(text_content);
// tr_content.appendChild(td_content);
// }
var divNode = document.createElement("div");
var p = document.createElement("p");
var labelNode = document.createTextNode(label);
@ -243,21 +200,33 @@ function createTable(label, name, cols,value, behaviorIndex) {
var thead = document.createElement("thead");
var tbody = document.createElement("tbody");
value=value.split("|;");//一行的信息
var row=value.length;
var input=null;
for(var m=0;m<row;m++){
input=value[m].split("|");
addCol(addColButton,input);
if (value != null) {
value = value.split("|;");// 一行的信息
var row = value.length - 1;
for (var m = 0; m < row; m++) {
var colValue = value[m].split("|");// 一行中的每列信息
var trNode = document.createElement("tr");
for (var n = 0; n < col; n++) {
var tdNode = document.createElement("td");
var input = document.createElement("input");
input.setAttribute("size", 10);
input.setAttribute("type", "text");
input.setAttribute("style", "width:" + tableWidth + "px;");
input.setAttribute("value", colValue[n]);
tdNode.appendChild(input);
trNode.appendChild(tdNode);
}
tbody.appendChild(trNode);
}
}
$(divNode).attr("class", "Table sample_frame");
$(divNode).attr("id", behaviorIndex + "_" + name);
$(div).attr("class", "sample_sub_frame");
$(addColButton).attr("type", "submit");
$(addColButton).attr("class", "btn-large");
$(addColButton).attr("onClick", "addCol("+this+","+input+")");
$(addColButton).attr("id",tableWidth);
$(addColButton).attr("onClick", "addCol(this)");
$(addColButton).attr("id", tableWidth);
$(removeColButton).attr("type", "submit");
$(removeColButton).attr("class", "btn-large");
$(removeColButton).attr("onClick", "removeCol(this)");
@ -268,7 +237,6 @@ function createTable(label, name, cols,value, behaviorIndex) {
addColButton.appendChild(addColNode);
removeColButton.appendChild(removeColNode);
thead.appendChild(tr);
tbody.appendChild(tr_content);
table.appendChild(thead);
table.appendChild(tbody);
div.appendChild(nameNode);
@ -283,8 +251,8 @@ function createTable(label, name, cols,value, behaviorIndex) {
}
function addCol(selectedNode,rowValue) {
var tableWidth=$(selectedNode).attr("id");
function addCol(selectedNode) {
var tableWidth = $(selectedNode).attr("id");
var tbody = selectedNode.nextSibling.nextSibling.nextSibling.lastChild;
var length = tbody.previousSibling.firstChild.childNodes.length;
var tr = document.createElement("tr");
@ -293,10 +261,7 @@ function addCol(selectedNode,rowValue) {
var input = document.createElement("input");
input.setAttribute("size", 10);
input.setAttribute("type", "text");
input.setAttribute("style", "width:"+tableWidth+"px;");
if(rowValue!=null){
input.setAttribute("value",rowValue[i]);
}
input.setAttribute("style", "width:" + tableWidth + "px;");
td.appendChild(input);
tr.appendChild(td);
}
@ -309,14 +274,27 @@ function removeCol(selectedNode) {
tbody.removeChild(removeNode);
}
function createCheckBox(label, name, rows,value ,behaviorIndex) {
function createCheckBox(label, name, rows, value, behaviorIndex) {
var valueList = new Array();
var defaultList = new Array();
for (var j = 0; j < rows.length; j++) {
valueList.push(rows[j].value);
defaultList.push(rows[j].defaultValue);
}
if (value != null) {
value = value.split(";");
for (var m = 0; m < value.length; m++) {
for (var n = 0; n < rows.length; n++) {
if (valueList[n] == value[m]) {
defaultList[n] = true;
break;
}
}
}
}
var divNode = document.createElement("div");
var p = document.createElement("p");
var div = document.createElement("div");
@ -329,8 +307,8 @@ function createCheckBox(label, name, rows,value ,behaviorIndex) {
$(div).attr("class", "sample_sub_frame");
$(divInput).attr("class", "sample_sub_frame");
p.appendChild(labelNode);
for (var i = 0; i < rows.length; i++) {
alert("value=" + valueList[i] + ",defaultValue=" + defaultList[i]);
var checkBoxNode = document.createElement("input");
var brInput = document.createElement("br");
checkBoxNode.setAttribute("type", "checkbox");
@ -353,14 +331,21 @@ function createCheckBox(label, name, rows,value ,behaviorIndex) {
}
function createRadioButton(label, name, rows,value, behaviorIndex) {
function createRadioButton(label, name, rows, value, behaviorIndex) {
var valueList = new Array();
var defaultList = new Array();
for (var i = 0; i < rows.length; i++) {
var choiceModel = rows[i];
valueList.push(choiceModel.value);
defaultList.push(choiceModel.defaultValue);
alert("value=" + choiceMode.value + ",defaultValue=" + defauleValue);
}
if(value!=null){
for(var m=0;m<rows.length;m++){
if(valueList[m]==value){
defaultList[m]=true;
break;
}
}
}
var divNode = document.createElement("div");
var p = document.createElement("p");

View File

@ -1,378 +1,312 @@
var pluginNameList = new Array();
var parameters = [];
var parameterList = [];
var behaviorChoosed;
var behaviorName;
var pluginName;
var plugin_id;
var behavior_id;
function loadUsePluigns(data) {
pluginNameList.splice(0, pluginNameList.length);
for (var i = 0; i < data.usePlugins.length; i++) {
var flag = false;
var usePlugin = data.usePlugins[i];
for (var j = 0; j < pluginNameList.length; j++) {
if (pluginNameList[j] == usePlugin.id) {
flag = true;
}
}
if (flag == false) {
pluginNameList.push(usePlugin.id);
}
}
var ulNode = document.getElementById("allPlugins");
for (var p = 0; p < pluginNameList.length; p++) {
createALi(ulNode, pluginNameList[p], "choosePlugin");
}
loadBehaviors("all");
}
function createALi(ulNode, name, action) {
var textNode = document.createTextNode(name);
var li = document.createElement("li");
var divider = document.createElement("li");
var a = document.createElement("a");
divider.setAttribute("class", "divider");
if (action == "choosePlugin") {
a.setAttribute("onClick", "choosePlugin(this);");
} else {
a.setAttribute("onClick", "chooseBehavior(this);");
}
a.appendChild(textNode);
li.appendChild(a);
ulNode.appendChild(li);
ulNode.appendChild(divider);
}
function choosePlugin(selectedNode) {
pluginName = selectedNode.firstChild.nodeValue;
if (pluginName == "All") {
loadBehaviors("all");
} else {
loadBehaviors("other");
}
}
function loadBehaviors(mark) {
var ul = document.getElementById("behaviorUl");
$(ul).html("");
$.each(modelData.pages, function(i, item) {
$.each(item.batches, function(i, item) {
var Id = item.Id;
if (mark == "other") {
$.each(item.behaviors, function(i, item) {
if (item.use == pluginName) {
var text = item.use + ":" + Id + "." + item.name + ":"
+ item.id;
createALi(ul, text, "");
}
});
} else if (mark == "all") {
$.each(item.behaviors, function(i, item) {
var text = item.use + ":" + Id + "." + item.name + ":"
+ item.id;
createALi(ul, text, "");
});
}
});
});
}
function chooseBehavior(selectedNode) {
document.getElementById("action").style.display = "none";
document.getElementById("showPluginMethodForm").innerHTML = "";
var behaviorMethod = selectedNode.firstChild.nodeValue;
var bm = behaviorMethod.split(".");
plugin_id = bm[0].split(":")[1];
behavior_id = bm[1].split(":")[1];
behaviorName = bm[1].split(":")[0];
// loadBehaviorParamInfos(behaviorMethod);
createBehaviorParamPage(behaviorMethod);
}
function loadBehaviorParamInfos(behaviorMethod) {
var plugin = "", method = "";
$.each(modelData.pages, function(i, item) {
$.each(item.batches, function(i, item) {
if (item.Id == plugin_id) {
$.each(item.behaviors, function(i, item) {
if (item.id == behavior_id) {
plugin = item.use;
method = item.name;
$.each(item.parameters, function(i, item) {
parameters.push(item.key);
parameters[item.key] = item.value;
});
}
});
}
});
});
loadBehaviorParameters(plugin, method, behaviorMethod);
}
function createBehaviorParamPage(behaviorData) {
var plugin = "", method = "";
var behaviorHTML = "";
var paramInfoModels = null, paramInfoModel = null;
var behaviorParameters = [];
$
.each(
modelData.pages,
function(i, item) {
$
.each(
item.batches,
function(i, item) {
if (item.Id == plugin_id) {
$
.each(
item.behaviors,
function(i,
item) {
if (item.id == behavior_id) {
plugin = item.use;
method = item.name;
$
.each(
item.parameters,
function(
i,
item) {
behaviorParameters
.push(item.key);
behaviorParameters[item.key] = item.value;
});
var behaviorList = loadBehaviorList(plugin.split("_")[0]);// List<BehaviorInfoModel>
for (var j = 0; j < behaviorList.length; j++) {
if (behaviorList[j].name == method) {
paramInfoModels = behaviorList[j].paramInfoModels;
break;
}
}
for (var k = 0; k < paramInfoModels.length; k++) {
paramInfoModel = paramInfoModels[k];
behaviorHTML += createParamInfoModelWithBehaviorParams(
paramInfoModel,
behaviorParameters,behavior_id);
}
}
});
}
});
});
document.getElementById("showPluginMethodForm").innerHTML = createAEditText(
behaviorHTML, behaviorData, behavior_id);
document.getElementById("action").style.display = "block";
}
// 生成页面显示
function createAEditText(behaviorHTML, behaviorData, behavior_id) {
var documentHtml = "";
var boxHeader = "";
boxHeader = "<div class='box-header well' data-original-title> "
+ "<i class='icon-pencil left'></i>" + "<h2>sample:<i>"
+ behaviorData + "</i></h2></div>";
documentHtml = "<div id='"
+ behavior_id
+ "' class=''><p class='hide'>"
+ behaviorData
+ "</p><div class='span10 box' style='margin-left:15px;margin-top:-2px;'>"
+ boxHeader + "<div class='box-content'>" + behaviorHTML
+ "</div></div></div>";
return documentHtml;
}
function createParamInfoModelWithBehaviorParams(paramInfoModel,
behaviorParameters,behaviorIndex) {
var name = paramInfoModel.name;
var value = behaviorParameters[name];
return createModelByType(value, paramInfoModel,behaviorIndex);
}
function createModelByType(value, paramInfoModel,behaviorIndex) {
var paramTypeModel = paramInfoModel.paramTypeModel;
var type = paramTypeModel.type;
var fieldHTML = "";
if (type == "field") {
var size = paramTypeModel.size;
fieldHTML += createField(paramInfoModel.lable, paramInfoModel.name,
size, value, behaviorIndex);
} else if (type == "nfield") {
var size = paramTypeModel.size;
fieldHTML += createMultiField(paramInfoModel.lable,
paramInfoModel.name, size, value, nfieldCount);
nfieldCount++;
} else if (type == "table") {
var cols = paramTypeModel.cols;
fieldHTML += createTable(paramInfoModel.lable, paramInfoModel.name,
cols, value, behaviorIndex);
} else if (type == "checkBox") {
var rows = paramTypeModel.choiceModels;
fieldHTML += createCheckBox(paramInfoModel.lable, paramInfoModel.name,
rows, value, behaviorIndex);
} else if (type == "radioButton") {
var rows = paramTypeModel.choiceModels;// List<ChoiceModel>
fieldHTML += createRadioButton(paramInfoModel.lable,
paramInfoModel.name, rows, value, behaviorIndex);
} else if (type == "file") {
fieldHTML += createFile(paramInfoModel.lable, paramInfoModel.name,
value, behaviorIndex);
}
return filedHTML;
}
function loadBehaviorList(plugin){
var behaviors=null;
$.ajax({
type : "POST",
url : "loadBehaviorList",
data:"pluginName="+plugin,
dataType : "json",
async : false,
success : function(response) {
if (!response.success) {
alert(response.failedMessage);
return;
}
behaviors=response.data;
}
});
return behaviors;
}
function loadBehaviorParameters(plugin, method, behaviorData) {
if (plugin.indexOf("_") >= 0) {
plugin = plugin.split("_")[0];
}
var behaviorIndex = behavior_id;
var behaviorList = null;
$
.post(
"loadBehaviorList",
{
pluginName : plugin,
},
function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
data = data.data;// List<BehaviorInfoModel>
// behaviorInfoModels
for (var i = 0; i < data.length; i++) {
if (data[i].name == method) {
behaviorList = data[i].paramInfoModels;
}
}
var documentHtml = "";
var boxHeader = "";
var fieldHTML = createPluginsOrBehaviorsForm(
behaviorList, behaviorData, behaviorIndex);
boxHeader = "<div class='box-header well' data-original-title> "
+ "<i class='icon-pencil left'></i>"
+ "<h2>sample:<i>"
+ behaviorData
+ "</i></h2></div>";
documentHtml = "<div id='"
+ behaviorIndex
+ "' class=''><p class='hide'>"
+ behaviorData
+ "</p><div class='span10 box' style='margin-left:15px;margin-top:-2px;'>"
+ boxHeader + "<div class='box-content'>"
+ fieldHTML + "</div></div></div>";
document.getElementById("showPluginMethodForm").innerHTML = documentHtml;
document.getElementById("action").style.display = "block";
createForm(behaviorIndex);
});
}
function saveFormModification() {
var div = document.getElementById("showPluginMethodForm").firstChild;
var contents = div.lastChild.lastChild.childNodes;
var length = contents.length;
for (var i = 0; i < length; i++) {
var node = contents[i];
var key = "", value = "", temp = "";
if ($(node).attr("class") == "Field sample_frame") {
key = node.lastChild.firstChild.nodeValue;
temp = $(node).find("input").val();
if (temp != "") {
value = temp;
}
} else if ($(node).attr("class") == "NField sample_frame") {
key = node.firstChild.firstChild.nodeValue.split(":")[0];
var fieldNode = $(node).find("table").children();
var fieldLength = $(fieldNode).length;
for (var j = 0; j < fieldLength; j++) {
temp = $(fieldNode[j]).find("input").val();
if (temp != "") {
value += temp;
}
if (j != fieldLength - 1) {
value += ";";
}
}
} else if ($(node).attr("class") == "Table sample_frame") {
key = node.lastChild.firstChild.nodeValue;
var table = $(node).find("table");
var col = table.find("th").length;
var row = table.find("tbody").children().length;
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];
temp = $(colNode).find("input").val();
if (temp != "") {
value += temp + "|";
}
}
if (value != "") {
value += ";";
}
}
} else if ($(node).attr("class") == "CheckBox sample_frame") {
key = node.lastChild.firstChild.nodeValue;
var id = $(node).attr("id");
$('input[name=' + id + ']:checked').each(function() {
temp = $(this).val();
if (temp != "") {
value += temp + ";";
}
});
}
parameterList.push(key);
parameterList[key] = value;
}
modifyJsonData();
}
function modifyJsonData() {
$.each(modelData.pages, function(i, item) {
$.each(item.batches, function(i, item) {
if (item.Id == plugin_id) {
$.each(item.behaviors, function(i, item) {
if (item.id == behavior_id) {
for (var i = 0; i < parameterList.length; i++) {
var key = parameterList.valueOf()[i];
var parameterModel = new ParameterModel(key,
parameterList[key]);
item.parameters[i] = parameterModel;
}
}
});
}
});
});
parameterList.splice(0, parameterList.length);
}
function editPlugin() {
window.location.href("plugin.jsp?jsonData=" + modelData);
}
var pluginNameList = new Array();
var parameters = [];
var parameterList = [];
var behaviorChoosed;
var behaviorName;
var pluginName;
var plugin_id;
var behavior_id;
function loadUsePluigns(data) {
pluginNameList.splice(0, pluginNameList.length);
for (var i = 0; i < data.usePlugins.length; i++) {
var flag = false;
var usePlugin = data.usePlugins[i];
for (var j = 0; j < pluginNameList.length; j++) {
if (pluginNameList[j] == usePlugin.id) {
flag = true;
}
}
if (flag == false) {
pluginNameList.push(usePlugin.id);
}
}
var ulNode = document.getElementById("allPlugins");
for (var p = 0; p < pluginNameList.length; p++) {
createALi(ulNode, pluginNameList[p], "choosePlugin");
}
loadBehaviors("all");
}
function createALi(ulNode, name, action) {
var textNode = document.createTextNode(name);
var li = document.createElement("li");
var divider = document.createElement("li");
var a = document.createElement("a");
divider.setAttribute("class", "divider");
if (action == "choosePlugin") {
a.setAttribute("onClick", "choosePlugin(this);");
} else {
a.setAttribute("onClick", "chooseBehavior(this);");
}
a.appendChild(textNode);
li.appendChild(a);
ulNode.appendChild(li);
ulNode.appendChild(divider);
}
function choosePlugin(selectedNode) {
pluginName = selectedNode.firstChild.nodeValue;
if (pluginName == "All") {
loadBehaviors("all");
} else {
loadBehaviors("other");
}
}
function loadBehaviors(mark) {
var ul = document.getElementById("behaviorUl");
$(ul).html("");
$.each(modelData.pages, function(i, item) {
$.each(item.batches, function(i, item) {
var Id = item.Id;
if (mark == "other") {
$.each(item.behaviors, function(i, item) {
if (item.use == pluginName) {
var text = item.use + ":" + Id + "." + item.name + ":"
+ item.id;
createALi(ul, text, "");
}
});
} else if (mark == "all") {
$.each(item.behaviors, function(i, item) {
var text = item.use + ":" + Id + "." + item.name + ":"
+ item.id;
createALi(ul, text, "");
});
}
});
});
}
function chooseBehavior(selectedNode) {
document.getElementById("action").style.display = "none";
document.getElementById("showPluginMethodForm").innerHTML = "";
var behaviorMethod = selectedNode.firstChild.nodeValue;
var bm = behaviorMethod.split(".");
plugin_id = bm[0].split(":")[1];
behavior_id = bm[1].split(":")[1];
behaviorName = bm[1].split(":")[0];
createBehaviorParamPage(behaviorMethod);
}
function createBehaviorParamPage(behaviorData) {
var plugin = "", method = "";
var behaviorHTML = "";
var paramInfoModels = null, paramInfoModel = null;
var behaviorParameters = [];
$
.each(
modelData.pages,
function(i, item) {
$
.each(
item.batches,
function(i, item) {
if (item.Id == plugin_id) {
$
.each(
item.behaviors,
function(i,
item) {
if (item.id == behavior_id) {
plugin = item.use;
method = item.name;
$
.each(
item.parameters,
function(
i,
item) {
behaviorParameters
.push(item.key);
behaviorParameters[item.key] = item.value;
});
var behaviorList = loadBehaviorList(plugin.split("_")[0]);// List<BehaviorInfoModel>
for (var j = 0; j < behaviorList.length; j++) {
if (behaviorList[j].name == method) {
paramInfoModels = behaviorList[j].paramInfoModels;
break;
}
}
for (var k = 0; k < paramInfoModels.length; k++) {
paramInfoModel = paramInfoModels[k];
behaviorHTML += createParamInfoModelWithBehaviorParams(
paramInfoModel,
behaviorParameters,behavior_id);
}
}
});
}
});
});
document.getElementById("showPluginMethodForm").innerHTML = createAEditText(
behaviorHTML, behaviorData, behavior_id);
document.getElementById("action").style.display = "block";
nfieldCount=0;
}
// 生成页面显示
function createAEditText(behaviorHTML, behaviorData, behavior_id) {
var documentHtml = "";
var boxHeader = "";
boxHeader = "<div class='box-header well' data-original-title> "
+ "<i class='icon-pencil left'></i>" + "<h2>sample:<i>"
+ behaviorData + "</i></h2></div>";
documentHtml = "<div id='"
+ behavior_id
+ "' class=''><p class='hide'>"
+ behaviorData
+ "</p><div class='span10 box' style='margin-left:15px;margin-top:-2px;'>"
+ boxHeader + "<div class='box-content'>" + behaviorHTML
+ "</div></div></div>";
return documentHtml;
}
function createParamInfoModelWithBehaviorParams(paramInfoModel,
behaviorParameters,behaviorIndex) {
var name = paramInfoModel.name;
var value = behaviorParameters[name];
return createModelByType(value, paramInfoModel,behaviorIndex);
}
var nfieldCount=0;
function createModelByType(value, paramInfoModel,behaviorIndex) {
var paramTypeModel = paramInfoModel.paramTypeModel;
var type = paramTypeModel.type;
var fieldHTML = "";
if (type == "field") {
var size = paramTypeModel.size;
fieldHTML += createField(paramInfoModel.lable, paramInfoModel.name,
size, value, behaviorIndex);
} else if (type == "nfield") {
var size = paramTypeModel.size;
fieldHTML += createMultiField(paramInfoModel.lable,
paramInfoModel.name, size, value, nfieldCount);
nfieldCount++;
} else if (type == "table") {
var cols = paramTypeModel.cols;
fieldHTML += createTable(paramInfoModel.lable, paramInfoModel.name,
cols, value, behaviorIndex);
} else if (type == "checkBox") {
var rows = paramTypeModel.choiceModels;
fieldHTML += createCheckBox(paramInfoModel.lable, paramInfoModel.name,
rows, value, behaviorIndex);
} else if (type == "radioButton") {
var rows = paramTypeModel.choiceModels;// List<ChoiceModel>
fieldHTML += createRadioButton(paramInfoModel.lable,
paramInfoModel.name, rows, value, behaviorIndex);
} else if (type == "file") {
fieldHTML += createFile(paramInfoModel.lable, paramInfoModel.name,
value, behaviorIndex);
}
return fieldHTML;
}
function loadBehaviorList(plugin){
var behaviors=null;
$.ajax({
type : "POST",
url : "loadBehaviorList",
data:"pluginName="+plugin,
dataType : "json",
async : false,
success : function(response) {
if (!response.success) {
alert(response.failedMessage);
return;
}
behaviors=response.data;
}
});
return behaviors;
}
function saveFormModification() {
alert("saveFormModification");
var div = document.getElementById("showPluginMethodForm").firstChild;
var contents = div.lastChild.lastChild.childNodes;
var length = contents.length;
for (var i = 0; i < length; i++) {
var node = contents[i];
var key = "", value = "", temp = "";
if ($(node).attr("class") == "Field sample_frame") {
key = node.lastChild.firstChild.nodeValue;
temp = $(node).find("input").val();
if (temp != "") {
value = temp;
}
} else if ($(node).attr("class") == "NField sample_frame") {
key = node.firstChild.firstChild.nodeValue.split(":")[0];
var fieldNode = $(node).find("table").children();
var fieldLength = $(fieldNode).length;
for (var j = 0; j < fieldLength; j++) {
temp = $(fieldNode[j]).find("input").val();
if (temp != "") {
value += temp;
}
if (j != fieldLength - 1) {
value += ";";
}
}
} else if ($(node).attr("class") == "Table sample_frame") {
key = node.lastChild.firstChild.nodeValue;
var table = $(node).find("table");
var col = table.find("th").length;
var row = table.find("tbody").children().length;
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];
temp = $(colNode).find("input").val();
if (temp != "") {
value += temp + "|";
}
}
if (value != "") {
value += ";";
}
}
} else if ($(node).attr("class") == "CheckBox sample_frame") {
key = node.lastChild.firstChild.nodeValue;
var id = $(node).attr("id");
$('input[name=' + id + ']:checked').each(function() {
temp = $(this).val();
if (temp != "") {
value += temp + ";";
}
});
}
parameterList.push(key);
parameterList[key] = value;
}
modifyJsonData();
}
function modifyJsonData() {
$.each(modelData.pages, function(i, item) {
$.each(item.batches, function(i, item) {
if (item.Id == plugin_id) {
$.each(item.behaviors, function(i, item) {
if (item.id == behavior_id) {
for (var i = 0; i < parameterList.length; i++) {
var key = parameterList.valueOf()[i];
var parameterModel = new ParameterModel(key,
parameterList[key]);
item.parameters[i] = parameterModel;
}
}
});
}
});
});
parameterList.splice(0, parameterList.length);
}
function editPlugin() {
window.location.href("plugin.jsp?jsonData=" + modelData);
}

View File

@ -11,6 +11,7 @@ var clickPluginMethodNode = -1;
var clickPluginChoosedNode = 0;
var place = "";
var parameters = [];
var files = [];
function setTab(name, m, n) {
for (var i = 1; i <= n; i++) {
@ -21,7 +22,21 @@ function setTab(name, m, n) {
}
}
function fileChange(event){
$.each(event.target.files, function(index, file) {
var reader = new FileReader();
reader.onload = function(event) {
object = {};
object.filename = file.name;
object.data = event.target.result;
files.push(object);
};
reader.readAsDataURL(file);
});
}
$(document).ready(function() {
loadPluginList();
loadPluginParams();
});
@ -56,6 +71,7 @@ function getPluginName(jsonData) {
var data = getParamInfoModelList(name.split("_")[0]);// paramInfoModels
document.getElementById("pluginParams").innerHTML += createAEditText(data,
name, i);
}
}
@ -196,6 +212,12 @@ function pluginFinish() {
var data = getParamInfoModelList(item);// paramInfoModels
document.getElementById("pluginParams").innerHTML += createAEditText(data,
pluginName, pluginChoosedList.length - 1);
alert($("input[type=file]").length);
$("input[type=file]").change(function(event){
fileChange(event);
});
}
function choosePlugin(selectedNode) {
@ -440,6 +462,8 @@ function createAEditText(data, name, index) {
+ name + "</p><div class='span12 box' style='margin-left:-2px;'>"
+ boxHeader + "<div class='box-content'>" + fieldHTML + "</div>"
+ "</div></div>";
console.log($("input[type=file]").lenth);
return documentHtml;
}
@ -455,3 +479,4 @@ $('#pluginCancel').click(function() {
$('#behaviorCancel').click(function() {
$('#myModal_Behavior').modal('hide');
});

View File

@ -1,45 +1,8 @@
var PluginNode = function() {
};
PluginNode.prototype.loadPluginParams = function() {
var pluginParamList=null;
$
.post(
"loadPluginUIList",
{},
function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
data = data.data;// List<PluginUIModel>pluginUIModels
for (var i = 0; i < data.length; i++) {
var pluginInfoModel = data[i].pluginInfoModel;
pluginParamList.push(pluginInfoModel.name);
pluginParamList[pluginInfoModel.name] = pluginInfoModel.paramInfoModels;
}
});
return pluginParamList;
};
PluginNode.prototype.getParamInfoModelList=function(plugin){
return this.pluginParamList[plugin];
};
PluginNode.prototype.createAPage=function(data, name, index){
var documentHtml = "";
var boxHeader = "";
var fieldHTML = "";
boxHeader = "<div class='box-header well' data-original-title> "
+ "<i class='icon-pencil left'></i>" + "<h2>sample:<i>" + name
+ "</i></h2></div>";
if (data != null) {
fieldHTML = createPluginsOrBehaviorsForm(data, index);
}
documentHtml = "<div id='" + index + "' class='hide'><p class='hide'>"
+ name + "</p><div class='span12 box' style='margin-left:-2px;'>"
+ boxHeader + "<div class='box-content'>" + fieldHTML + "</div>"
+ "</div></div>";
return documentHtml;
};
function setTab(name, m, n) {
for (var i = 1; i <= n; i++) {
var menu = document.getElementById(name + i);
var showDiv = document.getElementById("cont_" + name + "_" + i);
menu.className = i == m ? "on" : "";
showDiv.style.display = i == m ? "block" : "none";
}
}

View File

@ -19,7 +19,6 @@ function getvars() {
return vars;
}
$(function() {
var jsonData = getvars()['jsonData'];
if(jsonData!=null){

View File

@ -110,6 +110,9 @@ function refresh(){
location.replace(location) ;
}
//$('#createScript').click(function(){
// window.open("plugin.jsp");
//});
$('#createScript').click(function(){
window.open("plugin.jsp");
});
window.open("plugin-old.jsp");
});

View File

@ -3,7 +3,7 @@ function submit(selectedNode) {
saveBehaviorInfo();
savePluginInfo();
if (validateBehaviors(behaviors)) {
submitBehaviors(scriptName);
submitScriptWithScriptName(scriptName);
}
}
@ -130,7 +130,7 @@ function saveParamInfo(div) {
if (temp != "") {
value += temp + ";";
}
}
}
if (value != "") {
parameterModel = new ParameterModel(key, value);
parameters.push(parameterModel);
@ -147,7 +147,27 @@ function makePageList(behaviors) {
pageList.push(page);
}
function submitBehaviors(scriptName) {
function submitScriptByAjax(scriptModel){
$.ajax({
type : "POST",
url : "uploadEditScript",
data : {
content : JSON.stringify(scriptModel),
paramFiles : files
},
success : function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
data = data.data;
alert("upload success");
window.location.replace("script.jsp");
}
});
}
function submitScriptWithScriptName(scriptName) {
if (scriptName == null || scriptName == "") {
alert("Please input scriptName.");
return;
@ -163,19 +183,5 @@ function submitBehaviors(scriptName) {
var runScenarioModel = new RunScenarioModel(0, usePluginList, null,
pageList);
var scriptModel = new ScenarioModel(scriptName, runScenarioModel);
$.ajax({
type : "POST",
url : "uploadEditScript",
contentType : "application/json",
data : JSON.stringify(scriptModel),
success : function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
data = data.data;
alert("upload success");
window.location.replace("script.jsp");
}
});
submitScriptByAjax(scriptModel);
}

View File

@ -13,5 +13,5 @@ var add={
$("span[data='result']").text(result);
}
}
};

View File

@ -5,6 +5,6 @@ test("add.update", function() {
});
test("get num",function(){
var numbers=$("span[data='num']").text();
equal(numbers.length,2)
equal(numbers.length,2);
});

View File

@ -0,0 +1,77 @@
var files;
var file1;
var fileList = [];
test("upload files and other data", function() {
uploadFilesAndScript();
});
// function submitFiles() {
// var formData = new FormData();
// var file1 = $('#id1').files[0];
// var file2 = $('#id2').files[0];
// var fileList = new Array();
// fileList.push(file1);
// fileList.push(file2);
// formData.append("script", file1.files[0]);
// formData.append("scriptName", "testUploadFiles");
// formData.append("paramFiles", fileList);
// $.ajax({
// url : "uploadScript",
// type : "POST",
// data : formData,
// processData : false, // tell jQuery not to process the data
// contentType : false, // tell jQuery not to set contentType
// success : function(data) {
// alert(data);
// }
// });
// }
$(function() {
$("input[type=submit]").click(function() {
submit();
});
createFileInput(fileList);
});
function submit() {
uploadFilesAndScript();
}
function uploadFilesAndScript() {
var form = document.createElement("form");
$(form).attr("name", "fileUpload");
$("body").append($(form));
$(form).append($("#param"));
var formData = new FormData(form);
formData.append("content", "");
var oReq = new XMLHttpRequest();
oReq.open("POST", "../uploadEditScript");
oReq.send(formData);
alert(oReq.responseText);
}
function createFileInput(fileList) {
var fileContainer = $("#files");
var input = $(document.createElement("input"));
var lable = $(document.createElement("lable"));
lable.text("test");
input.attr("type", "file");
input.attr("name", "file");
input.attr("id","param");
fileContainer.append(lable);
fileContainer.append(input);
input.change(function(event) {
$.each(event.target.files, function(index, file) {
var reader = new FileReader();
reader.onload = function(event) {
object = {};
object.filename = file.name;
object.data = event.target.result;
fileList.push(object);
};
reader.readAsDataURL(file);
console.log(file.name);
});
console.log(fileList.length);
});
}

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>first test with Qunit</title>
<link rel="stylesheet"
href="http://code.jquery.com/qunit/qunit-1.14.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div id="files"></div>
<input type="submit" id="test"></input>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.min.js"></script>
<script src="http://code.jquery.com/qunit/qunit-1.14.0.js"></script>
<script src="js/testUploadFile.js"></script>
</body>
</html>

View File

@ -1,14 +1,11 @@
package org.bench4q.web.tool.test;
import static org.junit.Assert.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.web.service.CommunicateWithMaster;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -42,16 +39,11 @@ public class Test_CommunicateWithMaster {
@Test
public void test_uploadScriptWithParamFiles() {
String accessToken = this.loginHelper.login();
List<File> paramFiles = new ArrayList<File>();
String filePath = "ScriptParameters"
+ System.getProperty("file.separator") + "param1.txt";
TestHelper.createFileIfNotExist(new File(filePath));
paramFiles.add(new File(filePath));
HttpResponse httpResponse = this.communicateWithMaster
.uploadScriptWithParamFiles(accessToken, "test_chen",
new RunScenarioModel(), paramFiles);
System.out.println(httpResponse.getContent());
assertEquals(200, httpResponse.getCode());
}
}