<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangyi2652 $
    $Date: 2010/11/26 07:25:06 $
    $Revision: 1.2 $
    $Purpose: “事件消息模板维护” 新增界面
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:p="uncertain.proc" trace="true">
    <a:init-procedure>
        <p:echo/>
        <a:model-query defaultWhereClause=" cs.code = &apos;SYS_NOTIFY_SEND_METHOD&apos;" fetchAll="true" model="sys.SYS2020.sys_notify_code_codevalue" rootPath="send_method"/>
        <a:model-query defaultWhereClause=" cs.code = &apos;SYS_NOTIFY_SEND_METHOD&apos;" fetchAll="true" model="sys.SYS2020.sys_notify_code_codevalue" rootPath="send_method"/>
        <a:model-query defaultWhereClause=" cs.code = &apos;SYS_NOTIFY_SEND_MODE&apos;" fetchAll="true" model="sys.SYS2020.sys_notify_code_codevalue" rootPath="send_mode"/>
        <a:model-query defaultWhereClause=" cs.code = &apos;SYS_NOTIFY_DELAY_TIME_UNIT&apos;" fetchAll="true" model="sys.SYS2020.sys_notify_code_codevalue" rootPath="delay_time_unit"/>
        <a:model-query defaultWhereClause=" snrt.enabled_flag = &apos;Y&apos; " fetchAll="true" model="sys.SYS2020.sys_notify_recipient_type" rootPath="recipientType"/>
    </a:init-procedure>
    <a:view>
        <script type="text/javascript"><![CDATA[
        
            function onNotifyRecipientUpdate(ds,record,name,value){
                if (name=='recipient_type_id'){
                    record.set('recipient_name', '');
                    record.set('recipient_user_id', '');
                }
            }

            function onFieldSetUpdate(ds,record,name,value){
                if(name=='send_mode'){
                    var send_mode=record.get('send_mode');

                    var delay_time_unit_display=record.getMeta().getField('delay_time_unit_display');
                    var delay_time=record.getMeta().getField('delay_time');
                    if (send_mode=='02'){
                        delay_time_unit_display.setReadOnly(false);
                        delay_time.setReadOnly(false);
                    }else{
                        delay_time_unit_display.setReadOnly(true);
                        delay_time.setReadOnly(true);

                        record.set('delay_time_unit_display',null);
                        record.set('delay_time',null);
                        record.set('delay_time_unit',null);
                    }
                }
            }

            function onFieldSetInit(){
                var record = $('sys_notify_edit_ds').getCurrentRecord();
                var send_mode=record.get('send_mode');
                var delay_time_unit_display=record.getMeta().getField('delay_time_unit_display');
                var delay_time=record.getMeta().getField('delay_time');
                if (send_mode=='02'){
                    delay_time_unit_display.setReadOnly(false);
                    delay_time.setReadOnly(false);
                }else{
                    delay_time_unit_display.setReadOnly(true);
                    delay_time.setReadOnly(true);
                    record.set('delay_time_unit_display',null);
                    record.set('delay_time',null);
                    record.set('delay_time_unit',null);
                }
            }

            function onCellClick(grid, row, name, record){
                if(name =='recipient_name_display'){
                    var recipient_type_id = record.get('recipient_type_id');
                    var url=null;

                    if (recipient_type_id==null||recipient_type_id==''){
                        return;
                    }

                    var allRecords=$('sys_recipient_type_ds').getAll();
                    if (allRecords==null||allRecords==''||allRecords==undefined){
                        return;
                    }
                    for(var k = 0,l=allRecords.length;k<l;k++){
                        var rcd = allRecords[k];
                        if (rcd.get('recipient_type_id')==recipient_type_id){
                            url=rcd.get('lov_url');
                            break;
                        }
                    }

                    var recipient_name_display=record.getMeta().getField('recipient_name_display');
                    recipient_name_display.setLovService(url);
                }
            }

            function saveFunction(){
                var ds=$('sys_notify_edit_ds');
                var gridDs=$('sys_notify_recipient_ds');
                if (ds.validate()&&gridDs.validate()){
                    ds.submit();
                }
            }

            function onSuccess(dataSet, datas, res){
                Leaf.showMessage('${l:PROMPT_MESSAGE}','${l:HLS.SUBMIT_SUCCESS}',function(cmp){closeWindow();cmp.close();});
                queryRecipientType();
            }

            function closeWindow(){
                $('newNotify').close();
            }


        
        ]]></script>
        <a:dataSets>
            <a:dataSet id="sys_notify_sendMethod_ds">
                <a:datas dataSource="/model/send_method"/>
            </a:dataSet>
            <a:dataSet id="sys_notify_sendMode_ds">
                <a:datas dataSource="/model/send_mode"/>
            </a:dataSet>
            <a:dataSet id="sys_notify_delayTimeUnit_ds">
                <a:datas dataSource="/model/delay_time_unit"/>
            </a:dataSet>
            <a:dataSet id="sys_recipient_type_ds">
                <a:datas dataSource="/model/recipientType"/>
            </a:dataSet>
            <a:dataSet id="sys_notify_edit_ds" autoCreate="true" submitUrl="${/request/@context_path}/modules/sys/SYS2020/sys_notify_insert.lsc">
                <a:fields>
                    <a:field name="notify_code" required="true"/>
                    <a:field name="description" required="true"/>
                    <a:field name="send_method_display" displayField="code_value_name" options="sys_notify_sendMethod_ds" returnField="send_method" valueField="code_value"/>
                    <a:field name="send_mode_display" displayField="code_value_name" options="sys_notify_sendMode_ds" returnField="send_mode" valueField="code_value"/>
                    <a:field name="delay_time_unit_display" displayField="code_value_name" options="sys_notify_delayTimeUnit_ds" returnField="delay_time_unit" valueField="code_value"/>
                    <a:field name="enabled_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="onFieldSetUpdate"/>
                    <a:event name="submitsuccess" handler="onSuccess"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="sys_notify_recipient_ds" bindName="recipients" bindTarget="sys_notify_edit_ds" selectable="true">
                <a:fields>
                    <a:field name="recipient_type_display" displayField="description" options="sys_recipient_type_ds" required="true" returnField="recipient_type_id" valueField="recipient_type_id"/>
                    <a:field name="recipient_name_display" fetchRemote="false" lovGridHeight="320" lovHeight="440" lovWidth="500" title="RECIEVER_SELECT">
                        <a:mapping>
                            <a:map from="description" to="recipient_name_display"/>
                            <a:map from="notify_code" to="notify_code"/>
                            <a:map from="notify_id" to="recipient_name"/>
                            <a:map from="recipient_user_id" to="recipient_user_id"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="enabled_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                    <a:field name="notify_id" defaultValue="${/parameter/@notify_id}"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="onNotifyRecipientUpdate"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:tabPanel height="400" width="550">
                <a:tabs>
                    <a:tab prompt="SYS_NOTIFY_EDIT.TAB_TITLE1" width="110">
                        <a:fieldSet column="1" labelWidth="95" title="SYS_NOTIFY_EDIT.NEW_NOTIFY" width="525">
                            <a:hBox prompt="SYS_MESSAGES.MESSAGE_CODE">
                                <a:textField name="notify_code" bindTarget="sys_notify_edit_ds" typeCase="upper"/>
                                <a:textField name="description" bindTarget="sys_notify_edit_ds" prompt="SYS_MESSAGES.MESSAGE_NAME"/>
                            </a:hBox>
                            <a:hBox prompt="SYS_NOTIFY.MESSAGE_TITLE">
                                <a:textField name="message_title" bindTarget="sys_notify_edit_ds" width="380"/>
                            </a:hBox>
                            <a:hBox prompt="SYS_NOTIFY.MESSAGE_CONTENT">
                                <a:textArea name="message_content" bindTarget="sys_notify_edit_ds" width="380"/>
                            </a:hBox>
                            <a:hBox prompt="SYS_NOTIFY.SEND_METHOD">
                                <a:comboBox name="send_method_display" bindTarget="sys_notify_edit_ds"/>
                                <a:comboBox name="send_mode_display" bindTarget="sys_notify_edit_ds" prompt="SYS_NOTIFY.SEND_MODE"/>
                            </a:hBox>
                            <a:hBox prompt="SYS_NOTIFY.DELAY_TIME">
                                <a:numberField name="delay_time" bindTarget="sys_notify_edit_ds"/>
                                <a:comboBox name="delay_time_unit_display" bindTarget="sys_notify_edit_ds" prompt="SYS_NOTIFY_RECIPIENT.DELAY_TIME_UNIT"/>
                            </a:hBox>
                            <a:hBox prompt="SYS_NOTIFY.CONTENT_SQL">
                                <a:textArea name="content_sql" bindTarget="sys_notify_edit_ds" width="380"/>
                            </a:hBox>
                            <a:hBox prompt="SYS_NOTIFY.MSG_SEND_CHECK_PROC">
                                <a:textField name="msg_send_check_proc" bindTarget="sys_notify_edit_ds" width="380"/>
                            </a:hBox>
                            <a:hBox prompt="SYS_NOTIFY.MSG_CREATE_PROC">
                                <a:textField name="msg_create_proc" bindTarget="sys_notify_edit_ds"/>
                                <a:checkBox name="enabled_flag" bindTarget="sys_notify_edit_ds" prompt="FND_OPERATION_UNITS.ENABLED_FLAG"/>
                            </a:hBox>
                        </a:fieldSet>
                    </a:tab>
                    <a:tab prompt="SYS_NOTIFY_RECIPIENT.RECIPIENT_NAME" width="110">
                        <a:grid id="edit_grid" bindTarget="sys_notify_recipient_ds" height="350" navBar="true" width="525">
                            <a:toolBar>
                                <a:button type="add"/>
                                <a:button type="clear"/>
                            </a:toolBar>
                            <a:columns>
                                <a:column name="recipient_type_display" editor="edit_grid_comboBox" prompt="SYS_NOTIFY_RECIPIENT.RECIPIENT_TYPE" sortable="true"/>
                                <a:column name="recipient_name_display" editor="edit_grid_lov" prompt="SYS_NOTIFY_RECIPIENT.RECIPIENT_NAME" sortable="true"/>
                                <a:column name="recipient_mobile" editor="edit_grid_tf" prompt="SYS_NOTIFY_RECIPIENT.RECIPIENT_MOBILE" sortable="true"/>
                                <a:column name="recipient_mail" editor="edit_grid_tf" prompt="SYS_NOTIFY_RECIPIENT.EMAIL" sortable="true"/>
                                <a:column name="param1" editor="edit_grid_tf" prompt="SYS_NOTIFY_RECIPIENT.PARAM1" sortable="true"/>
                                <a:column name="param2" editor="edit_grid_tf" prompt="SYS_NOTIFY_RECIPIENT.PARAM2" sortable="true"/>
                                <a:column name="param3" editor="edit_grid_tf" prompt="SYS_NOTIFY_RECIPIENT.PARAM3" sortable="true"/>
                                <a:column name="param4" editor="edit_grid_tf" prompt="SYS_NOTIFY_RECIPIENT.PARAM4" sortable="true"/>
                                <a:column name="recipient_desc" editor="edit_grid_tf" prompt="WFL_WORKFLOW_PARAM_VALUE.VALUE_DESC" sortable="true"/>
                                <a:column name="enabled_flag" editor="edit_grid_checkBox" prompt="FND_OPERATION_UNITS.ENABLED_FLAG" sortable="true"/>
                            </a:columns>
                            <a:editors>
                                <a:textField id="edit_grid_tf"/>
                                <a:checkBox id="edit_grid_checkBox"/>
                                <a:comboBox id="edit_grid_comboBox"/>
                                <a:lov id="edit_grid_lov"/>
                            </a:editors>
                            <a:events>
                                <a:event name="cellClick" handler="onCellClick"/>
                            </a:events>
                        </a:grid>
                    </a:tab>
                </a:tabs>
            </a:tabPanel>
            <script type="text/javascript"><![CDATA[
                onFieldSetInit(); 
            ]]></script>
        </a:screenBody>
        <div class="win-toolbar" style="width:520px;height:40px;">
            <a:hBox style="float:right;margin-right:10px;margin-top:5px;">
                <a:button click="saveFunction" text="HAP_SAVE"/>
                <a:button click="closeWindow" text="HAP_CLOSE"/>
            </a:hBox>
        </div>
    </a:view>
</a:screen>