Merged community tracking branch from esanchez@yaco.es, r3175-3679,3713-3830.

[[Split portion of a mixed commit.]]
 - Legacy-Id: 4518.2
This commit is contained in:
Henrik Levkowetz 2012-06-27 08:15:14 +00:00
commit b2573a43aa
24 changed files with 935 additions and 38 deletions

View file

@ -11,7 +11,7 @@ from django.utils.translation import ugettext, ugettext_lazy as _
from ietf.utils.mail import send_mail
from ietf.utils import debug
#from ietf.person.models import Person, Email
from ietf.person.models import Person, Email
class RegistrationForm(forms.Form):
@ -96,34 +96,64 @@ class PasswordForm(forms.Form):
return self.cleaned_data.get('password1')
def create_user(self):
# user = User.objects.create(username=self.username,
# email=self.username)
# person = Person.objects.create(user=user,
# name=self.username,
# ascii=self.username)
# Email.objects.create(person=person,
# address=self.username)
# return user
return None
user = User.objects.create(username=self.username,
email=self.username)
email = Email.objects.filter(address=self.username)
person = None
if email.count():
email = email[0]
if email.person:
person = email.person
else:
email = None
if not person:
person = Person.objects.create(user=user,
name=self.username,
ascii=self.username)
if not email:
email = Email.objects.create(address=self.username,
person=person)
email.person = person
email.save()
person.user = user
person.save()
return user
def get_user(self):
return User.objects.get(username=self.username)
@debug.trace
def save_password_file(self):
if getattr(settings, 'USE_PYTHON_HTDIGEST', None):
pass_file = settings.HTPASSWD_FILE
realm = settings.HTDIGEST_REALM
password = self.get_password()
username = self.username
prefix = '%s:%s:' % (username, realm)
key = hashlib.md5(prefix + password).hexdigest()
f = open(pass_file, 'r+')
pos = f.tell()
line = f.readline()
while line:
if line.startswith(prefix):
break
pos=f.tell()
line = f.readline()
f.seek(pos)
f.write('%s%s\n' % (prefix, key))
f.close()
else:
p = subprocess.Popen([settings.HTPASSWD_COMMAND, "-b", settings.HTPASSWD_FILE, self.username, self.get_password()], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
def save(self):
# if self.update_user:
# user = self.get_user()
# else:
# user = self.create_user()
# user.set_password(self.get_password())
# user.save()
# return user
debug.show("[settings.HTPASSWD_COMMAND, settings.HTPASSWD_FILE, self.username, self.get_password()]")
p = subprocess.Popen([settings.HTPASSWD_COMMAND, "-b", settings.HTPASSWD_FILE, self.username, self.get_password()], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
debug.show('stdout')
debug.show('stderr')
return p.returncode
if self.update_user:
user = self.get_user()
else:
user = self.create_user()
user.set_password(self.get_password())
user.save()
self.save_password_file()
return user
class TestEmailForm(forms.Form):
email = forms.EmailField(required=False)

View file

@ -35,20 +35,25 @@
import datetime
import hashlib
from django.conf import settings
from django.template import RequestContext
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render_to_response
from django.contrib.auth.decorators import login_required
from django.contrib.auth import REDIRECT_FIELD_NAME, authenticate, login
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.conf import settings
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils import simplejson
from django.utils.http import urlquote
from django.contrib.auth.models import User
from django.utils import simplejson as json
from django.utils.translation import ugettext as _
from forms import *
#from forms import *
from ietf.ietfauth.forms import (RegistrationForm, PasswordForm,
RecoverPasswordForm)
def index(request):
@ -61,7 +66,8 @@ def url_login(request, user, passwd):
if user.is_active:
login(request, user)
return HttpResponseRedirect('/accounts/loggedin/?%s=%s' % (REDIRECT_FIELD_NAME, urlquote(redirect_to)))
return HttpResponse("Not authenticated?", status=500)
return HttpResponse("Not authenticated?", status=500)
def ietf_login(request):
if not request.user.is_authenticated():
@ -71,6 +77,7 @@ def ietf_login(request):
request.session.set_test_cookie()
return HttpResponseRedirect('/accounts/loggedin/?%s=%s' % (REDIRECT_FIELD_NAME, urlquote(redirect_to)))
def ietf_loggedin(request):
if not request.session.test_cookie_worked():
return HttpResponse("You need to enable cookies")
@ -79,13 +86,14 @@ def ietf_loggedin(request):
if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
redirect_to = settings.LOGIN_REDIRECT_URL
return HttpResponseRedirect(redirect_to)
@login_required
def profile(request):
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
from ietf.person.models import Person
from ietf.group.models import Role
roles = []
person = None
try:
@ -93,14 +101,13 @@ def profile(request):
roles = Role.objects.filter(person=person)
except Person.DoesNotExist:
pass
return render_to_response('registration/profileREDESIGN.html',
dict(roles=roles,
person=person),
context_instance=RequestContext(request))
return render_to_response('registration/profile.html', context_instance=RequestContext(request))
return render_to_response('registration/profile.html', context_instance=RequestContext(request))
def create_account(request):
success = False
@ -178,7 +185,7 @@ def ajax_check_username(request):
username = request.GET.get('username', '')
error = False
if User.objects.filter(username=username).count():
error = _('This email is already in use')
error = _('This email address is already registered')
return HttpResponse(json.dumps({'error': error}), mimetype='text/plain')
def test_email(request):

View file

@ -158,6 +158,7 @@ INSTALLED_APPS = (
'ietf.ietfworkflows',
'ietf.wgchairs',
'ietf.wgcharter',
'ietf.community',
)
INTERNAL_IPS = (

View file

@ -33,7 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{% endcomment %}
{% load wg_menu %}
{% load ietf_filters ietf_streams %}
{% load ietf_filters ietf_streams community_tags %}
{% load ietf_filters community_tags %}
<ul>
<li class="sect first">Accounts</li>
<li><a href="{% url account_index %}">New Account</a></li>
@ -76,6 +77,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<li><a href="http://tools.ietf.org/wg/concluded">Concluded WGs</a></li>
<li><a href="http://www.ietf.org/list/nonwg.html">Non-WG Lists</a></li>
{% get_user_managed_lists user as community_lists %}
{% if community_lists %}
<li class="sect">Community ID lists</li>
<li><a href="{{ community_lists.personal.get_manage_url }}">{{ community_lists.personal.short_name }}</a>
{% for cl in community_lists.group %}
<li><a href="{{ cl.get_manage_url }}">{{ cl.short_name }}</a>
{% endfor %}
{% endif %}
<li class="sect">Drafts&nbsp;&amp;&nbsp;RFCs</li>
<li><a href="/doc/">Search</a></li>
<li><form action="/doc/search/" method="get" style="padding-bottom:0;margin-bottom:0;"><input type="text" style="margin-left:10px; width:100px; border:1px solid #89d;" name="name" /><input type="hidden" name="activeDrafts" value="on"/><input type="hidden" name="rfcs" value="on"/></form></li>

View file

@ -0,0 +1,18 @@
<h2>Display customization</h2>
<form action="#custom" method="POST" />
<h3>Sort method</h2>
{{ display_form.sort_method }}
<h3>Show fields</h2>
<div>
{% for field in dc.get_display_fields_config %}
<div style="float: left; width: 30%;">
<input id="id_{{ field.codename }}" type="checkbox" name="{{ field.codename }}"{% if field.active %} checked="checked"{% endif %} />
<label for="id_{{ field.codename }}">{{ field.description }}</label>
</div>
{% endfor %}
</div>
<div style="clear: both;"><br /></div>
<input type="submit" value="Save configuration" name="save_display" />
</form>

View file

@ -0,0 +1 @@
<span class="displayField displayField-{{ field.codename }}">{{ value|safe }}</span>

View file

@ -0,0 +1,125 @@
{% extends "base.html" %}
{% block pagehead %}
{{ block.super }}
<script type="text/javascript" src="/js/lib/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/js/yui/yui-20100305.js"></script>
<script type="text/javascript" src="/js/base.js"></script>
<script type="text/javascript" src="/js/community.js"></script>
{% endblock pagehead %}
{% block title %}{{ cl.long_name }}{% endblock %}
{% block content %}
<h1>{{ cl.long_name }}</h1>
<div id="mytabs" class="yui-navset">
<ul class="yui-nav">
<li class="selected"><a href="#view"><em>Documents</em></a></li>
<li><a href="#documents"><em>Manually added</em></a></li>
<li><a href="#rules"><em>Rules</em></a></li>
<li><a href="#custom"><em>Display customization</em></a></li>
<li><a href="#info"><em>Exports</em></a></li>
</ul>
<div class="yui-content">
<div id="view">
{% include "community/view_list.html" %}
</div>
<div id="documents">
<h2>Documents manually added to this list</h2>
<p>
In order to add some individual documents to your list you have to:
</p>
<ul>
<li>Search the document or documents you want to add using <a href="/doc/search">the datatracker searcher</a>.</li>
<li>In the search result you'll find a link to add individual documents to your list.</li>
</ul>
<table class="ietf-table">
<tr><th>Name</th><th>Title</th><th>Remove from list</th></tr>
{% for doc in cl.added_ids.all %}
<tr class="{% cycle oddrow,evenrow %}">
<td>{{ doc }}</td>
<td><a href="{{ doc.get_absolute_url }}"</a>{{ doc.title }}</td>
<td><a href="{% url community_remove_document cl.pk doc.pk %}">Remove</a></td>
</tr>
{% endfor %}
</table>
</div>
<div id="rules">
<h2>Rules added to this list</h2>
<table class="ietf-table">
<tr><th>Rule</th><th>Value</th><th>Documents</th><th>Remove from list</th></tr>
{% for rule in cl.rule_set.all %}
{% with rule.get_callable_rule as callable %}
<tr class="{% cycle oddrow,evenrow %}">
<td>{{ callable.description }}</td>
<td>{{ callable.show_value }}</td>
<td>{% with rule.cached_ids.count as count %}{{ count }} document{{ count|pluralize }}{% endwith %}</td>
<td><a href="{% url community_remove_rule cl.pk rule.pk %}">Remove</a></td>
</tr>
{% endwith %}
{% endfor %}
</table>
<h3>Add a new rule</h3>
<form method="post" action="#rules">
{{ rule_form.as_p }}
<input type="submit" name="save_rule" value="Add rule" />
</form>
<div class="rule_values" style="display: none;">
{% for entry in rule_form.get_all_options %}
<div class="{{ entry.type }}">
<select>
{% for option in entry.options %}
<option value={{ option.0 }}>{{ option.1 }}</option>
{% endfor %}
</select>
</div>
{% endfor %}
</div>
</div>
<div id="custom">
{% include "community/customize_display.html" %}
</div>
<div id="info">
<p>Feel free to share the following links if you need it.</p>
<ul>
<li><a href="{{ cl.secret }}/view/">Read only view for {{ cl.long_name }}</a></li>
<li><a href="{{ cl.secret }}/changes/feed/">Feed for every change in status of {{ cl.long_name }}</a></li>
<li><a href="{{ cl.secret }}/changes/significant/feed/">Feed for significant change in status of {{ cl.long_name }}</a></li>
<li><a href="{{ cl.secret }}/subscribe/">Subscribe to the mailing list for every change in status of {{ cl.long_name }}</a></li>
<li><a href="{{ cl.secret }}/subscribe/significant/">Subscribe to the mailing list for significant change in status of {{ cl.long_name }}</a></li>
</ul>
<p>Export your list to CSV format</p>
<ul>
<li><a href="csv/">CSV for {{ cl.long_name }}</a></li>
</ul>
</div>
</div>
</div>
<script type="text/javascript">
//<![CDATA[
var tabView = new YAHOO.widget.TabView('mytabs');
var url = location.href.split('#');
if (url[1]) {
url[1] = "#"+url[1];
var tabs = tabView.get('tabs');
for (var i = 0; i < tabs.length; i++) {
if (url[1].indexOf(tabs[i].get('href')) == 0) {
tabView.set('activeIndex', i);
break;
}
}
}
//]]>
</script>
{% endblock %}

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">{{ title }}</title>
<subtitle type="text">{{ subtitle }}</subtitle>
<id>{{ id }}</id>
<updated>{{ updated|date:"Y-m-d\TH:i:s" }}Z</updated>
<link rel="alternate" type="text/html" hreflang="en" href="http://{{ request.get_host }}/"/>
<link rel="self" type="application/atom+xml" href="http://{{ request.get_host }}{{ request.get_full_path }}"/>
{% for entry in entries %}
<entry>
<title>{{ entry.doc.title }}</title>
<link href="{{ entry.doc.get_absolute_url }}"/>
<id>{{ entry.id }}</id>
<updated>{{ entry.time|date:"Y-m-d\TH:i:s" }}Z</updated>
<published>{{ entry.time|date:"Y-m-d\TH:i:s" }}</published>
<author>
<name>{{ entry.by }}</name>
</author>
<summary>{{ entry.desc|striptags }}</summary>
</entry>
{% endfor %}
</feed>

View file

@ -0,0 +1,15 @@
{% autoescape off %}
Hello,
This is a notification from {{ clist.long_name }}.
Document: {{ notification.doc }}
Change:
{{ notification.desc }}
Best regards,
The datatracker login manager service
(for the IETF Secretariat)
{% endautoescape %}

View file

@ -0,0 +1,22 @@
{% extends "base.html" %}
{% block title %}Subscribe to {{ cl.long_name }}{% endblock %}
{% block content %}
<h1>Subscribe to {{ cl.long_name }}</h1>
{% if success %}
<p>
We have sent and email to your email address with instructions to complete your subscription.
</p>
{% else %}
<p>
Subscribe to the email list for notifications of {% if significant %}significant {% endif %}changes on {{ cl.long_name }}.
</p>
<form action="" method="post">
<table>
{{ form }}
</table>
<input type="submit" value="Subscribe" />
</form>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,12 @@
{% autoescape off %}
Hello,
In order to complete your subscription for {% if significant %}significant {% endif %}changes on {{ clist.long_name }}, please follow this link or copy it and paste it in your web browser:
http://{{ domain }}{% if significant %}{% url confirm_significant_subscription clist.id to_email today auth %}{% else %}{% url confirm_subscription clist.id to_email today auth %}{% endif %}
Best regards,
The datatracker login manager service
(for the IETF Secretariat)
{% endautoescape %}

View file

@ -0,0 +1,13 @@
{% extends "base.html" %}
{% block title %}Subscription to {{ cl.long_name }}{% endblock %}
{% block content %}
<h1>Subscription to {{ cl.long_name }}</h1>
<p>
You email address {{ email }} has been successfully subscribed to {{ cl.long_name }}
</p>
<p>
<a href="{{ cl.get_public_url }}">Return to the list view</a>
</p>
{% endblock %}

View file

@ -0,0 +1,22 @@
{% extends "base.html" %}
{% block title %}Cancel subscription to {{ cl.long_name }}{% endblock %}
{% block content %}
<h1>Cancel subscription to {{ cl.long_name }}</h1>
{% if success %}
<p>
You will receive a confirmation email shortly containing further instructions on how to cancel your subscription.
</p>
{% else %}
<p>
Cancel your subscription to the email list for notifications of {% if significant %}significant {% endif %}changes on {{ cl.long_name }}.
</p>
<form action="" method="post">
<table>
{{ form }}
</table>
<input type="submit" value="Cancel subscription" />
</form>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,12 @@
{% autoescape off %}
Hello,
In order to complete the cancelation of your subscription to {% if significant %}significant {% endif %}changes on {{ clist.long_name }}, please follow this link or copy it and paste it in your web browser:
http://{{ domain }}{% if significant %}{% url confirm_significant_unsubscription clist.id to_email today auth %}{% else %}{% url confirm_unsubscription clist.id to_email today auth %}{% endif %}
Best regards,
The datatracker login manager service
(for the IETF Secretariat)
{% endautoescape %}

View file

@ -0,0 +1,13 @@
{% extends "base.html" %}
{% block title %}Canceled subscription to {{ cl.long_name }}{% endblock %}
{% block content %}
<h1>Canceled subscription to {{ cl.long_name }}</h1>
<p>
You email address {{ email }} has been successfully removed form {{ cl.long_name }} {% if significant %}significant {% endif %}changes mailing list.
</p>
<p>
<a href="{{ cl.get_public_url }}">Return to the list view</a>
</p>
{% endblock %}

View file

@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block pagehead %}
<link rel="alternate" type="application/rss+xml" title="Changes on {{ cl.long_name }} RSS Feed" href="../changes/feed/" />
<link rel="alternate" type="application/rss+xml" title="Significant changes on {{ cl.long_name }} RSS Feed" href="../changes/significant/feed/" />
{% endblock %}
{% block title %}{{ cl.long_name }}{% endblock %}
{% block content %}
<h1>{{ cl.long_name }}</h1>
<p>
Subscribe to notification email list:
</p>
<ul>
<li><a href="../subscribe/">All changes email list</a></li>
<li><a href="../subscribe/significant/">Significant changes email list</a></li>
</ul>
{% include "community/view_list.html" %}
{% endblock %}

View file

@ -0,0 +1,44 @@
{% load community_tags %}
{% with cl.get_rfcs_and_drafts as documents %}
{% with dc.get_active_fields as fields %}
<h2>Drafts</h2>
<table class="ietf-table">
<tr>
{% for field in fields %}
<th>{{ field.description }}</th>
{% endfor %}
</tr>
{% for doc in documents.1 %}
<tr class="{% cycle oddrow,evenrow %}">
{% for field in fields %}
<td>
{% show_field field doc %}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
{% endwith %}
<h2>RFCs</h2>
{% with dc.get_active_fields as fields %}
<table class="ietf-table">
<tr>
{% for field in fields %}
<th>{{ field.description }}</th>
{% endfor %}
</tr>
{% for doc in documents.0 %}
<tr class="{% cycle oddrow,evenrow %}">
{% for field in fields %}
<td>
{% show_field field doc %}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
{% endwith %}
{% endwith %}

View file

@ -0,0 +1,3 @@
{% load community_tags %}
{% get_clist_view cl %}

View file

@ -52,6 +52,27 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
YAHOO.util.Event.onContentReady("search_submit_button", function () {
var oButton = new YAHOO.widget.Button("search_submit_button", {});
});
{% if meta.searching %}
(function ($) {
$(document).ready(function () {
$('.addtolist a').click(function() {
var trigger = $(this);
$.ajax({
url: trigger.attr('href'),
type: 'GET',
cache: false,
dataType: 'json',
success: function(response){
if (response.success) {
trigger.replaceWith('added');
}
}
});
return false;
});
});
})(jQuery);
{% endif %}
{% endblock scripts %}
{% block js %}

View file

@ -35,6 +35,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{% load ietf_filters %}
{% load ballot_icon %}
<tr class="{{ forloop.counter|divisibleby:2|yesno:"oddrow,evenrow" }}">
{% if user.is_authenticated and show_add_to_list %}
<td class="addtolist">
<a href="{% url community_add_document doc.id.draft_name %}" title="Add to your personal ID list"><img src="/images/add_to_list.png" alt="Add to your personal ID list" /></a>
</td>
{% endif %}
<td class="doc">
{% if doc.rfc %}{{ doc.rfc.displayname_with_link|safe }}
{% if doc.id %}<br />(<a href="{{ doc.id.get_absolute_url }}">{{doc.id.draft_name}}</a>){%endif%}
@ -47,5 +52,4 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{% include "idrfc/ipr_column.html" %}
{# <td class="ad">{% if doc.ad_name %}{{ doc.ad_name }}{% else %}&nbsp;{% endif %}</td> #}
<td class="ad">{{ doc.ad_name|default:"" }}</td>
</tr>

View file

@ -40,16 +40,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{% else %}
{% regroup docs by view_sort_group as grouped_docs %}
<table class="ietf-table ietf-doctable">
<tr>
<tr>{% if user.is_authenticated %}<th></th>{% endif %}
{% for hdr in meta.hdrs %}
{% include "idrfc/table_header.html" %}
{% endfor %}
</tr>
<!-- <tr><th></th><th class="doc">Document</th><th class="title">Title</th><th class="date">Date</th><th class="status" colspan="2">Status</th><th class="ad">Area Director</th></tr> -->
{% for doc_group in grouped_docs %}
<tr class="header"><td colspan="7">{{doc_group.grouper}}s</td></tr>
{% with 1 as show_add_to_list %}
{% for doc in doc_group.list %}
{% include "idrfc/search_result_row.html" %}
{% endfor %}
{% endwith %}
{% endfor %}
</table>

View file

@ -65,6 +65,7 @@ urlpatterns = patterns('',
(r'^person/', include('ietf.person.urls')),
(r'^submit/', include('ietf.submit.urls')),
(r'^streams/', include('ietf.ietfworkflows.urls')),
(r'^community/', include('ietf.community.urls')),
(r'^$', 'ietf.idrfc.views.main'),
(r'^admin/doc/', include('django.contrib.admindocs.urls')),

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 B

469
static/js/community.js Normal file
View file

@ -0,0 +1,469 @@
(function ($) {
$.fn.AttachmentWidget = function() {
return this.each(function () {
var button = $(this);
var fieldset = $(this).parents('.fieldset');
var config = {};
var count = 0;
var readConfig = function() {
var disabledLabel = fieldset.find('.attachDisabledLabel');
if (disabledLabel.length) {
config.disabledLabel = disabledLabel.html();
var required = ''
fieldset.find('.attachRequiredField').each(function(index, field) {
required += '#' + $(field).html() + ',';
});
var fields = fieldset.find(required);
config.basefields = fields;
}
config.showOn = $('#' + fieldset.find('.showAttachsOn').html());
config.showOnDisplay = config.showOn.find('.attachedFiles');
count = config.showOnDisplay.find('.initialAttach').length;
config.showOnEmpty = config.showOn.find('.showAttachmentsEmpty').html();
config.enabledLabel = fieldset.find('.attachEnabledLabel').html();
};
var setState = function() {
var enabled = true;
config.fields.each(function() {
if (!$(this).val()) {
enabled = false;
return;
}
});
if (enabled) {
button.removeAttr('disabled').removeClass('disabledAddAttachment');
button.val(config.enabledLabel);
} else {
button.attr('disabled', 'disabled').addClass('disabledAddAttachment');
button.val(config.disabledLabel);
}
};
var cloneFields = function() {
var html = '<div class="attachedFileInfo">';
if (count) {
html = config.showOnDisplay.html() + html;
}
config.fields.each(function() {
var field = $(this);
var container= $(this).parents('.field');
if (container.find(':file').length) {
html += ' (' + field.val() + ')';
} else {
html += ' ' + field.val();
}
html += '<span style="display: none;" class="removeField">';
html += container.attr('id');
html += '</span>';
container.hide();
});
html += ' <a href="#" class="removeAttach">Remove</a>';
html += '</div>';
config.showOnDisplay.html(html);
count += 1;
initFileInput();
};
var doAttach = function() {
cloneFields();
setState();
};
var removeAttachment = function() {
var link = $(this);
var attach = $(this).parent('.attachedFileInfo');
var fields = attach.find('.removeField');
fields.each(function() {
$('#' + $(this).html()).remove();
});
attach.remove();
if (!config.showOnDisplay.html()) {
config.showOnDisplay.html(config.showOnEmpty);
count = 0;
}
return false;
};
var initTriggers = function() {
config.showOnDisplay.find('a.removeAttach').live('click', removeAttachment);
button.click(doAttach);
};
var initFileInput = function() {
var fieldids = ''
config.basefields.each(function(i) {
var field = $(this);
var oldcontainer= $(this).parents('.field');
var newcontainer= oldcontainer.clone();
var newfield = newcontainer.find('#' + field.attr('id'));
newfield.attr('name', newfield.attr('name') + '_' + count);
newfield.attr('id', newfield.attr('id') + '_' + count);
newcontainer.attr('id', 'container_id_' + newfield.attr('name'));
oldcontainer.after(newcontainer);
oldcontainer.hide();
newcontainer.show();
fieldids += '#' + newfield.attr('id') + ','
});
config.fields = $(fieldids);
config.fields.change(setState);
config.fields.keyup(setState);
};
var initWidget = function() {
readConfig();
initFileInput();
initTriggers();
setState();
};
initWidget();
});
};
$.fn.LiaisonForm = function() {
return this.each(function () {
var form = $(this);
var organization = form.find('#id_organization');
var from = form.find('#id_from_field');
var poc = form.find('#id_to_poc');
var cc = form.find('#id_cc1');
var reply = form.find('#id_replyto');
var purpose = form.find('#id_purpose');
var other_purpose = form.find('#id_purpose_text');
var deadline = form.find('#id_deadline_date');
var submission_date = form.find('#id_submitted_date');
var other_organization = form.find('#id_other_organization');
var approval = form.find('#id_approved');
var cancel = form.find('#id_cancel');
var cancel_dialog = form.find('#cancel-dialog');
var config = {};
var related_trigger = form.find('#id_related_to');
var related_url = form.find('#id_related_to').parent().find('.listURL').text();
var related_dialog = form.find('#related-dialog');
var unrelate_trigger = form.find('#id_no_related_to');
var readConfig = function() {
var confcontainer = form.find('.formconfig');
config.info_update_url = confcontainer.find('.info_update_url').text();
};
var render_mails_into = function(container, person_list, as_html) {
var html='';
$.each(person_list, function(index, person) {
if (as_html) {
html += person[0] + ' &lt;<a href="mailto:'+person[1]+'">'+person[1]+'</a>&gt;<br />';
} else {
html += person[0] + ' &lt;'+person[1]+'&gt;\n';
}
});
container.html(html);
};
var toggleApproval = function(needed) {
if (!approval.length) {
return;
}
if (needed) {
approval.removeAttr('disabled');
approval.removeAttr('checked');
} else {
approval.attr('checked','checked');
approval.attr('disabled','disabled');
}
};
var checkPostOnly = function(post_only) {
if (post_only) {
$("input[name=send]").hide();
} else {
$("input[name=send]").show();
}
};
var updateReplyTo = function() {
var select = form.find('select[name=from_fake_user]');
var option = select.find('option:selected');
reply.val(option.attr('title'));
updateFrom();
}
var userSelect = function(user_list) {
if (!user_list || !user_list.length) {
return;
}
var link = form.find('a.from_mailto');
var select = form.find('select[name=from_fake_user]');
var options = '';
link.hide();
$.each(user_list, function(index, person) {
options += '<option value="' + person[0] + '" title="' + person[1][1] + '">'+ person[1][0] + ' &lt;' + person[1][1] + '&gt;</option>';
});
select.remove();
link.after('<select name="from_fake_user">' + options +'</select>')
form.find('select[name=from_fake_user]').change(updateReplyTo);
updateReplyTo();
};
var updateInfo = function(first_time) {
var entity = organization;
var to_entity = from;
if (!entity.is('select') || !to_entity.is('select')) {
return false;
}
var url = config.info_update_url;
$.ajax({
url: url,
type: 'GET',
cache: false,
async: true,
dataType: 'json',
data: {to_entity_id: organization.val(),
from_entity_id: to_entity.val()},
success: function(response){
if (!response.error) {
if (!first_time || !cc.text()) {
render_mails_into(cc, response.cc, false);
}
render_mails_into(poc, response.poc, true);
toggleApproval(response.needs_approval);
checkPostOnly(response.post_only);
userSelect(response.full_list);
}
}
});
return false;
};
var updateFrom = function() {
var reply_to = reply.val();
form.find('a.from_mailto').attr('href', 'mailto:' + reply_to);
};
var updatePurpose = function() {
var datecontainer = deadline.parents('.field');
var othercontainer = other_purpose.parents('.field');
var selected_id = purpose.val();
var deadline_required = datecontainer.find('.fieldRequired');
if (selected_id == '1' || selected_id == '2' || selected_id == '5') {
datecontainer.show();
} else {
datecontainer.hide();
deadline.val('');
}
if (selected_id == '5') {
othercontainer.show();
deadline_required.hide();
} else {
othercontainer.hide();
other_purpose.val('');
deadline_required.show();
}
};
var checkOtherSDO = function() {
var entity = organization.val();
if (entity=='othersdo') {
other_organization.parents('.field').show();
} else {
other_organization.parents('.field').hide();
}
};
var cancelForm = function() {
cancel_dialog.dialog("open");
};
var getRelatedLink = function() {
link = $(this).text();;
pk = $(this).nextAll('.liaisonPK').text();
widget = related_trigger.parent();
widget.find('.relatedLiaisonWidgetTitle').text(link);
widget.find('.relatedLiaisonWidgetValue').val(pk);
widget.find('.noRelated').hide();
unrelate_trigger.show();
related_dialog.dialog('close');
return false;
};
var selectNoRelated = function() {
widget = $(this).parent();
widget.find('.relatedLiaisonWidgetTitle').text('');
widget.find('.noRelated').show();
widget.find('.relatedLiaisonWidgetValue').val('');
$(this).hide();
return false;
};
var selectRelated = function() {
trigger = $(this);
widget = $(this).parent();
url = widget.find('.listURL').text();
title = widget.find('.relatedLiaisonWidgetTitle');
related_dialog.html('<img src="/images/ajax-loader.gif" />');
related_dialog.dialog('open');
$.ajax({
url: url,
type: 'GET',
cache: false,
async: true,
dataType: 'html',
success: function(response){
related_dialog.html(response);
related_dialog.find('th a').click(function() {
widget.find('.listURL').text(related_url + $(this).attr('href'));
trigger.click();
return false;
});
related_dialog.find('td a').click(getRelatedLink);
}
});
return false;
};
var checkFrom = function(first_time) {
var reduce_options = form.find('.reducedToOptions');
if (!reduce_options.length) {
updateInfo(first_time);
return;
}
var to_select = organization;
var from_entity = from.val();
if (!reduce_options.find('.full_power_on_' + from_entity).length) {
to_select.find('optgroup').eq(1).hide();
to_select.find('option').each(function() {
if (!reduce_options.find('.reduced_to_set_' + $(this).val()).length) {
$(this).hide();
} else {
$(this).show();
}
});
if (!to_select.find('option:selected').is(':visible')) {
to_select.find('option:selected').removeAttr('selected');
}
} else {
to_select.find('optgroup').show();
to_select.find('option').show();
}
updateInfo(first_time);
};
var checkSubmissionDate = function() {
var date_str = submission_date.val();
if (date_str) {
var sdate = new Date(date_str);
var today = new Date();
if (Math.abs(today-sdate) > 2592000000) { // 2592000000 = 30 days in milliseconds
return confirm('Submission date ' + date_str + ' differ more than 30 days.\n\nDo you want to continue and post this liaison using that submission date?\n');
}
}
};
var initTriggers = function() {
organization.change(function() {updateInfo(false);});
organization.change(checkOtherSDO);
from.change(function() {checkFrom(false);});
reply.keyup(updateFrom);
purpose.change(updatePurpose);
cancel.click(cancelForm);
related_trigger.click(selectRelated);
unrelate_trigger.click(selectNoRelated);
form.submit(checkSubmissionDate);
};
var updateOnInit = function() {
updateFrom();
checkFrom(true);
updatePurpose();
checkOtherSDO();
};
var initDatePicker = function() {
deadline.datepicker({
dateFormat: $.datepicker.ATOM,
changeYear: true
});
submission_date.datepicker({
dateFormat: $.datepicker.ATOM,
changeYear: true
});
};
var initAttachments = function() {
form.find('.addAttachmentWidget').AttachmentWidget();
};
var initDialogs = function() {
cancel_dialog.dialog({
resizable: false,
height:200,
modal: true,
autoOpen: false,
buttons: {
Ok: function() {
window.location='..';
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
related_dialog.dialog({
height: 400,
width: 800,
draggable: true,
modal: true,
autoOpen: false
});
};
var initForm = function() {
readConfig();
initTriggers();
updateOnInit();
initDatePicker();
initAttachments();
initDialogs();
};
initForm();
});
};
$(document).ready(function () {
var container = $('#rules');
var changeInput = function() {
var rule = $(this);
var rule_id = rule.val();
var input = container.find('#id_value');
var select = container.find('.rule_values .' + rule_id + ' select');
container.find('[name="value"]').each(function(index, content) {
$(content).attr('name', '');
});
if (select.length) {
input.hide();
select.attr('name', 'value');
input.next('select').remove();
var newselect = select.clone()
newselect.insertAfter(input);
} else {
input.next('select').remove();
input.attr('name', 'value');
input.show();
}
};
container.find('#id_rule_type').change(changeInput);
});
})(jQuery);