Class: Glib::JsonUi::ViewBuilder::Fields::File

Inherits:
Text show all
Includes:
Upload
Defined in:
app/helpers/glib/json_ui/view_builder/fields.rb

Instance Attribute Summary

Attributes inherited from JsonUiElement

#json, #page

Instance Method Summary collapse

Methods inherited from AbstractField

#autoValidate, #context, #default_url_options, #hint, #hint_args, #label, #label_args, #name, #placeholder, #placeholder_args, #prop, #validation, #value

Methods inherited from View

component_name

Methods inherited from JsonUiElement

#initialize, #props

Constructor Details

This class inherits a constructor from Glib::JsonUi::JsonUiElement

Instance Method Details

#buttonLabels(obj) ⇒ Object



315
316
317
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 315

def buttonLabels(obj)
  @buttonLabels = ActiveSupport::HashWithIndifferentAccess.new(obj)
end

#createdObject



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 319

def created
  @buttonLabels ||= ActiveSupport::HashWithIndifferentAccess.new
  @buttonLabels['change'] ||= I18n.t('glib.change') if I18n.exists?('glib.change')
  @buttonLabels['upload'] ||= I18n.t('glib.upload') if I18n.exists?('glib.upload')
  @buttonLabels['delete'] ||= I18n.t('glib.delete') if I18n.exists?('glib.delete')

  json.set! :buttonLabels, @buttonLabels

  if @prop && context
    # json.fileTitle context.field_value(@prop).blob&.filename

    if (value = context.field_value(@prop)).attached?
      json.fileTitle value.blob.filename
      json.fileUrl url_for(value)
    end
  end

  super
end

#determine_value(context, prop) ⇒ Object



340
341
342
343
344
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 340

def determine_value(context, prop)
  if (value = context.field_value(prop)).attached?
    value.signed_id || ''
  end
end