Ext 樹 非同步獲取JSON資料
阿新 • • 發佈:2019-02-12
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
import="com.coship.dhm.portalMS.site.entity.Site"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="org.apache.struts2.ServletActionContext"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="page" uri="/WEB-INF/tlds/paginated.tld"%>
<%@ taglib prefix="priveliege" uri="/WEB-INF/tlds/priveliege.tld" %>
<%@ include file="../common/language.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>Panel</title>
<link href="../style/base<%=language_css%>.css" rel="stylesheet" type="text/css" />
<%@ include file="../common/commonJS.jsp" %>
<script type="text/javascript" src="../js/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../js/ext/ext-all.js"></script>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/dialogShow.js"></script>
<script type="text/javascript" src="../jsCBB/jquery.js" ></script>
<script type="text/javascript" src="../js/loading.js"></script>
<link rel="stylesheet" type="text/css"
href="../js/ext/resources/css/ext-all.css"></link>
<%
Site site = (Site) request.getAttribute("site");
Long siteid = site.getSiteID();
String siteAlias = site.getAlias();
%>
<style>
body {
background-color: #e9f0f9;
font-size: 12px
}
</style>
<style>
#pageOverlay { position:fixed; top:0; left:0; z-index:1987;
width:100%; height:100%;
background:#000; filter:alpha(opacity=50); opacity:0.50; }
</style>
<script type="text/javascript">
var tree;
var root;
var siteid = '<%=siteid%>';
var siteID;
var siteAlias = '<%=siteAlias%>';
var siteALIAS;
//防重複提交按鍵功能
var timerID;
function activethis(){
timerID=setTimeout('document.getElementById("syncTreeNode").disabled=false',10000);
$("#syncTreeNode").submit();
}
function changeTerminalType(parm){
var url = "initTree.action?site.siteID="+parm.trim();
var categoryType = window.parent.categoryType;
parent.mFrame.window.location ='showResourceCategoryList.action?category.categoryType='+categoryType+'&categorySite='+parm;
window.location = url;
}
function removeNodes(){
var queryString='';
var flag = false;
var rootindex='';
var rootid='';
// 所有選中的子選單的id
var checkedNodesIds = "";// 選中的節點id
var checkedNodes = tree.getChecked();
var nodes = new Array();
for (var i = checkedNodes.length - 1 ;i >= 0 ; i--) {
var node = checkedNodes[i];
if(node.parentNode.id=='root_id'){
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.root.not.delete"/>',400,200);
return;
}
nodes.push(node);
queryString += "&categoryids=" + node.id;
if(parent.mFrame.document.getElementById("clickNode").value==node.id)//如果主頁面顯示的節點為要刪除的節點
{
flag = true;
}
}
var url='delResourceCategorys.action?ts=' + new Date().getTime()+'&'+queryString;
//此處執行非同步
Ext.Ajax.request({
type:"POST",
url: url,
callback : function(options, success, response) {
if(response.responseText=='true')
{
var checkedNodes = tree.getChecked();
for (var a = checkedNodes.length - 1 ;a >= 0 ; a--) {
var node = checkedNodes[a];
var p = node.parentNode;
p.removeChild(node);
}
if(flag==true)
{
var s=root.firstChild;
//呼叫查詢的方法
parent.mFrame.window.location.href=
'showResourceCategoryList.action?category.categoryId='+s.id;
}
document.getElementById("showSuccessDialog").value="1";
//傳入引數true,定位到父親的父親顯示成功資訊
showSuccessWindowByParent( '<s:text name="msg.portalMS.success.message.deletecategory" />', '',2 );
}
else //alert('刪除失敗!請確保被刪除的欄目下沒有對應的資源、資訊或商品!');
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>',response.responseText,400,200);
}
}
});
}
function syncNodes(){
var queryString='';
var flag = false;
var rootindex='';
var rootid='';
// 所有選中的子選單的id
var checkedNodesIds = "";// 選中的節點id
var checkedNodes = tree.getChecked();
var nodes = new Array();
for (var i = checkedNodes.length - 1 ;i >= 0 ; i--) {
var node = checkedNodes[i];
if(node.parentNode.id=='root_id'){
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.root.not.delete"/>',400,200);
return;
}
nodes.push(node);
queryString += "&categoryids=" + node.id;
if(parent.mFrame.document.getElementById("clickNode").value==node.id)//如果主頁面顯示的節點為要刪除的節點
{
flag = true;
}
}
var url='syncResourceCategorys.action?ts=' + new Date().getTime()+'&'+queryString;
//此處執行非同步
Ext.Ajax.request({
type:"POST",
url: url,
callback : function(options,success, response) {
if(response.responseText=='true')
{
if(flag==true)
{
var s=root.firstChild;
//呼叫查詢的方法
parent.mFrame.window.location.href=
'showResourceCategoryList.action?category.categoryId='+s.id;
}
document.getElementById("showSuccessDialog").value="1";
//傳入引數true,定位到父親的父親顯示成功資訊
showSuccessWindowByParent( '<s:text name="msg.portalMS.success.message.deletecategory" />', '',2 );
}
else //alert('刪除失敗!請確保被刪除的欄目下沒有對應的資源、資訊或商品!');
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>',response.responseText,400,200);
}
}
});
}
function removeLocalAll()
{ var sitestext=$('#sitesid option:selected').text();//選中的文字
var delsiteid=document.getElementById("sitesid").value;
parent.parent.showConfirmAndCancel('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.delete.all.column"/>'+sitestext+'<s:text name="msg.portalMS.category.column"/>',"removeLocalAllAjax");
}
function removeLocalAllAjax(){
var sitestext=$('#sitesid option:selected').text();//選中的文字
var delsiteid=document.getElementById("sitesid").value;
var url='delLocalAllCategory.action?ts=' + new Date().getTime()+'&delsiteid='+delsiteid ;
//此處執行非同步
Ext.Ajax.request({
url: url,
callback : function(options,success, response) {
if(response.responseText=='true')
{ root.reload();// 重新載入根節點.
root.expand();
document.getElementById("showSuccessDialog").value="1";
//傳入引數true,定位到父親的父親顯示成功資訊
showSuccessWindowByParent( '<s:text name="msg.portalMS.success.message.deletecategory" />', '',2 );
}
else if(response.responseText=='nocategory')
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.city.no.column"/>'+sitestext+'<s:text name="msg.portalMS.category.column"/>',400,200);
}
else //alert('刪除失敗!請確保被刪除的欄目下沒有對應的資源、資訊或商品!');
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>',response.responseText,400,200);
}
}
});
}
function removenode()
{
var checkedNodes = tree.getChecked();
if(checkedNodes.length == 0)
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.delete.selected"/>',400,200,0,true);
return;
}if(checkedNodes.length > 100)
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.selected.too.much"/>',400,200,0,true);
return;
}
else
parent.parent.showConfirmAndCancel_b('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.deleted.confirm" />','');
}
function syncTreeNode()
{
var checkedNodes = tree.getChecked();
if(checkedNodes.length == 0)
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.sync.selected"/>',400,200,0,true);
return;
}if(checkedNodes.length > 100)
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.selected.too.much"/>',400,200,0,true);
return;
}
else
parent.parent.showConfirmAndCancelSyncCategory('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.synccategory.confirm" />','');
}
var heightWindows;
Ext.override(Ext.tree.TreeNode, {
deepExpand : function(anim, callback, scope){
// 先展開本節點
this.expand(false, anim, function(){
// 然後展開子節點
var cs = this.childNodes,
expanded = 0,
len = cs.length,
taskDone = function(){
// 每展開成功一個子節點,計數+1
expanded++;
// 如果所有子節點都展開,呼叫最終回撥
if(expanded >= len){
this.runCallback(callback, scope || this, [this]);
}
};
if(len<=0){
taskDone.call(this);// <--- 這裡? 應該修改為 taskDone.call(this);
return;
}
// 遞迴展開
for(var i = 0, len = cs.length; i < len; i++) {
cs[i].deepExpand(anim, taskDone, this);
}
}, this);
}
});
//用來註冊在Ext框架及頁面的html程式碼載入完後,所要執行的函式
/**
* 用Ext.override重寫控制元件屬性
一些通用的控制元件屬性,可以用Ext.override重寫並放在公共檔案中,這樣所有引用此公共檔案的頁面的控制元件,將自動繼承這些屬性.
例如:需要讓所有Grid的行號在翻頁後連續遞增並且其寬度自動設為30,則可在公共檔案中將Ext.grid.RowNumberer重寫如下:
Ext.override(Ext.grid.RowNumberer, {
width: 30,
renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {
return store.lastOptions.params.start + rowIndex + 1;
}
});
*/
Ext.onReady(
function() {
Ext.override(Ext.tree.TreeNode, {
deepExpand : function(anim, callback, scope){
// 先展開本節點
this.expand(false, anim, function(){
// 然後展開子節點
var cs = this.childNodes,
expanded = 0,
len = cs.length,
taskDone = function(){
// 每展開成功一個子節點,計數+1
expanded++;
// 如果所有子節點都展開,呼叫最終回撥
if(expanded >= len){
this.runCallback(callback, scope || this, [this]);
}
};
if(len<=0){
taskDone.call(this);// <--- 這裡? 應該修改為 taskDone.call(this);
return;
}
// 遞迴展開
for(var i = 0, len = cs.length; i < len; i++) {
cs[i].deepExpand(anim, taskDone, this);
}
}, this);
}
});
var heightWindows= document.documentElement.clientHeight -60;
var width= document.documentElement.clientWidth -5;
var siteID_;
var arr =Ext.query("*[name=site.siteID]");// 通過class name來獲取節點的陣列
siteID = arr[0].value;
if(siteID!=''){
siteID_ = siteID;
}else{
siteID_ = siteid;
}
document.getElementById("sitesid").value=siteID_;
var isClone = document.getElementById("isClone")
Ext.BLANK_IMAGE_URL = "../js/ext/resources/images/default/s.gif";
Ext.QuickTips.init();
var Tree = Ext.tree;
tree = new Tree.TreePanel({
el:'tree_div',
title:'右鍵進行克隆操作',
autoScroll : true,
border : false,
animate : true,
enableDD : false,
height:heightWindows,
bodyStyle:'background-color:#e9f0f9',
containerScroll : true,
loader: new Tree.TreeLoader({
dataUrl:'jsonTree.action'+'?site.siteID='+siteID
})
});
tree.on('beforeload',function(node){
tree.loader.dataUrl = 'jsonTree.action?nodeId='+node.id+'&site.siteID='+siteID_;
});
// set the root node
root = new Tree.AsyncTreeNode({
text: '<s:text name="msg.portalMS.system.root"/>',
draggable:false,
root:'menus',
url:'www.baidu.com',
id:'root_id',
icon:'../images/dataTemplate.gif'
});
tree.setRootNode(root);
root.expand();
// render the tree
tree.render();
if(typeof(isClone) != "undefined" && isClone != null)
{
tree.on("contextmenu", showNASClassTreeMenu);
}
tree.on("click", showDetail);
tree.on('checkchange', function(node, checked) {
node.deepExpand(false,function(){if(node.parentNode.id=='root_id'){
return;
}
selParent(node, checked);
selChild(node, checked);},this);
}, tree);
}
);
//這個方法是選擇父節點,自動選中所有的子節點
function selParent(node, checked) {
checked ? node.expand() : node.collapse();
if (node.hasChildNodes()) {
node.eachChild(function(child) {
child.attributes.checked = checked;
var cb = child.ui.checkbox;
if (cb) cb.checked = checked;
selParent(child, checked);
});
}
}
//這個方法是選擇子節點,自動選中父節點的父節點
function selChild(node, checked) {
if (checked) {
}
else{
var parentNode = node.parentNode;
if (parentNode != undefined) {
parentNode.attributes.checked = false;
var cb = parentNode.ui.checkbox;
if (cb) cb.checked = checked;
selChild(parentNode, checked);
}
}
}
function showNASClassTreeMenu(node, e) {
if(node.id=='root_id'||node.parentNode.id=='root_id')
{ return;
}
var nasclassMenu = new Ext.menu.Menu({
items : [{
text : '<s:text name="msg.portalMS.category.clone"/>'+node.text,
icon : '../images/cd.gif',
handler : function() {
columnClone(node.id);
}
}]
});
nasclassMenu.showAt(e.getPoint());
}
//欄目的克隆
function columnClone(id){
var queryString='';
queryString += "&categoryids=" + id;
if(!id){
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.selected.box"/>',400,200,0,true);
}else{
ToCloneFrame(id);
}
}
function ToCloneFrame(id){
parent.parent.showClonePage('<s:text name="msg.portalMS.category.select.clone"/>','<%=request.getContextPath()%>/resource/initTree.action?clone=1&cloneCatgoryId='+id,500,430);
}
function allclone(){
var clonesiteid=document.getElementById("sitesid").value;
parent.parent.showPage('<s:text name="msg.portalMS.category.selected.city"/>','<%=request.getContextPath()%>/resource/selectCity.action?clonesiteid='+clonesiteid,300,150);
}
function showDetail(node, e) {
alert("showDetail"+node.id);
if(node.id=='root_id')
{
return;
}
mFrameLoading();
parent.document.getElementById("mFrame").src="showResourceCategoryList.action?category.categoryId="+node.id;
}
function showNASClassTreeSubNode(node) {
tree.expand(true,false);
}
function showNASClassTreeSubNode(node) {
tree.expand(true,false);
}
function reLoadTree() {
root.reload();// 重新載入根節點.
root.expand();
}
var i=-1;
function getLevel(categoryId) {
i=-1;
if(typeof(tree) != "undefined" && tree != null)
{
var tmpNode=tree.getNodeById(categoryId);
if(typeof(tmpNode) != "undefined")
{
tt(tmpNode.id);
}
}
return i;
}
function tt(categoryId) {
var tmpNode=tree.getNodeById(categoryId);
if(tmpNode.id !='root_id')
{
tmpNode=tmpNode.parentNode;
i++;
tt(tmpNode.id);
}else{
return;
}
}
function updateLoadTree(text,id) {
tree.getNodeById(id).setText(text);
}
function reLoadTreeNode(id) {
var loadNode=tree.getNodeById(pid);
loadNode.removeAll();
tree.getStore.load({node:loadNode});//重新載入指定的節點。
}
function addNode(pid) {
var loadNode=tree.getNodeById(pid);
if(loadNode.isLeaf())
{
var parentNode = loadNode.parentNode;
parentNode.reload();
}else{
loadNode.reload();
}
//tree.getStore.load({node:loadNode});//重新載入指定的節點。
}
function parentNode(pid){
var nodes=tree.getChecked();
var loadNode=tree.getNodeById(pid);
if(typeof(loadNode) != 'undefined' )
{
if(loadNode.isLeaf())
{
var parentNode = loadNode.parentNode;
parentNode.reload();
}
else
{
loadNode.reload();
}
if(nodes && nodes.length)
{
for(var i=0;i<nodes.length;i++)
{
//設定UI狀態為未選中狀態
nodes[i].getUI().toggleCheck(false);
//設定節點屬性為未選中狀態
nodes[i].attributes.checked=false;
}
}
}
}
function layerMaskShow()
{
document.getElementById('pageOverlay').style.visibility = 'visible' ;
}
function layerMaskHidden()
{
document.getElementById('pageOverlay').style.visibility = 'hidden' ;
}
</script>
</head>
<body onload="layerMaskHidden()">
<div>
<priveliege:priveliege funCode="clone">
<s:hidden name="isClone" id="isClone"></s:hidden>
</priveliege:priveliege>
</div>
<s:hidden name="showSuccessDialog" />
<s:hidden name="site.siteID" id="site.siteID"></s:hidden>
<s:hidden name="catetype" id="cate_type" value="column" ></s:hidden>
<div id="pcolumn_delete" style="margin-left: -6px;">
<priveliege:priveliege funCode="delResourceCategorys">
<button id="deleteTreeNode" onclick="removenode()"> <s:text name="msg.portalMS.system.delete"/></button>
</priveliege:priveliege>
<s:if test='#session.loginUser.city.levelType == "P"'>
<priveliege:priveliege funCode="allclone">
<button id="allclonebutton" onclick="allclone()"> <s:text name="msg.portalMS.category.clone.all"/></button>
</priveliege:priveliege>
</s:if>
<s:else>
<priveliege:priveliege funCode="delLocalAllCategory">
<button id="delallButton" onclick="removeLocalAll()"><s:text name="msg.portalMS.category.delete.all"/></button>
</priveliege:priveliege>
</s:else>
<button id="syncTreeNode" onclick="this.disabled=true;activethis();syncTreeNode()"> <s:text name="msg.portalMS.sysmgr.syncmanage.sync"/></button>
</div>
<s:select id="sitesid" list="sites" name="iepgSiteVO.terminalType"
listKey="siteID" listValue="alias"
onchange="changeTerminalType(this.value)" cssStyle="width:100%">
</s:select>
<div id="tree_div" cssStyle="width:99%,height:80%"></div>
<div id="pageOverlay" ></div>
</body>
</html>
import="com.coship.dhm.portalMS.site.entity.Site"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="org.apache.struts2.ServletActionContext"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="page" uri="/WEB-INF/tlds/paginated.tld"%>
<%@ taglib prefix="priveliege" uri="/WEB-INF/tlds/priveliege.tld" %>
<%@ include file="../common/language.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>Panel</title>
<link href="../style/base<%=language_css%>.css" rel="stylesheet" type="text/css" />
<%@ include file="../common/commonJS.jsp" %>
<script type="text/javascript" src="../js/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../js/ext/ext-all.js"></script>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/dialogShow.js"></script>
<script type="text/javascript" src="../jsCBB/jquery.js" ></script>
<script type="text/javascript" src="../js/loading.js"></script>
<link rel="stylesheet" type="text/css"
href="../js/ext/resources/css/ext-all.css"></link>
<%
Site site = (Site) request.getAttribute("site");
Long siteid = site.getSiteID();
String siteAlias = site.getAlias();
%>
<style>
body {
background-color: #e9f0f9;
font-size: 12px
}
</style>
<style>
#pageOverlay { position:fixed; top:0; left:0; z-index:1987;
width:100%; height:100%;
background:#000; filter:alpha(opacity=50); opacity:0.50; }
</style>
<script type="text/javascript">
var tree;
var root;
var siteid = '<%=siteid%>';
var siteID;
var siteAlias = '<%=siteAlias%>';
var siteALIAS;
//防重複提交按鍵功能
var timerID;
function activethis(){
timerID=setTimeout('document.getElementById("syncTreeNode").disabled=false',10000);
$("#syncTreeNode").submit();
}
function changeTerminalType(parm){
var url = "initTree.action?site.siteID="+parm.trim();
var categoryType = window.parent.categoryType;
parent.mFrame.window.location ='showResourceCategoryList.action?category.categoryType='+categoryType+'&categorySite='+parm;
window.location = url;
}
function removeNodes(){
var queryString='';
var flag = false;
var rootindex='';
var rootid='';
// 所有選中的子選單的id
var checkedNodesIds = "";// 選中的節點id
var checkedNodes = tree.getChecked();
var nodes = new Array();
for (var i = checkedNodes.length - 1 ;i >= 0 ; i--) {
var node = checkedNodes[i];
if(node.parentNode.id=='root_id'){
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.root.not.delete"/>',400,200);
return;
}
nodes.push(node);
queryString += "&categoryids=" + node.id;
if(parent.mFrame.document.getElementById("clickNode").value==node.id)//如果主頁面顯示的節點為要刪除的節點
{
flag = true;
}
}
var url='delResourceCategorys.action?ts=' + new Date().getTime()+'&'+queryString;
//此處執行非同步
Ext.Ajax.request({
type:"POST",
url: url,
callback : function(options, success, response) {
if(response.responseText=='true')
{
var checkedNodes = tree.getChecked();
for (var a = checkedNodes.length - 1 ;a >= 0 ; a--) {
var node = checkedNodes[a];
var p = node.parentNode;
p.removeChild(node);
}
if(flag==true)
{
var s=root.firstChild;
//呼叫查詢的方法
parent.mFrame.window.location.href=
'showResourceCategoryList.action?category.categoryId='+s.id;
}
document.getElementById("showSuccessDialog").value="1";
//傳入引數true,定位到父親的父親顯示成功資訊
showSuccessWindowByParent( '<s:text name="msg.portalMS.success.message.deletecategory" />', '',2 );
}
else //alert('刪除失敗!請確保被刪除的欄目下沒有對應的資源、資訊或商品!');
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>',response.responseText,400,200);
}
}
});
}
function syncNodes(){
var queryString='';
var flag = false;
var rootindex='';
var rootid='';
// 所有選中的子選單的id
var checkedNodesIds = "";// 選中的節點id
var checkedNodes = tree.getChecked();
var nodes = new Array();
for (var i = checkedNodes.length - 1 ;i >= 0 ; i--) {
var node = checkedNodes[i];
if(node.parentNode.id=='root_id'){
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.root.not.delete"/>',400,200);
return;
}
nodes.push(node);
queryString += "&categoryids=" + node.id;
if(parent.mFrame.document.getElementById("clickNode").value==node.id)//如果主頁面顯示的節點為要刪除的節點
{
flag = true;
}
}
var url='syncResourceCategorys.action?ts=' + new Date().getTime()+'&'+queryString;
//此處執行非同步
Ext.Ajax.request({
type:"POST",
url: url,
callback : function(options,success, response) {
if(response.responseText=='true')
{
if(flag==true)
{
var s=root.firstChild;
//呼叫查詢的方法
parent.mFrame.window.location.href=
'showResourceCategoryList.action?category.categoryId='+s.id;
}
document.getElementById("showSuccessDialog").value="1";
//傳入引數true,定位到父親的父親顯示成功資訊
showSuccessWindowByParent( '<s:text name="msg.portalMS.success.message.deletecategory" />', '',2 );
}
else //alert('刪除失敗!請確保被刪除的欄目下沒有對應的資源、資訊或商品!');
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>',response.responseText,400,200);
}
}
});
}
function removeLocalAll()
{ var sitestext=$('#sitesid option:selected').text();//選中的文字
var delsiteid=document.getElementById("sitesid").value;
parent.parent.showConfirmAndCancel('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.delete.all.column"/>'+sitestext+'<s:text name="msg.portalMS.category.column"/>',"removeLocalAllAjax");
}
function removeLocalAllAjax(){
var sitestext=$('#sitesid option:selected').text();//選中的文字
var delsiteid=document.getElementById("sitesid").value;
var url='delLocalAllCategory.action?ts=' + new Date().getTime()+'&delsiteid='+delsiteid ;
//此處執行非同步
Ext.Ajax.request({
url: url,
callback : function(options,success, response) {
if(response.responseText=='true')
{ root.reload();// 重新載入根節點.
root.expand();
document.getElementById("showSuccessDialog").value="1";
//傳入引數true,定位到父親的父親顯示成功資訊
showSuccessWindowByParent( '<s:text name="msg.portalMS.success.message.deletecategory" />', '',2 );
}
else if(response.responseText=='nocategory')
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.city.no.column"/>'+sitestext+'<s:text name="msg.portalMS.category.column"/>',400,200);
}
else //alert('刪除失敗!請確保被刪除的欄目下沒有對應的資源、資訊或商品!');
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>',response.responseText,400,200);
}
}
});
}
function removenode()
{
var checkedNodes = tree.getChecked();
if(checkedNodes.length == 0)
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.delete.selected"/>',400,200,0,true);
return;
}if(checkedNodes.length > 100)
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.selected.too.much"/>',400,200,0,true);
return;
}
else
parent.parent.showConfirmAndCancel_b('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.deleted.confirm" />','');
}
function syncTreeNode()
{
var checkedNodes = tree.getChecked();
if(checkedNodes.length == 0)
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.sync.selected"/>',400,200,0,true);
return;
}if(checkedNodes.length > 100)
{
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.selected.too.much"/>',400,200,0,true);
return;
}
else
parent.parent.showConfirmAndCancelSyncCategory('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.synccategory.confirm" />','');
}
var heightWindows;
Ext.override(Ext.tree.TreeNode, {
deepExpand : function(anim, callback, scope){
// 先展開本節點
this.expand(false, anim, function(){
// 然後展開子節點
var cs = this.childNodes,
expanded = 0,
len = cs.length,
taskDone = function(){
// 每展開成功一個子節點,計數+1
expanded++;
// 如果所有子節點都展開,呼叫最終回撥
if(expanded >= len){
this.runCallback(callback, scope || this, [this]);
}
};
if(len<=0){
taskDone.call(this);// <--- 這裡? 應該修改為 taskDone.call(this);
return;
}
// 遞迴展開
for(var i = 0, len = cs.length; i < len; i++) {
cs[i].deepExpand(anim, taskDone, this);
}
}, this);
}
});
//用來註冊在Ext框架及頁面的html程式碼載入完後,所要執行的函式
/**
* 用Ext.override重寫控制元件屬性
一些通用的控制元件屬性,可以用Ext.override重寫並放在公共檔案中,這樣所有引用此公共檔案的頁面的控制元件,將自動繼承這些屬性.
例如:需要讓所有Grid的行號在翻頁後連續遞增並且其寬度自動設為30,則可在公共檔案中將Ext.grid.RowNumberer重寫如下:
Ext.override(Ext.grid.RowNumberer, {
width: 30,
renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {
return store.lastOptions.params.start + rowIndex + 1;
}
});
*/
Ext.onReady(
function() {
Ext.override(Ext.tree.TreeNode, {
deepExpand : function(anim, callback, scope){
// 先展開本節點
this.expand(false, anim, function(){
// 然後展開子節點
var cs = this.childNodes,
expanded = 0,
len = cs.length,
taskDone = function(){
// 每展開成功一個子節點,計數+1
expanded++;
// 如果所有子節點都展開,呼叫最終回撥
if(expanded >= len){
this.runCallback(callback, scope || this, [this]);
}
};
if(len<=0){
taskDone.call(this);// <--- 這裡? 應該修改為 taskDone.call(this);
return;
}
// 遞迴展開
for(var i = 0, len = cs.length; i < len; i++) {
cs[i].deepExpand(anim, taskDone, this);
}
}, this);
}
});
var heightWindows= document.documentElement.clientHeight -60;
var width= document.documentElement.clientWidth -5;
var siteID_;
var arr =Ext.query("*[name=site.siteID]");// 通過class name來獲取節點的陣列
siteID = arr[0].value;
if(siteID!=''){
siteID_ = siteID;
}else{
siteID_ = siteid;
}
document.getElementById("sitesid").value=siteID_;
var isClone = document.getElementById("isClone")
Ext.BLANK_IMAGE_URL = "../js/ext/resources/images/default/s.gif";
Ext.QuickTips.init();
var Tree = Ext.tree;
tree = new Tree.TreePanel({
el:'tree_div',
title:'右鍵進行克隆操作',
autoScroll : true,
border : false,
animate : true,
enableDD : false,
height:heightWindows,
bodyStyle:'background-color:#e9f0f9',
containerScroll : true,
loader: new Tree.TreeLoader({
dataUrl:'jsonTree.action'+'?site.siteID='+siteID
})
});
tree.on('beforeload',function(node){
tree.loader.dataUrl = 'jsonTree.action?nodeId='+node.id+'&site.siteID='+siteID_;
});
// set the root node
root = new Tree.AsyncTreeNode({
text: '<s:text name="msg.portalMS.system.root"/>',
draggable:false,
root:'menus',
url:'www.baidu.com',
id:'root_id',
icon:'../images/dataTemplate.gif'
});
tree.setRootNode(root);
root.expand();
// render the tree
tree.render();
if(typeof(isClone) != "undefined" && isClone != null)
{
tree.on("contextmenu", showNASClassTreeMenu);
}
tree.on("click", showDetail);
tree.on('checkchange', function(node, checked) {
node.deepExpand(false,function(){if(node.parentNode.id=='root_id'){
return;
}
selParent(node, checked);
selChild(node, checked);},this);
}, tree);
}
);
//這個方法是選擇父節點,自動選中所有的子節點
function selParent(node, checked) {
checked ? node.expand() : node.collapse();
if (node.hasChildNodes()) {
node.eachChild(function(child) {
child.attributes.checked = checked;
var cb = child.ui.checkbox;
if (cb) cb.checked = checked;
selParent(child, checked);
});
}
}
//這個方法是選擇子節點,自動選中父節點的父節點
function selChild(node, checked) {
if (checked) {
}
else{
var parentNode = node.parentNode;
if (parentNode != undefined) {
parentNode.attributes.checked = false;
var cb = parentNode.ui.checkbox;
if (cb) cb.checked = checked;
selChild(parentNode, checked);
}
}
}
function showNASClassTreeMenu(node, e) {
if(node.id=='root_id'||node.parentNode.id=='root_id')
{ return;
}
var nasclassMenu = new Ext.menu.Menu({
items : [{
text : '<s:text name="msg.portalMS.category.clone"/>'+node.text,
icon : '../images/cd.gif',
handler : function() {
columnClone(node.id);
}
}]
});
nasclassMenu.showAt(e.getPoint());
}
//欄目的克隆
function columnClone(id){
var queryString='';
queryString += "&categoryids=" + id;
if(!id){
parent.parent.showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.category.selected.box"/>',400,200,0,true);
}else{
ToCloneFrame(id);
}
}
function ToCloneFrame(id){
parent.parent.showClonePage('<s:text name="msg.portalMS.category.select.clone"/>','<%=request.getContextPath()%>/resource/initTree.action?clone=1&cloneCatgoryId='+id,500,430);
}
function allclone(){
var clonesiteid=document.getElementById("sitesid").value;
parent.parent.showPage('<s:text name="msg.portalMS.category.selected.city"/>','<%=request.getContextPath()%>/resource/selectCity.action?clonesiteid='+clonesiteid,300,150);
}
function showDetail(node, e) {
alert("showDetail"+node.id);
if(node.id=='root_id')
{
return;
}
mFrameLoading();
parent.document.getElementById("mFrame").src="showResourceCategoryList.action?category.categoryId="+node.id;
}
function showNASClassTreeSubNode(node) {
tree.expand(true,false);
}
function showNASClassTreeSubNode(node) {
tree.expand(true,false);
}
function reLoadTree() {
root.reload();// 重新載入根節點.
root.expand();
}
var i=-1;
function getLevel(categoryId) {
i=-1;
if(typeof(tree) != "undefined" && tree != null)
{
var tmpNode=tree.getNodeById(categoryId);
if(typeof(tmpNode) != "undefined")
{
tt(tmpNode.id);
}
}
return i;
}
function tt(categoryId) {
var tmpNode=tree.getNodeById(categoryId);
if(tmpNode.id !='root_id')
{
tmpNode=tmpNode.parentNode;
i++;
tt(tmpNode.id);
}else{
return;
}
}
function updateLoadTree(text,id) {
tree.getNodeById(id).setText(text);
}
function reLoadTreeNode(id) {
var loadNode=tree.getNodeById(pid);
loadNode.removeAll();
tree.getStore.load({node:loadNode});//重新載入指定的節點。
}
function addNode(pid) {
var loadNode=tree.getNodeById(pid);
if(loadNode.isLeaf())
{
var parentNode = loadNode.parentNode;
parentNode.reload();
}else{
loadNode.reload();
}
//tree.getStore.load({node:loadNode});//重新載入指定的節點。
}
function parentNode(pid){
var nodes=tree.getChecked();
var loadNode=tree.getNodeById(pid);
if(typeof(loadNode) != 'undefined' )
{
if(loadNode.isLeaf())
{
var parentNode = loadNode.parentNode;
parentNode.reload();
}
else
{
loadNode.reload();
}
if(nodes && nodes.length)
{
for(var i=0;i<nodes.length;i++)
{
//設定UI狀態為未選中狀態
nodes[i].getUI().toggleCheck(false);
//設定節點屬性為未選中狀態
nodes[i].attributes.checked=false;
}
}
}
}
function layerMaskShow()
{
document.getElementById('pageOverlay').style.visibility = 'visible' ;
}
function layerMaskHidden()
{
document.getElementById('pageOverlay').style.visibility = 'hidden' ;
}
</script>
</head>
<body onload="layerMaskHidden()">
<div>
<priveliege:priveliege funCode="clone">
<s:hidden name="isClone" id="isClone"></s:hidden>
</priveliege:priveliege>
</div>
<s:hidden name="showSuccessDialog" />
<s:hidden name="site.siteID" id="site.siteID"></s:hidden>
<s:hidden name="catetype" id="cate_type" value="column" ></s:hidden>
<div id="pcolumn_delete" style="margin-left: -6px;">
<priveliege:priveliege funCode="delResourceCategorys">
<button id="deleteTreeNode" onclick="removenode()"> <s:text name="msg.portalMS.system.delete"/></button>
</priveliege:priveliege>
<s:if test='#session.loginUser.city.levelType == "P"'>
<priveliege:priveliege funCode="allclone">
<button id="allclonebutton" onclick="allclone()"> <s:text name="msg.portalMS.category.clone.all"/></button>
</priveliege:priveliege>
</s:if>
<s:else>
<priveliege:priveliege funCode="delLocalAllCategory">
<button id="delallButton" onclick="removeLocalAll()"><s:text name="msg.portalMS.category.delete.all"/></button>
</priveliege:priveliege>
</s:else>
<button id="syncTreeNode" onclick="this.disabled=true;activethis();syncTreeNode()"> <s:text name="msg.portalMS.sysmgr.syncmanage.sync"/></button>
</div>
<s:select id="sitesid" list="sites" name="iepgSiteVO.terminalType"
listKey="siteID" listValue="alias"
onchange="changeTerminalType(this.value)" cssStyle="width:100%">
</s:select>
<div id="tree_div" cssStyle="width:99%,height:80%"></div>
<div id="pageOverlay" ></div>
</body>
</html>