Skip to content

Instantly share code, notes, and snippets.

@spritle
Created April 26, 2013 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spritle/5468772 to your computer and use it in GitHub Desktop.
Save spritle/5468772 to your computer and use it in GitHub Desktop.
mobile_app_sample_code.rb
require 'rho/rhocontroller'
require 'lib/flow/login_flow'
require 'lib/flow/new_trip_flow'
require 'lib/flow/transfer_detail_flow'
module UHS
# Base controller providing commonly used functionality
class BaseController < Rho::RhoController
end
class UhsController < BaseController
def serve(application, object_mapping, req, res)
@request, @response = req, res
@object_mapping = object_mapping
@params = Rho::RhoSupport::query_params req
@rendered = false
@redirected = false
Rho::RhoController.process_rho_object(@params)
if @@before and @@before[self.class.to_s] and not @params['rho_callback']
@@before[self.class.to_s].call(@params,@request)
end
act = req['action'].nil? ? default_action : req['action']
if self.respond_to?(act)
res = send req['action'].nil? ? default_action : req['action']
else
called_action = @request['action'].nil? ? default_action : @request['action']
Alert.show_popup(@request[:modelpath]+called_action.to_s+RHO_ERB_EXT)
unless Rho::file_exist?(@request[:modelpath]+called_action.to_s+RHO_ERB_EXT)
rho_error( "Action '#{act}' does not exist in controller or has private access." )
# test = '<div data-role="page" data-url="#" data-external-page="true" >Custom error handling by UHS</div>'
error = '<div data-role="page" data-url="#" data-external-page="true" >Custom error handling by UHS</div>'
res = render :string => error
end
end
if @params['rho_callback']
res = "" unless res.is_a?(String)
return res
end
res = render unless @rendered or @redirected
application.set_menu(@menu, @back_action)
@menu = nil
@back_action = nil;
res
end
end
class LoginFlowController < UhsController
include UHS::Flow::LoginFlow
end
class NewTripFlowController < UhsController
include UHS::Flow::NewTripFlow
end
class TransferDetailFlowController < UhsController
include UHS::Flow::TransferDetailFlow
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment