In the previous article, I posted the permission tree JS source code for adding the permission limit. I will also share the updated code with you for reference. This is because the updated code involves determining the existing permissions, which makes it more difficult.
The Code is as follows:
// JScript File
Function getParentByTagName (element, tagName)
{
Var parent = element. parentNode;
Var upperTagName = tagName. toUpperCase ();
While (parent & (parent. tagName. toUpperCase ()! = UpperTagName ))
{
Parent = parent. parentNode? Parent. parentNode: parent. parentElement;
}
Return parent;
}
Function setParentChecked (objNode)
{
Var objParentDiv = getParentByTagName (objNode, "p ");
If (objParentDiv = null | objParentDiv = "undefined ")
Return;
Var objID = objParentDiv. getAttribute ("ID ");
Var objParentCheckBox = document. getElementById (objID. replace ("Nodes", "CheckBox "));
If (objParentCheckBox = null | objParentCheckBox = "undefined ")
Return;
If (objParentCheckBox. tagName! = "INPUT" & objParentCheckBox. type = "checkbox ")
Return;
// Add
// If (objNode. checked = false) objPraentCheckBox. checked = false;
// ObjParentCheckBox. checked = true;
SetParentChecked (objParentCheckBox );
}
Function setParentUnChecked (objNode)
{
Var objParentDiv = getParentByTagName (objNode, "p ");
If (objParentDiv = null | objParentDiv = "undefined ")
Return;
Var objID = objParentDiv. getAttribute ("ID ");
Var objParentCheckBox = document. getElementById (objID. replace ("Nodes", "CheckBox "));
If (objParentCheckBox = null | objParentCheckBox = "undefined ")
Return;
If (objParentCheckBox. tagName! = "INPUT" & objParentCheckBox. type = "checkbox ")
Return;
// Add
// If (objNode. checked = false) objPraentCheckBox. checked = false;
ObjParentCheckBox. checked = false;
SetParentUnChecked (objParentCheckBox );
}
Function setChildCheckedState (p, state)
{
Var objchild = p. childNodes;
Var count = objchild. length;
For (var I = 0; I {
Var tempObj = objchild [I];
If (tempObj. tagName = "INPUT" & tempObj. type = "checkbox ")
{
TempObj. checked = state;
}
// Debugger;
SetChildCheckedState (tempObj, state );
}
}
Function TreeNodeChecked ()
{
Var objNode = window. event. srcElement;
If (objNode. tagName! = "INPUT" | objNode. type! = "Checkbox ")
Return;
// Debugger;
If (objNode. checked = true)
{
SetParentChecked (objNode );
}
Else
{
SetParentUnChecked (objNode );
}
Var objID = objNode. getAttribute ("ID ");
Var objParentDiv = document. getElementById (objID. replace ("CheckBox", "Nodes "));
If (objParentDiv = null | typeof (objParentDiv) = "undefined ")
Return;
SetChildCheckedState (objParentDiv, objNode. checked );
}
Function SetTreeNodeChecked (objNode1)
{
Var objNode = objNode1;
Var objID = objNode. getAttribute ("ID ");
Var objParentDiv = document. getElementById (objID. replace ("CheckBox", "Nodes "));
If (objParentDiv = null | typeof (objParentDiv) = "undefined ")
Return;
SetChildCheckedState (objParentDiv, objNode. checked );
}
Function GetYHQS (id)
{
PageMethods. CallYHQX (id, callsuccessed );
}
Function callsuccessed (result)
{
/// Cycle page
// Debugger;
For (I = 0; I {
Var objNode = document. form1.elements [I];
If (objNode. tagName = "INPUT" & objNode. type = "checkbox ")
{
ObjNode. checked = false;
}
}
For (I = 0; I {
Var objNode = document. form1.elements [I];
If (objNode. tagName = "INPUT" & objNode. type = "checkbox ")
{
// Find
// Compare
If (result. indexOf (objNode. title )! =-1)
{
ObjNode. checked = true;
SetTreeNodeChecked (objNode );
}
}
}
}
Function test ()
{
Debugger;
// Loop page
For (I = 0; I {
Var objNode = document. form1.elements [I];
If (objNode. tagName = "INPUT" & objNode. type = "checkbox ")
{
// Find
// Compare
ObjNode. checked = true;
}
}
}