|
楼主 |
发表于 2011-1-6 11:47:44
|
显示全部楼层
[PHP]
var mainActivity = {};
mainActivity.dataMainAfterNew = function(event){
mainActivity.generateFid(event);
};
mainActivity.grdMainAfterRowDrag = function(event){
var treeData= event.instance;
treeData.setValue('fParentId',event.targetRowId,event.srcRowId);
mainActivity.generateFid(event);
};
/**
* @autho 007slm
* @desc 用来生成当前节点的全路径id的函数
*/
mainActivity.generateFid=function(event){
/**
* 如果是拖拽的情况
*/
if(event.srcParentRowId){
debugger;
var treeData= event.instance;
treeData.setValue('fIsLeafNode','',event.targetRowId);
if(treeData.getValue('fIsLeafNode',event.srcParentRowId)==''){
/**
* 拖拽的时候如果移动的节点的父节点已经没有子节点,那么修改这个父节点的状态时叶子节点
*/
if(treeData.store.hasChildren(event.srcParentRowId)==0){
treeData.setValue('fIsLeafNode','nkLeaf',event.srcParentRowId);
}
}
var fParentFID=treeData.getValue('fFID',event.instance.getValue('fParentId',event.srcRowId));
var fParentLevel=treeData.getValue('fLevel',event.instance.getValue('fParentId',event.srcRowId));
/**
* 拖拽的节点依照父节点的level重新计算自己的level
*/
if(parseInt(fParentLevel)){
var fLevelValue=parseInt(fParentLevel)+1;
}
var fFID=fParentFID+"/"+event.srcRowId;
treeData.setValue('fFID',fFID,event.srcRowId);
treeData.setValue('fLevel',fLevelValue,event.srcRowId);
/**
* 如果是新增的情况
*/
}
else if(event.id){
var treeData= event.instance;
var fParentFID=treeData.getValue('fFID',event.instance.getValue('fParentId',event.id));
var fFID=fParentFID+"/"+event.id;
treeData.setValue('fFID',fFID,event.id);
}
};
[/PHP]
java部分
[PHP]
public static void dragableProcessBeforeSaveDE_TreeAction() {
/**
* 获取要保存的table对象
*/
Table table =(Table)ContextHelper.getActionContext().getParameter("table");
String dataModel =(String)ContextHelper.getActionContext().getParameter("dataModel");
for(Iterator<Row> it =table.iterator(ModifyState.EDIT);it.hasNext();){
/**
* 遍历table中已经修改的行,找到因为父id修改的行
*/
Row row =it.next();
boolean modefied = row.isModified("fParentId");
if(modefied){
String newfFId =(String)row.getValue("fFID");
String oldfFId =(String)row.getOldValue("fFID");
String DE_Tree=(String)row.getValue("DE_Tree");
String oldLevel=(String)row.getOldValue("fLevel");
String newLevel=(String)row.getValue("fLevel");
int diff=Integer.parseInt(newLevel)-Integer.parseInt(oldLevel);
/**
* 更行因为拖拽造成的全路径id和level的变动,包括拖拽的子节点的变动
*/
String updateFid="UPDATE DE_Tree DE_Tree set DE_Tree.fFID = REPLACE(DE_Tree.fFID,'"+oldfFId+"','"+newfFId+"') WHERE DE_Tree.fFID like '%/"+DE_Tree+"/%'";
String updateLevel="UPDATE DE_Tree DE_Tree set DE_Tree.fLevel = DE_Tree.fLevel + "+diff+" WHERE DE_Tree.fFID like '%/"+DE_Tree+"/%'";
if (logger.isInfoEnabled()){
logger.info("准备执行的语句是 updateFid:" + updateFid+"\nupdateLevel:"+updateLevel);
}
KSQL.executeUpdate(updateFid, null, dataModel, null);
KSQL.executeUpdate(updateLevel, null, dataModel, null);
}
}
}
[/PHP] |
|