﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="../Styles/Crmstyle.css" />
    <script type="text/javascript" src="../Scripts/jquery1.9.1.js"></script>
    <script type="text/javascript" src="../Scripts/json.js"></script>
    <script src="../../../ClientGlobalContext.js.aspx"></script>
    <script type="text/javascript">

        var webApiUrl = window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.0/";

        function RetrieveEmailTemplatesCaseReopen() {

            var filterQuery = "templates?$select=title,templatetypecode&$filter=templatetypecode eq 'incident'";
            var httpReq = new XMLHttpRequest();
            httpReq.open( "GET", webApiUrl + filterQuery, false );
            httpReq.setRequestHeader( "Accept", "application/json" );
            httpReq.setRequestHeader( "Content-Type", "application/json; charset=utf-8" );
            httpReq.setRequestHeader( "OData-MaxVersion", "4.0" );
            httpReq.setRequestHeader( "OData-Version", "4.0" );
            httpReq.send( null );

            if ( httpReq.status === 200 ) {
                var templateColl = JSON.parse( httpReq.responseText ).value;

                for ( var i = 0; i < templateColl.length; i++ ) {
                    $( '#SelectAutoResponseExternalCaseReopen' ).append( '<option value="' + templateColl[i].templateid + '">' + templateColl[i].title + '</option>' )
                    $( '#SelectAutoResponseInternalCaseReopen' ).append( '<option value="' + templateColl[i].templateid + '">' + templateColl[i].title + '</option>' )
                }
            }            

            if (window.parent.Xrm.Page.getAttribute('iotap_casereopenexternaltemplate').getValue() != null) {
                $('#SelectAutoResponseExternalCaseReopen').val(window.parent.Xrm.Page.getAttribute('iotap_casereopenexternaltemplate').getValue().toLowerCase());
            }

            if (window.parent.Xrm.Page.getAttribute('iotap_casereopeninternaltemplate').getValue() != null) {
                $('#SelectAutoResponseInternalCaseReopen').val(window.parent.Xrm.Page.getAttribute('iotap_casereopeninternaltemplate').getValue().toLowerCase());
            }

        }
            

        function UpdateAttributeCaseReopen() {
            var selectedAckTemplateExt = SelectAutoResponseExternalCaseReopen.value;
            var selectedAckTemplateInt = SelectAutoResponseInternalCaseReopen.value;
            
            var ackTemplateIdExt = "iotap_casereopenexternaltemplate";
            var ackTemplateIdInt = "iotap_casereopeninternaltemplate";

            window.parent.Xrm.Page.getAttribute(ackTemplateIdExt).setValue(selectedAckTemplateExt);
            window.parent.Xrm.Page.getAttribute(ackTemplateIdInt).setValue(selectedAckTemplateInt);
            
        }

    </script>
    <style type="text/css">
        .label
        {
            font-family: Segoe UI, Tahoma, Arial;
            font-size: 11px;
            font-weight: normal;
        }
        .label1
        {
            font-family: Segoe UI, Tahoma, Arial;
            font-size: 11px;
            font-weight: normal;
            color: Red;
        }
        .body
        {
            margin-left: 0px;
            margin-top: 0px;
            margin-right: 0px;
            margin-bottom: 0px;
            background-color: White;
            padding: 0px;
        }
        .style6
        {
            height: 26px;
        }
        .style7
        {
            width: 8%;
        }
        #SelectAutoResponseExternalCaseReopen
        {
            margin-left: 0px;
        }
    </style>
</head>
<body onload="RetrieveEmailTemplatesCaseReopen()" style="width: 100%; margin: 0 0 0 0; padding: 0 0 0 0;height:auto">
    <table style="width: 100%; border-style: none; table-layout: fixed;" cellpadding="0"
        cellspacing="0">
        <colgroup>
            <col width="108">
            <col>
            <col width="123" style="padding-left:10px">
            <col>
            <tbody>
                <tr>
                    <td class="ms-crm-Text" align="left" colspan="4">
                        Case Reopen
                    </td>
                </tr>
                <tr>
                    <td align="left" style="width: 92px">
                        <label class="label">
                            External Email Template</label>&nbsp;
                    </td>
                    <td align="right" width="42%">
                        <select id="SelectAutoResponseExternalCaseReopen" class="ms-crm-SelectBox" name="D1" onchange="UpdateAttributeCaseReopen()">
                            <option></option>
                        </select>
                    </td>
                    <td align="left" style="padding-left: 10px; width: 92px;">
                        <label class="label">
                            Internal Email Template</label>&nbsp;
                    </td>
                    <td align="right" width="42%">
                        <select id="SelectAutoResponseInternalCaseReopen" class="ms-crm-SelectBox" name="D2" onchange="UpdateAttributeCaseReopen()">
                            <option></option>
                        </select>
                    </td>
                </tr>
            </tbody>
    </table>
</body>
</html>
