Module: Glib::Json::Libs::ClassMethods

Defined in:
app/controllers/concerns/glib/json/libs.rb

Instance Method Summary collapse

Instance Method Details

#json_libs_force_json_uiObject



285
286
287
# File 'app/controllers/concerns/glib/json/libs.rb', line 285

def json_libs_force_json_ui
  before_action :glib_force_json_ui
end

#json_libs_init(options) ⇒ Object



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'app/controllers/concerns/glib/json/libs.rb', line 256

def json_libs_init(options)
  include Glib::Json::Transformation
  include Glib::Json::Validation
  include Glib::Json::Ui

  include Glib::Json::Traversal
  include Glib::Json::NewDynamicText

  before_action do
    __json_ui_start(options)
  end

  # Note that after_action gets executed in reverse
  after_action do
    __json_ui_commit(options)
  end
  after_action :__json_transformation_commit
  after_action :__json_validate_perform

  after_action :__json_traversal_perform
  after_action :__json_traversal_register_dynamic_text
end

#json_libs_rescue_404(preview_mode: false) ⇒ Object



351
352
353
354
355
# File 'app/controllers/concerns/glib/json/libs.rb', line 351

def json_libs_rescue_404(preview_mode: false)
  rescue_from ActiveRecord::RecordNotFound do |exception|
    glib_json_handle_404(exception, preview_mode)
  end
end

#json_libs_rescue_500(preview_mode: false) ⇒ Object

Call this before other rescues. Later rescue_from statements will take precedence, so more specific rescues have to be declared later.



345
346
347
348
349
# File 'app/controllers/concerns/glib/json/libs.rb', line 345

def json_libs_rescue_500(preview_mode: false)
  rescue_from StandardError do |exception|
    glib_json_handle_500(exception, preview_mode)
  end
end

#json_libs_rescue_csrfObject



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'app/controllers/concerns/glib/json/libs.rb', line 298

def json_libs_rescue_csrf
  rescue_from ActionController::InvalidAuthenticityToken do |exception|
    # sign_out(:user)

    # respond_to do |format|
    #   format.json do
    #     render json: {
    #       onResponse: {
    #         action: 'windows/open-v1',
    #         url: url
    #       }
    #     }
    #   end
    # end

    respond_to do |format|
      format.html do
        redirect_to 
      end
      format.json do
        render json: {
          glib_json_dialog_mode? ? :onLoad : :onResponse => __glib_error_dialog(
            'Your session has expired', 'Please refresh the page and retry.', [
              {
                view: 'button',
                text: 'Refresh',
                onClick: {
                  action: 'dialogs/close',
                  onClose: {
                    action: 'windows/reload',
                    onReload: {
                      action: 'snackbars/alert',
                      message: 'Refreshed. You can try again now.'
                    }
                  }
                }
              },
            ]
          )
        }
      end
    end
  end
end

#json_libs_set_localeObject



289
290
291
292
293
294
295
296
# File 'app/controllers/concerns/glib/json/libs.rb', line 289

def json_libs_set_locale
  before_action do
    # Need to explicitly fallback to EN
    I18n.locale = params[:_locale] || :en
  rescue
    I18n.locale = :en
  end
end

#json_libs_skip_json_ui(options = {}) ⇒ Object



279
280
281
282
283
# File 'app/controllers/concerns/glib/json/libs.rb', line 279

def json_libs_skip_json_ui(options = {})
  prepend_before_action options do
    params[:_skip_render] = 'true'
  end
end