Изменения документа Загрузить документ

Редактировал(а) HRlink 30.05.2025

От версии 77.1
отредактировано HRlink
на 30.05.2025
Изменить комментарий: К данной версии нет комментариев
К версии 80.1
отредактировано HRlink
на 30.05.2025
Изменить комментарий: К данной версии нет комментариев

Сводка

Подробности

Свойства страницы
Содержимое
... ... @@ -142,41 +142,38 @@
142 142  
143 143  [[Добавьте к документу сотрудников>>https://wiki.myhrlink.ru/bin/view/Main/Кадровик/Документы/Добавить%20в%20документ%20нескольких%20сотрудников%20/]] или отправьте загруженные документы на [[подпись>>https://wiki.myhrlink.ru/bin/view/Main/Кадровик/Документы/Отправить%20документ%20на%20подпись%20/]]
144 144  
145 -----
146 146  
147 147  {{velocity}}
148 -#set($likesKey = $doc.fullName)
149 -#set($likesDoc = $xwiki.getDocument("XWiki.LikesStorage"))
150 -#set($likesObject = $likesDoc.getObject("XWiki.LikesStorageClass", "key", $likesKey))
147 +#set($likesDocName = "XWiki.LikesStorage." + $doc.fullName.replaceAll("[^a-zA-Z0-9]", "_"))
148 +#set($likesDoc = $xwiki.getDocument($likesDocName))
149 +#set($likesObject = $likesDoc.getObject("XWiki.LikesStorageClass"))
151 151  
152 152  #if(!$likesObject)
153 - #set($likesObject = $likesDoc.newObject("XWiki.LikesStorageClass"))
154 - $likesObject.set("key", $likesKey)
155 - $likesObject.set("value", 0)
156 - $xwiki.saveDocument($likesDoc)
152 + #set($discard = $likesDoc.newObject("XWiki.LikesStorageClass"))
153 + $likesDoc.set("key", $doc.fullName)
154 + $likesDoc.set("value", 0)
155 + #set($discard = $xwiki.saveDocument($likesDoc))
157 157  #end
158 158  
159 -#set($likes = $likesObject.get("value"))
160 -#set($liked = $request.getCookie("liked-$likesKey"))
161 -#set($userLiked = false)
162 -#if("$!liked" == "true")
163 - #set($userLiked = true)
158 +#if($request.getParameter("like") == "1" && $xcontext.action != "save")
159 + #set($likes = $likesDoc.get("value"))
160 + $likesDoc.set("value", $math.add($likes, 1))
161 + #set($discard = $xwiki.saveDocument($likesDoc))
164 164  #end
165 165  
164 +#set($likes = $likesDoc.get("value"))
166 166  {{html clean="false"}}
167 167  <div id="like-container" style="margin-top:20px; display:flex; align-items:center; gap:10px;">
168 - <button id="like-button" style="cursor:pointer; font-size: 20px; background: none; border: none;" title="Нравится" aria-label="Лайк">
169 - <span id="heart" style="color:#e74c3c;">❤️</span>
167 + <button id="like-button" style="cursor:pointer; font-size: 22px; background: none; border: none;" title="Лайк">
168 + 👍
170 170   </button>
171 171   <span id="like-count" style="font-size:18px;">$likes</span>
172 - <span style="font-size:14px; color: #555;">Нравится статья?</span>
171 + <span style="font-size:14px; color:#555;">Нравится статья?</span>
173 173  </div>
174 -
175 175  <script>
176 176   document.addEventListener('DOMContentLoaded', function () {
177 - const key = "$likesKey";
175 + const key = "$doc.fullName";
178 178   const likeButton = document.getElementById('like-button');
179 - const likeCount = document.getElementById('like-count');
180 180  
181 181   function setCookie(name, value, days) {
182 182   const d = new Date();
... ... @@ -197,25 +197,11 @@
197 197  
198 198   likeButton.addEventListener('click', function () {
199 199   if (getCookie("liked-" + key) !== "true") {
200 - fetch(window.location.href + "?like=1", { method: 'GET' })
201 - .then(() => {
202 - let current = parseInt(likeCount.innerText);
203 - likeCount.innerText = current + 1;
204 - setCookie("liked-" + key, "true", 365);
205 - likeButton.disabled = true;
206 - likeButton.style.opacity = 0.6;
207 - });
197 + setCookie("liked-" + key, "true", 365);
198 + window.location.href = window.location.href + (window.location.href.indexOf('?') > -1 ? '&' : '?') + "like=1";
208 208   }
209 209   });
210 210   });
211 211  </script>
212 212  {{/html}}
213 -
214 -#if($request.getParameter("like") == "1")
215 - #set($likes = $likesObject.get("value"))
216 - $likesObject.set("value", $math.add($likes, 1))
217 - $xwiki.saveDocument($likesDoc)
218 -#end
219 219  {{/velocity}}
220 -
221 -