Class: Netzke::BasicApp

Inherits:
Base
  • Object
show all
Extended by:
ClassMethods
Defined in:
lib/netzke/basic_app.rb

Overview

BasicApp

Basis for a Ext.Viewport-based application

Features:

  • dynamic loading of widgets

  • authentification support

  • browser history support (press the “Back”-button to go to the previously loaded widget)

  • FeedbackGhost-powered feedback

  • aggregation of widget’s own menus

  • masquerade support

  • AJAX activity indicator

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from ClassMethods

config, js_base_class, js_extend_properties, js_panels

Constructor Details

#initialize(*args) ⇒ BasicApp

Returns a new instance of BasicApp.



253
254
255
256
257
258
259
260
261
262
# File 'lib/netzke/basic_app.rb', line 253

def initialize(*args)
  super

  if session[:netzke_just_logged_in] || session[:netzke_just_logged_out]
    session[:config_mode] = false
    session[:masq_world] = session[:masq_user] = session[:masq_roles] = nil
  end

  strong_children_config.deep_merge!({:ext_config => {:mode => :config}}) if session[:config_mode]
end

Instance Method Details

#actionsObject

Available actions



267
268
269
270
271
272
273
# File 'lib/netzke/basic_app.rb', line 267

def actions
  { 
    :masquerade_selector => {:text => "Masquerade as ...", :fn => "showMasqueradeSelector"},
    :toggle_config_mode => {:text => "#{session[:config_mode] ? "Leave" : "Enter"} config mode", :fn => "toggleConfigMode"},
    :logout => {:text => "Log out", :fn => "logout"}
  }
end

#initial_aggregateesObject

We rely on the FeedbackGhost (to not need to implement our own feedback management)



287
288
289
# File 'lib/netzke/basic_app.rb', line 287

def initial_aggregatees
  {:feedback_ghost => {:widget_class_name => "FeedbackGhost"}}
end

#js_widget_htmlObject

Html required for Ext.History to work



277
278
279
280
281
282
283
284
# File 'lib/netzke/basic_app.rb', line 277

def js_widget_html
  super << %Q{
<form id="history-form" class="x-hidden">
<input type="hidden" id="x-history-field" />
<iframe id="x-history-frame"></iframe>
</form>
  }
end

#js_widget_instanceObject

Besides instantiating ourselves, also instantiate the FeedbackGhost



292
293
294
295
296
297
298
# File 'lib/netzke/basic_app.rb', line 292

def js_widget_instance
  <<-END_OF_JAVASCRIPT << super
    new Ext.netzke.cache['FeedbackGhost']({id:'feedback_ghost'})
    // Initialize history (can't say why it's not working well inside the appLoaded handler)
    Ext.History.init();
  END_OF_JAVASCRIPT
end

#masquerade_as(params) ⇒ Object



312
313
314
315
316
317
318
# File 'lib/netzke/basic_app.rb', line 312

def masquerade_as(params)
  session = Netzke::Base.session
  session[:masq_world] = params[:world]
  session[:masq_role] = params[:role]
  session[:masq_user] = params[:user]
  {:js => "window.location.reload()"}
end

Set the Logout button if Netzke::Base.user is set



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/netzke/basic_app.rb', line 224

def menu
  res = []
  user = Netzke::Base.user
  if !user.nil?
    user_name = user.respond_to?(:name) ? user.name : user. # try to display user's name, fallback to login
    res << "->" <<
    {
      :text => "#{user_name}",
      :menu => user_menu
    }
  else
    res << "->" <<
    {
      :text => "Login",
      :handler => <<-END_OF_JAVASCRIPT.l,
        function(){
          window.location = "/login"
        }
      END_OF_JAVASCRIPT
      :scope => this
    }
  end
  res
end

#toggle_config_mode(params) ⇒ Object



305
306
307
308
309
# File 'lib/netzke/basic_app.rb', line 305

def toggle_config_mode(params)
  session = Netzke::Base.session
  session[:config_mode] = !session[:config_mode]
  {:js => "window.location.reload();"}
end

#user_menuObject



249
250
251
# File 'lib/netzke/basic_app.rb', line 249

def user_menu
  ['logout']
end