|
1
|
|
|
var WETU_IMPORTER = { |
|
2
|
|
|
|
|
3
|
|
|
init : function() { |
|
4
|
|
|
if(jQuery('body').hasClass('tour-operator_page_wetu-importer')){ |
|
5
|
|
|
this.myAccommodationSearch(); |
|
6
|
|
|
this.watchSearch(); |
|
7
|
|
|
this.watchAdvancedSearch(); |
|
8
|
|
|
this.watchImportButton(); |
|
9
|
|
|
this.watchAddToListButton(); |
|
10
|
|
|
this.watchClearButton(); |
|
11
|
|
|
this.watchBannerButton(); |
|
12
|
|
|
this.watchConnectButton(); |
|
13
|
|
|
this.watchCheckBoxes(); |
|
14
|
|
|
this.watchTourUpdate(); |
|
15
|
|
|
} |
|
16
|
|
|
}, |
|
17
|
|
|
myAccommodationSearch: function() { |
|
18
|
|
|
jQuery('#wetu-importer-search-form').on( 'click', '.search-toggle', function(event) { |
|
19
|
|
|
event.preventDefault(); |
|
20
|
|
|
|
|
21
|
|
|
var keyword = ''; |
|
22
|
|
|
if(jQuery(this).hasClass('published')){ |
|
23
|
|
|
keyword = 'publish'; |
|
24
|
|
|
}else if(jQuery(this).hasClass('pending')){ |
|
25
|
|
|
keyword = 'pending'; |
|
26
|
|
|
}else if(jQuery(this).hasClass('draft')){ |
|
27
|
|
|
keyword = 'draft'; |
|
28
|
|
|
}else if(jQuery(this).hasClass('import')){ |
|
29
|
|
|
keyword = 'import'; |
|
30
|
|
|
} |
|
31
|
|
|
jQuery(this).parents('#wetu-importer-search-form').find('input.keyword').val(keyword); |
|
32
|
|
|
jQuery('#wetu-importer-search-form').submit(); |
|
33
|
|
|
jQuery(this).parents('#wetu-importer-search-form').find('input.keyword').val(''); |
|
34
|
|
|
}); |
|
35
|
|
|
}, |
|
36
|
|
|
watchSearch: function() { |
|
37
|
|
|
jQuery('#wetu-importer-search-form').on( 'submit', function(event) { |
|
38
|
|
|
event.preventDefault(); |
|
39
|
|
|
|
|
40
|
|
|
jQuery('#posts-filter tbody').html('<tr><td style="text-align:center;" colspan="4">'+jQuery('#wetu-importer-search-form .ajax-loader').html()+'</td></tr>'); |
|
41
|
|
|
|
|
42
|
|
|
var type = jQuery('#wetu-importer-search-form').attr('data-type'); |
|
43
|
|
|
var keywords = []; |
|
44
|
|
|
|
|
45
|
|
|
if('' != jQuery('#wetu-importer-search-form input.keyword').val()){ |
|
46
|
|
|
keywords.push(jQuery('#wetu-importer-search-form input.keyword').val()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if(undefined != jQuery('#wetu-importer-search-form .advanced-search textarea').val()){ |
|
50
|
|
|
var bulk_keywords = jQuery('#wetu-importer-search-form .advanced-search textarea').val().split('\n'); |
|
51
|
|
|
var arrayLength = bulk_keywords.length; |
|
52
|
|
|
for (var i = 0; i < arrayLength; i++) { |
|
53
|
|
|
keywords.push(bulk_keywords[i]); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
console.log(lsx_tour_importer_params.ajax_url); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
jQuery.post(lsx_tour_importer_params.ajax_url, |
|
60
|
|
|
{ |
|
61
|
|
|
'action' : 'lsx_tour_importer', |
|
62
|
|
|
'type' : type, |
|
63
|
|
|
'keyword' : keywords |
|
64
|
|
|
}, |
|
65
|
|
|
function(response) { |
|
66
|
|
|
jQuery('#posts-filter tbody').html(response); |
|
67
|
|
|
}); |
|
68
|
|
|
return false; |
|
69
|
|
|
}); |
|
70
|
|
|
}, |
|
71
|
|
|
watchAdvancedSearch: function() { |
|
72
|
|
|
jQuery('#wetu-importer-search-form .advanced-search-toggle').on( 'click', function(event) { |
|
73
|
|
|
event.preventDefault(); |
|
74
|
|
|
if(jQuery('#wetu-importer-search-form .advanced-search').hasClass('hidden')){ |
|
75
|
|
|
jQuery('#wetu-importer-search-form .advanced-search').fadeIn('fast').removeClass('hidden'); |
|
76
|
|
|
jQuery('#wetu-importer-search-form .normal-search').hide('fast'); |
|
77
|
|
|
jQuery('#wetu-importer-search-form .normal-search input.keyword').val(''); |
|
78
|
|
|
|
|
79
|
|
|
}else{ |
|
80
|
|
|
jQuery('#wetu-importer-search-form .advanced-search').fadeOut('fast').addClass('hidden'); |
|
81
|
|
|
jQuery('#wetu-importer-search-form .advanced-search textarea').val(''); |
|
82
|
|
|
jQuery('#wetu-importer-search-form .normal-search').fadeIn('fast'); |
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
}); |
|
86
|
|
|
}, |
|
87
|
|
|
watchClearButton: function() { |
|
88
|
|
|
jQuery('#posts-filter input.button.clear').on('click',function(event){ |
|
89
|
|
|
event.preventDefault(); |
|
90
|
|
|
jQuery('#posts-filter tbody').html(''); |
|
91
|
|
|
jQuery('#wetu-importer-search-form input[type="text"]').val(''); |
|
92
|
|
|
}); |
|
93
|
|
|
}, |
|
94
|
|
|
watchAddToListButton: function() { |
|
95
|
|
|
jQuery('#posts-filter input.button.add').on('click',function(event){ |
|
96
|
|
|
|
|
97
|
|
|
event.preventDefault(); |
|
98
|
|
|
jQuery('.import-list-wrapper').fadeIn('fast'); |
|
99
|
|
|
|
|
100
|
|
|
jQuery('#posts-filter tbody tr input:checked').each(function(){ |
|
101
|
|
|
jQuery('#import-list tbody').append(jQuery(this).parent().parent()); |
|
102
|
|
|
}); |
|
103
|
|
|
|
|
104
|
|
|
jQuery('#import-list tbody tr input:checked').each(function(){ |
|
105
|
|
|
jQuery(this).parent().parent().fadeIn('fast'); |
|
106
|
|
|
}); |
|
107
|
|
|
}); |
|
108
|
|
|
}, |
|
109
|
|
|
|
|
110
|
|
|
importRow: function(args,row) { |
|
111
|
|
|
var $this = this; |
|
112
|
|
|
var $row = row; |
|
113
|
|
|
|
|
114
|
|
|
jQuery.ajax( { |
|
115
|
|
|
url : lsx_tour_importer_params.ajax_url, |
|
|
|
|
|
|
116
|
|
|
data : args, |
|
117
|
|
|
method : 'POST' |
|
118
|
|
|
} ) |
|
119
|
|
|
.always( function( data, textStatus, response ) { |
|
|
|
|
|
|
120
|
|
|
if('none' == jQuery('.completed-list-wrapper').css('display')){ |
|
121
|
|
|
jQuery('.completed-list-wrapper').fadeIn('fast'); |
|
122
|
|
|
} |
|
123
|
|
|
jQuery('.completed-list-wrapper ul').append(data); |
|
124
|
|
|
$row.fadeOut('fast', |
|
125
|
|
|
function(here){ |
|
|
|
|
|
|
126
|
|
|
jQuery(this).fadeOut('fast').remove(); |
|
127
|
|
|
}); |
|
128
|
|
|
} ) |
|
129
|
|
|
.done( function( data ) { |
|
|
|
|
|
|
130
|
|
|
$this.importNext(); |
|
131
|
|
|
} ) |
|
132
|
|
|
.fail( function( reason ) { |
|
133
|
|
|
// Handles errors only |
|
134
|
|
|
console.debug( reason ); |
|
135
|
|
|
} ); |
|
136
|
|
|
}, |
|
137
|
|
|
|
|
138
|
|
|
importNext: function() { |
|
139
|
|
|
var checkbox = jQuery('#import-list tr input.queued:checked:not(.importing):first'); |
|
140
|
|
|
|
|
141
|
|
|
if(1 == checkbox.length){ |
|
142
|
|
|
checkbox.addClass('importing'); |
|
143
|
|
|
|
|
144
|
|
|
var post_type = jQuery('.post_type').val(); |
|
|
|
|
|
|
145
|
|
|
var array_import = []; |
|
|
|
|
|
|
146
|
|
|
var type = jQuery('#wetu-importer-search-form').attr('data-type'); |
|
147
|
|
|
|
|
148
|
|
|
var team_members = []; |
|
149
|
|
|
if('undefined' != jQuery('#import-list input.team').length){ |
|
150
|
|
|
jQuery('#import-list input.team').each(function(){ |
|
151
|
|
|
if(jQuery(this).attr('checked')){ |
|
152
|
|
|
team_members.push(jQuery(this).val()); |
|
153
|
|
|
} |
|
154
|
|
|
}); |
|
155
|
|
|
} |
|
156
|
|
|
var content = []; |
|
157
|
|
|
if('undefined' != jQuery('#import-list input.content').length){ |
|
158
|
|
|
jQuery('#import-list input.content').each(function(){ |
|
159
|
|
|
if(jQuery(this).attr('checked')){ |
|
160
|
|
|
content.push(jQuery(this).val()); |
|
161
|
|
|
} |
|
162
|
|
|
}); |
|
163
|
|
|
} |
|
164
|
|
|
var safari_brands = []; |
|
165
|
|
|
if('undefined' != jQuery('#import-list input.accommodation-brand').length){ |
|
166
|
|
|
jQuery('#import-list input.accommodation-brand').each(function(){ |
|
167
|
|
|
if(jQuery(this).attr('checked')){ |
|
168
|
|
|
safari_brands.push(jQuery(this).val()); |
|
169
|
|
|
} |
|
170
|
|
|
}); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
var wetu_id = checkbox.attr('data-identifier'); |
|
174
|
|
|
var post_id = checkbox.val(); |
|
175
|
|
|
var row = checkbox.parents('tr'); |
|
176
|
|
|
var data = { |
|
177
|
|
|
'action' : 'lsx_import_items', |
|
178
|
|
|
'type' : type, |
|
179
|
|
|
'wetu_id' : wetu_id, |
|
180
|
|
|
'post_id' : post_id, |
|
181
|
|
|
'team_members' : team_members, |
|
182
|
|
|
'safari_brands' : safari_brands, |
|
183
|
|
|
'content' : content |
|
184
|
|
|
}; |
|
185
|
|
|
this.importRow(data,row); |
|
186
|
|
|
} |
|
187
|
|
|
}, |
|
188
|
|
|
watchImportButton: function() { |
|
189
|
|
|
var $this = this; |
|
190
|
|
|
|
|
191
|
|
|
jQuery('#import-list input[type="submit"]').on('click',function(event){ |
|
192
|
|
|
|
|
193
|
|
|
event.preventDefault(); |
|
194
|
|
|
counter = 0; |
|
|
|
|
|
|
195
|
|
|
var false_click = true; |
|
196
|
|
|
|
|
197
|
|
|
jQuery('#import-list tr input:checked:not(.queued)').each(function(){ |
|
198
|
|
|
jQuery(this).hide().addClass('queued'); |
|
199
|
|
|
jQuery(this).parents('tr').find('.check-column').append(jQuery('#wetu-importer-search-form .ajax-loader-small').html()); |
|
200
|
|
|
false_click = false; |
|
201
|
|
|
}); |
|
202
|
|
|
|
|
203
|
|
|
if(true != false_click){ |
|
204
|
|
|
$this.importNext(); |
|
205
|
|
|
}else{ |
|
206
|
|
|
alert('Make sure you have some items selected.'); |
|
207
|
|
|
} |
|
208
|
|
|
}); |
|
209
|
|
|
}, |
|
210
|
|
|
watchBannerButton: function() { |
|
211
|
|
|
jQuery('#banners-filter input.button.download').on('click',function(event){ |
|
212
|
|
|
|
|
213
|
|
|
event.preventDefault(); |
|
214
|
|
|
jQuery('#banners-filter tbody tr input:checked').each(function(){ |
|
215
|
|
|
var post_id = jQuery(this).val(); |
|
216
|
|
|
var current_row = jQuery(this).parents('tr'); |
|
217
|
|
|
|
|
218
|
|
|
jQuery(this).hide(); |
|
219
|
|
|
jQuery(this).parents('tr').find('.check-column').append(jQuery('#banners-filter .ajax-loader-small').html()); |
|
220
|
|
|
|
|
221
|
|
|
jQuery.post(lsx_tour_importer_params.ajax_url, |
|
|
|
|
|
|
222
|
|
|
{ |
|
223
|
|
|
'action' : 'lsx_import_sync_banners', |
|
224
|
|
|
'post_id' : post_id, |
|
225
|
|
|
}, |
|
226
|
|
|
function(response) { |
|
|
|
|
|
|
227
|
|
|
current_row.fadeOut('fast', |
|
228
|
|
|
function(here){ |
|
|
|
|
|
|
229
|
|
|
jQuery(this).fadeOut('fast').remove(); |
|
230
|
|
|
}); |
|
231
|
|
|
}); |
|
232
|
|
|
}); |
|
233
|
|
|
}); |
|
234
|
|
|
}, |
|
235
|
|
|
watchConnectButton: function() { |
|
236
|
|
|
jQuery('#connect-accommodation-filter input.button.connect').on('click',function(event){ |
|
237
|
|
|
|
|
238
|
|
|
event.preventDefault(); |
|
239
|
|
|
jQuery('#connect-accommodation-filter tbody tr input:checked').each(function(){ |
|
240
|
|
|
var post_id = jQuery(this).val(); |
|
241
|
|
|
var type = 'connect_accommodation'; |
|
242
|
|
|
var wetu_id = jQuery(this).attr('data-identifier'); |
|
243
|
|
|
|
|
244
|
|
|
var current_row = jQuery(this).parents('tr'); |
|
245
|
|
|
|
|
246
|
|
|
jQuery(this).hide(); |
|
247
|
|
|
jQuery(this).parents('tr').find('.check-column').append(jQuery('#connect-accommodation-filter .ajax-loader-small').html()); |
|
248
|
|
|
|
|
249
|
|
|
jQuery.post(lsx_tour_importer_params.ajax_url, |
|
|
|
|
|
|
250
|
|
|
{ |
|
251
|
|
|
'action' : 'lsx_import_connect_accommodation', |
|
252
|
|
|
'post_id' : post_id, |
|
253
|
|
|
'type' : type, |
|
254
|
|
|
'wetu_id' : wetu_id, |
|
255
|
|
|
}, |
|
256
|
|
|
function(response) { |
|
257
|
|
|
if('none' == jQuery('.completed-list-wrapper').css('display')){ |
|
258
|
|
|
jQuery('.completed-list-wrapper').fadeIn('fast'); |
|
259
|
|
|
} |
|
260
|
|
|
jQuery('.completed-list-wrapper ul').append(response); |
|
261
|
|
|
current_row.fadeOut('fast', |
|
262
|
|
|
function(here){ |
|
|
|
|
|
|
263
|
|
|
jQuery(this).fadeOut('fast').remove(); |
|
264
|
|
|
}); |
|
265
|
|
|
}); |
|
266
|
|
|
}); |
|
267
|
|
|
}); |
|
268
|
|
|
}, |
|
269
|
|
|
watchCheckBoxes: function() { |
|
270
|
|
|
jQuery('form#import-list .settings-all input[type="checkbox"]').on('change',function(event){ |
|
|
|
|
|
|
271
|
|
|
var thisOBJ = jQuery(this); |
|
272
|
|
|
if('all' === thisOBJ.val()){ |
|
273
|
|
|
thisOBJ.parents('form').find('.settings-all input[type="checkbox"]:not([value="all"])').each(function(){ |
|
274
|
|
|
|
|
275
|
|
|
if('checked' === thisOBJ.attr('checked')) { |
|
276
|
|
|
jQuery(this).attr('checked', 'checked'); |
|
277
|
|
|
}else{ |
|
278
|
|
|
jQuery(this).removeAttr('checked'); |
|
279
|
|
|
} |
|
280
|
|
|
}); |
|
281
|
|
|
}else{ |
|
|
|
|
|
|
282
|
|
|
|
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
|
|
286
|
|
|
}); |
|
287
|
|
|
|
|
288
|
|
|
var lastChecked = null; |
|
289
|
|
|
|
|
290
|
|
|
jQuery('#the-list input[type="checkbox"], #import-list tbody input[type="checkbox"]').on('click',function(event){ |
|
|
|
|
|
|
291
|
|
|
if(!lastChecked) { |
|
292
|
|
|
lastChecked = this; |
|
293
|
|
|
return; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
if(e.shiftKey) { |
|
|
|
|
|
|
297
|
|
|
var start = $chkboxes.index(this); |
|
|
|
|
|
|
298
|
|
|
var end = $chkboxes.index(lastChecked); |
|
299
|
|
|
|
|
300
|
|
|
$chkboxes.slice(Math.min(start,end), Math.max(start,end)+ 1).prop('checked', lastChecked.checked); |
|
301
|
|
|
|
|
302
|
|
|
} |
|
303
|
|
|
lastChecked = this; |
|
304
|
|
|
}); |
|
305
|
|
|
}, |
|
306
|
|
|
|
|
307
|
|
|
watchTourUpdate: function() { |
|
308
|
|
|
jQuery('.wetu-status.tour-wetu-status h3 a').on('click',function(event){ |
|
309
|
|
|
event.preventDefault(); |
|
310
|
|
|
jQuery(this).parents('.wetu-status.tour-wetu-status').find('form').submit(); |
|
311
|
|
|
}); |
|
312
|
|
|
|
|
313
|
|
|
} |
|
314
|
|
|
} |
|
315
|
|
|
jQuery(document).ready( function() { |
|
316
|
|
|
WETU_IMPORTER.init(); |
|
317
|
|
|
}); |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.