Changeset 3531

Show
Ignore:
Timestamp:
04/20/08 06:21:56 (7 months ago)
Author:
vnaum
Message:

Must now work for both 0.10 and 0.11
No longer INavigationContributor, IRequestFilter
Properly guesses cc / field-cc form field id

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ccselectorplugin/0.10/cc_selector/cc_selector.py

    r3454 r3531  
    11import re 
    22from trac.core import * 
     3from trac.web.api import IRequestFilter 
    34from trac.web.chrome import add_script, \ 
    4     INavigationContributor, \ 
    55    ITemplateProvider 
     6 
     7import trac 
    68 
    79 
    810class TicketWebUiAddon(Component): 
    9     implements(INavigationContributor, ITemplateProvider) 
     11    implements(IRequestFilter, ITemplateProvider) 
    1012     
    1113    def __init__(self): 
    1214        pass 
    13      
    14     def get_navigation_items(self, req): 
    15         if re.search('ticket', req.path_info): 
    16             add_script(req, 'cc_selector/cc_selector.js') 
    17         return [] 
     15 
     16    # IRequestFilter methods 
     17    # for trac 0.10 we call add_script in post_process_request 
     18    # for trac 0.11 we call add_script in pre_process_request 
     19    def pre_process_request(self, req, handler): 
     20        if trac.__version__.startswith('0.11'): 
     21            if re.search('ticket', req.path_info): 
     22                add_script(req, 'cc_selector/cc_selector.js') 
     23        return handler 
     24    def post_process_request(self, req, template, content_type): 
     25        if trac.__version__.startswith('0.10'): 
     26            if re.search('ticket', req.path_info): 
     27                add_script(req, 'cc_selector/cc_selector.js') 
     28        return(template, content_type) 
    1829 
    1930    # ITemplateProvider 
  • ccselectorplugin/0.10/cc_selector/htdocs/cc_selector.js

    r3492 r3531  
    4343} 
    4444 
     45function guess_cc_field() 
     46{ 
     47  doc = document; 
     48 
     49  if (window.opener) 
     50  { 
     51    // alert("QQ1: shifting to parent"); 
     52    doc = window.opener.document; 
     53  } 
     54 
     55  cc_field = "cc"; 
     56  if (doc.getElementById(cc_field)) 
     57    return cc_field; 
     58 
     59  cc_field = "field-cc"; 
     60  if (doc.getElementById(cc_field)) 
     61    return cc_field; 
     62 
     63 
     64  // alert("QQ2: could not find cc field, giving up"); 
     65} 
     66 
    4567// onload function. Used in both ticket window and in pop-up. 
    4668function afterLoad() 
    4769{ 
    48   after_field = "cc"; 
    49   p = document.getElementById(after_field); 
    50   if ( ! p )   
     70   
     71  // guess fromid (possible values: cc, from-cc) 
     72  cc_field = guess_cc_field() 
     73 
     74  nurl = document.location.href.split('/'); 
     75  if ( nurl.pop() == 'cc_selector.html') 
    5176  { 
    52     split_into_checkboxes('cc', 'ccdiv') 
    53     return; 
     77    // we're in pop-up window 
     78    // create checkboxes 
     79    split_into_checkboxes(cc_field, 'ccdiv') 
    5480  } 
    55    
    56   p = p.parentNode; 
    57    
    58   var ccb = document.createElement('input'); 
    59   ccb.setAttribute("type", "button"); 
    60   ccb.setAttribute("id", "ccbutton"); 
    61   ccb.setAttribute("name", "ccbutton"); 
    62   ccb.setAttribute("value", ">"); 
    63   ccb.setAttribute("alt", "Extended CC selection"); 
    64   // ccb.setAttribute("onClick", "show_selection()"); 
    65   ccb.onclick = show_selection; 
    66   p.appendChild(ccb); 
     81  else 
     82  { 
     83    // we're on ticket window 
     84    // create button 
     85    p = document.getElementById(cc_field); 
     86    p = p.parentNode; 
     87     
     88    var ccb = document.createElement('input'); 
     89    ccb.setAttribute("type", "button"); 
     90    ccb.setAttribute("id", "ccbutton"); 
     91    ccb.setAttribute("name", "ccbutton"); 
     92    ccb.setAttribute("value", ">"); 
     93    ccb.setAttribute("alt", "Extended CC selection"); 
     94    // ccb.setAttribute("onClick", "show_selection()"); 
     95    ccb.onclick = show_selection; 
     96    p.appendChild(ccb); 
     97  } 
    6798} 
    6899 
     
    127158function split_into_checkboxes(fromid, toid) { 
    128159  t = document.getElementById(toid); 
    129   
     160   
    130161  devs = split_field(fromid); 
    131162 
  • ccselectorplugin/0.10/setup.py

    r3454 r3531  
    88      description='Visual cc editor for Trac', 
    99      keywords='cc checkbox editor', 
    10       version='0.0.1', 
     10      version='0.0.2', 
    1111      author='Vladislav Naumov', 
    1212      author_email='vnaum@vnaum.com',