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



320
321
322
# File 'app/controllers/concerns/glib/json/libs.rb', line 320

def json_libs_force_json_ui
  before_action :glib_force_json_ui
end

#json_libs_init(options) ⇒ Object



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'app/controllers/concerns/glib/json/libs.rb', line 291

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



390
391
392
393
394
# File 'app/controllers/concerns/glib/json/libs.rb', line 390

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.



384
385
386
387
388
# File 'app/controllers/concerns/glib/json/libs.rb', line 384

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_csrf(sign_in_url_proc) ⇒ Object



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'app/controllers/concerns/glib/json/libs.rb', line 333

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 instance_exec(&)
      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.', ['dialog-csrf-error'], [
              {
                view: 'button',
                text: 'Refresh',
                onClick: {
                  action: 'auth/saveCsrfToken',
                  token: form_authenticity_token,
                  onSave: {
                    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



324
325
326
327
328
329
330
331
# File 'app/controllers/concerns/glib/json/libs.rb', line 324

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



314
315
316
317
318
# File 'app/controllers/concerns/glib/json/libs.rb', line 314

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