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

View File

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

View File

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

View File

@ -18,12 +18,10 @@
.hide{ .hide{
display:none; display:none;
} }
.top-one{ .right{
position:absolute; font-size:13px;
left:1000px;
top:50px; }
}
.ip-div{ .ip-div{
margin-top:10px; margin-top:10px;
margin-bottom:10px; margin-bottom:10px;
@ -75,3 +73,9 @@ display:none;
border:medium double black; 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/chosen.css' rel='stylesheet'>
<link href='css/uniform.default.css' rel='stylesheet'> <link href='css/uniform.default.css' rel='stylesheet'>
<link href='css/colorbox.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/jquery.noty.css' rel='stylesheet'>
<link href='css/noty_theme_default.css' rel='stylesheet'> <link href='css/noty_theme_default.css' rel='stylesheet'>
<link href='css/elfinder.min.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() { $(document).ready(function() {
scriptId = getvars()['scriptId'];
$("#scriptContent").attr('scriptId', scriptId);
$("#scriptContent").jstree({ $("#scriptContent").jstree({
"xml_data" : { "xml_data" : {
"ajax" : { "ajax" : {
"url" : "editscript", "url" : "editscript",
"data" : "scriptId=2", "data" : "scriptId=" + scriptId,
"success" : function(data) { "success" : function(data) {
if (data != null) {
var result = $('<dom></dom>'); var result = $('<dom></dom>');
var root = $('<root></root>'); var root = $('<root></root>');
var doc = traverseXbel(data, root); var doc = traverseXbel(data, root);
result.append(doc); result.append(doc);
return result.html(); return result.html();
}
} }
}, },
"xsl" : "nest" "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) { $('#scriptContent').bind("dblclick.jstree", function(event) {
node = $(event.target); node = $(event.target);
@ -47,26 +103,30 @@ $('#scriptContent').bind("dblclick.jstree", function(event) {
} }
}); });
function edit() { function saveEdit() {
var text = ''; var text = '';
if ($('#value').val() == '') { if ($('#value').val() == '') {
text = $('#key').val(); text = $('#key').val();
} else } else
text = $('#key').val() + " : " + $('#value').val(); text = $('#key').val() + " : " + $('#value').val();
node.text(text); node.text(text);
$('#valuediv').hide(); $('#valuediv').hide();
$('#keydiv').hide(); $('#keydiv').hide();
$('#button').hide(); $('#savexml').hide();
save(); $('#cancelxml').hide();
} }
function save() { function getScriptContent() {
var text = ''; var text = header;
var node = $('#scriptContent'); var node = $('#scriptContent');
text = getNodeXml(node); text = text + getNodeXml(node);
alert(text); return text;
}
function cancelXml() {
$('#valuediv').hide();
$('#keydiv').hide();
$('#savexml').hide();
$('#cancelxml').hide();
} }
function getNodeXml(node) { function getNodeXml(node) {
var text = ''; var text = '';
@ -77,15 +137,18 @@ function getNodeXml(node) {
if ($(this).text().indexOf(':') > 0) { if ($(this).text().indexOf(':') > 0) {
var content = $(this).text(); var content = $(this).text();
var index = content.indexOf(":"); var index = content.indexOf(":");
var key = content.substring(0, index);
var key = content.substring(1, index);
var value = content.substring(index + 1, content.length); var value = content.substring(index + 1, content.length);
text += '<' + key + '>' + value + '</' + key + '>'; text += "<" + key + ">" + value + "</" + key + ">";
text += getNodeXml(nextNode);
} }
else { else {
text += '<' + $(this).text() + '>'; var key=$(this).text();
text += getNodeXml(nextNode) + '</' + $(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) { function traverseXbel(xml, doc) {
for ( var i = 0; i < $(xml).length; i++) { for ( var i = 0; i < $(xml).length; i++) {
var child = $(xml)[i]; var child = $(xml)[i];
if (child.nodeName == "#comment") if (child.nodeName == "#comment") {
var text = child.nodeValue.replace(/"/g, '\"');
header = "<" + text + ">";
continue; continue;
}
var childList = $(child).children(); var childList = $(child).children();
if (childList.length > 0) { if (childList.length > 0) {
var id = count++; 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, port : server.port,
fileNameUUID : server.fileName fileNameUUID : server.fileName
}, function(data) { }, function(data) {
if(data){ if (data) {
$("#scriptinfo").text("Saving success!"); $("#scriptinfo").text("Saving success!");
$('#scriptdiv').hide(); $('#scriptdiv').hide();
} } else {
else{
$("#scriptinfo").text("Saving failure!"); $("#scriptinfo").text("Saving failure!");
$('#scriptdiv').hide(); $('#scriptdiv').hide();
} }
loadscript(); loadscript();
}); });
} }
@ -59,14 +58,16 @@ function savescript() {
function loadscript() { function loadscript() {
$('#scripttab').dataTable().fnClearTable(); $('#scripttab').dataTable().fnClearTable();
$.post("loadscript", {}, function(data) { $.post("loadscript", {}, function(data) {
if (data != null) {
for ( var i = 0; i < data.length; i++) { for ( var i = 0; i < data.length; i++) {
var time = new Date(data[i].createDateTime); var time = new Date(data[i].createDateTime);
time.setTime(data[i].createDateTime); time.setTime(data[i].createDateTime);
addtablerow(data[i].name, data[i].id, time); 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("id",
$('#scripttab >tbody').children("tr").eq(i).attr("name", data[i].id);
data[i].name); $('#scripttab >tbody').children("tr").eq(i).attr("name",
data[i].name);
}
} }
}, "json"); }, "json");

View File

@ -36,11 +36,9 @@ body {
<link href="css/charisma-app.css" rel="stylesheet"> <link href="css/charisma-app.css" rel="stylesheet">
<link href="css/jquery-ui-1.8.21.custom.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.css' rel='stylesheet'>
<link href='css/fullcalendar.print.css' rel='stylesheet' media='print'>
<link href='css/chosen.css' rel='stylesheet'> <link href='css/chosen.css' rel='stylesheet'>
<link href='css/uniform.default.css' rel='stylesheet'> <link href='css/uniform.default.css' rel='stylesheet'>
<link href='css/colorbox.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/jquery.noty.css' rel='stylesheet'>
<link href='css/noty_theme_default.css' rel='stylesheet'> <link href='css/noty_theme_default.css' rel='stylesheet'>
<link href='css/elfinder.min.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/jquery.iphone.toggle.css' rel='stylesheet'>
<link href='css/opa-icons.css' rel='stylesheet'> <link href='css/opa-icons.css' rel='stylesheet'>
<link href='css/uploadify.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 --> <!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]> <!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
@ -96,7 +94,7 @@ body {
</div> </div>
<div class="row-fluid sortable"> <div class="row-fluid sortable">
<div class="box span12 center"> <div class="box span12 ">
<div class="box-header well" data-original-title> <div class="box-header well" data-original-title>
<h2> <h2>
<i class="icon-edit"></i> <i class="icon-edit"></i>
@ -112,24 +110,44 @@ body {
</div> </div>
</div> </div>
<div class="box-content"> <div class="box-content">
<form class="form-horizontal">
<fieldset> <fieldset>
<textarea id="textarea2" cols="160" rows="20"></textarea> <div id="scriptContent" class="text-left"></div>
<div class=" right">
<div class="form-actions"> <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" <button type="submit" class="btn btn-primary"
onClick="save()"> onClick="saveScript()">
<fmt:message key="savechanges" /> <fmt:message key="savechanges" />
</button> </button>
<button class="btn" onClick="cancel()"> <button class="btn" onClick="cancelScript()">
<fmt:message key="cancel" /> <fmt:message key="cancel" />
</button> </button>
</div> </div>
</fieldset> </fieldset>
</form>
</div> </div>
</div> </div>
<!--/span--> <!--/span-->
@ -185,6 +203,7 @@ body {
<!--jQuery UI --> <!--jQuery UI -->
<script src="js/jquery-ui-1.8.21.custom.min.js"></script> <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.i18n.properties-1.0.9.js"></script>
<script src="js/jquery.jstree.js"></script>
<!-- modal / dialog library --> <!-- modal / dialog library -->
<script src="js/bootstrap-modal.js"></script> <script src="js/bootstrap-modal.js"></script>
<!-- custom dropdown library--> <!-- custom dropdown library-->
@ -199,8 +218,7 @@ body {
<!-- application script for Charisma demo --> <!-- application script for Charisma demo -->
<script src="script/base.js"></script> <script src="script/base.js"></script>
<script src="js/theme.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> </fmt:bundle>
</body> </body>
</html> </html>