Changeset 3405

Show
Ignore:
Timestamp:
03/20/08 13:03:33 (9 months ago)
Author:
coderanger
Message:

Migrate the prototype screen to not require JS.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tracforgeplugin/0.11/tracforge/admin/__init__.py

    r3394 r3405  
    55#import perm_admin 
    66import prototypes 
    7 #import prototypes_admin 
     7import prototypes_admin 
    88#import dispatch 
  • tracforgeplugin/0.11/tracforge/admin/model.py

    r3394 r3405  
    303303        """Return a prototype for the defaults on the new prototype screen.""" 
    304304        proto = cls(env, '') 
    305         proto.append({'action':'MakeTracEnvironment', 'args':''}
     305        proto.append(('MakeTracEnvironment', os.path.dirname(env.path))
    306306        return proto 
    307307    default = classmethod(default) 
  • tracforgeplugin/0.11/tracforge/admin/prototypes_admin.py

    r3401 r3405  
    11# TracForge prototype admin panel 
     2import itertools 
     3 
    24from trac.core import * 
    35from trac.web.chrome import add_stylesheet, add_script 
     
    1719        if 'TRACFORGE_ADMIN' in req.perm: 
    1820            yield 'tracforge', 'TracForge', 'prototypes', 'Project Prototypes' 
     21            yield 'tracforge', 'TracForge', 'configset', 'Configset Management' 
    1922             
    20     def process_admin_request(self, req, cat, page, path_info): 
    21         # Page locations 
    22         req.hdf['tracforge.href'] = { 
    23             'prototypes': req.href.admin(cat, page), 
    24             'configset': req.href.admin(cat, page, 'configset'), 
    25             'new': req.href.admin(cat, page, 'new'), 
    26             'htdocs': req.href.chrome('tracforge'), 
    27         } 
     23    def render_admin_panel(self, req, cat, page, path_info): 
     24        data = {} 
    2825         
    2926        # General stuff 
    3027        add_stylesheet(req, 'tracforge/css/admin.css') 
    31         add_script(req, 'tracforge/js/jquery.js') 
    32         req.cat = cat 
    33         req.page = page 
    3428 
    3529        # Subpage dispatchers 
    3630        if path_info: 
    37             if path_info == 'configset': 
    38                 return self.process_configset_admin_request(req, cat, page, path_info) 
    39             elif path_info == 'new': 
     31            if path_info == 'new': 
    4032                return self._show_prototype(req, path_info, action='new') 
    4133            else: 
    4234                return self._show_prototype(req, path_info, action='edit') 
    4335         
    44      
    45         req.hdf['tracforge.prototypes.tags'] = list(Prototype.select(self.env)) 
    46          
    47         return 'admin_tracforge_prototypes.cs', None 
     36        data['prototypes'] = Prototype.select(self.env) 
     37        return 'admin_tracforge_prototypes.html', data 
    4838         
    4939    def process_configset_admin_request(self, req, cat, page, path_info): 
     
    9686    def _show_prototype(self, req, path_info, action): 
    9787        """Handler for creating a new prototype.""" 
    98         add_stylesheet(req, 'tracforge/css/prototypes_new.css') 
    99         add_script(req, 'tracforge/js/interface/iutil.js') 
    100         add_script(req, 'tracforge/js/jquery.animatedswap.js') 
    101         req.hdf['tracforge.prototypes.name'] = path_info.strip('/') 
     88        data = { 
     89            'name': path_info, 
     90            'action': action, 
     91        } 
    10292         
     93        proto = None 
    10394        if req.method == 'POST': 
    104             if req.args.get('save'): # Save either a new prototype or a changed existing ones 
    105                 name = req.args.get('name') 
    106                 if action == 'edit': 
    107                     name = path_info.strip('/') 
    108                 if not name: 
    109                     raise TracError('You must specify a name for the prototype') 
    110                 if name in ('new', 'configset'): 
    111                     raise TracError('"new" and "configset" are reserved names') 
     95            proto = Prototype(self.env, '') 
     96            for i in itertools.count(): 
     97                a = req.args.get('step%s'%i) 
     98                if a is not None: 
     99                    proto.append((a, req.args[a])) 
     100                else: 
     101                    break 
    112102             
    113                 data = req.args.get('data') 
    114                 if not data: 
    115                     raise TracError("Warning: Peguins on fire. You might have JavaScript off, don't do that") 
    116                 data = data[4:] # Strip off the 'data' literal at the start 
    117                 if not data: 
    118                     raise TracError("You must have at least one step in a prototype") 
    119                  
    120                 proto = Prototype(self.env, name) 
    121                 if action == 'new' and proto.exists: 
    122                     raise TracError("Prototype %s already exists"%name) 
    123                 del proto[:] 
    124                 for x in data.split('|'): 
    125                     proto.append(x.split(',',1)) 
    126                 proto.save() 
    127             elif req.args.get('cancel'):  
    128                 pass # This should just redirect back 
    129             elif req.args.get('delete') and action == 'edit': # Show the confirmation screen 
    130                 return 'admin_tracforge_prototypes_delete.cs', None 
    131             elif req.args.get('reallydelete') and action == 'edit': # Actually delete this prototype 
    132                 name = path_info.strip('/') 
    133                 proto = Prototype(self.env, name) 
    134                 if not proto.exists: 
    135                     raise TracError('Prototype %s does not exist'%name) 
    136                 proto.delete() 
    137             req.redirect(req.href.admin(req.cat, req.page)) 
    138  
     103            if 'movedown' in req.args: 
     104                i = int(req.args['movedown']) 
     105                x = proto.pop(i) 
     106                proto.insert(i+1, x) 
     107             
     108             
    139109        #steps = {} 
    140110        #for p in self.setup_participants: 
     
    144114        #            'description': p.get_setup_action_description(a), 
    145115        #        } 
    146         steps = TracForgeAdminSystem(self.env).get_project_setup_participants() 
     116        data['steps'] = TracForgeAdminSystem(self.env).get_project_setup_participants() 
    147117         
    148         initial_steps = []         
    149118        if action == 'new': # For a new one, use the specified defaults  
    150             initial_steps = Prototype.default(self.env) # XXX: This should really read from trac.ini somehow 
     119            if proto is None: 
     120                proto = Prototype.default(self.env) # XXX: This should really read from trac.ini somehow 
    151121        elif action == 'edit':  
    152             proto = Prototype(self.env, path_info.strip('/')) 
    153             if not proto.exists: 
    154                 raise TracError('Unknown prototype %s'%proto.tag) 
    155             initial_steps = proto 
     122            if proto is None: 
     123                proto = Prototype(self.env, data['name']) 
     124                if not proto.exists: 
     125                    raise TracError('Unknown prototype %s'%proto.tag) 
    156126        else: 
    157127            raise TracError('Invalid action %s'%action) 
    158  
    159         req.hdf['tracforge.prototypes.action'] = action 
    160         req.hdf['tracforge.prototypes.steps'] = steps 
    161         req.hdf['tracforge.prototypes.initialsteps'] = initial_steps 
    162         req.hdf['tracforge.prototypes.liststeps'] = [k for k in steps.iterkeys() if k not in initial_steps] 
     128        data['proto'] = proto 
    163129         
    164         return 'admin_tracforge_prototypes_show.cs', None 
     130        add_stylesheet(req, 'tracforge/css/prototypes_new.css') 
     131        #add_script(req, 'tracforge/js/interface/iutil.js') 
     132        #add_script(req, 'tracforge/js/jquery.animatedswap.js') 
     133        return 'admin_tracforge_prototype.html', data