﻿<!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() {

            Xrm.WebApi.online.retrieveMultipleRecords("template", "?$select=templateid,templatetypecode,title&$filter=templatetypecode eq 'incident'").then(
                function success(results) {
                    return results;
                },
                function (error) {
                    Xrm.Utility.alertDialog(error.message);
                }
            ).then(function (results) {
                if (results.entities.length >= 1) {
                    for (var i = 0; i < results.entities.length; i++) {
                        var templateid = results.entities[i]["templateid"];
                        var templatetypecode = results.entities[i]["templatetypecode"];
                        var title = results.entities[i]["title"];

                        $('#SelectAutoResponseExternalCaseReopen').append('<option value="' + templateid + '">' + title + '</option>')
                        $('#SelectAutoResponseInternalCaseReopen').append('<option value="' + templateid + '">' + 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>
