Class: Rho::Application

Inherits:
Object show all
Defined in:
lib/framework/rho/rhoapplication.rb,
lib/commonAPI/coreapi/RhoApplicationApi.rb

Constant Summary collapse

TOOLBAR_TYPE =
0
TABBAR_TYPE =
1
NOBAR_TYPE =
2
VTABBAR_TYPE =
3
@@toolbar =
[{:action => :back}, {:action => :forward}, {:action => :separator},
{:action => :home}, {:action => :refresh}, {:action => :options} ]
@@current_controller =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/framework/rho/rhoapplication.rb', line 68

def initialize
  #LocalizationSimplified.requre_loc(Rho::RhoFSConnector::get_app_path('app') + 'lang/lang_',true)
  
  unless @rhom
    @rhom = Rhom::Rhom.get_instance
  end
  unless @default_menu
  	@default_menu = Rho::Application::make_default_native_menu()
 end

  if @vtabs != nil
    @@native_bar_data = {:type => :vtabbar, :data => @vtabs}
  elsif @tabs != nil
    @@native_bar_data = {:type => :tabbar, :data => @tabs}
  elsif @@toolbar != nil
    @@native_bar_data = {:type => :toolbar, :data => @@toolbar}
  else
    @@native_bar_data = nil #{:type => :nobar}
  end
	  
  #::Rho::RHO.get_instance().check_sources_migration(self)
  @initialized = true
  
  ::Rho::RHO.get_instance().set_app(::Rho::RHO::APPNAME, self)
end

Instance Attribute Details

#default_menuObject

Returns the value of attribute default_menu.



38
39
40
# File 'lib/framework/rho/rhoapplication.rb', line 38

def default_menu
  @default_menu
end

Class Method Details

.current_controllerObject



183
184
185
# File 'lib/framework/rho/rhoapplication.rb', line 183

def self.current_controller()
    @@current_controller        
end

.defaultNativeMenuObject



59
60
61
# File 'lib/commonAPI/coreapi/RhoApplicationApi.rb', line 59

def defaultNativeMenu()
  make_default_native_menu()        
end

.get_app_path(appname) ⇒ Object



31
32
33
# File 'lib/commonAPI/coreapi/RhoApplicationApi.rb', line 31

def get_app_path(appname)
  File.join( Rho::Application.appsBundleFolder, appname + "/")
end

.get_base_app_pathObject



35
36
37
# File 'lib/commonAPI/coreapi/RhoApplicationApi.rb', line 35

def get_base_app_path
  Rho::Application.appsBundleFolder          
end

.get_blob_folderObject



47
48
49
# File 'lib/commonAPI/coreapi/RhoApplicationApi.rb', line 47

def get_blob_folder()
  Rho::Application.databaseBlobFolder()
end

.get_blob_path(relative_path) ⇒ Object



55
56
57
# File 'lib/commonAPI/coreapi/RhoApplicationApi.rb', line 55

def get_blob_path(relative_path)
  Rho::Application.expandDatabaseBlobFilePath(relative_path)
end

.get_model_path(appname, modelname) ⇒ Object



43
44
45
# File 'lib/commonAPI/coreapi/RhoApplicationApi.rb', line 43

def get_model_path(appname, modelname)
  Rho::Application.modelFolderPath(modelname)
end

.get_public_folderObject



51
52
53
# File 'lib/commonAPI/coreapi/RhoApplicationApi.rb', line 51

def get_public_folder()
  Rho::Application.publicFolder()          
end

.get_user_pathObject



39
40
41
# File 'lib/commonAPI/coreapi/RhoApplicationApi.rb', line 39

def get_user_path
  Rho::Application.userFolder                  
end

.make_default_native_menuObject

def self.make_default_native_menu

  { Rho::RhoMessages.get_message('home_menu') => :home, Rho::RhoMessages.get_message('refresh_menu') => :refresh, 
		Rho::RhoMessages.get_message('sync_menu') => :sync, Rho::RhoMessages.get_message('options_menu') => :options, Rho::RhoMessages.get_message('log_menu') => :log, :separator => nil, Rho::RhoMessages.get_message('close_menu') => :close }

end



