DESKTOP-0K9VGFE\hp
2022-03-11 6d766b0c8e9b31e7e03ffd344a94c2851aa9beb9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<apex:page Controller="ContentPreviewController" sidebar="false" action="{!init}" id="Page">
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
<apex:includeScript value="{!URLFOR($Resource.CommonUtilJs)}"/>
<apex:includeScript value="{!URLFOR($Resource.downloadJs)}"/>
<apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
<apex:includeScript value="{!URLFOR($Resource.apex20)}"/>
<script type="text/javascript" src="{!URLFOR($Resource.pdfjs113, 'build/pdf.js')}"></script>
<script type="text/javascript" src="{!URLFOR($Resource.pdfjs113, 'build/pdf.worker.js')}"></script>
<apex:form id="Form">
<apex:outputPanel id="message"><apex:pageMessages /></apex:outputPanel>
<apex:outputPanel layout="none" rendered="{!isError}">
{!msg}
</apex:outputPanel>
<apex:outputPanel layout="none" rendered="{!noDoc}">
{!msg}
<br/>
<input class="btn" style="width:120px;" type="button" value="现状分析文档更新" onclick="sendRefRequest();" />
</apex:outputPanel>
<apex:outputPanel layout="none" rendered="{!NOT(isError || noDoc)}">
<script type="text/javascript">
// pdf.worker.js へのパスを指定する 
PDFJS.workerSrc = "{!URLFOR($Resource.pdfjs113, 'build/pdf.worker.js')}";
 
sforce.connection.sessionId = '{!$Api.Session_ID}';
 
var idx = 1;
var base64pdfData;
var pdfData;
var docid;
var docInfoMap;
 
// PDFとPPTファイルのマッピング
var pdfpptObj = new Object();
<apex:repeat value="{!pdfpptList}" var="pp">
var tmpid = '{!pp}';
pdfpptObj[tmpid.split('_')[0]] = tmpid.split('_')[1];
</apex:repeat>
 
function drawPdfCanvas(cnt) {
    PDFJS.getDocument(pdfData).then(function (pdf) {
        // nページ目を取得する
        return pdf.getPage(cnt);
    }).then(function (page) {
        // Canvas にnページ目の内容を描画
        var scale = 1;
        var viewport = page.getViewport(scale);
        var canvas = jQuery(escapeVfId('myCanvas'))[0];
        var context = canvas.getContext('2d');
        canvas.height = viewport.height;
        canvas.width = viewport.width;
        var renderContext = {
            canvasContext: context,
            viewport: viewport
        };
        page.render(renderContext);
    }, function(reason){
        if (idx > 1) {
            alert("已到最后一页");
            idx = idx - 1;
        }
    });
}
 
function showPage(id) {
    docid = id;
    docInfoMap = null;
    ContentPreviewController.getDocumentBody(docid, function(res, event) {
    if(event.status) {
        docInfoMap = res;
        base64pdfData = docInfoMap['body'];
        pdfData = loadPDFData();
        
        // title描画
        jQuery("#pdfTitle").html('<font size="4"><b>'
                            + docInfoMap['name'] + '(作成日期:' + docInfoMap['time'] + ')'
                            + '</b></font>');
        jQuery(escapeVfId('previewPDF')).val("");
        jQuery(escapeVfId('downloadPPT')).val("");
        idx = 1;
        drawPdfCanvas(idx);
    } else {
        alert(event.message);
    }}, {buffer: false, escape: true, timeout: 120000});
}
 
function loadPDFData() {
    function base64ToUint8Array(base64) {
        var raw = atob(base64);
        var uint8Array = new Uint8Array(new ArrayBuffer(raw.length));
        for (var i = 0, len = raw.length; i < len; ++i) {
            uint8Array[i] = raw.charCodeAt(i);
        }
        return uint8Array;
    }
    return base64ToUint8Array(base64pdfData);
}
 
function nextPage() {
    idx = idx + 1;
    drawPdfCanvas(idx);
    // プレビューカウント
    var previewPDF = jQuery(escapeVfId('previewPDF')).value();
    if (previewPDF == "") {
       sforce.apex.execute("ControllerUtil", "addBatchIfLogForCnt", {typeStr:"现状分析阅览统计", operationType:"阅览PDF", fileType:docInfoMap['type'], hpId:'{!hpId}'});
       jQuery(escapeVfId('previewPDF')).val(docid);
    }
}
 
function prevPage() {
    if (idx == 1) {
        alert("已到第一页");
    } else {
        idx = idx - 1;
        drawPdfCanvas(idx);
    }
}
 
function downloadppt() {
    var pptid = pdfpptObj[docid];
    docInfoMap = null;
    ContentPreviewController.getDocumentBody(pptid, function(res, event) {
    if(event.status) {
        docInfoMap = res;
        base64pdfData = docInfoMap['body'];
        download("data:text/plain;base64," + base64pdfData, docInfoMap['name'] + ".ppt", "text/plain");
        // ダウンロードカウント
        var downloadPPT = jQuery(escapeVfId('downloadPPT')).value();
        if (downloadPPT == "") {
           sforce.apex.execute("ControllerUtil", "addBatchIfLogForCnt", {typeStr:"现状分析阅览统计", operationType:"下载PPT", fileType:docInfoMap['type'], hpId:'{!hpId}'});
           jQuery(escapeVfId('downloadPPT')).val(pptid);
        }
    } else {
        alert(event.message);
    }}, {buffer: false, escape: true, timeout: 120000});
}
 
