Projet

Général

Profil

0001-add-possibility-to-set-colours-on-workflows-status-3.patch

Frédéric Péters, 14 janvier 2014 10:24

Télécharger (8,03 ko)

Voir les différences:

Subject: [PATCH] add possibility to set colours on workflows status (#3977)

 wcs/admin/workflows.py           | 24 +++++++++++++++++++++++-
 wcs/forms/backoffice.py          | 24 ++++++++++++++++++++++++
 wcs/qommon/form.py               | 13 +++++++++++++
 wcs/qommon/static/css/qommon.css | 30 ++++++++++++++++++++++++++++++
 wcs/qommon/static/js/popup.js    |  3 +++
 wcs/workflows.py                 |  5 +++++
 6 files changed, 98 insertions(+), 1 deletion(-)
wcs/admin/workflows.py
290 290
class WorkflowStatusPage(Directory):
291 291
    _q_exports = ['', 'delete', 'newitem', ('items', 'items_dir'),
292 292
                  'update_order', 'edit', 'reassign', 'visibility',
293
                  'endpoint']
293
                  'endpoint', 'colour']
294 294

  
295 295
    def __init__(self, workflow, status_id, html_top):
296 296
        self.html_top = html_top
......
367 367

  
368 368

  
369 369
    def get_sidebar(self):
370
        get_response().add_javascript(['jquery.js', 'jquery-ui.js', 'popup.js',
371
            'jquery.colourpicker.js'])
370 372
        r = TemplateIO(html=True)
371 373
        if str(self.workflow.id).startswith(str('_')):
372 374
            r += htmltext('<p>')
......
378 380
            r += htmltext('<li><a href="edit">%s</a></li>') % _('Change Status Name')
379 381
            r += htmltext('<li><a href="visibility" rel="popup">%s</a></li>') % _('Change Status Visibility')
380 382
            r += htmltext('<li><a href="endpoint" rel="popup">%s</a></li>') % _('Change Terminal Status')
383
            r += htmltext('<li><a href="colour" rel="popup">%s</a></li>') % _('Change Status Colour')
381 384
            r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete')
382 385
            r += htmltext('</ul>')
383 386
            r += htmltext('<div id="new-field">')
......
611 614
        get_response().breadcrumb.append( ('endpoint', _('Terminal Status')) )
612 615
        return form.render()
613 616

  
617
    def colour(self):
618
        form = Form(enctype = 'multipart/form-data')
619
        form.add(ColourWidget, 'colour',
620
                 title=_('Colour'),
621
                 value=self.status.colour)
622
        form.add_submit('submit', _('Submit'))
623
        form.add_submit('cancel', _('Cancel'))
624
        if form.get_widget('cancel').parse():
625
            return redirect('..')
626

  
627
        if form.is_submitted() and not form.has_errors():
628
            self.status.colour = form.get_widget('colour').parse()
629
            self.workflow.store()
630
            return redirect('.')
631

  
632
        self.html_top(title = _('Edit Status Colour'))
633
        get_response().breadcrumb.append( ('colour', _('Status Colour')) )
634
        return form.render()
635

  
614 636

  
615 637
class WorkflowStatusDirectory(Directory):
616 638
    _q_exports = ['']
wcs/forms/backoffice.py
50 50

  
51 51
        get_response().add_css_include('../js/tablesorter/themes/blue/style.css')
52 52
        r = TemplateIO(html=True)
53

  
54
        if self.formdef.workflow:
55
            colours = []
56
            for status in self.formdef.workflow.possible_status:
57
                if status.colour and status.colour != 'ffffff':
58
                    # luminance coefficients taken from section C-9 fro
59
                    # http://www.faqs.org/faqs/graphics/colorspace-faq/
60
                    brightess = int(status.colour[0:2], 16) * 0.212671 + \
61
                            int(status.colour[2:4], 16) * 0.715160 + \
62
                            int(status.colour[4:6], 16) * 0.072169
