All Downloads are FREE. Search and download functionalities are using the official Maven repository.

vm.maven.page_js_for_tree.vm Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
// JavaScript Document
/**
 * $!{tablePdmXml.name}管理界面
 * @type 
 */
$!{tablePdmXml.className}Panel = {
    version: '1.0',
    
	/**
	 * $!{tablePdmXml.name}数据根节点
	 * @type Ext.tree.AsyncTreeNode 
	 */
	$!{className}Root: null,
    
    /**
     * $!{tablePdmXml.name}数据
     * @type Ext.data.TreeStore 
     */
    $!{className}Store: null,
    
	/**
	 * $!{tablePdmXml.name}树控件对象
	 * @type Ext.ux.tree.TreeGrid 
	 */
	$!{className}Tree: null,
    
    /**
     * 链接:/$!{className}/{0}.do?txnCode=$!{txnCodePrefix}_{1}
     */
    URL_ACTION: '/$!{className}/{0}.do?txnCode=$!{txnCodePrefix}_{1}', 
    
    /**
     * 标题:$!{tablePdmXml.name}列表
     * @type String
     */
    TITLE_LIST: '$!{tablePdmXml.name}列表',
    /**
     * 标题:新增$!{tablePdmXml.name}
     * @type String
     */
    TITLE_ADD: '新增$!{tablePdmXml.name}',
    /**
     * 标题:复制$!{tablePdmXml.name}
     * @type String
     */
    TITLE_COPY: '复制$!{tablePdmXml.name}',
    /**
     * 标题:修改$!{tablePdmXml.name}
     * @type String
     */
    TITLE_UPDATE: '修改$!{tablePdmXml.name}',
    /**
     * 标题:查看$!{tablePdmXml.name}
     * @type String
     */
    TITLE_VIEW: '查看$!{tablePdmXml.name}',
    
    /**
     * 提示信息:没有调入任何参数!
     * @type String
     */
    MSG_ERR_PARAMS_NULL: '没有调入任何参数!',
    /**
     * 提示信息:缺少字段信息!
     * @type String
     */
    MSG_ERR_MODEL_STORE_NULL: '缺少字段信息!',
#foreach($columnPdmXml in $dictionaryList)
    /**
     * 提示信息:$!{columnPdmXml.name}的Json数据为空!
     * @type String
     */
    MSG_ERR_JSONDATA_${columnPdmXml.code.toUpperCase()}_NULL: '$!{columnPdmXml.name}的Json数据为空!',
#end
    
    /**
     * 对象信息:$!{tablePdmXml.name}
     * @type Ext.data.ArrayStore
     */
    MODEL_STORE_$!{tablePdmXml.className.toUpperCase()}: null,
#foreach($columnPdmXml in $dictionaryList)
    /**
     * Json数据:$!{columnPdmXml.name}类型
     * @type json 
     */
    JSONDATA_$!{columnPdmXml.code.toUpperCase()}: [],
#end
    /**
     * 是否允许查看详细页面
     * @type Boolean
     */
    IS_VIEW: null,
    /**
     * 动态表单控件
     * @type DevUtil.DynamicForm
     */
    dynamicForm: null,
    /**
     * 已选定记录的编号
     * @type String
     */
    selectedId: null,

#set($columnLength = 0)
#foreach($columnPdmXml in $dictionaryList)
#set($codeLength = $columnPdmXml.code.length())
#if($columnLength < $codeLength)
#set($columnLength = $codeLength)
#end
#end
#set($columnLength = $columnLength + 9)
#set($exSpace = "")
#set($spaceLength = 12)
#if($columnLength > 11)
#set($spaceLength = $columnLength+2)
#end
#set($length = $spaceLength - 12)
#foreach($i in [1..$length])
#set($exSpace = $exSpace + " ")
#end
    /**
     * 初始化
     * @param {Object}         params            $!{exSpace}传入参数
     * @param {Ext.data.Store} params.model_store$!{exSpace}字段信息数据源
#foreach($columnPdmXml in $dictionaryList)
#set($length = $spaceLength - $columnPdmXml.code.length() - 10)
#set($spaceNum = "")
#foreach($i in [1..$length])
#set($spaceNum = $spaceNum + " ")
#end
     * @param {json}           params.jsonData_$!{columnPdmXml.code}$!{spaceNum}Json数据:$!{columnPdmXml.name}
#end
     * @param {Boolean}        params.is_view    $!{exSpace}是否允许查看详细页面
     */
    init: function(params){
        if (params == null){
            alert($!{tablePdmXml.className}Panel.MSG_ERR_PARAMS_NULL);
            throw $!{tablePdmXml.className}Panel.MSG_ERR_PARAMS_NULL;
        }
        else if (params.model_store.getCount() == 0){
            alert(SysCodePanel.MSG_ERR_MODEL_STORE_NULL);
            throw $!{tablePdmXml.className}Panel.MSG_ERR_MODEL_STORE_NULL;
        }
#foreach($columnPdmXml in $dictionaryList)
        else if (params.jsonData_$!{columnPdmXml.code} == null){
            alert($!{tablePdmXml.className}Panel.MSG_ERR_JSONDATA_$!{columnPdmXml.code.toUpperCase()}_NULL);
            throw $!{tablePdmXml.className}Panel.MSG_ERR_JSONDATA_$!{columnPdmXml.code.toUpperCase()}_NULL;
        }
#end
        else{
	    	Ext.QuickTips.init();	
            
            $!{tablePdmXml.className}Panel.URL_ACTION = DevUtil.contextPath + $!{tablePdmXml.className}Panel.URL_ACTION; 
#foreach($columnPdmXml in $dictionaryList)
            $!{tablePdmXml.className}Panel.JSONDATA_$!{columnPdmXml.code.toUpperCase()} = params.jsonData_$!{columnPdmXml.code};
#end
            $!{tablePdmXml.className}Panel.IS_VIEW = params.is_view == null ? false : params.is_view;
            
            $!{tablePdmXml.className}Panel.MODEL_STORE_$!{tablePdmXml.className.toUpperCase()} = params.model_store;
        }
    },
    
#set($columnLength = 0)
#foreach($columnPdmXml in $dictionaryList)
#if($columnLength < $columnPdmXml.code.length())
#set($columnLength = $columnPdmXml.code.length())
#end
#end
#set($columnLength = $columnLength + 9)
#set($exSpace = "")
#set($spaceLength = 17)
#if($columnLength > 15)
#set($spaceLength = $columnLength+2)
#end
#set($length = $spaceLength - 16)
#foreach($i in [1..$length])
#set($exSpace = $exSpace + " ")
#end    
    /**
     * 绘画
     * @param {Object}         params                $!{exSpace}传入参数
     * @param {Ext.data.Store} params.model_store    $!{exSpace}字段信息数据源
     * @param {Ext.data.Store} params.quickSearchText$!{exSpace}快查文字信息
#foreach($columnPdmXml in $dictionaryList)
#set($length = $spaceLength - $columnPdmXml.code.length() - 10)
#set($spaceNum = "")
#foreach($i in [1..$length])
#set($spaceNum = $spaceNum + " ")
#end
     * @param {json}           params.jsonData_$!{columnPdmXml.code}$!{spaceNum}Json数据:$!{columnPdmXml.name}
#end
     * @param {Boolean}        params.is_view        $!{exSpace}是否允许查看详细页面
     */
    render: function(params){
        $!{tablePdmXml.className}Panel.init(params);
      
		var root = new Ext.tree.AsyncTreeNode({
			id: '0', name: $!{tablePdmXml.className}Panel.TITLE_LIST, expanded: true
		});
		var store = new Ext.ux.tree.TreeGridLoader({
        	dataUrl: String.format($!{tablePdmXml.className}Panel.URL_ACTION, 'search', 'SEARCH'),
            requestMethod: 'POST',
            listeners:{
              	'load': function(){
               		$!{tablePdmXml.className}Panel.setDisabledBtn(true);
               		$!{tablePdmXml.className}Panel.$!{className}Tree.expandAll();
               	}
            }
        });
        
        var modelLblNameObj = DevUtil.getModelLblNameObj($!{tablePdmXml.className}Panel.MODEL_STORE_$!{tablePdmXml.className.toUpperCase()});
        var tree = new Ext.ux.tree.TreeGrid({
            id: '$!{className}Tree', title: $!{tablePdmXml.className}Panel.TITLE_LIST, loader: store, 
            border: false, enableSort: false, width: DevUtil.getBodyWidth(), 
            height: DevUtil.getBodyHeight(), columns: [
#set($isFrist = true)
#foreach($columnPdmXml in $tablePdmXml.columnPdmXmlList)
#if($columnPdmXml.code.toLowerCase().indexOf("id") < 0 
        && $columnPdmXml.code != "createUser"
        && $columnPdmXml.code != "createTime"
        && $columnPdmXml.code != "modUser"
        && $columnPdmXml.code != "modTime"
        && $columnPdmXml.code != "remark")
#set($renderer = "")
#set($flex = 2)
#if($isFrist)
#set($isFrist = false)
#else
            ,
#end
#if($columnPdmXml.dictionary)   
#set($flex = 1) 
#if($columnPdmXml.code == "status")
#set($renderer = ", tpl: new Ext.XTemplate('{$!{columnPdmXml.code}:this.renderValue}', { renderValue:DevUtil.renderValue("+$!{tablePdmXml.className}+"Panel.JSONDATA_"+$!{columnPdmXml.code.toUpperCase()}+", {columnName: 'status'}) })")
#else
#set($renderer = ", tpl: new Ext.XTemplate('{$!{columnPdmXml.code}:this.renderValue}', { renderValue:DevUtil.renderValue("+$!{tablePdmXml.className}+"Panel.JSONDATA_"+$!{columnPdmXml.code.toUpperCase()}+") })")
#end
#end
              {
                  header: modelLblNameObj.$!{columnPdmXml.code}, dataIndex: '$!{columnPdmXml.code}', flex: $!{flex}
#if($renderer)                
                  $!{renderer}
#end
              }
#end
#end
            ],
            tbar: new Ext.Toolbar({
                id:'$!{className}Toolbar', enableOverflow: true, items: [
                    new Ext.ux.form.SearchField({
                    	id:'$!{className}Searchfield', store: store, 
                    	root: root, hidden: !params.quickSearchText,
                    	emptyText: DevUtil.P.Txt.QUICK_SEARCH + '(' + params.quickSearchText + ')'
                }),'-',
                {
                    text: DevUtil.P.BtnTxt.ADVANCED_SEARCH, iconCls: 'advancedSearch',
                    handler: function(){
                        var winId = 'win_$!{className}_Search';
                        var win = Ext.getCmp(winId);
                        if (!win){
                            win = new DevUtil.AdvancedSearch({
                                id: winId, searchfieldId: '$!{className}Searchfield',        
                                winTitle: $!{tablePdmXml.className}Panel.TITLE_LIST, 
                                ctrlStore: $!{tablePdmXml.className}Panel.MODEL_STORE_$!{tablePdmXml.className.toUpperCase()},    
                                store: store,
                                root: root
                            });
                        }
                        win.show();
                    }
                },'->']
            }),
            listeners:{
               	'click': function(node){
                    $!{tablePdmXml.className}Panel.setDisabledBtn(false);
                    $!{tablePdmXml.className}Panel.selectedId = node.id;
                },
               	'dblclick': function(node){
                    if ($!{tablePdmXml.className}Panel.IS_VIEW){
                        $!{tablePdmXml.className}Panel.createDynamicForm('view');
                        $!{tablePdmXml.className}Panel.dynamicForm.show({
                            action: 'view',
                            loadUrl: String.format($!{tablePdmXml.className}Panel.URL_ACTION, 'edit', 'EDIT'),
                            selectedId: node.id,
                            title: $!{tablePdmXml.className}Panel.TITLE_VIEW
                        });
                    }
                }
            }
        });
		tree.setRootNode(root);
		tree.render(Ext.getBody());
        
        Ext.EventManager.onWindowResize(function(w, h){
            if (w > 0 && h > 0){
                tree.setSize(w, h);
	    		tree.updateColumnWidths();
            }
        });
        
        $!{tablePdmXml.className}Panel.$!{className}Root = root;
		$!{tablePdmXml.className}Panel.$!{className}Store = store;
		$!{tablePdmXml.className}Panel.$!{className}Tree = tree;
    },
    
    /**
     * 添加主页面顶部按钮
     * @param {Object}  btn          按钮参数
     * @param {String}  btn.id       按钮编号
     * @param {String}  btn.text     按钮名称
     * @param {String}  btn.iconCls  按钮图标
     * @param {Boolean} btn.disabled 是否禁用按钮
     * @param {String}  btn.handler  按钮事件
     */
    addToolBar: function(btn){
        var toolBar = Ext.getCmp('$!{className}Toolbar');
        toolBar.add('-');
        toolBar.add({
            id: btn.id, text: btn.text, iconCls: btn.iconCls,
            disabled: btn.disabled ? btn.disabled : false,
            handler: btn.handler
        });
    },
    
    /**
     * 创建表单对象
     * @param {String} action 表单类型[save: 新增; copy: 复制; update: 编辑; view: 查看详细页面]
     */
    createDynamicForm: function(action){    
        $!{tablePdmXml.className}Panel.dynamicForm = new DevUtil.DynamicForm({
            action: action,
            postUrl: String.format($!{tablePdmXml.className}Panel.URL_ACTION, 
                                   'copy' == action ? 'save' : action, 
                                   action.toUpperCase()),
            columnStore: $!{tablePdmXml.className}Panel.MODEL_STORE_$!{tablePdmXml.className.toUpperCase()},
            dataStore: $!{tablePdmXml.className}Panel.$!{className}Store, root: $!{tablePdmXml.className}Panel.$!{className}Root
//			,beforCreateCtrlFn: function(ctrlName, action, formId, ctrlObj){
//			}
        });    
    },
    
    /**
     * 添加新增按钮
     */
    addAddBtn: function(){
        $!{tablePdmXml.className}Panel.addToolBar({
            id: '$!{className}AddBtn',
            text: DevUtil.P.BtnTxt.ADD, 
            iconCls: DevUtil.P.Icons.ADD,
            handler: function(){
                $!{tablePdmXml.className}Panel.createDynamicForm('save');
                $!{tablePdmXml.className}Panel.dynamicForm.on('afterLoad', function(win){
#foreach($columnPdmXml in $dictionaryList)
                    Ext.getCmp(win.getId()+'_$!{columnPdmXml.code}').setValue(DevUtil.getDefaultValue($!{tablePdmXml.className}Panel.JSONDATA_$!{columnPdmXml.code.toUpperCase()}));
#end
                });
                $!{tablePdmXml.className}Panel.dynamicForm.show({
                    title: $!{tablePdmXml.className}Panel.TITLE_ADD
                });
            }
        });
    },
    
    /**
     * 添加复制按钮
     */
    addCopyBtn: function(){
        $!{tablePdmXml.className}Panel.addToolBar({
            id: '$!{className}CopyBtn',
            text: DevUtil.P.BtnTxt.COPY, 
            iconCls: DevUtil.P.Icons.COPY,
            disabled: true,
            handler: function(){                
                $!{tablePdmXml.className}Panel.createDynamicForm('copy');
                $!{tablePdmXml.className}Panel.dynamicForm.show({
                    loadUrl: String.format($!{tablePdmXml.className}Panel.URL_ACTION, 'edit', 'EDIT'),
                    selectedId: $!{tablePdmXml.className}Panel.selectedId,
                    title: $!{tablePdmXml.className}Panel.TITLE_COPY
                });
                $!{tablePdmXml.className}Panel.dynamicForm.on('afterLoad', function(win){
                    Ext.getCmp(win.getId()+'_id').reset();
#foreach($columnPdmXml in $tablePdmXml.columnPdmXmlList)
#if(!$columnPdmXml.isPK && "String" == $!columnPdmXml.dataType)  
                    var $!{columnPdmXml.code} = Ext.getCmp(win.getId()+'_$!{columnPdmXml.code}');
                    $!{columnPdmXml.code}.setValue($!{columnPdmXml.code}.getValue()+'_c'); 
#break
#end
#end                    
                });
            }
        });
    },
    
    /**
     * 添加修改按钮
     */
    addUpdateBtn: function(){
        $!{tablePdmXml.className}Panel.addToolBar({
            id: '$!{className}UpdateBtn',
            text: DevUtil.P.BtnTxt.UPDATE, 
            iconCls: DevUtil.P.Icons.UPDATE,
            disabled: true,
            handler: function(){                
                $!{tablePdmXml.className}Panel.createDynamicForm('update');
                $!{tablePdmXml.className}Panel.dynamicForm.show({
                    loadUrl: String.format($!{tablePdmXml.className}Panel.URL_ACTION, 'edit', 'EDIT'),
                    selectedId: $!{tablePdmXml.className}Panel.selectedId,
                    title: $!{tablePdmXml.className}Panel.TITLE_UPDATE
                });
            }
        });
    },
