-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
103 lines (98 loc) · 3.06 KB
/
Copy pathscript.js
File metadata and controls
103 lines (98 loc) · 3.06 KB
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
$(document).ready(function () {
load_data();
$('#action').val("Insert");
$("#refresh").click(function () {
load_data();
});
$('#adding').click(function() { //update the "Add" button
$('#name').val('');
$('#description').val('');
$('#price').val('');
$('#picture').val('');
$('#my_image').hide();
$('#button_action').val("Insert");
$('#action').val("Insert");
});
$(document).on('click', '#button_action', function () { // dont show the same image after updating
$('#my_image').hide();
});
function filter(query) {
var action = "Filter";
$.ajax({
url: "action.php",
method: "POST",
data: {query: query, action: action},
success: function (data) {
$('#user_table').html(data);
}
});
}
$('#search_text').keyup(function () {
var search = $(this).val();
if (search != '') {
filter(search);
} else {
filter();
}
});
function load_data() {
var action = "Load";
$.ajax({
url: "action.php",
method: "POST",
data: {action: action},
success: function (data) {
$('#user_table').html(data);
}
});
}
$('#user_form').on('submit', function (event) {
event.preventDefault();
$.ajax({
url: "action.php",
method: "POST",
data: new FormData(this),
contentType: false,
processData: false,
success: function (data) {
alert(data);
$('#user_form')[0].reset();
}
})
});
$(document).on('click', '.update', function () {
var user_id = $(this).attr("id");
var action = "Fetch";
$.ajax({
url: "action.php",
method: "POST",
data: {user_id: user_id, action: action},
dataType: "json",
success: function (data) {
$('#modalPush').modal('show');
$('#name').val(data.name);
$('#description').val(data.description);
$('#price').val(data.price);
$('#my_image').attr('src',data.picture);
$('#my_image').show()
$('#picture').val(data.picture);
$('#button_action').val("Edit");
$('#action').val("Edit");
$('#user_id').val(user_id);
}
});
});
$(document).on('click', '.delete', function () {
var user_id = $(this).attr("id");
var action = "Delete";
$.ajax({
url: "action.php",
method: "POST",
data: {user_id: user_id, action: action},
success: function (data) {
alert(data);
$("#" + user_id).prop('disabled', true);
}
});
});
});