Class: Glib::JsonUi::ViewBuilder::Fields::MultiUpload

Inherits:
AbstractField show all
Includes:
Default
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 included from Default

#default_accepts

Methods inherited from AbstractField

#context, #default_url_options, #determine_value, #hint, #hint_args, #label, #label_args, #name, #placeholder, #placeholder_args, #prop, #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

#accepts(value) ⇒ Object



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

def accepts(value)
  @accepts = value
end

#createdObject



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
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 336

def created
  super

  @placeholder ||= I18n.t('glib.multi_upload.placeholder', default: nil)
  @hint ||= I18n.t('glib.multi_upload.hint', default: nil)

  ['200', '403', '401', 'else'].each do |status|
    key = "glib.multi_upload.responseMessages.#{status}"
    @responseMessages[status] = I18n.t(key) if I18n.exists?(key)
  end
  json.responseMessages (@responseMessages || {}).reverse_merge({
    '200' => 'File uploaded',
    '403' => 'Forbidden',
    '401' => 'Session expired',
    'else' => 'Upload failed'
  })

  json.placeholder @placeholder if @placeholder
  json.hint @hint if @hint

  json.accepts default_accepts(@accepts)

  if @prop && context
    # association = form.nested_associations.last
    # context = association || form

    @files ||= context.field_value(@prop, collect_ids: false).to_a.map { |file| { name: file.blob&.filename, signed_id: file.signed_id, url: url_for(file) } }
  end

  json.files @files if @files.present?
end

#files(values) ⇒ Object



328
329
330
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 328

def files(values)
  @files = values
end

#responseMessages(values) ⇒ Object



332
333
334
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 332

def responseMessages(values)
  @responseMessages = values
end