Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 457
- Log:
Add admin ability to revert an underway poll to an open state.
More sensible entries now presented in the state change menu.
- Author:
- rool
- Date:
- Thu Oct 24 05:58:50 +0100 2013
- Size:
- 3532 Bytes
1 | ######################################################################## |
2 | # File:: polls_helper.rb |
3 | # (C):: Hipposoft 2011 |
4 | # |
5 | # Purpose:: Utility methods for views related to Polls. |
6 | # ---------------------------------------------------------------------- |
7 | # 30-Jan-2011 (ADH): Created. |
8 | ######################################################################## |
9 | |
10 | module PollsHelper |
11 | |
12 | # Return text suitable for a link, button or heading when wanting to list |
13 | # polls created by a given user - e.g. "Your polls" vs "<Foo>'s polls". |
14 | # Pass "nil" for a generic string - e.g. "All polls". |
15 | # |
16 | # The returned string is HTML-safe, with any sensitive characters escaped. |
17 | # |
18 | def pollshelp_index_text( user ) |
19 | if ( user.nil? ) |
20 | apphelp_heading( PollsController, :index ) |
21 | elsif ( user.id == current_user.try( :id ) ) |
22 | apphelp_view_hint( :your_polls, PollsController ) |
23 | else |
24 | apphelp_view_hint( :other_polls, PollsController, :name => h( user.name ) ) |
25 | end |
26 | end |
27 | |
28 | # Called via shared/_simple_search.html.erb due to its appearance in |
29 | # Poll::SEARCH_COLUMNS. Generates HTML used to search for a workflow |
30 | # state. Passed the ID to use for the field and the current field value. |
31 | # |
32 | def pollhelp_search_states( id, value ) |
33 | ctrl = PollsController |
34 | blank_entry = [ |
35 | t( :'uk.org.pond.canvass.search.menu_blank' ), |
36 | '' |
37 | ] |
38 | |
39 | select_tag( |
40 | id, |
41 | options_for_select( |
42 | |
43 | # The use of "states.keys" gives us an array of state names as symbols; |
44 | # reject the 'initial' state, then collect the remainder into pairs of |
45 | # internal state name and human-readable state name. Finally, add the |
46 | # blank menu entry array at the start of the collection. |
47 | |
48 | Poll.workflow_spec.states.keys.reject { | state | |
49 | state == Poll::STATE_INITIAL |
50 | }.collect { | state | |
51 | [ apphelp_state( state, ctrl ), state.to_s ] |
52 | }.unshift( blank_entry ), |
53 | |
54 | :selected => ( value || '' ) |
55 | ) |
56 | ) |
57 | end |
58 | |
59 | # Return a SELECT menu for the given form, representing the given poll item, |
60 | # according to its current state and, consequently, the states to which it |
61 | # may be set. |
62 | # |
63 | def pollshelp_state_change_menu( form, item ) |
64 | blank_entry = [ |
65 | apphelp_view_hint( :menu_no_change, PollsController ), |
66 | '' |
67 | ] |
68 | |
69 | # 'Events' is a hash of event names yielding event data. Collect this to |
70 | # an array of key/value pairs and sort using the value's "transitions_to" |
71 | # field. State names have "a_", "b_" etc. prefixes so that they sort in a |
72 | # rational order for the progression from one state to another. |
73 | |
74 | events = item.current_state.events.dup.collect.sort do | a, b | |
75 | a[ 1 ].transitions_to.to_s <=> b[ 1 ].transitions_to.to_s |
76 | end |
77 | |
78 | # Generate a menu from this array using the translated event name for the |
79 | # visible text and the state name to which the item should be transitioned |
80 | # as the associated form value. We use the sorted array from above rather |
81 | # than the raw events data as the raw events hash is not sorted by logical |
82 | # transition order (hashes are not inherently sorted and event names do |
83 | # not have the sortable prefix convention used for state names). |
84 | |
85 | form.select( |
86 | :workflow_state, |
87 | events.collect { | event | |
88 | event_name = event[ 0 ] |
89 | event_data = event[ 1 ] |
90 | [ apphelp_event( event_name, PollsController ), event_data.transitions_to ] |
91 | }.unshift( blank_entry ), |
92 | :selected => '' |
93 | ) |
94 | end |
95 | end |