source: trunk/admin/themes/default/template/derivatives_build.tpl @ 12865

Last change on this file since 12865 was 12865, checked in by rvelices, 12 years ago

feature 2548 multisize - added a page to build missing derivatives

  • browser driven, chained ws calls to retrieve urls, visual feedback of progress through slideshow
File size: 3.6 KB
Line 
1{html_head}{literal}
2<style type="text/css">
3TABLE {
4        font-size: larger;
5}
6</style>
7{/literal}{/html_head}
8
9<p>
10        <select id="types" name="types[]" multiple="multiple">
11        {foreach from=$derivatives item=type}
12        <option value="{$type}" selected="selected">{$type|@translate}</option>
13        {/foreach}
14        </select>
15        <input id="startLink" value="{'Start'|@translate}" onclick="start()" type="button">
16        <input id="pauseLink" value="{'Pause'|@translate}" onclick="pause()" type="button" disabled="disbled">
17        <input id="stopLink" value="{'Stop'|@translate}" onclick="stop()" type="button" disabled="disbled">
18</p>
19<hr/>
20<p>
21<table>
22        <tr>
23                <td>Errors</td>
24                <td id="errors">0</td>
25        </tr>
26        <tr>
27                <td>Loaded</td>
28                <td id="loaded">0</td>
29        </tr>
30        <tr>
31                <td>Remaining</td>
32                <td id="remaining">0</td>
33        </tr>
34</table>
35<div id="feedbackWrap" style="height:320px; min-height:320px;">
36<img id="feedbackImg">
37</div>
38</p>
39
40<div id="errorList">
41</div>
42
43{combine_script id='iloader' load='footer' path='themes/default/js/image.loader.js'}
44
45{footer_script require='jquery.effects.slide'}{literal}
46
47var loader = new ImageLoader( {onChanged: loaderChanged} )
48        , pending_next_page = null
49        , last_image_show_time = 0
50        , allDoneDfd, urlDfd;
51
52function start() {
53        allDoneDfd = jQuery.Deferred();
54        urlDfd = jQuery.Deferred();
55
56        allDoneDfd.always( function() {
57                        jQuery("#startLink").attr('disabled', false).css("opacity", 1);
58                        jQuery("#pauseLink,#stopLink").attr('disabled', true).css("opacity", 0.5);
59                } );
60
61        urlDfd.always( function() {
62                if (loader.remaining()==0)
63                        allDoneDfd.resolve();
64                } );
65
66        jQuery("#startLink").attr('disabled', true).css("opacity", 0.5);
67        jQuery("#pauseLink,#stopLink").attr('disabled', false).css("opacity", 1);
68
69        loader.pause(false);
70        updateStats();
71        getUrls();
72}
73
74function pause() {
75        loader.pause( !loader.pause() );
76}
77
78function stop() {
79        loader.clear();
80        urlDfd.resolve();
81}
82
83function getUrls(page_token) {
84        data = {max_urls: 500, types: []};
85        jQuery.each(jQuery("#types").serializeArray(), function(i, t) {
86                        data.types.push( t.value );
87                } );
88
89        if (page_token)
90                data['prev_page'] = page_token;
91        jQuery.post( '{/literal}{$ROOT_URL}{literal}ws.php?format=json&method=pwg.getMissingDerivatives',
92                data, wsData, "json").fail( wsError );
93}
94
95function wsData(data) {
96        if (!data.stat || data.stat != "ok") {
97                wsError();
98                return;
99        }
100        loader.add( data.result.urls );
101        if (data.result.next_page) {
102                if (loader.pause() || loader.remaining() > 100) {
103                        pending_next_page = data.result.next_page;
104                }
105                else {
106                        getUrls(data.result.next_page);
107                }
108        }
109}
110
111function wsError() {
112        urlDfd.reject();
113}
114
115function updateStats() {
116        jQuery("#loaded").text( loader.loaded );
117        jQuery("#errors").text( loader.errors );
118        jQuery("#remaining").text( loader.remaining() );
119}
120
121function loaderChanged(type, img) {
122        updateStats();
123        if (img) {
124                if (type==="load") {
125                        var now = jQuery.now();
126                        if (now - last_image_show_time > 3000) {
127                                last_image_show_time = now;
128                                var h=img.height, url=img.src;
129                                jQuery("#feedbackWrap").hide("slide", {direction:'down'}, function() {
130                                        last_image_show_time = jQuery.now();
131                                        if (h > 300 )
132                                                jQuery("#feedbackImg").attr("height", 300);
133                                        else
134                                                jQuery("#feedbackImg").removeAttr("height");
135                                        jQuery("#feedbackImg").attr("src", url);
136                                        jQuery("#feedbackWrap").show("slide", {direction:'up'} );
137                                        } );
138                        }
139                }
140                else {
141                        jQuery("#errorList").prepend( '<a href="'+img.src+'">'+img.src+'</a>' + "<br>");
142                }
143        }
144        if (pending_next_page && 100 > loader.remaining() )     {
145                getUrls(pending_next_page);
146                pending_next_page = null;
147        }
148        else if (loader.remaining() == 0 && (urlDfd.isResolved() || urlDfd.isRejected()))       {
149                allDoneDfd.resolve();
150        }
151}
152{/literal}{/footer_script}
Note: See TracBrowser for help on using the repository browser.