<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Hongquan.Dai  代宏全
    $Date: 2018-1-23 下午1:36:54  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="sys_msg_edit_sql_link" url="${/request/@context_path}/modules/sys/SYS400/sys_msg_edit_sql.lview"/>
        <a:link id="insert_sys_sms_list_link_id" model="db.sys_phone_msg_send_pkg.insert_sys_sms_list" modelaction="batch_update"/>
        <script type="text/javascript"><![CDATA[
            function sys_phone_msg_delete() {
                var ds_id = 'sys400_sys_phone_msg_send_ds';
                var records = $(ds_id).getSelected();
                if (records.length < 1) {
                    Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                    return;
                }
                Leaf.showConfirm('提示', '是否确认删除?', function() {
                    for (var i = 0;i < records.length;i++) {
            
                        $(ds_id).remove(records[i]);
            
                    }
                }, null);
                
                                       
            }
            
            function sys_phone_msg_save() {
                $('sys400_sys_phone_msg_send_ds').submit();
            }
            //新增
            
            function sys_phone_msg_add() {
                $('sys400_sys_phone_msg_send_grid').showEditorByRecord($('sys400_sys_phone_msg_send_ds').create());
            }
            
        
         
              //编辑 消息内容(SQL)
            function send_sql(id) {
                if (!Ext.isEmpty(id)) {
                     new Leaf.Window({
                    id: 'phone_msg_edit_window',
                    url: $('sys_msg_edit_sql_link').getUrl() + '?phone_msg_id=' + id,
                    title: '短信内容(SQL)',
                    params: {
                            'winid': 'phone_msg_edit_window'
                        },
                    height: 450,
                    width: 600,
                    fullScreen: false
                });
                    
                }else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
                    return;
                }
               
            }
             //超链接
             function edit_render(value, record, name) {
                return '<a href="javascript:send_sql(' + record.get('phone_msg_id') + ')">${l:PROMPT.EDIT}</a>';
            }
            
            
            //发送
             function sys_phone_msg_send() {
                var records = $('sys400_sys_phone_msg_send_ds').getSelected();
                if (records.length < 1) {
                    Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                    return;
                }
                var param_list = [];
                var param = {};
                for (var i = 0;i < records.length;i++) {
                    if (Ext.isEmpty(records[i].get('phone_msg_id'))) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
                        return;
                    }
                    param = {};
                    param['phone_msg_id'] = records[i].get('phone_msg_id');
                    param['_status'] = 'update';
                    param_list.push(param);
                }
                Leaf.showConfirm('提示', '是否确认发送选中记录?', function() {
                Leaf.request({
                    url: $('insert_sys_sms_list_link_id').getUrl(),
                    para: param_list,
                    success: function(res) {
                        
                         Leaf.SideBar.show({
                            html: '<div style="background-color:#ccfbd5;position:absolute;padding:3px;border:1px solid #009900">' + '发送成功'+ '</div>',
                            duration: 1000
                        });
                        $('sys400_sys_phone_msg_send_ds').query();
                         
                    },
                    error: function() {
                    },
                    failure: function() {
                    },
                    sync: true,
                    scope: this
                });
                    }, null);
            }
          
        ]]></script>
        <a:dataSets>
            <a:dataSet id="phone_msg_type_ds" lookupCode="PHONE_MSG_TYPE"/>
            <a:dataSet id="notice_way_ds" lookupCode="NOTICE_WAY"/>
            <a:dataSet id="sys400_sys_phone_msg_send_ds" autoQuery="true" model="sys.SYS400.sys_phone_msg_send" selectable="true">
                <a:fields>
                    <!--  <a:field name="msg_code_desc" displayField="code_value_name" options="phone_msg_type_ds" returnField="msg_code" valueField="code_value" defaultValue="预警通知" /> -->
                    <a:field name="msg_code" defaultValue="预警通知"/>
                    <a:field name="notice_way_desc" defaultValue="短信" displayField="code_value_name" options="notice_way_ds" readOnly="true" returnField="notice_way" valueField="code_value"/>
                    <a:field name="notice_way" defaultValue="PHONE_MSG"/>
                    <a:field name="status" defaultValue="NO"/>
                    <a:field name="enable_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="sys_phone_msg_add" text="HLS.NEW"/>
                <a:gridButton click="sys_phone_msg_save" text="HLS.SAVE"/>
                <a:gridButton click="sys_phone_msg_delete" text="HLS.DELETE"/>
                <a:gridButton click="sys_phone_msg_send" text="发送"/>
            </a:screenTopToolbar>
            <a:grid id="sys400_sys_phone_msg_send_grid" bindTarget="sys400_sys_phone_msg_send_ds" marginHeight="265" marginWidth="30" rowRenderer="">
                <a:columns>
                    <a:column name="msg_code" align="center" editor="text_edit" prompt="消息模板名称" width="250"/>
                    <a:column name="notice_way_desc" align="center" prompt="通知方式" width="150"/>
                    <a:column name="send_sql" align="center" prompt="短信内容(SQL)" renderer="edit_render" width="250"/>
                    <a:column name="enable_flag" align="center" editor="cbox_edit" prompt="是否启用" width="250"/>
                </a:columns>
                <a:editors>
                    <a:comboBox id="desc_checkbox"/>
                    <a:textField id="text_edit"/>
                    <a:checkBox id="cbox_edit"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>