Permalink
Browse files

Reading options from the trac.ini file.

Works only with de default trac tields.
  • Loading branch information...
1 parent f93023e commit e8664a5b0d698c16d4e38c369343d96b900ec318 @daltonmatos committed Nov 25, 2009
@@ -1,5 +1,6 @@
from trac.core import *
+from trac.config import Option, ListOption
from trac.ticket import TicketSystem
from trac.web.api import ITemplateStreamFilter, IRequestFilter
from trac.web.chrome import add_script, ITemplateProvider
@@ -11,24 +12,34 @@ class ConditionalFields(Component):
implements(ITemplateStreamFilter, IRequestFilter, ITemplateProvider)
base_url = 'cf'
+ config_section = 'conditional-fields'
default_fields = ['priority', 'milestone', 'component', 'version',\
'keywords', 'cc', 'owner'];
-
# ITemplateStreamFilter
def filter_stream(self, req, method, filename, stream, data):
logger = self.env.log
- logger.info(">>> filename=%s" % filename)
if filename == 'ticket.html':
ticket_sys = TicketSystem(self.env)
all_fields = ticket_sys.get_ticket_fields()
+ # The default fields are aways available
script = "<script>\n"
for field_name in self.default_fields:
script += ("all_fields.push('%s');\n" % field_name)
- script += "</script>\n"
+
+
+ i = 1
+ while len(self.config.getlist(self.config_section, ('ticket_type_%d' % i))) > 0 :
+ ticket_type = self.config.getlist(self.config_section, ('ticket_type_%d' % i))
+ visible_fields = self.config.getlist(self.config_section, ('visible_fields_%d' % i))
+ if len(visible_fields) > 0 :
+ script += ("types['%s'] = ['%s'];\n" % ("".join(ticket_type), "','".join(visible_fields)))
+ i += 1
+
+ script += "</script>\n"
stream |= Transformer("//div[@id='footer']").after(MarkupTemplate(script).generate())
return stream
@@ -42,7 +53,7 @@ def post_process_request(self, req, template, data, content_type):
add_script(req, ('%s/conditional-fields.js' % self.base_url))
return template, data, content_type
-
+ #ITemplateProvider
def get_templates_dirs(self):
return []
@@ -27,10 +27,10 @@ types = {};
-types['task'] = ['version', 'cc', 'priority'];
-types['defect'] = ['keywords'];
-types['enhancement'] = ['cc'];
-types['Tipo de téste'] = ['cc', 'keywords', 'priority']
+//types['task'] = ['version', 'cc', 'priority'];
+//types['defect'] = ['keywords'];
+//types['enhancement'] = ['cc'];
+//types['Tipo de téste'] = ['cc', 'keywords', 'priority']
function change_event_handler(){

0 comments on commit e8664a5

Please sign in to comment.