Using AJAX+J2EE to develop organizational management systems (2)

Source: Internet
Author: User
Tags add object cdata return string
ajax|j2ee| Institutional Management

The Init method is implemented as follows:

function init () {
Define Persondom as a xmldom ' object
persondom= new ActiveXObject (' Microsoft.XMLDOM ');
Persondom.async = false;
Defines stylesheet as a xmldom ' object, and stylesheet for Persondom determines the display style
Stylesheet = new ActiveXObject (' Microsoft.XMLDOM ');
Stylesheet.async = false;
Stylesheet.load ("addorgperson.xsl"); Load stylesheet Style definition file

Load organization type data
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
Xmlhttp.open ("POST", "Org.jsp?mode=getorgtype", false);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send ();
Retxml=xmlhttp.responsetext;
alert (retxml);
Insert the organization type into a drop-down list control
var orgdoc = new ActiveXObject (' Microsoft.XMLDOM ');
Orgdoc.async = false;
Orgdoc.loadxml (Retxml);
var root = orgdoc.documentelement;
Onodelist = Root.childnodes;
TxtType.options.length =onodelist.length;
for (var i=0; i<onodelist.length; i++)
{
Item = Onodelist.item (i);
var orgtypeid=item.childnodes (0). text;
var orgtypename=item.childnodes (1). text;
Txttype.options[i].value=orgtypeid;
Txttype.options[i].text=orgtypename;
Txttype.options[0].
}
}

3 The method of writing tree drag and selecting nodes

Mydraghandler the parent-child relationship when implementing a tree-node drag.
function Mydraghandler (idfrom,idto) {
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
Xmlhttp.open ("POST", "org.jsp?mode=moveorg&orgid=" + Idfrom + "&newparentorgid=" + Idto, false);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send ();
Retxml=xmlhttp.orgponsetext;

return true;
}
Myselecthandler enables the selection of tree nodes to control the system while displaying the organization information and the personnel under the organization.
function Myselecthandler (ID) {
tborg.style.display= "Block";
Divorgmemo.style.display= "None";
Divorginfo.style.display= "None";

if (id==1)
{
divorgmemo.style.display= "Block";
Div1.style.display= "None";
Div2.style.display= "None";
Div3.style.display= "None";
Divcontent.style.display= "None";
Div5.style.display= "None";
}
Else
{
divorginfo.style.display= "Block";
div1.style.display= "Block";
div2.style.display= "Block";
div3.style.display= "Block";
divcontent.style.display= "Block";
div5.style.display= "Block";
}
Currnodeid=id;
Load Organization information and display it on a text control with encoding and name.
loadorg (ID);
Load personnel information under an organization
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
Xmlhttp.open ("POST", "org.jsp?mode=getperson&orgid=" + ID, false);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send ();

Retxml=xmlhttp.responsetext;
Persondom.loadxml (Retxml);
Add serial number to each line of personnel information
for (var i=0; i<persondom.documentelement.childnodes.length; i++) {
Persondom.documentelement.childnodes[i].setattribute ("Seqno", nextseq);
nextseq++;
}
Personnel information displayed on Divcontent
divcontent.innerhtml = Persondom.transformnode (stylesheet);
};
Load Organization information and display it on a text control with encoding and name.
function loadorg (orgid) {
if (OrgID = = null) {
OrgID = Orgtree.getselecteditemid ();
}
if (OrgID = = "") {
TbOrg.style.display = "None";
Return
}
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
Xmlhttp.open ("POST", "org.jsp?mode=loadorg&orgid=" + OrgID, false);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send ();
Retxml=xmlhttp.responsetext;
var orgdoc = new ActiveXObject (' Microsoft.XMLDOM ');
Orgdoc.async = false;
Orgdoc.loadxml (Retxml);
if (OrgID!= 1) {
Txtcode.value = Orgdoc.selectsinglenode ("//orgcode"). Text;
Txtname.value = Orgdoc.selectsinglenode ("//orgname"). Text;
}
TbOrg.style.display = "block";
}


4) Establishment of an organization

The organization is built primarily by invoking the XMLHTTP object . We mainly learn how to call XMLHTTP. Organization establishment should be implemented in the background, the organization information into the database . here we implement through the JSP . There is a createorg method in our org.jsp file that passes a parent ID.

function createorg (parentorgid) {
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
Xmlhttp.open ("POST", "org.jsp?mode=createorg&parentorgid=" + Parentorgid, false);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send ();
Retxml=xmlhttp.responsetext;
var OrgID = (new number (Retxml)). ToString ();
return orgid;
}

5) Delete organization

Organization deletion is also done by calling the Deleteorg method in the org.jsp file, which passes the deleted node ID .

function deleteorg () {
var orgid = Orgtree.getselecteditemid ();
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
Xmlhttp.open ("POST", "org.jsp?mode=deleteorg&orgid=" + OrgID, false);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send ();
}

6) Editing organization

Organizational modifications are implemented by calling the Modifyorg method in the org.jsp file, which passes the modified node ID . The modified data is routed through a custom XML-formatted string, which is implemented by the Send string . The data must be validated and the error message should be indicated before the modification. .

function modifyorg () {
if (orgtree.getselecteditemid () = = "") {
return "N";
}
if (Txtcode.value = = "") {
Alert ("Please enter the encoding!") ");
return "N";
}
if (Txtname.value = = "") {
Alert ("Please enter a name!") ");
return "N";
}
var orgid = Orgtree.getselecteditemid ();
var Orgkind;
Alert (Txttype.options[txttype.selectedindex].value)
var strmodify = "<?xml version= ' 1.0 ' encoding= ' gb2312 '" > "+
"<data>" +
"<OrgCode>! [cdata[+ Txtcode.value + "]]> </OrgCode>" +
"<OrgName>! [cdata[+ Txtname.value + "]]> </OrgName>" +
"<OrgKind>! [cdata[+ txttype.options[txttype.selectedindex].value+ "]]> </OrgKind>" +
"</data>";
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
Xmlhttp.open ("POST", "org.jsp?mode=modifyorg&orgid=" + OrgID, false);
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xmlhttp.send (strmodify);
Orgtree.setitemtext (Orgtree.getselecteditemid (), txtname.value);
}
3. The realization of Personnel management

People can add, delete, edit . At the same time when the tree node should be selected to display people for editing, viewing ...

1) Additional personnel

The principle of an increase in personnel is to add a node Peorsone in Persondom, which corresponds to a row of tables, setting properties . At the same time in the Peorsone to join the other nodes, representing DataThe field of the library and must have the same name as the label of the XLT file . These nodes are quite the columns of the row . Finally inserts a row in the table, inserts a column on the row, and displays the .



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.