aboutsummaryrefslogtreecommitdiffstats
path: root/lib/customstates.rb
blob: c09eb8c6a63a4ea369b00e537a297c7deeef4196 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# See `doc/THEMES.md` for more explanation of this file
# This example adds a "transferred" state to requests.

module InfoRequestCustomStates

    def self.included(base)
        base.extend(ClassMethods)
    end

    # Work out what the situation of the request is. In addition to
    # values of self.described_state, in base Alaveteli can return
    # these (calculated) values:
    #   waiting_classification
    #   waiting_response_overdue
    #   waiting_response_very_overdue
    def theme_calculate_status
        # just fall back to the core calculation
        return self.base_calculate_status
    end

    # Mixin methods for InfoRequest
    module ClassMethods 
        def theme_display_status(status)
            if status == 'transferred'
                _("Transferred.")
            else
                raise _("unknown status ") + status        
            end
        end

        def theme_extra_states
            return ['transferred']
        end
    end
end

module RequestControllerCustomStates

    def theme_describe_state(info_request)
        # called after the core describe_state code.  It should
        # end by raising an error if the status is unknown
        if info_request.calculate_status == 'transferred'
            flash[:notice] = _("Authority has transferred your request to a different public body.")
            redirect_to request_url(@info_request)
        else
            raise "unknown calculate_status " + info_request.calculate_status
        end
    end

end