function downloadexcel() {
    docInfoMap = null;
    ContentPreviewController.getDocumentBody('{!xlsId}', function(res, event) {
    if(event.status) {
        docInfoMap = res;
        base64pdfData = docInfoMap['body'];
        download("data:text/plain;base64," + base64pdfData, docInfoMap['name'] + ".xlsx", "text/plain");
        // ダウンロードカウント
        var downloadExcel = jQuery(escapeVfId('downloadExcel')).value();
        if (downloadExcel == "") {
           sforce.apex.execute("ControllerUtil", "addBatchIfLogForCnt", {typeStr:"现状分析阅览统计", operationType:"下载Excel", fileType:docInfoMap['type'], hpId:'{!hpId}'});
           jQuery(escapeVfId('downloadExcel')).val('{!xlsId}');
        }
    } else {
        alert(event.message);
    }}, {buffer: false, escape: true, timeout: 120000});
}
 
function downloadRequest() {
    if (jQuery(escapeVfId("Page:Form:targetUser_lkid")).val() == '000000000000000') {
        alert("请先选择请求对象");
        return;
    }
    sendDlRequest(docid, jQuery(escapeVfId("Page:Form:targetUser_lkid")).val());
}
 
function sendComment() {
    var subject = '{!hpName}的提案书有问题';
    var comment = jQuery(escapeVfId("Page:Form:comment")).val();
    if (comment != "") {
        ContentPreviewController.saveComment(subject, comment, docid, '{!hpId}', function(res, event) {
        if(event.status) {
            alert("留言完毕");
        } else {
            alert(event.message);
        }}, {buffer: false, escape: true, timeout: 120000});
    }
}
 
</script>
    <input type="hidden" value="" id="previewPDF" />
    <input type="hidden" value="" id="downloadPPT" />
    <input type="hidden" value="" id="downloadExcel" />
    <div>
        <table>
            <tr height="50px">
                <td width="720px"><div id="pdfTitle" style="width:720px; height:50px; text-align: center;"></div></td>
                <td width="200px" style="padding-left: 10px;"><input id="refBtn" class="btn" type="button" value="文档更新" onclick="document.getElementById('requestBtn').style.top = '180px';sendRefRequest();"/></td>
            </tr>
            <tr>
                <td>
                    <table width="100%">
                        <tr>
                            <td style="width:50%; text-align: left;"><input class="btn" style="width:100px" type="button" value="←" onclick="prevPage();"/></td>
                            <td style="text-align: right;"><input class="btn" style="width:100px" type="button" value="→" onclick="nextPage();"/></td>
                        </tr>
                    </table>
                </td>
                <td style="padding-left: 10px;">切换提案书:<apex:selectList id="pdfType" value="{!docId}" size="1" style="width:120px;" onchange="showPage(this.value);return false;"><apex:selectOptions value="{!pdfTypeOpts}"/></apex:selectList></td>
            </tr>
            <tr>
                <td><canvas id="myCanvas" width="720px" height="540px"></canvas></td>
                <td style="vertical-align: top;padding-left: 10px;">
                    <apex:outputPanel layout="none" rendered="{!NOT(disableDL)}">
                        <input class="btn" type="button" value="下载PPT" onclick="downloadppt();"/>&nbsp;
                        <input class="btn" type="button" value="下载Excel" onclick="downloadexcel();"/>
                    </apex:outputPanel>
                    <apex:outputPanel layout="none" rendered="{!disableDL}">
                        您没有下载提案书的权限,<br/>请选择别的用户发送下载请求<br/><br/>
                        <apex:inputField id="targetUser" value="{!dummyReport.OwnerId}" style="width:90px;"/>
                        <input id="requestBtn" class="btn" style="width:90px; position: absolute; left: 870px; top: 135px;" type="button" value="下载请求" onclick="downloadRequest();" />
                    </apex:outputPanel>
                </td>
            </tr>
        </table>
    </div>
    <b>对te2am的反馈意见:</b><br/>
    <apex:inputTextarea id="comment" value="{!comment}" cols="90" rows="10" style="resize: none;"/>
    <input class="btn" style="width:90px; position: absolute; left: 600px; bottom: 20px;" type="button" value="留言" onclick="sendComment();" />
</apex:outputPanel>
<script type="text/javascript">
setFocusOnLoad();
showPage('{!docId}');
if ('{!refBtnNG}' == "true") {
    //jQuery(escapeVfId('refBtn')).prop("disabled", true);
    jQuery(escapeVfId('refBtn')).css("display", "none");
}
</script>
</apex:form>
<!-- TODO なぜプルダウンのValidationエラーが発生しますか?一旦別フォームにする -->
<apex:form id="Form2">
    <apex:actionFunction name="sendDlRequest" action="{!sendDlRequest}" rerender="dummy" oncomplete="alert('您的下载请求已发送');">
        <apex:param name="p1" value="" assignTo="{!docId}" />
        <apex:param name="p2" value="" assignTo="{!dummyReport.OwnerId}" />
    </apex:actionFunction>
    <apex:actionFunction name="sendRefRequest" action="{!sendRefRequest}" rerender="message" />
</apex:form>
</apex:page>