|
Connect
--rule.hta--
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>XML Editer</TITLE>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="myApp"
BORDER="thick"
BORDERSTYLE="normal"
CAPTION="yes"
ContextMenu="yes"
ICON=""
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
scroll="no"
selection="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
VERSION="1.0"
WINDOWSTATE="normal"
>
<style type="text/css">
</style>
</HEAD>
<script language="javascript">
// load the xml file
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("rule.xml");
// load the xsl file
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
xslDoc.async = false;
xslDoc.resolveExternals = false;
xslDoc.load("rule.xsl");
// create the xslt object
var xslt = new ActiveXObject("Msxml2.XSLTemplate");
xslt.stylesheet = xslDoc;
var xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
var checked_count = 0;
var cur_page = 1;
var total_page = 1;
function OutputDocument(number){
xslProc.addParameter("ename", number);
xslProc.addParameter("startno", (cur_page-1)*10);
xslProc.addParameter("endno", cur_page*10);
xslProc.transform();
return xslProc.output;
}
function delete_node(node){
if( node.hasChildNodes()) {
var kids = node.childNodes;
for(var i=0;i<kids.length;i++) {
delete_node(kids[i]);
}
}
node.parentNode.removeChild(node);
}
function delete_rule(id){
var node = xmlDoc.selectSingleNode("/rules/rule[event/id="+id+"]");
delete_node(node);
}
function modify_node(node){
node.selectSingleNode("event/id").text = modify_id.value;
node.selectSingleNode("event/name").text = modify_name.value;
if( modify_state.checked) {
node.selectSingleNode("enable").text = "true";
} else {
node.selectSingleNode("enable").text = "false";
}
}
function modify_rule(id){
var node = xmlDoc.selectSingleNode("/rules/rule[event/id="+id+"]");
modify_node(node);
}
function add_rule(){
var id = xmlDoc.createElement("id");
id.appendChild(xmlDoc.createTextNode(add_id.value));
var name = xmlDoc.createElement("name");
name.appendChild(xmlDoc.createTextNode(add_name.value));
var event = xmlDoc.createElement("event");
event.appendChild(id);
event.appendChild(name);
var enable = xmlDoc.createElement("enable");
if( add_state.checked) {
enable.appendChild(xmlDoc.createTextNode("true"));
} else {
enable.appendChild(xmlDoc.createTextNode("false"));
}
var rule = xmlDoc.createElement("rule");
rule.appendChild(event);
rule.appendChild(enable);
var parent = xmlDoc.selectSingleNode("/rules");
if( parent.hasChildNodes()) {
parent.insertBefore(rule, parent.firstChild);
} else {
parent.appendChild(rule);
}
}
function gotoPage(pageno){
if( pageno <1) {
cur_page = 1;
} else if( pageno >= total_page) {
cur_page = total_page;
} else {
cur_page = pageno;
}
Transform();
}
function saveXML(){
xmlDoc.save("rule.xml");
}
function protectsubmit(val){
if( val == 1) {//add
if( add_id.value <10000 || add_name.value == "") {
window.alert("The event number must be a 5-digit integer and the event name cannot be empty");
} else if( xmlDoc.selectSingleNode("/rules/rule/event/id[. = "+ add_id.value + "]")) {
window.alert("event number" + add_id.value + "already exists");
} else {
add_rule();
saveXML();
Transform();
}
} else if( val == 2) {//modify
var id = viewTable.rows[getFirstCheckedLine()].cells[2].innerText;
if( modify_id.value <10000 || modify_name.value == "") {
window.alert("The event number must be a 5-digit integer and the event name cannot be empty");
} else if( id != modify_id.value&&xmlDoc.selectSingleNode("/rules/rule/event/id[. = "+ modify_id.value + "]")) {
window.alert("event number" + modify_id.value + "already exists");
} else {
if( confirm("Confirm changes?")) {
modify_rule(id);
saveXML();
Transform();
}
}
} else if( val == 3) {//delete
if( !confirm("Confirm delete?")) {
return;
}
for( var i = 1; i <viewTable.rows.length; i++) {
var id = viewTable.rows[i].cells[2].innerText;
if( eval("viewchk_" + id + ".checked") == true) {
delete_rule(id)
}
}
saveXML();
Transform();
} else if( val == 4) {//select all
checked_count = viewTable.rows.length-1;
for( var i = 1; i <viewTable.rows.length; i++) {
var id = viewTable.rows[i].cells[2].innerText;
eval("viewchk_" + id + ".checked = true");
}
changeState();
} else if( val == 5) {//cancel all
checked_count = 0;
for( var i = 1; i <viewTable.rows.length; i++) {
var id = viewTable.rows[i].cells[2].innerText;
eval("viewchk_" + id + ".checked = false");
}
changeState();
}
}
function getFirstCheckedLine(){
for( var i = 1; i <viewTable.rows.length; i++) {
var id = viewTable.rows[i].cells[2].innerText;
if( eval("viewchk_" + id + ".checked") == true) {
return i;
}
}
return 0;
}
function checkOVItem(val){
if( eval("viewchk_" + val+".checked") == true) {
checked_count++;
} else {
checked_count--;
}
changeState();
}
function changeState(){
if( checked_count) {
delete_btn.disabled = false;
cancel_all_btn.disabled = false;
} else {
delete_btn.disabled = true;
cancel_all_btn.disabled = true;
}
if( (checked_count + 1) == viewTable.rows.length) {
select_all_btn.disabled = true;
} else {
select_all_btn.disabled = false;
}
if( checked_count == 1) {
modify_btn.disabled = false;
modify_id.disabled = false;
modify_name.disabled = false;
modify_state.disabled = false;
var id = getFirstCheckedLine();
modify_id.value = viewTable.rows(id).cells(2).innerText;
modify_name.value = viewTable.rows(id).cells(3).innerText;
if( viewTable.rows(id).cells(1).innerText == "valid") {
modify_state.checked = true;
} else {
modify_state.checked = false;
}
} else {
modify_btn.disabled = true;
modify_id.disabled = true;
modify_name.disabled = true;
modify_state.disabled = true;
modify_id.value="Please select a rule";
modify_name.value="Please select a rule";
}
}
function showPageInfo(){
if( total_item.value == 0) {
total_page = 1;
} else {
total_page = Math.floor((9 + parseInt(total_item.value)) / 10);
}
var txt = "Total"+total_item.value+"records";
var prev_page = cur_page-1;
var next_page = parseInt(cur_page) + 1;
if( cur_page> 1) {
txt += "<input type='button' value='<' onClick='gotoPage(" + prev_page + ")'/>"
} else {
txt += "<input type='button' value='<' onClick='gotoPage(" + prev_page + ")' disabled/>"
}
if( cur_page <total_page) {
txt += "<input type='button' value='>' onClick='gotoPage(" + next_page + ")'/>"
} else {
txt += "<input type='button' value='>' onClick='gotoPage(" + next_page + ")' disabled/>"
}
txt += "page <input type='text' id='page_number' size='4' maxlength='4' value='" + cur_page + "'onBlur='gotoPage(this.value)'/> page total "+ total_page + "page";
page_info.innerHTML = txt;
// window.alert(txt);
} |
|