#if($isSort)  
      
    /**
     * 添加同级排序按钮
     */
    addSortBtn: function(){
        $!{tablePdmXml.className}Panel.addToolBar({
            id: '$!{className}SortBtn',
            text: DevUtil.P.BtnTxt.SORT, 
            iconCls: DevUtil.P.Icons.SORT,
            disabled: true,
            handler: function(){
                var code = $!{tablePdmXml.className}Panel.$!{className}Tree.getNodeById($!{tablePdmXml.className}Panel.selectedId).attributes.code;
                new DevUtil.SortData({
                    url: String.format($!{tablePdmXml.className}Panel.URL_ACTION, 'searchSort', 'SORT&code='+code),
                    postUrl: String.format($!{tablePdmXml.className}Panel.URL_ACTION, 'sort', 'SORT'),
                    store: $!{tablePdmXml.className}Panel.$!{className}Store, root: $!{tablePdmXml.className}Panel.$!{className}Root
                }).show();
            }
        });
    },
#end
#if($isStatus)  
      
    /**
     * 添加启用/禁用按钮
     */
    addStatusBtn: function(){
        $!{tablePdmXml.className}Panel.addToolBar({
            id: '$!{className}StatusBtn',
            text: DevUtil.P.BtnTxt.STATUS, 
            iconCls: DevUtil.P.Icons.STATUS,
            disabled: true,
            handler: function(){
                DevUtil.updateStatusRecord({
                    url: String.format($!{tablePdmXml.className}Panel.URL_ACTION, 'status', 'STATUS'),
                    id: $!{tablePdmXml.className}Panel.selectedId,
                    store: $!{tablePdmXml.className}Panel.$!{className}Store, 
                    root: $!{tablePdmXml.className}Panel.$!{className}Root
                });
            }
        });
    },
