Files @ e0626084e9c5
Branch filter:

Location: kallithea/kallithea/templates/base/default_perms_box.html

Thomas De Schampheleire
files: remove need for webhelpers.html.literal

The following code is unnecessarily complex:
h.literal(_('There are no files yet. %s') % add_new)

First of all, the '%s' part in the translatable string is a whole new
sentence, independent of the first. There is no reason it needs to be part
of the same translatable string.

Secondly, the only reason for h.literal is to preserve the link in
'add_new' (which contains the result of 'h.link_to'). But, h.link_to
actually already is a 'literal' object. The problem is that the special
'literal' property is lost due to the coercion into a plain string via the
'%' operator.

The following code would be a possible solution for the second issue:
h.HTML(_('There are no files yet. %s')) % add_new
i.e. make sure that the format string is not a plain string but itself a
literal object (after its contents being escaped), before applying the '%'
operator.

To handle the first issue, this would become:
h.HTML(_('There are no files yet.')) + ' ' + h.HTML(add_new)
but, here h.HTML is unnecessary on the first string because there is nothing
special about it, and equally unnecessary on the 'add_new' variable because
h.link_to already returns a literal object.

So, the final code becomes:
_('There are no files yet.') + ' ' + add_new
## snippet for displaying default permission box
## usage:
##    <%namespace name="dpb" file="/base/default_perms_box.html"/>
##    ${dpb.default_perms_box(<url_to_form>)}


<%def name="default_perms_box(form_url)">
${h.form(form_url)}
    <div class="form">
            <div class="form-group">
                <label class="control-label" for="inherit_default_permissions">${_('Inherit defaults')}:</label>
                <div>
                    ${h.checkbox('inherit_default_permissions',value=True)}
                    <span class="help-block">
                        ${h.literal(_('Select to inherit global settings, IP whitelist and permissions from the %s.')
                                    % h.link_to(_('default permissions'), url('admin_permissions')))}
                    </span>
                </div>
            </div>

            <div id="inherit_overlay">
            <div class="form-group">
                <label class="control-label" for="create_repo_perm">${_('Create repositories')}:</label>
                <div>
                    ${h.checkbox('create_repo_perm',value=True)}
                    <span class="help-block">
                        ${_('Select this option to allow repository creation for this user')}
                    </span>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label" for="create_user_group_perm">${_('Create user groups')}:</label>
                <div>
                    ${h.checkbox('create_user_group_perm',value=True)}
                    <span class="help-block">
                        ${_('Select this option to allow user group creation for this user')}
                    </span>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label" for="fork_repo_perm">${_('Fork repositories')}:</label>
                <div>
                    ${h.checkbox('fork_repo_perm',value=True)}
                    <span class="help-block">
                        ${_('Select this option to allow repository forking for this user')}
                    </span>
                </div>
            </div>

            </div>

            <div class="form-group">
                <div class="buttons">
                    ${h.submit('save',_('Save'),class_="btn btn-default")}
                    ${h.reset('reset',_('Reset'),class_="btn btn-default")}
                </div>
            </div>
    </div>
${h.end_form()}

## JS
<script>
$(document).ready(function(e){
    var show_custom_perms = function(inherit_default){
        if(inherit_default){
            $('#inherit_overlay').hide();
        }else{
            $('#inherit_overlay').show();
        }
    };

    show_custom_perms($('#inherit_default_permissions').prop('checked'));
    $('#inherit_default_permissions').change(function(){
        show_custom_perms($('#inherit_default_permissions').prop('checked'));
    });
});
</script>

</%def>