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

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

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

Сводка

Подробности

Свойства страницы
Содержимое
... ... @@ -142,38 +142,46 @@
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 +----
145 145  
146 146  {{velocity}}
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"))
148 +#set($likesKey = $doc.fullName)
149 +#set($likesDoc = $xwiki.getDocument("XWiki.LikesStorage"))
150 +#set($likesObject = $likesDoc.getObject("XWiki.LikesStorageClass", "key", $likesKey))
150 150  
151 151  #if(!$likesObject)
152 - #set($discard = $likesDoc.newObject("XWiki.LikesStorageClass"))
153 - $likesDoc.set("key", $doc.fullName)
154 - $likesDoc.set("value", 0)
155 - #set($discard = $xwiki.saveDocument($likesDoc))
153 + #set($likesObject = $likesDoc.newObject("XWiki.LikesStorageClass"))
154 + $likesObject.set("key", $likesKey)
155 + $likesObject.set("value", 0)
156 + $xwiki.saveDocument($likesDoc)
156 156  #end
157 157  
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))
159 +#if($request.getParameter("like") == "1")
160 + #set($likes = $likesObject.get("value"))
161 + $likesObject.set("value", $math.add($likes, 1))
162 + $xwiki.saveDocument($likesDoc)
162 162  #end
163 163  
164 -#set($likes = $likesDoc.get("value"))
165 +#set($likes = $likesObject.get("value"))
166 +#set($liked = $request.getCookie("liked-$likesKey"))
167 +#set($userLiked = false)
168 +#if("$!liked" == "true")
169 + #set($userLiked = true)
170 +#end
171 +
165 165  {{html clean="false"}}
166 166  <div id="like-container" style="margin-top:20px; display:flex; align-items:center; gap:10px;">
167 - <button id="like-button" style="cursor:pointer; font-size: 22px; background: none; border: none;" title="Лайк">
168 - 👍
174 + <button id="like-button" style="cursor:pointer; font-size: 20px; background: none; border: none;" title="Нравится">
175 + <span id="heart" style="color:#e74c3c;">❤️</span>
169 169   </button>
170 170   <span id="like-count" style="font-size:18px;">$likes</span>
171 - <span style="font-size:14px; color:#555;">Нравится статья?</span>
178 + <span style="font-size:14px; color: #555;">Нравится статья?</span>
172 172  </div>
173 173  <script>
174 174   document.addEventListener('DOMContentLoaded', function () {
175 - const key = "$doc.fullName";
182 + const key = "$likesKey";
176 176   const likeButton = document.getElementById('like-button');
184 + const likeCount = document.getElementById('like-count');
177 177  
178 178   function setCookie(name, value, days) {
179 179   const d = new Date();
... ... @@ -194,8 +194,14 @@
194 194  
195 195   likeButton.addEventListener('click', function () {
196 196   if (getCookie("liked-" + key) !== "true") {
197 - setCookie("liked-" + key, "true", 365);
198 - window.location.href = window.location.href + (window.location.href.indexOf('?') > -1 ? '&' : '?') + "like=1";
205 + fetch(window.location.href + "?like=1", { method: 'GET' })
206 + .then(() => {
207 + let current = parseInt(likeCount.innerText);
208 + likeCount.innerText = current + 1;
209 + setCookie("liked-" + key, "true", 365);
210 + likeButton.disabled = true;
211 + likeButton.style.opacity = 0.6;
212 + });
199 199   }
200 200   });
201 201   });