Edgewall Software

Ticket #918: multi.1048.patch

File multi.1048.patch, 5.5 kB (added by cboos@…, 4 years ago)

patch that does the proposed feature

  • templates/macros.cs

    === templates/macros.cs
    ==================================================================
     
    179179      var c.name ?>" value="1" <?cs if c.selected ?>checked="checked"<?cs /if ?> /> 
    180180    <label for="custom_<?cs var c.name ?>"><?cs alt c.label ?><?cs 
    181181      var c.name ?><?cs /alt ?></label><?cs 
     182   elif c.type == 'multi' ?> 
     183    <div style="float: left"> 
     184     <label for="custom_<?cs var c.name ?>"><?cs alt c.label ?><?cs 
     185        var c.name ?><?cs /alt ?></label>: 
     186     <?cs call:hdf_select_multiple(c.option, 'custom_'+c.name, 4) ?> 
     187    </div><?cs 
    182188   elif c.type == 'select' ?> 
    183189    <select name="custom_<?cs var c.name ?>"><?cs each v = c.option ?> 
    184190     <option <?cs if v.selected ?>selected="selected"<?cs /if ?>><?cs 
    185        var v ?></option><?cs /each ?> 
     191       var v.name ?></option><?cs /each ?> 
    186192    </select><?cs 
    187193   elif c.type == 'radio' ?> 
    188194    <fieldset class="radio"> 
  • templates/query.cs

    === templates/query.cs
    ==================================================================
     
    8181  </div> 
    8282  <?cs if:len(query.custom) ?><?cs set:idx = 0 ?><?cs 
    8383   each:custom = query.custom ?><?cs 
    84     if:custom.type == 'select' || custom.type == 'radio' ?> 
     84    if:custom.type == 'select' || custom.type == 'radio' || custom.type == 'multi' ?> 
    8585     <?cs if:idx == 0 ?><br /><?cs /if ?><div> 
    8686      <label for="<?cs var:custom.name ?>"><?cs var:custom.label ?></label> 
    8787      <?cs call:hdf_select_multiple(custom.options, custom.name, 4) ?> 
  • trac/Query.py

    === trac/Query.py
    ==================================================================
     
    129129 
    130130        custom_fields = get_custom_fields(self.env) 
    131131        for custom in custom_fields: 
    132             if custom['type'] == 'select' or custom['type'] == 'radio': 
     132            if custom['type'] in ['select', 'radio', 'multi']: 
    133133                check = constraints.has_key(custom['name']) 
    134134                options = filter(None, custom['options']) 
    135135                for i in range(len(options)): 
  • trac/Ticket.py

    === trac/Ticket.py
    ==================================================================
     
    112112                       *std_values) 
    113113        id = db.db.sqlite_last_insert_rowid() 
    114114        for name in custom_fields: 
     115            value = self[name] 
     116            if isinstance(value, list): 
     117                value = '|'.join(value) 
    115118            cursor.execute('INSERT INTO ticket_custom(ticket,name,value)' 
    116                            ' VALUES(%d, %s, %s)', id, name[7:], self[name]) 
     119                           ' VALUES(%d, %s, %s)', id, name[7:], value) 
    117120        db.commit() 
    118121        self['id'] = id 
    119122        self._forget_changes() 
     
    144147            
    145148 
    146149        for name in self._old.keys(): 
     150            newvalue = self[name] 
    147151            if name[:7] == 'custom_': 
    148152                fname = name[7:] 
     153                if isinstance(newvalue, list): 
     154                    newvalue = '|'.join(newvalue) 
    149155                cursor.execute('REPLACE INTO ticket_custom(ticket,name,value)' 
    150                                ' VALUES(%s, %s, %s)', id, fname, self[name]) 
     156                               ' VALUES(%s, %s, %s)', id, fname, newvalue) 
    151157            else: 
    152158                fname = name 
    153159                cursor.execute ('UPDATE ticket SET %s=%s WHERE id=%s', 
    154                                 fname, self[name], id) 
     160                                fname, newvalue, id) 
    155161 
    156162            cursor.execute ('INSERT INTO ticket_change ' 
    157163                            '(ticket, time, author, field, oldvalue, newvalue) ' 
    158164                            'VALUES (%s, %s, %s, %s, %s, %s)', 
    159                             id, when, author, fname, self._old[name], self[name]) 
     165                            id, when, author, fname, self._old[name], newvalue) 
    160166        if comment: 
    161167            cursor.execute ('INSERT INTO ticket_change ' 
    162168                            '(ticket,time,author,field,oldvalue,newvalue) ' 
     
    226232            'label': items.get(name + '.label', ''), 
    227233            'value': items.get(name + '.value', '') 
    228234        } 
    229         if field['type'] == 'select' or field['type'] == 'radio': 
     235        if field['type'] in ['multi', 'select', 'radio']: 
    230236            field['options'] = items.get(name + '.options', '').split('|') 
    231237        elif field['type'] == 'textarea': 
    232238            field['width'] = items.get(name + '.cols', '') 
     
    248254        hdf.setValue('%s.type' % pfx, f['type']) 
    249255        hdf.setValue('%s.label' % pfx, f['label']) 
    250256        hdf.setValue('%s.value' % pfx, val) 
    251         if f['type'] == 'select' or f['type'] == 'radio': 
     257        if f['type'] in ['multi', 'select', 'radio']: 
    252258            j = 0 
     259            if f['type'] == 'multi': 
     260                multi = 1 
     261                val = val.split('|') # see Ticket.save_changes 
    253262            for option in f['options']: 
    254                 hdf.setValue('%s.option.%d' % (pfx, j), option) 
    255                 if val and (option == val or str(j) == val): 
    256                     hdf.setValue('%s.option.%i.selected' % (pfx, j), '1') 
     263                hdf.setValue('%s.option.%d.name' % (pfx, j), option) 
     264                if val: 
     265                    if (multi and option in val) or (option == val or str(j) == val): 
     266                        hdf.setValue('%s.option.%i.selected' % (pfx, j), '1') 
    257267                j += 1 
    258268        elif f['type'] == 'checkbox': 
    259269            if val in util.TRUE: