1 | {footer_script require='jquery.ajaxmanager,jquery.jgrowl'} |
---|
2 | /* global vars */ |
---|
3 | var errorHead = '{'ERROR'|@translate|@escape:'javascript'}'; |
---|
4 | var errorMsg = '{'an error happened'|@translate|@escape:'javascript'}'; |
---|
5 | var successHead = '{'Success'|@translate|@escape:'javascript'}'; |
---|
6 | |
---|
7 | var import_done = 0; |
---|
8 | var import_selected = {$nb_elements}; |
---|
9 | var queuedManager = jQuery.manageAjax.create('queued', {ldelim} |
---|
10 | queue: true, |
---|
11 | maxRequests: 1 |
---|
12 | }); |
---|
13 | |
---|
14 | {literal} |
---|
15 | /* import queue */ |
---|
16 | function performImport(photo, album, fills) { |
---|
17 | queuedManager.add({ |
---|
18 | type: 'GET', |
---|
19 | dataType: 'json', |
---|
20 | url: 'ws.php', |
---|
21 | data: { method: 'pwg.images.addFlickr', id: photo, category: album, fills: fills, format: 'json' }, |
---|
22 | success: function(data) { |
---|
23 | if (data['stat'] == 'ok') { |
---|
24 | jQuery.jGrowl(data['result'], { theme: 'success', header: successHead, life: 4000, sticky: false }); |
---|
25 | jQuery("#photo-"+photo.id).fadeOut(function(){ $(this).remove(); }); |
---|
26 | } else { |
---|
27 | jQuery.jGrowl(data['result'], { theme: 'error', header: errorHead, sticky: true }); |
---|
28 | } |
---|
29 | |
---|
30 | import_done++; |
---|
31 | $("#progress").html(import_done +"/"+ import_selected); |
---|
32 | |
---|
33 | if (import_done == import_selected) { |
---|
34 | $("#import_form").append('<input type="hidden" name="done" value="' + import_done + '">'); |
---|
35 | $("#import_form").submit(); |
---|
36 | } |
---|
37 | }, |
---|
38 | error: function(data) { |
---|
39 | jQuery.jGrowl(errorMsg, { theme: 'error', header: errorHead, sticky: true }); |
---|
40 | } |
---|
41 | }); |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | $(document).ready(function() { |
---|
46 | //var all_elements = jQuery.parseJSON('{/literal}{$all_elements}{literal}'); |
---|
47 | var all_elements = {/literal}{$all_elements}{literal}; |
---|
48 | |
---|
49 | /* begin import */ |
---|
50 | jQuery('#beginImport').click(function() { |
---|
51 | $("#loader_import").fadeIn(); |
---|
52 | |
---|
53 | if ($("input[name='album_mode']:checked").val() == 'identical') { |
---|
54 | var album = 0; |
---|
55 | } else { |
---|
56 | var album = $("#albumSelect option:selected").val(); |
---|
57 | } |
---|
58 | |
---|
59 | var fills = ''; |
---|
60 | $("input[name^='fill_']:checked").each(function() { |
---|
61 | fills+= $(this).attr("name") +','; |
---|
62 | }); |
---|
63 | |
---|
64 | import_selected = all_elements.length; |
---|
65 | $("#progress").html("0/"+ import_selected); |
---|
66 | |
---|
67 | for (var i in all_elements) { |
---|
68 | if (album == 0) this_album = all_elements[i]['albums']; |
---|
69 | else this_album = album; |
---|
70 | |
---|
71 | performImport(all_elements[i]['id'], this_album, fills); |
---|
72 | } |
---|
73 | |
---|
74 | return false; |
---|
75 | }); |
---|
76 | |
---|
77 | /* album mode */ |
---|
78 | $("input[name='album_mode']").change(function() { |
---|
79 | if ($(this).val() == 'one_album') { |
---|
80 | $("#albumSelectWrapper").slideDown(); |
---|
81 | } else { |
---|
82 | $("#albumSelectWrapper").slideUp(); |
---|
83 | } |
---|
84 | }); |
---|
85 | }); |
---|
86 | {/literal} |
---|
87 | {/footer_script} |
---|
88 | |
---|
89 | <form action="{$F_ACTION}" method="post" id="import_form"> |
---|
90 | |
---|
91 | <fieldset> |
---|
92 | <legend>{'Selection'|@translate}</legend> |
---|
93 | |
---|
94 | {if $nb_elements} |
---|
95 | {'%d elements ready for importation'|@translate|@sprintf:$nb_elements} |
---|
96 | {else} |
---|
97 | <div>{'No photo in the current set.'|@translate}</div> |
---|
98 | {/if} |
---|
99 | </fieldset> |
---|
100 | |
---|
101 | <fieldset> |
---|
102 | <legend>{'Import options'|@translate}</legend> |
---|
103 | |
---|
104 | <p> |
---|
105 | <label><input type="radio" name="album_mode" value="identical" checked="checked"> {'Reproduce flickr albums'|@translate}</label><br> |
---|
106 | <label><input type="radio" name="album_mode" value="one_album"> {'Import all photos in this album'|@translate} :</label> |
---|
107 | </p> |
---|
108 | |
---|
109 | <p id="albumSelectWrapper" style="display:none;"> |
---|
110 | <select style="width:400px" name="associate" id="albumSelect" size="1"> |
---|
111 | {html_options options=$category_parent_options} |
---|
112 | </select> |
---|
113 | {'... or '|@translate}<a href="#" class="addAlbumOpen" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a> |
---|
114 | </p> |
---|
115 | |
---|
116 | <p> |
---|
117 | <b>{'Fill these fields from Flickr datas'|@translate}:</b> |
---|
118 | <label><input type="checkbox" name="fill_name" checked="checked"> {'Photo name'|@translate}</label> |
---|
119 | <label><input type="checkbox" name="fill_author" checked="checked"> {'Author'|@translate}</label> |
---|
120 | <label><input type="checkbox" name="fill_tags" checked="checked"> {'Tags'|@translate}</label> |
---|
121 | <label><input type="checkbox" name="fill_taken" checked="checked"> {'Creation date'|@translate}</label> |
---|
122 | <label><input type="checkbox" name="fill_posted"> {'Post date'|@translate}</label> |
---|
123 | <label><input type="checkbox" name="fill_description" checked="checked"> {'Description'|@translate}</label> |
---|
124 | {if $GMAPS_LOADED}<label><input type="checkbox" name="fill_geotag" checked="checked"> {'Geolocalization'|@translate}</label>{/if} |
---|
125 | </p> |
---|
126 | |
---|
127 | <p> |
---|
128 | <input type="submit" name="import_set" id="beginImport" value="{'Begin transfer'|@translate}" {if not $nb_elements}style="display:none;"{/if}> |
---|
129 | <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|@translate}</i> <span id="progress"></span></span> |
---|
130 | </p> |
---|
131 | </fieldset> |
---|
132 | </form> |
---|