#end
    
    /**
     * 添加删除按钮
     */
    addDelBtn: function(){
        $!{tablePdmXml.className}Panel.addToolBar({
            id: '$!{className}DelBtn',
            text: DevUtil.P.BtnTxt.DEL, 
            iconCls: DevUtil.P.Icons.DEL,
            disabled: true,
            handler: function(){
                DevUtil.deleteRecord({
                    url: String.format($!{tablePdmXml.className}Panel.URL_ACTION, 'delete', 'DELETE'),
                    id: $!{tablePdmXml.className}Panel.selectedId,
                    store: $!{tablePdmXml.className}Panel.$!{className}Store, 
                    root: $!{tablePdmXml.className}Panel.$!{className}Root
                });
            }
        });
    },
    
    /**
     * 设置页面按钮是否禁用
     * @param {Boolean} isDisabled 是否禁用
     */
    setDisabledBtn: function(isDisabled){
#set($btnIds = "")
#if($isSort)  
#set($btnIds = ",'"+$className+"SortBtn'") 
#end
#if($isStatus)  
#set($btnIds = $btnIds + ",'"+$className+"StatusBtn'") 
#end
        var btnIds = ['$!{className}CopyBtn','$!{className}UpdateBtn','$!{className}DelBtn'$!{btnIds}];
        for(var i = 0, len = btnIds.length; i < len; i++){
            var btn = Ext.getCmp(btnIds[i]);
            if (btn) btn.setDisabled(isDisabled);
        }
        if (isDisabled) $!{tablePdmXml.className}Panel.selectedId = null; 
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy