add editScript.js and modify some disadvantages

This commit is contained in:
zhengyingying 2014-03-31 18:05:29 +08:00
parent ec89f4a969
commit 7eaf62e62f
5 changed files with 123 additions and 77 deletions

View File

@ -68,7 +68,7 @@ div.convert-left,div.convert-right {
#action {
margin-top: 10px;
margin-right: 520px;
margin-right: 220px;
text-align: right;
}
@ -162,4 +162,14 @@ td {
font-weight: normal;
vertical-align: top;
text-align: left;
}
.chooseScript{
margin-top:10px;
margin-bottom:10px;
margin-left:20px;
font-size:120%;
font-weight:bold;
color: #3689BB;
}

View File

@ -73,12 +73,13 @@ td,th{
height: 340px;
margin-bottom: 15px;
outline-style: outset;
color: black;
outline-color: #A0D0EC;
/* color: black; */
}
.behavior-box {
height: 400px;
border: solid 1px black;
border:1px solid #3689BB;
margin-left: 5px;
}

View File

@ -85,7 +85,7 @@
</div>
<!-- API Documentation -->
<div class="box span3" style="margin-top:0px;">
<div class="box span3" style="margin-top: 0px;">
<div class="box-header well" data-original-title>
<h2>
<i></i> API Documentation
@ -96,7 +96,8 @@
</a>
</div>
</div>
<div class="box-content main-menu-span " id="apiDocumentation " style="height:398px;">
<div class="box-content main-menu-span " id="apiDocumentation "
style="height: 398px;">
<div class="api" onclick="toggleAPIContent('apiHeader1')">
<div class="title_style">
<p class="" id="apiHeader1">poolSize</p>
@ -290,8 +291,21 @@
</div>
</div>
<!-- /API Documentation -->
<div class="span10 row-fluid">
<div class="span4 chooseScript" >
<p>UsePlugins:</p> <select name="usePlugins">
<!-- <option value="http">http -->
</select>
</div>
<div class="span4 chooseScript" >
<p>Behaviors:</p> <select name="behaviors">
<!-- <option value="send">Send -->
</select>
</div>
</div>
</div>
</div>
<div id="action">
<button type="button" class="btn btn-primary" id="submit"
title="save edit">
@ -331,6 +345,7 @@
<script src="js/lib/ace/theme-jsoneditor.js"></script>
<script src="script/jsonEditorApp.js"></script>
<script src="js/theme.js"></script>
<script src="script/editScriptModel.js"></script>
<script src="script/editScript.js"></script>
<script src="script/base.js"></script>
</fmt:bundle>

View File

@ -0,0 +1,23 @@
var rsm;
var pluginNameList=new Array();
var behaviors=new Array();
var parameters=new Array();
function loadUsePluigns(data){
for(var i=0;i<data.usePlugins.length;i++){
var usePlugin=data.usePlugins[i];
pluginNameList.push(usePlugin.name);
}
for ( var j = 0; j < pluginNameList.length; j++) {
var textNode = document.createTextNode(pluginNameList[j]);
var optionNode = document.createElement("option");
optionNode.setAttribute("selected", "loadBehaviors("+pluginNameList[j]+")");
optionNode.setAttribute("value", pluginNameList[j]);
optionNode.appendChild(textNode);
var selectNode = document.getElementsByName("usePlugins")[0];
selectNode.appendChild(optionNode);
}
}
function loadBehaviors(pluginName){
alert("pluginName="+pluginName);
}

View File

@ -9,7 +9,7 @@ function getvars() {
var hashes = window.location.href.slice(
window.location.href.indexOf('?') + 1).split('&');
for ( var i = 0; i < hashes.length; i++)
for (var i = 0; i < hashes.length; i++)
{
@ -23,78 +23,75 @@ function getvars() {
return vars;
}
var codeEditor = null, editor = {};
editor.load = function(scriptId) {
try {
editor.scriptId=scriptId;
$.post("editScript", {
scriptId : scriptId
}, function(data) {
if(!data.success)
{
alert("failed to get script:"+data.failedMessage);
editor.originalData="";
return ;
}
else data=eval('('+data.data+')');
editor.originalData=data;
var codeContainer = document.getElementById("codeEditor");
var options = {
mode: 'tree',
modes: ['code','tree'], // allowed modes
error: function (err) {
alert(err.toString());
}
};
codeEditor = new jsoneditor.JSONEditor(codeContainer,
options);
codeEditor.set(data);
}, "json");
var $submit=$("#submit");
$submit.click(function(){
editor.save();
});
var $cancel=$("#cancel");
$cancel.click(function(){
editor.cancel();
});
var $validate=$('#validate');
$validate.click(function(){
jsonValidate(codeEditor.get());
});
} catch (p) {
alert(p);
var codeEditor = null, editor = {};
editor.load = function(scriptId) {
try {
editor.scriptId = scriptId;
$.post("editScript", {
scriptId : scriptId
}, function(data) {
if (!data.success) {
alert("failed to get script:" + data.failedMessage);
editor.originalData = "";
return;
} else {
data = eval('(' + data.data + ')');
}
},
editor.save=function(){
if(codeEditor!=null){
var script=codeEditor.get();
$.ajax({
url : "saveEditScript",
data : {
scriptId: editor.scriptId,
script: JSON.stringify(script),
},
type : "POST",
success : function(data) {
if (data.success) {
alert("save success");
} else {
alert("save fail:"+data.failedMessage);
}
editor.originalData = data;
var codeContainer = document.getElementById("codeEditor");
var options = {
mode : 'tree',
modes : [ 'code', 'tree' ], // allowed modes
error : function(err) {
alert(err.toString());
}
});
}
};
codeEditor = new jsoneditor.JSONEditor(codeContainer, options);
codeEditor.set(data);
loadUsePluigns(data);
loadBehaviors(data);
},
editor.cancel=function(){
if(codeEditor!=null&&treeEditor!=null){
codeEditor.set(editor.originalData);
/*treeEditor.set(editor.originalData);*/
}, "json");
var $submit = $("#submit");
$submit.click(function() {
editor.save();
});
var $cancel = $("#cancel");
$cancel.click(function() {
editor.cancel();
});
var $validate = $('#validate');
$validate.click(function() {
jsonValidate(codeEditor.get());
});
} catch (p) {
alert(p);
}
}, editor.save = function() {
if (codeEditor != null) {
var script = codeEditor.get();
$.ajax({
url : "saveEditScript",
data : {
scriptId : editor.scriptId,
script : JSON.stringify(script),
},
type : "POST",
success : function(data) {
if (data.success) {
alert("save success");
} else {
alert("save fail:" + data.failedMessage);
}
}
};
});
}
}, editor.cancel = function() {
if (codeEditor != null && treeEditor != null) {
codeEditor.set(editor.originalData);
/* treeEditor.set(editor.originalData); */
}
};