add behavior tree editor
This commit is contained in:
parent
d59306aa3f
commit
d6e03a7393
|
@ -0,0 +1,250 @@
|
|||
<!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">
|
||||
<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">
|
||||
<link href="lib/jquery/css/jquery-ui-1.10.4.css" rel="stylesheet">
|
||||
<link href='css/scriptEditor.css' rel='stylesheet'>
|
||||
<link rel="shortcut icon" href="images/bench4q.png">
|
||||
<link rel="stylesheet" href="lib/bootstrap/bootstrap.css" />
|
||||
<link rel="stylesheet" href="css/style.min.css" />
|
||||
<style type="text/css">
|
||||
body {
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
padding: 9px 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<fmt:bundle basename="i18n">
|
||||
<jsp:include page="publiccontrol/navigatebar.jsp"></jsp:include>
|
||||
<div class="container-fluid">
|
||||
<div class="row-fluid">
|
||||
<jsp:include page="publiccontrol/leftmenubar.jsp"></jsp:include>
|
||||
<div id="content" class="span10">
|
||||
<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="createScript.jsp"><fmt:message
|
||||
key="home-createScript" /></a></li>
|
||||
</ul>
|
||||
<div id="tabs">
|
||||
<ul>
|
||||
<li><a href="#usePluginPanel"><fmt:message
|
||||
key="plugin_jsp_plugins" />(usePlugins)</a></li>
|
||||
<li><a href="#behavior"><fmt:message
|
||||
key="plugin_jsp_behavior" />(behaviors)</a></li>
|
||||
<li><a href="#submitScriptPanel"><fmt:message
|
||||
key="script-submitScript" /></a></li>
|
||||
</ul>
|
||||
<div id="usePluginPanel">
|
||||
<div class="span5 editorContainer">
|
||||
<div class="header">
|
||||
<h4>
|
||||
<span><fmt:message key="plugin_jsp_plugins" />(usePlugins)</span>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="row-fluid ">
|
||||
<div class="span9 " id="usePluginList"></div>
|
||||
<div class="span3 buttonsControl ">
|
||||
<div>
|
||||
<button type="submit" class="btn btn-primary btn-width"
|
||||
id="addPlugin">
|
||||
<fmt:message key="plugin_jsp_add" />
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-primary btn-width"
|
||||
id="removePlugin">
|
||||
<fmt:message key="plugin_jsp_remove" />
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-primary btn-width"
|
||||
id="clearPlugin">
|
||||
<fmt:message key="plugin_jsp_clear" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="span7 editorContainer">
|
||||
|
||||
<div class="header">
|
||||
<h4>
|
||||
<span><fmt:message key="plugin_jsp_plugins" />(usePlugins)</span>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="pluginEditor"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="behavior">
|
||||
<div class="span5 editorContainer">
|
||||
<div class="header">
|
||||
<h4>
|
||||
<span><fmt:message key="plugin_jsp_behavior" />
|
||||
(behaviors)</span>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="span9" id="useBehaviorList">
|
||||
|
||||
</div>
|
||||
<div class="span3 buttonsControl">
|
||||
<div id="insertChildDiv" class="hide">
|
||||
<button type="submit" class="btn btn-primary btn-width"
|
||||
id="insertChildNode">
|
||||
<fmt:message key="plugin_jsp_insertChild" />
|
||||
</button>
|
||||
</div>
|
||||
<div id="addBehaviorDiv">
|
||||
<button type="submit" class="btn btn-primary btn-width"
|
||||
id="addBehavior">
|
||||
<fmt:message key="plugin_jsp_add" />
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-primary btn-width"
|
||||
id="removeBehavior">
|
||||
<fmt:message key="plugin_jsp_remove" />
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-primary btn-width"
|
||||
id="cleaBehavior">
|
||||
<fmt:message key="plugin_jsp_clear" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span7 editorContainer">
|
||||
<div class="header">
|
||||
<h4>
|
||||
<span><fmt:message key="plugin_jsp_behavior" />
|
||||
(behaviors)</span>
|
||||
</h4>
|
||||
|
||||
</div>
|
||||
<div id="behaviorEditor"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="submitScriptPanel">
|
||||
<div class="span12">
|
||||
<label><fmt:message key="scriptname" /></label> <input
|
||||
type='text' name='scriptName' id="scriptName"></input>
|
||||
<button id="submitScript" type="submit" class="btn btn-primary">
|
||||
<fmt:message key="script-submitScript" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
<div class="modal hide fade " id="selectUsePlugin">
|
||||
<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"">
|
||||
<div class="inset scroll" id="pluginList"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
||||
<button type="button" class="btn btn-primary btn-width" id="ok">
|
||||
<fmt:message key="plugin_jsp_finish" />
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary btn-width" id="cancel">
|
||||
<fmt:message key="plugin_jsp_cancel" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal hide fade " id="selectBehavior">
|
||||
<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="usePlugins"></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" id="ok">
|
||||
<fmt:message key="plugin_jsp_finish" />
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary btn-width" onClick=""
|
||||
id="cancel">
|
||||
<fmt:message key="plugin_jsp_cancel" />
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<jsp:include page="publiccontrol/footer.jsp"></jsp:include>
|
||||
</div>
|
||||
<script
|
||||
src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.min.js"></script>
|
||||
<script src="lib/jquery/js/jquery-ui-1.10.4.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="lib/chrisma/js/jquery.cookie.js"></script>
|
||||
<script src="lib/chrisma/js/theme.js"></script>
|
||||
<!-- <script src="script/base.js"></script> -->
|
||||
<script src="lib/HashMap/HashMap.js"></script>
|
||||
<!-- <script src="lib/other/jstree.js"></script> -->
|
||||
<script src="script/editor/pluginEditor/editorFactory.js"></script>
|
||||
<script src="script/editor/pluginEditor/dataFormat.js"></script>
|
||||
<script src="script/editor/pluginEditor/containerFactory.js"></script>
|
||||
<script src="script/editor/pluginEditor/dataCollect.js"></script>
|
||||
<script src="script/editor/uiFactory.js"></script>
|
||||
<script src="script/editor/jstreeFactory.js"></script>
|
||||
<script src="script/editor/behavior.js"></script>
|
||||
<script src="script/editor/usePlugin.js"></script>
|
||||
<script src="script/editor/submitScript.js"></script>
|
||||
<script src="script/editor/createScript.js"></script>
|
||||
|
||||
<script src="script/ScriptEditor/pluginModel.js"></script>
|
||||
|
||||
<!-- <script src="script/editor/jquery.js"></script>-->
|
||||
<script src="script/editor/jstree.js"></script>
|
||||
<script src="lib/other/jstree.min.js"></script>
|
||||
</fmt:bundle>
|
||||
</body>
|
||||
</html>
|
|
@ -1 +0,0 @@
|
|||
/uiFactory.js
|
|
@ -0,0 +1,379 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
function BehaviorViewModel(pluginModel, method, id) {
|
||||
this.pluginModel = pluginModel;
|
||||
this.method = method;
|
||||
this.id = id;
|
||||
this.behaviorName = pluginModel.nickName + "_" + method + "_" + id;
|
||||
}
|
||||
|
||||
function Behavior(usePlugin) {
|
||||
this.containerId = "useBehaviorList"
|
||||
this.usePlugin = usePlugin;
|
||||
this.behaviorList = new Array();
|
||||
this.behaviorEditorMap = new HashMap();
|
||||
this.pagesMap = new HashMap();
|
||||
this.index = 1;
|
||||
var behavior = this;
|
||||
// init tree node container
|
||||
jstreeCreate(this.containerId);
|
||||
|
||||
$("#addBehavior").click(function() {
|
||||
// selected node's type
|
||||
var selectedNodes = behavior.getSelectedNodes();
|
||||
if (!selectedNodes.length) {
|
||||
// add page
|
||||
behavior.showPage();
|
||||
} else {
|
||||
var currNode = selectedNodes[0];
|
||||
var currNodeType = currNode.data;
|
||||
if (currNodeType == "page") {
|
||||
// add page
|
||||
behavior.showPage();
|
||||
} else if (currNodeType == "batch") {
|
||||
// add batch
|
||||
behavior.showBatch();
|
||||
} else {
|
||||
// add behavior
|
||||
behavior.showPluginList();
|
||||
}
|
||||
}
|
||||
$("#selectBehavior").modal('show');
|
||||
$("#addBehavior").addClass("clicked");
|
||||
});
|
||||
$("#insertChildNode").click(function() {
|
||||
|
||||
var selectedNodes = behavior.getSelectedNodes();
|
||||
if (!selectedNodes.length) {
|
||||
return;
|
||||
} else {
|
||||
var currNode = selectedNodes[0];
|
||||
var currNodeType = currNode.data;
|
||||
if (currNodeType == "page") {
|
||||
// add batch
|
||||
behavior.showBatch();
|
||||
} else if (currNodeType == "batch") {
|
||||
// add behavior
|
||||
behavior.showPluginList();
|
||||
} else {
|
||||
// other container behavior;
|
||||
}
|
||||
}
|
||||
$("#selectBehavior").modal('show');
|
||||
$("#insertChildNode").addClass("clicked");
|
||||
});
|
||||
|
||||
$("#useBehaviorList").bind("select_node.jstree",
|
||||
function(node, selected, event) {
|
||||
var type = selected.node.data;
|
||||
if (type == "page" || type == "batch") {
|
||||
$("#insertChildDiv").removeClass("hide");
|
||||
} else {
|
||||
$("#insertChildDiv").addClass("hide");
|
||||
|
||||
behavior.updateBehaviorEditors();
|
||||
$("#behaviorEditor").append(
|
||||
behavior.behaviorEditorMap.get(selected.node.id));
|
||||
$("#behaviorEditor").attr("behavior", selected.node.id);
|
||||
}
|
||||
|
||||
});
|
||||
// $("#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",
|
||||
"div[name='behavior_usePlugin']",
|
||||
function() {
|
||||
var pluginName = $(
|
||||
"#selectBehavior input[name='behavior_usePlugin']:checked")
|
||||
.val();
|
||||
if (pluginName == "page" || pluginName == "batch") {
|
||||
return;
|
||||
}
|
||||
$.post("loadBehaviorList", {
|
||||
pluginName : pluginName
|
||||
}, function(data) {
|
||||
if (!data.success) {
|
||||
alert("fail");
|
||||
return;
|
||||
}
|
||||
$("#pluginMethod").html("");
|
||||
createRadioGroupByAttribute(data.behaviors, "name",
|
||||
"name", "name", "method", "pluginMethod")
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$("#selectBehavior #ok")
|
||||
.click(
|
||||
function() {
|
||||
var usePluginId = $(
|
||||
"#usePlugins input[name='behavior_usePlugin']:checked")
|
||||
.attr("id");
|
||||
var method = $(
|
||||
"#pluginMethod input[name='method']:checked")
|
||||
.val();
|
||||
var pluginId = usePluginId.split("_")[2];
|
||||
// get add type, insert or add
|
||||
var pos;
|
||||
if ($("#insertChildNode").hasClass("clicked")) {
|
||||
pos = "last";
|
||||
$("#insertChildNode").removeClass("clicked")
|
||||
} else {
|
||||
pos = "after";
|
||||
$("#addBehavior").removeClass("clicked");
|
||||
|
||||
}
|
||||
// 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",
|
||||
pageModel.id, pos);
|
||||
behavior.updateBehaviorEditors();
|
||||
} 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());
|
||||
pageModel.batches
|
||||
.put(batchModel.id, batchModel);
|
||||
// add batch to web
|
||||
jstreeCreateNode("useBehaviorList", "batch",
|
||||
"batch", batchModel.id, pos);
|
||||
}
|
||||
behavior.updateBehaviorEditors();
|
||||
} 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 behaviorModel = new BehaviorModel(
|
||||
behavior.index, pluginModel, method,
|
||||
behavior.getBehaviorType(pluginModel.name),
|
||||
new HashMap());
|
||||
|
||||
batchModel.behaviors.put(behaviorModel);
|
||||
jstreeCreateNode("useBehaviorList",
|
||||
behaviorModel.name,
|
||||
behaviorModel.use.nickName + "_"
|
||||
+ behaviorModel.name + "_"
|
||||
+ behaviorModel.id,
|
||||
behaviorModel.id, pos);
|
||||
|
||||
behavior.updateBehaviorEditors();
|
||||
behavior.createBehaviorEditor(behaviorModel);
|
||||
|
||||
}
|
||||
$("#selectBehavior").modal('hide');
|
||||
$("#usePlugins").html("");
|
||||
$("#pluginMethod").html("");
|
||||
behavior.index++;
|
||||
});
|
||||
$("#selectBehavior #cancel").click(function() {
|
||||
$("#selectBehavior").modal('hide');
|
||||
$("#usePlugins").html("");
|
||||
$("#pluginMethod").html("");
|
||||
});
|
||||
$("#removeBehavior").click(
|
||||
function() {
|
||||
var behaviorName = $(
|
||||
"#useBehaviorList input[name='useBehavior']:checked")
|
||||
.val();
|
||||
if (behaviorName == undefined) {
|
||||
return;
|
||||
}
|
||||
var index = behavior.behaviorList.length;
|
||||
for (var i = 0; i < behavior.behaviorList.length; i++) {
|
||||
|
||||
if (behavior.behaviorList[i] == behaviorName) {
|
||||
index = i;
|
||||
}
|
||||
|
||||
}
|
||||
behavior.behaviorList.splice(index, 1);
|
||||
|
||||
|
||||
behavior.behaviorEditorMap.remove(behaviorName);
|
||||
|
||||
$("#behaviorEditor").html("");
|
||||
$("#behaviorEditor").attr("behavior", "");
|
||||
});
|
||||
$("#cleaBehavior").click(function() {
|
||||
$("#useBehaviorList").html("");
|
||||
behavior.behaviorList = [];
|
||||
})
|
||||
$("#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").html("");
|
||||
|
||||
}
|
||||
this.createBehaviorEditor = function(behaviorModel) {
|
||||
|
||||
var pluginName = behaviorModel.use.name;// this.getPluginName(behaviorName);
|
||||
var methodName = behaviorModel.name;// this.getBehaviorMethod(behaviorName);
|
||||
var containerFactory = new ContainerFactory();
|
||||
$.post("getPluginMethod" + "/" + pluginName + "/" + methodName, {},
|
||||
function(data) {
|
||||
if (data.success) {
|
||||
var methodData = dataTransfer(data.method);
|
||||
var generator = containerFactory.createEditorContainer(
|
||||
methodName, "generator", methodData);
|
||||
|
||||
$(generator).addClass("generator");
|
||||
behavior.behaviorEditorMap.put(behaviorModel.id,
|
||||
generator);
|
||||
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
this.appendBehavior = function(behaviorName) {
|
||||
|
||||
this.behaviorList.push(behaviorName);
|
||||
}
|
||||
this.insertBehavior = function(behaviorName) {
|
||||
var behaviorBeforeName = $(
|
||||
"#useBehaviorList input[name='useBehavior']:checked").val();
|
||||
this.behaviorList.push(null);
|
||||
for (var i = this.behaviorList.length - 2; i >= 0; i--) {
|
||||
if (this.behaviorList[i] == behaviorBeforeName) {
|
||||
this.behaviorList[i + 1] = behaviorName;
|
||||
break;
|
||||
} else {
|
||||
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";
|
||||
} else {
|
||||
return "USERBEHAVIOR";
|
||||
}
|
||||
}
|
||||
|
||||
this.getSelectedNodes = function() {
|
||||
var treeObj = $("#" + behavior.containerId).jstree(true);
|
||||
return treeObj.get_selected(true);
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
this.showPage = function() {
|
||||
$("#usePlugins").html("");
|
||||
$("#usePlugins").append(
|
||||
createRadio("behavior_plugin_page", "page",
|
||||
"behavior_usePlugin", "page"));
|
||||
|
||||
}
|
||||
this.showBatch = function() {
|
||||
$("#usePlugins").html("");
|
||||
$("#usePlugins").append(
|
||||
createRadio("behavior_plugin_batch", "batch",
|
||||
"behavior_usePlugin", "batch"));
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
function createRadioGroup(items,name,containerId){
|
||||
for ( var i = 0; i < items.length; i++) {
|
||||
var radio = createRadio(items[i],items[i],name,items[i]);
|
||||
$("#" + containerId).append(radio);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 (id,text,name,value) {
|
||||
var line = $("<div style='cursor:pointer;' name='"+name+"'>");
|
||||
line.click(function(){
|
||||
document.getElementById(id).checked = true;
|
||||
})
|
||||
var input = $("<input type='radio' name="+name+" id="+id+">");
|
||||
input.attr("value",value);
|
||||
input.attr("text",text);
|
||||
var span = $("<label for="+id+" style='cursor:pointer;'>");
|
||||
span.html(text);
|
||||
line.append(input);
|
||||
line.append(span);
|
||||
line.addClass("line");
|
||||
return line;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param items
|
||||
* @param textAttr the key of text which is show in the web
|
||||
* @param valueAttr the key of value which is store in the web
|
||||
* @param idAttr
|
||||
* @param name
|
||||
* @param containerId
|
||||
*/
|
||||
function createRadioGroupByAttribute(items,textAttr,valueAttr,idAttr, name,containerId){
|
||||
for ( var i = 0; i < items.length; i++) {
|
||||
var radio = createRadio(items[i][idAttr],items[i][textAttr],name,items[i][valueAttr]);
|
||||
$("#" + containerId).append(radio);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue