behavior edit success

This commit is contained in:
hmm 2014-08-20 14:15:32 +08:00
parent e92560e3a8
commit 9d874db5be
8 changed files with 122 additions and 197 deletions

View File

@ -214,14 +214,15 @@ public class ScriptController extends BaseController {
@ResponseBody
public Map<String, Object> submitScriptCreated(
@ModelAttribute("accessToken") String accessToken,
@RequestBody ScenarioModel scenarioModel,
// @RequestBody ScenarioModel scenarioModel,
@RequestBody RunScenarioModel runScenarioModel,
@PathVariable String scriptName,
@RequestParam(required = false) MultipartFile[] paramFiles) {
Map<String, Object> map = new HashMap<String, Object>();
RunScenarioModel runScenarioModel = this.getScriptService()
.createRunScenarioModel(scenarioModel.getUsePlugins(),
scenarioModel.getBehaviors());
// RunScenarioModel runScenarioModel = this.getScriptService()
// .createRunScenarioModel(scenarioModel.getUsePlugins(),
// scenarioModel.getBehaviors());
OperateScriptServerResponseModel operateScriptServerResponseModel = this
.getScriptMessager().uploadScript(accessToken, scriptName,
MarshalHelper.tryMarshal(runScenarioModel), paramFiles);

View File

@ -128,7 +128,7 @@ body {
</div>
<div>
<button type="submit" class="btn btn-primary btn-width"
id="cleaBehavior">
id="clearBehavior">
<fmt:message key="plugin_jsp_clear" />
</button>
</div>

View File

@ -1,11 +1,4 @@
/**
*
*/
/**
* @param pluginModel
* @param method
* @param id
*/
function BehaviorViewModel(pluginModel, method, id) {
this.pluginModel = pluginModel;
this.method = method;
@ -38,7 +31,7 @@ function Behavior(usePlugin) {
$("#addBehavior").click(function() {
// selected node's type
var selectedNodes = behavior.getSelectedNodes();
var selectedNodes = getSelectedNodes(behavior.containerId);
if (!selectedNodes.length) {
// add page
behavior.showPage();
@ -61,7 +54,7 @@ function Behavior(usePlugin) {
});
$("#insertChildNode").click(function() {
var selectedNodes = behavior.getSelectedNodes();
var selectedNodes = getSelectedNodes(behavior.containerId);
if (!selectedNodes.length) {
return;
} else {
@ -87,6 +80,8 @@ function Behavior(usePlugin) {
var type = selected.node.data;
if (type == "page" || type == "batch") {
$("#insertChildDiv").removeClass("hide");
behavior.updateBehaviorEditors();
} else {
$("#insertChildDiv").addClass("hide");
@ -97,18 +92,6 @@ function Behavior(usePlugin) {
}
});
// $("#insertBehaviorBefore").click(function() {
// behavior.showPluginList();
// // $("#usePlugins").html($("#usePluginList").html());
// $("#selectBehavior").modal('show');
// $("#insertBehaviorBefore").addClass("clicked");
// });
// $("#insertBehaviorAfter").click(function() {
// behavior.showPluginList();
// // $("#usePlugins").html($("#usePluginList").html());
// $("#selectBehavior").modal('show');
// $("#insertBehaviorAfter").addClass("clicked");
// });
$("#selectBehavior")
.on(
"click",
@ -155,58 +138,22 @@ function Behavior(usePlugin) {
}
// deal page and batch
if (pluginId == "page") {
// add page
// var pageModel = new PageModel(behavior.index,
// new HashMap());
// behavior.pagesMap.put(pageModel.id, pageModel);
// add page to web
jstreeCreateNode("useBehaviorList", "page", "page",
jstreeCreateNode(behavior.containerId, "page", "page",
behavior.index, pos);
behavior.updateBehaviorEditors();
jstreeSelectNode(behavior.containerId, behavior.index);
} else if (pluginId == "batch") {
// get page id
// var selectedNodes = behavior.getSelectedNodes();
// if (selectedNodes.length) {
// var currNode = selectedNodes[0];
// var pageId;
// if (currNode.data == "page") {
// pageId = currNode.id;
// } else {
// pageId = currNode.parent[0];
// }
// var pageModel = behavior.pagesMap.get(pageId);
// var batchModel = new BatchModel(behavior.index,
// -1, -1, new HashMap());
var batchViewModel = new BatchViewModel(behavior.index, -1,
-1);
behavior.batchMap.put(batchViewModel.id, batchViewModel);
// add batch to web
jstreeCreateNode("useBehaviorList", "batch", "batch",
batchViewModel.id, pos);
// }
behavior.updateBehaviorEditors();
jstreeSelectNode(behavior.containerId, behavior.index);
} else {
if (pluginId == undefined || method == undefined) {
return;
}
// // get page id
// var selectedNodes = behavior.getSelectedNodes();
// if (!selectedNodes.length) {
// return;
// }
// var currNode = selectedNodes[0];
// var pageModel;
// var batchModel;
// if (currNode.data == "batch") {
// pageModel = behavior.pagesMap.get(currNode.parents[0]);
// batchModel = pageModel.batches.get(currNode.id);
// } else {
// var len = currNode.parents.length;
// pageModel = behavior.pagesMap
// .get(currNode.parents[len - 2]);
// batchModel = pageModel.batches
// .get(currNode.parents[len - 3]);
// }
var pluginModel = behavior.usePlugin.map.get(pluginId);
var behaviorViewModel = new BehaviorViewModel(
@ -214,7 +161,6 @@ function Behavior(usePlugin) {
jstreeCreateNode("useBehaviorList", behaviorViewModel.method,behaviorViewModel.behaviorName, behaviorViewModel.id, pos);
behavior.behaviorList.push(behaviorViewModel);
behavior.updateBehaviorEditors();
behavior.createBehaviorEditor(behaviorViewModel);
}
@ -231,7 +177,7 @@ function Behavior(usePlugin) {
$("#removeBehavior").click(
function() {
// selected node's type
var selectedNodes = behavior.getSelectedNodes();
var selectedNodes = getSelectedNodes(behavior.containerId);
if (!selectedNodes.length) {
return;
}
@ -254,37 +200,27 @@ function Behavior(usePlugin) {
$("#behaviorEditor").html("");
$("#behaviorEditor").attr("behavior", "");
});
$("#cleaBehavior").click(function() {
$("#useBehaviorList").html("");
$("#clearBehavior").click(function() {
behavior.behaviorList = [];
behavior.behaviorEditorMap.clear();
//clear tree
jstreeClearNode(behavior.containerId);
})
// $("#useBehaviorList").on(
// "click",
// "input[name='useBehavior']",
// function() {
// var behaviorName = $(
// "#useBehaviorList input[name='useBehavior']:checked")
// .val();
// behavior.updateBehaviorEditors();
// $("#behaviorEditor").append(
// behavior.behaviorEditorMap.get(behaviorName));
// $("#behaviorEditor").attr("behavior", behaviorName);
// });
this.updateBehaviorEditors = function() {
if ($("#behaviorEditor").attr("behavior") == undefined
|| $("#behaviorEditor").attr("behavior") == "") {
return;
}
this.behaviorEditorMap.put($("#behaviorEditor").attr("behavior"), $(
"#behaviorEditor div:first").clone())
"#behaviorEditor div:first").clone(true))
$("#behaviorEditor").attr("behavior","")
$("#behaviorEditor").html("");
}
this.createBehaviorEditor = function(behaviorModel) {
var pluginName = behaviorModel.pluginModel.name;// this.getPluginName(behaviorName);
var methodName = behaviorModel.method;// this.getBehaviorMethod(behaviorName);
var pluginName = behaviorModel.pluginModel.name;
var methodName = behaviorModel.method;
var containerFactory = new ContainerFactory();
$.post("getPluginMethod" + "/" + pluginName + "/" + methodName, {},
function(data) {
@ -296,7 +232,7 @@ function Behavior(usePlugin) {
$(generator).addClass("generator");
behavior.behaviorEditorMap.put(behaviorModel.id,
generator);
jstreeSelectNode(behavior.containerId, behaviorModel.id);
} else {
return;
}
@ -320,34 +256,9 @@ function Behavior(usePlugin) {
this.behaviorList[i + 1] = this.behaviorList[i];
}
}
// this.updateUseBehavior();
}
/*
* this.updateUseBehavior = function() { $("#useBehaviorList").html("");
*
* for ( var i = 0; i < this.behaviorList.length; i++) {
* $("#useBehaviorList").append( createRadio(this.behaviorList[i],
* "useBehavior")); } }
*/
this.getUsePluginName = function(behaviorName) {
var parts = behaviorName.split("_");
return parts[0] + "_" + parts[1];
}
this.getPluginName = function(behaviorName) {
return behaviorName.split("_")[0];
}
this.getBehaviorMethod = function(behaviorName) {
return behaviorName.split("_")[2];
}
// this.getBehaviorType = function(behaviorName) {
// var pluginName = this.getPluginName(behaviorName);
// if (pluginName == "ConstantTimer") {
// return "TIMERBEHAVIOR";
// } else {
// return "USERBEHAVIOR";
// }
// }
this.getBehaviorType = function(pluginName) {
if (pluginName == "ConstantTimer") {
return "TIMERBEHAVIOR";
@ -355,12 +266,6 @@ function Behavior(usePlugin) {
return "USERBEHAVIOR";
}
}
//function about tree
this.getSelectedNodes = function() {
var treeObj = $("#" + behavior.containerId).jstree(true);
return treeObj.get_selected(true);
}
//end function about tree
this.showPluginList = function() {
$("#usePlugins").html("");
var keys = usePlugin.map.getKeys();

View File

@ -4,8 +4,8 @@ $(function() {
usePlugin.getPluginList();
var behavior = new Behavior(usePlugin);
var collectScriptData = new CollectScriptData(usePlugin, behavior);
// var collectScriptData = new CollectScriptData(usePlugin, behavior);
$("#submitScript").click(function() {
submitScript(collectScriptData);
submitScript(behavior);
});
});

View File

@ -24,6 +24,7 @@ function jstreeCreateNode(containerId,data,name,id,pos){
}
/**
* delete current node
* @param containerId the id of jstree container
*/
function jstreeDeleteNode(containerId){
@ -33,7 +34,6 @@ function jstreeDeleteNode(containerId){
ref.delete_node(parentNode);
return ref.element.context.id;
}
/**
* @param containerId the id of jstree container
* @param node the id of to be selected node
@ -85,4 +85,21 @@ function jstreeCreate(containerId){
}
})
return $("#"+containerId).jstree(true);
}
function getSelectedNodes(containerId){
var treeObj = $("#"+containerId).jstree(true);
return treeObj.get_selected(true);
}
/**
* @param containerId the id of jstree container
*/
function jstreeClearNode(containerId){
var ref = $("#"+containerId).jstree(true);
var parentNode = ref.get_selected("#");
if(!parentNode.length){return false;}
ref.delete_node(parentNode);
return ref.element.context.id;
}

View File

@ -101,7 +101,7 @@ EditorFactory.prototype.createFieldLine = function(size, name, value) {
$(fieldName).html(name);
var field = document.createElement("input");
$(field).attr("type", "text");
$(field).attr("maxlength", size);
// $(field).attr("maxlength", size);
$(field).attr("value", value);
$(fieldDiv).append(fieldName.outerHTML + field.outerHTML);
return fieldDiv;
@ -119,7 +119,7 @@ EditorFactory.prototype.createFile = function(label, name, size, id, value) {
$(fieldName).html(name);
var file = document.createElement("input");
$(file).attr("type", "file");
$(field).attr("maxlength", size);
// $(field).attr("maxlength", size);
$(fileEditor).append(fieldName.outerHTML + file.outerHTML);
$(div).children(".editor").append(fileEditor);
return div;
@ -172,6 +172,7 @@ EditorFactory.prototype.createTable = function(label, name, cols, id, value) {
}
function createTable(cols, name, headers, value) {
value==null?value="":value;
var values = value.split(";");
var table = document.createElement("table");
var thead = document.createElement("thead");
@ -199,6 +200,7 @@ EditorFactory.prototype.createTable = function(label, name, cols, id, value) {
return tr;
}
function createTr(headers, name, value) {
value == null? value="":value;
var values = value.split("|");
var tr = document.createElement("tr");
// var td = document.createElement("td");

View File

@ -1,77 +1,77 @@
function CollectScriptData(usePlugin, behavior) {
this.usePlugin = usePlugin;
this.behavior = behavior;
this.usePlugins = new Array();
this.behaviors = new Array();
this.paramDataCollector = new DataCollector();
this.collectUsePlugin = function() {
this.usePlugin.updateUsePlugin();
var keys = this.usePlugin.map.getKeys();
var usePlugins = new Array();
for ( var i = 0; i < keys.length; i++) {
var id = keys[i];
var pluginName = this.usePlugin.map.get(id);
var usePluginName = pluginName + "_" + id;
var usePluginContainer = this.usePlugin.usePluginEditorMap
.get(usePluginName);
var params = this.paramDataCollector.getUnitParams($(
usePluginContainer).find(".editor"));
usePlugins.push(new UsePluginModel(usePluginName, pluginName, params));
}
return usePlugins;
//function CollectScriptData(usePlugin, behavior) {
// this.usePlugin = usePlugin;
// this.behavior = behavior;
// this.usePlugins = new Array();
// this.behaviors = new Array();
// this.paramDataCollector = new DataCollector();
// this.collectUsePlugin = function() {
// this.usePlugin.updateUsePlugin();
// var keys = this.usePlugin.map.getKeys();
// var usePlugins = new Array();
// for ( var i = 0; i < keys.length; i++) {
// var id = keys[i];
// var pluginName = this.usePlugin.map.get(id);
// var usePluginName = pluginName + "_" + id;
// var usePluginContainer = this.usePlugin.usePluginEditorMap
// .get(usePluginName);
// var params = this.paramDataCollector.getUnitParams($(
// usePluginContainer).find(".editor"));
// usePlugins.push(new UsePluginModel(usePluginName, pluginName, params));
// }
// return usePlugins;
//
// }
//
// this.collectBehavior = function() {
// this.behavior.updateBehaviorEditors();
// var behaviorList = this.behavior.behaviorList;
// var behaviors = new Array();
// for ( var i = 0; i < behaviorList.length; i++) {
// var id = i;
// var use = behaviorList[i].split("_")[0]
// +"_"+ behaviorList[i].split("_")[1];
// var name = this.behavior.getBehaviorMethod(behaviorList[i]);
// var type = this.behavior.getBehaviorType(behaviorList[i]);
// var behaviorContainer = behaviorList[i];
// var params = this.paramDataCollector.getUnitParams($(
// this.behavior.behaviorEditorMap.get(behaviorList[i])).find(
// ".editor"));
// behaviors
// .push(new BehaviorModel(id, use, name, type, params));
// }
// return behaviors;
//
// }
// function getPluginData(id, container, pluginName) {
// var dataCollector = new DataCollector();
//
// return new UsePluginModel(id, pluginName, params)
// }
//
//}
//
//var ParameterModel = function(key, value) {
// this.key = key;
// this.value = value;
//}
//var UsePluginModel = function(id, name, parameters) {
// this.id = id;
// this.name = name;
// this.parameters = parameters;
//}
//var BehaviorModel = function(id, use, name, type, parameters) {
// this.id = id;
// this.name = name;
// this.type = type;
// this.use = use;
// this.parameters = parameters;
//}
//var ScenarioModel = function(usePlugins, behaviors) {
// this.usePlugins = usePlugins;
// this.behaviors = behaviors;
//}
}
this.collectBehavior = function() {
this.behavior.updateBehaviorEditors();
var behaviorList = this.behavior.behaviorList;
var behaviors = new Array();
for ( var i = 0; i < behaviorList.length; i++) {
var id = i;
var use = behaviorList[i].split("_")[0]
+"_"+ behaviorList[i].split("_")[1];
var name = this.behavior.getBehaviorMethod(behaviorList[i]);
var type = this.behavior.getBehaviorType(behaviorList[i]);
var behaviorContainer = behaviorList[i];
var params = this.paramDataCollector.getUnitParams($(
this.behavior.behaviorEditorMap.get(behaviorList[i])).find(
".editor"));
behaviors
.push(new BehaviorModel(id, use, name, type, params));
}
return behaviors;
}
function getPluginData(id, container, pluginName) {
var dataCollector = new DataCollector();
return new UsePluginModel(id, pluginName, params)
}
}
var ParameterModel = function(key, value) {
this.key = key;
this.value = value;
}
var UsePluginModel = function(id, name, parameters) {
this.id = id;
this.name = name;
this.parameters = parameters;
}
var BehaviorModel = function(id, use, name, type, parameters) {
this.id = id;
this.name = name;
this.type = type;
this.use = use;
this.parameters = parameters;
}
var ScenarioModel = function(usePlugins, behaviors) {
this.usePlugins = usePlugins;
this.behaviors = behaviors;
}
function submitScript(collectScriptData) {
function submitScript(behavior) {
var usePlugins = collectScriptData.collectUsePlugin();
var behaviors = collectScriptData.collectBehavior();
var scenarioModel = new ScenarioModel(usePlugins, behaviors);