source: Git/src/main/resources/static/js/sharedScript.js@ c02189f

main
Last change on this file since c02189f was c02189f, checked in by Petar Partaloski <ppartaloski@…>, 3 years ago

Added new core functionalities, fixed bugs and improved visual clarity

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