Ignore:
Timestamp:
Jun 4, 2013, 12:55:59 PM (11 years ago)
Author:
plg
Message:

manage quota (number of photos, disk usage)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/community/add_photos.tpl

    r22820 r23037  
    1212{footer_script}{literal}
    1313jQuery(document).ready(function(){
     14function sprintf() {
     15        var i = 0, a, f = arguments[i++], o = [], m, p, c, x, s = '';
     16        while (f) {
     17                if (m = /^[^\x25]+/.exec(f)) {
     18                        o.push(m[0]);
     19                }
     20                else if (m = /^\x25{2}/.exec(f)) {
     21                        o.push('%');
     22                }
     23                else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
     24                        if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) {
     25                                throw('Too few arguments.');
     26                        }
     27                        if (/[^s]/.test(m[7]) && (typeof(a) != 'number')) {
     28                                throw('Expecting number but found ' + typeof(a));
     29                        }
     30                        switch (m[7]) {
     31                                case 'b': a = a.toString(2); break;
     32                                case 'c': a = String.fromCharCode(a); break;
     33                                case 'd': a = parseInt(a); break;
     34                                case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
     35                                case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
     36                                case 'o': a = a.toString(8); break;
     37                                case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
     38                                case 'u': a = Math.abs(a); break;
     39                                case 'x': a = a.toString(16); break;
     40                                case 'X': a = a.toString(16).toUpperCase(); break;
     41                        }
     42                        a = (/[def]/.test(m[7]) && m[2] && a >= 0 ? '+'+ a : a);
     43                        c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
     44                        x = m[5] - String(a).length - s.length;
     45                        p = m[5] ? str_repeat(c, x) : '';
     46                        o.push(s + (m[4] ? a + p : p + a));
     47                }
     48                else {
     49                        throw('Huh ?!');
     50                }
     51                f = f.substring(m[0].length);
     52        }
     53        return o.join('');
     54}
     55
    1456  function checkUploadStart() {
    1557    var nbErrors = 0;
     
    167209{/literal}
    168210{if $upload_mode eq 'html'}
     211  {if isset($limit_nb_photos)}
     212  var limit_nb_photos = {$limit_nb_photos};
     213  {/if}
    169214{literal}
     215
    170216  function addUploadBox() {
    171217    var uploadBox = '<p class="file"><input type="file" size="60" name="image_upload[]"></p>';
    172218    jQuery(uploadBox).appendTo("#uploadBoxes");
     219
     220    if (typeof limit_nb_photos != 'undefined') {
     221      if (jQuery("input[name^=image_upload]").size() >= limit_nb_photos) {
     222        jQuery("#addUploadBox").hide();
     223      }
     224    }
    173225  }
    174226
     
    176228
    177229  jQuery("#addUploadBox A").click(function () {
     230    if (typeof limit_nb_photos != 'undefined') {
     231      if (jQuery("input[name^=image_upload]").size() >= limit_nb_photos) {
     232        alert('tu rigoles mon gaillard !');
     233        return false;
     234      }
     235    }
     236
    178237    addUploadBox();
    179238  });
     
    191250var buttonText = "{'Select files'|@translate}";
    192251var sizeLimit = Math.round({$upload_max_filesize} / 1024); /* in KBytes */
     252var sumQueueFilesize = 0;
     253  {if isset($limit_storage)}
     254var limit_storage = {$limit_storage};
     255  {/if}
    193256
    194257{literal}
     
    209272    'fileSizeLimit'  : sizeLimit,
    210273    'progressData'   : 'percentage',
     274{/literal}
     275  {if isset($limit_nb_photos)}
     276    'queueSizeLimit' : {$limit_nb_photos},
     277  {/if}
     278{literal}
    211279    requeueErrors   : false,
    212     'onSelect'       : function(event,ID,fileObj) {
     280    'onSelect'       : function(file) {
     281      console.log('filesize = '+file.size+'bytes');
     282
     283      if (typeof limit_storage != 'undefined') {
     284        if (sumQueueFilesize + file.size > limit_storage) {
     285          jQuery.jGrowl(
     286            '<p></p>'+sprintf(
     287              '{/literal}{'File %s too big (%uMB), quota of %uMB exceeded'|@translate}{literal}',
     288              file.name,
     289              Math.round(file.size/(1024*1024)),
     290              limit_storage/(1024*1024)
     291            ),
     292            {
     293              theme:  'error',
     294              header: 'ERROR',
     295              life:   4000,
     296              sticky: false
     297            }
     298          );
     299
     300          jQuery('#uploadify').uploadifyCancel(file.id);
     301          return false;
     302        }
     303        else {
     304          sumQueueFilesize += file.size;
     305        }
     306      }
     307
    213308      jQuery("#fileQueue").show();
     309    },
     310    'onCancel' : function(file) {
     311      console.log('The file ' + file.name + ' was cancelled ('+file.size+')');
    214312    },
    215313    'onQueueComplete'  : function(stats) {
     
    432530      <legend>{'Select files'|@translate}</legend>
    433531
    434     <p id="uploadWarningsSummary">{$upload_max_filesize_shorthand}B. {$upload_file_types}. {if isset($max_upload_resolution)}{$max_upload_resolution}Mpx{/if} <a class="showInfo" title="{'Learn more'|@translate}">i</a></p>
     532    <p id="uploadWarningsSummary">{$upload_max_filesize_shorthand}B. {$upload_file_types}. {if isset($max_upload_resolution)}{$max_upload_resolution}Mpx.{/if} {$quota_summary}
     533<a class="showInfo" title="{'Learn more'|@translate}">i</a></p>
    435534
    436535    <p id="uploadWarnings">
     
    440539{'Approximate maximum resolution: %dM pixels (that\'s %dx%d pixels).'|@translate|@sprintf:$max_upload_resolution:$max_upload_width:$max_upload_height}
    441540  {/if}
     541{$quota_details}
    442542    </p>
    443543
Note: See TracChangeset for help on using the changeset viewer.