-
Notifications
You must be signed in to change notification settings - Fork 3
/
open-csa-wp-deliveries.js
175 lines (135 loc) · 5.18 KB
/
open-csa-wp-deliveries.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
var $j = jQuery.noConflict();
$j(document).ready(function() {
var table = $j("#open-csa-wp-showDeliveriesList_table");
if (table.length > 0) {
table.dataTable({
"bPaginate": false,
"bStateSave": true,
"bInfo": false,
"bFilter": true,
"bSort" : true
});
}
var delivery_tips = $j("#open-csa-wp-newDelivery_div .open-csa-wp-tip_deliveries");
if(delivery_tips.length > 0) {
delivery_tips.cluetip({
splitTitle: '|',
showTitle: false,
hoverClass: 'highlight',
open: 'slideDown',
openSpeed: 'slow'
});
}
delivery_tips = $j("#open-csa-wp-showDeliveriesList_div .open-csa-wp-tip_deliveries");
if(delivery_tips.length > 0) {
delivery_tips.cluetip({
splitTitle: '|',
showTitle: false,
hoverClass: 'highlight',
open: 'slideDown',
openSpeed: 'slow'
});
}
});
function open_csa_wp_new_delivery_format_custom_values (btn) {
btn.disabled = true;
var deadline_time_obj = document.getElementById("open-csa-wp-newDelivery_order_deadline_time_input_id");
deadline_time_obj.value = deadline_time_obj.value.split(" ")[2] + ":00";
var delivery_start_time_obj = document.getElementById("open-csa-wp-newDelivery_spotDetails_delivery_start_time_input_id");
delivery_start_time_obj.value = delivery_start_time_obj.value.split(" ")[1] + ":00";
var deliveryEndTimeObj = document.getElementById("open-csa-wp-newDelivery_spotDetails_delivery_end_time_input_id");
deliveryEndTimeObj.value = deliveryEndTimeObj.value.split(" ")[1] + ":00";
var $j = jQuery.noConflict();
$j(btn).closest("form").submit();
}
function open_csa_wp_request_initiate_new_or_update_delivery(btn, delivery_id, url_address) {
var $j = jQuery.noConflict();
document.getElementById("open-csa-wp-newDelivery_spotDetails_spotID_input_disabled_id").disabled = false;
document.getElementById("open-csa-wp-newDelivery_delivery_deadline_date_disabled_id").disabled = false;
document.getElementById("open-csa-wp-newDelivery_inCharge_input_disabled_id").disabled = false;
var serialized_form_data = $j('#open-csa-wp-initiateNewDelivery_form_id').serializeArray();
if (serialized_form_data[1].value == "") {
open_csa_wp_you_forgot_this_one (document.getElementById("open-csa-wp-newDelivery_delivery_deadline_date_input_span_id"));
event.preventDefault();
}
else {
btn.disabled = true;
var $j = jQuery.noConflict();
serialized_form_data = JSON.stringify(serialized_form_data);
var data = {
'action': 'open-csa-wp-initiate_or_update_new_delivery_request',
'delivery_id' : delivery_id,
'data' : serialized_form_data
}
$j.post(ajaxurl, data ,
function(response){
//console.log("Server returned: [" + response + "]");
btn.disabled = false;
window.location.replace(url_address);
});
}
}
function open_csa_wp_request_delete_deliver(delivery) {
var $j = jQuery.noConflict();
var deliveryTR = $j(delivery).closest("tr");
var delivery_id = $j(deliveryTR).attr("id").split('_')[1];
var data = {
"action" : "open-csa-wp-delete_delivery",
"delivery_id" : delivery_id
};
$j.post(ajaxurl, data,
function(response) {
//console.log ("Server returned:["+response+"]");
$j(deliveryTR).fadeOut(200,function() {
$j(deliveryTR).remove();
if ($j('#open-csa-wp-showDeliveriesList_table .open-csa-wp-showDeliveries-delivery').length == 0) {
location.reload(true);
}
});
}
);
}
function open_csa_wp_edit_delivery(deliveryObj, page_url) {
var deliveryTR = $j(deliveryObj).closest("tr");
var delivery_id = $j(deliveryTR).attr("id").split('_')[1];
window.location.replace( page_url + "&delivery_id=" + delivery_id);
}
function open_csa_wp_request_toggle_delivery_ability_to_order(image_obj, plugins_dir) {
var $j = jQuery.noConflict();
var row = image_obj.parentNode.parentNode;
var delivery_id = row.id.split('_')[1];
var are_orders_open = image_obj.title.split(" ")[0]=='remove'?0:1;
//update database
var data = {
"action" : "open-csa-wp-update_delivery_abilityToOrder",
"delivery_id" : delivery_id,
"are_orders_open" : are_orders_open
};
$j.post(ajaxurl, data,
function(response) {
//console.log ("Server returned:["+response+"]");
open_csa_wp_toggle_delivery_ability_to_order (delivery_id, plugins_dir);
}
);
}
function open_csa_wp_toggle_delivery_ability_to_order (delivery_id, plugins_dir) {
obj_tr = document.getElementById ("open-csa-wp-showDeliveriesDeliveryID_"+delivery_id);
image_obj = document.getElementById("open-csa-wp-showDeliveriesOpenOrdersIconID_"+delivery_id);;
text_obj = document.getElementById("open-csa-wp-showDeliveriesOpenOrdersID_"+delivery_id);
//toggle row color, image source, text, and title
if (image_obj.title.split(" ")[0] == 'grant') {
if (obj_tr.style.color != 'grey') {
obj_tr.style.color = 'green';
}
image_obj.src = plugins_dir + "/open-csa-wp/icons/open.png";
text_obj.innerHTML = deliveries_translation.yes;
image_obj.title = deliveries_translation.remove_ability_to_order;
} else {
if (obj_tr.style.color != 'grey') {
obj_tr.style.color = 'brown';
}
image_obj.src = plugins_dir + "/open-csa-wp/icons/close.png";
text_obj.innerHTML = deliveries_translation.no;
image_obj.title = deliveries_translation.grant_ability_to_order";
}
}