标签:
processEvent : function(type, view, cell, recordIndex, cellIndex, e,
record, row) {
var me = this;
if (type === 'click') {
var module = this.up('modulegrid').module;
if (e.getTarget().className === 'manyToManyContext') {
app.modules.showModuleRecord(this.manyToManyModuleName, e
.getTarget().getAttribute('_id'));
} else if (Ext.String.startsWith(e.getTarget().className,
'manyToManyContextClose')) {
// 点击了删除按钮,先找到前面一个节点,里面包含了要删除的信息
var target = e.getTarget().previousElementSibling;
var text = module.tf_title + ' ' + record.getTitleTpl() + ' 的 '
+ this.manyToManyModuleTitle + '【' + target.innerHTML + '】';
Ext.MessageBox.confirm('确定删除', '确定要删除' + text + '吗?', function(
btn) {
if (btn == 'yes') {
// 使用module里面批量删除的ajax
Ext.Ajax.request({
url : 'rest/module/removerecords.do',
params : {
moduleName : me.fieldDefine.tf_joinTable,
ids : target.getAttribute('_joinid'),
titles : target.innerHTML
},
success : function(response) {
var info = Ext.decode(response.responseText, true);
if (info.resultCode == 0) {
Ext.toastInfo(text + ' 已成功被删除。');
// 删除记录后,刷新当前记录
me.up('modulegrid').refreshSelectedRecord();
} else {
Ext.MessageBox.show({
title : '删除结果',
msg : text + '删除失败:<br/><br/>'
+ info.errorMessageList,
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.ERROR
});
}
},
failure : function() {
window.alert('删除时,服务器返回返回错误');
}
})
}
});
} else if (Ext.String.startsWith(e.getTarget().className,
'manyToManyEdit')) {
//编辑当前记录的manyToMany字段;
Ext.widget(
'manytomanyeditwindow',
{
grid : me.up('modulegrid'),
title : module.tf_title + '【' + record.getTitleTpl()
+ '】的' + this.manyToManyModuleTitle,
moduleName : module.tf_moduleName,
idvalue : record.getIdValue(),
manyToManyModuleName : me.manyToManyModuleName,
linkModuleName : me.fieldDefine.tf_joinTable
}).show();
}
}
}/**
* 修改记录的manyToMany字段的窗口,在窗口中完成选择操作,并可保存。
*/
Ext.define('app.module.widget.window.ManyToManyEditWindow', {
extend : 'Ext.window.Window',
alias : 'widget.manytomanyeditwindow',
requires : [ 'app.lib.CheckTreePanel' ],
width : 450,
height : 600,
modal : true,
maximizable : true,
layout : 'fit',
buttons : [ '->', {
text : '保存',
iconCls : 'fa fa-save',
handler : function(button) {
var window = button.up('window');
var tree = window.down('treepanel');
var selected = []
tree.getRootNode().cascadeBy(function(node) {
// 所有选中的 ManyToMany 的值
if (node.data.checked == true && node.data.leaf == true) {
selected.push(node.data.fieldvalue);
}
});
// 提交ajax请求后台修改
Ext.Ajax.request({
url : 'modulemanytomany/setmanytomanydetail.do',
params : {
moduleName : window.moduleName,
id : window.idvalue,
manyToManyModuleName : window.manyToManyModuleName,
linkModuleName : window.linkModuleName,
selected : selected.join(',')
},
success : function(response) {
var info = Ext.decode(response.responseText, true);
if (info.success) {
Ext.toastInfo(window.titlemess + ' 已保存。');
window.grid.refreshSelectedRecord();
window.close();
} else
Ext.toastError(window.titlemess + ' 保存失败。<br>' + '原因:' + info.msg);
}
})
}
}, {
text : '关闭',
iconCls : 'fa fa-close',
handler : function(button) {
button.up('window').close();
}
}, '->' ],
initComponent : function() {
var me = this;
this.titlemess = this.title;
this.title = '设置 ' + this.titlemess;
this.items = [ {
xtype : 'checktreepanel',
autoLoad : false,
rootVisible : false,
root : {},
store : Ext.create('Ext.data.TreeStore', {
proxy : {
type : 'ajax',
url : 'modulemanytomany/getmanytomanydetail.do',
extraParams : {
moduleName : me.moduleName,
id : me.idvalue,
manyToManyModuleName : me.manyToManyModuleName,
linkModuleName : me.linkModuleName
}
}
})
} ];
this.callParent(arguments);
}
})package com.jfok.cfcmms.controller;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jfok.cfcmms.service.ModuleManyToManyService;
import com.jfok.cfcmms.share.TreeNodeRecordChecked;
import com.jfok.cfcmms.util.ActionResult;
/**
* 用来管理模块的ManyToMany数据的读取和修改的保存
*
* @author jiangfeng
*
* 2016-01-11
*
*/
@Controller
@RequestMapping("/modulemanytomany")
public class ModuleManyToManyController {
@Resource
private ModuleManyToManyService moduleManyToManyService;
/**
*
* @param request
* @param moduleName
* 当前模块名称
* @param id
* 当前记录id
* @param manyToManyModuleName
* manyToMany的模块名称
* @param linkModuleName
* 中间模块名称
* @return 返回所有manyToManyModuleName的记录数据,并把当前记录已有的manyToMany值的checked置为true
*/
@RequestMapping("/getmanytomanydetail.do")
public @ResponseBody List<TreeNodeRecordChecked> genManyToManyDetail(HttpServletRequest request,
String moduleName, String id, String manyToManyModuleName, String linkModuleName) {
return moduleManyToManyService.getManyToManyDetail(request, moduleName, id,
manyToManyModuleName, linkModuleName);
}
/**
*
* @param request
* @param moduleName
* 当前模块名称
* @param id
* 当前记录id
* @param manyToManyModuleName
* manyToMany的模块名称
* @param linkModuleName
* 中间模块名称
* @param selected
* 所有选中的值,以逗号分隔
* @return 返回所有manyToManyModuleName的记录数据,并把当前记录已有的manyToMany值的checked置为true
*/
@RequestMapping("/setmanytomanydetail.do")
public @ResponseBody ActionResult setManyToManyDetail(HttpServletRequest request,
String moduleName, String id, String manyToManyModuleName, String linkModuleName,
String selected) {
return moduleManyToManyService.setManyToManyDetail(request, moduleName, id,
manyToManyModuleName, linkModuleName, selected.split(","));
}
}
package com.jfok.cfcmms.service;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.jfok.cfcmms.DAO.ModuleDAO;
import com.jfok.cfcmms.DAO.SystemBaseDAO;
import com.jfok.cfcmms.core.module.SqlGenerator;
import com.jfok.cfcmms.core.module.SqlModuleFilter;
import com.jfok.cfcmms.hibernate.system.module._Module;
import com.jfok.cfcmms.share.TreeNodeRecord;
import com.jfok.cfcmms.share.TreeNodeRecordChecked;
import com.jfok.cfcmms.share.ValueText;
import com.jfok.cfcmms.util.ActionResult;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Service
public class ModuleManyToManyService {
@Resource
private SystemBaseDAO systemBaseDAO;
@Resource
private ModuleDAO moduleDAO;
@Resource
private ModuleService moduleService;
/**
*
* @param request
* @param moduleName
* 当前模块名称
* @param id
* 当前记录id
* @param manyToManyModuleName
* manyToMany的模块名称
* @param linkModuleName
* 中间模块名称
* @return 返回所有manyToManyModuleName的记录数据,并把当前记录已有的manyToMany值的checked置为true
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List<TreeNodeRecordChecked> getManyToManyDetail(HttpServletRequest request,
String moduleName, String id, String manyToManyModuleName, String linkModuleName) {
_Module module = SystemAndLoginInfoService.getModuleWithName(moduleName);
_Module manyToManyModule = SystemAndLoginInfoService.getModuleWithName(manyToManyModuleName);
List<TreeNodeRecord> result = new ArrayList<TreeNodeRecord>();
// 首先读取manyToManyModuleName中的所有权限可视范围之内的数据
List<ValueText> allTreeItems = moduleDAO.getModuleWithComboDataWithQuery(manyToManyModuleName,
null, request);
for (ValueText vt : allTreeItems) {
TreeNodeRecordChecked record = new TreeNodeRecordChecked();
record.setFieldvalue(vt.getValue());
record.setText(vt.getText());
record.setLeaf(true);
result.add(record);
}
// 在linkModuleName中读取当前id的manyToMany的值,在数据可视涠之内
List<SqlModuleFilter> filters = new ArrayList<SqlModuleFilter>();
SqlModuleFilter moduleIdFilter = new SqlModuleFilter();
moduleIdFilter.setModuleName(module.getTf_moduleName());
moduleIdFilter.setTableAsName(module.getTableAsName());
moduleIdFilter.setPrimarykey(module.getTf_primaryKey());
moduleIdFilter.setEqualsValue(id);
filters.add(moduleIdFilter);
SqlGenerator generator = new SqlGenerator(linkModuleName, request);
generator.setModuleFilters(filters);
JSONArray dataArray = moduleDAO.getData(generator, -1, 0);
// 生成TreeNodeRecordChecked,并加入checked标志
for (int i = 0; i < dataArray.size(); i++) {
String manytomanyid = dataArray.getJSONObject(i).getString(
manyToManyModule.getTableAsName() + "___" + manyToManyModule.getTf_primaryKey());
for (TreeNodeRecord record : result) {
if (record.getFieldvalue().equals(manytomanyid))
((TreeNodeRecordChecked) record).setChecked(true);
}
}
// 返回结果
List<TreeNodeRecordChecked> root = new ArrayList<TreeNodeRecordChecked>();
TreeNodeRecordChecked rootrecord = new TreeNodeRecordChecked();
rootrecord.setText(manyToManyModule.getTf_title());
rootrecord.setChildren(result);
rootrecord.setExpanded(true);
root.add(rootrecord);
return root;
}
public ActionResult setManyToManyDetail(HttpServletRequest request, String moduleName, String id,
String manyToManyModuleName, String linkModuleName, String[] selected) {
_Module module = SystemAndLoginInfoService.getModuleWithName(moduleName);
_Module manyToManyModule = SystemAndLoginInfoService.getModuleWithName(manyToManyModuleName);
_Module linkedModule = SystemAndLoginInfoService.getModuleWithName(linkModuleName);
// 在linkModuleName中读取当前id的manyToMany的值,在数据可视涠之内
List<SqlModuleFilter> filters = new ArrayList<SqlModuleFilter>();
SqlModuleFilter moduleIdFilter = new SqlModuleFilter();
moduleIdFilter.setModuleName(module.getTf_moduleName());
moduleIdFilter.setTableAsName(module.getTableAsName());
moduleIdFilter.setPrimarykey(module.getTf_primaryKey());
moduleIdFilter.setEqualsValue(id);
filters.add(moduleIdFilter);
SqlGenerator generator = new SqlGenerator(linkModuleName, request);
generator.setModuleFilters(filters);
JSONArray dataArray = moduleDAO.getData(generator, -1, 0);
// 如果原来有,现在selected里面没有了,那么就要删除了
for (int i = 0; i < dataArray.size(); i++) {
String manytomanyid = dataArray.getJSONObject(i).getString(
manyToManyModule.getTableAsName() + "___" + manyToManyModule.getTf_primaryKey());
boolean isfound = false;
for (String selectedid : selected) {
if (manytomanyid.equals(selectedid)) {
isfound = true;
break;
}
}
if (!isfound) {
// 需要删除这个manyTomany,调用系统Service的remove,会判断能否删除的逻辑,会记入日志
// 尚未做出错处理
moduleService.remove(linkModuleName,
dataArray.getJSONObject(i).getString(linkedModule.getTf_primaryKey()), request);
}
}
// 如果原来没有,现在selected里面有了,那么就要增加进去
for (String selectedid : selected) {
if (selectedid.length() > 0) {
boolean isfound = false;
for (int i = 0; i < dataArray.size(); i++) {
String manytomanyid = dataArray.getJSONObject(i).getString(
manyToManyModule.getTableAsName() + "___" + manyToManyModule.getTf_primaryKey());
if (manytomanyid.equals(selectedid)) {
isfound = true;
break;
}
}
if (!isfound) {
JSONObject object = new JSONObject();
object.put(
manyToManyModule.getTableAsName() + "___" + manyToManyModule.getTf_primaryKey(),
selectedid);
object.put(module.getTableAsName() + "___" + module.getTf_primaryKey(), id);
// 需要新增这个manyTomany,调用系统Service的add ,会判断是否能新增等逻辑,会记入日志
// 尚未做出错处理
moduleService.add(linkModuleName, object.toString(), request);
}
}
}
ActionResult result = new ActionResult();
return result;
}
}
常规功能和模块自定义系统 (cfcmms)—030开发日志(创建ManyToMany的column5)
标签:
原文地址:http://blog.csdn.net/jfok/article/details/50493145