Module: Merb::ExtJS::Direct::RemotingProvider

Defined in:
lib/merb-extjs-direct/mixins/remoting_provider.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

standard ruby method called when some class does: include Merb::ExtJS::Direct::RemotingProvider



72
73
74
75
76
# File 'lib/merb-extjs-direct/mixins/remoting_provider.rb', line 72

def self.included(base)
    # must explicity specify controller-actions to make callable.  security-wise, this is a *good* thing.
    # just one action is added.
    base.show_action(:rpc)
end

Instance Method Details

#rpcObject

rpc remote procedure call handler for Ext.direct requests.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/merb-extjs-direct/mixins/remoting_provider.rb', line 82

def rpc
    if !request.ajax? && !params["extAction"]
        return "Ext::Direct::RemotingProvider#rpc -- This method is an ajax-handler only"
    end

    is_form = false
    is_upload = false
    if params["extAction"] && params["extMethod"]
        # create fake response here.
        is_form = true
        is_upload = params.delete("extUpload") == 'true'

        request = {
            "xcontroller"   => params.delete("extAction"),
            "xaction"       => params.delete("extMethod"),
            "type"          => "rpc",
            "id"            => params.delete("id"),
            "tid"           => params.delete("extTID"),
            "format"        => params.delete("format"),
            "data"          => params
        }
        params.delete('controller')
        params.delete('action')
        res = "<html><body><textarea>#{handle_request(request).gsub(/&quot;/, "\&quot;")}</textarea></body></html>"
        return res
    elsif (params[:inflated_object])
        # multiple requests found.  I'm not sure how this "inflated_object" mechanism works.  This is Merb magic?
        # controllers always return a string, so each response has already been json-encoded.
        # since we're dealing with multiple requests here, we have to manually string-concat-wrap the retured
        # string-of-json.
        #
        return "[" + params[:inflated_object].collect {|req| handle_request(req)}.join(',') + "]"
    else
        ##
        # just a single request found
        #
        return handle_request(params)
    end
end