Commits

Anonymous committed 45870f1

#267: remove the remove button from the issue page, move it to the msg/file page, and add a button to add back removed messages/files.

Comments (0)

Files changed (4)

extensions/pydevutils.py

     db = request.client.db
     return 'Coordinator' in db.user.get(user, 'roles')
 
+
+def issueid_and_action_from_class(cls):
+    """
+    Return the id of the issue where the msg/file is/was linked
+    and if the last "linking action" was 'link' or 'unlink'.
+    """
+    last_action = ''
+    for entry in cls._klass.history(cls._nodeid):
+        if 'unlink' in entry:
+            last_unlink = entry
+            last_action = 'unlink'
+        elif 'link' in entry:
+            last_entry = entry
+            last_action = 'link'
+    if last_action in ('link', 'unlink'):
+        # the msg has been unlinked and not linked back
+        # the link looks like: ('16', <Date 2011-07-22.05:14:12.342>, '4',
+        #                       'link', ('issue', '1', 'messages'))
+        return last_entry[4][1], last_action
+    return None, None
+
 def init(instance):
     instance.registerUtil('is_history_ok', is_history_ok)
     instance.registerUtil('is_coordinator', is_coordinator)
+    instance.registerUtil('issueid_and_action_from_class',
+                          issueid_and_action_from_class)

html/file.item.html

       <input type="submit" name="trainham" value="Mark as HAM (not SPAM)" i18n:attributes="value">
      </form>
 
+
+<form tal:define="u_hasRole python:request.user.hasRole;
+                  issueid_action python:utils.issueid_and_action_from_class(context);
+                  issueid python:'issue%s' % issueid_action[0];
+                  action python:issueid_action[1]"
+      tal:condition="python:issueid and context.is_edit_ok()"
+      tal:attributes="action issueid" method="post">
+    <input type="hidden" name="@action" value="edit" />
+    <tal:block tal:condition="python: action == 'link'">
+        <input type="hidden" name="@remove@files" tal:attributes="value context/id" />
+        <p>This file is linked to <a tal:attributes="href issueid" tal:content="issueid" />:
+           <input type="submit" value="Unlink" i18n:attributes="value"/></p>
+    </tal:block>
+    <tal:block tal:condition="python: action == 'unlink'">
+        <input type="hidden" name="@add@files" tal:attributes="value context/id" />
+        <p>This file has been unlinked from <a tal:attributes="href issueid" tal:content="issueid" />:
+           <input type="submit" value="Restore" i18n:attributes="value"/></p>
+    </tal:block>
+</form>
+
+
 <tal:block tal:condition="context/id" tal:replace="structure context/history" />
 
 </td>

html/issue.item.html

   <th i18n:translate="">Uploaded</th>
   <th i18n:translate="">Description</th>
   <th i18n:translate="">Edit</th>
-  <th i18n:translate="">Remove</th>
  </tr>
  <tr tal:repeat="file python:context.files.sorted('creation')">
   <td>
       <a tal:condition="rvlink" tal:attributes="href rvlink">review</a>
       </tal:block>
   </td>
-  <td>
-   <form style="padding:0" method="post" tal:condition="file/is_edit_ok"
-         tal:attributes="action string:issue${context/id}">
-    <input type="hidden" name="@remove@files" tal:attributes="value file/id">
-    <input type="hidden" name="@action" value="edit">
-    <input type="submit" value="remove" i18n:attributes="value">
-   </form>
-  </td>
  </tr>
 </table>
 
    </th>
    <th i18n:translate="">Date: <tal:x replace="python:msg.date.pretty('%Y-%m-%d %H:%M')"
        i18n:name="date" /></th>
-   <th>
-    <form style="padding:0" method="post" tal:condition="msg/is_edit_ok"
-          tal:attributes="action string:issue${context/id}">
-     <input type="hidden" name="@remove@messages" tal:attributes="value msg/id">
-     <input type="hidden" name="@action" value="edit">
-     <input type="submit" value="remove" i18n:attributes="value">
-    </form>
-   </th>
   </tr>
   <tr>
    <td colspan="4" class="content">

html/msg.item.html

  </tr>
 </table>
 
+
+<form tal:define="u_hasRole python:request.user.hasRole;
+                  issueid_action python:utils.issueid_and_action_from_class(context);
+                  issueid python:'issue%s' % issueid_action[0];
+                  action python:issueid_action[1]"
+      tal:condition="python:issueid and context.is_edit_ok()"
+      tal:attributes="action issueid" method="post">
+    <input type="hidden" name="@action" value="edit" />
+    <tal:block tal:condition="python: action == 'link'">
+        <input type="hidden" name="@remove@messages" tal:attributes="value context/id" />
+        <p>This message is linked to <a tal:attributes="href issueid" tal:content="issueid" />:
+           <input type="submit" value="Unlink" i18n:attributes="value"/></p>
+    </tal:block>
+    <tal:block tal:condition="python: action == 'unlink'">
+        <input type="hidden" name="@add@messages" tal:attributes="value context/id" />
+        <p>This message has been unlinked from <a tal:attributes="href issueid" tal:content="issueid" />:
+           <input type="submit" value="Restore" i18n:attributes="value"/></p>
+    </tal:block>
+</form>
+
+
 <tal:block tal:replace="structure context/history" />
 
 </div>