Редактировал(а) Alexey Semenihin 27.05.2025 06:26

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