示例#1
0
    def post_process_request(self, req, template, data, content_type):
        # Some ticket views do not actually load the data in this way
        # e.g. action=history or action=diff
        if not data or not data.has_key('fields'):
            return template, data, content_type

        newticket = req.path_info.startswith('/newticket')
        if req.path_info.startswith('/ticket/') or newticket:
            for field in data['fields']:
                if 'client' == field['name']:
                    field['options'] = []
                    for client in Client.select(self.env):
                        field['options'].append(client.name)
                    if not field['options']:
                        # Don't show field if there are no clients
                        data['fields'].remove(field)
                    else:
                        field['type'] = 'select'
                        if newticket:
                            default_client = self.config.get('ticket', 'default_client')
                            if default_client:
                                data['ticket']['client'] = default_client
                    break;
        elif req.path_info.startswith('/query'):
            if data['fields'].has_key('client'):
                data['fields']['client']['type'] = 'select'
                data['fields']['client']['options'] = []
                for client in Client.select(self.env):
                    data['fields']['client']['options'].append(client.name)
        return template, data, content_type
示例#2
0
    def post_process_request(self, req, template, data, content_type):
        # Some ticket views do not actually load the data in this way
        # e.g. action=history or action=diff
        if not data or not data.has_key('fields'):
            return template, data, content_type

        newticket = req.path_info.startswith('/newticket')
        if req.path_info.startswith('/ticket/') or newticket:
            for field in data['fields']:
                if 'client' == field['name']:
                    field['options'] = []
                    for client in Client.select(self.env):
                        field['options'].append(client.name)
                    if not field['options']:
                        # Don't show field if there are no clients
                        data['fields'].remove(field)
                    else:
                        field['type'] = 'select'
                        if newticket:
                            default_client = self.config.get(
                                'ticket', 'default_client')
                            if default_client:
                                data['ticket']['client'] = default_client
                    break
        elif req.path_info.startswith('/query'):
            if data['fields'].has_key('client'):
                data['fields']['client']['type'] = 'select'
                data['fields']['client']['options'] = []
                for client in Client.select(self.env):
                    data['fields']['client']['options'].append(client.name)
        return template, data, content_type
示例#3
0
    def filter_stream(self, req, method, filename, stream, data):
        # Add Stylesheet here, so that the ticket page gets it too :)
        add_stylesheet(req, "clients/clients.css")

        newticket = req.path_info.startswith('/newticket')
        if req.path_info.startswith('/ticket/') or newticket:
            setdefaultrate = ''
            if newticket:
              setdefaultrate = "$('#field-client').trigger('change');"
            
            script = StringIO()
            script.write("""
              $(document).ready(function() {
                $('#field-client').change(function() {
                  """);
            script.write('var clientrates = new Array();')
            for client in Client.select(self.env):
                script.write('clientrates["%s"] = %s;' % (client.name, client.default_rate or '""'))
            script.write("""
                  try { $('#field-clientrate').attr('value', clientrates[this.options[this.selectedIndex].value]); }
                  catch (er) { }
                });
                %s
             });""" % setdefaultrate);
            stream |= Transformer('.//head').append(tag.script(script.getvalue(), type_='text/javascript'))
        return stream
示例#4
0
    def filter_stream(self, req, method, filename, stream, data):
        # Add Stylesheet here, so that the ticket page gets it too :)
        add_stylesheet(req, "clients/clients.css")

        newticket = req.path_info.startswith('/newticket')
        if req.path_info.startswith('/ticket/') or newticket:
            setdefaultrate = ''
            if newticket:
                setdefaultrate = "$('#field-client').trigger('change');"

            script = StringIO()
            script.write("""
              $(document).ready(function() {
                $('#field-client').change(function() {
                  """)
            script.write('var clientrates = new Array();')
            for client in Client.select(self.env):
                script.write('clientrates["%s"] = %s;' %
                             (client.name, client.default_rate or '""'))
            script.write("""
                  try { $('#field-clientrate').attr('value', clientrates[this.options[this.selectedIndex].value]); }
                  catch (er) { }
                });
                %s
             });""" % setdefaultrate)
            stream |= Transformer('.//head').append(
                tag.script(script.getvalue(), type_='text/javascript'))
        return stream