63
                    if brightess > 128:
64
                        fg_colour = 'black'
65
                    else:
66
                        fg_colour = 'white'
67
                    colours.append((status.id, status.colour, fg_colour))
68
            if colours:
69
                r += htmltext('<style>')
70
                for status_id, bg_colour, fg_colour  in colours:
71
                    r += htmltext('tr.status-%s-wf-%s td.cell-status { '\
72
                            'background-color: #%s !important; color: %s !important; }\n' % (
73
                                self.formdef.workflow.id, status_id, bg_colour,
74
                                fg_colour))
75
                r += htmltext('</style>')
76

  
53 77
        r += htmltext('<table id="listing" class="sortable tablesorter">')
54 78

  
55 79
        r += htmltext('<colgroup>')
wcs/qommon/form.py
23 23
import time
24 24
import random
25 25
import datetime
26
import itertools
26 27

  
27 28
from storage import atomic_write
28 29

  
......
1674 1675
</script>""")
1675 1676

  
1676 1677
        return r.getvalue()
1678

  
1679

  
1680
class ColourWidget(SingleSelectWidget):
1681

  
1682
    def __init__(self, *args, **kwargs):
1683
        colours = ['%s%s%s' % x for x in itertools.product(('00', '66', '99', 'FF'), repeat=3)]
1684
        SelectWidget.__init__(self, options=colours, *args, **kwargs)
1685
        self.attrs['class'] = 'colour-picker'
1686

  
1687
    def render_content(self):
1688
        get_response().add_javascript(['jquery.js', 'jquery.colourpicker.js'])
1689
        return SingleSelectWidget.render_content(self)
wcs/qommon/static/css/qommon.css
355 355
.passStrengthify {
356 356
	padding-left: 1em;
357 357
}
358

  
359
#jquery-colour-picker {
360
        background: #fafafa;
361
        width: 250px;
362
        padding: 10px 5px;
363
        border-radius: 5px;
364
        box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.3);
365
        z-index: 1000;
366
}
367

  
368
#jquery-colour-picker ul {
369
        margin: 0;
370
        padding: 0;
371
        list-style-type: none;
372
}
373

  
374
#jquery-colour-picker li {
375
        float: left;
376
        margin: 0 5px 5px 0;
377
}
378

  
379
#jquery-colour-picker li a {
380
        display: block;
381
        width: 13px;
382
        height: 13px;
383
        text-decoration: none;
384
        text-indent: -10000px;
385
        outline: 0;
386
        border: 1px solid #aaa;
387
}
wcs/qommon/static/js/popup.js
13 13
            if ($(dialog).find('input[name$=add_element]').length) {
14 14
                prepare_widget_list_elements();
15 15
            }
16
            if (jQuery.fn.colourPicker !== undefined) {
17
              jQuery('select.colour-picker').colourPicker({title: ''});
18
            }
16 19
            return false;
17 20
        }
18 21
    });
wcs/workflows.py
266 266
        just_submitted_status = workflow.add_status(_('Just Submitted'), 'just_submitted')
267 267
        just_submitted_status.visibility = ['_receiver']
268 268
        new_status = workflow.add_status(_('New'), 'new')
269
        new_status.colour = '66FF00'
269 270
        rejected_status = workflow.add_status(_('Rejected'), 'rejected')
271
        rejected_status.colour = 'FF3300'
270 272
        accepted_status = workflow.add_status(_('Accepted'), 'accepted')
273
        accepted_status.colour = '66CCFF'
271 274
        finished_status = workflow.add_status(_('Finished'), 'finished')
275
        finished_status.colour = 'CCCCCC'
272 276

  
273 277
        commentable = CommentableWorkflowStatusItem()
274 278
        commentable.id = '_commentable'
......
387 391
    items = None
388 392
    visibility = None
389 393
    forced_endpoint = False
394
    colour = 'FFFFFF'
390 395

  
391 396
    def __init__(self, name = None):
392 397
        self.name = name
393
-