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