Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 390
- Log:
Initial import of Canvass, a donations-based poll application.
- Author:
- rool
- Date:
- Mon Mar 21 14:58:04 +0000 2011
- Size:
- 2558 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 | form.select( |
70 | :workflow_state, |
71 | item.allowed_new_states.collect { | state | |
72 | [ apphelp_state( state, PollsController ), state ] |
73 | }.unshift( blank_entry ), |
74 | :selected => '' |
75 | ) |
76 | end |
77 | end |