53
54
55
# File 'lib/framework/rho/rhoapplication.rb', line 53

def self.make_default_native_menu
    NativeMenubar_defaultMainMenu()
end

.NativeMenubar_defaultMainMenuObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/framework/rho/rhoapplication.rb', line 57

def self.NativeMenubar_defaultMainMenu
    [ {:label=>Rho::RhoMessages.get_message('home_menu'), :action=>:home}, 
      { :label =>Rho::RhoMessages.get_message('refresh_menu'), :action => :refresh }, 
  	  { :label => Rho::RhoMessages.get_message('sync_menu'), :action => :sync}, 
  	  { :label =>Rho::RhoMessages.get_message('options_menu'), :action => :options},
  	  { :label=>Rho::RhoMessages.get_message('log_menu'), :action => :log}, 
  	  { :label=>:separator, :action => nil}, 
  	  { :label => Rho::RhoMessages.get_message('close_menu'), :action => :close }
  	]
end

.processApplicationEvent(params) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
# File 'lib/commonAPI/coreapi/RhoApplicationApi.rb', line 65

def self.processApplicationEvent(params)
  applicationEvent = params['applicationEvent'] 
  eventData = params['eventData']
  eventData = {} unless eventData

  case applicationEvent
  when 'Activated'
    puts "AppEvent #{applicationEvent}"

  when 'Deactivated'
    puts "AppEvent #{applicationEvent}"

  when 'UICreated'
    start_url = Rho::Application.startURI
    start_url = "" unless start_url

    if System.get_property('platform') != 'WP8'

      invalid_security_token_start_path = Rho::Application.invalidSecurityTokenStartPath
      
      if Rho::Application.securityTokenNotPassed
        if invalid_security_token_start_path && invalid_security_token_start_path.length() > 0
          start_url = invalid_security_token_start_path
        else
          # exit from application - old way
          puts 'security_token is not passed - application will closed'
          System.exit
        end
      end
    end

    puts "on_ui_created.navigate to start url: '#{start_url}'"
    WebView.navigate(start_url)

  when 'UIDestroyed'
    puts "AppEvent #{applicationEvent}"

  when 'SyncUserChanged'
    Rhom::Rhom.database_full_reset(false, false)    
    #::Rho::RHO.get_user_db().execute_sql("UPDATE client_info SET client_id=?", "")

  when 'ConfigConflict'
    puts "on_reinstall_config_update: #{eventData.conflicts}"

  when 'DBMigrateSource'
    puts "default on_migrate_source - do nothing; old_version :#{eventData.old_version}; new_src : #{eventData.new_src}"
    #if new_src['schema']
    #    db = ::Rho::RHO.get_src_db(new_src['name'])
    #    db.delete_table(new_src['name'])

    #    return false  #create new table
    #end
    return true
  end
end

.set_current_controller(ctrl) ⇒ Object



186
187
188
# File 'lib/framework/rho/rhoapplication.rb', line 186

def self.set_current_controller(ctrl)
    @@current_controller = ctrl
end

Instance Method Details

#init_nativebarObject



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
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/framework/rho/rhoapplication.rb', line 94

def init_nativebar
  return unless @@native_bar_data
  
  if @@native_bar_data[:type] == :vtabbar
    tabs = @@native_bar_data[:data]
    # normalize the list
    if tabs.kind_of? Array
         tabs.map! { |tab| tab[:refresh] = false unless tab[:refresh]; tab }
    else
         if tabs.kind_of? Hash
             tabs[:tabs].map! { |tab| tab[:refresh] = false unless tab[:refresh]; tab }
         end
    end
    puts "Initializing application with vertical tabs: #{tabs.inspect}"
    NativeTabbar.create_vertical(tabs)
    #NativeTabbar.create(tabs)
    NativeTabbar.switch_tab(0)
  elsif @@native_bar_data[:type] == :tabbar
    tabs = @@native_bar_data[:data]
    # normalize the list
    if tabs.kind_of? Array
         tabs.map! { |tab| tab[:refresh] = false unless tab[:refresh]; tab }
    else
         if tabs.kind_of? Hash
              tabs[:tabs].map! { |tab| tab[:refresh] = false unless tab[:refresh]; tab }
         end
    end
    puts "Initializing application with tabs: #{tabs.inspect}"
    NativeTabbar.create(tabs)
    NativeTabbar.switch_tab(0)
  elsif @@native_bar_data[:type] == :toolbar
    NativeToolbar.create(@@native_bar_data[:data])
  #else
  #  NativeBar.create(NOBAR_TYPE, [])
  end
  
  @@native_bar_data = nil
