From b17be3968019d21c82aa54fa5fafa233aa7430c6 Mon Sep 17 00:00:00 2001 From: Alex Lewis Date: Thu, 4 Oct 2012 22:33:23 +1000 Subject: [PATCH] Structure, Tasty pie API Added tasty pie Re-arranged app structure Posts & comments test --- bodyrep/apps/{core/auth => api}/__init__.py | 0 bodyrep/apps/api/auth.py | 22 + bodyrep/apps/api/models.py | 69 + bodyrep/apps/auth/__init__.py | 0 bodyrep/apps/auth/forms.py | 134 ++ bodyrep/apps/auth/views.py | 74 + bodyrep/apps/core/auth/views.py | 73 - bodyrep/apps/core/forms.py | 129 +- bodyrep/apps/core/models.py | 34 +- bodyrep/apps/core/views.py | 75 +- bodyrep/media/css/jquery-ui.css | 563 +++++++ bodyrep/media/css/site.css | 10 +- bodyrep/media/js/application.js | 69 +- bodyrep/media/js/backbone-tastypie.js | 104 ++ bodyrep/media/js/backbone.js | 1431 +++++++++++++++++ bodyrep/media/js/underscore.js | 1189 ++++++++++++++ bodyrep/settings.py | 8 +- bodyrep/templates/{core => }/auth/login.html | 0 bodyrep/templates/auth/signup.html | 30 + bodyrep/templates/base.html | 48 +- bodyrep/templates/core/landing.html | 8 +- bodyrep/templates/core/member/post.html | 50 + bodyrep/templates/core/member/profile.html | 203 +-- .../templates/core/user/searchResults.html | 2 +- bodyrep/templates/navbar.html | 2 +- bodyrep/urls.py | 43 +- bodyrep/utils/functions.py | 70 +- 27 files changed, 3974 insertions(+), 466 deletions(-) rename bodyrep/apps/{core/auth => api}/__init__.py (100%) create mode 100644 bodyrep/apps/api/auth.py create mode 100644 bodyrep/apps/api/models.py create mode 100644 bodyrep/apps/auth/__init__.py create mode 100644 bodyrep/apps/auth/forms.py create mode 100644 bodyrep/apps/auth/views.py delete mode 100644 bodyrep/apps/core/auth/views.py create mode 100644 bodyrep/media/css/jquery-ui.css create mode 100644 bodyrep/media/js/backbone-tastypie.js create mode 100644 bodyrep/media/js/backbone.js create mode 100644 bodyrep/media/js/underscore.js rename bodyrep/templates/{core => }/auth/login.html (100%) create mode 100644 bodyrep/templates/auth/signup.html create mode 100644 bodyrep/templates/core/member/post.html diff --git a/bodyrep/apps/core/auth/__init__.py b/bodyrep/apps/api/__init__.py similarity index 100% rename from bodyrep/apps/core/auth/__init__.py rename to bodyrep/apps/api/__init__.py diff --git a/bodyrep/apps/api/auth.py b/bodyrep/apps/api/auth.py new file mode 100644 index 0000000..d771bb7 --- /dev/null +++ b/bodyrep/apps/api/auth.py @@ -0,0 +1,22 @@ +from tastypie.authentication import Authentication +from tastypie.authorization import Authorization + + +class APIAuthentication(Authentication): + def is_authenticated(self, request, **kwargs): + return not request.user.is_anonymous() + + # Optional but recommended + def get_identifier(self, request): + return request.user.username + +class APIAuthorization(Authorization): + def is_authorized(self, request, object=None): + return not request.user.is_anonymous() + + # Optional but useful for advanced limiting, such as per user. + #def apply_limits(self, request, object_list): + # if request and hasattr(request, 'user'): + # return object_list.filter(author__username=request.user.username) + + # return object_list.none() \ No newline at end of file diff --git a/bodyrep/apps/api/models.py b/bodyrep/apps/api/models.py new file mode 100644 index 0000000..c9758ca --- /dev/null +++ b/bodyrep/apps/api/models.py @@ -0,0 +1,69 @@ +# Django +from django.contrib.auth.models import User +from django.db import models +from django.forms.models import model_to_dict + +# Tasty pie +from tastypie.resources import ModelResource +from tastypie.models import create_api_key +from tastypie import fields + +# BR +from apps.core.models import * +from apps.api.auth import APIAuthentication, APIAuthorization + +class AbstractResource(ModelResource): + + def alter_list_data_to_serialize(self, request, data): + return data['objects'] + + def dehydrate_id(self, bundle): + return int(bundle.data['id']) + + class Meta: + include_resource_uri = False + limit = 0 + +class PostResource(AbstractResource): + #member = fields.ForeignKey('apps.api.models.MemberResource', 'member', full = True) + class Meta: + queryset = Post.objects.all() + authorization = APIAuthorization() + authentication = APIAuthentication() + resource_name = 'post' + +# Members +class MemberResource(AbstractResource): + class Meta: + queryset = Member.objects.all() + authorization = APIAuthorization() + #include_resource_uri = False + + authentication = APIAuthentication() + resource_name = 'members' + fields = ['username', 'firstname', 'lastname'] + + def dehydrate(self, bundle): + bundle.data['fullname'] = bundle.data['firstname'].lower() + ' ' + bundle.data['lastname'].lower() + return bundle + +# Comments +class CommentResource(AbstractResource): + post = fields.ForeignKey(PostResource, 'comment') + + class Meta: + queryset = Comment.objects.all() + authorization = APIAuthorization() + authentication = APIAuthentication() + resource_name = 'comment' + + +# Workouts +class WorkoutResource(ModelResource): + user = User.objects.all() + + class Meta: + queryset = Workout.objects.all() + authorization = APIAuthorization() + authentication = APIAuthentication() + resource_name = 'workouts' diff --git a/bodyrep/apps/auth/__init__.py b/bodyrep/apps/auth/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bodyrep/apps/auth/forms.py b/bodyrep/apps/auth/forms.py new file mode 100644 index 0000000..e9eafa0 --- /dev/null +++ b/bodyrep/apps/auth/forms.py @@ -0,0 +1,134 @@ +import datetime + +# Django +from django import forms +from django.utils.translation import ugettext_lazy as _ +from django.contrib.auth.models import User +from django.contrib.auth import authenticate +from django.db.models import Q + +# Br +from apps.core.models import Member + +class LoginForm(forms.Form): + username = forms.CharField(label=_("Username"), max_length=30, + widget=forms.TextInput(attrs={'tabindex': 1, 'class': 'NB-input'}), + error_messages={'required': 'Please enter a username.'}) + password = forms.CharField(label=_("Password"), + widget=forms.PasswordInput(attrs={'tabindex': 2, 'class': 'NB-input'}), + required=False) + + def __init__(self, *args, **kwargs): + self.user_cache = None + super(LoginForm, self).__init__(*args, **kwargs) + + def clean(self): + username = self.cleaned_data.get('username', '').lower() + password = self.cleaned_data.get('password', '') + + user = User.objects.filter(Q(username__iexact=username) | Q(email=username)) + if username and user: + self.user_cache = authenticate(username=user[0].username, password=password) + if self.user_cache is None: + self.user_cache = authenticate(username=user[0].username, password="") + if self.user_cache is None: + email_username = User.objects.filter(email=username) + if email_username: + self.user_cache = authenticate(username=email_username[0].username, password=password) + if self.user_cache is None: + self.user_cache = authenticate(username=email_username[0].username, password="") + if self.user_cache is None: + jkless_password = password.replace('j', '').replace('k', '') + self.user_cache = authenticate(username=username, password=jkless_password) + if self.user_cache is None: + raise forms.ValidationError(_("Login failed. Try again")) +# else: + # Supreme fuck-up. Accidentally removed the letters J and K from + # all user passwords. Re-save with correct password. + #logging.info(" ***> [%s] FIXING JK-LESS PASSWORD" % username) + # self.user_cache.set_password(password) + # self.user_cache.save() + if not self.user_cache.is_active: + raise forms.ValidationError(_("This account is inactive.")) + elif username and not user: + raise forms.ValidationError(_("That username is not registered. Create an account with it instead.")) + + return self.cleaned_data + + def get_user_id(self): + if self.user_cache: + return self.user_cache.id + return None + + def get_user(self): + return self.user_cache + +class SignupForm(forms.Form): + username = forms.RegexField(regex=r'^\w+$', + max_length=30, + widget=forms.TextInput(attrs={'class': ''}), + required=False, + label=_(u'username'), + error_messages={ + 'required': 'Please enter a username.', + 'invalid': "Your username may only contain letters and numbers." + }) + email = forms.EmailField(widget=forms.TextInput(attrs={'maxlength': 75, 'class': ''}), + label=_(u'email address'), + required=False) + # error_messages={'required': 'Please enter your email.'}) + password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'NB-input'}), + label=_(u'password'), + required=False) + # error_messages={'required': 'Please enter a password.'}) + + def clean_username(self): + username = self.cleaned_data['username'] + return username + + def clean_password(self): + if not self.cleaned_data['password']: + return "" + return self.cleaned_data['password'] + + def clean_email(self): + if not self.cleaned_data['email']: + return "" + return self.cleaned_data['email'] + + def clean(self): + username = self.cleaned_data.get('username', '') + password = self.cleaned_data.get('password', '') + exists = User.objects.filter(username__iexact=username).count() + #if exists: + # user_auth = authenticate(username=username, password=password) + # if not user_auth: + # raise forms.ValidationError(_(u'Someone is already using that username.')) + return self.cleaned_data + + def save(self, profile_callback=None): + username = self.cleaned_data['username'] + password = self.cleaned_data['password'] + + exists = User.objects.filter(username__iexact=username).count() + # if exists: + # user_auth = authenticate(username=username, password=password) + # if not user_auth: + # raise forms.ValidationError(_(u'Someone is already using that username.')) + # else: + # return user_auth + + new_user = User(username=username) + new_user.set_password(password) + new_user.is_active = True + new_user.email = self.cleaned_data['email'] + new_user.save() + new_user = authenticate(username=username, + password=password) + + # MActivity.new_signup(user_id=new_user.pk) + + # if new_user.email: + # EmailNewUser.delay(user_id=new_user.pk) + + return new_user \ No newline at end of file diff --git a/bodyrep/apps/auth/views.py b/bodyrep/apps/auth/views.py new file mode 100644 index 0000000..5504b6b --- /dev/null +++ b/bodyrep/apps/auth/views.py @@ -0,0 +1,74 @@ +import urllib +import urlparse + +# Django +from django.contrib.auth.decorators import login_required +from django.core.urlresolvers import reverse +from django.contrib.auth.models import User +from django.contrib.sites.models import Site +from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404 +from django.conf import settings +from django.views.decorators.cache import never_cache +from django.contrib.auth import login as login_user +from django.contrib.auth import logout as logout_user + +# Libs +from annoying.decorators import render_to, ajax_request + +# BR +from apps.auth.forms import LoginForm, SignupForm +from utils.functions import get_user, render_to + +# Vendors +#from vendor import facebook + +@never_cache +@render_to('auth/signup.html') +def signup(request): + form = SignupForm(prefix='signup', data=request.POST) + if request.method == "POST": + if form.is_valid(): + new_user = form.save() + login_user(request, new_user) + return HttpResponseRedirect(reverse('showUserProfile')) + + return {'signup_form':form} + +@never_cache +@render_to('auth/login.html') +def login(request): + if not request.user.is_anonymous(): + return HttpResponseRedirect(reverse('showUserProfile')) + + if request.method == "POST": + if request.POST.get('submit', '').startswith('log'): + login_form = LoginForm(request.POST, prefix='login') + else: + login_form = LoginForm(prefix='login') + else: + login_form = LoginForm(prefix='login') + + + return {'login_form':login_form} + +@never_cache +def dologin(request): + code = -1 + message = "" + if request.method == "POST": + form = LoginForm(request.POST, prefix='login') + if form.is_valid(): + login_user(request, form.get_user()) + return HttpResponseRedirect(reverse('showUserProfile')) + else: + message = form.errors.items()[0][1][0] + +@never_cache +def logout(request): + logout_user(request) + + if request.GET.get('api'): + return HttpResponse(json.encode(dict(code=1)), mimetype='application/json') + else: + return HttpResponseRedirect(reverse('index')) + \ No newline at end of file diff --git a/bodyrep/apps/core/auth/views.py b/bodyrep/apps/core/auth/views.py deleted file mode 100644 index 0d7add8..0000000 --- a/bodyrep/apps/core/auth/views.py +++ /dev/null @@ -1,73 +0,0 @@ -import urllib -import urlparse - -from django.contrib.auth.decorators import login_required -from django.core.urlresolvers import reverse -from django.contrib.auth.models import User -from django.contrib.sites.models import Site -from django.http import HttpResponseForbidden, HttpResponseRedirect -from django.conf import settings -from utils.functions import ajax_login_required, render_to - -from vendor import facebook - -@render_to('core/auth/facebook.html') -def facebook_connect(request): - facebook_app_id = settings.FACEBOOK_APP_ID - facebook_secret = settings.FACEBOOK_SECRET - - args = { - "client_id": facebook_app_id, - "redirect_uri": "http://" + Site.objects.get_current().domain + reverse('facebook-connect'), - "scope": "offline_access,user_website,publish_actions", - "display": "popup", - } - - verification_code = request.REQUEST.get('code') - if verification_code: - args["client_secret"] = facebook_secret - args["code"] = verification_code - uri = "https://graph.facebook.com/oauth/access_token?" + \ - urllib.urlencode(args) - response_text = urllib.urlopen(uri).read() - response = urlparse.parse_qs(response_text) - - if "access_token" not in response: - logging.user(request, "~BB~FRFailed Facebook connect") - return dict(error="Facebook has returned an error. Try connecting again.") - - access_token = response["access_token"][-1] - - # Get the user's profile. - graph = facebook.GraphAPI(access_token) - profile = graph.get_object("me") - uid = profile["id"] - - # Be sure that two people aren't using the same Facebook account. - existing_user = MSocialServices.objects.filter(facebook_uid=uid) - if existing_user and existing_user[0].user_id != request.user.pk: - user = User.objects.get(pk=existing_user[0].user_id) - #logging.user(request, "~BB~FRFailed FB connect, another user: %s" % user.username) - return dict(error=("Another user (%s, %s) has " - "already connected with those Facebook credentials." - % (user.username, user.email or "no email"))) - - social_services, _ = MSocialServices.objects.get_or_create(user_id=request.user.pk) - social_services.facebook_uid = uid - social_services.facebook_access_token = access_token - social_services.syncing_facebook = True - social_services.save() - - SyncFacebookFriends.delay(user_id=request.user.pk) - - #srequest, "~BB~FRFinishing Facebook connect") - return {} - elif request.REQUEST.get('error'): - #logging.user(request, "~BB~FRFailed Facebook connect") - return {'error': '%s... Try connecting again.' % request.REQUEST.get('error')} - else: - # Start the OAuth process - #logging.user(request, "~BB~FRStarting Facebook connect") - url = "https://www.facebook.com/dialog/oauth?" + urllib.urlencode(args) - return {'next': url} - \ No newline at end of file diff --git a/bodyrep/apps/core/forms.py b/bodyrep/apps/core/forms.py index 7eef456..ff6ff96 100644 --- a/bodyrep/apps/core/forms.py +++ b/bodyrep/apps/core/forms.py @@ -1,92 +1,39 @@ -import datetime - -# Django -from django import forms -from django.utils.translation import ugettext_lazy as _ -from django.contrib.auth.models import User -from django.contrib.auth import authenticate -from django.db.models import Q - -# Br -from apps.core.models import Members - -class LoginForm(forms.Form): - username = forms.CharField(label=_("Username"), max_length=30, - widget=forms.TextInput(attrs={'tabindex': 1, 'class': 'NB-input'}), - error_messages={'required': 'Please enter a username.'}) - password = forms.CharField(label=_("Password"), - widget=forms.PasswordInput(attrs={'tabindex': 2, 'class': 'NB-input'}), - required=False) - - def __init__(self, *args, **kwargs): - self.user_cache = None - super(LoginForm, self).__init__(*args, **kwargs) - - def clean(self): - username = self.cleaned_data.get('username', '').lower() - password = self.cleaned_data.get('password', '') - - user = User.objects.filter(Q(username__iexact=username) | Q(email=username)) - if username and user: - self.user_cache = authenticate(username=user[0].username, password=password) - if self.user_cache is None: - self.user_cache = authenticate(username=user[0].username, password="") - if self.user_cache is None: - email_username = User.objects.filter(email=username) - if email_username: - self.user_cache = authenticate(username=email_username[0].username, password=password) - if self.user_cache is None: - self.user_cache = authenticate(username=email_username[0].username, password="") - if self.user_cache is None: - jkless_password = password.replace('j', '').replace('k', '') - self.user_cache = authenticate(username=username, password=jkless_password) - if self.user_cache is None: - raise forms.ValidationError(_("Login failed. Try again")) -# else: - # Supreme fuck-up. Accidentally removed the letters J and K from - # all user passwords. Re-save with correct password. - #logging.info(" ***> [%s] FIXING JK-LESS PASSWORD" % username) - # self.user_cache.set_password(password) - # self.user_cache.save() - if not self.user_cache.is_active: - raise forms.ValidationError(_("This account is inactive.")) - elif username and not user: - raise forms.ValidationError(_("That username is not registered. Create an account with it instead.")) - - return self.cleaned_data - - def get_user_id(self): - if self.user_cache: - return self.user_cache.id - return None - - def get_user(self): - return self.user_cache - -class EditProfileForm(forms.Form): - firstname = forms.CharField(label=_("First Name"), max_length=30, - widget=forms.TextInput(attrs={'tabindex': 1, 'class': 'NB-input'}), - error_messages={'required': 'Please enter a first name'}) - lastname = forms.CharField(label=_("LastName"), - widget=forms.TextInput(attrs={'tabindex': 2, 'class': 'NB-input'}), - error_messages={'required': 'Please enter a last name.'}) - - def __init__(self, *args, **kwargs): - super(EditProfileForm, self).__init__(*args, **kwargs) - - def clean(self): - firstname = self.cleaned_data.get('firstname', '') - lastname = self.cleaned_data.get('lastname', '') - - return self.cleaned_data - - def save(self, username): - firstname = self.cleaned_data['firstname'] - lastname = self.cleaned_data['lastname'] - - member = Members.objects.get(username=username) - member.firstname = firstname - member.lastname = lastname - member.save() - +import datetime + +# Django +from django import forms +from django.utils.translation import ugettext_lazy as _ +from django.contrib.auth.models import User +from django.contrib.auth import authenticate +from django.db.models import Q + +#BR +from apps.core.models import Member + +class EditProfileForm(forms.Form): + firstname = forms.CharField(label=_("First Name"), max_length=30, + widget=forms.TextInput(attrs={'tabindex': 1, 'class': 'NB-input'}), + error_messages={'required': 'Please enter a first name'}) + lastname = forms.CharField(label=_("LastName"), + widget=forms.TextInput(attrs={'tabindex': 2, 'class': 'NB-input'}), + error_messages={'required': 'Please enter a last name.'}) + + def __init__(self, *args, **kwargs): + super(EditProfileForm, self).__init__(*args, **kwargs) + + def clean(self): + firstname = self.cleaned_data.get('firstname', '') + lastname = self.cleaned_data.get('lastname', '') + + return self.cleaned_data + + def save(self, username): + firstname = self.cleaned_data['firstname'] + lastname = self.cleaned_data['lastname'] + + member = Member.objects.get(username=username) + member.firstname = firstname + member.lastname = lastname + member.save() + return member \ No newline at end of file diff --git a/bodyrep/apps/core/models.py b/bodyrep/apps/core/models.py index 611fde0..86840fe 100644 --- a/bodyrep/apps/core/models.py +++ b/bodyrep/apps/core/models.py @@ -1,8 +1,26 @@ -from django.db import models -from django.contrib import admin -from django.contrib.auth.models import User, UserManager - -class Members(models.Model): - username = models.CharField(max_length = 30) - firstname = models.CharField(max_length=30) - lastname = models.CharField(max_length=30) +from django.db import models +from django.contrib import admin +from django.contrib.auth.models import User, UserManager + +class Member(models.Model): + username = models.CharField(max_length = 30) + firstname = models.CharField(max_length=30) + lastname = models.CharField(max_length=30) + +class Post(models.Model): + username = models.CharField(max_length = 30) + text = models.CharField(max_length=100) + created = models.DateTimeField() + member = models.ForeignKey(Member) + +class Comment(models.Model): + username = models.CharField(max_length = 30) + text = models.CharField(max_length=100) + created = models.DateTimeField() + post = models.ForeignKey('Post') + +class Workout(models.Model): + username = models.CharField(max_length = 30) + timeSpent = models.CharField(max_length=30) + exercise = models.CharField(max_length=30) + member = models.ForeignKey(Member) \ No newline at end of file diff --git a/bodyrep/apps/core/views.py b/bodyrep/apps/core/views.py index 61e874e..520b746 100644 --- a/bodyrep/apps/core/views.py +++ b/bodyrep/apps/core/views.py @@ -9,8 +9,6 @@ from django.template.loader import render_to_string from django.db import IntegrityError from django.views.decorators.cache import never_cache from django.core.urlresolvers import reverse -from django.contrib.auth import login as login_user -from django.contrib.auth import logout as logout_user from django.contrib.auth.models import User from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404 from django.conf import settings @@ -18,14 +16,16 @@ from django.contrib.sites.models import Site from django.core.context_processors import csrf from django.template import RequestContext from django.db.models import Q +from django.views.decorators.cache import never_cache # Libs from annoying.decorators import render_to, ajax_request # BR -from apps.core.forms import LoginForm, EditProfileForm -from apps.core.models import Members +from apps.core.models import * +from apps.core.forms import EditProfileForm from utils.functions import get_user, render_to +from apps.auth.views import login @render_to('core/landing.html') def index(request): @@ -36,71 +36,39 @@ def showUserProfile(request): if request.user.is_anonymous(): return login(request) else: - member = Members.objects.get(username=request.user.username) + try: + member = Member.objects.get(username=request.user.username) + except Member.DoesNotExist: + return render_to_response('core/errors/memberNotFound.html') + return {'member': member} @login_required @render_to('core/member/profile.html') def showMemberProfile(request, username): try: - member = Members.objects.get(username=username) - except Members.DoesNotExist: + member = Member.objects.get(username=username) + except Member.DoesNotExist: return render_to_response('core/errors/memberNotFound.html') - + if request.user.is_anonymous(): return login(request) else: - return { 'user': request.user, 'member': member } + post = Post.objects.filter(username=request.user.username).prefetch_related('comment_set').all().order_by('created') -@never_cache -@render_to('core/auth/login.html') -def login(request): - if not request.user.is_anonymous(): - return HttpResponseRedirect(reverse('showUserProfile')) - if request.method == "POST": - if request.POST.get('submit', '').startswith('log'): - login_form = LoginForm(request.POST, prefix='login') - else: - login_form = LoginForm(prefix='login') - else: - login_form = LoginForm(prefix='login') - - - return {'login_form':login_form} + return { 'user': request.user, 'member': member, 'post': post } @never_cache def search(request, kw): try: - members = Members.objects.filter(Q(firstname__icontains=kw) | Q(lastname__icontains=kw)) + members = Member.objects.filter(Q(firstname__icontains=kw) | Q(lastname__icontains=kw)) - except Members.DoesNotExist: + except Member.DoesNotExist: x=1 return render_to_response ('core/user/searchResults.html', { 'user': request.user, 'members': members} ) -@never_cache -def dologin(request): - code = -1 - message = "" - if request.method == "POST": - form = LoginForm(request.POST, prefix='login') - if form.is_valid(): - login_user(request, form.get_user()) - return HttpResponseRedirect(reverse('showUserProfile')) - else: - message = form.errors.items()[0][1][0] - -@never_cache -def logout(request): - logout_user(request) - - if request.GET.get('api'): - return HttpResponse(json.encode(dict(code=1)), mimetype='application/json') - else: - return HttpResponseRedirect(reverse('index')) - - @ajax_request @render_to('core/user/editProfile.html') def editUserProfile(request): @@ -108,7 +76,7 @@ def editUserProfile(request): return login(request) else: - member = Members.objects.get(username=request.user.username) + member = Member.objects.get(username=request.user.username) mdata = {'firstname': member.firstname, 'lastname': member.lastname } @@ -123,3 +91,12 @@ def saveUserProfile(request): return { 'result': 1 } else: return { 'result': 0 } + +@render_to('core/member/comment.html') +def comment(request): + try: + comment = Comment.objects.filter(username=request.user.username) + except Comment.DoesNotExist: + render_to_response('core/member/memberNotFound.html') + + return {'comment': comment} \ No newline at end of file diff --git a/bodyrep/media/css/jquery-ui.css b/bodyrep/media/css/jquery-ui.css new file mode 100644 index 0000000..c1cbd2b --- /dev/null +++ b/bodyrep/media/css/jquery-ui.css @@ -0,0 +1,563 @@ +/*! + * jQuery UI CSS Framework 1.8.23 + * + * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Theming/API + */ + +/* Layout helpers +----------------------------------*/ +.ui-helper-hidden { display: none; } +.ui-helper-hidden-accessible { position: absolute !important; clip: rect(1px 1px 1px 1px); clip: rect(1px,1px,1px,1px); } +.ui-helper-reset { margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.3; text-decoration: none; font-size: 100%; list-style: none; } +.ui-helper-clearfix:before, .ui-helper-clearfix:after { content: ""; display: table; } +.ui-helper-clearfix:after { clear: both; } +.ui-helper-clearfix { zoom: 1; } +.ui-helper-zfix { width: 100%; height: 100%; top: 0; left: 0; position: absolute; opacity: 0; filter:Alpha(Opacity=0); } + + +/* Interaction Cues +----------------------------------*/ +.ui-state-disabled { cursor: default !important; } + + +/* Icons +----------------------------------*/ + +/* states and images */ +.ui-icon { display: block; text-indent: -99999px; overflow: hidden; background-repeat: no-repeat; } + + +/* Misc visuals +----------------------------------*/ + +/* Overlays */ +.ui-widget-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } + + +/*! + * jQuery UI CSS Framework 1.8.23 + * + * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Theming/API + * + * To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Verdana,Arial,sans-serif&fwDefault=normal&fsDefault=1.1em&cornerRadius=4px&bgColorHeader=cccccc&bgTextureHeader=03_highlight_soft.png&bgImgOpacityHeader=75&borderColorHeader=aaaaaa&fcHeader=222222&iconColorHeader=222222&bgColorContent=ffffff&bgTextureContent=01_flat.png&bgImgOpacityContent=75&borderColorContent=aaaaaa&fcContent=222222&iconColorContent=222222&bgColorDefault=e6e6e6&bgTextureDefault=02_glass.png&bgImgOpacityDefault=75&borderColorDefault=d3d3d3&fcDefault=555555&iconColorDefault=888888&bgColorHover=dadada&bgTextureHover=02_glass.png&bgImgOpacityHover=75&borderColorHover=999999&fcHover=212121&iconColorHover=454545&bgColorActive=ffffff&bgTextureActive=02_glass.png&bgImgOpacityActive=65&borderColorActive=aaaaaa&fcActive=212121&iconColorActive=454545&bgColorHighlight=fbf9ee&bgTextureHighlight=02_glass.png&bgImgOpacityHighlight=55&borderColorHighlight=fcefa1&fcHighlight=363636&iconColorHighlight=2e83ff&bgColorError=fef1ec&bgTextureError=02_glass.png&bgImgOpacityError=95&borderColorError=cd0a0a&fcError=cd0a0a&iconColorError=cd0a0a&bgColorOverlay=aaaaaa&bgTextureOverlay=01_flat.png&bgImgOpacityOverlay=0&opacityOverlay=30&bgColorShadow=aaaaaa&bgTextureShadow=01_flat.png&bgImgOpacityShadow=0&opacityShadow=30&thicknessShadow=8px&offsetTopShadow=-8px&offsetLeftShadow=-8px&cornerRadiusShadow=8px + */ + + +/* Component containers +----------------------------------*/ +.ui-widget { font-family: Verdana,Arial,sans-serif; font-size: 1.1em; } +.ui-widget .ui-widget { font-size: 1em; } +.ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Verdana,Arial,sans-serif; font-size: 1em; } +.ui-widget-content { border: 1px solid #aaaaaa; background: #ffffff url(/s/img/ui-bg_flat_75_ffffff_40x100.png) 50% 50% repeat-x; color: #222222; } +.ui-widget-content a { color: #222222; } +.ui-widget-header { border: 1px solid #aaaaaa; background: #cccccc url(/s/img/ui-bg_highlight-soft_75_cccccc_1x100.png) 50% 50% repeat-x; color: #222222; font-weight: bold; } +.ui-widget-header a { color: #222222; } + +/* Interaction states +----------------------------------*/ +.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #d3d3d3; background: #e6e6e6 url(/s/img/ui-bg_glass_75_e6e6e6_1x400.png) 50% 50% repeat-x; font-weight: normal; color: #555555; } +.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #555555; text-decoration: none; } +.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #999999; background: #dadada url(/s/img/ui-bg_glass_75_dadada_1x400.png) 50% 50% repeat-x; font-weight: normal; color: #212121; } +.ui-state-hover a, .ui-state-hover a:hover { color: #212121; text-decoration: none; } +.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #aaaaaa; background: #ffffff url(/s/img/ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x; font-weight: normal; color: #212121; } +.ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #212121; text-decoration: none; } +.ui-widget :active { outline: none; } + +/* Interaction Cues +----------------------------------*/ +.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fcefa1; background: #fbf9ee url(/s/img/ui-bg_glass_55_fbf9ee_1x400.png) 50% 50% repeat-x; color: #363636; } +.ui-state-highlight a, .ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a { color: #363636; } +.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #fef1ec url(/s/img/ui-bg_glass_95_fef1ec_1x400.png) 50% 50% repeat-x; color: #cd0a0a; } +.ui-state-error a, .ui-widget-content .ui-state-error a, .ui-widget-header .ui-state-error a { color: #cd0a0a; } +.ui-state-error-text, .ui-widget-content .ui-state-error-text, .ui-widget-header .ui-state-error-text { color: #cd0a0a; } +.ui-priority-primary, .ui-widget-content .ui-priority-primary, .ui-widget-header .ui-priority-primary { font-weight: bold; } +.ui-priority-secondary, .ui-widget-content .ui-priority-secondary, .ui-widget-header .ui-priority-secondary { opacity: .7; filter:Alpha(Opacity=70); font-weight: normal; } +.ui-state-disabled, .ui-widget-content .ui-state-disabled, .ui-widget-header .ui-state-disabled { opacity: .35; filter:Alpha(Opacity=35); background-image: none; } + +/* Icons +----------------------------------*/ + +/* states and images */ +.ui-icon { width: 16px; height: 16px; background-image: url(/s/img/ui-icons_222222_256x240.png); } +.ui-widget-content .ui-icon {background-image: url(/s/img/ui-icons_222222_256x240.png); } +.ui-widget-header .ui-icon {background-image: url(/s/img/ui-icons_222222_256x240.png); } +.ui-state-default .ui-icon { background-image: url(/s/img/ui-icons_888888_256x240.png); } +.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(/s/img/ui-icons_454545_256x240.png); } +.ui-state-active .ui-icon {background-image: url(/s/img/ui-icons_454545_256x240.png); } +.ui-state-highlight .ui-icon {background-image: url(/s/img/ui-icons_2e83ff_256x240.png); } +.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(/s/img/ui-icons_cd0a0a_256x240.png); } + +/* positioning */ +.ui-icon-carat-1-n { background-position: 0 0; } +.ui-icon-carat-1-ne { background-position: -16px 0; } +.ui-icon-carat-1-e { background-position: -32px 0; } +.ui-icon-carat-1-se { background-position: -48px 0; } +.ui-icon-carat-1-s { background-position: -64px 0; } +.ui-icon-carat-1-sw { background-position: -80px 0; } +.ui-icon-carat-1-w { background-position: -96px 0; } +.ui-icon-carat-1-nw { background-position: -112px 0; } +.ui-icon-carat-2-n-s { background-position: -128px 0; } +.ui-icon-carat-2-e-w { background-position: -144px 0; } +.ui-icon-triangle-1-n { background-position: 0 -16px; } +.ui-icon-triangle-1-ne { background-position: -16px -16px; } +.ui-icon-triangle-1-e { background-position: -32px -16px; } +.ui-icon-triangle-1-se { background-position: -48px -16px; } +.ui-icon-triangle-1-s { background-position: -64px -16px; } +.ui-icon-triangle-1-sw { background-position: -80px -16px; } +.ui-icon-triangle-1-w { background-position: -96px -16px; } +.ui-icon-triangle-1-nw { background-position: -112px -16px; } +.ui-icon-triangle-2-n-s { background-position: -128px -16px; } +.ui-icon-triangle-2-e-w { background-position: -144px -16px; } +.ui-icon-arrow-1-n { background-position: 0 -32px; } +.ui-icon-arrow-1-ne { background-position: -16px -32px; } +.ui-icon-arrow-1-e { background-position: -32px -32px; } +.ui-icon-arrow-1-se { background-position: -48px -32px; } +.ui-icon-arrow-1-s { background-position: -64px -32px; } +.ui-icon-arrow-1-sw { background-position: -80px -32px; } +.ui-icon-arrow-1-w { background-position: -96px -32px; } +.ui-icon-arrow-1-nw { background-position: -112px -32px; } +.ui-icon-arrow-2-n-s { background-position: -128px -32px; } +.ui-icon-arrow-2-ne-sw { background-position: -144px -32px; } +.ui-icon-arrow-2-e-w { background-position: -160px -32px; } +.ui-icon-arrow-2-se-nw { background-position: -176px -32px; } +.ui-icon-arrowstop-1-n { background-position: -192px -32px; } +.ui-icon-arrowstop-1-e { background-position: -208px -32px; } +.ui-icon-arrowstop-1-s { background-position: -224px -32px; } +.ui-icon-arrowstop-1-w { background-position: -240px -32px; } +.ui-icon-arrowthick-1-n { background-position: 0 -48px; } +.ui-icon-arrowthick-1-ne { background-position: -16px -48px; } +.ui-icon-arrowthick-1-e { background-position: -32px -48px; } +.ui-icon-arrowthick-1-se { background-position: -48px -48px; } +.ui-icon-arrowthick-1-s { background-position: -64px -48px; } +.ui-icon-arrowthick-1-sw { background-position: -80px -48px; } +.ui-icon-arrowthick-1-w { background-position: -96px -48px; } +.ui-icon-arrowthick-1-nw { background-position: -112px -48px; } +.ui-icon-arrowthick-2-n-s { background-position: -128px -48px; } +.ui-icon-arrowthick-2-ne-sw { background-position: -144px -48px; } +.ui-icon-arrowthick-2-e-w { background-position: -160px -48px; } +.ui-icon-arrowthick-2-se-nw { background-position: -176px -48px; } +.ui-icon-arrowthickstop-1-n { background-position: -192px -48px; } +.ui-icon-arrowthickstop-1-e { background-position: -208px -48px; } +.ui-icon-arrowthickstop-1-s { background-position: -224px -48px; } +.ui-icon-arrowthickstop-1-w { background-position: -240px -48px; } +.ui-icon-arrowreturnthick-1-w { background-position: 0 -64px; } +.ui-icon-arrowreturnthick-1-n { background-position: -16px -64px; } +.ui-icon-arrowreturnthick-1-e { background-position: -32px -64px; } +.ui-icon-arrowreturnthick-1-s { background-position: -48px -64px; } +.ui-icon-arrowreturn-1-w { background-position: -64px -64px; } +.ui-icon-arrowreturn-1-n { background-position: -80px -64px; } +.ui-icon-arrowreturn-1-e { background-position: -96px -64px; } +.ui-icon-arrowreturn-1-s { background-position: -112px -64px; } +.ui-icon-arrowrefresh-1-w { background-position: -128px -64px; } +.ui-icon-arrowrefresh-1-n { background-position: -144px -64px; } +.ui-icon-arrowrefresh-1-e { background-position: -160px -64px; } +.ui-icon-arrowrefresh-1-s { background-position: -176px -64px; } +.ui-icon-arrow-4 { background-position: 0 -80px; } +.ui-icon-arrow-4-diag { background-position: -16px -80px; } +.ui-icon-extlink { background-position: -32px -80px; } +.ui-icon-newwin { background-position: -48px -80px; } +.ui-icon-refresh { background-position: -64px -80px; } +.ui-icon-shuffle { background-position: -80px -80px; } +.ui-icon-transfer-e-w { background-position: -96px -80px; } +.ui-icon-transferthick-e-w { background-position: -112px -80px; } +.ui-icon-folder-collapsed { background-position: 0 -96px; } +.ui-icon-folder-open { background-position: -16px -96px; } +.ui-icon-document { background-position: -32px -96px; } +.ui-icon-document-b { background-position: -48px -96px; } +.ui-icon-note { background-position: -64px -96px; } +.ui-icon-mail-closed { background-position: -80px -96px; } +.ui-icon-mail-open { background-position: -96px -96px; } +.ui-icon-suitcase { background-position: -112px -96px; } +.ui-icon-comment { background-position: -128px -96px; } +.ui-icon-person { background-position: -144px -96px; } +.ui-icon-print { background-position: -160px -96px; } +.ui-icon-trash { background-position: -176px -96px; } +.ui-icon-locked { background-position: -192px -96px; } +.ui-icon-unlocked { background-position: -208px -96px; } +.ui-icon-bookmark { background-position: -224px -96px; } +.ui-icon-tag { background-position: -240px -96px; } +.ui-icon-home { background-position: 0 -112px; } +.ui-icon-flag { background-position: -16px -112px; } +.ui-icon-calendar { background-position: -32px -112px; } +.ui-icon-cart { background-position: -48px -112px; } +.ui-icon-pencil { background-position: -64px -112px; } +.ui-icon-clock { background-position: -80px -112px; } +.ui-icon-disk { background-position: -96px -112px; } +.ui-icon-calculator { background-position: -112px -112px; } +.ui-icon-zoomin { background-position: -128px -112px; } +.ui-icon-zoomout { background-position: -144px -112px; } +.ui-icon-search { background-position: -160px -112px; } +.ui-icon-wrench { background-position: -176px -112px; } +.ui-icon-gear { background-position: -192px -112px; } +.ui-icon-heart { background-position: -208px -112px; } +.ui-icon-star { background-position: -224px -112px; } +.ui-icon-link { background-position: -240px -112px; } +.ui-icon-cancel { background-position: 0 -128px; } +.ui-icon-plus { background-position: -16px -128px; } +.ui-icon-plusthick { background-position: -32px -128px; } +.ui-icon-minus { background-position: -48px -128px; } +.ui-icon-minusthick { background-position: -64px -128px; } +.ui-icon-close { background-position: -80px -128px; } +.ui-icon-closethick { background-position: -96px -128px; } +.ui-icon-key { background-position: -112px -128px; } +.ui-icon-lightbulb { background-position: -128px -128px; } +.ui-icon-scissors { background-position: -144px -128px; } +.ui-icon-clipboard { background-position: -160px -128px; } +.ui-icon-copy { background-position: -176px -128px; } +.ui-icon-contact { background-position: -192px -128px; } +.ui-icon-image { background-position: -208px -128px; } +.ui-icon-video { background-position: -224px -128px; } +.ui-icon-script { background-position: -240px -128px; } +.ui-icon-alert { background-position: 0 -144px; } +.ui-icon-info { background-position: -16px -144px; } +.ui-icon-notice { background-position: -32px -144px; } +.ui-icon-help { background-position: -48px -144px; } +.ui-icon-check { background-position: -64px -144px; } +.ui-icon-bullet { background-position: -80px -144px; } +.ui-icon-radio-off { background-position: -96px -144px; } +.ui-icon-radio-on { background-position: -112px -144px; } +.ui-icon-pin-w { background-position: -128px -144px; } +.ui-icon-pin-s { background-position: -144px -144px; } +.ui-icon-play { background-position: 0 -160px; } +.ui-icon-pause { background-position: -16px -160px; } +.ui-icon-seek-next { background-position: -32px -160px; } +.ui-icon-seek-prev { background-position: -48px -160px; } +.ui-icon-seek-end { background-position: -64px -160px; } +.ui-icon-seek-start { background-position: -80px -160px; } +/* ui-icon-seek-first is deprecated, use ui-icon-seek-start instead */ +.ui-icon-seek-first { background-position: -80px -160px; } +.ui-icon-stop { background-position: -96px -160px; } +.ui-icon-eject { background-position: -112px -160px; } +.ui-icon-volume-off { background-position: -128px -160px; } +.ui-icon-volume-on { background-position: -144px -160px; } +.ui-icon-power { background-position: 0 -176px; } +.ui-icon-signal-diag { background-position: -16px -176px; } +.ui-icon-signal { background-position: -32px -176px; } +.ui-icon-battery-0 { background-position: -48px -176px; } +.ui-icon-battery-1 { background-position: -64px -176px; } +.ui-icon-battery-2 { background-position: -80px -176px; } +.ui-icon-battery-3 { background-position: -96px -176px; } +.ui-icon-circle-plus { background-position: 0 -192px; } +.ui-icon-circle-minus { background-position: -16px -192px; } +.ui-icon-circle-close { background-position: -32px -192px; } +.ui-icon-circle-triangle-e { background-position: -48px -192px; } +.ui-icon-circle-triangle-s { background-position: -64px -192px; } +.ui-icon-circle-triangle-w { background-position: -80px -192px; } +.ui-icon-circle-triangle-n { background-position: -96px -192px; } +.ui-icon-circle-arrow-e { background-position: -112px -192px; } +.ui-icon-circle-arrow-s { background-position: -128px -192px; } +.ui-icon-circle-arrow-w { background-position: -144px -192px; } +.ui-icon-circle-arrow-n { background-position: -160px -192px; } +.ui-icon-circle-zoomin { background-position: -176px -192px; } +.ui-icon-circle-zoomout { background-position: -192px -192px; } +.ui-icon-circle-check { background-position: -208px -192px; } +.ui-icon-circlesmall-plus { background-position: 0 -208px; } +.ui-icon-circlesmall-minus { background-position: -16px -208px; } +.ui-icon-circlesmall-close { background-position: -32px -208px; } +.ui-icon-squaresmall-plus { background-position: -48px -208px; } +.ui-icon-squaresmall-minus { background-position: -64px -208px; } +.ui-icon-squaresmall-close { background-position: -80px -208px; } +.ui-icon-grip-dotted-vertical { background-position: 0 -224px; } +.ui-icon-grip-dotted-horizontal { background-position: -16px -224px; } +.ui-icon-grip-solid-vertical { background-position: -32px -224px; } +.ui-icon-grip-solid-horizontal { background-position: -48px -224px; } +.ui-icon-gripsmall-diagonal-se { background-position: -64px -224px; } +.ui-icon-grip-diagonal-se { background-position: -80px -224px; } + + +/* Misc visuals +----------------------------------*/ + +/* Corner radius */ +.ui-corner-all, .ui-corner-top, .ui-corner-left, .ui-corner-tl { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; -khtml-border-top-left-radius: 4px; border-top-left-radius: 4px; } +.ui-corner-all, .ui-corner-top, .ui-corner-right, .ui-corner-tr { -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; -khtml-border-top-right-radius: 4px; border-top-right-radius: 4px; } +.ui-corner-all, .ui-corner-bottom, .ui-corner-left, .ui-corner-bl { -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; -khtml-border-bottom-left-radius: 4px; border-bottom-left-radius: 4px; } +.ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br { -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; -khtml-border-bottom-right-radius: 4px; border-bottom-right-radius: 4px; } + +/* Overlays */ +.ui-widget-overlay { background: #aaaaaa url(/s/img/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x; opacity: .30;filter:Alpha(Opacity=30); } +.ui-widget-shadow { margin: -8px 0 0 -8px; padding: 8px; background: #aaaaaa url(/s/img/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x; opacity: .30;filter:Alpha(Opacity=30); -moz-border-radius: 8px; -khtml-border-radius: 8px; -webkit-border-radius: 8px; border-radius: 8px; }/*! + * jQuery UI Resizable 1.8.23 + * + * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Resizable#theming + */ +.ui-resizable { position: relative;} +.ui-resizable-handle { position: absolute;font-size: 0.1px; display: block; } +.ui-resizable-disabled .ui-resizable-handle, .ui-resizable-autohide .ui-resizable-handle { display: none; } +.ui-resizable-n { cursor: n-resize; height: 7px; width: 100%; top: -5px; left: 0; } +.ui-resizable-s { cursor: s-resize; height: 7px; width: 100%; bottom: -5px; left: 0; } +.ui-resizable-e { cursor: e-resize; width: 7px; right: -5px; top: 0; height: 100%; } +.ui-resizable-w { cursor: w-resize; width: 7px; left: -5px; top: 0; height: 100%; } +.ui-resizable-se { cursor: se-resize; width: 12px; height: 12px; right: 1px; bottom: 1px; } +.ui-resizable-sw { cursor: sw-resize; width: 9px; height: 9px; left: -5px; bottom: -5px; } +.ui-resizable-nw { cursor: nw-resize; width: 9px; height: 9px; left: -5px; top: -5px; } +.ui-resizable-ne { cursor: ne-resize; width: 9px; height: 9px; right: -5px; top: -5px;}/*! + * jQuery UI Selectable 1.8.23 + * + * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Selectable#theming + */ +.ui-selectable-helper { position: absolute; z-index: 100; border:1px dotted black; } +/*! + * jQuery UI Accordion 1.8.23 + * + * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Accordion#theming + */ +/* IE/Win - Fix animation bug - #4615 */ +.ui-accordion { width: 100%; } +.ui-accordion .ui-accordion-header { cursor: pointer; position: relative; margin-top: 1px; zoom: 1; } +.ui-accordion .ui-accordion-li-fix { display: inline; } +.ui-accordion .ui-accordion-header-active { border-bottom: 0 !important; } +.ui-accordion .ui-accordion-header a { display: block; font-size: 1em; padding: .5em .5em .5em .7em; } +.ui-accordion-icons .ui-accordion-header a { padding-left: 2.2em; } +.ui-accordion .ui-accordion-header .ui-icon { position: absolute; left: .5em; top: 50%; margin-top: -8px; } +.ui-accordion .ui-accordion-content { padding: 1em 2.2em; border-top: 0; margin-top: -2px; position: relative; top: 1px; margin-bottom: 2px; overflow: auto; display: none; zoom: 1; } +.ui-accordion .ui-accordion-content-active { display: block; } +/*! + * jQuery UI Autocomplete 1.8.23 + * + * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Autocomplete#theming + */ +.ui-autocomplete { position: absolute; cursor: default; } + +/* workarounds */ +* html .ui-autocomplete { width:1px; } /* without this, the menu expands to 100% in IE6 */ + +/* + * jQuery UI Menu 1.8.23 + * + * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Menu#theming + */ +.ui-menu { + list-style:none; + padding: 2px; + margin: 0; + display:block; + float: left; +} +.ui-menu .ui-menu { + margin-top: -3px; +} +.ui-menu .ui-menu-item { + margin:0; + padding: 0; + zoom: 1; + float: left; + clear: left; + width: 100%; +} +.ui-menu .ui-menu-item a { + text-decoration:none; + display:block; + padding:.2em .4em; + line-height:1.5; + zoom:1; +} +.ui-menu .ui-menu-item a.ui-state-hover, +.ui-menu .ui-menu-item a.ui-state-active { + font-weight: normal; + margin: -1px; +} +/*! + * jQuery UI Button 1.8.23 + * + * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Button#theming + */ +.ui-button { display: inline-block; position: relative; padding: 0; margin-right: .1em; text-decoration: none !important; cursor: pointer; text-align: center; zoom: 1; overflow: visible; } /* the overflow property removes extra width in IE */ +.ui-button-icon-only { width: 2.2em; } /* to make room for the icon, a width needs to be set here */ +button.ui-button-icon-only { width: 2.4em; } /* button elements seem to need a little more width */ +.ui-button-icons-only { width: 3.4em; } +button.ui-button-icons-only { width: 3.7em; } + +/*button text element */ +.ui-button .ui-button-text { display: block; line-height: 1.4; } +.ui-button-text-only .ui-button-text { padding: .4em 1em; } +.ui-button-icon-only .ui-button-text, .ui-button-icons-only .ui-button-text { padding: .4em; text-indent: -9999999px; } +.ui-button-text-icon-primary .ui-button-text, .ui-button-text-icons .ui-button-text { padding: .4em 1em .4em 2.1em; } +.ui-button-text-icon-secondary .ui-button-text, .ui-button-text-icons .ui-button-text { padding: .4em 2.1em .4em 1em; } +.ui-button-text-icons .ui-button-text { padding-left: 2.1em; padding-right: 2.1em; } +/* no icon support for input elements, provide padding by default */ +input.ui-button { padding: .4em 1em; } + +/*button icon element(s) */ +.ui-button-icon-only .ui-icon, .ui-button-text-icon-primary .ui-icon, .ui-button-text-icon-secondary .ui-icon, .ui-button-text-icons .ui-icon, .ui-button-icons-only .ui-icon { position: absolute; top: 50%; margin-top: -8px; } +.ui-button-icon-only .ui-icon { left: 50%; margin-left: -8px; } +.ui-button-text-icon-primary .ui-button-icon-primary, .ui-button-text-icons .ui-button-icon-primary, .ui-button-icons-only .ui-button-icon-primary { left: .5em; } +.ui-button-text-icon-secondary .ui-button-icon-secondary, .ui-button-text-icons .ui-button-icon-secondary, .ui-button-icons-only .ui-button-icon-secondary { right: .5em; } +.ui-button-text-icons .ui-button-icon-secondary, .ui-button-icons-only .ui-button-icon-secondary { right: .5em; } + +/*button sets*/ +.ui-buttonset { margin-right: 7px; } +.ui-buttonset .ui-button { margin-left: 0; margin-right: -.3em; } + +/* workarounds */ +button.ui-button::-moz-focus-inner { border: 0; padding: 0; } /* reset extra padding in Firefox */ +/*! + * jQuery UI Dialog 1.8.23 + * + * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Dialog#theming + */ +.ui-dialog { position: absolute; padding: .2em; width: 300px; overflow: hidden; } +.ui-dialog .ui-dialog-titlebar { padding: .4em 1em; position: relative; } +.ui-dialog .ui-dialog-title { float: left; margin: .1em 16px .1em 0; } +.ui-dialog .ui-dialog-titlebar-close { position: absolute; right: .3em; top: 50%; width: 19px; margin: -10px 0 0 0; padding: 1px; height: 18px; } +.ui-dialog .ui-dialog-titlebar-close span { display: block; margin: 1px; } +.ui-dialog .ui-dialog-titlebar-close:hover, .ui-dialog .ui-dialog-titlebar-close:focus { padding: 0; } +.ui-dialog .ui-dialog-content { position: relative; border: 0; padding: .5em 1em; background: none; overflow: auto; zoom: 1; } +.ui-dialog .ui-dialog-buttonpane { text-align: left; border-width: 1px 0 0 0; background-image: none; margin: .5em 0 0 0; padding: .3em 1em .5em .4em; } +.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset { float: right; } +.ui-dialog .ui-dialog-buttonpane button { margin: .5em .4em .5em 0; cursor: pointer; } +.ui-dialog .ui-resizable-se { width: 14px; height: 14px; right: 3px; bottom: 3px; } +.ui-draggable .ui-dialog-titlebar { cursor: move; } +/*! + * jQuery UI Slider 1.8.23 + * + * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Slider#theming + */ +.ui-slider { position: relative; text-align: left; } +.ui-slider .ui-slider-handle { position: absolute; z-index: 2; width: 1.2em; height: 1.2em; cursor: default; } +.ui-slider .ui-slider-range { position: absolute; z-index: 1; font-size: .7em; display: block; border: 0; background-position: 0 0; } + +.ui-slider-horizontal { height: .8em; } +.ui-slider-horizontal .ui-slider-handle { top: -.3em; margin-left: -.6em; } +.ui-slider-horizontal .ui-slider-range { top: 0; height: 100%; } +.ui-slider-horizontal .ui-slider-range-min { left: 0; } +.ui-slider-horizontal .ui-slider-range-max { right: 0; } + +.ui-slider-vertical { width: .8em; height: 100px; } +.ui-slider-vertical .ui-slider-handle { left: -.3em; margin-left: 0; margin-bottom: -.6em; } +.ui-slider-vertical .ui-slider-range { left: 0; width: 100%; } +.ui-slider-vertical .ui-slider-range-min { bottom: 0; } +.ui-slider-vertical .ui-slider-range-max { top: 0; }/*! + * jQuery UI Tabs 1.8.23 + * + * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Tabs#theming + */ +.ui-tabs { position: relative; padding: .2em; zoom: 1; } /* position: relative prevents IE scroll bug (element with position: relative inside container with overflow: auto appear as "fixed") */ +.ui-tabs .ui-tabs-nav { margin: 0; padding: .2em .2em 0; } +.ui-tabs .ui-tabs-nav li { list-style: none; float: left; position: relative; top: 1px; margin: 0 .2em 1px 0; border-bottom: 0 !important; padding: 0; white-space: nowrap; } +.ui-tabs .ui-tabs-nav li a { float: left; padding: .5em 1em; text-decoration: none; } +.ui-tabs .ui-tabs-nav li.ui-tabs-selected { margin-bottom: 0; padding-bottom: 1px; } +.ui-tabs .ui-tabs-nav li.ui-tabs-selected a, .ui-tabs .ui-tabs-nav li.ui-state-disabled a, .ui-tabs .ui-tabs-nav li.ui-state-processing a { cursor: text; } +.ui-tabs .ui-tabs-nav li a, .ui-tabs.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-selected a { cursor: pointer; } /* first selector in group seems obsolete, but required to overcome bug in Opera applying cursor: text overall if defined elsewhere... */ +.ui-tabs .ui-tabs-panel { display: block; border-width: 0; padding: 1em 1.4em; background: none; } +.ui-tabs .ui-tabs-hide { display: none !important; } +/*! + * jQuery UI Datepicker 1.8.23 + * + * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Datepicker#theming + */ +.ui-datepicker { width: 17em; padding: .2em .2em 0; display: none; } +.ui-datepicker .ui-datepicker-header { position:relative; padding:.2em 0; } +.ui-datepicker .ui-datepicker-prev, .ui-datepicker .ui-datepicker-next { position:absolute; top: 2px; width: 1.8em; height: 1.8em; } +.ui-datepicker .ui-datepicker-prev-hover, .ui-datepicker .ui-datepicker-next-hover { top: 1px; } +.ui-datepicker .ui-datepicker-prev { left:2px; } +.ui-datepicker .ui-datepicker-next { right:2px; } +.ui-datepicker .ui-datepicker-prev-hover { left:1px; } +.ui-datepicker .ui-datepicker-next-hover { right:1px; } +.ui-datepicker .ui-datepicker-prev span, .ui-datepicker .ui-datepicker-next span { display: block; position: absolute; left: 50%; margin-left: -8px; top: 50%; margin-top: -8px; } +.ui-datepicker .ui-datepicker-title { margin: 0 2.3em; line-height: 1.8em; text-align: center; } +.ui-datepicker .ui-datepicker-title select { font-size:1em; margin:1px 0; } +.ui-datepicker select.ui-datepicker-month-year {width: 100%;} +.ui-datepicker select.ui-datepicker-month, +.ui-datepicker select.ui-datepicker-year { width: 49%;} +.ui-datepicker table {width: 100%; font-size: .9em; border-collapse: collapse; margin:0 0 .4em; } +.ui-datepicker th { padding: .7em .3em; text-align: center; font-weight: bold; border: 0; } +.ui-datepicker td { border: 0; padding: 1px; } +.ui-datepicker td span, .ui-datepicker td a { display: block; padding: .2em; text-align: right; text-decoration: none; } +.ui-datepicker .ui-datepicker-buttonpane { background-image: none; margin: .7em 0 0 0; padding:0 .2em; border-left: 0; border-right: 0; border-bottom: 0; } +.ui-datepicker .ui-datepicker-buttonpane button { float: right; margin: .5em .2em .4em; cursor: pointer; padding: .2em .6em .3em .6em; width:auto; overflow:visible; } +.ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current { float:left; } + +/* with multiple calendars */ +.ui-datepicker.ui-datepicker-multi { width:auto; } +.ui-datepicker-multi .ui-datepicker-group { float:left; } +.ui-datepicker-multi .ui-datepicker-group table { width:95%; margin:0 auto .4em; } +.ui-datepicker-multi-2 .ui-datepicker-group { width:50%; } +.ui-datepicker-multi-3 .ui-datepicker-group { width:33.3%; } +.ui-datepicker-multi-4 .ui-datepicker-group { width:25%; } +.ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header { border-left-width:0; } +.ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header { border-left-width:0; } +.ui-datepicker-multi .ui-datepicker-buttonpane { clear:left; } +.ui-datepicker-row-break { clear:both; width:100%; font-size:0em; } + +/* RTL support */ +.ui-datepicker-rtl { direction: rtl; } +.ui-datepicker-rtl .ui-datepicker-prev { right: 2px; left: auto; } +.ui-datepicker-rtl .ui-datepicker-next { left: 2px; right: auto; } +.ui-datepicker-rtl .ui-datepicker-prev:hover { right: 1px; left: auto; } +.ui-datepicker-rtl .ui-datepicker-next:hover { left: 1px; right: auto; } +.ui-datepicker-rtl .ui-datepicker-buttonpane { clear:right; } +.ui-datepicker-rtl .ui-datepicker-buttonpane button { float: left; } +.ui-datepicker-rtl .ui-datepicker-buttonpane button.ui-datepicker-current { float:right; } +.ui-datepicker-rtl .ui-datepicker-group { float:right; } +.ui-datepicker-rtl .ui-datepicker-group-last .ui-datepicker-header { border-right-width:0; border-left-width:1px; } +.ui-datepicker-rtl .ui-datepicker-group-middle .ui-datepicker-header { border-right-width:0; border-left-width:1px; } + +/* IE6 IFRAME FIX (taken from datepicker 1.5.3 */ +.ui-datepicker-cover { + position: absolute; /*must have*/ + z-index: -1; /*must have*/ + filter: mask(); /*must have*/ + top: -4px; /*must have*/ + left: -4px; /*must have*/ + width: 200px; /*must have*/ + height: 200px; /*must have*/ +}/*! + * jQuery UI Progressbar 1.8.23 + * + * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Progressbar#theming + */ +.ui-progressbar { height:2em; text-align: left; overflow: hidden; } +.ui-progressbar .ui-progressbar-value {margin: -1px; height:100%; } diff --git a/bodyrep/media/css/site.css b/bodyrep/media/css/site.css index c5de81f..cef3130 100644 --- a/bodyrep/media/css/site.css +++ b/bodyrep/media/css/site.css @@ -5,9 +5,11 @@ height : 1000px; } -.hidden { -display: none; +.comment[placeholder] { + width: 400px; + color: #ccc; } + .mc-main-nav { width : 170px; border-right : 1px solid #e6e6e6; @@ -19,6 +21,10 @@ display: none; color: navy; } +.hidden { + display: none; +} + .mc-profile-pic { width : 140px; height : 125px; diff --git a/bodyrep/media/js/application.js b/bodyrep/media/js/application.js index b4df4f7..0495972 100644 --- a/bodyrep/media/js/application.js +++ b/bodyrep/media/js/application.js @@ -1,5 +1,6 @@ -$(function() { + +$(document).ready(function() { $('#edprf').unbind().live('click', function() { $.get('/m/profile/edit', {}, function(data) { $('#mcnt').html(data); @@ -31,5 +32,69 @@ $(function() { }, function(){ $(this).animate({height:'0px'},{queue:false,duration:200}); }); + + $('.comment').keyup(function(e) { + var code = (e.keyCode ? e.keyCode : e.which); + ctx = $(this); + + if(code == 13) + { + ctx.parent().parent().find('.hidden').removeClass('hidden').find('span').html('Just now'); + var text = ctx.val(); + ctx.replaceWith(text) + } + + }); + + + $('.comment').live('focus', function() { + ctx = $(this); + if (ctx.val() == '') + { + ctx.attr('placeholder', '') + ctx.css('color', '#000') + } + }); + + $('.comment').live('blur', function(e) { + ctx = $(this); + if (ctx.val() == '') + { + ctx.attr('placeholder', 'Type something') + ctx.css('color', '#ccc') + } + }); + + var Member = Backbone.Model.extend({}); + + var MemberList = Backbone.Collection.extend({ + model: Member, + url: '/api/members/?format=json', + parse: function(response) { + return response; + } + }); + + var SelectionView = Backbone.View.extend({ + el : $('#user-selection'), + render: function() { + window.location = '/' + this.model.get('username') + return this; + }, + }); + + var members = new MemberList(); + members.fetch({async: false}); + var fns = members.pluck("fullname"); + $("#topsearch").autocomplete({ + source : fns, + minLength : 2, + select: function(event, ui){ + var selectedModel = members.where({fullname: ui.item.value})[0]; + var view = new SelectionView({model: selectedModel}); + view.render(); + } + }); }); - \ No newline at end of file + + \ No newline at end of file diff --git a/bodyrep/media/js/backbone-tastypie.js b/bodyrep/media/js/backbone-tastypie.js new file mode 100644 index 0000000..cdc7e2e --- /dev/null +++ b/bodyrep/media/js/backbone-tastypie.js @@ -0,0 +1,104 @@ +(function($, _, Backbone) { + Backbone.Tastypie = { + defaultLimit: 20 + }; + + Backbone.Tastypie.Model = Backbone.Model.extend({ + idAttribute: 'resource_uri', + + url: function() { + var url = getValue(this, 'urlRoot') || getValue(this.collection, 'urlRoot') || urlError(); + + if (this.isNew()) + return url; + + return this.get('resource_uri'); + }, + _getId: function() { + if (this.has('id')) + return this.get('id'); + + return _.chain(this.get('resource_uri').split('/')).compact().last().value(); + } + }); + + Backbone.Tastypie.Collection = Backbone.Collection.extend({ + constructor: function(models, options) { + Backbone.Collection.prototype.constructor.apply(this, arguments); + + this.meta = {}; + this.filters = { + limit: Backbone.Tastypie.defaultLimit, + offset: 0 + }; + + if (options && options.filters) + _.extend(this.filters, options.filters); + }, + url: function(models) { + var url = this.urlRoot; + + if (models) { + var ids = _.map(models, function(model) { + return model._getId(); + }); + + url += 'set/' + ids.join(';') + '/'; + } + + return url + this._getQueryString(); + }, + parse: function(response) { + if (response && response.meta) + this.meta = response.meta; + + return response && response.objects; + }, + fetchNext: function(options) { + options = options || {}; + options.add = true; + + this.filters.limit = this.meta.limit; + this.filters.offset = this.meta.offset + this.meta.limit; + + if (this.filters.offset > this.meta.total_count) + this.filters.offset = this.meta.total_count; + + return this.fetch.call(this, options); + }, + fetchPrevious: function(options) { + options = options || {}; + options.add = true; + options.at = 0; + + this.filters.limit = this.meta.limit; + this.filters.offset = this.meta.offset - this.meta.limit; + + if (this.filters.offset < 0){ + this.filters.limit += this.filters.offset; + this.filters.offset = 0; + } + + return this.fetch.call(this, options); + }, + _getQueryString: function() { + if (!this.filters) + return ''; + + return '?' + $.param(this.filters); + } + }); + + // Helper function from Backbone to get a value from a Backbone + // object as a property or as a function. + var getValue = function(object, prop) { + if ((object && object[prop])) + return _.isFunction(object[prop]) ? object[prop]() : object[prop]; + }; + + // Helper function from Backbone that raises error when a model's + // url cannot be determined. + var urlError = function() { + throw new Error('A "url" property or function must be specified'); + }; +})(window.$, window._, window.Backbone); \ No newline at end of file diff --git a/bodyrep/media/js/backbone.js b/bodyrep/media/js/backbone.js new file mode 100644 index 0000000..3373c95 --- /dev/null +++ b/bodyrep/media/js/backbone.js @@ -0,0 +1,1431 @@ +// Backbone.js 0.9.2 + +// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc. +// Backbone may be freely distributed under the MIT license. +// For all details and documentation: +// http://backbonejs.org + +(function(){ + + // Initial Setup + // ------------- + + // Save a reference to the global object (`window` in the browser, `global` + // on the server). + var root = this; + + // Save the previous value of the `Backbone` variable, so that it can be + // restored later on, if `noConflict` is used. + var previousBackbone = root.Backbone; + + // Create a local reference to slice/splice. + var slice = Array.prototype.slice; + var splice = Array.prototype.splice; + + // The top-level namespace. All public Backbone classes and modules will + // be attached to this. Exported for both CommonJS and the browser. + var Backbone; + if (typeof exports !== 'undefined') { + Backbone = exports; + } else { + Backbone = root.Backbone = {}; + } + + // Current version of the library. Keep in sync with `package.json`. + Backbone.VERSION = '0.9.2'; + + // Require Underscore, if we're on the server, and it's not already present. + var _ = root._; + if (!_ && (typeof require !== 'undefined')) _ = require('underscore'); + + // For Backbone's purposes, jQuery, Zepto, or Ender owns the `$` variable. + var $ = root.jQuery || root.Zepto || root.ender; + + // Set the JavaScript library that will be used for DOM manipulation and + // Ajax calls (a.k.a. the `$` variable). By default Backbone will use: jQuery, + // Zepto, or Ender; but the `setDomLibrary()` method lets you inject an + // alternate JavaScript library (or a mock library for testing your views + // outside of a browser). + Backbone.setDomLibrary = function(lib) { + $ = lib; + }; + + // Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable + // to its previous owner. Returns a reference to this Backbone object. + Backbone.noConflict = function() { + root.Backbone = previousBackbone; + return this; + }; + + // Turn on `emulateHTTP` to support legacy HTTP servers. Setting this option + // will fake `"PUT"` and `"DELETE"` requests via the `_method` parameter and + // set a `X-Http-Method-Override` header. + Backbone.emulateHTTP = false; + + // Turn on `emulateJSON` to support legacy servers that can't deal with direct + // `application/json` requests ... will encode the body as + // `application/x-www-form-urlencoded` instead and will send the model in a + // form param named `model`. + Backbone.emulateJSON = false; + + // Backbone.Events + // ----------------- + + // Regular expression used to split event strings + var eventSplitter = /\s+/; + + // A module that can be mixed in to *any object* in order to provide it with + // custom events. You may bind with `on` or remove with `off` callback functions + // to an event; trigger`-ing an event fires all callbacks in succession. + // + // var object = {}; + // _.extend(object, Backbone.Events); + // object.on('expand', function(){ alert('expanded'); }); + // object.trigger('expand'); + // + var Events = Backbone.Events = { + + // Bind one or more space separated events, `events`, to a `callback` + // function. Passing `"all"` will bind the callback to all events fired. + on: function(events, callback, context) { + + var calls, event, node, tail, list; + if (!callback) return this; + events = events.split(eventSplitter); + calls = this._callbacks || (this._callbacks = {}); + + // Create an immutable callback list, allowing traversal during + // modification. The tail is an empty object that will always be used + // as the next node. + while (event = events.shift()) { + list = calls[event]; + node = list ? list.tail : {}; + node.next = tail = {}; + node.context = context; + node.callback = callback; + calls[event] = {tail: tail, next: list ? list.next : node}; + } + + return this; + }, + + // Remove one or many callbacks. If `context` is null, removes all callbacks + // with that function. If `callback` is null, removes all callbacks for the + // event. If `events` is null, removes all bound callbacks for all events. + off: function(events, callback, context) { + var event, calls, node, tail, cb, ctx; + + // No events, or removing *all* events. + if (!(calls = this._callbacks)) return; + if (!(events || callback || context)) { + delete this._callbacks; + return this; + } + + // Loop through the listed events and contexts, splicing them out of the + // linked list of callbacks if appropriate. + events = events ? events.split(eventSplitter) : _.keys(calls); + while (event = events.shift()) { + node = calls[event]; + delete calls[event]; + if (!node || !(callback || context)) continue; + // Create a new list, omitting the indicated callbacks. + tail = node.tail; + while ((node = node.next) !== tail) { + cb = node.callback; + ctx = node.context; + if ((callback && cb !== callback) || (context && ctx !== context)) { + this.on(event, cb, ctx); + } + } + } + + return this; + }, + + // Trigger one or many events, firing all bound callbacks. Callbacks are + // passed the same arguments as `trigger` is, apart from the event name + // (unless you're listening on `"all"`, which will cause your callback to + // receive the true name of the event as the first argument). + trigger: function(events) { + var event, node, calls, tail, args, all, rest; + if (!(calls = this._callbacks)) return this; + all = calls.all; + events = events.split(eventSplitter); + rest = slice.call(arguments, 1); + + // For each event, walk through the linked list of callbacks twice, + // first to trigger the event, then to trigger any `"all"` callbacks. + while (event = events.shift()) { + if (node = calls[event]) { + tail = node.tail; + while ((node = node.next) !== tail) { + node.callback.apply(node.context || this, rest); + } + } + if (node = all) { + tail = node.tail; + args = [event].concat(rest); + while ((node = node.next) !== tail) { + node.callback.apply(node.context || this, args); + } + } + } + + return this; + } + + }; + + // Aliases for backwards compatibility. + Events.bind = Events.on; + Events.unbind = Events.off; + + // Backbone.Model + // -------------- + + // Create a new model, with defined attributes. A client id (`cid`) + // is automatically generated and assigned for you. + var Model = Backbone.Model = function(attributes, options) { + var defaults; + attributes || (attributes = {}); + if (options && options.parse) attributes = this.parse(attributes); + if (defaults = getValue(this, 'defaults')) { + attributes = _.extend({}, defaults, attributes); + } + if (options && options.collection) this.collection = options.collection; + this.attributes = {}; + this._escapedAttributes = {}; + this.cid = _.uniqueId('c'); + this.changed = {}; + this._silent = {}; + this._pending = {}; + this.set(attributes, {silent: true}); + // Reset change tracking. + this.changed = {}; + this._silent = {}; + this._pending = {}; + this._previousAttributes = _.clone(this.attributes); + this.initialize.apply(this, arguments); + }; + + // Attach all inheritable methods to the Model prototype. + _.extend(Model.prototype, Events, { + + // A hash of attributes whose current and previous value differ. + changed: null, + + // A hash of attributes that have silently changed since the last time + // `change` was called. Will become pending attributes on the next call. + _silent: null, + + // A hash of attributes that have changed since the last `'change'` event + // began. + _pending: null, + + // The default name for the JSON `id` attribute is `"id"`. MongoDB and + // CouchDB users may want to set this to `"_id"`. + idAttribute: 'id', + + // Initialize is an empty function by default. Override it with your own + // initialization logic. + initialize: function(){}, + + // Return a copy of the model's `attributes` object. + toJSON: function(options) { + return _.clone(this.attributes); + }, + + // Get the value of an attribute. + get: function(attr) { + return this.attributes[attr]; + }, + + // Get the HTML-escaped value of an attribute. + escape: function(attr) { + var html; + if (html = this._escapedAttributes[attr]) return html; + var val = this.get(attr); + return this._escapedAttributes[attr] = _.escape(val == null ? '' : '' + val); + }, + + // Returns `true` if the attribute contains a value that is not null + // or undefined. + has: function(attr) { + return this.get(attr) != null; + }, + + // Set a hash of model attributes on the object, firing `"change"` unless + // you choose to silence it. + set: function(key, value, options) { + var attrs, attr, val; + + // Handle both `"key", value` and `{key: value}` -style arguments. + if (_.isObject(key) || key == null) { + attrs = key; + options = value; + } else { + attrs = {}; + attrs[key] = value; + } + + // Extract attributes and options. + options || (options = {}); + if (!attrs) return this; + if (attrs instanceof Model) attrs = attrs.attributes; + if (options.unset) for (attr in attrs) attrs[attr] = void 0; + + // Run validation. + if (!this._validate(attrs, options)) return false; + + // Check for changes of `id`. + if (this.idAttribute in attrs) this.id = attrs[this.idAttribute]; + + var changes = options.changes = {}; + var now = this.attributes; + var escaped = this._escapedAttributes; + var prev = this._previousAttributes || {}; + + // For each `set` attribute... + for (attr in attrs) { + val = attrs[attr]; + + // If the new and current value differ, record the change. + if (!_.isEqual(now[attr], val) || (options.unset && _.has(now, attr))) { + delete escaped[attr]; + (options.silent ? this._silent : changes)[attr] = true; + } + + // Update or delete the current value. + options.unset ? delete now[attr] : now[attr] = val; + + // If the new and previous value differ, record the change. If not, + // then remove changes for this attribute. + if (!_.isEqual(prev[attr], val) || (_.has(now, attr) != _.has(prev, attr))) { + this.changed[attr] = val; + if (!options.silent) this._pending[attr] = true; + } else { + delete this.changed[attr]; + delete this._pending[attr]; + } + } + + // Fire the `"change"` events. + if (!options.silent) this.change(options); + return this; + }, + + // Remove an attribute from the model, firing `"change"` unless you choose + // to silence it. `unset` is a noop if the attribute doesn't exist. + unset: function(attr, options) { + (options || (options = {})).unset = true; + return this.set(attr, null, options); + }, + + // Clear all attributes on the model, firing `"change"` unless you choose + // to silence it. + clear: function(options) { + (options || (options = {})).unset = true; + return this.set(_.clone(this.attributes), options); + }, + + // Fetch the model from the server. If the server's representation of the + // model differs from its current attributes, they will be overriden, + // triggering a `"change"` event. + fetch: function(options) { + options = options ? _.clone(options) : {}; + var model = this; + var success = options.success; + options.success = function(resp, status, xhr) { + if (!model.set(model.parse(resp, xhr), options)) return false; + if (success) success(model, resp); + }; + options.error = Backbone.wrapError(options.error, model, options); + return (this.sync || Backbone.sync).call(this, 'read', this, options); + }, + + // Set a hash of model attributes, and sync the model to the server. + // If the server returns an attributes hash that differs, the model's + // state will be `set` again. + save: function(key, value, options) { + var attrs, current; + + // Handle both `("key", value)` and `({key: value})` -style calls. + if (_.isObject(key) || key == null) { + attrs = key; + options = value; + } else { + attrs = {}; + attrs[key] = value; + } + options = options ? _.clone(options) : {}; + + // If we're "wait"-ing to set changed attributes, validate early. + if (options.wait) { + if (!this._validate(attrs, options)) return false; + current = _.clone(this.attributes); + } + + // Regular saves `set` attributes before persisting to the server. + var silentOptions = _.extend({}, options, {silent: true}); + if (attrs && !this.set(attrs, options.wait ? silentOptions : options)) { + return false; + } + + // After a successful server-side save, the client is (optionally) + // updated with the server-side state. + var model = this; + var success = options.success; + options.success = function(resp, status, xhr) { + var serverAttrs = model.parse(resp, xhr); + if (options.wait) { + delete options.wait; + serverAttrs = _.extend(attrs || {}, serverAttrs); + } + if (!model.set(serverAttrs, options)) return false; + if (success) { + success(model, resp); + } else { + model.trigger('sync', model, resp, options); + } + }; + + // Finish configuring and sending the Ajax request. + options.error = Backbone.wrapError(options.error, model, options); + var method = this.isNew() ? 'create' : 'update'; + var xhr = (this.sync || Backbone.sync).call(this, method, this, options); + if (options.wait) this.set(current, silentOptions); + return xhr; + }, + + // Destroy this model on the server if it was already persisted. + // Optimistically removes the model from its collection, if it has one. + // If `wait: true` is passed, waits for the server to respond before removal. + destroy: function(options) { + options = options ? _.clone(options) : {}; + var model = this; + var success = options.success; + + var triggerDestroy = function() { + model.trigger('destroy', model, model.collection, options); + }; + + if (this.isNew()) { + triggerDestroy(); + return false; + } + + options.success = function(resp) { + if (options.wait) triggerDestroy(); + if (success) { + success(model, resp); + } else { + model.trigger('sync', model, resp, options); + } + }; + + options.error = Backbone.wrapError(options.error, model, options); + var xhr = (this.sync || Backbone.sync).call(this, 'delete', this, options); + if (!options.wait) triggerDestroy(); + return xhr; + }, + + // Default URL for the model's representation on the server -- if you're + // using Backbone's restful methods, override this to change the endpoint + // that will be called. + url: function() { + var base = getValue(this, 'urlRoot') || getValue(this.collection, 'url') || urlError(); + if (this.isNew()) return base; + return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + encodeURIComponent(this.id); + }, + + // **parse** converts a response into the hash of attributes to be `set` on + // the model. The default implementation is just to pass the response along. + parse: function(resp, xhr) { + return resp; + }, + + // Create a new model with identical attributes to this one. + clone: function() { + return new this.constructor(this.attributes); + }, + + // A model is new if it has never been saved to the server, and lacks an id. + isNew: function() { + return this.id == null; + }, + + // Call this method to manually fire a `"change"` event for this model and + // a `"change:attribute"` event for each changed attribute. + // Calling this will cause all objects observing the model to update. + change: function(options) { + options || (options = {}); + var changing = this._changing; + this._changing = true; + + // Silent changes become pending changes. + for (var attr in this._silent) this._pending[attr] = true; + + // Silent changes are triggered. + var changes = _.extend({}, options.changes, this._silent); + this._silent = {}; + for (var attr in changes) { + this.trigger('change:' + attr, this, this.get(attr), options); + } + if (changing) return this; + + // Continue firing `"change"` events while there are pending changes. + while (!_.isEmpty(this._pending)) { + this._pending = {}; + this.trigger('change', this, options); + // Pending and silent changes still remain. + for (var attr in this.changed) { + if (this._pending[attr] || this._silent[attr]) continue; + delete this.changed[attr]; + } + this._previousAttributes = _.clone(this.attributes); + } + + this._changing = false; + return this; + }, + + // Determine if the model has changed since the last `"change"` event. + // If you specify an attribute name, determine if that attribute has changed. + hasChanged: function(attr) { + if (!arguments.length) return !_.isEmpty(this.changed); + return _.has(this.changed, attr); + }, + + // Return an object containing all the attributes that have changed, or + // false if there are no changed attributes. Useful for determining what + // parts of a view need to be updated and/or what attributes need to be + // persisted to the server. Unset attributes will be set to undefined. + // You can also pass an attributes object to diff against the model, + // determining if there *would be* a change. + changedAttributes: function(diff) { + if (!diff) return this.hasChanged() ? _.clone(this.changed) : false; + var val, changed = false, old = this._previousAttributes; + for (var attr in diff) { + if (_.isEqual(old[attr], (val = diff[attr]))) continue; + (changed || (changed = {}))[attr] = val; + } + return changed; + }, + + // Get the previous value of an attribute, recorded at the time the last + // `"change"` event was fired. + previous: function(attr) { + if (!arguments.length || !this._previousAttributes) return null; + return this._previousAttributes[attr]; + }, + + // Get all of the attributes of the model at the time of the previous + // `"change"` event. + previousAttributes: function() { + return _.clone(this._previousAttributes); + }, + + // Check if the model is currently in a valid state. It's only possible to + // get into an *invalid* state if you're using silent changes. + isValid: function() { + return !this.validate(this.attributes); + }, + + // Run validation against the next complete set of model attributes, + // returning `true` if all is well. If a specific `error` callback has + // been passed, call that instead of firing the general `"error"` event. + _validate: function(attrs, options) { + if (options.silent || !this.validate) return true; + attrs = _.extend({}, this.attributes, attrs); + var error = this.validate(attrs, options); + if (!error) return true; + if (options && options.error) { + options.error(this, error, options); + } else { + this.trigger('error', this, error, options); + } + return false; + } + + }); + + // Backbone.Collection + // ------------------- + + // Provides a standard collection class for our sets of models, ordered + // or unordered. If a `comparator` is specified, the Collection will maintain + // its models in sort order, as they're added and removed. + var Collection = Backbone.Collection = function(models, options) { + options || (options = {}); + if (options.model) this.model = options.model; + if (options.comparator) this.comparator = options.comparator; + this._reset(); + this.initialize.apply(this, arguments); + if (models) this.reset(models, {silent: true, parse: options.parse}); + }; + + // Define the Collection's inheritable methods. + _.extend(Collection.prototype, Events, { + + // The default model for a collection is just a **Backbone.Model**. + // This should be overridden in most cases. + model: Model, + + // Initialize is an empty function by default. Override it with your own + // initialization logic. + initialize: function(){}, + + // The JSON representation of a Collection is an array of the + // models' attributes. + toJSON: function(options) { + return this.map(function(model){ return model.toJSON(options); }); + }, + + // Add a model, or list of models to the set. Pass **silent** to avoid + // firing the `add` event for every new model. + add: function(models, options) { + var i, index, length, model, cid, id, cids = {}, ids = {}, dups = []; + options || (options = {}); + models = _.isArray(models) ? models.slice() : [models]; + + // Begin by turning bare objects into model references, and preventing + // invalid models or duplicate models from being added. + for (i = 0, length = models.length; i < length; i++) { + if (!(model = models[i] = this._prepareModel(models[i], options))) { + throw new Error("Can't add an invalid model to a collection"); + } + cid = model.cid; + id = model.id; + if (cids[cid] || this._byCid[cid] || ((id != null) && (ids[id] || this._byId[id]))) { + dups.push(i); + continue; + } + cids[cid] = ids[id] = model; + } + + // Remove duplicates. + i = dups.length; + while (i--) { + models.splice(dups[i], 1); + } + + // Listen to added models' events, and index models for lookup by + // `id` and by `cid`. + for (i = 0, length = models.length; i < length; i++) { + (model = models[i]).on('all', this._onModelEvent, this); + this._byCid[model.cid] = model; + if (model.id != null) this._byId[model.id] = model; + } + + // Insert models into the collection, re-sorting if needed, and triggering + // `add` events unless silenced. + this.length += length; + index = options.at != null ? options.at : this.models.length; + splice.apply(this.models, [index, 0].concat(models)); + if (this.comparator) this.sort({silent: true}); + if (options.silent) return this; + for (i = 0, length = this.models.length; i < length; i++) { + if (!cids[(model = this.models[i]).cid]) continue; + options.index = i; + model.trigger('add', model, this, options); + } + return this; + }, + + // Remove a model, or a list of models from the set. Pass silent to avoid + // firing the `remove` event for every model removed. + remove: function(models, options) { + var i, l, index, model; + options || (options = {}); + models = _.isArray(models) ? models.slice() : [models]; + for (i = 0, l = models.length; i < l; i++) { + model = this.getByCid(models[i]) || this.get(models[i]); + if (!model) continue; + delete this._byId[model.id]; + delete this._byCid[model.cid]; + index = this.indexOf(model); + this.models.splice(index, 1); + this.length--; + if (!options.silent) { + options.index = index; + model.trigger('remove', model, this, options); + } + this._removeReference(model); + } + return this; + }, + + // Add a model to the end of the collection. + push: function(model, options) { + model = this._prepareModel(model, options); + this.add(model, options); + return model; + }, + + // Remove a model from the end of the collection. + pop: function(options) { + var model = this.at(this.length - 1); + this.remove(model, options); + return model; + }, + + // Add a model to the beginning of the collection. + unshift: function(model, options) { + model = this._prepareModel(model, options); + this.add(model, _.extend({at: 0}, options)); + return model; + }, + + // Remove a model from the beginning of the collection. + shift: function(options) { + var model = this.at(0); + this.remove(model, options); + return model; + }, + + // Get a model from the set by id. + get: function(id) { + if (id == null) return void 0; + return this._byId[id.id != null ? id.id : id]; + }, + + // Get a model from the set by client id. + getByCid: function(cid) { + return cid && this._byCid[cid.cid || cid]; + }, + + // Get the model at the given index. + at: function(index) { + return this.models[index]; + }, + + // Return models with matching attributes. Useful for simple cases of `filter`. + where: function(attrs) { + if (_.isEmpty(attrs)) return []; + return this.filter(function(model) { + for (var key in attrs) { + if (attrs[key] !== model.get(key)) return false; + } + return true; + }); + }, + + // Force the collection to re-sort itself. You don't need to call this under + // normal circumstances, as the set will maintain sort order as each item + // is added. + sort: function(options) { + options || (options = {}); + if (!this.comparator) throw new Error('Cannot sort a set without a comparator'); + var boundComparator = _.bind(this.comparator, this); + if (this.comparator.length == 1) { + this.models = this.sortBy(boundComparator); + } else { + this.models.sort(boundComparator); + } + if (!options.silent) this.trigger('reset', this, options); + return this; + }, + + // Pluck an attribute from each model in the collection. + pluck: function(attr) { + return _.map(this.models, function(model){ return model.get(attr); }); + }, + + // When you have more items than you want to add or remove individually, + // you can reset the entire set with a new list of models, without firing + // any `add` or `remove` events. Fires `reset` when finished. + reset: function(models, options) { + models || (models = []); + options || (options = {}); + for (var i = 0, l = this.models.length; i < l; i++) { + this._removeReference(this.models[i]); + } + this._reset(); + this.add(models, _.extend({silent: true}, options)); + if (!options.silent) this.trigger('reset', this, options); + return this; + }, + + // Fetch the default set of models for this collection, resetting the + // collection when they arrive. If `add: true` is passed, appends the + // models to the collection instead of resetting. + fetch: function(options) { + options = options ? _.clone(options) : {}; + if (options.parse === undefined) options.parse = true; + var collection = this; + var success = options.success; + options.success = function(resp, status, xhr) { + collection[options.add ? 'add' : 'reset'](collection.parse(resp, xhr), options); + if (success) success(collection, resp); + }; + options.error = Backbone.wrapError(options.error, collection, options); + return (this.sync || Backbone.sync).call(this, 'read', this, options); + }, + + // Create a new instance of a model in this collection. Add the model to the + // collection immediately, unless `wait: true` is passed, in which case we + // wait for the server to agree. + create: function(model, options) { + var coll = this; + options = options ? _.clone(options) : {}; + model = this._prepareModel(model, options); + if (!model) return false; + if (!options.wait) coll.add(model, options); + var success = options.success; + options.success = function(nextModel, resp, xhr) { + if (options.wait) coll.add(nextModel, options); + if (success) { + success(nextModel, resp); + } else { + nextModel.trigger('sync', model, resp, options); + } + }; + model.save(null, options); + return model; + }, + + // **parse** converts a response into a list of models to be added to the + // collection. The default implementation is just to pass it through. + parse: function(resp, xhr) { + return resp; + }, + + // Proxy to _'s chain. Can't be proxied the same way the rest of the + // underscore methods are proxied because it relies on the underscore + // constructor. + chain: function () { + return _(this.models).chain(); + }, + + // Reset all internal state. Called when the collection is reset. + _reset: function(options) { + this.length = 0; + this.models = []; + this._byId = {}; + this._byCid = {}; + }, + + // Prepare a model or hash of attributes to be added to this collection. + _prepareModel: function(model, options) { + options || (options = {}); + if (!(model instanceof Model)) { + var attrs = model; + options.collection = this; + model = new this.model(attrs, options); + if (!model._validate(model.attributes, options)) model = false; + } else if (!model.collection) { + model.collection = this; + } + return model; + }, + + // Internal method to remove a model's ties to a collection. + _removeReference: function(model) { + if (this == model.collection) { + delete model.collection; + } + model.off('all', this._onModelEvent, this); + }, + + // Internal method called every time a model in the set fires an event. + // Sets need to update their indexes when models change ids. All other + // events simply proxy through. "add" and "remove" events that originate + // in other collections are ignored. + _onModelEvent: function(event, model, collection, options) { + if ((event == 'add' || event == 'remove') && collection != this) return; + if (event == 'destroy') { + this.remove(model, options); + } + if (model && event === 'change:' + model.idAttribute) { + delete this._byId[model.previous(model.idAttribute)]; + this._byId[model.id] = model; + } + this.trigger.apply(this, arguments); + } + + }); + + // Underscore methods that we want to implement on the Collection. + var methods = ['forEach', 'each', 'map', 'reduce', 'reduceRight', 'find', + 'detect', 'filter', 'select', 'reject', 'every', 'all', 'some', 'any', + 'include', 'contains', 'invoke', 'max', 'min', 'sortBy', 'sortedIndex', + 'toArray', 'size', 'first', 'initial', 'rest', 'last', 'without', 'indexOf', + 'shuffle', 'lastIndexOf', 'isEmpty', 'groupBy']; + + // Mix in each Underscore method as a proxy to `Collection#models`. + _.each(methods, function(method) { + Collection.prototype[method] = function() { + return _[method].apply(_, [this.models].concat(_.toArray(arguments))); + }; + }); + + // Backbone.Router + // ------------------- + + // Routers map faux-URLs to actions, and fire events when routes are + // matched. Creating a new one sets its `routes` hash, if not set statically. + var Router = Backbone.Router = function(options) { + options || (options = {}); + if (options.routes) this.routes = options.routes; + this._bindRoutes(); + this.initialize.apply(this, arguments); + }; + + // Cached regular expressions for matching named param parts and splatted + // parts of route strings. + var namedParam = /:\w+/g; + var splatParam = /\*\w+/g; + var escapeRegExp = /[-[\]{}()+?.,\\^$|#\s]/g; + + // Set up all inheritable **Backbone.Router** properties and methods. + _.extend(Router.prototype, Events, { + + // Initialize is an empty function by default. Override it with your own + // initialization logic. + initialize: function(){}, + + // Manually bind a single named route to a callback. For example: + // + // this.route('search/:query/p:num', 'search', function(query, num) { + // ... + // }); + // + route: function(route, name, callback) { + Backbone.history || (Backbone.history = new History); + if (!_.isRegExp(route)) route = this._routeToRegExp(route); + if (!callback) callback = this[name]; + Backbone.history.route(route, _.bind(function(fragment) { + var args = this._extractParameters(route, fragment); + callback && callback.apply(this, args); + this.trigger.apply(this, ['route:' + name].concat(args)); + Backbone.history.trigger('route', this, name, args); + }, this)); + return this; + }, + + // Simple proxy to `Backbone.history` to save a fragment into the history. + navigate: function(fragment, options) { + Backbone.history.navigate(fragment, options); + }, + + // Bind all defined routes to `Backbone.history`. We have to reverse the + // order of the routes here to support behavior where the most general + // routes can be defined at the bottom of the route map. + _bindRoutes: function() { + if (!this.routes) return; + var routes = []; + for (var route in this.routes) { + routes.unshift([route, this.routes[route]]); + } + for (var i = 0, l = routes.length; i < l; i++) { + this.route(routes[i][0], routes[i][1], this[routes[i][1]]); + } + }, + + // Convert a route string into a regular expression, suitable for matching + // against the current location hash. + _routeToRegExp: function(route) { + route = route.replace(escapeRegExp, '\\$&') + .replace(namedParam, '([^\/]+)') + .replace(splatParam, '(.*?)'); + return new RegExp('^' + route + '$'); + }, + + // Given a route, and a URL fragment that it matches, return the array of + // extracted parameters. + _extractParameters: function(route, fragment) { + return route.exec(fragment).slice(1); + } + + }); + + // Backbone.History + // ---------------- + + // Handles cross-browser history management, based on URL fragments. If the + // browser does not support `onhashchange`, falls back to polling. + var History = Backbone.History = function() { + this.handlers = []; + _.bindAll(this, 'checkUrl'); + }; + + // Cached regex for cleaning leading hashes and slashes . + var routeStripper = /^[#\/]/; + + // Cached regex for detecting MSIE. + var isExplorer = /msie [\w.]+/; + + // Has the history handling already been started? + History.started = false; + + // Set up all inheritable **Backbone.History** properties and methods. + _.extend(History.prototype, Events, { + + // The default interval to poll for hash changes, if necessary, is + // twenty times a second. + interval: 50, + + // Gets the true hash value. Cannot use location.hash directly due to bug + // in Firefox where location.hash will always be decoded. + getHash: function(windowOverride) { + var loc = windowOverride ? windowOverride.location : window.location; + var match = loc.href.match(/#(.*)$/); + return match ? match[1] : ''; + }, + + // Get the cross-browser normalized URL fragment, either from the URL, + // the hash, or the override. + getFragment: function(fragment, forcePushState) { + if (fragment == null) { + if (this._hasPushState || forcePushState) { + fragment = window.location.pathname; + var search = window.location.search; + if (search) fragment += search; + } else { + fragment = this.getHash(); + } + } + if (!fragment.indexOf(this.options.root)) fragment = fragment.substr(this.options.root.length); + return fragment.replace(routeStripper, ''); + }, + + // Start the hash change handling, returning `true` if the current URL matches + // an existing route, and `false` otherwise. + start: function(options) { + if (History.started) throw new Error("Backbone.history has already been started"); + History.started = true; + + // Figure out the initial configuration. Do we need an iframe? + // Is pushState desired ... is it available? + this.options = _.extend({}, {root: '/'}, this.options, options); + this._wantsHashChange = this.options.hashChange !== false; + this._wantsPushState = !!this.options.pushState; + this._hasPushState = !!(this.options.pushState && window.history && window.history.pushState); + var fragment = this.getFragment(); + var docMode = document.documentMode; + var oldIE = (isExplorer.exec(navigator.userAgent.toLowerCase()) && (!docMode || docMode <= 7)); + + if (oldIE) { + this.iframe = $('