1 | {combine_script id='jquery.ajaxmanager' load='footer' path='themes/default/js/plugins/jquery.ajaxmanager.js'} |
---|
2 | {combine_script id='jquery.jgrowl' load='footer' path='themes/default/js/plugins/jquery.jgrowl_minimized.js'} |
---|
3 | {combine_css path="themes/default/js/plugins/jquery.jGrowl.css"} |
---|
4 | |
---|
5 | {combine_script id='MultiGetSet' load='header' path=$PBASE_PATH|cat:'admin/template/MultiGetSet.js'} |
---|
6 | |
---|
7 | {footer_script require='jquery.ajaxmanager,jquery.jgrowl'} |
---|
8 | (function($){ |
---|
9 | var errors_final_msg = '{'%1$d errors occured. %2$d albums and %3$d photos added.'|translate|escape:javascript}'; |
---|
10 | var final_manage_link = '{'Manage this set of %d photos'|translate}'; |
---|
11 | |
---|
12 | // custom class for counters listening |
---|
13 | var MyClass = function(){ |
---|
14 | var public = this; |
---|
15 | var private = {}; |
---|
16 | |
---|
17 | private.lenght = 0; |
---|
18 | private.errors = 0; |
---|
19 | private.categories = 0; |
---|
20 | private.pictures = 0; |
---|
21 | |
---|
22 | MultiGetSet({ |
---|
23 | public: public, |
---|
24 | private: private, |
---|
25 | handler: Observable |
---|
26 | }); |
---|
27 | }; |
---|
28 | |
---|
29 | var queue = new MyClass(); |
---|
30 | |
---|
31 | queue.listen("lenght", function(opt){ |
---|
32 | if (opt.newValue == 0) { |
---|
33 | $(".loading").css('display', 'none'); |
---|
34 | if (queue.get("errors") == 0) { |
---|
35 | $(".infos").css('display', 'block'); |
---|
36 | } |
---|
37 | else { |
---|
38 | errors_final_msg = errors_final_msg.replace('%1$d', queue.get("errors")); |
---|
39 | errors_final_msg = errors_final_msg.replace('%2$d', queue.get("categories")); |
---|
40 | errors_final_msg = errors_final_msg.replace('%3$d', queue.get("pictures")); |
---|
41 | final_manage_link = final_manage_link.replac('%d', queue.get("pictures")); |
---|
42 | |
---|
43 | $(".warnings").css('display', '').find('.i').html(errors_final_msg); |
---|
44 | $(".warnings").find('.a').html('<a href="{$MANAGE_LINK}">' + final_manage_link + '</a>'); |
---|
45 | } |
---|
46 | } |
---|
47 | }); |
---|
48 | queue.listen("categories", function(opt) { |
---|
49 | $(".nb_categories").html(opt.newValue); |
---|
50 | }); |
---|
51 | queue.listen("pictures", function(opt) { |
---|
52 | $(".nb_pictures").html(opt.newValue); |
---|
53 | }); |
---|
54 | queue.listen("errors", function(opt) { |
---|
55 | $(".nb_errors").html(opt.newValue); |
---|
56 | }); |
---|
57 | |
---|
58 | |
---|
59 | var queuedManager = $.manageAjax.create('queued', { |
---|
60 | queue: true, |
---|
61 | maxRequests: 1 |
---|
62 | }); |
---|
63 | |
---|
64 | function add_cat_to_add_queue(path, parent_id, recursive, fills) { |
---|
65 | queuedManager.add({ |
---|
66 | type: 'POST', |
---|
67 | dataType: 'json', |
---|
68 | url: 'ws.php?format=json', |
---|
69 | data: { |
---|
70 | method: 'pwg.pBase.addCat', |
---|
71 | path: path, |
---|
72 | parent_id: parent_id, |
---|
73 | recursive: recursive |
---|
74 | }, |
---|
75 | success: function(data) { |
---|
76 | if (data['stat'] == 'ok') { |
---|
77 | data = data['result']; |
---|
78 | |
---|
79 | for (i in data['pictures']) { |
---|
80 | queue.increment("lenght"); |
---|
81 | add_picture_to_add_queue(data['pictures'][i], data['category_id'], fills); |
---|
82 | } |
---|
83 | if (recursive) { |
---|
84 | for (i in data['categories']) { |
---|
85 | queue.increment("lenght"); |
---|
86 | add_cat_to_add_queue(data['categories'][i], data['category_id'], recursive, fills); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | $.jGrowl(data['message'], { |
---|
91 | theme: 'success', life: 4000, sticky: false, |
---|
92 | header: '{'Success'|translate}' |
---|
93 | }); |
---|
94 | queue.increment("categories"); |
---|
95 | } |
---|
96 | else { |
---|
97 | $.jGrowl(data['result'], { |
---|
98 | theme: 'error', sticky: true, |
---|
99 | header: '{'ERROR'|translate}' |
---|
100 | }); |
---|
101 | queue.increment("errors"); |
---|
102 | } |
---|
103 | |
---|
104 | queue.decrement("lenght"); |
---|
105 | }, |
---|
106 | error: function () { |
---|
107 | $.jGrowl('{'an error happened'|translate|escape:javascript}', { |
---|
108 | theme: 'error', sticky: true, |
---|
109 | header: '{'ERROR'|translate}' |
---|
110 | }); |
---|
111 | queue.increment("errors"); |
---|
112 | } |
---|
113 | }); |
---|
114 | } |
---|
115 | |
---|
116 | function add_picture_to_add_queue(url, cat_id, fills) { |
---|
117 | queuedManager.add({ |
---|
118 | type: 'POST', |
---|
119 | dataType: 'json', |
---|
120 | url: 'ws.php?format=json', |
---|
121 | data: { |
---|
122 | method: 'pwg.pBase.addImage', |
---|
123 | url: url, |
---|
124 | category: cat_id, |
---|
125 | fills: fills |
---|
126 | }, |
---|
127 | success: function(data) { |
---|
128 | if (data['stat'] == 'ok') { |
---|
129 | $.jGrowl(data['result'], { |
---|
130 | theme: 'success', life: 2000, sticky: false, |
---|
131 | header: '{'Success'|translate}' |
---|
132 | }); |
---|
133 | queue.increment("pictures"); |
---|
134 | } |
---|
135 | else { |
---|
136 | $.jGrowl(data['result'], { |
---|
137 | theme: 'error', sticky: true, |
---|
138 | header: '{'ERROR'|translate}' |
---|
139 | }); |
---|
140 | queue.increment("errors"); |
---|
141 | } |
---|
142 | |
---|
143 | queue.decrement("lenght"); |
---|
144 | }, |
---|
145 | error: function () { |
---|
146 | $.jGrowl('{'an error happened'|translate|escape:javascript}', { |
---|
147 | theme: 'error', sticky: true, |
---|
148 | header: '{'ERROR'|translate}' |
---|
149 | }); |
---|
150 | queue.increment("errors"); |
---|
151 | } |
---|
152 | }); |
---|
153 | } |
---|
154 | |
---|
155 | {foreach from=$categories item=cat} |
---|
156 | add_cat_to_add_queue('{$cat}', {$PARENT_CATEGORY}, {$RECURSIVE}, '{$FILLS}'); |
---|
157 | {/foreach} |
---|
158 | |
---|
159 | queue.set("lenght", {$categories|@count}); |
---|
160 | }(jQuery)); |
---|
161 | {/footer_script} |
---|
162 | |
---|
163 | |
---|
164 | <div class="infos" style="display:none;"> |
---|
165 | <ul> |
---|
166 | <li>{'Completed. %1$d albums and %2$d photos added.'|translate:$nb_categories:$nb_pictures}</li> |
---|
167 | <li><a href="{$MANAGE_LINK}">{'Manage this set of %d photos'|translate:$nb_pictures}</a></li> |
---|
168 | </ul> |
---|
169 | </div> |
---|
170 | <div class="warnings" style="display:none;"> |
---|
171 | <ul> |
---|
172 | <li class="i"></li> |
---|
173 | <li class="a"></li> |
---|
174 | </ul> |
---|
175 | </div> |
---|
176 | |
---|
177 | <p> |
---|
178 | <b>{'Nb albums'|translate}</b>: <span class="nb_categories">0</span>/{$nb_categories}<br> |
---|
179 | <b>{'Nb photos'|translate}</b>: <span class="nb_pictures">0</span>/{$nb_pictures}<br> |
---|
180 | <b>{'Errors'|translate}</b>: <span class="nb_errors">0</span><br> |
---|
181 | <br> |
---|
182 | <img class="loading" src="{$PBASE_PATH}admin/template/loader-{$themeconf.name}.gif"> |
---|
183 | </p> |
---|