Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file.
authorPawel Solyga <Pawel.Solyga@gmail.com>
Thu, 02 Apr 2009 10:11:38 +0000
changeset 2051 cecbef1289a5
parent 2050 b3b235acdc6e
child 2052 a723a2509e21
Make the mentor and organization admin comment submission on student proposal nicer. Now drop down box allows you to select comment type and based on selected type and your current Role shows you available comment options. Left TODO to put inline JS into separate JS file. Patch by: Tim Ansell (small fixes by Pawel Solyga) Reviewed by: Pawel Solyga
app/soc/templates/soc/student_proposal/review.html
app/soc/views/models/student_proposal.py
--- a/app/soc/templates/soc/student_proposal/review.html	Wed Apr 01 17:23:49 2009 +0000
+++ b/app/soc/templates/soc/student_proposal/review.html	Thu Apr 02 10:11:38 2009 +0000
@@ -61,14 +61,42 @@
 
 <hr />
 <form method="POST">
-  <tr>
-  <td><b>Score and Review</b></td>
-  </tr>
-  <table>
-    {% block form_table %}
-      {% as_table form %}
-    {% endblock %}
+<b>Score and Review</b>
+
+<div class="box" style="border: 1px solid blue;">
+  <table id="commentcommon">
+    <!-- By default this is not displayed, so that all options work on non-javascript browsers -->
+    <tr style="display: none;">
+      <td class="formfieldlabel">
+        Comment Type:
+      </td>
+      <td class="formfieldvalue" colspan=3>
+        <select id="commenttypeselector" onchange="commentType();">
+          <option value="Public">Public Comment</option>
+          <option value="Private">Private Comment</option>
+         {% if is_org_admin %}
+          <option value="Admin">Admin Comment</option>
+         {% endif %} 
+        </select>
+      </td>
+    </tr>
+    <tbody id="commentpublic">
+      {% block comment_public_form_table %}
+        {% as_table comment_public %}
+      {% endblock %}
+    </tbody>
+    <tbody id="commentprivate">
+      {% block comment_private_form_table %}
+        {% as_table comment_private %}
+      {% endblock %}
+    </tbody>
+    <tbody id="commentadmin">
+      {% block comment_admin_form_table %}
+        {% as_table comment_admin %}
+      {% endblock %}
+    </tbody>
   </table>
+</div>
  <table>
   <tr>
    <td colspan="4">&nbsp;</td>
@@ -117,4 +145,55 @@
 {% endfor %}
 <hr />
 
+{% comment %}
+  TODO(pawel.solyga): Put this javascript into separate file
+{% endcomment %}
+<script type="text/javascript"/>
+function commentType() {
+  var commentTypeSelector = document.getElementById("commenttypeselector");
+  var type = commentTypeSelector[commentTypeSelector.options.selectedIndex].value;
+
+  var commentPublic = document.getElementById("commentpublic");
+  var commentPrivate = document.getElementById("commentprivate");
+  var commentAdmin = document.getElementById("commentadmin");
+
+  var publicCheckbox = document.getElementById("id_public");
+
+  switch (type) {
+    case "Public":
+      commentPublic.style.display = "";
+      commentPrivate.style.display = "none";
+      commentAdmin.style.display = "none";
+      publicCheckbox.value = true;
+      break;
+    case "Private":
+      commentPublic.style.display = "";
+      commentPrivate.style.display = "";
+      commentAdmin.style.display = "none";
+      publicCheckbox.value = false;
+      break;
+    case "Admin":
+      commentPublic.style.display = "";
+      commentPrivate.style.display = "";
+      commentAdmin.style.display = "";
+      publicCheckbox.value = false;
+      break;
+    default:
+      alert("Unknown value");
+      alert(type);
+      break;
+  }
+}
+
+// Set the comment type selector to be displayed
+var commentTypeSelector = document.getElementById("commenttypeselector");
+commentTypeSelector.parentNode.parentNode.style.display = "";
+commentTypeSelector.options.selectedIndex = 0;
+var publicCheckbox = document.getElementById("id_public");
+publicCheckbox.parentNode.parentNode.style.display = "none";
+
+// Set the comment view to default to what ever is selected
+commentType();
+</script>
+
 {% endblock %}
--- a/app/soc/views/models/student_proposal.py	Wed Apr 01 17:23:49 2009 +0000
+++ b/app/soc/views/models/student_proposal.py	Thu Apr 02 10:11:38 2009 +0000
@@ -763,6 +763,37 @@
 
     context['form'] = form(initial)
 
+    # create the special form for mentors
+    comment_public = ['public', 'comment']
+    comment_private = ['score']
+    comment_admin = ['rank', 'mentor']
+    class FilterForm(object):
+      def __init__(self, form, fields):
+        self.__form = form
+        self.__fields = fields
+
+      @property
+      def fields(self):
+        return dict([(k,i) for k, i in self.__form.fields.iteritems() if k in self.__fields])
+
+      def __iter__(self):
+        for x in self.__form:
+          if x.name not in self.__fields:
+            continue
+          yield x
+
+      _marker = []
+      def __getattr__(self, key, default=_marker):
+        if default is self._marker:
+          return getattr(self.__form, key)
+        else:
+          return getattr(self.__form, key, default)
+
+    context['form'] = form(initial)
+    context['comment_public'] = FilterForm(context['form'], comment_public)
+    context['comment_private'] = FilterForm(context['form'], comment_private)
+    context['comment_admin'] = FilterForm(context['form'], comment_admin)
+
     # get all the extra information that should be in the context
     review_context = self._getDefaultReviewContext(entity, org_admin, mentor)
     context = dicts.merge(context, review_context)