Changeset 12825
- Timestamp:
- Mar 28, 2013, 1:30:39 AM (12 years ago)
- Location:
- condfieldsplugin/0.11
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
condfieldsplugin/0.11/condfields/templates/condfields.js
r5287 r12825 1 var condfields = {}; 2 #for type, fields in condfields.types.iteritems() 3 condfields['$type'] = {}; 4 #for field, val in fields.iteritems() 5 condfields['$type']['$field'] = ${val and 'true' or 'false'}; 6 #end 7 #end 8 9 var ok_view_fields = []; 10 #for field, val in enumerate(condfields.ok_view_fields) 11 ok_view_fields[$field] = '$val'; 12 #end 13 14 var ok_new_fields = []; 15 #for field, val in enumerate(condfields.ok_new_fields) 16 ok_new_fields[$field] = '$val'; 17 #end 1 var condfields = $condfields.types; 2 var field_types = $condfields.field_types; 3 var required_fields = $condfields.required_fields; 18 4 19 5 $(function() { 20 6 var mode = '$condfields.mode'; 21 22 if(mode == 'view'){ 23 ok_fields = ok_view_fields; 24 } else { 25 ok_fields = ok_new_fields; 26 } 27 7 var all_fields = []; 8 $('#properties tbody').find('label[for]').each(function(i,e) { 9 var field = e.getAttribute('for') ? e.getAttribute('for').substr(6): e.getAttribute('htmlFor').substr(6); 10 all_fields.push(field) 11 }); 28 12 var field_data = {}; 29 for(var i=0;i<ok_fields.length;i++) { 30 var field = ok_fields[i]; 31 if(mode == 'view' && field == 'owner') continue; 13 for(var i=0;i<all_fields.length;i++) { 14 var field = all_fields[i]; 32 15 field_data[field] = { 33 label: $('label[@for=field-'+field+']').parents('th') .html(),34 input: $('#field-'+field).parents('td') .html()16 label: $('label[@for=field-'+field+']').parents('th'), 17 input: $('#field-'+field).parents('td') 35 18 } 36 19 } … … 40 23 function set_type(t) { 41 24 25 var condfields_fragement = $("<div/>"); 26 $('#properties tbody tr').each(function(i,e) { 27 var lf = $(this).find("label[for]").attr('for'); 28 if (lf && lf.length > 6 && required_fields.join(' ').indexOf(lf.substr(6))==-1) { 29 $(this).appendTo(condfields_fragement); 30 } 31 }) 32 42 33 var col = 1; 43 var table = '';44 var values = [];45 for(var i=0;i<ok_fields.length;i++) {46 var field = ok_fields[i];34 var rows = []; 35 for(var i=0;i<all_fields.length;i++) { 36 var field = all_fields[i]; 37 if (!field_data[field] || field_data[field].label == null) continue; 47 38 if(mode == 'view' && field == 'owner') continue; 48 if( condfields[t][field] == 0) continue;39 if(required_fields.join(' ').indexOf(field) != -1 || condfields[t][field] == 0) continue; 49 40 50 if(col == 1) { 51 table += '<tr><th class="col1">'; 52 table += field_data[field].label + '</th>' 53 table += '<td class="col1">' + field_data[field].input + '</td>' 41 full_row = field_types[field] == 'textarea' 42 43 if(col == 1 || full_row) { 44 var tr = $("<tr/>"); 45 field_data[field].label.removeClass("col2"); 46 field_data[field].label.addClass("col1"); 47 tr.append(field_data[field].label); 48 field_data[field].input.removeClass("col2"); 49 field_data[field].input.addClass("col1"); 50 tr.append(field_data[field].input); 51 rows.push(tr); 52 col = 2; 54 53 } else { 55 table += '<th class="col2">' 56 table += field_data[field].label + '</th>' 57 table += '<td class="col2">' + field_data[field].input + '</td>' 58 } 59 60 61 62 if(col == 1){ 63 col =2; 64 } else { 65 table += '</tr>' 66 col = 1; 54 tr = rows[rows.length-1]; 55 field_data[field].label.removeClass("col1"); 56 field_data[field].label.addClass("col2"); 57 tr.append(field_data[field].label); 58 field_data[field].input.removeClass("col1"); 59 field_data[field].input.addClass("col2"); 60 tr.append(field_data[field].input); 61 col = 1; 67 62 } 68 63 69 // Copy out the value 70 values.push({field:field,value:$('#field-'+field).val()}); 64 if (full_row) { 65 col = 1 66 } 67 } 71 68 72 } 73 74 if(mode == 'new') { 75 //$('#properties tbody').html(table); 76 var n=0; 77 $('#properties tbody tr').each(function() { 78 if(n > 3) { 79 $(this).remove() 80 } 81 n += 1; 82 }) 83 $('#properties tbody').append(table); 84 } else { 85 var n=0; 86 $('#properties tbody tr').each(function() { 87 if(n > 3) { 88 $(this).remove() 89 } 90 n += 1; 91 }) 92 $('#properties tbody').append(table); 93 } 94 95 // Restore the previous values 96 for(var i=0;i<values.length;i++) { 97 $('#field-'+values[i].field).val(values[i].value); 98 } 69 if (col == 2) { 70 tr = rows[rows.length-1]; 71 tr.append('<th class="col2"/><td class="col2"/>'); 72 } 73 for (var i=0; i < rows.length; i++) { 74 $('#properties tbody').append(rows[i]); 75 } 99 76 } 100 77 101 78 function set_header_type(t) { 102 // Make a dict so I can check containment103 ok_fields_dict = {}104 for(var i=0;i<ok_fields.length;i++) {105 ok_fields_dict[ok_fields[i]] = 1;106 }107 108 79 var elms = [[]]; 109 80 $('table.properties tr').each(function() { -
condfieldsplugin/0.11/condfields/web_ui.py
r5287 r12825 1 # Created by Noah Kantrowitz on 2007-05-05. 2 # Copyright (c) 2007 Noah Kantrowitz. All rights reserved. 1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # 4 # Copyright (C) 2007-2009 Noah Kantrowitz <noah@coderanger.net> 5 # All rights reserved. 6 # 7 # This software is licensed as described in the file COPYING, which 8 # you should have received as part of this distribution. 9 # 10 11 try: 12 import json 13 except ImportError: 14 import simplejson as json 15 import urllib 3 16 4 17 from trac.core import * … … 9 22 from trac.ticket.api import TicketSystem 10 23 from trac.util.compat import sorted, set 11 import urllib12 24 13 from pkg_resources import resource_filename14 25 15 26 class CondFieldsModule(Component): … … 20 31 include_std = BoolOption('condfields', 'include_standard', default='true', 21 32 doc='Include the standard fields for all types.') 33 show_default = BoolOption('condfields', 'show_default', default='false', 34 doc='Default is to show or hide selected fields.') 22 35 23 forced_fields = set(['type', 'summary', 'reporter', 'description', 'status', 'resolution', 'priority']) 36 forced_fields = ListOption('condfields', 'forced_fields', doc='Fields that cannot be disabled', 37 default="type, summary, reporter, description, status, resolution, priority") 24 38 25 39 def __init__(self): … … 28 42 self.types = [t.name for t in Type.select(self.env)] 29 43 for t in self.types: 30 setattr(self.__class__, '%s_fields'%t, ListOption('condfields', t, doc='Fields to include for type "%s"'%t))44 setattr(self.__class__, '%s_fields'%t, ListOption('condfields', t, doc='Fields to hide for type "%s"'%t)) 31 45 32 46 # IRequestHandler methods … … 37 51 #self.log.debug("@ process_request") 38 52 data = {} 39 data['types'] = {} 53 ticket_types = {} 54 field_types = {} 40 55 mode = req.path_info[12:-3] 41 56 if mode != 'new' and mode != 'view': … … 45 60 for f in TicketSystem(self.env).get_ticket_fields(): 46 61 all_fields.append(f['name']) 62 63 field_types[f['name']] = f['type'] 64 47 65 if not f.get('custom'): 48 66 standard_fields.add(f['name']) … … 59 77 60 78 for t in self.types: 61 fields = set(getattr(self, t+'_fields')) 62 if self.include_std: 63 fields.update(standard_fields) 64 fields.update(self.forced_fields) 65 data['types'][t] = dict([ 79 if not self.show_default: 80 hiddenfields = set(getattr(self, t+'_fields')) 81 fields = set(all_fields) 82 fields.difference_update(hiddenfields) 83 else: 84 fields = set(getattr(self, t+'_fields')) 85 if self.include_std: 86 fields.update(standard_fields) 87 fields.update(set(self.forced_fields)) 88 ticket_types[t] = dict([ 66 89 (f, f in fields) for f in all_fields 67 90 ]) … … 71 94 72 95 data['mode'] = mode 73 data['all_fields'] = list(all_fields) 74 data['ok_view_fields'] = sorted(set(all_fields) - self.forced_fields, key=lambda x: all_fields.index(x)) 75 data['ok_new_fields'] = sorted(set(all_fields) - set(['summary', 'reporter', 'description', 'owner', 'type', 'status', 'resolution']), key=lambda x: all_fields.index(x)) 76 return 'condfields.js', {'condfields': data}, 'text/javascript' 96 data['types'] = json.dumps(ticket_types) 97 data['field_types'] = json.dumps(field_types) 98 data['required_fields'] = json.dumps(list(self.forced_fields)) 99 #data['ok_view_fields'] = sorted(set(all_fields) - set(self.forced_fields), key=lambda x: all_fields.index(x)) 100 #data['ok_new_fields'] = sorted(set(all_fields) - set(['summary', 'reporter', 'description', 'owner', 'type', 'status', 'resolution']), key=lambda x: all_fields.index(x)) 101 return 'condfields.js', {'condfields': data}, 'text/plain' 77 102 78 103 # IRequestFilter methods … … 96 121 return template, data, content_type 97 122 98 # ITemplateProvider methods 123 ### ITemplateProvider methods 124 99 125 def get_htdocs_dirs(self): 100 #from pkg_resources import resource_filename 101 #return [('condfields', resource_filename(__name__, 'htdocs'))] 102 return () 126 return [] 103 127 104 128 def get_templates_dirs(self): 105 #yield resource_filename(__name__, 'templates')106 129 return () 130 from pkg_resources import resource_filename 131 return [resource_filename(__name__, 'templates')] 107 132 108 -
condfieldsplugin/0.11/setup.py
r5287 r12825 1 1 #!/usr/bin/env python 2 # -*- coding: iso-8859-1 -*- 2 # -*- coding: utf-8 -*- 3 # 4 # Copyright (C) 2007-2009 Noah Kantrowitz <noah@coderanger.net> 5 # All rights reserved. 6 # 7 # This software is licensed as described in the file COPYING, which 8 # you should have received as part of this distribution. 9 # 3 10 4 11 from setuptools import setup 5 12 6 13 setup( 7 name ='TracCondFields',8 version ='2.0',9 packages =['condfields'],10 package_data = { 'condfields': ['templates/*', 'htdocs/*.js', 'htdocs/*.css' ]},14 name='TracCondFields', 15 version='2.0', 16 packages=['condfields'], 17 package_data={'condfields': ['templates/*']}, 11 18 12 author ='Noah Kantrowitz',13 author_email ='noah@coderanger.net',14 description ='Support for conditional fields in different ticket types.',15 license = 'BSD',16 keywords ='trac plugin ticket conditional fields',17 url ='http://trac-hacks.org/wiki/CondFieldsPlugin',18 classifiers =[19 author='Noah Kantrowitz', 20 author_email='noah@coderanger.net', 21 description='Support for conditional fields in different ticket types.', 22 license='BSD 3-Clause', 23 keywords='trac plugin ticket conditional fields', 24 url='http://trac-hacks.org/wiki/CondFieldsPlugin', 25 classifiers=[ 19 26 'Framework :: Trac', 20 27 ], 21 22 install_requires = ['Trac>=0.11'],23 28 24 entry_points = { 29 install_requires=['Trac>=0.11'], 30 extras_require={'customfieldadmin': 'TracCustomFieldAdmin'}, 31 32 entry_points={ 25 33 'trac.plugins': [ 26 34 'condfields.web_ui = condfields.web_ui', 35 'condfields.admin = condfields.admin[customfieldadmin]', 27 36 ] 28 37 },
Note: See TracChangeset
for help on using the changeset viewer.