source: extensions/community/admin_permissions.tpl @ 23037

Last change on this file since 23037 was 23037, checked in by plg, 11 years ago

manage quota (number of photos, disk usage)

File size: 10.5 KB
Line 
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
4{literal}
5<style>
6form fieldset p {text-align:left;margin:0 0 1.5em 0;line-height:20px;}
7.permissionActions {text-align:center;height:20px}
8.permissionActions a:hover {border:none}
9.permissionActions img {margin-bottom:-2px}
10.rowSelected {background-color:#C2F5C2 !important}
11#community_nb_photos, #community_storage {width:400px; display:inline-block; margin-right:10px;}
12</style>
13{/literal}
14
15{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
58$(document).ready(function() {
59  $("select[name=who]").change(function () {
60    $("[name^=who_]").hide();
61    $("[name=who_"+$(this).attr("value")+"]").show();
62  });
63
64  function checkWhereOptions() {
65    var recursive = $("input[name=recursive]");
66    var create = $("input[name=create_subcategories]");
67
68    if ($("select[name=category] option:selected").val() == 0) {
69      $(recursive).attr("disabled", true);
70      $(recursive).attr('checked', true);
71    }
72    else {
73      $(recursive).removeAttr("disabled");
74    }
75
76    if (!$(recursive).is(':checked')) {
77      $(create).attr('checked', false);
78      $(create).attr("disabled", true);
79    }
80    else {
81      $(create).removeAttr("disabled");
82    }
83  }
84
85  checkWhereOptions();
86
87  $("select[name=category]").change(function() {
88    checkWhereOptions();
89  });
90
91  $("input[name=recursive]").change(function() {
92    checkWhereOptions();
93  });
94
95  $("#displayForm").click(function() {
96    $("[name=add_permission]").show();
97    $(this).hide();
98    return false;
99  });
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
176});
177{/literal}{/footer_script}
178
179
180<div class="titrePage">
181  <h2>{'Upload Permissions'|@translate} - {'Community'|@translate}</h2>
182</div>
183
184{if not isset($edit)}
185<a id="displayForm" href="#">{'Add a permission'|@translate}</a>
186{/if}
187
188<form method="post" name="add_permission" action="{$F_ADD_ACTION}" class="properties" {if not isset($edit)}style="display:none"{/if}>
189  <fieldset>
190    <legend>{if isset($edit)}{'Edit a permission'|@translate}{else}{'Add a permission'|@translate}{/if}</legend>
191
192    <p>
193      <strong>{'Who?'|@translate}</strong>
194      <br>
195      <select name="who">
196{html_options options=$who_options selected=$who_options_selected}
197      </select>
198
199      <select name="who_user" {if not isset($user_options_selected)}style="display:none"{/if}>
200{html_options options=$user_options selected=$user_options_selected}
201      </select>
202
203      <select name="who_group" {if not isset($group_options_selected)}style="display:none"{/if}>
204{html_options options=$group_options selected=$group_options_selected}
205      </select>
206    </p>
207
208    <p>
209      <strong>{'Where?'|@translate}</strong>
210      <br>
211      <select class="categoryDropDown" name="category">
212        <option value="0" {if not isset($category_options_selected)}selected="selected"{/if}>{'The whole gallery'|@translate}</option>
213        <option disabled="disabled">------------</option>
214        {html_options options=$category_options selected=$category_options_selected}
215      </select>
216      <br>
217      <label><input type="checkbox" name="recursive" {if $recursive}checked="checked"{/if}> {'Apply to sub-albums'|@translate}</label>
218      <br>
219      <label><input type="checkbox" name="create_subcategories" {if $create_subcategories}checked="checked"{/if}> {'ability to create sub-albums'|@translate}</label>
220    </p>
221
222    <p>
223      <strong>{'Which level of trust?'|@translate}</strong>
224      <br><label><input type="radio" name="moderated" value="true" {if $moderated}checked="checked"{/if}> <em>{'low trust'|@translate}</em> : {'uploaded photos must be validated by an administrator'|@translate}</label>
225      <br><label><input type="radio" name="moderated" value="false" {if not $moderated}checked="checked"{/if}> <em>{'high trust'|@translate}</em> : {'uploaded photos are directly displayed in the gallery'|@translate}</label>
226    </p>
227
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
242    {if isset($edit)}
243      <input type="hidden" name="edit" value="{$edit}">
244    {/if}
245   
246    <p style="margin-top:1.5em;">
247      <input class="submit" type="submit" name="submit_add" value="{if isset($edit)}{'Submit'|@translate}{else}{'Add'|@translate}{/if}"/>
248      <a href="{$F_ADD_ACTION}">{'Cancel'|@translate}</a>
249    </p>
250  </fieldset>
251</form>
252
253<table class="table2" style="margin:15px auto;">
254  <tr class="throw">
255    <th>{'Who?'|@translate}</th>
256    <th>{'Where?'|@translate}</th>
257    <th>{'Options'|@translate}</th>
258    <th>{'Actions'|@translate}</th>
259  </tr>
260{if not empty($permissions)}
261  {foreach from=$permissions item=permission name=permission_loop}
262  <tr class="{if $smarty.foreach.permission_loop.index is odd}row1{else}row2{/if}{if $permission.HIGHLIGHT} rowSelected{/if}">
263    <td>{$permission.WHO}</td>
264    <td>{$permission.WHERE}</td>
265    <td>
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}
270    {if $permission.CREATE_SUBCATEGORIES}
271, {'sub-albums creation'|@translate}
272    {/if}
273    </td>
274    <td class="permissionActions">
275      <a href="{$permission.U_EDIT}">
276        <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/edit_s.png" alt="{'edit'|@translate}" title="{'edit'|@translate}" />
277      </a>
278      <a href="{$permission.U_DELETE}" onclick="return confirm( document.getElementById('btn_delete').title + '\n\n' + '{'Are you sure?'|@translate|@escape:'javascript'}');">
279        <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/delete.png" id="btn_delete" alt="{'delete'|@translate}" title="{'Delete permission'|@translate}" />
280      </a>
281    </td>
282  </tr>
283  {/foreach}
284{/if}
285</table>
Note: See TracBrowser for help on using the repository browser.