cciw-website / cciw / bookings /

from autocomplete.widgets import AutoCompleteWidget

class AccountAutoCompleteWidget(AutoCompleteWidget):
    AC_TEMPLATE = u'''
        <input type="hidden" name="%(name)s" id="id_hidden_%(name)s" value="%(hidden_value)s" />
        <input type="text" value="%(value)s" %(attrs)s />
        <a href="javascript:void(0)" class="add-another" id="add_id_account"> New account </a> | 

        <a href="javascript:void(0)" class="add-another" id="edit_id_account"> Edit </a>

<script type="text/javascript">
var %(var_name)s = new autocomplete("%(name)s", "%(url)s", %(force_selection)s);

// For 'add another', we need slightly customised behaviour instead of showAddAnotherPopup

function showAddAnotherAccountPopup(ev) {
    var name = 'id_account';
    name = id_to_windowname(name);
    var href = '/admin/bookings/bookingaccount/add/?_popup=1&name=' + encodeURIComponent($('#id_account').val());
    var win =, name, 'height=500,width=800,resizable=yes,scrollbars=yes');

function showEditAccountPopup(ev) {
    var name = 'id_account';
    name = id_to_windowname(name);
    var account_id = $('#id_hidden_account').val();
    if (/^\d+$/.test(account_id)) {
        var href = '/admin/bookings/bookingaccount/' + account_id + '/?_popup=1';
        var win =, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
    } else {
        alert('No account selected');

// Hack: we need dismissAddAnotherPopup to do something different,
// so we monkey patch it.

var originalDismissAddAnotherPopup = window.dismissAddAnotherPopup;
window.dismissAddAnotherPopup = function(win, newId, newRepr) {
    newId = html_unescape(newId);
    newRepr = html_unescape(newRepr);
    var name = windowname_to_id(;
    var elem = document.getElementById(name);
    if (name == 'id_account') {
    } else {
        originalDismissAddAnotherPopup(win, newId, newRepr);

    // autocomplete doesn't do quite what we want with focusout:


    class Media:
        extend = False
        css = {'all': ('',),
        js = (
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.