source: Git/Sources/target/classes/static/js/sharedScript.js

main
Last change on this file was 980eeda, checked in by Test <matonikolov77@…>, 2 years ago

Restructuring project

  • Property mode set to 100644
File size: 15.3 KB
Line 
1var urlRating;
2
3$(document).ready(function (){
4 var elements = $(".elements")
5 var elementGrade;
6 var first_time = true;
7
8 $("#button-add").on("click", function (){
9 itemInput = $("#pageInput")
10 itemInput.val(Number(itemInput.val()) + 1);
11 $("#button-submit-page").click()
12 })
13
14 $("#button-sub").on("click", function (){
15 itemInput = $("#pageInput")
16 if(Number(itemInput.val()) > 1){
17 itemInput.val(Number(itemInput.val()) - 1);
18 $("#button-submit-page").click()
19 }
20 })
21
22 $("#searchTitle").on("keyup", function() {
23 var value = $(this).val().toLowerCase();
24 console.log(value)
25 $(".elements div a .title").filter(function() {
26 console.log($(this).text())
27 if($(this).text().toLowerCase().indexOf(value) <= -1)
28 $(this).parent().parent().parent().addClass("visibility")
29 else
30 $(this).parent().parent().parent().removeClass("visibility")
31 });
32 });
33
34
35
36
37 $("#dialog-rating").dialog({
38 autoOpen: false,
39 modal: true,
40 buttons: [
41 {
42 text: "Потврди",
43 click: function () {
44 $("#dialog-rating").dialog("close")
45 ajaxCallRating(urlRating,elementGrade)
46 }
47 },
48 {
49 text: "Откажи",
50 click: function () {
51 $("#dialog-rating").dialog("close")
52 }
53 }
54 ]
55 });
56 $(".button-add-grade-movie").on("click",function (){
57 elementGrade = $(this)
58 urlRating ="/api/movies/grade/"+$(this).attr("movie-id")
59 $("#dialog-rating").dialog("open")
60 })
61 $(".button-add-grade-person").on("click",function (){
62 elementGrade = $(this)
63 urlRating ="/api/persons/grade/"+$(this).attr("person-id")
64 $("#dialog-rating").dialog("open")
65 })
66
67
68 /*$(".search-button-title").on("click",function (){
69 let filter = $("#searchTitle").val()
70 console.log(elements)
71 for (let item of elements){
72 let title = $(item).find(".card-title").text()
73 if (title.toLowerCase() === filter.toLowerCase()){
74 console.log("Da")
75 $(item).css("display","block")
76 }
77 else{
78 $(item).css("display","none")
79 }
80 }
81 })*/
82
83 $("#button_toggle_filters").on("click", function (){
84 if(first_time){
85 $("#filters_div").removeClass("invisible-search")
86 first_time=false
87 }
88 else
89 $("#filters_div").fadeToggle();
90 })
91
92 $(".user-movies-list").on("click", function (){
93 let children = $(this).children()
94 let first = true
95 for (let item of children){
96 if(first){
97 first = !first
98 }
99 else{
100 $(item).fadeToggle();
101 }
102 }
103 $(this).toggleClass("hidden-class")
104 })
105
106 $(".search-button").on("click",function () {
107 elements = $(".elements")
108 let filter = $("#searchGenre").val()
109 console.log('\''+filter+'\'')
110 console.log(elements)
111 if(filter.length==0){
112 console.log("HERE")
113 for (let item of elements) {
114 $(item).removeClass("visibility")
115 }
116 }
117 for (let item of elements) {
118 $(item).removeClass("visibility")
119 let genre = $(item).children(".card-genre")
120 let visible = false;
121 console.log(genre.length)
122 for (let g of genre) {
123 if (( $(g).text().toLowerCase() === filter.toLowerCase())){
124 console.log(item.text + ' ' + $(g).text())
125 visible = true
126 $(item).removeClass("visibility")
127 break;
128 }
129 }
130 if(!visible){
131 $(item).addClass("visibility")
132 }
133
134 }
135 });
136
137 $(".button-delete-movie").on("click",function (){
138 let button = $(this)
139 let url = "/api/movies/delete/" + $(button).attr("movie-id")
140 ajaxCallDelete(url,button)
141 })
142 $(".button-delete-actor").on("click",function (){
143 let button = $(this)
144 let url = "/api/persons/delete/" + $(button).attr("person-id")
145 ajaxCallDelete(url,button)
146 })
147 $(".button-delete-discussion").on("click",function (){
148 let button = $(this)
149 let url = "/api/discussions/delete/" + $(button).attr("discussion-id")
150 ajaxCallDelete(url,button)
151 })
152
153 $(document.body).on("click",".button-confirm",function (){
154
155 $(this).parent().parent().fadeOut(2000)
156 })
157 $(".person-movies").change(function (){
158 if (this.value === "A"){
159 $(".movie-directors").attr("hidden",true).prop("selected",false)
160
161
162 $(".movies-actors").attr("hidden",false)
163
164 }
165 else{
166 $(".movies-actors").attr("hidden",true).prop("selected",false)
167 $(".movie-directors").attr("hidden",false)
168 }
169 })
170 $(document.body).on("click",".button-add-favourite-list",function (){
171 let button = $(this)
172 let url = "/api/movies/like/"+ $(this).attr("movie-id") + "?userId="+ $(this).attr("user-id")
173 ajaxCallLike(url,button,'like','Веќе е филмот допаднат!')
174 })
175 $(document.body).on("click",".button-remove-favourite-list",function (){
176 let button = $(this)
177 let url = "/api/movies/unlike/"+ $(this).attr("movie-id")+"?userId="+ $(this).attr("user-id")
178 ajaxCallLike(url,button,'unlike','Немате оставено допаѓање на филмот!')
179 })
180 $(document.body).on("click",".button-add-genre-liked-list",function (){
181 let button = $(this)
182 let url = "/api/genres/like/"+ $(this).attr("genre-id") + "?userId="+ $(this).attr("user-id")
183 ajaxCallLikeGenre(url,button,'like','Веќе ви се допаѓа жанрот!')
184 })
185 $(document.body).on("click",".button-remove-genre-liked-list",function (){
186 let button = $(this)
187 let url = "/api/genres/unlike/"+ $(this).attr("genre-id")+"?userId="+ $(this).attr("user-id")
188 ajaxCallLikeGenre(url,button,'unlike','Немате оставено допаѓање на жанрот!')
189 })
190 $(document.body).on("click",".button-like-discussion",function (){
191 let button = $(this)
192 let url = "/api/discussions/like/"+ $(this).attr("discussion-id")+"?userId="+ $(this).attr("user-id")
193 ajaxCallLikeDiscussion(url,button,'like','Веќе имате оставено допаѓање на дискусијата!')
194 })
195 $(document.body).on("click",".button-unlike-discussion",function (){
196 let button = $(this)
197 let url = "/api/discussions/unlike/"+ $(this).attr("discussion-id")+"?userId="+ $(this).attr("user-id")
198 ajaxCallLikeDiscussion(url,button,'unlike','Немате оставено допаѓање на дискусијата!')
199 })
200 $(document.body).on("click",".button-like-discussion-alt",function (){
201 let button = $(this)
202 let url = "/api/discussions/like/"+ $(this).attr("discussion-id")+"?userId="+ $(this).attr("user-id")
203 ajaxCallLikeDiscussionAlternative(url,button,'like','Веќе имате оставено допаѓање на дискусијата!')
204 })
205 $(document.body).on("click",".button-unlike-discussion-alt",function (){
206 let button = $(this)
207 let url = "/api/discussions/unlike/"+ $(this).attr("discussion-id")+"?userId="+ $(this).attr("user-id")
208 ajaxCallLikeDiscussionAlternative(url,button,'unlike','Немате оставено допаѓање на дискусијата!')
209 })
210 $(".discussion-type").change(function (){
211 if (this.value === "M"){
212 $(".persons-discussion").hide()
213 $(".movies-discussion").show()
214
215
216 }
217 else{
218 $(".movies-discussion").hide()
219 $(".persons-discussion").show()
220 }
221 })
222
223
224})
225function ajaxCallLike(url,button,type,message){
226 $.ajax({
227 url:url,
228 success:function (data){
229 if (data){
230 let el = $(button).parent().siblings().eq(3)
231 console.log(el)
232 if (type=="like") {
233 $(el).html(parseInt($(el).text()) + 1)
234 console.log("da")
235 }
236 else
237 $(el).html(parseInt($(el).text()) - 1)
238 $(button).css("display","none")
239 let userId = $(button).attr("user-id")
240 let movieId=$(button).attr("movie-id")
241 if (type==='like') {
242 $(button).parent().append("<a class='btn btn-danger button-remove-favourite-list' movie-id=" + movieId + " user-id=" + userId + ">💔</a>")
243 console.log("da")
244 }
245 else{
246 $(button).parent().append("<a class='btn btn-success button-add-favourite-list' movie-id=" + movieId + " user-id=" + userId + ">❤</a>")
247 }
248 likes_count = $("#movie_likes_count")
249 count = Number($(likes_count).text())
250 if(type==="like")
251 count++
252 else
253 count--
254 likes_count.text(count)
255 $(button).remove()
256 }
257 else {
258 $(button).parent().append("<div>" + message +" <button class='button-confirm'>Ок</button></div>")
259 }
260 }
261 })
262}
263function ajaxCallDelete(url,button){
264 $.ajax({
265 url:url,
266 method:"DELETE",
267 success: function (data){
268 if (data){
269 console.log(data)
270 $(button).parent().parent().html("<div>Бришењето е успешно!<button class='button-confirm'>Ок</button></div>")
271 }
272 else {
273 var div = "<div>Веќе е избришан записот! <button class='button-confirm'>Ок</button></div>"
274 button.parent().html(button.parent().html() + div)
275 }
276 }
277 })
278}
279
280
281
282function ajaxCallLikeGenre(url,button,type,message){
283 $.ajax({
284 url:url,
285 success:function (data){
286 if (data){
287 let el = $(button).parent().siblings().eq(3)
288 console.log(el)
289 if (type=="like") {
290 $(el).html(parseInt($(el).text()) + 1)
291 console.log("da")
292 }
293 else
294 $(el).html(parseInt($(el).text()) - 1)
295 $(button).css("display","none")
296 let userId = $(button).attr("user-id")
297 let genreId=$(button).attr("genre-id")
298 if (type==='like') {
299 $(button).parent().append("<a class='btn btn-danger button-remove-genre-liked-list' genre-id=" + genreId + " user-id=" + userId + ">💔</a>")
300 console.log("da")
301 }
302 else{
303 $(button).parent().append("<a class='btn btn-success button-add-genre-liked-list' genre-id=" + genreId + " user-id=" + userId + ">❤</a>")
304 }
305 let likes_sibling = $("#"+genreId+"genre")
306 value_likes = Number(likes_sibling.text())
307 if(type=="like")
308 value_likes+=1
309 else
310 value_likes-=1
311 likes_sibling.text(value_likes)
312 $(button).remove()
313 }
314 else {
315 $(button).parent().append("<div>" + message +" <button class='button-confirm'>Ок</button></div>")
316 }
317 }
318 })
319}
320
321
322
323
324function ajaxCallLikeDiscussion(url,button,type,message){
325 $.ajax({
326 url:url,
327 success:function (data){
328 if (data){
329 let el = $(button).parent().siblings().eq(3)
330 console.log(el)
331 if (type=="like") {
332 $(el).html(parseInt($(el).text()) + 1)
333 console.log("da")
334 }
335 else
336 $(el).html(parseInt($(el).text()) - 1)
337 $(button).css("display","none")
338 let userId = $(button).attr("user-id")
339 let discussionId=$(button).attr("discussion-id")
340 if (type==='like') {
341 $(button).parent().append("<a class='btn btn-danger button-unlike-discussion' discussion-id=" + discussionId + " user-id=" + userId + ">💔</a>")
342 console.log("da")
343 }
344 else{
345 $(button).parent().append("<a class='btn btn-success button-like-discussion' discussion-id=" + discussionId + " user-id=" + userId + ">❤</a>")
346 }
347 var likes_count = $("#likes_count")
348 var count = Number($(likes_count).text())
349 if(type==='like')
350 count += 1
351 else
352 count -= 1
353 $(likes_count).text(count);
354 $(button).remove()
355 }
356 else {
357 $(button).parent().append("<div>" + message +" <button class='button-confirm'>Ок</button></div>")
358 }
359 }
360 })
361}
362
363
364
365function ajaxCallLikeDiscussionAlternative(url,button,type,message){
366 $.ajax({
367 url:url,
368 success:function (data){
369 if (data){
370 let el = $(button).parent().siblings().eq(3)
371 console.log(el)
372 if (type=="like") {
373 $(el).html(parseInt($(el).text()) + 1)
374 console.log("da")
375 }
376 else
377 $(el).html(parseInt($(el).text()) - 1)
378 $(button).css("display","none")
379 let userId = $(button).attr("user-id")
380 let discussionId=$(button).attr("discussion-id")
381 if (type==='like') {
382 $(button).parent().append("<a class='btn btn-danger button-unlike-discussion-alt' discussion-id=" + discussionId + " user-id=" + userId + ">💔</a>")
383 console.log("da")
384 }
385 else{
386 $(button).parent().append("<a class='btn btn-success button-like-discussion-alt' discussion-id=" + discussionId + " user-id=" + userId + ">❤</a>")
387 }
388 var likes_count = $(button).parent().siblings(".likes_count").first()
389 var count = Number(likes_count.text())
390 if(type==='like')
391 count += 1
392 else
393 count -= 1
394 $(likes_count).text(count);
395 $(button).remove()
396 }
397 else {
398 $(button).parent().append("<div>" + message +" <button class='button-confirm'>Ок</button></div>")
399 }
400 }
401 })
402}
403
404
405function ajaxCallRating(url,button,type){
406 model = {
407 rating:$("#grade").val(),
408 reason:$("#reason").val()
409 }
410 $.ajax({
411 url:urlRating,
412 method: "POST",
413 dataType:"json",
414 data:JSON.stringify(model),
415 contentType : 'application/json; charset=utf-8',
416 success: function (data){
417 if (data){
418 console.log(data)
419 $(button).text("Промени оцена и мислење")
420 }
421
422 }
423 })
424}
Note: See TracBrowser for help on using the repository browser.