forked from plegall/Piwigo-community
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_photos.js
192 lines (168 loc) · 4.95 KB
/
edit_photos.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* based on core batchManagerGlobal.js, but simplified */
/* ********** Thumbs */
/* Shift-click: select all photos between the click and the shift+click */
jQuery(document).ready(function() {
var last_clicked=0,
last_clickedstatus=true;
jQuery.fn.enableShiftClick = function() {
var inputs = [],
count=0;
this.find('input[type=checkbox]').each(function() {
var pos=count;
inputs[count++]=this;
$(this).bind("shclick", function (dummy,event) {
if (event.shiftKey) {
var first = last_clicked;
var last = pos;
if (first > last) {
first=pos;
last=last_clicked;
}
for (var i=first; i<=last;i++) {
input = $(inputs[i]);
$(input).prop('checked', last_clickedstatus).trigger("change");
if (last_clickedstatus)
{
$(input).closest("li").addClass("thumbSelected");
}
else
{
$(input).closest("li").removeClass("thumbSelected");
}
}
}
else {
last_clicked = pos;
last_clickedstatus = this.checked;
}
return true;
});
$(this).click(function(event) { $(this).triggerHandler("shclick",event)});
});
}
$('ul.thumbnails').enableShiftClick();
});
jQuery("a.preview-box").colorbox( {photo: true} );
/*
jQuery('.thumbnails img').tipTip({
'delay' : 0,
'fadeIn' : 200,
'fadeOut' : 200
});
*/
/* ********** Actions*/
function progress(success) {
jQuery('#progressBar').progressBar(derivatives.done, {
max: derivatives.total,
textFormat: 'fraction',
boxImage: 'themes/default/images/progressbar.gif',
barImage: 'themes/default/images/progressbg_orange.gif'
});
if (success !== undefined) {
var type = success ? 'regenerateSuccess': 'regenerateError',
s = jQuery('[name="'+type+'"]').val();
jQuery('[name="'+type+'"]').val(++s);
}
if (derivatives.finished()) {
jQuery('#applyAction').click();
}
}
/* sync metadatas or delete photos by blocks, with progress bar */
jQuery('#applyAction').click(function(e) {
if (typeof(elements) != "undefined") {
return true;
}
if (jQuery('[name="selectAction"]').val() == 'delete') {
if (!jQuery("#action_delete input[name=confirm_deletion]").is(':checked')) {
jQuery("#action_delete span.errors").show();
return false;
}
e.stopPropagation();
}
else {
return true;
}
jQuery('.bulkAction').hide();
jQuery('#regenerationText').html(lang.deleteProgressMessage);
var maxRequests=1;
var queuedManager = jQuery.manageAjax.create('queued', {
queue: true,
cacheResponse: false,
maxRequests: maxRequests
});
elements = Array();
if (jQuery('input[name=setSelected]').is(':checked')) {
elements = all_elements;
}
else {
jQuery('input[name="selection[]"]').filter(':checked').each(function() {
elements.push(jQuery(this).val());
});
}
progressBar_max = elements.length;
var todo = 0;
var deleteBlockSize = Math.min(
Number((elements.length/2).toFixed()),
1000
);
var image_ids = Array();
jQuery('#applyActionBlock').hide();
jQuery('select[name="selectAction"]').hide();
jQuery('#regenerationMsg').show();
jQuery('#progressBar').progressBar(0, {
max: progressBar_max,
textFormat: 'fraction',
boxImage: 'themes/default/images/progressbar.gif',
barImage: 'themes/default/images/progressbg_orange.gif'
});
for (i=0;i<elements.length;i++) {
image_ids.push(elements[i]);
if (i % deleteBlockSize != deleteBlockSize - 1 && i != elements.length - 1) {
continue;
}
(function(ids) {
var thisBatchSize = ids.length;
queuedManager.add({
type: 'POST',
url: 'ws.php?format=json',
data: {
method: "pwg.images.delete",
pwg_token: jQuery("input[name=pwg_token]").val(),
image_id: ids.join(',')
},
dataType: 'json',
success: function(data) {
todo += thisBatchSize;
var isOk = data.stat && "ok" == data.stat;
if (isOk && data.result != thisBatchSize)
/*TODO: user feedback only data.result images out of thisBatchSize were deleted*/;
/*TODO: user feedback if isError*/
progressionBar(todo, progressBar_max, isOk);
},
error: function(data) {
todo += thisBatchSize;
/*TODO: user feedback*/
progressionBar(todo, progressBar_max, false);
}
});
} )(image_ids);
image_ids = Array();
}
/* tell PHP how many photos were deleted */
jQuery('form').append('<input type="hidden" name="nb_photos_deleted" value="'+elements.length+'">');
return false;
});
function progressionBar(val, max, success) {
jQuery('#progressBar').progressBar(val, {
max: max,
textFormat: 'fraction',
boxImage: 'themes/default/images/progressbar.gif',
barImage: 'themes/default/images/progressbg_orange.gif'
});
if (val == max) {
jQuery('#applyAction').click();
}
}
jQuery("#action_delete input[name=confirm_deletion]").change(function() {
jQuery("#action_delete span.errors").hide();
});