finish the xml edit

This commit is contained in:
xiaoran 2013-11-14 17:04:20 +08:00
parent 1ac4730c18
commit 6683696a32
10 changed files with 1553 additions and 125 deletions

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.JAXBException;
import org.apache.bcel.generic.NEW;
import org.apache.log4j.Logger;
import org.bench4q.web.communication.HttpRequester.HttpResponse;
import org.bench4q.web.entity.master.Script;
@ -235,7 +236,7 @@ public class ScriptActionController extends BaseControllerService {
System.out.println("fail");
return null;
}
System.out.println(httpResponse.getContent());
System.out.println(new String(httpResponse.getContent().getBytes(),"UTF-8"));
OperateScriptServerResponseModel operateScriptServerResponseModel = ExtractObject
.extractoperateScriptServerResponseModel(httpResponse
.getContent());
@ -272,8 +273,12 @@ public class ScriptActionController extends BaseControllerService {
throws IOException, JAXBException {
System.out.println("entry savescript");
String urlString = masterIP + "RecordScript/updateScript";
/*scriptId=new String(scriptId.getBytes(),"UTF-8");
content=new String(content.getBytes(),"UTF-8");*/
/*content.replaceAll("聽", "?");*/
Map<String, String> params = this.makeParamsMap("scriptId", scriptId);
params.put("content", content);
System.out.println("content:"+content);
try {
HttpResponse httpResponse = this.getHttpRequester().sendGet(
urlString, params, this.makeAccessTockenMap(accessToken));

View File

@ -40,7 +40,7 @@ startserver=Start Server
stopserver=Stop Server
savefile=Save File
editscript=Edit Script
savechanges=Save Changes
savechanges=Save
cancel=Cancel
close=Close
viewscript=View Script

View File

@ -40,7 +40,7 @@ startserver=\u542F\u52A8\u670D\u52A1\u5668
stopserver=\u505C\u6B62\u670D\u52A1\u5668
savefile=\u4FDD\u5B58\u6587\u4EF6
editscript=\u7F16\u8F91\u811A\u672C
savechanges=\u4FDD\u5B58\u53D8\u66F4
savechanges=\u4FDD\u5B58
cancel=\u53D6\u6D88
close=\u5173\u95ED
viewscript=\u6D4F\u89C8\u811A\u672C

View File

@ -18,12 +18,10 @@
.hide{
display:none;
}
.top-one{
position:absolute;
left:1000px;
top:50px;
}
.right{
font-size:13px;
}
.ip-div{
margin-top:10px;
margin-bottom:10px;
@ -75,3 +73,9 @@ display:none;
border:medium double black;
}
.text-left{
text-align:left;
}
.text-right{
text-align:right;
}

View File

@ -30,7 +30,6 @@ body {
<link href='css/chosen.css' rel='stylesheet'>
<link href='css/uniform.default.css' rel='stylesheet'>
<link href='css/colorbox.css' rel='stylesheet'>
<link href='css/jquery.cleditor.css' rel='stylesheet'>
<link href='css/jquery.noty.css' rel='stylesheet'>
<link href='css/noty_theme_default.css' rel='stylesheet'>
<link href='css/elfinder.min.css' rel='stylesheet'>

View File

@ -1,17 +1,22 @@
var node;
var header = "";
var scriptId;
$(document).ready(function() {
scriptId = getvars()['scriptId'];
$("#scriptContent").attr('scriptId', scriptId);
$("#scriptContent").jstree({
"xml_data" : {
"ajax" : {
"url" : "editscript",
"data" : "scriptId=2",
"data" : "scriptId=" + scriptId,
"success" : function(data) {
var result = $('<dom></dom>');
var root = $('<root></root>');
var doc = traverseXbel(data, root);
result.append(doc);
return result.html();
if (data != null) {
var result = $('<dom></dom>');
var root = $('<root></root>');
var doc = traverseXbel(data, root);
result.append(doc);
return result.html();
}
}
},
"xsl" : "nest"
@ -25,8 +30,59 @@ $(document).ready(function() {
});
});
function cancelScript(obj) {
var node;
window.close();
}
function saveScript() {
var content = getScriptContent();
alert(content);
var scriptId = $("#scriptContent").attr('scriptId');
$.ajax({
url : "savescript",
data :
{
scriptId:scriptId,
content:content
},
type : "POST",
/*contentType : "utf-8,*/
success : function(data) {
if (data) {
window.close();
} else {
}
}
});
}
function getvars() {
var vars = [], hash;
var hashes = window.location.href.slice(
window.location.href.indexOf('?') + 1).split('&');
for ( var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
$('#scriptContent').bind("dblclick.jstree", function(event) {
node = $(event.target);
@ -47,26 +103,30 @@ $('#scriptContent').bind("dblclick.jstree", function(event) {
}
});
function edit() {
function saveEdit() {
var text = '';
if ($('#value').val() == '') {
text = $('#key').val();
} else
text = $('#key').val() + " : " + $('#value').val();
node.text(text);
$('#valuediv').hide();
$('#keydiv').hide();
$('#button').hide();
save();
$('#savexml').hide();
$('#cancelxml').hide();
}
function save() {
var text = '';
function getScriptContent() {
var text = header;
var node = $('#scriptContent');
text = getNodeXml(node);
alert(text);
text = text + getNodeXml(node);
return text;
}
function cancelXml() {
$('#valuediv').hide();
$('#keydiv').hide();
$('#savexml').hide();
$('#cancelxml').hide();
}
function getNodeXml(node) {
var text = '';
@ -77,15 +137,18 @@ function getNodeXml(node) {
if ($(this).text().indexOf(':') > 0) {
var content = $(this).text();
var index = content.indexOf(":");
var key = content.substring(0, index);
var key = content.substring(1, index);
var value = content.substring(index + 1, content.length);
text += '<' + key + '>' + value + '</' + key + '>';
text += getNodeXml(nextNode);
text += "<" + key + ">" + value + "</" + key + ">";
}
else {
text += '<' + $(this).text() + '>';
text += getNodeXml(nextNode) + '</' + $(this).text() + '>';
var key=$(this).text();
key=key.substring(1,key.length);
text += "<" + key + ">";
text += getNodeXml(nextNode) + "</" + key+ ">";
}
});
});
@ -96,8 +159,12 @@ var count = 0;
function traverseXbel(xml, doc) {
for ( var i = 0; i < $(xml).length; i++) {
var child = $(xml)[i];
if (child.nodeName == "#comment")
if (child.nodeName == "#comment") {
var text = child.nodeValue.replace(/"/g, '\"');
header = "<" + text + ">";
continue;
}
var childList = $(child).children();
if (childList.length > 0) {
var id = count++;

View File

@ -1,63 +0,0 @@
function save(obj) {
var scriptId = $('#textarea2').attr("scriptId");
;
var content = $('#textarea2').val();
$.post("savescript", {
scriptId : scriptId,
content : content
}, function(data) {
if (data) {
} else {
}
}
// data is false or true?
);
window.close();
}
function cancel(obj) {
window.close();
}
function getvars() {
var vars = [], hash;
var hashes = window.location.href.slice(
window.location.href.indexOf('?') + 1).split('&');
for ( var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
function loadscript() {
var scriptId = getvars()['scriptId'];
if (scriptId != null) {
$.post("editscript", {
scriptId : scriptId
}, function(data) {
alert(data);
$('#textarea2').val(data.scriptContent);
}, "json");
$('#textarea2').attr("scriptId", scriptId);
} else
window.close();
}
$(document).ready(function(scriptId) {
loadscript();
});

View File

@ -43,15 +43,14 @@ function savescript() {
port : server.port,
fileNameUUID : server.fileName
}, function(data) {
if(data){
if (data) {
$("#scriptinfo").text("Saving success!");
$('#scriptdiv').hide();
}
else{
} else {
$("#scriptinfo").text("Saving failure!");
$('#scriptdiv').hide();
}
loadscript();
});
}
@ -59,14 +58,16 @@ function savescript() {
function loadscript() {
$('#scripttab').dataTable().fnClearTable();
$.post("loadscript", {}, function(data) {
for ( var i = 0; i < data.length; i++) {
var time = new Date(data[i].createDateTime);
time.setTime(data[i].createDateTime);
addtablerow(data[i].name, data[i].id, time);
$('#scripttab >tbody').children("tr").eq(i).attr("id", data[i].id);
$('#scripttab >tbody').children("tr").eq(i).attr("name",
data[i].name);
if (data != null) {
for ( var i = 0; i < data.length; i++) {
var time = new Date(data[i].createDateTime);
time.setTime(data[i].createDateTime);
addtablerow(data[i].name, data[i].id, time);
$('#scripttab >tbody').children("tr").eq(i).attr("id",
data[i].id);
$('#scripttab >tbody').children("tr").eq(i).attr("name",
data[i].name);
}
}
}, "json");

View File

@ -36,11 +36,9 @@ body {
<link href="css/charisma-app.css" rel="stylesheet">
<link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet">
<link href='css/fullcalendar.css' rel='stylesheet'>
<link href='css/fullcalendar.print.css' rel='stylesheet' media='print'>
<link href='css/chosen.css' rel='stylesheet'>
<link href='css/uniform.default.css' rel='stylesheet'>
<link href='css/colorbox.css' rel='stylesheet'>
<link href='css/jquery.cleditor.css' rel='stylesheet'>
<link href='css/jquery.noty.css' rel='stylesheet'>
<link href='css/noty_theme_default.css' rel='stylesheet'>
<link href='css/elfinder.min.css' rel='stylesheet'>
@ -48,7 +46,7 @@ body {
<link href='css/jquery.iphone.toggle.css' rel='stylesheet'>
<link href='css/opa-icons.css' rel='stylesheet'>
<link href='css/uploadify.css' rel='stylesheet'>
<link href='bench4q-css/bench4q.css' rel='stylesheet'>
<!-- 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>
@ -96,7 +94,7 @@ body {
</div>
<div class="row-fluid sortable">
<div class="box span12 center">
<div class="box span12 ">
<div class="box-header well" data-original-title>
<h2>
<i class="icon-edit"></i>
@ -112,24 +110,44 @@ body {
</div>
</div>
<div class="box-content">
<form class="form-horizontal">
<fieldset>
<textarea id="textarea2" cols="160" rows="20"></textarea>
<div class="form-actions">
<div id="scriptContent" class="text-left"></div>
<div class=" right">
<table >
<tr id="keydiv" class=" hide ">
<td><lable>Key :</lable></td>
<td><input type="text" id="key" value="" /></td>
</tr>
<tr id="valuediv" class=" hide ">
<td><lable>Value:</lable></td>
<td><input type="text" id="value" value="" /></td>
</tr>
<tr id= 'button' class="hide">
<td><button class="btn " id="savexml"
onClick="saveEdit()">
<fmt:message key="savechanges" />
</button></td>
<td>
<button class="btn " id=cancelxml onClick="cancelXml()">
<fmt:message key="cancel" />
</button>
</td>
</tr>
</table>
</div>
<div class="clearfix:after"></div>
<div id="message" class="hide"></div>
<div class="form-actions center">
<button type="submit" class="btn btn-primary"
onClick="save()">
onClick="saveScript()">
<fmt:message key="savechanges" />
</button>
<button class="btn" onClick="cancel()">
<button class="btn" onClick="cancelScript()">
<fmt:message key="cancel" />
</button>
</div>
</fieldset>
</form>
</div>
</div>
<!--/span-->
@ -185,6 +203,7 @@ body {
<!--jQuery UI -->
<script src="js/jquery-ui-1.8.21.custom.min.js"></script>
<script src="js/jquery.i18n.properties-1.0.9.js"></script>
<script src="js/jquery.jstree.js"></script>
<!-- modal / dialog library -->
<script src="js/bootstrap-modal.js"></script>
<!-- custom dropdown library-->
@ -199,8 +218,7 @@ body {
<!-- application script for Charisma demo -->
<script src="script/base.js"></script>
<script src="js/theme.js"></script>
<script src="script/editscript.js"></script>
<script src="script/editscript.js"></script>
<script src="script/editScript.js"></script>
</fmt:bundle>
</body>
</html>