[Python-checkins] r82348 - in tracker/instances/python-dev/html: issue.item.html issue.item.js

ezio.melotti python-checkins at python.org
Mon Jun 28 23:29:16 CEST 2010


Author: ezio.melotti
Date: Mon Jun 28 23:29:16 2010
New Revision: 82348

Log:
#266: Add an "Add me to nosy" button next to the nosy list.

Added:
   tracker/instances/python-dev/html/issue.item.js
Modified:
   tracker/instances/python-dev/html/issue.item.html

Modified: tracker/instances/python-dev/html/issue.item.html
==============================================================================
--- tracker/instances/python-dev/html/issue.item.html	(original)
+++ tracker/instances/python-dev/html/issue.item.html	Mon Jun 28 23:29:16 2010
@@ -9,6 +9,11 @@
  >New Issue - <span tal:replace="config/TRACKER_NAME" i18n:name="tracker"
 /></tal:block>
 </title>
+
+<metal:slot fill-slot="more-javascript">
+<script type="text/javascript" src="@@file/issue.item.js"></script>
+</metal:slot>
+
 <tal:block metal:fill-slot="body_title">
  <span tal:condition="python: not (context.id or context.is_edit_ok())"
   tal:omit-tag="python:1" i18n:translate="">New Issue</span>
@@ -130,13 +135,17 @@
  <td tal:condition="not:context/assignee/is_edit_ok">
   <span tal:replace="structure context/assignee/plain" />
  </td>
- <th><tal:block i18n:translate="">Nosy List</tal:block>:
+ <th><tal:block i18n:translate="">Nosy List</tal:block><span tal:condition="context/nosy_count" tal:replace="python: ' (%d)' % context.nosy_count" />:
   <span tal:condition="context/nosy/is_edit_ok"
         tal:replace="structure python:db.user.classhelp('username,realname,address', property='nosy')" />
  </th>
  <td>
      <span tal:replace="structure context/nosy/field" />
-     <span tal:condition="context/nosy_count" tal:replace="python: '(%d)' % context.nosy_count" />
+     <span id="add_me_to_nosy" style="display: none"
+        tal:define="current_user request/user/username"
+        tal:condition="python:request.user.username != 'anonymous' and current_user not in str(context.nosy).replace(' ','').split(',')"
+        tal:attributes="onclick string:add_to_nosy('$current_user')"
+        onclick="add_to_nosy(the_current_username)" />
  </td>
 </tr>
 <tr>

Added: tracker/instances/python-dev/html/issue.item.js
==============================================================================
--- (empty file)
+++ tracker/instances/python-dev/html/issue.item.js	Mon Jun 28 23:29:16 2010
@@ -0,0 +1,39 @@
+window.onload = function () {
+    // create the input button and use it to replace the span/placeholder --
+    // users without javascript won't notice anything.
+    // This might eventually be replaced by jquery
+    var node_id = 'add_me_to_nosy';
+    var add_me_span = document.getElementById(node_id);
+    var add_me_button = document.createElement('input');
+    var add_me_parent = add_me_span.parentNode;
+    add_me_button.value = '+';
+    add_me_button.type = 'button';
+    add_me_button.title = 'Add me to the nosy list (remember to Submit Changes)';
+    add_me_button.onclick = add_me_span.onclick;
+    add_me_button.style.display = 'inline';
+    add_me_parent.replaceChild(add_me_button, add_me_span);
+    add_me_button.id = node_id;
+}
+
+
+function add_to_nosy(user) {
+    var add_me_button = document.getElementById('add_me_to_nosy');
+    var nosy = document.getElementsByName('nosy')[0];
+    var nosy_text = nosy.value.replace(/\s+/g, '');
+    if (nosy_text == "") {
+        // nosy_list is empty, add the user
+        nosy.value = user;
+    }
+    else {
+        re = new RegExp("(^|,)" + user + "(,|$)");
+        if (!re.test(nosy_text)) {
+            // make sure the user not in nosy and then add it at the beginning
+            nosy.value = user + ',' + nosy_text;
+        }
+    }
+    // hide the button and resize the list to fill the void
+    var new_width = nosy.offsetWidth + add_me_button.offsetWidth;
+    add_me_button.style.display = 'none';
+    nosy.style.display = 'block';
+    nosy.style.width = new_width + "px";
+}


More information about the Python-checkins mailing list