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