From b62219436140a7dbb638e40cbfb37b5108435f9c Mon Sep 17 00:00:00 2001 From: "stan.madueke" Date: Sat, 10 Oct 2009 09:56:21 +0000 Subject: [PATCH] Added demo application Added minified version Added README.txt git-svn-id: https://django-dynamic-formset.googlecode.com/svn/trunk@2 9f2ace40-7153-11de-83e1-4fc93b4a6815 --- INSTALL.txt | 0 README.txt | 17 + demo/__init__.py | 0 demo/example/__init__.py | 0 demo/example/fixtures/initial_data.json | 79 ++++ demo/example/forms.py | 48 +++ demo/example/models.py | 31 ++ demo/example/urls.py | 12 + demo/example/views.py | 40 ++ demo/manage.py | 11 + demo/settings.py | 91 +++++ demo/static/css/default.css | 342 ++++++++++++++++++ demo/static/css/jquery.autocomplete.css | 48 +++ demo/static/images/add.png | Bin 0 -> 733 bytes demo/static/images/bg01.jpg | Bin 0 -> 556 bytes demo/static/images/bg02.jpg | Bin 0 -> 563 bytes demo/static/images/bg03.jpg | Bin 0 -> 1167 bytes demo/static/images/bg04.jpg | Bin 0 -> 7125 bytes demo/static/images/comments.png | Bin 0 -> 557 bytes demo/static/images/delete.png | Bin 0 -> 715 bytes demo/static/images/doc.png | Bin 0 -> 294 bytes demo/static/images/edit.png | Bin 0 -> 618 bytes demo/static/images/img02.gif | Bin 0 -> 48 bytes demo/static/images/img05.gif | Bin 0 -> 99 bytes demo/static/images/img06.jpg | Bin 0 -> 818 bytes demo/static/images/spacer.gif | Bin 0 -> 43 bytes demo/static/js/autocomplete-init.js | 13 + demo/static/js/jquery.autocomplete.min.js | 55 +++ demo/static/js/jquery.formset.min.js | 10 + demo/static/js/jquery.js | 32 ++ demo/templates/base.html | 56 +++ demo/templates/example/formset-stacked.html | 44 +++ demo/templates/example/formset-table.html | 56 +++ .../example/inline-formset-autocomplete.html | 78 ++++ demo/templates/example/inline-formset.html | 56 +++ demo/templates/example/posted-data.html | 24 ++ demo/templates/index.html | 19 + demo/urls.py | 26 ++ src/jquery.formset.js | 102 ++++++ 39 files changed, 1290 insertions(+) create mode 100644 INSTALL.txt create mode 100644 README.txt create mode 100644 demo/__init__.py create mode 100644 demo/example/__init__.py create mode 100644 demo/example/fixtures/initial_data.json create mode 100644 demo/example/forms.py create mode 100644 demo/example/models.py create mode 100644 demo/example/urls.py create mode 100644 demo/example/views.py create mode 100644 demo/manage.py create mode 100644 demo/settings.py create mode 100644 demo/static/css/default.css create mode 100644 demo/static/css/jquery.autocomplete.css create mode 100644 demo/static/images/add.png create mode 100644 demo/static/images/bg01.jpg create mode 100644 demo/static/images/bg02.jpg create mode 100644 demo/static/images/bg03.jpg create mode 100644 demo/static/images/bg04.jpg create mode 100644 demo/static/images/comments.png create mode 100644 demo/static/images/delete.png create mode 100644 demo/static/images/doc.png create mode 100644 demo/static/images/edit.png create mode 100644 demo/static/images/img02.gif create mode 100644 demo/static/images/img05.gif create mode 100644 demo/static/images/img06.jpg create mode 100644 demo/static/images/spacer.gif create mode 100644 demo/static/js/autocomplete-init.js create mode 100644 demo/static/js/jquery.autocomplete.min.js create mode 100644 demo/static/js/jquery.formset.min.js create mode 100644 demo/static/js/jquery.js create mode 100644 demo/templates/base.html create mode 100644 demo/templates/example/formset-stacked.html create mode 100644 demo/templates/example/formset-table.html create mode 100644 demo/templates/example/inline-formset-autocomplete.html create mode 100644 demo/templates/example/inline-formset.html create mode 100644 demo/templates/example/posted-data.html create mode 100644 demo/templates/index.html create mode 100644 demo/urls.py create mode 100644 src/jquery.formset.js diff --git a/INSTALL.txt b/INSTALL.txt new file mode 100644 index 0000000..e69de29 diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..b7d73ee --- /dev/null +++ b/README.txt @@ -0,0 +1,17 @@ +============================================ +A jQuery plugin for managing Django formsets +============================================ + +This jQuery_ plugin helps you create more usable Django_ formsets by +allowing clients add and remove forms on the client-side. + +For installation instructions, see the file ``INSTALL.txt`` in +this directory; for documentation see the files in the ``docs/`` +directory. + +The latest versions of these documents can always be viewed on the +Google Code project web site for this application, which is located at +http://code.google.com/p/django-dynamic-formset/. + +.. _jQuery: http://jquery.com/ +.. _Django: http://www.djangoproject.com/ diff --git a/demo/__init__.py b/demo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/demo/example/__init__.py b/demo/example/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/demo/example/fixtures/initial_data.json b/demo/example/fixtures/initial_data.json new file mode 100644 index 0000000..d6ac5bc --- /dev/null +++ b/demo/example/fixtures/initial_data.json @@ -0,0 +1,79 @@ +[ + { + "pk": 1, + "model": "example.product", + "fields": { + "name": "Black-eyed Peas" + } + }, + { + "pk": 10, + "model": "example.product", + "fields": { + "name": "Kidney Beans" + } + }, + { + "pk": 3, + "model": "example.product", + "fields": { + "name": "Minty Loin of Lamb" + } + }, + { + "pk": 7, + "model": "example.product", + "fields": { + "name": "Olive Oil (Extra Virgin)" + } + }, + { + "pk": 8, + "model": "example.product", + "fields": { + "name": "Oreos" + } + }, + { + "pk": 2, + "model": "example.product", + "fields": { + "name": "Prime Bac'n" + } + }, + { + "pk": 9, + "model": "example.product", + "fields": { + "name": "Reese's Peanut Butter Cups" + } + }, + { + "pk": 6, + "model": "example.product", + "fields": { + "name": "Rice Wine Vinegar" + } + }, + { + "pk": 4, + "model": "example.product", + "fields": { + "name": "Sweetcorn" + } + }, + { + "pk": 5, + "model": "example.product", + "fields": { + "name": "Szechuan Peppercorn" + } + }, + { + "pk": 11, + "model": "example.product", + "fields": { + "name": "Uncle Bob's Hot, Hot Sauce" + } + } +] diff --git a/demo/example/forms.py b/demo/example/forms.py new file mode 100644 index 0000000..fe97b85 --- /dev/null +++ b/demo/example/forms.py @@ -0,0 +1,48 @@ +from django import forms +from django.forms import fields, models, formsets, widgets +from example.models import Product, Order, OrderedItem + +class OrderForm(models.ModelForm): + class Meta: + model = Order + +class OrderedItemForm(models.ModelForm): + class Meta: + model = OrderedItem + +class AutoCompleteOrderedItemForm(models.ModelForm): + """ + Display the Ordered Item form with an autocomplete textbox for the + Products instead of the Dropdown List. + """ + + class Meta: + model = OrderedItem + + class Media: + js = ('js/jquery.autocomplete.min.js', 'js/autocomplete-init.js',) + css = { + 'all': ('css/jquery.autocomplete.css',), + } + + def __init__(self, *args, **kwargs): + super(AutoCompleteOrderedItemForm, self).__init__(*args, **kwargs) + self.fields['product'].widget = widgets.TextInput(attrs={'class': 'autocomplete-me'}) + +def get_ordereditem_formset(form, formset=models.BaseInlineFormSet, **kwargs): + return models.inlineformset_factory(Order, OrderedItem, form, formset, **kwargs) + +CONTACT_INFO_TYPES = ( + ('Phone', 'Phone'), + ('Fax', 'Fax'), + ('Email', 'Email'), + ('AIM', 'AIM'), + ('Gtalk', 'Gtalk/Jabber'), + ('Yahoo', 'Yahoo'), +) + +class ContactInfoForm(forms.Form): + type = fields.ChoiceField(choices=CONTACT_INFO_TYPES) + value = fields.CharField(max_length=200) + +ContactFormset = formsets.formset_factory(ContactInfoForm) diff --git a/demo/example/models.py b/demo/example/models.py new file mode 100644 index 0000000..f5bf89f --- /dev/null +++ b/demo/example/models.py @@ -0,0 +1,31 @@ + +# Test with inlineformsets and inlinemodelformsets +# Test with fieldsets (admin)? + +from django.db import models +from django.template.defaultfilters import pluralize +from datetime import date + +class Product(models.Model): + name = models.CharField(max_length=150) + + class Meta: + ordering = ('name',) + + def __unicode__(self): + return self.name + +class Order(models.Model): + customer = models.CharField(max_length=150) + date = models.DateField(default=date.today, editable=False) + + def __unicode__(self): + return u"%s's order" % self.customer + +class OrderedItem(models.Model): + order = models.ForeignKey(Order, related_name='ordered_items') + product = models.ForeignKey(Product, related_name='orders') + quantity = models.PositiveSmallIntegerField() + + def __unicode__(self): + return u"%s (%d)" % (self.product, self.quantity) diff --git a/demo/example/urls.py b/demo/example/urls.py new file mode 100644 index 0000000..7ccbd6c --- /dev/null +++ b/demo/example/urls.py @@ -0,0 +1,12 @@ +from django.conf.urls.defaults import * +from example.forms import AutoCompleteOrderedItemForm, OrderedItemForm + +urlpatterns = patterns('example.views', + url(r'^stacked/$', 'formset', {'template': 'example/formset-stacked.html'}, name='example_stacked'), + url(r'^table/$', 'formset', {'template': 'example/formset-table.html'}, name='example_table'), + url(r'^inline-formset/$', 'inline_formset', + {'form_class': OrderedItemForm, 'template': 'example/inline-formset.html'}, name='example_inline_formset'), + url(r'^inline-formset-autocomplete/$', 'inline_formset', + {'form_class': AutoCompleteOrderedItemForm, 'template': 'example/inline-formset-autocomplete.html'}, name='example_inline_autocomplete'), + url(r'^autocomplete-products/$', 'autocomplete_products', name='example_autocomplete_products') +) diff --git a/demo/example/views.py b/demo/example/views.py new file mode 100644 index 0000000..1a61741 --- /dev/null +++ b/demo/example/views.py @@ -0,0 +1,40 @@ +from django.http import HttpResponse +from django.shortcuts import render_to_response +from django.template.context import RequestContext +from example.forms import ContactFormset, Order, OrderForm, get_ordereditem_formset +from example.models import Order, Product + +def autocomplete_products(request): + q = request.GET.get('q', '') + products = Product.objects.filter(name__icontains=q).values_list('pk', 'name') + output = u'\n'.join([u'%d|%s' % tuple(product) for product in products]) + return HttpResponse(output, mimetype='text/plain') + +def display_data(request, data): + return render_to_response('example/posted-data.html', {'data': data}, + context_instance=RequestContext(request)) + +def formset(request, template): + if request.method == 'POST': + formset = ContactFormset(request.POST) + if formset.is_valid(): + data = formset.cleaned_data + return display_data(request, data) + else: + formset = ContactFormset() + return render_to_response(template, {'formset': formset}, + context_instance=RequestContext(request)) + +def inline_formset(request, form_class, template): + OrderedItemFormset = get_ordereditem_formset(form_class, extra=1) + if request.method == 'POST': + form = OrderForm(request.POST) + formset = OrderedItemFormset(request.POST) + if form.is_valid() and formset.is_valid(): + data = formset.cleaned_data + return display_data(request, data) + else: + form = OrderForm() + formset = OrderedItemFormset() + return render_to_response(template, {'form': form, 'formset': formset}, + context_instance=RequestContext(request)) diff --git a/demo/manage.py b/demo/manage.py new file mode 100644 index 0000000..b8c4be8 --- /dev/null +++ b/demo/manage.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python +from django.core.management import execute_manager +try: + import settings # Assumed to be in the same directory. +except ImportError: + import sys + sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) + sys.exit(1) + +if __name__ == "__main__": + execute_manager(settings) diff --git a/demo/settings.py b/demo/settings.py new file mode 100644 index 0000000..740469c --- /dev/null +++ b/demo/settings.py @@ -0,0 +1,91 @@ +# Django settings for demo project. +import os + +PROJECT_DIR = os.path.normpath(os.path.dirname(__file__)) + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +ADMINS = ( + # ('Your Name', 'your_email@domain.com'), +) + +MANAGERS = ADMINS + +DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. +DATABASE_NAME = 'demo.sqlite' # Or path to database file if using sqlite3. +DATABASE_USER = '' # Not used with sqlite3. +DATABASE_PASSWORD = '' # Not used with sqlite3. +DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. +DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = 'Africa/Lagos' + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +LANGUAGE_CODE = 'en-us' + +SITE_ID = 1 + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = True + +# Absolute path to the directory that holds media. +# Example: "/home/media/media.lawrence.com/" +MEDIA_ROOT = os.path.join(PROJECT_DIR, 'static') + +# URL that handles the media served from MEDIA_ROOT. Make sure to use a +# trailing slash if there is a path component (optional in other cases). +# Examples: "http://media.lawrence.com", "http://example.com/media/" +MEDIA_URL = '/static/' + +# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a +# trailing slash. +# Examples: "http://foo.com/media/", "/media/". +ADMIN_MEDIA_PREFIX = '/media/' + +# Make this unique, and don't share it with anybody. +SECRET_KEY = 's2r2k*nqosri4%)5c8w^--jpv+8tzrvbzr11p-frp9kq5ot13v' + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.load_template_source', + 'django.template.loaders.app_directories.load_template_source', +) + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', +) + +ROOT_URLCONF = 'demo.urls' + +TEMPLATE_DIRS = ( + # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. + os.path.join(PROJECT_DIR, 'templates'), +) + +TEMPLATE_CONTEXT_PROCESSORS = ( + 'django.core.context_processors.auth', + 'django.core.context_processors.media', + #'django.core.context_processors.i18n', + #'django.core.context_processors.request', + #'django.core.context_processors.debug', +) + +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'example', +) diff --git a/demo/static/css/default.css b/demo/static/css/default.css new file mode 100644 index 0000000..afe88dc --- /dev/null +++ b/demo/static/css/default.css @@ -0,0 +1,342 @@ +/* +Design by Free CSS Templates +http://www.freecsstemplates.org +Released for free under a Creative Commons Attribution 2.5 License +*/ + +body { + margin: 0; + padding: 0; + background: #FFFFFF url(../images/bg01.jpg) repeat-x top left; + font-size: 13px; + color: #7F7F7F; +} + +body, th, td, input, textarea, select, option { + font-weight: normal; + font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; +} + +h1, h2, h3 { + font-weight: normal; + color: #484848; +} + +h1 { + text-transform: lowercase; + letter-spacing: -1px; + font-size: 24px; +} + +h2 { + text-transform: lowercase; + letter-spacing: -1px; + font-size: 24px; +} + +h3 { + font-size: 1em; +} + +p, ul, ol { + line-height: 200%; +} +p.notice { + line-height: normal; + color: #003300; + font-weight: bold; +} + +blockquote { + padding-left: 1em; +} + +blockquote p, blockquote ul, blockquote ol { + line-height: normal; + font-style: italic; +} + +a { + color: #7ACE11; +} + +a:hover { + text-decoration: none; + color: #7ACE11; +} + +/* Comments */ + +.comment-header { + padding-left: 10px; + padding-right: 10px; + background-color: #f6f6f6; + border-bottom: 1px solid #ddd; + font-style: italic; + line-height: 250%; +} +.comment-header a { + float: right; + clear: right; +} + +/* Header */ + +#header { + width: 890px; + height: 190px; + margin: 0px auto; +} + +/* Logo */ + +#logo { + float: left; + padding: 40px 0 0 0; +} + +#logo h1 { + margin: 0; + text-transform: lowercase; + letter-spacing: -2px; + font-size: 3.6em; + font-weight: normal; + color: #FFFFFF; +} + +#logo h1 a { + padding-right: 20px; + text-decoration: none; + color: #FFFFFF; +} + +#logo p { + margin: -5px 0 0 0; + text-transform: uppercase; + font-size: 1.22em; + letter-spacing: -1px; +} + +#logo a { + text-decoration: none; + color: #FFFFFF; +} + +/* Menu */ + +#menu { + float: right; +} + +#menu ul { + margin: 0px; + padding: 93px 0px 0px 0px; + list-style: none; +} + +#menu li { + display: inline; +} + +#menu a { + display: block; + float: left; + margin-left: 20px; + text-decoration: none; + text-transform: lowercase; + font-size: 1.6em; + color: #FFFFFF; +} + +#menu a:hover, .active a { + border-bottom: 3px solid #FFFFFF; +} + + +/* Page */ + +#page { + width: 890px; + margin: 0 auto; +} + +/* Content */ + +#content { + float: left; + width: 590px; +} + +.post { + padding: 20px 20px; + background: url(../images/bg04.jpg) no-repeat top left; +} + +.title { + margin: 0; + border-bottom: 1px solid #484848; + color: #484848; +} + +.byline { + margin: 0; + color: #D79B00; +} + +.meta { + text-align: left; + color: #646464; +} + +.meta .edit { + padding-left: 20px; + background: url(../images/edit.png) no-repeat left center; +} + +.meta .more { + padding-left: 20px; + background: url(../images/doc.png) no-repeat left center; +} + +.meta .comments { + padding-left: 20px; + background: url(../images/comments.png) no-repeat left center; +} + +strong { + font-weight: bolder; +} + +/* Sidebar */ + +#sidebar { + float: right; + width: 240px; +} + +#sidebar ul { + margin: 0; + padding: 0; + list-style: none; +} + +#sidebar li { +} + +#sidebar li ul { + padding: 15px 0; +} + +#sidebar li li { + padding-left: 20px; + border-bottom: 1px dotted #7B9418; +} + +#sidebar h2 { + margin: 0; + padding: 5px 0 0 20px; + background: url(../images/img06.jpg) no-repeat left 80%; +} +#sidebar h2.user { + margin-bottom: 20px; + font-size: 20px; + text-transform: none; +} + +#sidebar a { + text-decoration: none; +} + +#sidebar a:hover { +} + +a.download { + display: block; + padding-left: 85px; + background: url(../images/download.png) 0 50% no-repeat; + line-height: 80px; + font-size: 22px; + text-decoration: none; +} + +/* Footer */ + +#footer { + clear: both; + margin: 0px; + height: 80px; + background: #F2F2F2 url(../images/bg02.jpg) repeat-x left top; +} + +#footer p { + padding: 20px 0; + text-align: center; + font-size: smaller; + color: #717171; +} + +/* Forms */ + +form { + margin-left: auto; + margin-right: auto; + width: 90%; +} +form input[type="text"], +form input[type="password"] { + width: 200px; +} +form textarea { + display: block; + width: 100%; + height: 160px; +} +form select { + display: block; +} +form ul { + list-style: none; + margin-top: 0; + margin-left: 0; +} + +/* Calendar */ + +.calendar { + margin-left: auto; + margin-right: auto; + margin-bottom: 20px; + width: 235px; +} +.calendar table caption { + font-size: 22px; + text-transform: lowercase; + color: #484848; +} +.calendar table { + margin-bottom: 0; + width: 235px; +} +.calendar th, .calendar td { + text-align: center; +} +.calendar th { + color: #484848; +} +.calendar td.wkend { + color: #D79B00; +} +.calendar td a { + display: block; + background-color: #484848; + color: #fff; +} +.calendar td a:hover { + background-color: #7ACE11; +} +.previous-month { + float: left; +} +.next-month { + float: right; +} diff --git a/demo/static/css/jquery.autocomplete.css b/demo/static/css/jquery.autocomplete.css new file mode 100644 index 0000000..91b6228 --- /dev/null +++ b/demo/static/css/jquery.autocomplete.css @@ -0,0 +1,48 @@ +.ac_results { + padding: 0px; + border: 1px solid black; + background-color: white; + overflow: hidden; + z-index: 99999; +} + +.ac_results ul { + width: 100%; + list-style-position: outside; + list-style: none; + padding: 0; + margin: 0; +} + +.ac_results li { + margin: 0px; + padding: 2px 5px; + cursor: default; + display: block; + /* + if width will be 100% horizontal scrollbar will apear + when scroll mode will be used + */ + /*width: 100%;*/ + font: menu; + font-size: 12px; + /* + it is very important, if line-height not setted or setted + in relative units scroll will be broken in firefox + */ + line-height: 16px; + overflow: hidden; +} + +.ac_loading { + background: white url('indicator.gif') right center no-repeat; +} + +.ac_odd { + background-color: #eee; +} + +.ac_over { + background-color: #0A246A; + color: white; +} diff --git a/demo/static/images/add.png b/demo/static/images/add.png new file mode 100644 index 0000000000000000000000000000000000000000..6332fefea4be19eeadf211b0b202b272e8564898 GIT binary patch literal 733 zcmV<30wVp1P)9VHk(~TedF+gQSL8D5xnVSSWAVY>J9b+m>@{iq7_KE}go~11+5s4;8hc+i0Xa zI1j@EX5!S+Me6HNqKzU5YQwL;-W5$p%ZMKMeR<%zp69-~?<4?8|C8S?bklXr4v&Ov zb&06v2|-x?qB`90yn>Qi%Sh2^G4n)$ZdyvTPf9}1)_buUT7>`e2G&2VU@~Bb(o+Mz zi4)>IxlSY${Dj4k={-9RzU^W5g9|2V5RZ2ZulL9s2xQbZ@r6eP9Ra5u(s|C0Nj#&4>wTSkb?%#=9?@ z^oxDy-O@tyN{L@by(WWvQ3%CyEu8x{+#Jb4-h&K9Owi)2pgg+heWDyked|3R$$kL@A z#sp1v-r+=G4B8D6DqsDH0@7OztA7aT9qc1Py{()w`m``?Y0&gi2=ROcc-9+nU^I6< zT=e_Y=vSnG@?3Ue{BW5ONFttcE!R-R_W4O01|0-|K-YNXLo2`4Qv z`r1LxR6#yf3FB%T95gJnaKKivA~Z}S9A(ZxEDK}O3T04USJ P00000NkvXXu0mjf^IS-S literal 0 HcmV?d00001 diff --git a/demo/static/images/bg01.jpg b/demo/static/images/bg01.jpg new file mode 100644 index 0000000000000000000000000000000000000000..36dc6719acc1b882611e863f81f72e3cd2b5e374 GIT binary patch literal 556 zcma)&OAY}+5QhJ%@(#%~5o;R@mk^0aSUCe@WicxYD;xI^aS;)R@Ypzjh#R!RnC_U3 z>QwUOuh*ZpM|(vu><{`N210$XH<;dhGFyOfMi0Nh z#hy_X((7XMgVqoKtjF3`P!p8pt<8 literal 0 HcmV?d00001 diff --git a/demo/static/images/bg02.jpg b/demo/static/images/bg02.jpg new file mode 100644 index 0000000000000000000000000000000000000000..34fa750c327ea779b1a8dcdc570ed3544d2b4a4e GIT binary patch literal 563 zcma)2u}T9$5PdU~i%}GI4JibRXkn=YJ3*o#2im2u7B#6XB%p;hBB-rkWhVife1%a2 zD}{7M8%?8yh?VU+m(yF$DsLHh^Jd;KJMPiFz^sJJA&7yhKDZCqrQOY~JrFX8M7U2( zEmpTTYN)nUAweM{*`X1oO^thiMWf`NaRllg>>&w$?M$Rqjik^oaW}9zln@A6uqCnN zZgCtfrptRsX7Hb)HKSiiw^>t^yaff`sjNtCKARm)x2l}i>qx4#SZ^46_*GeNzq%(3 z>vXna^=zH)_1$>=RK=X`K>@#=H*%F;%29gNqv9!Zw#)~y>M4<`4~4KC4-zU*T-Hv; nR^vfYx)xjhs9(YG!a(9OlXLSk-Tmo~?6ls$FA}@)cBP#kx)oLm literal 0 HcmV?d00001 diff --git a/demo/static/images/bg03.jpg b/demo/static/images/bg03.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e22d877297467e77f709be2bf9d160e7224db24f GIT binary patch literal 1167 zcmex=w`EbC<&cw;Z!H6OTk`!QIWMN`tg{uSV z6l7szWiJp2NMK?X1p1$em5GfRCeO&k%)-DbXecDirl_P4kdSC3k`&A?gl=qsFwg-E ztjsJ3jSPYx6cZ;N3@9)ZNN@}+T)6T7Ee0N-8<_-wwlFZ>Elg(?0NTQ-0<#K*7VSL0 z@q%GS1BxILhq3WlvD0&)ksvQJvNA2bksS4Eu7nzAQ^E`=(Oz@rMsl+8Ea&pSrN=Mr zEnOM)_=l$Qm6&f|x%#EzKA%5#%O0$s38ep_KbXyo#Aae*vu6^42qTz`j6l&1MH1^& zkG-3=W0Uxj=Iz=!N;##8my1lc=x(j^{E!+M7CIG5R6gh5qP zcE_rE9R9lLOIbkeU6I|gAGa?r)VySV?tIN|o#hPPlNN3BxZm@QxpaqKvNB+^br;n2yLyI=|eq*qZ6!wjT@(yjK_)q%Z%!&CtTYNIYOd0A@IVYG-0(1j+(2T!L7} z|3eId91NG3{FoU98JGkanFSgDA7PjSau@?MBhdXYz{JeR!paF0MFRpLColkI;o^eK z!V?xWFtGp)WMpMzU}Ry2Nii{8WHz46D5z*Cq_iN>NeH0_qGEwC1JD~lqk#ILa*Tot z6E6l9PJCDpkg!0}u)*>FEe0N-3MN5jL15tiZYXttnT|=9^_yS{!bL>jEKCMBrVw0& z70$wBFde`YgNZOMfU&U9I#|SDLSirm78;nWa012zoKg%77x2hQ;gMr@z$2M~M-E?* zvNhn*NUlrq#zg`i3m4##BiD!Q3V00NfJd$fj~qWRGjITN3L`7i^{?6Af0y69pI$rn z+W=AZ_HlduFuPC`py>Sc-gNRf1tHF`g<_)%Ql zo%g5b)!qBI=g-4>NFrlqv{#%zq3FYZh9e7Z{_E+LGRe5O*bOK3pTQZoBv|7b_HQO> zhyRK!5pZN70}1}t6Xa-dQWWTLQKBBBi9>-LWY2Yo$_@egtWFd&>yzg^4uv*n#R(@; zj3jwR859Qs|36Ktr@I!XKl|XZP3=StN=xyOLK2jV|G`Q_1P9Tg5`en`lOg1(G6@%Q zz*J6@2u=e%RVEN+09_Pu;`X>FT^xY01dmHp5UK{6#e^%J0L2}s?>KU;vxnDh0{**J zaOPTP$KTG~YX8Xl*Ix+%1&2l^77m{rq zHs@$|ns&5d)XlDIXTr86ZQVR7I2s@$EHP}7=RfBB@W+W7drAKG$BG~Rq}a*#v>*OB z;YXd(@Rs_|pg;6mAahs0ytQvA62m`z;mA_Qf9ntNR_~0p@4v<9iFdRf`Y5m?PDz~m ih||N0ju?GG?$$?&1$$hEw^ZF}_|S&{^3VsEa}xk6xj6~| literal 0 HcmV?d00001 diff --git a/demo/static/images/comments.png b/demo/static/images/comments.png new file mode 100644 index 0000000000000000000000000000000000000000..39433cf78a3e9869f24b0a95f04b1819391596e8 GIT binary patch literal 557 zcmV+|0@D47P)kO-!8JjERGZgNx4o8zwI5pnrkJT^AW7B+k01lLkoCLBu@bfRhnJSkT}{ z5cwz-C?AEk;`Q7|NyO0V@Jst%?>X<@)8|?6hNplZoH}p}R=_wBd4A);huvr*D{8ta zv>weaRZy(zA{a{x)NMK$oUyoq;&Q_jA9Yid>V_!Q3{lkDazCTg+2GL8fKO$yVv7pZ zw#ZdlB3o|B^q?JFdAt+nq80!As0d}1Z|KFR(*lEh^G}{es&~_I}wY;n4d5jAs0d}gj@(+ z%6*K*29I(Myv%_UPWDD&5qS@s3~ZAJGDH vT*SlN0ce3)r#d%-F%SaNZe6;L@E^Vb!Ji3~dec0&00000NkvXXu0mjflI-*P literal 0 HcmV?d00001 diff --git a/demo/static/images/delete.png b/demo/static/images/delete.png new file mode 100644 index 0000000000000000000000000000000000000000..08f249365afd29594b51210c6e21ba253897505d GIT binary patch literal 715 zcmV;+0yO=JP)C4}Mrzlg<+1Y8PEBfUp0jJpx4B>@E+cy3`^(Gw`Mf+2&yxZm<$to~Vpgvg&QKNR z_f#1(r6svZt%iF?s+n<8X?B&!h3g9Dbb8_=MX}!;HiQSAh`bp^WMl~Z-44teO7W_Y zV4thSL{h;rJY7!l3%5J4H1!tIzB`Dv+YxO(haWeausGZYkI8^hWj6mzo=L0{%;yxzh{5!Htr?51 zvG|W62MzC8BZ76hRpCyO2zOn<%e)K>NHge!-~)Ap33OdWw6hsLYbCxGNt0%wk_2z7 zfyYvXheSG)5HRK1VB~%mq7Dmurw#bi@hEcOr3&G1ZiF*$M=&9nB#VNf&Q^r$4G5kp zTURh&s)E0%5&hyVD}sp<72~zmAY`Y(9aqO6CXF%=zFHGzO-A&I(pE}v70YQxCPJ{Y z4L+?5-crdLn3ZRPEs!A4ehEY3ZRpL~w9>@aMN+{F4dI@v&>(QDHQum!mG~E^$OS8l z!7?%Uwib*ROP67Hw`ika)gX-(8Ia`-u_IEhxG7U<13kSsMW+$lbb2dUMm5p6pa}cjgA+U$^mJ^AjD?&bdi)8~y+Q002ovPDHLkV1g8IMc@Dc literal 0 HcmV?d00001 diff --git a/demo/static/images/doc.png b/demo/static/images/doc.png new file mode 100644 index 0000000000000000000000000000000000000000..8b8b1ca0000bc8fa8d0379926736029f8fabe364 GIT binary patch literal 294 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zbpD<_bdI{u9mbgZg z1m~xflqVLYGB~E>C#5QQ<|d}62BjvZR2H60wE-&H;pyTSqH(@-Vl>|&1p(LP>kg~E zYiz5X^`c$+%8#zC{u)yfe-5 zmgid={Z3k(ERKCKrE7DF;=x4^O+ pzO8rLO8p|Ip=x)jHOtWj`bJBmKdh_V<`47(gQu&X%Q~loCIFbEay|e6 literal 0 HcmV?d00001 diff --git a/demo/static/images/edit.png b/demo/static/images/edit.png new file mode 100644 index 0000000000000000000000000000000000000000..b93e77600def75c9a144d3d0a5088a62c02cbb0b GIT binary patch literal 618 zcmV-w0+s!VP)$>5Y&axjp2O=VLu>*f>1L;s0)kkvKC!*u?s6CVL=HJ6oP~pNfZc; zsKr=bq;7MITw8NXw{SZm%59TId2x_9BQ zV86`NuvGI!>o^V!Na!=$7GJE{Cq`b+XwknM{UcGHFTTfmuS+ zm-zYC!P3+zmY;SG$?!fYkOih`QYaLxyF}A86h$GGN}kFj)_o*0e zjPMP%zTG7FYMAfO2Nn1D`D0Cj?Wl>5q%@CE10nX)KxpNmwk+!IWkzywiYD( zqUXiYYIq3qcRyMGJ;IY`(Gz~E$J$zu2+R{)xGlE*88b3WK6V*J>}2iPY1HH|tER0W z_+^^FdppY?o)Gt5M2`%xwRDH@R3G}^i1l4|6uchm0X0f!@&YdVLB5K&dd7Rv{)DXX zt^&vP;}kqj3f>94j+4xd93>s|Q!Ezi>?r8(Il$P}PFxSqu{d*!Y%*#cX(R0f|Juz# z3o0_xI14Al->1uky@W-rCI_%l&>O1eh5G8JGkanFSgDA7PjbbRZ+p@d&`g%)-uyF38Bt3e?KX2m}a~j7%)7 z41&x+(->J%#hDod6@^#=4TUfb5>ylrW@KOjTFS@@Gm24Ak-;#~QQ$*jVdKL8w-|VU zvP>X@85nOaa#J&OIoS^slx4qq8?*9y6NhXkFx!pqL znI0PL_rXHUU?H0|?xG5-Ce=e!F|pY*Wj!o{$b&hL=Yu(nj6j)+2RcHwt&>?^x2g2} zT~~O`vwL~y#dBwN&kgzg{Z`&S*Yw_#2`84m-4+??mRs{^`uer8$>EVHlR`Bj7VcWL z^6dJz5L+0T8SNG0*Xo^kaUf`Mc-N&hSwg$k2(Of#vFY%wx$~}als~l$F<>bE#IeGJ z5n?+qK&r9d%swr?bN>UG^KknGil=d2&CZ%G91*DTVbi1o-|H+cNTja5 ScjS)m)8lvU`eg9@zX<@6qSmYc literal 0 HcmV?d00001 diff --git a/demo/static/images/spacer.gif b/demo/static/images/spacer.gif new file mode 100644 index 0000000000000000000000000000000000000000..5bfd67a2d6f72ac3a55cbfcea5866e841d22f5d9 GIT binary patch literal 43 mcmZ?wbhEHbWMp7uXkdT>#h)yUAf^t80Ld^gF}W}@SOWlZ0R#L1 literal 0 HcmV?d00001 diff --git a/demo/static/js/autocomplete-init.js b/demo/static/js/autocomplete-init.js new file mode 100644 index 0000000..6158b72 --- /dev/null +++ b/demo/static/js/autocomplete-init.js @@ -0,0 +1,13 @@ + +function makeAutocomplete(sel) { + sel.autocomplete('/examples/autocomplete-products/', { + delay: 200, + formatItem: function(row) { + return row[1]; + } + }); +} + +$(function() { + makeAutocomplete($('.autocomplete-me')); +}) diff --git a/demo/static/js/jquery.autocomplete.min.js b/demo/static/js/jquery.autocomplete.min.js new file mode 100644 index 0000000..144f5b9 --- /dev/null +++ b/demo/static/js/jquery.autocomplete.min.js @@ -0,0 +1,55 @@ +;(function($){$.fn.extend({autocomplete:function(urlOrData,options){var isUrl=typeof urlOrData=="string";options=$.extend({},$.Autocompleter.defaults,{url:isUrl?urlOrData:null,data:isUrl?null:urlOrData,delay:isUrl?$.Autocompleter.defaults.delay:10,max:options&&!options.scroll?10:150},options);options.highlight=options.highlight||function(value){return value;};options.formatMatch=options.formatMatch||options.formatItem;return this.each(function(){new $.Autocompleter(this,options);});},result:function(handler){return this.bind("result",handler);},search:function(handler){return this.trigger("search",[handler]);},flushCache:function(){return this.trigger("flushCache");},setOptions:function(options){return this.trigger("setOptions",[options]);},unautocomplete:function(){return this.trigger("unautocomplete");}});$.Autocompleter=function(input,options){var KEY={UP:38,DOWN:40,DEL:46,TAB:9,RETURN:13,ESC:27,COMMA:188,PAGEUP:33,PAGEDOWN:34,BACKSPACE:8};var $input=$(input).attr("autocomplete","off").addClass(options.inputClass);var timeout;var previousValue="";var cache=$.Autocompleter.Cache(options);var hasFocus=0;var lastKeyPressCode;var config={mouseDownOnSelect:false};var select=$.Autocompleter.Select(options,input,selectCurrent,config);var blockSubmit;$.browser.opera&&$(input.form).bind("submit.autocomplete",function(){if(blockSubmit){blockSubmit=false;return false;}});$input.bind(($.browser.opera?"keypress":"keydown")+".autocomplete",function(event){lastKeyPressCode=event.keyCode;switch(event.keyCode){case KEY.UP:event.preventDefault();if(select.visible()){select.prev();}else{onChange(0,true);} +break;case KEY.DOWN:event.preventDefault();if(select.visible()){select.next();}else{onChange(0,true);} +break;case KEY.PAGEUP:event.preventDefault();if(select.visible()){select.pageUp();}else{onChange(0,true);} +break;case KEY.PAGEDOWN:event.preventDefault();if(select.visible()){select.pageDown();}else{onChange(0,true);} +break;case options.multiple&&$.trim(options.multipleSeparator)==","&&KEY.COMMA:case KEY.TAB:case KEY.RETURN:if(selectCurrent()){event.preventDefault();blockSubmit=true;return false;} +break;case KEY.ESC:select.hide();break;default:clearTimeout(timeout);timeout=setTimeout(onChange,options.delay);break;}}).focus(function(){hasFocus++;}).blur(function(){hasFocus=0;if(!config.mouseDownOnSelect){hideResults();}}).click(function(){if(hasFocus++>1&&!select.visible()){onChange(0,true);}}).bind("search",function(){var fn=(arguments.length>1)?arguments[1]:null;function findValueCallback(q,data){var result;if(data&&data.length){for(var i=0;i1){v=words.slice(0,words.length-1).join(options.multipleSeparator)+options.multipleSeparator+v;} +v+=options.multipleSeparator;} +$input.val(v);hideResultsNow();$input.trigger("result",[selected.data,selected.value]);return true;} +function onChange(crap,skipPrevCheck){if(lastKeyPressCode==KEY.DEL){select.hide();return;} +var currentValue=$input.val();if(!skipPrevCheck&¤tValue==previousValue) +return;previousValue=currentValue;currentValue=lastWord(currentValue);if(currentValue.length>=options.minChars){$input.addClass(options.loadingClass);if(!options.matchCase) +currentValue=currentValue.toLowerCase();request(currentValue,receiveData,hideResultsNow);}else{stopLoading();select.hide();}};function trimWords(value){if(!value){return[""];} +var words=value.split(options.multipleSeparator);var result=[];$.each(words,function(i,value){if($.trim(value)) +result[i]=$.trim(value);});return result;} +function lastWord(value){if(!options.multiple) +return value;var words=trimWords(value);return words[words.length-1];} +function autoFill(q,sValue){if(options.autoFill&&(lastWord($input.val()).toLowerCase()==q.toLowerCase())&&lastKeyPressCode!=KEY.BACKSPACE){$input.val($input.val()+sValue.substring(lastWord(previousValue).length));$.Autocompleter.Selection(input,previousValue.length,previousValue.length+sValue.length);}};function hideResults(){clearTimeout(timeout);timeout=setTimeout(hideResultsNow,200);};function hideResultsNow(){var wasVisible=select.visible();select.hide();clearTimeout(timeout);stopLoading();if(options.mustMatch){$input.search(function(result){if(!result){if(options.multiple){var words=trimWords($input.val()).slice(0,-1);$input.val(words.join(options.multipleSeparator)+(words.length?options.multipleSeparator:""));} +else +$input.val("");}});} +if(wasVisible) +$.Autocompleter.Selection(input,input.value.length,input.value.length);};function receiveData(q,data){if(data&&data.length&&hasFocus){stopLoading();select.display(data,q);autoFill(q,data[0].value);select.show();}else{hideResultsNow();}};function request(term,success,failure){if(!options.matchCase) +term=term.toLowerCase();var data=cache.load(term);if(data&&data.length){success(term,data);}else if((typeof options.url=="string")&&(options.url.length>0)){var extraParams={timestamp:+new Date()};$.each(options.extraParams,function(key,param){extraParams[key]=typeof param=="function"?param():param;});$.ajax({mode:"abort",port:"autocomplete"+input.name,dataType:options.dataType,url:options.url,data:$.extend({q:lastWord(term),limit:options.max},extraParams),success:function(data){var parsed=options.parse&&options.parse(data)||parse(data);cache.add(term,parsed);success(term,parsed);}});}else{select.emptyList();failure(term);}};function parse(data){var parsed=[];var rows=data.split("\n");for(var i=0;i]*)("+term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi,"\\$1")+")(?![^<>]*>)(?![^&;]+;)","gi"),"$1");},scroll:true,scrollHeight:180};$.Autocompleter.Cache=function(options){var data={};var length=0;function matchSubset(s,sub){if(!options.matchCase) +s=s.toLowerCase();var i=s.indexOf(sub);if(i==-1)return false;return i==0||options.matchContains;};function add(q,value){if(length>options.cacheLength){flush();} +if(!data[q]){length++;} +data[q]=value;} +function populate(){if(!options.data)return false;var stMatchSets={},nullData=0;if(!options.url)options.cacheLength=1;stMatchSets[""]=[];for(var i=0,ol=options.data.length;i0){var c=data[k];$.each(c,function(i,x){if(matchSubset(x.value,q)){csub.push(x);}});}} +return csub;}else +if(data[q]){return data[q];}else +if(options.matchSubset){for(var i=q.length-1;i>=options.minChars;i--){var c=data[q.substr(0,i)];if(c){var csub=[];$.each(c,function(i,x){if(matchSubset(x.value,q)){csub[csub.length]=x;}});return csub;}}} +return null;}};};$.Autocompleter.Select=function(options,input,select,config){var CLASSES={ACTIVE:"ac_over"};var listItems,active=-1,data,term="",needsInit=true,element,list;function init(){if(!needsInit) +return;element=$("
").hide().addClass(options.resultsClass).css("position","absolute").appendTo(document.body);list=$("
    ").appendTo(element).mouseover(function(event){if(target(event).nodeName&&target(event).nodeName.toUpperCase()=='LI'){active=$("li",list).removeClass(CLASSES.ACTIVE).index(target(event));$(target(event)).addClass(CLASSES.ACTIVE);}}).click(function(event){$(target(event)).addClass(CLASSES.ACTIVE);select();input.focus();return false;}).mousedown(function(){config.mouseDownOnSelect=true;}).mouseup(function(){config.mouseDownOnSelect=false;});if(options.width>0) +element.css("width",options.width);needsInit=false;} +function target(event){var element=event.target;while(element&&element.tagName!="LI") +element=element.parentNode;if(!element) +return[];return element;} +function moveSelect(step){listItems.slice(active,active+1).removeClass(CLASSES.ACTIVE);movePosition(step);var activeItem=listItems.slice(active,active+1).addClass(CLASSES.ACTIVE);if(options.scroll){var offset=0;listItems.slice(0,active).each(function(){offset+=this.offsetHeight;});if((offset+activeItem[0].offsetHeight-list.scrollTop())>list[0].clientHeight){list.scrollTop(offset+activeItem[0].offsetHeight-list.innerHeight());}else if(offset=listItems.size()){active=0;}} +function limitNumberOfItems(available){return options.max&&options.max").html(options.highlight(formatted,term)).addClass(i%2==0?"ac_even":"ac_odd").appendTo(list)[0];$.data(li,"ac_data",data[i]);} +listItems=list.find("li");if(options.selectFirst){listItems.slice(0,1).addClass(CLASSES.ACTIVE);active=0;} +if($.fn.bgiframe) +list.bgiframe();} +return{display:function(d,q){init();data=d;term=q;fillList();},next:function(){moveSelect(1);},prev:function(){moveSelect(-1);},pageUp:function(){if(active!=0&&active-8<0){moveSelect(-active);}else{moveSelect(-8);}},pageDown:function(){if(active!=listItems.size()-1&&active+8>listItems.size()){moveSelect(listItems.size()-1-active);}else{moveSelect(8);}},hide:function(){element&&element.hide();listItems&&listItems.removeClass(CLASSES.ACTIVE);active=-1;},visible:function(){return element&&element.is(":visible");},current:function(){return this.visible()&&(listItems.filter("."+CLASSES.ACTIVE)[0]||options.selectFirst&&listItems[0]);},show:function(){var offset=$(input).offset();element.css({width:typeof options.width=="string"||options.width>0?options.width:$(input).width(),top:offset.top+input.offsetHeight,left:offset.left}).show();if(options.scroll){list.scrollTop(0);list.css({maxHeight:options.scrollHeight,overflow:'auto'});if($.browser.msie&&typeof document.body.style.maxHeight==="undefined"){var listHeight=0;listItems.each(function(){listHeight+=this.offsetHeight;});var scrollbarsVisible=listHeight>options.scrollHeight;list.css('height',scrollbarsVisible?options.scrollHeight:listHeight);if(!scrollbarsVisible){listItems.width(list.width()-parseInt(listItems.css("padding-left"))-parseInt(listItems.css("padding-right")));}}}},selected:function(){var selected=listItems&&listItems.filter("."+CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);return selected&&selected.length&&$.data(selected[0],"ac_data");},emptyList:function(){list&&list.empty();},unbind:function(){element&&element.remove();}};};$.Autocompleter.Selection=function(field,start,end){if(field.createTextRange){var selRange=field.createTextRange();selRange.collapse(true);selRange.moveStart("character",start);selRange.moveEnd("character",end);selRange.select();}else if(field.setSelectionRange){field.setSelectionRange(start,end);}else{if(field.selectionStart){field.selectionStart=start;field.selectionEnd=end;}} +field.focus();};})(jQuery); \ No newline at end of file diff --git a/demo/static/js/jquery.formset.min.js b/demo/static/js/jquery.formset.min.js new file mode 100644 index 0000000..b3bf8bb --- /dev/null +++ b/demo/static/js/jquery.formset.min.js @@ -0,0 +1,10 @@ +(function($){$.fn.formset=function(opts) +{var options=$.extend({},$.fn.formset.defaults,opts);var updateElementIndex=function(el,prefix,ndx){var id_regex=new RegExp('('+prefix+'-\\d+)');var replacement=prefix+'-'+ndx;if($(el).attr("for"))$(el).attr("for",$(el).attr("for").replace(id_regex,replacement));if(el.id)el.id=el.id.replace(id_regex,replacement);if(el.name)el.name=el.name.replace(id_regex,replacement);};$(this).each(function(i){$(this).addClass('dynamic-form');if($(this).attr('tagName')=='TR'){$(this).children(':last').append(''+options.deleteText+'');}else{$(this).append(''+options.deleteText+'');} +$(this).find('a.'+options.deleteCssClass).click(function(){var row=$(this).parents('.dynamic-form');row.remove();if(options.removed)options.removed(row);var forms=$('.dynamic-form');$('#id_'+options.prefix+'-TOTAL_FORMS').val(forms.length);if(forms.length==1){$('a.'+options.deleteCssClass).hide();} +for(var i=0,formCount=forms.length;i'+options.addText+'');}else{$(this).filter(':last').after(''+options.addText+'');} +$(this).parent().find('a.'+options.addCssClass).click(function(){var nextIndex=parseInt($('#id_'+options.prefix+'-TOTAL_FORMS').val());var row=$('.dynamic-form:first').clone(true).get(0);$(row).removeAttr('id').insertAfter($('.dynamic-form:last'));$(row).find('input,select,textarea,label').each(function(){updateElementIndex(this,options.prefix,nextIndex);$(this).val('');});var formCount=nextIndex+1;$('#id_'+options.prefix+'-TOTAL_FORMS').val(formCount);if(formCount>1){$('a.'+options.deleteCssClass).show();} +if(options.added)options.added($(row));return false;});} +if($(this).length==1){$('a.'+options.deleteCssClass).hide();} +return $(this);} +$.fn.formset.defaults={prefix:'form',addText:'add another',deleteText:'remove',addCssClass:'add-row',deleteCssClass:'delete-row',added:null,removed:null}})(jQuery) diff --git a/demo/static/js/jquery.js b/demo/static/js/jquery.js new file mode 100644 index 0000000..82b98e1 --- /dev/null +++ b/demo/static/js/jquery.js @@ -0,0 +1,32 @@ +/* + * jQuery 1.2.6 - New Wave Javascript + * + * Copyright (c) 2008 John Resig (jquery.com) + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * $Date: 2008-05-24 14:22:17 -0400 (Sat, 24 May 2008) $ + * $Rev: 5685 $ + */ +(function(){var _jQuery=window.jQuery,_$=window.$;var jQuery=window.jQuery=window.$=function(selector,context){return new jQuery.fn.init(selector,context);};var quickExpr=/^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/,isSimple=/^.[^:#\[\.]*$/,undefined;jQuery.fn=jQuery.prototype={init:function(selector,context){selector=selector||document;if(selector.nodeType){this[0]=selector;this.length=1;return this;}if(typeof selector=="string"){var match=quickExpr.exec(selector);if(match&&(match[1]||!context)){if(match[1])selector=jQuery.clean([match[1]],context);else{var elem=document.getElementById(match[3]);if(elem){if(elem.id!=match[3])return jQuery().find(selector);return jQuery(elem);}selector=[];}}else +return jQuery(context).find(selector);}else if(jQuery.isFunction(selector))return jQuery(document)[jQuery.fn.ready?"ready":"load"](selector);return this.setArray(jQuery.makeArray(selector));},jquery:"1.2.6",size:function(){return this.length;},length:0,get:function(num){return num==undefined?jQuery.makeArray(this):this[num];},pushStack:function(elems){var ret=jQuery(elems);ret.prevObject=this;return ret;},setArray:function(elems){this.length=0;Array.prototype.push.apply(this,elems);return this;},each:function(callback,args){return jQuery.each(this,callback,args);},index:function(elem){var ret=-1;return jQuery.inArray(elem&&elem.jquery?elem[0]:elem,this);},attr:function(name,value,type){var options=name;if(name.constructor==String)if(value===undefined)return this[0]&&jQuery[type||"attr"](this[0],name);else{options={};options[name]=value;}return this.each(function(i){for(name in options)jQuery.attr(type?this.style:this,name,jQuery.prop(this,options[name],type,i,name));});},css:function(key,value){if((key=='width'||key=='height')&&parseFloat(value)<0)value=undefined;return this.attr(key,value,"curCSS");},text:function(text){if(typeof text!="object"&&text!=null)return this.empty().append((this[0]&&this[0].ownerDocument||document).createTextNode(text));var ret="";jQuery.each(text||this,function(){jQuery.each(this.childNodes,function(){if(this.nodeType!=8)ret+=this.nodeType!=1?this.nodeValue:jQuery.fn.text([this]);});});return ret;},wrapAll:function(html){if(this[0])jQuery(html,this[0].ownerDocument).clone().insertBefore(this[0]).map(function(){var elem=this;while(elem.firstChild)elem=elem.firstChild;return elem;}).append(this);return this;},wrapInner:function(html){return this.each(function(){jQuery(this).contents().wrapAll(html);});},wrap:function(html){return this.each(function(){jQuery(this).wrapAll(html);});},append:function(){return this.domManip(arguments,true,false,function(elem){if(this.nodeType==1)this.appendChild(elem);});},prepend:function(){return this.domManip(arguments,true,true,function(elem){if(this.nodeType==1)this.insertBefore(elem,this.firstChild);});},before:function(){return this.domManip(arguments,false,false,function(elem){this.parentNode.insertBefore(elem,this);});},after:function(){return this.domManip(arguments,false,true,function(elem){this.parentNode.insertBefore(elem,this.nextSibling);});},end:function(){return this.prevObject||jQuery([]);},find:function(selector){var elems=jQuery.map(this,function(elem){return jQuery.find(selector,elem);});return this.pushStack(/[^+>] [^+>]/.test(selector)||selector.indexOf("..")>-1?jQuery.unique(elems):elems);},clone:function(events){var ret=this.map(function(){if(jQuery.browser.msie&&!jQuery.isXMLDoc(this)){var clone=this.cloneNode(true),container=document.createElement("div");container.appendChild(clone);return jQuery.clean([container.innerHTML])[0];}else +return this.cloneNode(true);});var clone=ret.find("*").andSelf().each(function(){if(this[expando]!=undefined)this[expando]=null;});if(events===true)this.find("*").andSelf().each(function(i){if(this.nodeType==3)return;var events=jQuery.data(this,"events");for(var type in events)for(var handler in events[type])jQuery.event.add(clone[i],type,events[type][handler],events[type][handler].data);});return ret;},filter:function(selector){return this.pushStack(jQuery.isFunction(selector)&&jQuery.grep(this,function(elem,i){return selector.call(elem,i);})||jQuery.multiFilter(selector,this));},not:function(selector){if(selector.constructor==String)if(isSimple.test(selector))return this.pushStack(jQuery.multiFilter(selector,this,true));else +selector=jQuery.multiFilter(selector,this);var isArrayLike=selector.length&&selector[selector.length-1]!==undefined&&!selector.nodeType;return this.filter(function(){return isArrayLike?jQuery.inArray(this,selector)<0:this!=selector;});},add:function(selector){return this.pushStack(jQuery.unique(jQuery.merge(this.get(),typeof selector=='string'?jQuery(selector):jQuery.makeArray(selector))));},is:function(selector){return!!selector&&jQuery.multiFilter(selector,this).length>0;},hasClass:function(selector){return this.is("."+selector);},val:function(value){if(value==undefined){if(this.length){var elem=this[0];if(jQuery.nodeName(elem,"select")){var index=elem.selectedIndex,values=[],options=elem.options,one=elem.type=="select-one";if(index<0)return null;for(var i=one?index:0,max=one?index+1:options.length;i=0||jQuery.inArray(this.name,value)>=0);else if(jQuery.nodeName(this,"select")){var values=jQuery.makeArray(value);jQuery("option",this).each(function(){this.selected=(jQuery.inArray(this.value,values)>=0||jQuery.inArray(this.text,values)>=0);});if(!values.length)this.selectedIndex=-1;}else +this.value=value;});},html:function(value){return value==undefined?(this[0]?this[0].innerHTML:null):this.empty().append(value);},replaceWith:function(value){return this.after(value).remove();},eq:function(i){return this.slice(i,i+1);},slice:function(){return this.pushStack(Array.prototype.slice.apply(this,arguments));},map:function(callback){return this.pushStack(jQuery.map(this,function(elem,i){return callback.call(elem,i,elem);}));},andSelf:function(){return this.add(this.prevObject);},data:function(key,value){var parts=key.split(".");parts[1]=parts[1]?"."+parts[1]:"";if(value===undefined){var data=this.triggerHandler("getData"+parts[1]+"!",[parts[0]]);if(data===undefined&&this.length)data=jQuery.data(this[0],key);return data===undefined&&parts[1]?this.data(parts[0]):data;}else +return this.trigger("setData"+parts[1]+"!",[parts[0],value]).each(function(){jQuery.data(this,key,value);});},removeData:function(key){return this.each(function(){jQuery.removeData(this,key);});},domManip:function(args,table,reverse,callback){var clone=this.length>1,elems;return this.each(function(){if(!elems){elems=jQuery.clean(args,this.ownerDocument);if(reverse)elems.reverse();}var obj=this;if(table&&jQuery.nodeName(this,"table")&&jQuery.nodeName(elems[0],"tr"))obj=this.getElementsByTagName("tbody")[0]||this.appendChild(this.ownerDocument.createElement("tbody"));var scripts=jQuery([]);jQuery.each(elems,function(){var elem=clone?jQuery(this).clone(true)[0]:this;if(jQuery.nodeName(elem,"script"))scripts=scripts.add(elem);else{if(elem.nodeType==1)scripts=scripts.add(jQuery("script",elem).remove());callback.call(obj,elem);}});scripts.each(evalScript);});}};jQuery.fn.init.prototype=jQuery.fn;function evalScript(i,elem){if(elem.src)jQuery.ajax({url:elem.src,async:false,dataType:"script"});else +jQuery.globalEval(elem.text||elem.textContent||elem.innerHTML||"");if(elem.parentNode)elem.parentNode.removeChild(elem);}function now(){return+new Date;}jQuery.extend=jQuery.fn.extend=function(){var target=arguments[0]||{},i=1,length=arguments.length,deep=false,options;if(target.constructor==Boolean){deep=target;target=arguments[1]||{};i=2;}if(typeof target!="object"&&typeof target!="function")target={};if(length==i){target=this;--i;}for(;i-1;}},swap:function(elem,options,callback){var old={};for(var name in options){old[name]=elem.style[name];elem.style[name]=options[name];}callback.call(elem);for(var name in options)elem.style[name]=old[name];},css:function(elem,name,force){if(name=="width"||name=="height"){var val,props={position:"absolute",visibility:"hidden",display:"block"},which=name=="width"?["Left","Right"]:["Top","Bottom"];function getWH(){val=name=="width"?elem.offsetWidth:elem.offsetHeight;var padding=0,border=0;jQuery.each(which,function(){padding+=parseFloat(jQuery.curCSS(elem,"padding"+this,true))||0;border+=parseFloat(jQuery.curCSS(elem,"border"+this+"Width",true))||0;});val-=Math.round(padding+border);}if(jQuery(elem).is(":visible"))getWH();else +jQuery.swap(elem,props,getWH);return Math.max(0,val);}return jQuery.curCSS(elem,name,force);},curCSS:function(elem,name,force){var ret,style=elem.style;function color(elem){if(!jQuery.browser.safari)return false;var ret=defaultView.getComputedStyle(elem,null);return!ret||ret.getPropertyValue("color")=="";}if(name=="opacity"&&jQuery.browser.msie){ret=jQuery.attr(style,"opacity");return ret==""?"1":ret;}if(jQuery.browser.opera&&name=="display"){var save=style.outline;style.outline="0 solid black";style.outline=save;}if(name.match(/float/i))name=styleFloat;if(!force&&style&&style[name])ret=style[name];else if(defaultView.getComputedStyle){if(name.match(/float/i))name="float";name=name.replace(/([A-Z])/g,"-$1").toLowerCase();var computedStyle=defaultView.getComputedStyle(elem,null);if(computedStyle&&!color(elem))ret=computedStyle.getPropertyValue(name);else{var swap=[],stack=[],a=elem,i=0;for(;a&&color(a);a=a.parentNode)stack.unshift(a);for(;i]*?)\/>/g,function(all,front,tag){return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i)?all:front+">";});var tags=jQuery.trim(elem).toLowerCase(),div=context.createElement("div");var wrap=!tags.indexOf("",""]||!tags.indexOf("",""]||tags.match(/^<(thead|tbody|tfoot|colg|cap)/)&&[1,"","
    "]||!tags.indexOf("",""]||(!tags.indexOf("",""]||!tags.indexOf("",""]||jQuery.browser.msie&&[1,"div
    ","
    "]||[0,"",""];div.innerHTML=wrap[1]+elem+wrap[2];while(wrap[0]--)div=div.lastChild;if(jQuery.browser.msie){var tbody=!tags.indexOf(""&&tags.indexOf("=0;--j)if(jQuery.nodeName(tbody[j],"tbody")&&!tbody[j].childNodes.length)tbody[j].parentNode.removeChild(tbody[j]);if(/^\s/.test(elem))div.insertBefore(context.createTextNode(elem.match(/^\s*/)[0]),div.firstChild);}elem=jQuery.makeArray(div.childNodes);}if(elem.length===0&&(!jQuery.nodeName(elem,"form")&&!jQuery.nodeName(elem,"select")))return;if(elem[0]==undefined||jQuery.nodeName(elem,"form")||elem.options)ret.push(elem);else +ret=jQuery.merge(ret,elem);});return ret;},attr:function(elem,name,value){if(!elem||elem.nodeType==3||elem.nodeType==8)return undefined;var notxml=!jQuery.isXMLDoc(elem),set=value!==undefined,msie=jQuery.browser.msie;name=notxml&&jQuery.props[name]||name;if(elem.tagName){var special=/href|src|style/.test(name);if(name=="selected"&&jQuery.browser.safari)elem.parentNode.selectedIndex;if(name in elem&¬xml&&!special){if(set){if(name=="type"&&jQuery.nodeName(elem,"input")&&elem.parentNode)throw"type property can't be changed";elem[name]=value;}if(jQuery.nodeName(elem,"form")&&elem.getAttributeNode(name))return elem.getAttributeNode(name).nodeValue;return elem[name];}if(msie&¬xml&&name=="style")return jQuery.attr(elem.style,"cssText",value);if(set)elem.setAttribute(name,""+value);var attr=msie&¬xml&&special?elem.getAttribute(name,2):elem.getAttribute(name);return attr===null?undefined:attr;}if(msie&&name=="opacity"){if(set){elem.zoom=1;elem.filter=(elem.filter||"").replace(/alpha\([^)]*\)/,"")+(parseInt(value)+''=="NaN"?"":"alpha(opacity="+value*100+")");}return elem.filter&&elem.filter.indexOf("opacity=")>=0?(parseFloat(elem.filter.match(/opacity=([^)]*)/)[1])/100)+'':"";}name=name.replace(/-([a-z])/ig,function(all,letter){return letter.toUpperCase();});if(set)elem[name]=value;return elem[name];},trim:function(text){return(text||"").replace(/^\s+|\s+$/g,"");},makeArray:function(array){var ret=[];if(array!=null){var i=array.length;if(i==null||array.split||array.setInterval||array.call)ret[0]=array;else +while(i)ret[--i]=array[i];}return ret;},inArray:function(elem,array){for(var i=0,length=array.length;i*",this).remove();while(this.firstChild)this.removeChild(this.firstChild);}},function(name,fn){jQuery.fn[name]=function(){return this.each(fn,arguments);};});jQuery.each(["Height","Width"],function(i,name){var type=name.toLowerCase();jQuery.fn[type]=function(size){return this[0]==window?jQuery.browser.opera&&document.body["client"+name]||jQuery.browser.safari&&window["inner"+name]||document.compatMode=="CSS1Compat"&&document.documentElement["client"+name]||document.body["client"+name]:this[0]==document?Math.max(Math.max(document.body["scroll"+name],document.documentElement["scroll"+name]),Math.max(document.body["offset"+name],document.documentElement["offset"+name])):size==undefined?(this.length?jQuery.css(this[0],type):null):this.css(type,size.constructor==String?size:size+"px");};});function num(elem,prop){return elem[0]&&parseInt(jQuery.curCSS(elem[0],prop,true),10)||0;}var chars=jQuery.browser.safari&&parseInt(jQuery.browser.version)<417?"(?:[\\w*_-]|\\\\.)":"(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",quickChild=new RegExp("^>\\s*("+chars+"+)"),quickID=new RegExp("^("+chars+"+)(#)("+chars+"+)"),quickClass=new RegExp("^([#.]?)("+chars+"*)");jQuery.extend({expr:{"":function(a,i,m){return m[2]=="*"||jQuery.nodeName(a,m[2]);},"#":function(a,i,m){return a.getAttribute("id")==m[2];},":":{lt:function(a,i,m){return im[3]-0;},nth:function(a,i,m){return m[3]-0==i;},eq:function(a,i,m){return m[3]-0==i;},first:function(a,i){return i==0;},last:function(a,i,m,r){return i==r.length-1;},even:function(a,i){return i%2==0;},odd:function(a,i){return i%2;},"first-child":function(a){return a.parentNode.getElementsByTagName("*")[0]==a;},"last-child":function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;},"only-child":function(a){return!jQuery.nth(a.parentNode.lastChild,2,"previousSibling");},parent:function(a){return a.firstChild;},empty:function(a){return!a.firstChild;},contains:function(a,i,m){return(a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;},visible:function(a){return"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";},hidden:function(a){return"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";},enabled:function(a){return!a.disabled;},disabled:function(a){return a.disabled;},checked:function(a){return a.checked;},selected:function(a){return a.selected||jQuery.attr(a,"selected");},text:function(a){return"text"==a.type;},radio:function(a){return"radio"==a.type;},checkbox:function(a){return"checkbox"==a.type;},file:function(a){return"file"==a.type;},password:function(a){return"password"==a.type;},submit:function(a){return"submit"==a.type;},image:function(a){return"image"==a.type;},reset:function(a){return"reset"==a.type;},button:function(a){return"button"==a.type||jQuery.nodeName(a,"button");},input:function(a){return/input|select|textarea|button/i.test(a.nodeName);},has:function(a,i,m){return jQuery.find(m[3],a).length;},header:function(a){return/h\d/i.test(a.nodeName);},animated:function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;}}},parse:[/^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,/^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,new RegExp("^([:.#]*)("+chars+"+)")],multiFilter:function(expr,elems,not){var old,cur=[];while(expr&&expr!=old){old=expr;var f=jQuery.filter(expr,elems,not);expr=f.t.replace(/^\s*,\s*/,"");cur=not?elems=f.r:jQuery.merge(cur,f.r);}return cur;},find:function(t,context){if(typeof t!="string")return[t];if(context&&context.nodeType!=1&&context.nodeType!=9)return[];context=context||document;var ret=[context],done=[],last,nodeName;while(t&&last!=t){var r=[];last=t;t=jQuery.trim(t);var foundToken=false,re=quickChild,m=re.exec(t);if(m){nodeName=m[1].toUpperCase();for(var i=0;ret[i];i++)for(var c=ret[i].firstChild;c;c=c.nextSibling)if(c.nodeType==1&&(nodeName=="*"||c.nodeName.toUpperCase()==nodeName))r.push(c);ret=r;t=t.replace(re,"");if(t.indexOf(" ")==0)continue;foundToken=true;}else{re=/^([>+~])\s*(\w*)/i;if((m=re.exec(t))!=null){r=[];var merge={};nodeName=m[2].toUpperCase();m=m[1];for(var j=0,rl=ret.length;j=0;if(!not&&pass||not&&!pass)tmp.push(r[i]);}return tmp;},filter:function(t,r,not){var last;while(t&&t!=last){last=t;var p=jQuery.parse,m;for(var i=0;p[i];i++){m=p[i].exec(t);if(m){t=t.substring(m[0].length);m[2]=m[2].replace(/\\/g,"");break;}}if(!m)break;if(m[1]==":"&&m[2]=="not")r=isSimple.test(m[3])?jQuery.filter(m[3],r,true).r:jQuery(r).not(m[3]);else if(m[1]==".")r=jQuery.classFilter(r,m[2],not);else if(m[1]=="["){var tmp=[],type=m[3];for(var i=0,rl=r.length;i=0)^not)tmp.push(a);}r=tmp;}else if(m[1]==":"&&m[2]=="nth-child"){var merge={},tmp=[],test=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(m[3]=="even"&&"2n"||m[3]=="odd"&&"2n+1"||!/\D/.test(m[3])&&"0n+"+m[3]||m[3]),first=(test[1]+(test[2]||1))-0,last=test[3]-0;for(var i=0,rl=r.length;i=0)add=true;if(add^not)tmp.push(node);}r=tmp;}else{var fn=jQuery.expr[m[1]];if(typeof fn=="object")fn=fn[m[2]];if(typeof fn=="string")fn=eval("false||function(a,i){return "+fn+";}");r=jQuery.grep(r,function(elem,i){return fn(elem,i,m,r);},not);}}return{r:r,t:t};},dir:function(elem,dir){var matched=[],cur=elem[dir];while(cur&&cur!=document){if(cur.nodeType==1)matched.push(cur);cur=cur[dir];}return matched;},nth:function(cur,result,dir,elem){result=result||1;var num=0;for(;cur;cur=cur[dir])if(cur.nodeType==1&&++num==result)break;return cur;},sibling:function(n,elem){var r=[];for(;n;n=n.nextSibling){if(n.nodeType==1&&n!=elem)r.push(n);}return r;}});jQuery.event={add:function(elem,types,handler,data){if(elem.nodeType==3||elem.nodeType==8)return;if(jQuery.browser.msie&&elem.setInterval)elem=window;if(!handler.guid)handler.guid=this.guid++;if(data!=undefined){var fn=handler;handler=this.proxy(fn,function(){return fn.apply(this,arguments);});handler.data=data;}var events=jQuery.data(elem,"events")||jQuery.data(elem,"events",{}),handle=jQuery.data(elem,"handle")||jQuery.data(elem,"handle",function(){if(typeof jQuery!="undefined"&&!jQuery.event.triggered)return jQuery.event.handle.apply(arguments.callee.elem,arguments);});handle.elem=elem;jQuery.each(types.split(/\s+/),function(index,type){var parts=type.split(".");type=parts[0];handler.type=parts[1];var handlers=events[type];if(!handlers){handlers=events[type]={};if(!jQuery.event.special[type]||jQuery.event.special[type].setup.call(elem)===false){if(elem.addEventListener)elem.addEventListener(type,handle,false);else if(elem.attachEvent)elem.attachEvent("on"+type,handle);}}handlers[handler.guid]=handler;jQuery.event.global[type]=true;});elem=null;},guid:1,global:{},remove:function(elem,types,handler){if(elem.nodeType==3||elem.nodeType==8)return;var events=jQuery.data(elem,"events"),ret,index;if(events){if(types==undefined||(typeof types=="string"&&types.charAt(0)=="."))for(var type in events)this.remove(elem,type+(types||""));else{if(types.type){handler=types.handler;types=types.type;}jQuery.each(types.split(/\s+/),function(index,type){var parts=type.split(".");type=parts[0];if(events[type]){if(handler)delete events[type][handler.guid];else +for(handler in events[type])if(!parts[1]||events[type][handler].type==parts[1])delete events[type][handler];for(ret in events[type])break;if(!ret){if(!jQuery.event.special[type]||jQuery.event.special[type].teardown.call(elem)===false){if(elem.removeEventListener)elem.removeEventListener(type,jQuery.data(elem,"handle"),false);else if(elem.detachEvent)elem.detachEvent("on"+type,jQuery.data(elem,"handle"));}ret=null;delete events[type];}}});}for(ret in events)break;if(!ret){var handle=jQuery.data(elem,"handle");if(handle)handle.elem=null;jQuery.removeData(elem,"events");jQuery.removeData(elem,"handle");}}},trigger:function(type,data,elem,donative,extra){data=jQuery.makeArray(data);if(type.indexOf("!")>=0){type=type.slice(0,-1);var exclusive=true;}if(!elem){if(this.global[type])jQuery("*").add([window,document]).trigger(type,data);}else{if(elem.nodeType==3||elem.nodeType==8)return undefined;var val,ret,fn=jQuery.isFunction(elem[type]||null),event=!data[0]||!data[0].preventDefault;if(event){data.unshift({type:type,target:elem,preventDefault:function(){},stopPropagation:function(){},timeStamp:now()});data[0][expando]=true;}data[0].type=type;if(exclusive)data[0].exclusive=true;var handle=jQuery.data(elem,"handle");if(handle)val=handle.apply(elem,data);if((!fn||(jQuery.nodeName(elem,'a')&&type=="click"))&&elem["on"+type]&&elem["on"+type].apply(elem,data)===false)val=false;if(event)data.shift();if(extra&&jQuery.isFunction(extra)){ret=extra.apply(elem,val==null?data:data.concat(val));if(ret!==undefined)val=ret;}if(fn&&donative!==false&&val!==false&&!(jQuery.nodeName(elem,'a')&&type=="click")){this.triggered=true;try{elem[type]();}catch(e){}}this.triggered=false;}return val;},handle:function(event){var val,ret,namespace,all,handlers;event=arguments[0]=jQuery.event.fix(event||window.event);namespace=event.type.split(".");event.type=namespace[0];namespace=namespace[1];all=!namespace&&!event.exclusive;handlers=(jQuery.data(this,"events")||{})[event.type];for(var j in handlers){var handler=handlers[j];if(all||handler.type==namespace){event.handler=handler;event.data=handler.data;ret=handler.apply(this,arguments);if(val!==false)val=ret;if(ret===false){event.preventDefault();event.stopPropagation();}}}return val;},fix:function(event){if(event[expando]==true)return event;var originalEvent=event;event={originalEvent:originalEvent};var props="altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target timeStamp toElement type view wheelDelta which".split(" ");for(var i=props.length;i;i--)event[props[i]]=originalEvent[props[i]];event[expando]=true;event.preventDefault=function(){if(originalEvent.preventDefault)originalEvent.preventDefault();originalEvent.returnValue=false;};event.stopPropagation=function(){if(originalEvent.stopPropagation)originalEvent.stopPropagation();originalEvent.cancelBubble=true;};event.timeStamp=event.timeStamp||now();if(!event.target)event.target=event.srcElement||document;if(event.target.nodeType==3)event.target=event.target.parentNode;if(!event.relatedTarget&&event.fromElement)event.relatedTarget=event.fromElement==event.target?event.toElement:event.fromElement;if(event.pageX==null&&event.clientX!=null){var doc=document.documentElement,body=document.body;event.pageX=event.clientX+(doc&&doc.scrollLeft||body&&body.scrollLeft||0)-(doc.clientLeft||0);event.pageY=event.clientY+(doc&&doc.scrollTop||body&&body.scrollTop||0)-(doc.clientTop||0);}if(!event.which&&((event.charCode||event.charCode===0)?event.charCode:event.keyCode))event.which=event.charCode||event.keyCode;if(!event.metaKey&&event.ctrlKey)event.metaKey=event.ctrlKey;if(!event.which&&event.button)event.which=(event.button&1?1:(event.button&2?3:(event.button&4?2:0)));return event;},proxy:function(fn,proxy){proxy.guid=fn.guid=fn.guid||proxy.guid||this.guid++;return proxy;},special:{ready:{setup:function(){bindReady();return;},teardown:function(){return;}},mouseenter:{setup:function(){if(jQuery.browser.msie)return false;jQuery(this).bind("mouseover",jQuery.event.special.mouseenter.handler);return true;},teardown:function(){if(jQuery.browser.msie)return false;jQuery(this).unbind("mouseover",jQuery.event.special.mouseenter.handler);return true;},handler:function(event){if(withinElement(event,this))return true;event.type="mouseenter";return jQuery.event.handle.apply(this,arguments);}},mouseleave:{setup:function(){if(jQuery.browser.msie)return false;jQuery(this).bind("mouseout",jQuery.event.special.mouseleave.handler);return true;},teardown:function(){if(jQuery.browser.msie)return false;jQuery(this).unbind("mouseout",jQuery.event.special.mouseleave.handler);return true;},handler:function(event){if(withinElement(event,this))return true;event.type="mouseleave";return jQuery.event.handle.apply(this,arguments);}}}};jQuery.fn.extend({bind:function(type,data,fn){return type=="unload"?this.one(type,data,fn):this.each(function(){jQuery.event.add(this,type,fn||data,fn&&data);});},one:function(type,data,fn){var one=jQuery.event.proxy(fn||data,function(event){jQuery(this).unbind(event,one);return(fn||data).apply(this,arguments);});return this.each(function(){jQuery.event.add(this,type,one,fn&&data);});},unbind:function(type,fn){return this.each(function(){jQuery.event.remove(this,type,fn);});},trigger:function(type,data,fn){return this.each(function(){jQuery.event.trigger(type,data,this,true,fn);});},triggerHandler:function(type,data,fn){return this[0]&&jQuery.event.trigger(type,data,this[0],false,fn);},toggle:function(fn){var args=arguments,i=1;while(i=0){var selector=url.slice(off,url.length);url=url.slice(0,off);}callback=callback||function(){};var type="GET";if(params)if(jQuery.isFunction(params)){callback=params;params=null;}else{params=jQuery.param(params);type="POST";}var self=this;jQuery.ajax({url:url,type:type,dataType:"html",data:params,complete:function(res,status){if(status=="success"||status=="notmodified")self.html(selector?jQuery("
    ").append(res.responseText.replace(//g,"")).find(selector):res.responseText);self.each(callback,[res.responseText,status,res]);}});return this;},serialize:function(){return jQuery.param(this.serializeArray());},serializeArray:function(){return this.map(function(){return jQuery.nodeName(this,"form")?jQuery.makeArray(this.elements):this;}).filter(function(){return this.name&&!this.disabled&&(this.checked||/select|textarea/i.test(this.nodeName)||/text|hidden|password/i.test(this.type));}).map(function(i,elem){var val=jQuery(this).val();return val==null?null:val.constructor==Array?jQuery.map(val,function(val,i){return{name:elem.name,value:val};}):{name:elem.name,value:val};}).get();}});jQuery.each("ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","),function(i,o){jQuery.fn[o]=function(f){return this.bind(o,f);};});var jsc=now();jQuery.extend({get:function(url,data,callback,type){if(jQuery.isFunction(data)){callback=data;data=null;}return jQuery.ajax({type:"GET",url:url,data:data,success:callback,dataType:type});},getScript:function(url,callback){return jQuery.get(url,null,callback,"script");},getJSON:function(url,data,callback){return jQuery.get(url,data,callback,"json");},post:function(url,data,callback,type){if(jQuery.isFunction(data)){callback=data;data={};}return jQuery.ajax({type:"POST",url:url,data:data,success:callback,dataType:type});},ajaxSetup:function(settings){jQuery.extend(jQuery.ajaxSettings,settings);},ajaxSettings:{url:location.href,global:true,type:"GET",timeout:0,contentType:"application/x-www-form-urlencoded",processData:true,async:true,data:null,username:null,password:null,accepts:{xml:"application/xml, text/xml",html:"text/html",script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},lastModified:{},ajax:function(s){s=jQuery.extend(true,s,jQuery.extend(true,{},jQuery.ajaxSettings,s));var jsonp,jsre=/=\?(&|$)/g,status,data,type=s.type.toUpperCase();if(s.data&&s.processData&&typeof s.data!="string")s.data=jQuery.param(s.data);if(s.dataType=="jsonp"){if(type=="GET"){if(!s.url.match(jsre))s.url+=(s.url.match(/\?/)?"&":"?")+(s.jsonp||"callback")+"=?";}else if(!s.data||!s.data.match(jsre))s.data=(s.data?s.data+"&":"")+(s.jsonp||"callback")+"=?";s.dataType="json";}if(s.dataType=="json"&&(s.data&&s.data.match(jsre)||s.url.match(jsre))){jsonp="jsonp"+jsc++;if(s.data)s.data=(s.data+"").replace(jsre,"="+jsonp+"$1");s.url=s.url.replace(jsre,"="+jsonp+"$1");s.dataType="script";window[jsonp]=function(tmp){data=tmp;success();complete();window[jsonp]=undefined;try{delete window[jsonp];}catch(e){}if(head)head.removeChild(script);};}if(s.dataType=="script"&&s.cache==null)s.cache=false;if(s.cache===false&&type=="GET"){var ts=now();var ret=s.url.replace(/(\?|&)_=.*?(&|$)/,"$1_="+ts+"$2");s.url=ret+((ret==s.url)?(s.url.match(/\?/)?"&":"?")+"_="+ts:"");}if(s.data&&type=="GET"){s.url+=(s.url.match(/\?/)?"&":"?")+s.data;s.data=null;}if(s.global&&!jQuery.active++)jQuery.event.trigger("ajaxStart");var remote=/^(?:\w+:)?\/\/([^\/?#]+)/;if(s.dataType=="script"&&type=="GET"&&remote.test(s.url)&&remote.exec(s.url)[1]!=location.host){var head=document.getElementsByTagName("head")[0];var script=document.createElement("script");script.src=s.url;if(s.scriptCharset)script.charset=s.scriptCharset;if(!jsonp){var done=false;script.onload=script.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){done=true;success();complete();head.removeChild(script);}};}head.appendChild(script);return undefined;}var requestDone=false;var xhr=window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();if(s.username)xhr.open(type,s.url,s.async,s.username,s.password);else +xhr.open(type,s.url,s.async);try{if(s.data)xhr.setRequestHeader("Content-Type",s.contentType);if(s.ifModified)xhr.setRequestHeader("If-Modified-Since",jQuery.lastModified[s.url]||"Thu, 01 Jan 1970 00:00:00 GMT");xhr.setRequestHeader("X-Requested-With","XMLHttpRequest");xhr.setRequestHeader("Accept",s.dataType&&s.accepts[s.dataType]?s.accepts[s.dataType]+", */*":s.accepts._default);}catch(e){}if(s.beforeSend&&s.beforeSend(xhr,s)===false){s.global&&jQuery.active--;xhr.abort();return false;}if(s.global)jQuery.event.trigger("ajaxSend",[xhr,s]);var onreadystatechange=function(isTimeout){if(!requestDone&&xhr&&(xhr.readyState==4||isTimeout=="timeout")){requestDone=true;if(ival){clearInterval(ival);ival=null;}status=isTimeout=="timeout"&&"timeout"||!jQuery.httpSuccess(xhr)&&"error"||s.ifModified&&jQuery.httpNotModified(xhr,s.url)&&"notmodified"||"success";if(status=="success"){try{data=jQuery.httpData(xhr,s.dataType,s.dataFilter);}catch(e){status="parsererror";}}if(status=="success"){var modRes;try{modRes=xhr.getResponseHeader("Last-Modified");}catch(e){}if(s.ifModified&&modRes)jQuery.lastModified[s.url]=modRes;if(!jsonp)success();}else +jQuery.handleError(s,xhr,status);complete();if(s.async)xhr=null;}};if(s.async){var ival=setInterval(onreadystatechange,13);if(s.timeout>0)setTimeout(function(){if(xhr){xhr.abort();if(!requestDone)onreadystatechange("timeout");}},s.timeout);}try{xhr.send(s.data);}catch(e){jQuery.handleError(s,xhr,null,e);}if(!s.async)onreadystatechange();function success(){if(s.success)s.success(data,status);if(s.global)jQuery.event.trigger("ajaxSuccess",[xhr,s]);}function complete(){if(s.complete)s.complete(xhr,status);if(s.global)jQuery.event.trigger("ajaxComplete",[xhr,s]);if(s.global&&!--jQuery.active)jQuery.event.trigger("ajaxStop");}return xhr;},handleError:function(s,xhr,status,e){if(s.error)s.error(xhr,status,e);if(s.global)jQuery.event.trigger("ajaxError",[xhr,s,e]);},active:0,httpSuccess:function(xhr){try{return!xhr.status&&location.protocol=="file:"||(xhr.status>=200&&xhr.status<300)||xhr.status==304||xhr.status==1223||jQuery.browser.safari&&xhr.status==undefined;}catch(e){}return false;},httpNotModified:function(xhr,url){try{var xhrRes=xhr.getResponseHeader("Last-Modified");return xhr.status==304||xhrRes==jQuery.lastModified[url]||jQuery.browser.safari&&xhr.status==undefined;}catch(e){}return false;},httpData:function(xhr,type,filter){var ct=xhr.getResponseHeader("content-type"),xml=type=="xml"||!type&&ct&&ct.indexOf("xml")>=0,data=xml?xhr.responseXML:xhr.responseText;if(xml&&data.documentElement.tagName=="parsererror")throw"parsererror";if(filter)data=filter(data,type);if(type=="script")jQuery.globalEval(data);if(type=="json")data=eval("("+data+")");return data;},param:function(a){var s=[];if(a.constructor==Array||a.jquery)jQuery.each(a,function(){s.push(encodeURIComponent(this.name)+"="+encodeURIComponent(this.value));});else +for(var j in a)if(a[j]&&a[j].constructor==Array)jQuery.each(a[j],function(){s.push(encodeURIComponent(j)+"="+encodeURIComponent(this));});else +s.push(encodeURIComponent(j)+"="+encodeURIComponent(jQuery.isFunction(a[j])?a[j]():a[j]));return s.join("&").replace(/%20/g,"+");}});jQuery.fn.extend({show:function(speed,callback){return speed?this.animate({height:"show",width:"show",opacity:"show"},speed,callback):this.filter(":hidden").each(function(){this.style.display=this.oldblock||"";if(jQuery.css(this,"display")=="none"){var elem=jQuery("<"+this.tagName+" />").appendTo("body");this.style.display=elem.css("display");if(this.style.display=="none")this.style.display="block";elem.remove();}}).end();},hide:function(speed,callback){return speed?this.animate({height:"hide",width:"hide",opacity:"hide"},speed,callback):this.filter(":visible").each(function(){this.oldblock=this.oldblock||jQuery.css(this,"display");this.style.display="none";}).end();},_toggle:jQuery.fn.toggle,toggle:function(fn,fn2){return jQuery.isFunction(fn)&&jQuery.isFunction(fn2)?this._toggle.apply(this,arguments):fn?this.animate({height:"toggle",width:"toggle",opacity:"toggle"},fn,fn2):this.each(function(){jQuery(this)[jQuery(this).is(":hidden")?"show":"hide"]();});},slideDown:function(speed,callback){return this.animate({height:"show"},speed,callback);},slideUp:function(speed,callback){return this.animate({height:"hide"},speed,callback);},slideToggle:function(speed,callback){return this.animate({height:"toggle"},speed,callback);},fadeIn:function(speed,callback){return this.animate({opacity:"show"},speed,callback);},fadeOut:function(speed,callback){return this.animate({opacity:"hide"},speed,callback);},fadeTo:function(speed,to,callback){return this.animate({opacity:to},speed,callback);},animate:function(prop,speed,easing,callback){var optall=jQuery.speed(speed,easing,callback);return this[optall.queue===false?"each":"queue"](function(){if(this.nodeType!=1)return false;var opt=jQuery.extend({},optall),p,hidden=jQuery(this).is(":hidden"),self=this;for(p in prop){if(prop[p]=="hide"&&hidden||prop[p]=="show"&&!hidden)return opt.complete.call(this);if(p=="height"||p=="width"){opt.display=jQuery.css(this,"display");opt.overflow=this.style.overflow;}}if(opt.overflow!=null)this.style.overflow="hidden";opt.curAnim=jQuery.extend({},prop);jQuery.each(prop,function(name,val){var e=new jQuery.fx(self,opt,name);if(/toggle|show|hide/.test(val))e[val=="toggle"?hidden?"show":"hide":val](prop);else{var parts=val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),start=e.cur(true)||0;if(parts){var end=parseFloat(parts[2]),unit=parts[3]||"px";if(unit!="px"){self.style[name]=(end||1)+unit;start=((end||1)/e.cur(true))*start;self.style[name]=start+unit;}if(parts[1])end=((parts[1]=="-="?-1:1)*end)+start;e.custom(start,end,unit);}else +e.custom(start,val,"");}});return true;});},queue:function(type,fn){if(jQuery.isFunction(type)||(type&&type.constructor==Array)){fn=type;type="fx";}if(!type||(typeof type=="string"&&!fn))return queue(this[0],type);return this.each(function(){if(fn.constructor==Array)queue(this,type,fn);else{queue(this,type).push(fn);if(queue(this,type).length==1)fn.call(this);}});},stop:function(clearQueue,gotoEnd){var timers=jQuery.timers;if(clearQueue)this.queue([]);this.each(function(){for(var i=timers.length-1;i>=0;i--)if(timers[i].elem==this){if(gotoEnd)timers[i](true);timers.splice(i,1);}});if(!gotoEnd)this.dequeue();return this;}});var queue=function(elem,type,array){if(elem){type=type||"fx";var q=jQuery.data(elem,type+"queue");if(!q||array)q=jQuery.data(elem,type+"queue",jQuery.makeArray(array));}return q;};jQuery.fn.dequeue=function(type){type=type||"fx";return this.each(function(){var q=queue(this,type);q.shift();if(q.length)q[0].call(this);});};jQuery.extend({speed:function(speed,easing,fn){var opt=speed&&speed.constructor==Object?speed:{complete:fn||!fn&&easing||jQuery.isFunction(speed)&&speed,duration:speed,easing:fn&&easing||easing&&easing.constructor!=Function&&easing};opt.duration=(opt.duration&&opt.duration.constructor==Number?opt.duration:jQuery.fx.speeds[opt.duration])||jQuery.fx.speeds.def;opt.old=opt.complete;opt.complete=function(){if(opt.queue!==false)jQuery(this).dequeue();if(jQuery.isFunction(opt.old))opt.old.call(this);};return opt;},easing:{linear:function(p,n,firstNum,diff){return firstNum+diff*p;},swing:function(p,n,firstNum,diff){return((-Math.cos(p*Math.PI)/2)+0.5)*diff+firstNum;}},timers:[],timerId:null,fx:function(elem,options,prop){this.options=options;this.elem=elem;this.prop=prop;if(!options.orig)options.orig={};}});jQuery.fx.prototype={update:function(){if(this.options.step)this.options.step.call(this.elem,this.now,this);(jQuery.fx.step[this.prop]||jQuery.fx.step._default)(this);if(this.prop=="height"||this.prop=="width")this.elem.style.display="block";},cur:function(force){if(this.elem[this.prop]!=null&&this.elem.style[this.prop]==null)return this.elem[this.prop];var r=parseFloat(jQuery.css(this.elem,this.prop,force));return r&&r>-10000?r:parseFloat(jQuery.curCSS(this.elem,this.prop))||0;},custom:function(from,to,unit){this.startTime=now();this.start=from;this.end=to;this.unit=unit||this.unit||"px";this.now=this.start;this.pos=this.state=0;this.update();var self=this;function t(gotoEnd){return self.step(gotoEnd);}t.elem=this.elem;jQuery.timers.push(t);if(jQuery.timerId==null){jQuery.timerId=setInterval(function(){var timers=jQuery.timers;for(var i=0;ithis.options.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;var done=true;for(var i in this.options.curAnim)if(this.options.curAnim[i]!==true)done=false;if(done){if(this.options.display!=null){this.elem.style.overflow=this.options.overflow;this.elem.style.display=this.options.display;if(jQuery.css(this.elem,"display")=="none")this.elem.style.display="block";}if(this.options.hide)this.elem.style.display="none";if(this.options.hide||this.options.show)for(var p in this.options.curAnim)jQuery.attr(this.elem.style,p,this.options.orig[p]);}if(done)this.options.complete.call(this.elem);return false;}else{var n=t-this.startTime;this.state=n/this.options.duration;this.pos=jQuery.easing[this.options.easing||(jQuery.easing.swing?"swing":"linear")](this.state,n,0,1,this.options.duration);this.now=this.start+((this.end-this.start)*this.pos);this.update();}return true;}};jQuery.extend(jQuery.fx,{speeds:{slow:600,fast:200,def:400},step:{scrollLeft:function(fx){fx.elem.scrollLeft=fx.now;},scrollTop:function(fx){fx.elem.scrollTop=fx.now;},opacity:function(fx){jQuery.attr(fx.elem.style,"opacity",fx.now);},_default:function(fx){fx.elem.style[fx.prop]=fx.now+fx.unit;}}});jQuery.fn.offset=function(){var left=0,top=0,elem=this[0],results;if(elem)with(jQuery.browser){var parent=elem.parentNode,offsetChild=elem,offsetParent=elem.offsetParent,doc=elem.ownerDocument,safari2=safari&&parseInt(version)<522&&!/adobeair/i.test(userAgent),css=jQuery.curCSS,fixed=css(elem,"position")=="fixed";if(elem.getBoundingClientRect){var box=elem.getBoundingClientRect();add(box.left+Math.max(doc.documentElement.scrollLeft,doc.body.scrollLeft),box.top+Math.max(doc.documentElement.scrollTop,doc.body.scrollTop));add(-doc.documentElement.clientLeft,-doc.documentElement.clientTop);}else{add(elem.offsetLeft,elem.offsetTop);while(offsetParent){add(offsetParent.offsetLeft,offsetParent.offsetTop);if(mozilla&&!/^t(able|d|h)$/i.test(offsetParent.tagName)||safari&&!safari2)border(offsetParent);if(!fixed&&css(offsetParent,"position")=="fixed")fixed=true;offsetChild=/^body$/i.test(offsetParent.tagName)?offsetChild:offsetParent;offsetParent=offsetParent.offsetParent;}while(parent&&parent.tagName&&!/^body|html$/i.test(parent.tagName)){if(!/^inline|table.*$/i.test(css(parent,"display")))add(-parent.scrollLeft,-parent.scrollTop);if(mozilla&&css(parent,"overflow")!="visible")border(parent);parent=parent.parentNode;}if((safari2&&(fixed||css(offsetChild,"position")=="absolute"))||(mozilla&&css(offsetChild,"position")!="absolute"))add(-doc.body.offsetLeft,-doc.body.offsetTop);if(fixed)add(Math.max(doc.documentElement.scrollLeft,doc.body.scrollLeft),Math.max(doc.documentElement.scrollTop,doc.body.scrollTop));}results={top:top,left:left};}function border(elem){add(jQuery.curCSS(elem,"borderLeftWidth",true),jQuery.curCSS(elem,"borderTopWidth",true));}function add(l,t){left+=parseInt(l,10)||0;top+=parseInt(t,10)||0;}return results;};jQuery.fn.extend({position:function(){var left=0,top=0,results;if(this[0]){var offsetParent=this.offsetParent(),offset=this.offset(),parentOffset=/^body|html$/i.test(offsetParent[0].tagName)?{top:0,left:0}:offsetParent.offset();offset.top-=num(this,'marginTop');offset.left-=num(this,'marginLeft');parentOffset.top+=num(offsetParent,'borderTopWidth');parentOffset.left+=num(offsetParent,'borderLeftWidth');results={top:offset.top-parentOffset.top,left:offset.left-parentOffset.left};}return results;},offsetParent:function(){var offsetParent=this[0].offsetParent;while(offsetParent&&(!/^body|html$/i.test(offsetParent.tagName)&&jQuery.css(offsetParent,'position')=='static'))offsetParent=offsetParent.offsetParent;return jQuery(offsetParent);}});jQuery.each(['Left','Top'],function(i,name){var method='scroll'+name;jQuery.fn[method]=function(val){if(!this[0])return;return val!=undefined?this.each(function(){this==window||this==document?window.scrollTo(!i?val:jQuery(window).scrollLeft(),i?val:jQuery(window).scrollTop()):this[method]=val;}):this[0]==window||this[0]==document?self[i?'pageYOffset':'pageXOffset']||jQuery.boxModel&&document.documentElement[method]||document.body[method]:this[0][method];};});jQuery.each(["Height","Width"],function(i,name){var tl=i?"Left":"Top",br=i?"Right":"Bottom";jQuery.fn["inner"+name]=function(){return this[name.toLowerCase()]()+num(this,"padding"+tl)+num(this,"padding"+br);};jQuery.fn["outer"+name]=function(margin){return this["inner"+name]()+num(this,"border"+tl+"Width")+num(this,"border"+br+"Width")+(margin?num(this,"margin"+tl)+num(this,"margin"+br):0);};});})(); \ No newline at end of file diff --git a/demo/templates/base.html b/demo/templates/base.html new file mode 100644 index 0000000..7ddc775 --- /dev/null +++ b/demo/templates/base.html @@ -0,0 +1,56 @@ + + + + + +{% block title %}Velkomm{% endblock %} :: Django Dynamic Formset Examples + + + +{% block extrahead %}{% endblock %} + + + + + + +
    + +
    + {% block content %} + {% endblock %} +
    + + + + +
    + + + + diff --git a/demo/templates/example/formset-stacked.html b/demo/templates/example/formset-stacked.html new file mode 100644 index 0000000..b01d0ee --- /dev/null +++ b/demo/templates/example/formset-stacked.html @@ -0,0 +1,44 @@ +{% extends "base.html" %} + +{% block title %}Basic Formset (DIV layout){% endblock %} + +{% block extrahead %} + + +{% endblock %} + +{% block content %} +
    +
    +
    + {% for form in formset.forms %} +
    + {{ form.type.label_tag }}
    + {{ form.type }} + {{ form.value.label_tag }}
    + {{ form.value }} +
    + {% endfor %} + {{ formset.management_form }} +

    + +

    +
    +
    +
    +{% endblock %} diff --git a/demo/templates/example/formset-table.html b/demo/templates/example/formset-table.html new file mode 100644 index 0000000..a426c76 --- /dev/null +++ b/demo/templates/example/formset-table.html @@ -0,0 +1,56 @@ +{% extends "base.html" %} + +{% block title %}Basic Formset (Table layout){% endblock %} + +{% block extrahead %} + + + +{% endblock %} + +{% block content %} +
    +
    +
    + + + + + + + + + {% for form in formset.forms %} + + + + + {% endfor %} + +
    TypeValue
    {{ form.type }}{{ form.value }}
    + {{ formset.management_form }} +

    + +

    +
    +
    +
    +{% endblock %} diff --git a/demo/templates/example/inline-formset-autocomplete.html b/demo/templates/example/inline-formset-autocomplete.html new file mode 100644 index 0000000..2a15734 --- /dev/null +++ b/demo/templates/example/inline-formset-autocomplete.html @@ -0,0 +1,78 @@ +{% extends "base.html" %} + +{% block title %}Inline Formset using Autocomplete{% endblock %} + +{% block extrahead %} +{{ formset.media }} + + +{% endblock %} + +{% block content %} +
    +
    +
    + {{ form.as_p }} +

    Order details

    + + + + + + + + + {% for form in formset.forms %} + + + + + {% endfor %} + +
    ProductQuantity
    + {{ form.order.as_hidden }} + {{ form.product }} + {{ form.quantity }}
    + {{ formset.management_form }} +

    + +

    +
    +
    +
    +{% endblock %} + +{% block sidebar %} +

    + This autocomplete example is supposed to show one possible use for the optional "added" and + "removed" callbacks. I know it's not user-friendly to select a product name and have a strange + number "magically" appear -- believe me, I wouldn't do that in production code :) +

    +

    + The original code I extracted this from was a bit more complicated (it allowed users specify + search criteria used to create ad-hoc groups). Rather than use that, I decided to base this + on the inline formset example. +

    +{% endblock %} diff --git a/demo/templates/example/inline-formset.html b/demo/templates/example/inline-formset.html new file mode 100644 index 0000000..340fdd6 --- /dev/null +++ b/demo/templates/example/inline-formset.html @@ -0,0 +1,56 @@ +{% extends "base.html" %} + +{% block title %}Inline Formset{% endblock %} + +{% block extrahead %} + + +{% endblock %} + +{% block content %} +
    +
    +
    + {{ form.as_p }} +

    Order details

    + + + + + + + + + {% for form in formset.forms %} + + + + + {% endfor %} + +
    ProductQuantity
    + {{ form.order.as_hidden }} + {{ form.product }} + {{ form.quantity }}
    + {{ formset.management_form }} +

    + +

    +
    +
    +
    +{% endblock %} diff --git a/demo/templates/example/posted-data.html b/demo/templates/example/posted-data.html new file mode 100644 index 0000000..aeb227c --- /dev/null +++ b/demo/templates/example/posted-data.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} + +{% block title %}Posted Data{% endblock %} + +{% block content %} +
    +

    Posted data

    +
    +

    Received data from {{ data|length }} forms.

    + {% for form_data in data %} +

    + Form #{{ forloop.counter }}
    + {% if form_data.product %} + Product: {{ form_data.product }}
    + Quantity: {{ form_data.quantity }} + {% else %} + Type: {{ form_data.type }}
    + Value: {{ form_data.value }} + {% endif %} +

    + {% endfor %} +
    +
    +{% endblock %} diff --git a/demo/templates/index.html b/demo/templates/index.html new file mode 100644 index 0000000..1f6f5ac --- /dev/null +++ b/demo/templates/index.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% block content %} +
    +

    Examples

    +
    +

    + The examples below were mostly pulled out from working code. View the source + to see how they work: +

    + +
    +
    +{% endblock %} diff --git a/demo/urls.py b/demo/urls.py new file mode 100644 index 0000000..a0d8e51 --- /dev/null +++ b/demo/urls.py @@ -0,0 +1,26 @@ +from django.conf import settings +from django.conf.urls.defaults import * +from django.views.generic.simple import direct_to_template + +# Uncomment the next two lines to enable the admin: +# from django.contrib import admin +# admin.autodiscover() + +urlpatterns = patterns('', + (r'^$', direct_to_template, {'template': 'index.html'}), + (r'^examples/', include('example.urls')), + + # Uncomment the admin/doc line below and add 'django.contrib.admindocs' + # to INSTALLED_APPS to enable admin documentation: + # (r'^admin/doc/', include('django.contrib.admindocs.urls')), + + # Uncomment the next line to enable the admin: + # (r'^admin/', include(admin.site.urls)), +) + +if settings.DEBUG: + urlpatterns += patterns('', + (r'^%s/(?P.*)$' % settings.MEDIA_URL[1:-1], + 'django.views.static.serve', + {'document_root': settings.MEDIA_ROOT, 'show_indexes': False}), + ) diff --git a/src/jquery.formset.js b/src/jquery.formset.js new file mode 100644 index 0000000..6b73e67 --- /dev/null +++ b/src/jquery.formset.js @@ -0,0 +1,102 @@ +/** + * jQuery Formset 1.0 + * @author Stanislaus Madueke (stan DOT madueke AT gmail DOT com) + * @requires jQuery 1.2.6 or later + * + * Copyright (c) 2009, Stanislaus Madueke + * All rights reserved. + * + * Licensed under the New BSD License + * See: http://www.opensource.org/licenses/bsd-license.php + */ +(function($) { + $.fn.formset = function(opts) + { + var options = $.extend({}, $.fn.formset.defaults, opts); + + var updateElementIndex = function(el, prefix, ndx) { + var id_regex = new RegExp('(' + prefix + '-\\d+)'); + var replacement = prefix + '-' + ndx; + if ($(el).attr("for")) $(el).attr("for", $(el).attr("for").replace(id_regex, replacement)); + if (el.id) el.id = el.id.replace(id_regex, replacement); + if (el.name) el.name = el.name.replace(id_regex, replacement); + }; + + $(this).each(function(i) { + $(this).addClass('dynamic-form'); + if ($(this).attr('tagName') == 'TR') { + // If the forms are laid out in table rows, insert + // the remove button into the last table cell: + $(this).children(':last').append('' + options.deleteText + ''); + } else { + // Otherwise, just insert the remove button as the + // last child element of the form's container: + $(this).append('' + options.deleteText +''); + } + $(this).find('a.' + options.deleteCssClass).click(function() { + // Remove the parent form containing this button: + var row = $(this).parents('.dynamic-form'); + row.remove(); + // If a post-delete callback was provided, call it with the deleted form: + if (options.removed) options.removed(row); + // Update the TOTAL_FORMS form count. + // Also, update names and ids for all remaining form controls + // so they remain in sequence: + var forms = $('.dynamic-form'); + $('#id_' + options.prefix + '-TOTAL_FORMS').val(forms.length); + // If there's only one form left, disable its delete button: + if (forms.length == 1) { $('a.' + options.deleteCssClass).hide(); } + for (var i=0, formCount=forms.length; i' + options.addText + ''); + } else { + // Otherwise, insert it immediately after the last form: + $(this).filter(':last').after('' + options.addText + ''); + } + $(this).parent().find('a.' + options.addCssClass).click(function() { + var nextIndex = parseInt($('#id_' + options.prefix + '-TOTAL_FORMS').val()); + var row = $('.dynamic-form:first').clone(true).get(0); + $(row).removeAttr('id').insertAfter($('.dynamic-form:last')); + $(row).find('input,select,textarea,label').each(function() { + updateElementIndex(this, options.prefix, nextIndex); + $(this).val(''); + }); + var formCount = nextIndex + 1; + $('#id_' + options.prefix + '-TOTAL_FORMS').val(formCount); + // If we've got more than one form, enable delete buttons: + if (formCount > 1) { $('a.' + options.deleteCssClass).show(); } + // If a post-add callback was supplied, call it with the added form: + if (options.added) options.added($(row)); + return false; + }); + } + + // If the formset is initialized with a single form, hide the delete button: + if ($(this).length == 1) { $('a.' + options.deleteCssClass).hide(); } + + return $(this); + } + + /* Setup plugin defaults */ + $.fn.formset.defaults = { + prefix: 'form', // The form prefix for your django formset + addText: 'add another', // Text for the add link + deleteText: 'remove', // Text for the delete link + addCssClass: 'add-row', // CSS class applied to the add link + deleteCssClass: 'delete-row', // CSS class applied to the delete link + added: null, // Function called each time a new form is added + removed: null // Function called each time a form is deleted + } +})(jQuery)