diff --git a/Bench4Q-Web/src/main/webapp/createScript.jsp b/Bench4Q-Web/src/main/webapp/createScript.jsp index e29c7210..e8085e4e 100644 --- a/Bench4Q-Web/src/main/webapp/createScript.jsp +++ b/Bench4Q-Web/src/main/webapp/createScript.jsp @@ -108,20 +108,16 @@ body {
-
diff --git a/Bench4Q-Web/src/main/webapp/script/ScriptEditor/scriptEditor.js b/Bench4Q-Web/src/main/webapp/script/ScriptEditor/scriptEditor.js index 119fde9e..2ec78343 100644 --- a/Bench4Q-Web/src/main/webapp/script/ScriptEditor/scriptEditor.js +++ b/Bench4Q-Web/src/main/webapp/script/ScriptEditor/scriptEditor.js @@ -19,7 +19,7 @@ function getScriptObject(scriptId) { } else { // alert(data.script); var scriptObj = eval("(" + data.script + ")"); - createRadioGroupByAttribute(scriptObj.usePlugins, "name", "plugins", + createRadioGroupByAttribute(scriptObj.usePlugins, "nickName", "name","id","plugins", "usePluginList"); diff --git a/Bench4Q-Web/src/main/webapp/script/editor/behavior.js b/Bench4Q-Web/src/main/webapp/script/editor/behavior.js index a08e7a81..92f88e19 100644 --- a/Bench4Q-Web/src/main/webapp/script/editor/behavior.js +++ b/Bench4Q-Web/src/main/webapp/script/editor/behavior.js @@ -1,35 +1,46 @@ /** * */ -function Behavior() { +function BehaviorModel(pluginModel, method, id){ + this.pluginModel = pluginModel; + this.method = method; + this.id = id; + this.behaviorName = pluginModel.nickName+"_"+method+"_"+id; +} +function Behavior(usePlugin) { + this.usePlugin = usePlugin; this.behaviorList = new Array(); this.behaviorEditorMap = new HashMap(); this.index = 1; var behavior = this; + //init tree node container + jstreeCreate("useBehaviorList"); $("#addBehavior").click(function() { - - $("#usePlugins").html($("#usePluginList").html()); + behavior.showPluginList(); + // $("#usePlugins").html($("#usePluginList").html()); $("#selectBehavior").modal('show'); $("#addBehavior").addClass("clicked"); }); $("#insertBehaviorBefore").click(function() { - $("#usePlugins").html($("#usePluginList").html()); + behavior.showPluginList(); + // $("#usePlugins").html($("#usePluginList").html()); $("#selectBehavior").modal('show'); $("#insertBehaviorBefore").addClass("clicked"); }); $("#insertBehaviorAfter").click(function() { - $("#usePlugins").html($("#usePluginList").html()); + behavior.showPluginList(); + // $("#usePlugins").html($("#usePluginList").html()); $("#selectBehavior").modal('show'); $("#insertBehaviorAfter").addClass("clicked"); }); $("#selectBehavior").on( "click", - "input[name='usePlugin']", + "div[name='behavior_usePlugin']", function() { - var usePluginName = $( - "#selectBehavior input[name='usePlugin']:checked") + var pluginName = $( + "#selectBehavior input[name='behavior_usePlugin']:checked") .val(); - var pluginName = usePluginName.split("_")[0]; +// var pluginName = usePluginName.split("_")[0]; $.post("loadBehaviorList", { pluginName : pluginName }, function(data) { @@ -37,51 +48,51 @@ function Behavior() { alert("fail"); return; } - var methods = new Array(); - for ( var i = 0; i < data.behaviors.length; i++) { - methods.push(data.behaviors[i].name); - } +// var methods = new Array(); +// for ( var i = 0; i < data.behaviors.length; i++) { +// methods.push(data.behaviors[i].name); +// } $("#pluginMethod").html(""); - createRadioGroup(methods, "method", "pluginMethod"); + createRadioGroupByAttribute(data.behaviors, "name", "name", "name", "method", "pluginMethod") }); }); $("#selectBehavior #ok").click( function() { - var usePluginName = $( - "#usePlugins input[name='usePlugin']:checked").val(); + var usePluginId = $( + "#usePlugins input[name='behavior_usePlugin']:checked").attr("id"); var method = $("#pluginMethod input[name='method']:checked") .val(); - if (usePluginName == undefined || method == undefined) { + var pluginId = usePluginId.split("_")[2]; + if (pluginId == undefined || method == undefined) { return; } - var behaviorName = usePluginName + "_" + method + "_" - + behavior.index; - behavior.index++; - jstreeCreate("useBehaviorList"); + var behaviorModel = new BehaviorModel(behavior.usePlugin.map.get(pluginId),method,behavior.index); + if ($("#addBehavior").hasClass("clicked")) { var pos = "last"; - behavior.appendBehavior(behaviorName); - jstreeCreateNode("useBehaviorList",behaviorName,behavior.index,pos); + behavior.appendBehavior( behaviorModel); + jstreeCreateNode("useBehaviorList", behaviorModel.behaviorName,behaviorModel.id,pos); $("#addBehavior").removeClass("clicked"); } else if ($("#insertBehaviorBefore").hasClass("clicked")) { var pos = "before"; behavior.insertBehavior(behaviorName);//前插入和后插入一样?? - jstreeCreateNode("useBehaviorList",behaviorName,behavior.index,pos); + jstreeCreateNode("useBehaviorList", behaviorModel.behaviorName,behaviorModel.id,pos); $("#insertBehaviorBefore").removeClass("clicked"); } else { var pos = "after"; behavior.insertBehavior(behaviorName);//前插入和后插入一样?? - jstreeCreateNode("useBehaviorList",behaviorName,behavior.index,pos); + jstreeCreateNode("useBehaviorList", behaviorModel.behaviorName,behaviorModel.id,pos); $("#insertBehaviorAfter").removeClass("clicked"); } + behavior.updateBehaviorEditors(); behavior.createBehaviorEditor(behaviorName); $("#selectBehavior").modal('hide'); $("#usePlugins").html(""); $("#pluginMethod").html(""); - + behavior.index++; }); $("#selectBehavior #cancel").click(function() { $("#selectBehavior").modal('hide'); @@ -210,4 +221,14 @@ function Behavior() { } } + this.showPluginList = function(){ + $("#usePlugins").html(""); + var keys = usePlugin.map.getKeys(); + for (var i = 0; i < keys.length; i++) { + var pluginModel = usePlugin.map.get(keys[i]); + $("#usePlugins").append( + createRadio("behavior_plugin_"+pluginModel.id,pluginModel.nickName, "behavior_usePlugin",pluginModel.name)); + } + } + } diff --git a/Bench4Q-Web/src/main/webapp/script/editor/createScript.js b/Bench4Q-Web/src/main/webapp/script/editor/createScript.js index b303d29a..ebfac661 100644 --- a/Bench4Q-Web/src/main/webapp/script/editor/createScript.js +++ b/Bench4Q-Web/src/main/webapp/script/editor/createScript.js @@ -2,7 +2,7 @@ $(function() { $("#tabs").tabs(); var usePlugin = new UsePlugin(); usePlugin.getPluginList(); - var behavior = new Behavior(); + var behavior = new Behavior(usePlugin); var collectScriptData = new CollectScriptData(usePlugin, behavior); $("#submitScript").click(function() { submitScript(collectScriptData); diff --git a/Bench4Q-Web/src/main/webapp/script/editor/uiFactory.js b/Bench4Q-Web/src/main/webapp/script/editor/uiFactory.js index 96696b3e..cf66422a 100644 --- a/Bench4Q-Web/src/main/webapp/script/editor/uiFactory.js +++ b/Bench4Q-Web/src/main/webapp/script/editor/uiFactory.js @@ -1,37 +1,48 @@ function createRadioGroup(items,name,containerId){ for ( var i = 0; i < items.length; i++) { - var radio = createRadio(items[i],name,items[i]); + var radio = createRadio(items[i],items[i],name,items[i]); $("#" + containerId).append(radio); } } /** - * @param item 显示文本 - * @param name 统一radio - * @param id 方便label标签和div选择 - * @returns + * @param id synchronize the radio, label and div + * @param text show in the web + * @param name this is same in a radio group + * @param value + * @returns */ -function createRadio (item,name,id) { - var line = $("
"); +function createRadio (id,text,name,value) { + var line = $("
"); line.click(function(){ document.getElementById(id).checked = true; }) var input = $(""); - input.attr("value",item); + input.attr("value",value); + input.attr("text",text); var span = $("