sys_function.lview 17.8 KB
Newer Older
Spencer Chang's avatar
Spencer Chang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: machao1505 $
    $Date: 2010/12/21 09:04:27 $
    $Revision: 1.12 $
    $Purpose: 功能定义
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:view>
        <a:link id="sys_function_getcontainsbm_link" url="${/request/@context_path}/modules/sys/SYS8010/sys_function_getcontainsbm.lsc"/>
        <a:link id="bm_accesscheck_link" model="sys.SYS8010.bm_accesscheck" modelaction="query"/>
        <a:link id="bmLink_function_service" model="sys.SYS8010.sys_function_service" modelaction="query"/>
        <a:link id="sys_function_autobm_link" url="${/request/@context_path}/modules/sys/SYS8010/sys_function_autobm.lsc"/>
        <a:link id="sys_function_makezip_link" url="${/request/@context_path}/modules/sys/SYS8010/sys_function_makezip.lsc"/>
        <a:link id="sys_function_tree_link" url="${/request/@context_path}/modules/sys/SYS8010/sys_function_tree.lview"/>
        <a:link id="sys_function_bm_link" url="${/request/@context_path}/modules/sys/SYS8010/sys_function_bm.lview"/>
        <a:link id="pageLink_function_service" url="${/request/@context_path}/modules/sys/SYS8010/sys_function_service.lview"/>
        <a:link id="sys_service_welcome_link" url="${/request/@context_path}/welcome.lview"/>
        <script type="text/javascript"><![CDATA[
            
            function functionDs_query() {
                $('functionDs').query();
            }
            
            function resetFunction() {
                $('para_functionDs').reset();
            }

        	function functionDs_grid_add(){
                $('functionDs_grid').showEditorByRecord($('functionDs').create());
            }
            function functionDs_grid_clear(){
                $('functionDs_grid').clear();
            }
            function functionDs_grid_remove(){
                $('functionDs_grid').remove();
            }
            function functionDs_grid_submit() {
                var ds = $('functionDs');
                if (ds.validate()) {
                    ds.submit();
                }
            }
            function sys_8010_next(){
                history.go(1);
            }
            function sys_8010_back(){
                history.go(-1);
            }
            function sys_8010_quit(){
                location.href = $('sys_service_welcome_link').getUrl();
            }
            
            function openAssignPage(id) {
                new Leaf.Window({
                    id: 'sys_function_service_assign_window',
                    url: $('pageLink_function_service').getUrl(),
                    params:{
                    	function_id : id
                    },
                    title: '${l:SYS8010.LINK.ASSIGN_PAGE}',
                    height: 480,
                    width: 680
                });
            }
            
            function openAssignBM(id) {
                new Leaf.Window({
                    id: 'sys_function_bm_window',
                    url: $('sys_function_bm_link').getUrl(),
                    params:{
                    	function_id : id
                    },
                    title: '${l:SYS8010.LINK.ASSIGN_BM}',
                    height: 480,
                    width: 680
                });
            }
            
            
            function downloadFunction(f_id,fn) {
                Leaf.request({
                    url:$('sys_function_makezip_link').getUrl(),
                    para:{
                        'function_id':f_id,
                        'filename':fn
                    },
                    success:function(args){
                        location.pathname = "${/request/@context_path}/"+fn+".zip";
                    }
                });
            }
            
            function render_functionDs_grid(value, record, name) {
                if(name=='parent_function_name')
                {
                    return ( !! value) ? value : '<font color="red">${l:ROOT}</font>';
                }
                var function_id = record.get('function_id');
                var function_type = record.get('function_type');
                if(record.isNew||Ext.isEmpty(function_id)||function_type=='G')
                {
                    return '';
                }
                else
                {
                    if(name=='assign_page')
	                {
		                return '<a href="javascript:openAssignPage(' + function_id + ')">${l:SYS8010.LINK.ASSIGN_PAGE}</a>';
	                }
	                if(name=='assign_bm')
	                {
		                return '<a href="javascript:openAssignBM(' + function_id + ')">${l:SYS8010.LINK.ASSIGN_BM}</a>';
	                }
	                if(name=='download')
	                {
		                return '<a href="javascript:downloadFunction(' + function_id + ',\'' + record.get('function_code') + '\')" title="${l:HAP_DOWNLOAD}"><img src="${/request/@context_path}/images/download.png"/></a>';
	                }
	                return '';
                }
                return '';
                
            }
            
            function onUpdate_functionDs(ds, record, name, value) {
                if (name == 'function_type') {
                    if (value == 'G') {
                        record.set('command_line', '');
                    }
                    if(value!='F'){
                        record.set('service_name','');
                        record.set('service_id','');
                    }
                    record.getMeta().getField('service_name').setRequired(value == 'F');
                }
            }
            
            function viewFunctionTree() {
                new Leaf.Window({
                    id: 'sys_function_tree_window',
                    url: $('sys_function_tree_link').getUrl(),
                    title: '${l:SYS8010.BUTTON.VIEW_FUNCTION_TREE}',
                    height: 500,
                    width: 400
                });
            }
            
            function editorFun_functionDs_grid(record, name) {
                if(name=='function_code')
                {
                    if(record.isNew)
                    {
                        return 'functionDs_grid_tf_upper';
                    }
                    return '';
                }
                return '';
            }
            
            Array.prototype.indexOf = function(ele) {
                for (var i = 0;i < this.length;i++) {
                    if (this[i] == ele) {
                        return i;
                    }
                }
                return -1;
            };
            
            //在不重复的情况下添加新数据
            Array.prototype.union = function(ele) {
                if (this.indexOf(ele) == -1) {
                    this.add(ele);
                }
            };
            
            function fetchBM() {
                var ds = $('functionDs');
                var recs = ds.getSelected(); //取得选定的所有行
                if (!recs.length) {
                    return;
                }
            
                var nrecs = [];
                ///////取得所有需要插入的数据
                for (var i = 0;i < recs.length;i++) {
                    var f_id = recs[i].get('function_id');
                    if (!f_id || recs[i].get('function_type') != 'F' || !recs[i].validateRecord()) {
                        continue; //过滤未保存的新行,过滤不是"功能"的行,过滤没有主页面的行
                    }
                    var bma = fetchBM(f_id)[0];
                    for (var m = 0;m < bma.length;m++) {
                        nrecs.add({
                            'function_id': f_id,
                            'bm_name': bma[m],
                            'insert_option': 'Y',
                            'update_option': 'Y',
                            'delete_option': 'Y',
                            'query_option': 'Y',
                            'execute_option': 'Y',
                            '_status': 'insert'
                        });
                    }
                }
                /////
                Leaf.request({
                    url: $('sys_function_autobm_link').getUrl(),
                    para: nrecs,
                    //success: function(args3) {
                    //    alert(Ext.util.JSON.encode(args3));
                    //},
                    scope: this
                });
            }
            
            
            function getRegisteredPage(function_id) {
                var pages = [];
                Leaf.request({ //取得当前功能所分配的页面
                    url: $('bmLink_function_service').getUrl()+'?function_id=' + function_id,
                    success: function(args0) {
                        if (!args0.result.record) {
                            return;
                        }
                        pages = [].concat(args0.result.record);
                    },
                    scope: this,
                    sync: true
                });
                return pages;
            }
            
            //取得页面已经注册过的BM,数组
            
            function getRegisteredBM(function_id) {
                var bmArrayo = [];
                Leaf.request({
                    url: $('bm_accesscheck_link').getUrl()+'?function_id=' + function_id,
                    success: function(args2) {
                        if (!args2.result.record) {
                            return;
                        }
                        var recs = [].concat(args2.result.record);
                        for (var i = 0;i < recs.length;i++) {
                            var sn = recs[i].bm_name.trim();
                            if (sn.length > 0) { //去掉空的,以及重复的
                                bmArrayo.union(sn);
                            }
                        }
                    },
                    scope: this,
                    sync: true
                });
                return bmArrayo;
            }
            
            //取得所有应该注册但还没有注册bm,和已经注册过的bm
            
            function fetchBM(function_id) {
                var bmArray = []; //页面中引用了但还没有注册的bm
                var bmArrayo = getRegisteredBM(function_id);
            
                var pages = getRegisteredPage(function_id);
                for (var i = 0;i < pages.length;i++) { //对于每个页面...
                    Leaf.request({ //对于每个页面,取得其关联的bm
                        url: $('sys_function_getcontainsbm_link').getUrl(),
                        para: {
                            'scrpath': pages[i].service_name
                        },
                        success: function(args1) {
                            var bmrs = args1.result.record;
                            if (!bmrs) {
                                return;
                            }
                            bmrs = [].concat(bmrs);
                            for (var j = 0;j < bmrs.length;j++) {
                                if (bmrs[j].bm.length > 0) {
                                    if (bmArrayo.indexOf(bmrs[j].bm) == -1) {
                                        bmArray.union(bmrs[j].bm);
                                    }
                                }
                            }
                        },
                        scope: this,
                        sync: true
                    });
                }
                return [bmArray, bmArrayo];
            }
            
           ]]></script>
        <a:dataSets>
            <a:dataSet id="function_type_ds" lookupCode="FUNCTION_TYPE"/>
            <a:dataSet id="para_functionDs" autoCreate="true" model="sys.SYS8010.sys_function">
                <a:fields>
                    <a:field name="parent_function_name" autoComplete="true" autoCompleteField="function_name" lovGridHeight="300" lovHeight="460" lovService="sys.SYS8010.sys_function_lov" lovWidth="480" title="SYS8010.SYS_FUNCTION.PARENT_FUNCTION">
                        <a:mapping>
                            <a:map from="function_id" to="parent_function_id"/>
                            <a:map from="function_name" to="parent_function_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="function_type_desc" displayField="code_value_name" options="function_type_ds" returnField="function_type" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="functionDs" autoQuery="true" model="sys.SYS8010.sys_function" pageSize="15" queryDataSet="para_functionDs" selectable="true">
                <a:fields>
                    <a:field name="function_code" required="true"/>
                    <a:field name="function_name" required="true"/>
                    <a:field name="parent_function_name" autoComplete="true" autoCompleteField="function_name" lovGridHeight="300" lovHeight="450" lovService="sys.SYS8010.sys_function_lov?function_type=G" lovWidth="500" title="SYS8010.SYS_FUNCTION.PARENT_FUNCTION">
                        <a:mapping>
                            <a:map from="function_id" to="parent_function_id"/>
                            <a:map from="function_name" to="parent_function_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="service_name" lovGridHeight="330" lovHeight="460" lovService="sys.sys_service" lovWidth="450" title="SYS8010.SYS_FUNCTION.SERVICE_NAME">
                        <a:mapping>
                            <a:map from="service_id" to="service_id"/>
                            <a:map from="service_name" to="service_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="function_type_desc" displayField="code_value_name" options="function_type_ds" required="true" returnField="function_type" valueField="code_value"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="onUpdate_functionDs"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="sys_8010_back" text="HLS.BACK"/>
                <a:gridButton click="sys_8010_next" text="HLS.FORWARD"/>
                <a:gridButton click="sys_8010_quit" text="HLS.EXIT"/>
                <a:gridButton click="functionDs_grid_add" text="HLS.NEW"/>
                <a:gridButton click="functionDs_grid_remove" text="HLS.REMOVE"/>
                <a:gridButton click="functionDs_grid_clear" text="HLS.CLEAR"/>
                <a:gridButton click="functionDs_grid_submit" text="HLS.SAVE"/>
                <a:gridButton click="functionDs_query" text="HLS.QUERY"/>
                <a:gridButton click="viewFunctionTree" text="SYS8010.BUTTON.VIEW_FUNCTION_TREE"/>
                <a:gridButton click="fetchBM" text="SYS8010.BUTTON.FETCH_BM"/>
            </a:screenTopToolbar>
            <a:form column="4" title="HAP_QUERY_TITLE">
                <a:textField name="function_code" bindTarget="para_functionDs" typeCase="upper">
                    <a:events>
                        <a:event name="enterdown" handler="functionDs_query"/>
                    </a:events>
                </a:textField>
                <a:textField name="function_name" bindTarget="para_functionDs">
                    <a:events>
                        <a:event name="enterdown" handler="functionDs_query"/>
                    </a:events>
                </a:textField>
                <a:lov name="parent_function_name" bindTarget="para_functionDs">
                    <a:events>
                        <a:event name="commit" handler="functionDs_query"/>
                    </a:events>
                </a:lov>
                <a:comboBox name="function_type_desc" bindTarget="para_functionDs">
                    <a:events>
                        <a:event name="select" handler="functionDs_query"/>
                    </a:events>
                </a:comboBox>
            </a:form>
            <a:grid id="functionDs_grid" bindTarget="functionDs" marginHeight="180" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="function_code" editorFunction="editorFun_functionDs_grid" lock="true" width="100"/>
                    <a:column name="function_name" editor="functionDs_grid_tf" width="120"/>
                    <a:column name="parent_function_name" editor="functionDs_grid_lov" renderer="render_functionDs_grid" width="120"/>
                    <a:column name="function_type_desc" editor="functionDs_grid_comb" width="80"/>
                    <a:column name="sequence" align="right" editor="functionDs_grid_nf_integer" width="50"/>
                    <a:column name="service_name" editor="functionDs_grid_lov" width="400"/>
                    <a:column name="icon" editor="functionDs_grid_tf" width="100"/>
                    <a:column name="assign_page" align="center" prompt="SYS8010.LINK.ASSIGN_PAGE" renderer="render_functionDs_grid" width="80"/>
                    <a:column name="assign_bm" align="center" prompt="SYS8010.LINK.ASSIGN_BM" renderer="render_functionDs_grid" width="80"/>
                    <a:column name="download" align="center" prompt="HAP_DOWNLOAD" renderer="render_functionDs_grid" width="60"/>
                </a:columns>
                <a:editors>
                    <a:textField id="functionDs_grid_tf_upper" typeCase="upper"/>
                    <a:textField id="functionDs_grid_tf" typeCase="upper"/>
                    <a:numberField id="functionDs_grid_nf_integer" allowdecimals="false"/>
                    <a:comboBox id="functionDs_grid_comb"/>
                    <a:lov id="functionDs_grid_lov"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>