Изменения документа Загрузить документ
Редактировал(а) HRlink 30.05.2025
Сводка
-
Свойства страницы (1 изменено, 0 добавлено, 0 удалено)
Подробности
- Свойства страницы
-
- Содержимое
-
... ... @@ -142,63 +142,41 @@ 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 +---- 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")) 150 - 151 -#if(!$likesObject) 147 +#set($likesKey = "$doc.fullName_LikeCount") 148 +#set($cookieName = "like_given_${likesKey}") 149 +#set($hasLiked = $request.getCookie($cookieName)) 150 +#set($likesDoc = $xwiki.getDocument("XWiki.XWikiPreferences")) 151 +#set($obj = $likesDoc.getObject("XWiki.LikesStorageClass", "key", $likesKey)) 152 +#if(!$obj) 152 152 #set($discard = $likesDoc.newObject("XWiki.LikesStorageClass")) 153 - $likesDoc.set("key", $doc.fullName) 154 - $likesDoc.set("value", 0) 155 - #set($discard = $xwiki.saveDocument($likesDoc)) 154 + #set($obj = $likesDoc.getObject("XWiki.LikesStorageClass", "key", $likesKey)) 155 + $obj.set("key", $likesKey) 156 + $obj.set("value", 0) 157 + $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)) 160 +#set($likes = $obj.getIntValue("value")) 161 + 162 +## Увеличение, если кнопка нажата и не было лайка 163 +#if($request.getParameter("like") && !$hasLiked) 164 + #set($likes = $likes + 1) 165 + $obj.set("value", $likes) 166 + $xwiki.saveDocument($likesDoc) 167 + $response.setCookie($cookieName, "true", 365*24*60*60) 162 162 #end 169 +{{/velocity}} 163 163 164 -#set($likes = $likesDoc.get("value")) 165 165 {{html clean="false"}} 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 - 👍 169 - </button> 170 - <span id="like-count" style="font-size:18px;">$likes</span> 171 - <span style="font-size:14px; color:#555;">Нравится статья?</span> 172 +<div style="margin-top:30px; display:flex; align-items:center; gap:10px; font-size:16px;"> 173 + <form method="post"> 174 + <input type="hidden" name="like" value="1"/> 175 + <button type="submit" title="Поставить лайк" style="background:none; border:none; font-size:24px; cursor:pointer;">❤️</button> 176 + </form> 177 + <span style="font-size:18px;">$likes</span> 178 + <span>Нравится статья?</span> 172 172 </div> 173 -<script> 174 - document.addEventListener('DOMContentLoaded', function () { 175 - const key = "$doc.fullName"; 176 - const likeButton = document.getElementById('like-button'); 177 - 178 - function setCookie(name, value, days) { 179 - const d = new Date(); 180 - d.setTime(d.getTime() + (days*24*60*60*1000)); 181 - document.cookie = name + "=" + value + "; expires=" + d.toUTCString() + "; path=/"; 182 - } 183 - 184 - function getCookie(name) { 185 - const value = `; ${document.cookie}`; 186 - const parts = value.split(`; ${name}=`); 187 - if (parts.length === 2) return parts.pop().split(';').shift(); 188 - } 189 - 190 - if (getCookie("liked-" + key) === "true") { 191 - likeButton.disabled = true; 192 - likeButton.style.opacity = 0.6; 193 - } 194 - 195 - likeButton.addEventListener('click', function () { 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"; 199 - } 200 - }); 201 - }); 202 -</script> 203 203 {{/html}} 204 -{{/velocity}} 181 + 182 +