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



324
325
326
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 324

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

#createdObject



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 328

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



349
350
351
352
353
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 349

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