1 | {combine_css path=$USER_COLLEC_PATH|cat:'template/style_thumbnails.css'} |
---|
2 | |
---|
3 | {* <!-- all pages but collection edit page --> *} |
---|
4 | {if not $UC_IN_EDIT} |
---|
5 | {footer_script require='jquery'} |
---|
6 | var $cdm = jQuery("#collectionsDropdown"); |
---|
7 | |
---|
8 | {if not $IN_PICTURE} |
---|
9 | $cdm.on("mouseleave", function() {ldelim} |
---|
10 | $cdm.hide(); |
---|
11 | }); |
---|
12 | {/if} |
---|
13 | |
---|
14 | // click on "create collection" button |
---|
15 | $cdm.find("a.new").on("click", function(event) {ldelim} |
---|
16 | jQuery(this).hide().next().show().focus(); |
---|
17 | event.stopPropagation(); |
---|
18 | return false; |
---|
19 | }); |
---|
20 | |
---|
21 | // events on "new collection" input |
---|
22 | $cdm.find("input.new").on({ldelim} |
---|
23 | // ENTER or ESC pressed |
---|
24 | "keyup": function(event) {ldelim} |
---|
25 | if (event.which == 27) { |
---|
26 | jQuery(this).val('').hide().prev().show(); |
---|
27 | return; |
---|
28 | } |
---|
29 | |
---|
30 | if (event.which != 13) return; |
---|
31 | |
---|
32 | jQuery(this).hide().prev().show(); |
---|
33 | var name = jQuery(this).val(); |
---|
34 | jQuery(this).val(''); |
---|
35 | |
---|
36 | if (name == "" || name == null) return; |
---|
37 | |
---|
38 | jQuery.ajax({ldelim} |
---|
39 | type: "GET", |
---|
40 | dataType: "json", |
---|
41 | url: "{$ROOT_URL}ws.php", |
---|
42 | data: {ldelim} |
---|
43 | format: "json", |
---|
44 | method: "pwg.collections.create", |
---|
45 | name: name, |
---|
46 | }, |
---|
47 | success: function(data) {ldelim} |
---|
48 | if (data.stat == 'ok') {ldelim} |
---|
49 | var col = data.result; |
---|
50 | var html = '<span>★</span> <a class="add" data-id="'+ col.id +'">'+ col.name +'</a> ' |
---|
51 | +'<span class="menuInfoCat">[<span class="nbImagesCollec-'+ col.id +'">'+ col.nb_images +'</span>]</span> ' |
---|
52 | +'<a class="remove" data-id="'+ col.id +'">{'(remove)'|@translate}</a>' |
---|
53 | +'<br>'; |
---|
54 | |
---|
55 | $cdm.children(".switchBoxFooter").before(html); |
---|
56 | $cdm.children(".noCollecMsg").remove(); |
---|
57 | } |
---|
58 | else {ldelim} |
---|
59 | alert(data.message); |
---|
60 | } |
---|
61 | }, |
---|
62 | error: function() {ldelim} |
---|
63 | alert("{'An unknown error occured'|@translate}"); |
---|
64 | } |
---|
65 | }); |
---|
66 | |
---|
67 | return false; |
---|
68 | }, |
---|
69 | // prevent click propagation |
---|
70 | "click": function(event) {ldelim} |
---|
71 | event.stopPropagation(); |
---|
72 | } |
---|
73 | }); |
---|
74 | |
---|
75 | // add and remove links (delegate for new collections) |
---|
76 | $cdm.on("click", ".add, .remove", function() {ldelim} |
---|
77 | var img_id = $cdm.data("img_id"); |
---|
78 | var col_id = jQuery(this).data("id"); |
---|
79 | var method = jQuery(this).hasClass("add") ? "pwg.collections.addImages" : "pwg.collections.removeImages"; |
---|
80 | |
---|
81 | jQuery.ajax({ldelim} |
---|
82 | type: "GET", |
---|
83 | dataType: "json", |
---|
84 | url: "{$ROOT_URL}ws.php", |
---|
85 | data: {ldelim} |
---|
86 | format: "json", |
---|
87 | method: method, |
---|
88 | col_id: col_id, |
---|
89 | image_ids: img_id |
---|
90 | }, |
---|
91 | success: function(data) {ldelim} |
---|
92 | if (data.stat == 'ok') {ldelim} |
---|
93 | // update col counters |
---|
94 | jQuery(".nbImagesCollec-"+col_id).html(data.result.nb_images); |
---|
95 | |
---|
96 | // update item datas |
---|
97 | var $target = jQuery(".addCollection[data-id='"+ img_id +"']"); |
---|
98 | var col_ids = $target.data("cols"); |
---|
99 | if (method == "pwg.collections.addImages" && col_ids.indexOf(col_id) == -1) |
---|
100 | col_ids[ col_ids.length ] = col_id; |
---|
101 | else if (method == "pwg.collections.removeImages") |
---|
102 | col_ids.splice(col_ids.indexOf(col_id), 1); |
---|
103 | $target.data("col", col_ids); |
---|
104 | } |
---|
105 | else {ldelim} |
---|
106 | alert(data.message); |
---|
107 | } |
---|
108 | }, |
---|
109 | error: function() {ldelim} |
---|
110 | alert("{'An unknown error occured'|@translate}"); |
---|
111 | } |
---|
112 | }); |
---|
113 | |
---|
114 | $cdm.hide(); |
---|
115 | return false; |
---|
116 | }); |
---|
117 | |
---|
118 | // main button, open the menu |
---|
119 | jQuery(".addCollection").on("click", function(event) {ldelim} |
---|
120 | var img_id = jQuery(this).data("id"); |
---|
121 | var col_ids = jQuery(this).data("cols"); |
---|
122 | |
---|
123 | $cdm.data("img_id", img_id); |
---|
124 | |
---|
125 | $cdm.children(".add").each(function() {ldelim} |
---|
126 | if (col_ids.indexOf($(this).data("id")) != -1) {ldelim} |
---|
127 | $(this).css("font-weight", "bold").next().next().show(); |
---|
128 | } |
---|
129 | else {ldelim} |
---|
130 | $(this).css("font-weight", "normal").next().next().hide(); |
---|
131 | } |
---|
132 | }); |
---|
133 | |
---|
134 | {if not $IN_PICTURE} |
---|
135 | $cdm.css({ldelim} |
---|
136 | "top": event.pageY-5-$(window).scrollTop(), |
---|
137 | "left": Math.min(event.pageX-jQuery(window).scrollLeft()-20, jQuery(window).width()-$cdm.outerWidth(true)-5) |
---|
138 | }); |
---|
139 | $cdm.show(); |
---|
140 | {/if} |
---|
141 | |
---|
142 | return false; |
---|
143 | }); |
---|
144 | |
---|
145 | // try to respect theme colors |
---|
146 | $cdm.children(".switchBoxFooter").css("border-top-color", $cdm.children(".switchBoxTitle").css("border-bottom-color")); |
---|
147 | {/footer_script} |
---|
148 | |
---|
149 | <div id="collectionsDropdown" class="switchBox"> |
---|
150 | <div class="switchBoxTitle">{'Collections'|@translate}</div> |
---|
151 | |
---|
152 | {foreach from=$COLLECTIONS item=col} |
---|
153 | <span>★</span> <a class="add" data-id="{$col.id}">{$col.name}</a> |
---|
154 | <span class="menuInfoCat">[<span class="nbImagesCollec-{$col.id}">{$col.nb_images}</span>]</span> |
---|
155 | <a class="remove" data-id="{$col.id}">{'(remove)'|@translate}</a> |
---|
156 | <br> |
---|
157 | {foreachelse} |
---|
158 | <span class="noCollecMsg">{'You have no collection'|@translate}</span> |
---|
159 | {/foreach} |
---|
160 | |
---|
161 | <div class="switchBoxFooter"> |
---|
162 | <span>✚</span> <a class="new">{'Create a new collection'|@translate}</a> |
---|
163 | <input class="new" placeholder="{'Name'|@translate}" size="25"/> |
---|
164 | </div> |
---|
165 | </div> |
---|
166 | |
---|
167 | {* <!-- collection edit page --> *} |
---|
168 | {else} |
---|
169 | {footer_script require='jquery'} |
---|
170 | jQuery(".addCollection").on("click", function(event) {ldelim} |
---|
171 | var $trigger = jQuery(this); |
---|
172 | var img_id = jQuery(this).data("id"); |
---|
173 | var col_id = {$collection.ID}; |
---|
174 | |
---|
175 | jQuery.ajax({ldelim} |
---|
176 | type: "GET", |
---|
177 | dataType: "json", |
---|
178 | url: "{$ROOT_URL}ws.php", |
---|
179 | data: {ldelim} |
---|
180 | format: "json", |
---|
181 | method: "pwg.collections.removeImages", |
---|
182 | col_id: col_id, |
---|
183 | image_ids: img_id |
---|
184 | }, |
---|
185 | success: function(data) {ldelim} |
---|
186 | if (data.stat == 'ok') {ldelim} |
---|
187 | $trigger.parent("li").hide("fast", function() {ldelim} |
---|
188 | jQuery(this).remove(); |
---|
189 | if (typeof GThumb != "undefined") GThumb.build(); |
---|
190 | }); |
---|
191 | |
---|
192 | jQuery(".nbImagesCollec-"+col_id).html(data.result.nb_images); |
---|
193 | if (typeof batchdown_count != 'undefined') batchdown_count = data.result.nb_images; |
---|
194 | } |
---|
195 | else {ldelim} |
---|
196 | alert(data.message); |
---|
197 | } |
---|
198 | }, |
---|
199 | error: function() {ldelim} |
---|
200 | alert("{'An unknown error occured'|@translate}"); |
---|
201 | } |
---|
202 | }); |
---|
203 | |
---|
204 | event.stopPropagation(); |
---|
205 | event.preventDefault(); |
---|
206 | return false; |
---|
207 | }); |
---|
208 | {/footer_script} |
---|
209 | {/if} |
---|