﻿
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML Strict//EN">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<html>
<head>
    <style>
        body, input, select, textarea, table.ms-crm-Loading, div.ms-crm-Grid-Title
        {
            font-family: Segoe UI,Tahoma,Arial;
            font-size: 11px;
        }

        button
        {
            font-size: 11px;
        }

        .ms-crm-RefreshDialog-Button, .ms-crm-RefreshDialog-Header-Desc, .ms-crm-RefreshDialog-Main, .ms-crm-RefreshDialog-Main-HeaderLess
        {
            font-size: 12px;
        }

        html, body
        {
            height: 100%;
        }

        body
        {
            margin-top: 0px;
            margin-right: 0px;
            margin-bottom: 0px;
            margin-left: 0px;
            border-top-color: currentColor;
            border-right-color: currentColor;
            border-bottom-color: currentColor;
            border-left-color: currentColor;
            border-top-width: 0px;
            border-right-width: 0px;
            border-bottom-width: 0px;
            border-left-width: 0px;
            border-top-style: none;
            border-right-style: none;
            border-bottom-style: none;
            border-left-style: none;
            cursor: default;
            direction: ltr;
        }

        button
        {
            width: 84px;
            height: 20px;
            text-align: center;
            line-height: 16px;
            padding-right: 5px;
            padding-left: 5px;
            border-top-width: 1px;
            border-right-width: 1px;
            border-bottom-width: 1px;
            border-left-width: 1px;
            border-top-style: solid;
            border-right-style: solid;
            border-bottom-style: solid;
            border-left-style: solid;
            cursor: pointer;
            background-repeat: repeat-x;
        }

        body.ms-crm-Setting-Context-top, body
        {
            scrollbar-base-color: #cdcdcd;
            scrollbar-face-color: #cdcdcd;
            scrollbar-3dlight-color: #f0f0f0;
            scrollbar-shadow-color: #cdcdcd;
            scrollbar-highlight-color: #cdcdcd;
            scrollbar-darkshadow-color: #f0f0f0;
            scrollbar-arrow-color: #1e395b;
            scrollbar-track-color: #f0f0f0;
            background-color: transparent;
        }

        button
        {
            border-top-color: #666666;
            border-right-color: #666666;
            border-bottom-color: #666666;
            border-left-color: #666666;
            background-image: url("/_imgs/theme/Outlook15White/ButtonNormalGradient.png?ver=-152044938");
        }

        .ms-crm-RefreshDialog-Button
        {
            color: #444444;
            background-color: rgb(255, 255, 255);
        }

        body
        {
            left: 0px;
            top: 0px;
            right: 0px;
            bottom: 0px;
            overflow: hidden;
            position: absolute;
        }

        .ms-crm-RefreshDialog-Button
        {
            width: auto;
            height: 24px;
            font-family: Segoe UI,Tahoma,Arial;
            border-top-color: #c6c6c6;
            border-right-color: #c6c6c6;
            border-bottom-color: #c6c6c6;
            border-left-color: #c6c6c6;
            border-top-width: 1px;
            border-right-width: 1px;
            border-bottom-width: 1px;
            border-left-width: 1px;
            border-top-style: solid;
            border-right-style: solid;
            border-bottom-style: solid;
            border-left-style: solid;
            white-space: nowrap;
            min-width: 80px;
            background-image: none;
        }

        :enabled.ms-crm-RefreshDialog-Button:hover
        {
            background-color: rgb(177, 214, 240);
        }
    </style>
    <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>
    <script type="text/javascript" src="iotap_scripts/iotap_utility.js"></script>
    <script type="text/javascript" src="iotap_scripts/iotap_jQuery.js"></script>
    <script type="text/javascript" src="iotap_scripts/iotap_ReportDownloader.js"></script>
    <script type="text/javascript" src="iotap_XrmSvcToolkit.js"></script>

    <script type="text/javascript">

        function btnDynamicButton_onClick()
        {
            var _actionId = getDataParam(1).replace(/ /g, ""); Log("_actionId: " + _actionId);
            var _downloaderConfiguration = ExecuteOdata(_getUrl(parent.Xrm.Page.context), Constant.OrgService, ConfigEntity.LogicalName + "Set?$filter=iotap_actionid eq '" + _actionId + "'");
            if (_downloaderConfiguration == null)
            {
                var features = "location=no,menubar=no,status=no,toolbar=no,width=400,height=500,top=200,left=500";
                window.open(_getUrl(parent.Xrm.Page.context) +
                        "/webresources/iotap_DownloadOptions.htm?Data=" +
                        encodeURIComponent(parent.Xrm.Page.data.entity.getEntityName()) + "|" +
                        encodeURIComponent(parent.Xrm.Page.data.entity.getId()), "_blank", features, false);
                //var customParameters = encodeURIComponent(parent.Xrm.Page.data.entity.getEntityName() + "|" + parent.Xrm.Page.data.entity.getId())
                //parent.Xrm.Utility.openWebResource(Constant.WebRes.DownloadOption, customParameters);
            }
            else
            {
                ReportDownloader.ReportId = _downloaderConfiguration[0].iotap_report;
                ReportDownloader.Action = _downloaderConfiguration[0].iotap_action.Value.toString(); //false = SAVE & true = open
                ReportDownloader.Fileformat = _downloaderConfiguration[0].iotap_fileformat.Value;
                ReportDownloader.FileName = _downloaderConfiguration[0].iotap_filename;
                DownloadReport();
            }
        }

        document.onreadystatechange = function ()
        {
            if (document.readyState == "complete")
            {
                if (!IsRequiredPluginPresent()) { alert(Constant.TrialFailError); return; }
                AppendSilverlightObject(_getUrl(parent.Xrm.Page.context));
                document.getElementById("btnDynamicButton").innerHTML = getDataParam(0);
            }
        }
    </script>

</head>
<body>
    <div style="width: 100%; height: 100%; overflow: auto; text-align: right;">
        <button class="ms-crm-RefreshDialog-Button" id="btnDynamicButton" onclick="btnDynamicButton_onClick();" type="button"></button>
    </div>
    <div id="trEditFilter">
        <table id="tblReport" style="width: 100%;" cellpading="3" cellspacing="0">
            <tbody>
                <tr>
                    <td>
                        <div id="silverlightControlHost" style="position: absolute;">
                            <!--<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="0%" height="0%">
                                <param name="source" value="https://qwe123.crm5.dynamics.com/WebResources/iotap_Base64Convertor.xap">
                                <param name="onError" value="onSilverlightError">
                                <param name="background" value="white">
                                <param name="minRuntimeVersion" value="5.0.61118.0">
                                <param name="autoUpgrade" value="true">
                                <param name="onLoad" value="pluginLoaded" />
                                <a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=5.0.61118.0" style="text-decoration: none">
                                    <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style: none">
                                </a>
                            </object>
                            <iframe id="_sl_historyFrame" style="visibility: hidden; height: 0px; width: 0px; border: 0px"></iframe>-->
                        </div>
                        <div id="divLoadingPanel" style="display: none; background-color: #898AA0; border-color: black; width: 200px; height: 50px; position: absolute; left: 48%; top: 48%px; z-index: 1; text-align: center; vertical-align: middle; font-size: large;">Please wait.....</div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
</html>