Commits

Alex Willmer committed 1758295

Create linked ticket form

  • Participants
  • Parent commits 4dc7ce5
  • Branches ticket-links-trunk

Comments (0)

Files changed (2)

File trac/ticket/templates/ticket_box.html

         </tr>
       </tbody>
     </table>
+    <form id="newlinked" method="get" action="${context.href.newticket()}">
+      <input type="hidden" name="linked_val" value="${ticket.id}" />
+      <label for="linked-end">New</label>
+      <select id="linked-end" name="linked_end">
+        <option py:for="link_label, link_end in newlinked_options"
+                value="${link_end}">${link_label} ticket</option>
+      </select>
+      <input type="submit" name="fred" value="Create" title="Create new linked ticket" />
+    </form> 
   </div>
 </div>

File trac/ticket/web_ui.py

 
         return 'ticket.html', data, None
 
+    def _other_end(self, field, link_ends_map):
+        other_end = link_ends_map[field['name']]
+        if other_end is None:
+            return field['name']
+        return  other_end
+        
     def _prepare_data(self, req, ticket, absurls=False):
         ticket_sys = TicketSystem(self.env)
+        link_ends_map = ticket_sys.link_ends_map
         context = Context.from_request(req, ticket.resource, absurls=absurls)
+        link_fields = [field for field in ticket.fields 
+                             if field['type'] == 'link']
+        # Create a pairwise list of (label, end_on_the_other_ticket)
+        # A ticket created using a given label will then be linked to this
+        # ticket by the chosen end
+        new_linked = [(field['label'], self._other_end(field, link_ends_map))
+                      for field in link_fields]
         
         return {'ticket': ticket,
                 'linked_tickets': 
                         [(field['label'], 
                           format_to_oneliner(self.env, context, '#%s' % tkt_id), 
                           Ticket(self.env, tkt_id)) 
-                         for field in ticket.fields if field['type'] == 'link'
+                         for field in link_fields
                          for tkt_id in ticket_sys
                                             .parse_links(ticket[field['name']])
                          ],
+                'newlinked_options': new_linked,
                 'context': context,
                 'preserve_newlines': self.must_preserve_newlines}
 
                            if k.startswith('field_')])
         else:
             fields = req.args.copy()
+        
+        # Populate a link field using the value of linked_end as the field 
+        # name and linked_val the actual value.
+        if 'linked_val' in fields and 'linked_end' in fields:
+            link_val = fields.pop('linked_val')
+            link_end = fields.pop('linked_end')
+            if link_end in TicketSystem(self.env).link_ends_map:
+                fields[link_end] = link_val
+        
         # Prevent direct changes to protected fields (status and resolution are
         # set in the workflow, in get_ticket_changes())
         for each in Ticket.protected_fields: