Изменения документа Создание разделов по шаблону

Редактировал(а) Alexey Semenihin 24.06.2025

От версии 2.1
отредактировано Alexey Semenihin
на 23.04.2025
Изменить комментарий: Загрузить новое вложение Инструкция пользователя Xwiki.docx
К версии 5.1
отредактировано Alexey Semenihin
на 23.04.2025
Изменить комментарий: К данной версии нет комментариев

Сводка

Подробности

Свойства страницы
Содержимое
... ... @@ -1,0 +1,212 @@
1 +{{velocity}}
2 +=== Прикрепите вложения и используйте кнопки для навигации ===
3 +#set($spaceRef = $doc.documentReference.lastSpaceReference.name)
4 +#set($pageName = $doc.documentReference.name)
5 +#set($docFullName = "${spaceRef}.${pageName}")
6 +#set($attachments = $doc.getAttachmentList())
7 +#set($itemsPerPage = 1)
8 +#set($totalPages = ($attachments.size() + $itemsPerPage - 1) / $itemsPerPage)
9 +#set($currentPage = 1)
10 +#if("$!request.page" != "")
11 + #set($currentPage = $mathtool.toInteger($request.page))
12 +#end
13 +#set($startIndex = ($currentPage - 1) * $itemsPerPage)
14 +#set($endIndex = $startIndex + $itemsPerPage - 1)
15 +#if($endIndex >= $attachments.size())
16 + #set($endIndex = $attachments.size() - 1)
17 +#end
18 +
19 +{{html}}
20 +<div class="navigation-controls">
21 + #if($attachments && !$attachments.isEmpty())
22 + <!-- Выпадающий список для выбора вложения -->
23 + <div class="attachment-selector">
24 + <label for="attachment-select">Выберите вложение:</label>
25 + <select id="attachment-select">
26 + #foreach($attachment in $attachments)
27 + <option value="$attachment.filename" #if($velocityCount == $currentPage)selected#end>
28 + $attachment.filename
29 + </option>
30 + #end
31 + </select>
32 + </div>
33 + <!-- Пагинация -->
34 + <div class="pagination-controls">
35 + #if($currentPage > 1)
36 + #set($prevPage = $currentPage - 1)
37 + <a href="$doc.getURL('view', "page=${prevPage}")" class="btn btn-primary">Назад</a>
38 + #else
39 + <span class="btn btn-disabled">Назад</span>
40 + #end
41 +
42 + <span class="page-info">Страница $currentPage из $totalPages</span>
43 +
44 + #if($currentPage < $totalPages)
45 + #set($nextPage = $currentPage + 1)
46 + <a href="$doc.getURL('view', "page=${nextPage}")" class="btn btn-primary">Далее</a>
47 + #else
48 + <span class="btn btn-disabled">Далее</span>
49 + #end
50 + </div>
51 + #else
52 + <div class="no-attachments-message">
53 + Нет прикрепленных вложений. Пожалуйста, добавьте файлы для просмотра.
54 + </div>
55 + #end
56 +</div>
57 +{{/html}}
58 +
59 +#if($attachments && !$attachments.isEmpty())
60 + #foreach($i in [$startIndex..$endIndex])
61 + #set($attachment = $attachments.get($i))
62 + #set($filename = $attachment.filename)
63 + #set($fileurl = $doc.getAttachmentURL($filename, "download"))
64 + #set($fileExtension = $filename.substring($filename.lastIndexOf('.') + 1).toLowerCase())
65 +
66 + === Документ: $filename ===
67 +
68 + {{html}}
69 + <div class="document-viewer-container" id="document-viewer">
70 + #if($fileExtension == 'pdf')
71 + <!-- PDF Viewer -->
72 + <iframe
73 + id="document-frame"
74 + src="/resources/pdfjs/web/viewer.html?file=${escapetool.url($fileurl)}"
75 + width="1200px"
76 + height="600px">
77 + </iframe>
78 + #elseif($fileExtension == 'doc' || $fileExtension == 'docx' || $fileExtension == 'ppt' || $fileExtension == 'pptx' || $fileExtension == 'xls' || $fileExtension == 'xlsx')
79 + <!-- Office Viewer -->
80 + #set($officeViewerUrl = "${doc.getURL('view')}?xpage=office&attachment=${escapetool.url($filename)}")
81 + <iframe
82 + id="document-frame"
83 + src="$officeViewerUrl"
84 + width="1200px"
85 + height="600px">
86 + </iframe>
87 + #else
88 + <div class="unsupported-format">
89 + Формат файла (${fileExtension}) не поддерживается для просмотра.
90 + <a href="${fileurl}">Скачать файл</a>
91 + </div>
92 + #end
93 + </div>
94 + {{/html}}
95 + #end
96 +#else
97 +
98 + {{html}}
99 + <div class="no-attachments-message">
100 + Нет доступных вложений для отображения.
101 + </div>
102 + {{/html}}
103 +
104 +#end
105 +
106 +{{html}}
107 +<style>
108 + .navigation-controls {
109 + display: flex;
110 + flex-direction: column;
111 + gap: 15px;
112 + margin-bottom: 20px;
113 + }
114 + .attachment-selector {
115 + display: flex;
116 + align-items: center;
117 + gap: 10px;
118 + }
119 + .attachment-selector select {
120 + padding: 8px;
121 + border-radius: 4px;
122 + min-width: 300px;
123 + }
124 + .document-viewer-container {
125 + margin: 20px 0;
126 + border: 1px solid #eee;
127 + padding: 10px;
128 + background: #f9f9f9;
129 + }
130 + .pagination-controls {
131 + margin: 20px 0;
132 + display: flex;
133 + justify-content: center;
134 + align-items: center;
135 + gap: 20px;
136 + }
137 + .btn {
138 + padding: 8px 16px;
139 + border-radius: 4px;
140 + text-decoration: none;
141 + }
142 + .btn-primary {
143 + background-color: #3366cc;
144 + color: white;
145 + }
146 + .btn-disabled {
147 + background-color: #eee;
148 + color: #999;
149 + cursor: not-allowed;
150 + }
151 + .page-info {
152 + font-weight: bold;
153 + }
154 + .unsupported-format {
155 + padding: 20px;
156 + text-align: center;
157 + color: #666;
158 + }
159 + .no-attachments-message {
160 + padding: 20px;
161 + text-align: center;
162 + color: #666;
163 + font-style: italic;
164 + border: 1px dashed #ccc;
165 + background-color: #f5f5f5;
166 + }
167 +</style>
168 +<script>
169 +//<![CDATA[
170 +document.addEventListener('DOMContentLoaded', function() {
171 + const select = document.getElementById('attachment-select');
172 + const viewerContainer = document.getElementById('document-viewer');
173 +
174 + if (select && viewerContainer) {
175 + select.addEventListener('change', function() {
176 + const filename = this.value;
177 + const fileExtension = filename.split('.').pop().toLowerCase();
178 + const fileurl = "${doc.getURL('download')}" + "/" + encodeURIComponent(filename);
179 + const pdfViewerUrl = "/resources/pdfjs/web/viewer.html?file=" + encodeURIComponent(fileurl);
180 + const baseUrl = "${doc.getURL('view')}";
181 +
182 + let viewerHtml = '';
183 +
184 + if (fileExtension === 'pdf') {
185 + viewerHtml = '<iframe id="document-frame" ' +
186 + 'src="' + pdfViewerUrl + '" ' +
187 + 'width="100%" height="600px"></iframe>';
188 + } else if (['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx'].indexOf(fileExtension) >= 0) {
189 + viewerHtml = '<iframe id="document-frame" ' +
190 + 'src="' + baseUrl + '?xpage=office&attachment=' + encodeURIComponent(filename) + '" ' +
191 + 'width="100%" height="600px"></iframe>';
192 + } else {
193 + viewerHtml = '<div class="unsupported-format">' +
194 + 'Формат файла (' + fileExtension + ') не поддерживается для просмотра. ' +
195 + '<a href="' + fileurl + '">Скачать файл</a></div>';
196 + }
197 +
198 + viewerContainer.innerHTML = viewerHtml;
199 +
200 + // Обновляем заголовок документа
201 + const titleElement = viewerContainer.previousElementSibling;
202 + if (titleElement && titleElement.tagName === 'H3') {
203 + titleElement.textContent = 'Документ: ' + filename;
204 + }
205 + });
206 + }
207 +});
208 +//]]>
209 +</script>
210 +{{/html}}
211 +
212 +{{/velocity}}