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

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

Fixed and added a better front end, improved clarity

  • Property mode set to 100644
File size: 6.3 KB
Line 
1var urlRating;
2
3$(document).ready(function (){
4 var elements = $(".elements")
5 var elementGrade;
6
7
8 $("#dialog-rating").dialog({
9 autoOpen: false,
10 modal: true,
11 buttons: [
12 {
13 text: "Потврди",
14 click: function () {
15 $("#dialog-rating").dialog("close")
16 ajaxCallRating(urlRating,elementGrade)
17 }
18 },
19 {
20 text: "Откажи",
21 click: function () {
22 $("#dialog-rating").dialog("close")
23 }
24 }
25 ]
26 });
27 $(".button-add-grade-movie").on("click",function (){
28 elementGrade = $(this)
29 urlRating ="api/movies/grade/"+$(this).attr("movie-id")
30 $("#dialog-rating").dialog("open")
31 })
32 $(".button-add-grade-person").on("click",function (){
33 elementGrade = $(this)
34 urlRating ="api/persons/grade/"+$(this).attr("person-id")
35 $("#dialog-rating").dialog("open")
36 })
37
38
39 $(".search-button-title").on("click",function (){
40 let filter = $("#searchTitle").val()
41 for (let item of elements){
42 let title = item.cells[0].innerText
43 if (title.toLowerCase() === filter.toLowerCase()){
44 $(item).css("display","block")
45 }
46 else{
47 $(item).css("display","none")
48 }
49 }
50
51 })
52
53
54 $(".search-button").on("click",function () {
55 let filter = $("#searchGenre").val()
56 for (let item of elements) {
57 let genre = item.cells[4].children;
58 let visible = false;
59
60 for (g of genre) {
61
62 if ($(g).text().toLowerCase() === filter.toLowerCase()) {
63 visible = true
64 $(item).css("display","block")
65 break;
66 }
67 }
68 if (!visible)
69 $(item).css("display","none")
70 }
71 });
72
73 $(".button-delete-movie").on("click",function (){
74 let button = $(this)
75 let url = "api/movies/delete/" + $(button).attr("movie-id")
76 ajaxCallDelete(url,button)
77 })
78 $(".button-delete-actor").on("click",function (){
79 let button = $(this)
80 let url = "api/persons/delete/" + $(button).attr("person-id")
81 ajaxCallDelete(url,button)
82 })
83 $(".button-delete-discussion").on("click",function (){
84 let button = $(this)
85 let url = "api/discussions/delete/" + $(button).attr("discussion-id")
86 ajaxCallDelete(url,button)
87 })
88
89 $(document.body).on("click",".button-confirm",function (){
90
91 $(this).parent().parent().fadeOut(2000)
92 })
93 $(".person-movies").change(function (){
94 if (this.value === "A"){
95 $(".movie-directors").attr("hidden",true).prop("selected",false)
96
97
98 $(".movies-actors").attr("hidden",false)
99
100 }
101 else{
102 $(".movies-actors").attr("hidden",true).prop("selected",false)
103 $(".movie-directors").attr("hidden",false)
104 }
105 })
106 $(document.body).on("click",".button-add-favourite-list",function (){
107 let button = $(this)
108 let url = "api/movies/like/"+ $(this).attr("movie-id") + "?userId="+ $(this).attr("user-id")
109 ajaxCallLike(url,button,'like','Веќе е филмот допаднат!')
110 })
111 $(document.body).on("click",".button-remove-favourite-list",function (){
112 let button = $(this)
113 let url = "api/movies/unlike/"+ $(this).attr("movie-id")+"?userId="+ $(this).attr("user-id")
114 ajaxCallLike(url,button,'unlike','Немате оставено допаѓање на филмот!')
115 })
116 $(".discussion-type").change(function (){
117 if (this.value === "M"){
118 $(".persons-discussion").hide()
119 $(".movies-discussion").show()
120
121
122 }
123 else{
124 $(".movies-discussion").hide()
125 $(".persons-discussion").show()
126 }
127 })
128
129
130})
131function ajaxCallLike(url,button,type,message){
132 $.ajax({
133 url:url,
134 success:function (data){
135 if (data){
136 let el = $(button).parent().siblings().eq(3)
137 console.log(el)
138 if (type=="like") {
139 $(el).html(parseInt($(el).text()) + 1)
140 console.log("da")
141 }
142 else
143 $(el).html(parseInt($(el).text()) - 1)
144 $(button).css("display","none")
145 let userId = $(button).attr("user-id")
146 let movieId=$(button).attr("movie-id")
147 if (type==='like') {
148 $(button).parent().append("<a class='btn btn-warning button-remove-favourite-list' movie-id=" + movieId + " user-id=" + userId + ">Избриши од омилена листа</a>")
149 console.log("da")
150 }
151 else{
152 $(button).parent().append("<a class='btn btn-success button-add-favourite-list' movie-id=" + movieId + " user-id=" + userId + ">Додади во омилена листа</a>")
153
154 }
155 }
156 else {
157 $(button).parent().append("<div>" + message +" <button class='button-confirm'>Ок</button></div>")
158 }
159 }
160 })
161}
162function ajaxCallDelete(url,button){
163 $.ajax({
164 url:url,
165 method:"DELETE",
166 success: function (data){
167 if (data){
168 console.log(data)
169 $(button).parent().parent().html("<div>Бришењето е успешно!<button class='button-confirm'>Ок</button></div>")
170 }
171 else {
172 var div = "<div>Веќе е избришан записот! <button class='button-confirm'>Ок</button></div>"
173 button.parent().html(button.parent().html() + div)
174 }
175 }
176 })
177}
178function ajaxCallRating(url,button,type){
179 model = {
180 rating:$("#grade").val(),
181 reason:$("#reason").val()
182 }
183 $.ajax({
184 url:urlRating,
185 method: "POST",
186 dataType:"json",
187 data:JSON.stringify(model),
188 contentType : 'application/json; charset=utf-8',
189 success: function (data){
190 if (data){
191 console.log(data)
192 $(button).text("Промени оцена и мислење")
193 }
194
195 }
196 })
197}
Note: See TracBrowser for help on using the repository browser.