示例#5
0
    def _render_admin_panel(self, req, cat, page, client):
        # Detail view?
        if client:
            clnt = Client(self.env, client)
            events = ClientEvent.select(self.env, client)
            if req.method == 'POST':
                if req.args.get('save'):
                    clnt.name = req.args.get('name')
                    clnt.description = req.args.get('description')
                    clnt.changes_list = req.args.get('changes_list')
                    clnt.changes_period = req.args.get('changes_period')
                    clnt.summary_list = req.args.get('summary_list')
                    clnt.summary_period = req.args.get('summary_period')
                    clnt.default_rate = req.args.get('default_rate')
                    clnt.currency = req.args.get('currency')
                    clnt.update()

                    @self.env.with_transaction()
                    def do_client_event_updates(db):
                        for clev in events:
                            for option in clev.summary_client_options:
                                arg = 'summary-option-%s-%s' % (
                                    clev.md5,
                                    clev.summary_client_options[option]['md5'])
                                clev.summary_client_options[option][
                                    'value'] = req.args.get(arg)
                            for option in clev.action_client_options:
                                arg = 'action-option-%s-%s' % (
                                    clev.md5,
                                    clev.action_client_options[option]['md5'])
                                clev.action_client_options[option][
                                    'value'] = req.args.get(arg)
                            clev.update_options(client, db)

                    req.redirect(req.href.admin(cat, page))
                elif req.args.get('cancel'):
                    req.redirect(req.href.admin(cat, page))

            add_script(req, 'common/js/wikitoolbar.js')
            data = {'view': 'detail', 'client': clnt, 'events': events}

        else:
            if req.method == 'POST':
                # Add Client
                if req.args.get('add') and req.args.get('name'):
                    clnt = Client(self.env)
                    clnt.name = req.args.get('name')
                    clnt.insert()
                    req.redirect(req.href.admin(cat, page))

                # Remove clients
                elif req.args.get('remove') and req.args.get('sel'):
                    sel = req.args.get('sel')
                    sel = isinstance(sel, list) and sel or [sel]
                    if not sel:
                        raise TracError('No client selected')

                    @self.env.with_transaction()
                    def do_delete(db):
                        for name in sel:
                            clnt = Client(self.env, name, db=db)
                            clnt.delete(db=db)

                    req.redirect(req.href.admin(cat, page))

                # Set default client
                elif req.args.get('apply'):
                    if req.args.get('default'):
                        name = req.args.get('default')
                        self.log.info('Setting default client to %s', name)
                        self.config.set('ticket', 'default_client', name)
                        self.config.save()
                        req.redirect(req.href.admin(cat, page))

            default = self.config.get('ticket', 'default_client')
            data = {
                'view': 'list',
                'clients': Client.select(self.env),
                'default': default
            }

        return 'admin_clients.html', data
示例#6
0
    def _render_admin_panel(self, req, cat, page, client):
        # Detail view?
        if client:
            clnt = Client(self.env, client)
            events = ClientEvent.select(self.env, client)
            if req.method == 'POST':
                if req.args.get('save'):
                    clnt.name = req.args.get('name')
                    clnt.description = req.args.get('description')
                    clnt.changes_list = req.args.get('changes_list')
                    clnt.changes_period = req.args.get('changes_period')
                    clnt.summary_list = req.args.get('summary_list')
                    clnt.summary_period = req.args.get('summary_period')
                    clnt.default_rate = req.args.get('default_rate')
                    clnt.currency = req.args.get('currency')
                    clnt.update()

                    @self.env.with_transaction()
                    def do_client_event_updates(db):
                      for clev in events:
                        for option in clev.summary_client_options:
                          arg = 'summary-option-%s-%s' % (clev.md5, clev.summary_client_options[option]['md5'])
                          clev.summary_client_options[option]['value'] = req.args.get(arg)
                        for option in clev.action_client_options:
                          arg = 'action-option-%s-%s' % (clev.md5, clev.action_client_options[option]['md5'])
                          clev.action_client_options[option]['value'] = req.args.get(arg)
                        clev.update_options(client, db)

                    req.redirect(req.href.admin(cat, page))
                elif req.args.get('cancel'):
                    req.redirect(req.href.admin(cat, page))

            add_script(req, 'common/js/wikitoolbar.js')
            data = {'view': 'detail', 'client': clnt, 'events': events}

        else:
            if req.method == 'POST':
                # Add Client
                if req.args.get('add') and req.args.get('name'):
                    clnt = Client(self.env)
                    clnt.name = req.args.get('name')
                    clnt.insert()
                    req.redirect(req.href.admin(cat, page))

                # Remove clients
                elif req.args.get('remove') and req.args.get('sel'):
                    sel = req.args.get('sel')
                    sel = isinstance(sel, list) and sel or [sel]
                    if not sel:
                        raise TracError('No client selected')

                    @self.env.with_transaction()
                    def do_delete(db):
                        for name in sel:
                            clnt = Client(self.env, name, db=db)
                            clnt.delete(db=db)
                    req.redirect(req.href.admin(cat, page))

                # Set default client
                elif req.args.get('apply'):
                    if req.args.get('default'):
                        name = req.args.get('default')
                        self.log.info('Setting default client to %s', name)
                        self.config.set('ticket', 'default_client', name)
                        self.config.save()
                        req.redirect(req.href.admin(cat, page))

            default = self.config.get('ticket', 'default_client')
            data = {'view': 'list',
                    'clients': Client.select(self.env),
                    'default': default}

        return 'admin_clients.html', data