Code

Ticket #15632: base_site.html

File base_site.html, 8.1 KB (added by andrew@…, 3 years ago)
Line 
1{% extends "admin/base.html" %}
2
3{% comment %}
4
5
6    This file contains a handful of unrelated admin customizations that
7    mostly get applied globally to different parts of the admin.
8
9    In the ``extrahead`` block:
10
11      * CSS for the login form
12      * Javascript for the login form to add the ``interface`` radio buttons
13      * Global CSS fixes (when logged in)
14      * Javascript for injecting Mezzanine's menu into the top of every page
15      * Javascript for fixing inlines to work with Mezzanine's dynamic inlines
16
17    In the ``footer`` block:
18
19      * HTML for the ``interface`` radio buttons in the login form
20      * HTML for Mezzanine's menu
21
22
23{% endcomment %}
24
25{% load mezzanine_tags i18n %}
26
27{% block title %}{{ title }} | Mezzanine{% endblock %}
28{% block branding %}<h1 id="site-name">Mezzanine</h1>{% endblock %}
29{% block nav-global %}{% endblock %}
30
31{% block extrahead %}
32<script type="text/javascript">
33
34if (typeof $ == 'undefined') {
35    document.write('<scr' + 
36        'ipt src="{{ settings.CONTENT_MEDIA_URL }}js/jquery-1.4.4.min.js"></scr' + 
37        'ipt>');
38}
39
40$.ajaxSetup({
41    beforeSend: function(xhr, settings) {
42        xhr.setRequestHeader('X-CSRFToken', '{{ csrf_token }}');
43    }
44});
45
46window.__admin_keywords_submit_url = '{% try_url "admin_keywords_submit" %}';
47window.__grappelli_installed = {{ settings.GRAPPELLI_INSTALLED|lower }};
48
49</script>
50
51{% if not request.user.is_authenticated %}
52<style type="text/css">
53    #extra-login-fields .required {margin-top:1px;}
54    input.interface {margin:0 0 0 0px; vertical-align:middle;}
55    label.interface {display:inline !important; float:none !important; 
56        vertical-align:middle; cursor:pointer;}
57    #forgot-password {margin-top:30px; text-align:center;}
58    .submit-row input {margin-left:8px;}
59</style>
60<script type="text/javascript">
61
62$(function() {
63    // We "inject" the extra login fields here rather than defining them in the
64    // login.html template, since we don't want to override the login.html
65    // template as it's very different between Grappelli and the regular admin.
66    if ($('#id_password').length == 1) { 
67        $('#forgot-password').insertAfter($('.submit-row')).show();
68        $('#extra-login-fields').insertAfter($('#id_password').parent()).show();
69    }
70    // Fix the ``Home`` breadcrumb link non logged-in views.
71    var home = $('.breadcrumbs a:first');
72    if (home.length == 1) {
73        home.attr('href', '{% try_url "admin:index" %}');
74    }
75    // Fix the submit margin on the new password form.
76    if ($('#id_new_password1').length == 1) {
77        $('input:submit').css({marginTop: '20px'});
78    }
79});
80
81</script>
82{% endif %}
83
84{% if request.user.is_authenticated and not is_popup and not request.GET.pop %}
85<style type="text/css">
86
87    .add-row {display:none;}
88    .breadcrumbs {display:none; height:30px; margin:0; padding:0;
89        background:#e6e6e6 !important;}
90    .dropdown-menu {left:0; padding:0;}
91    .dropdown-menu ul {display:inline; padding:0; margin:0;}
92    .dropdown-menu li {float:left; width:auto; padding:11px 15px; 
93        cursor:pointer; height:30px;
94        font-size:15px; font-weight:bold; list-style-type:none;}
95    .cloned li {display:block; font-size:13px; font-weight:normal; 
96        padding:15px 20px 15px 20px !important; border-top:1px solid #eee;}
97    .cloned .first {border-top:0px !important;}
98    .dropdown-menu li ul {display:none; float:left;}
99    .cloned {background:#e6e6e6; border-radius:0 0 5px 5px; 
100        border-bottom:1px solid #ccc; padding:0;}
101    #bookmarks {display:none;}
102    .messagelist {margin-top:14px; z-index:0 !important;}
103
104    {# These are set in PageAdmin's view methods #}
105    {% if hide_delete_link %}.deletelink {display:none !important;}{% endif %}
106    {% if hide_slug_field %}.slug {display:none !important;}{% endif %}
107
108    {% if singleton %}
109    .submit-row * {display:none !important;}
110    .submit-row .default {display:inline !important;}
111    {% endif %}
112
113    /* make save/delete buttons always available at bottom of screen. */
114    .change-form div.submit-row {
115        position: fixed; left: 0; bottom: 0; right: 0; 
116        margin: 0; padding: 10px 15px;
117        background: #e6e6e6; border-top: 1px solid #ccc;
118        text-align: right;
119    }
120       
121        /* Fix for IE7 layout issue */
122        #content { margin-left: 0; margin-right: 0; padding: 0 15px; }
123       
124</style>
125
126<script type="text/javascript">
127// Global flag used for checking whether to hide the visible menu after a small
128// timeout has passed when mousing out from a menu.
129var onMenu; 
130
131$(function() {
132
133    // Empty out the breadcrumbs div and position the menu over it.
134    var breadcrumb = $('.breadcrumbs');
135    $('.breadcrumbs').html(' ').show();
136    $('body').append($('.dropdown-menu'));
137    // The top value here previously used breadcrumb.offset().top but breaks
138    // when scrolling and reloading in Firefox, so to resolve this it's
139    // hard-coded for now. Reported in github issue #11
140    var menuCss;
141    if (window.__grappelli_installed) {
142        menuCss = {top: 30, position: 'fixed'};
143    } else {
144        menuCss = {top: 37, position: 'absolute'};
145    }
146    $('.dropdown-menu').css(menuCss).show();
147
148    $('.dropdown-menu a').mouseover(function() {
149        var parent = $(this).parent();
150        var menu = parent.find('.dropdown-menu-menu').clone();
151        // If we're over a primary menu link, clone the child menu and show it.
152        if (menu.length == 1) {
153            onMenu = true;
154            $('.cloned').remove();
155            $('body').append(menu);
156            // Position the child menu under its parent.
157            var pos = {
158                top: breadcrumb.offset().top + breadcrumb.height(), 
159                left: parent.offset().left,
160                position: 'absolute'
161            }
162            menu.css(pos).addClass('cloned').show();
163            // Ensure the menu stays visible when we mouse onto another item in it.
164            menu.mouseover(function() {
165                onMenu = true;
166            });
167            // Trigger the parent mouseout if we mouseout of the menu.
168            menu.mouseout(function() {
169                $('.dropdown-menu a').mouseout();
170            });
171        }
172    });
173
174    // Set a timeout to hide visible menus on mouseout of primary menu item.
175    $('.dropdown-menu a').mouseout(function() {
176        var parent = $(this).parent();
177        if (parent.find('.dropdown-menu-menu').length == 1) {
178            onMenu = false;
179            window.setTimeout(function() {
180                if (!onMenu) {
181                    $('.cloned').remove();
182                }
183            }, 1000);
184        }
185    })
186
187    // Provides link back to homepage.
188    $('#user-tools li:last').before('<li><a href="/">{% trans "View Site" %}</a></li>');
189
190});
191
192// Remove extraneous ``template`` forms from inline formsets since
193// Mezzanine has its own method of dynamic inlines.
194$(function() {
195    var removeRows = {};
196    $.each($('*[name*=__prefix__]'), function(i, e) {
197        var row = $(e).parent().parent();
198        if (!row.attr('id')) {
199            row.attr('id', 'remove__prefix__' + i);
200        }
201        removeRows[row.attr('id')] = true;
202    });
203    for (var rowID in removeRows) {
204        $('#' + rowID).remove();
205    }
206});
207
208</script>
209{% endif %}
210
211{% endblock %}
212
213{% block footer %}{{ block.super }}
214{% if not request.user.is_authenticated %}
215<p id="forgot-password" style="display:none;">
216    <a href="{% try_url "password_reset" %}">{% trans "Forgot password?" %}</a>
217</p>
218<div class="form-row" id="extra-login-fields" style="display:none;">
219
220    <label class="required">{% trans "Interface:" %}</label> 
221
222    <input class="interface" type="radio" name="mezzanine_login_interface" id="interface_admin" 
223        value="admin"{% ifnotequal request.REQUEST.mezzanine_login_interface "site" %} checked{% endifnotequal %} />
224    <label class="interface" for="interface_admin">{% trans "Admin" %}</label>
225
226    <input class="interface" type="radio" name="mezzanine_login_interface" id="interface_site" 
227        value="site"{% ifequal request.REQUEST.mezzanine_login_interface "site" %} checked{% endifequal %} />
228    <label class="interface" for="interface_site">{% trans "Site" %}</label>
229
230</div>
231{% endif %}
232{% if request.user.is_authenticated %}
233{% admin_dropdown_menu %}
234{% endif %}
235{% endblock %}