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/admin_permissions.tpl

    r9807 r23037  
     1{combine_script id='jquery.ui.slider' require='jquery.ui' load='footer' path='themes/default/js/ui/minified/jquery.ui.slider.min.js'}
     2{combine_css path="themes/default/js/ui/theme/jquery.ui.slider.css"}
     3
    14{literal}
    25<style>
     
    69.permissionActions img {margin-bottom:-2px}
    710.rowSelected {background-color:#C2F5C2 !important}
     11#community_nb_photos, #community_storage {width:400px; display:inline-block; margin-right:10px;}
    812</style>
    913{/literal}
    1014
    1115{footer_script}{literal}
     16function sprintf() {
     17        var i = 0, a, f = arguments[i++], o = [], m, p, c, x, s = '';
     18        while (f) {
     19                if (m = /^[^\x25]+/.exec(f)) {
     20                        o.push(m[0]);
     21                }
     22                else if (m = /^\x25{2}/.exec(f)) {
     23                        o.push('%');
     24                }
     25                else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
     26                        if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) {
     27                                throw('Too few arguments.');
     28                        }
     29                        if (/[^s]/.test(m[7]) && (typeof(a) != 'number')) {
     30                                throw('Expecting number but found ' + typeof(a));
     31                        }
     32                        switch (m[7]) {
     33                                case 'b': a = a.toString(2); break;
     34                                case 'c': a = String.fromCharCode(a); break;
     35                                case 'd': a = parseInt(a); break;
     36                                case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
     37                                case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
     38                                case 'o': a = a.toString(8); break;
     39                                case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
     40                                case 'u': a = Math.abs(a); break;
     41                                case 'x': a = a.toString(16); break;
     42                                case 'X': a = a.toString(16).toUpperCase(); break;
     43                        }
     44                        a = (/[def]/.test(m[7]) && m[2] && a >= 0 ? '+'+ a : a);
     45                        c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
     46                        x = m[5] - String(a).length - s.length;
     47                        p = m[5] ? str_repeat(c, x) : '';
     48                        o.push(s + (m[4] ? a + p : p + a));
     49                }
     50                else {
     51                        throw('Huh ?!');
     52                }
     53                f = f.substring(m[0].length);
     54        }
     55        return o.join('');
     56}
     57
    1258$(document).ready(function() {
    1359  $("select[name=who]").change(function () {
     
    5298    return false;
    5399  });
     100
     101  /* ∞ */
     102  /**
     103   * find the key from a value in the startStopValues array
     104   */
     105  function getSliderKeyFromValue(value, values) {
     106    for (var key in values) {
     107      if (values[key] == value) {
     108        return key;
     109      }
     110    }
     111    return 0;
     112  }
     113
     114  var nbPhotosValues = [5,10,20,50,100,500,1000,5000,-1];
     115
     116  function getNbPhotosInfoFromIdx(idx) {
     117    if (idx == nbPhotosValues.length - 1) {
     118      return "{/literal}{'no limit'|@translate}{literal}";
     119    }
     120
     121    return sprintf(
     122      "{/literal}{'up to %d photos (for each user)'|@translate}{literal}",
     123      nbPhotosValues[idx]
     124    );
     125  }
     126
     127  /* init nb_photos info span */
     128  var nbPhotos_init = getSliderKeyFromValue(jQuery('input[name=nb_photos]').val(), nbPhotosValues);
     129
     130  jQuery("#community_nb_photos_info").html(getNbPhotosInfoFromIdx(nbPhotos_init));
     131
     132  jQuery("#community_nb_photos").slider({
     133    range: "min",
     134    min: 0,
     135    max: nbPhotosValues.length - 1,
     136    value: nbPhotos_init,
     137    slide: function( event, ui ) {
     138      jQuery("#community_nb_photos_info").html(getNbPhotosInfoFromIdx(ui.value));
     139    },
     140    stop: function( event, ui ) {
     141      jQuery("input[name=nb_photos]").val(nbPhotosValues[ui.value]);
     142    }
     143  });
     144
     145  var storageValues = [10,50,100,200,500,1000,5000,-1];
     146
     147  function getStorageInfoFromIdx(idx) {
     148    if (idx == storageValues.length - 1) {
     149      return "{/literal}{'no limit'|@translate}{literal}";
     150    }
     151
     152    return sprintf(
     153      "{/literal}{'up to %dMB (for each user)'|@translate}{literal}",
     154      storageValues[idx]
     155    );
     156  }
     157
     158  /* init storage info span */
     159  var storage_init = getSliderKeyFromValue(jQuery('input[name=storage]').val(), storageValues);
     160
     161  jQuery("#community_storage_info").html(getStorageInfoFromIdx(storage_init));
     162
     163  jQuery("#community_storage").slider({
     164    range: "min",
     165    min: 0,
     166    max: storageValues.length - 1,
     167    value: storage_init,
     168    slide: function( event, ui ) {
     169      jQuery("#community_storage_info").html(getStorageInfoFromIdx(ui.value));
     170    },
     171    stop: function( event, ui ) {
     172      jQuery("input[name=storage]").val(storageValues[ui.value]);
     173    }
     174  });
     175
    54176});
    55177{/literal}{/footer_script}
     
    104226    </p>
    105227
     228    <p style="margin-bottom:0">
     229      <strong>{'How many photos?'|@translate}</strong>
     230    </p>
     231    <div id="community_nb_photos"></div>
     232    <span id="community_nb_photos_info">{'no limit'|@translate}</span>
     233    <input type="hidden" name="nb_photos" value="{$nb_photos}">
     234
     235    <p style="margin-top:1.5em;margin-bottom:0;">
     236      <strong>{'How much disk space?'|@translate}</strong>
     237    </p>
     238    <div id="community_storage"></div>
     239    <span id="community_storage_info">{'no limit'|@translate}</span>
     240    <input type="hidden" name="storage" value="{$storage}">
     241
    106242    {if isset($edit)}
    107243      <input type="hidden" name="edit" value="{$edit}">
    108244    {/if}
    109245   
    110     <p style="margin:0;">
     246    <p style="margin-top:1.5em;">
    111247      <input class="submit" type="submit" name="submit_add" value="{if isset($edit)}{'Submit'|@translate}{else}{'Add'|@translate}{/if}"/>
    112248      <a href="{$F_ADD_ACTION}">{'Cancel'|@translate}</a>
     
    128264    <td>{$permission.WHERE}</td>
    129265    <td>
    130       <span title="{$permission.TRUST_TOOLTIP}">{$permission.TRUST}</span>
    131     {if $permission.RECURSIVE}
    132 , <span title="{$permission.RECURSIVE_TOOLTIP}">{'sub-albums'|@translate}</span>
    133     {/if}
     266      <span title="{$permission.TRUST_TOOLTIP}">{$permission.TRUST}</span>{if $permission.RECURSIVE},
     267<span title="{$permission.RECURSIVE_TOOLTIP}">{'sub-albums'|@translate}</span>{/if}{if $permission.NB_PHOTOS},
     268<span title="{$permission.NB_PHOTOS_TOOLTIP}">{'%d photos'|@translate|sprintf:$permission.NB_PHOTOS}</span>{/if}{if $permission.STORAGE},
     269<span title="{$permission.STORAGE_TOOLTIP}">{$permission.STORAGE}MB</span>{/if}
    134270    {if $permission.CREATE_SUBCATEGORIES}
    135271, {'sub-albums creation'|@translate}
Note: See TracChangeset for help on using the changeset viewer.