forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyscript.js
145 lines (107 loc) · 3.87 KB
/
myscript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/***************************** Authentication Actions ******************************/
$("#loginbtn").on("click", function(){
var user = $("#username").val();
var password = $("#password").val();
var nextURL = $("#nextURL").val();
$("#loader").html('<img src="loader.gif">');
$.post("process-auth.php", {action: 'login', username: user, password: password}, function (response) {
$("#loader").html('');
var response = JSON.parse(response);
if (response.success) {
window.location.href = nextURL;
}
else {
$("#loader").html('<p class="alert alert-danger">Invalid username/password</p>');
}
});
});
$("#logoutbtn").on("click", function(){
$.post("process-auth.php", {action: 'logout'}, function (response) {
window.location.href = "index.php";
});
});
/***************************** Gallery Actions ******************************/
// Add Gallery Action
$("#addGallerybtn").on("click", function(){
var galleryName = $("#galleryName").val();
if(galleryName != "") {
$("#loader").html('<img src="loader.gif">');
$.post("process-gallery.php", {action: 'addGallery', galleryName: galleryName}, function (response) {
$("#loader").html('');
var response = JSON.parse(response);
if (response.success) {
location.reload();
}
else {
console.log("Error Adding Gallery");
}
});
}
});
// Delete Gallery Action
$("#deleteGallerybtn").on("click", function(){
var galleryName = $(this).data("galleryname");
if(galleryName != "") {
$("#loader").html('<img src="loader.gif">');
$.post("process-gallery.php", {action: 'deleteGallery', galleryName: galleryName}, function (response) {
$("#loader").html('');
var response = JSON.parse(response);
if (response.success) {
location.reload();
}
else {
console.log("Error Adding Gallery");
}
});
}
});
// Edit Gallery Action
$(document).on("click", '#editGallerybtn', function(){
var galleryName = $(this).data("name");
$("#oldGalleryName").val(galleryName);
});
// Edit Gallery Modal Action
$("#editGalleryModalBtn").on("click", function(){
var newName = $("#newGalleryName").val();
var galleryName = $("#oldGalleryName").val();
if(galleryName != "") {
$("#loader").html('<img src="loader.gif">');
$.post("process-gallery.php", {action: 'editGallery', galleryName: galleryName, newName: newName}, function (response) {
$("#loader").html('');
var response = JSON.parse(response);
if (response.success) {
location.reload();
}
else {
console.log("Error Adding Gallery");
}
});
}
});
/***************************** Photos Actions ******************************/
// Delete Photo Action
$("#deletePhotobtn").on("click", function(){
var galleryName = $(this).data("galleryname");
var photoName = $(this).data("photoname");
if(galleryName != "") {
$.post("process-photos.php", {action: 'deletePhoto', galleryName: galleryName, photoName: photoName}, function (response) {
var response = JSON.parse(response);
if (response.success) {
location.reload();
//console.log("success");
}
else {
console.log("Error Deleting Photo");
}
});
}
});
$(document).on("click", '#popImage', function(){
var imgSrc = $(this).data("imgsrc");
$('#imagepreview').attr('src', imgSrc);
$('#imagemodal').modal('show');
});
// $('#popImage').on('click', function() {
// $('.imagepreview').attr('src', $(this).find('img').attr('src'));
// $('#imagemodal').modal('show');
// });