end

#initialized?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/framework/rho/rhoapplication.rb', line 133

def initialized?
  @initialized
end

#on_activate_appObject



137
138
139
# File 'lib/framework/rho/rhoapplication.rb', line 137

def on_activate_app
  Rho::Application.processApplicationEvent({'applicationEvent'=>'Activated'})
end

#on_deactivate_appObject



141
142
143
# File 'lib/framework/rho/rhoapplication.rb', line 141

def on_deactivate_app
  Rho::Application.processApplicationEvent({'applicationEvent'=>'Deactivated'})
end

#on_migrate_source(old_version, new_src) ⇒ Object

works for schema sources return true to run script creating table



163
164
165
# File 'lib/framework/rho/rhoapplication.rb', line 163

def on_migrate_source(old_version, new_src)
  Rho::Application.processApplicationEvent({'applicationEvent'=>'DBMigrateSource','eventData'=>{ 'old_version' => old_version, 'new_src' =>  new_src}})
end

#on_reinstall_config_update(conflicts) ⇒ Object



157
158
159
# File 'lib/framework/rho/rhoapplication.rb', line 157

def on_reinstall_config_update(conflicts)
  Rho::Application.processApplicationEvent({'applicationEvent'=>'ConfigConflict','eventData'=>{ 'conflicts' => conflicts}})
end

#on_sync_user_changedObject



153
154
155
# File 'lib/framework/rho/rhoapplication.rb', line 153

def on_sync_user_changed
  Rho::Application.processApplicationEvent({'applicationEvent'=>'SyncUserChanged'})
end

#on_ui_createdObject



145
146
147
# File 'lib/framework/rho/rhoapplication.rb', line 145

def on_ui_created
  Rho::Application.processApplicationEvent({'applicationEvent'=>'UICreated'})
end

#on_ui_destroyedObject



149
150
151
# File 'lib/framework/rho/rhoapplication.rb', line 149

def on_ui_destroyed
  Rho::Application.processApplicationEvent({'applicationEvent'=>'UIDestroyed'})
end

#serve(req, res) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/framework/rho/rhoapplication.rb', line 190

def serve(req,res)
  req[:modelpath] = self.class.get_model_path req['application'], req['model']
  controller_class = req['model']+'Controller'
  undercase = controller_class.split(/(?=[A-Z])/).map{|w| w.downcase}.join("_")
	  undercase.slice!(0) if undercase.start_with?('_')
	  #TODO: WP7 - for some reason it added _ at the start

  is_found = false  	  	
  
  if Rho::file_exist?(  req[:modelpath]+ undercase +RHO_RB_EXT )
    require req['model'] + '/' + undercase #req[:modelpath]+ undercase
    
    is_found = true
  elsif Rho::System.isRhoSimulator
    begin
        require req['model'] + '/' + undercase #req[:modelpath]+ undercase
        is_found = true
    rescue Exception => exc
    end
    
  end
  
  unless is_found
    require req['model'] + '/controller' #req[:modelpath]+'controller'
  end
  
  @@current_controller = (Object.const_get(req['model']+'Controller').new) 
  res['request-body'] = @@current_controller.send :serve, self, @rhom, req, res
end

#set_menu(menu = nil, back_action = nil) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/framework/rho/rhoapplication.rb', line 167

def set_menu(menu=nil,back_action=nil)
  @default_menu = {} if @default_menu.nil?
  disp_menu = menu ? menu.dup : @default_menu.dup
  if back_action
    if disp_menu.is_a?(Array)
        disp_menu << {:label => 'Back', :action => back_action }
    else
       disp_menu['Back'] = back_action 
    end
        
  end   
  #puts "RhoApplication: Using menu - #{disp_menu.inspect}"
 WebView.set_menu_items(disp_menu)
end