-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
149 lines (126 loc) · 5.28 KB
/
Copy pathscript.js
File metadata and controls
149 lines (126 loc) · 5.28 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
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
(function($) {
$(document).ready(function() {
$('.migrate-sets .more').click(function() {
var $tr = $(this).parents('tr');
var set_flickr_id = $('input', $tr).val();
var data = {
action : 'photoset_info',
flickr_id : set_flickr_id
};
$.post(ajaxurl, data, function(resp) {
resp = JSON.parse(resp);
var desc = (resp.description) ? resp.description + '<br />' : '';
var date = new Date(resp.date_create * 1000);
$('.title', $tr).append('<div class="more-info">' + desc + 'Photos: ' + resp.photos + ' Date Created: ' + date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate() + '</div>');
$('.more', $tr).remove();
});
return false;
});
$('.select-controls a').click(function() {
$('input[type=checkbox]').attr('checked', $(this).hasClass('select-all'));
return false;
});
$('input.migrate-photos').click(function() {
var sets = new PhotoSets();
$('input.set-ids:checked').each(function() {
var $table_row = $(this).parents('tr').eq(0);
sets.addSet($table_row, $(this).val(), $(this).attr('rel'));
});
sets.migrateNextSet();
return false;
});
$('input.collection-ids').click(function() {
var id = $(this).val();
var checked = ($(this).attr('checked')) ? true : false;
$('input.collection-' + id).attr('checked', checked);
});
});
function PhotoSets() {
var self = this;
this.sets = new Array();
this.migrateNextSet = function() {
var set = self.sets.shift();
if (!set) return;
set.migrate();
};
this.addSet = function(table_row, flickr_id, collection_term_id) {
self.sets.push(new PhotoSet(this, table_row, flickr_id, collection_term_id));
};
}
function PhotoSet(sets, table_row, flickr_id, collection_term_id) {
var self = this;
this.sets = sets;
this.table_row = table_row;
this.flickr_id = flickr_id;
this.collection_term_id = collection_term_id;
this.wp_id = 0;
this.photos = new Array();
this.photo_count = 0;
this.photo_num = 0;
this.scrollToRow = function() {
$.scrollTo(self.table_row, { offset: { top: -20 } });
};
this.migrateNextPhoto = function() {
var photo = self.photos.shift();
if (!photo) {
var msg = 'Complete. Imported ' + self.photo_count + ' photos.';
if (!self.photo_count) {
msg += ' Looks like you may not have access to these photos. Maybe you need to upgrade to Flickr Pro?';
}
self.updateProgress(msg, 100);
return self.sets.migrateNextSet();
}
self.photo_num = self.photo_num + 1;
photo.migrate();
};
this.migrate = function() {
var data = {
action : 'migrate_set',
set_flickr_id : self.flickr_id,
collection_term_id : self.collection_term_id
};
$.post(ajaxurl, data, function(resp) {
if (!resp) return self.updateProgress('Error downloading set!');
resp = JSON.parse(resp);
self.wp_id = resp.set_wp_id;
self.photo_count = resp.photos.length;
for (i in resp.photos) {
var p = resp.photos[i];
self.photos.push(new Photo(self, p.flickr_id, p.url, p.isprimary));
}
self.scrollToRow();
self.migrateNextPhoto();
});
};
this.updateProgress = function(content, width, css_class) {
var $progress = $('.progress', self.table_row);
var $bar = $('.bar', $progress);
var $txt = $('.txt', $progress);
$txt.html(content);
$bar.css('width', width + '%');
if (css_class) $bar.addClass(css_class);
};
}
function Photo(set, flickr_id, url, isprimary) {
var self = this;
this.set = set;
this.flickr_id = flickr_id;
this.url = url;
this.isprimary = isprimary;
this.migrate = function() {
var percent = Math.floor((self.set.photo_num-1) / self.set.photo_count * 100);
self.set.updateProgress('Importing photo ' + self.set.photo_num + ' of ' + self.set.photo_count, percent);
var data = {
action : 'migrate_photo',
photo_flickr_id : self.flickr_id,
set_wp_id : self.set.wp_id,
photo_url : self.url,
isprimary : self.isprimary
};
$.post(ajaxurl, data, function(resp) {
$('.thumb', self.set.table_row).html(resp);
self.set.migrateNextPhoto();
});
};
}
})(jQuery);