Class: UU::OS::VUC::View

Inherits:
GVC::Container show all
Defined in:
uu_adk-0.28.16/lib/uu/os/vuc/view.rb

Overview

View object used for communication with forms.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from GVC::Container

#add_message, #components, #focus, #focused_component, #get_component_by_id, #get_components_by_code, #messages

Constructor Details

- (View) initialize(data = nil)

Creates new instance of view.

Parameters:

  • data (String, Hash) (defaults to: nil)

    Initialization data in form of JSON string or Hash (optional)



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'uu_adk-0.28.16/lib/uu/os/vuc/view.rb', line 95

def initialize(data = nil)
  if data.nil?
    super(data)
    return
  end
  if data.kind_of?String
    data = JSON.parse(data, :symbolize_names => true)
  end
  if !data.kind_of?Hash
    raise ArgumentError.new("View data must be JSON String or Hash, but was #{data.class}.")
  end
  super(data)
  @id = data[:id]
  @code = data[:code]
  @name = data[:name]
  @status = data[:status]
  @component_type = data[:componentType]
  @event = UU::OS::VUC::Event.new(data[:event])
  @context = UU::OS::VUC::Context.new(data[:context])
  @navigation = UU::OS::VUC::Navigation.new(data[:navigation])
  @result = data[:result]
  @view_template =  UU::OS::VUC::ViewTemplate.new(data[:viewTemplate])
end

Instance Attribute Details

- (String) code (readonly)

View code.

Returns:

  • (String)


23
24
25
# File 'uu_adk-0.28.16/lib/uu/os/vuc/view.rb', line 23

def code
  @code
end

- (Numeric) component_type (readonly)

View type.

Returns:

  • (Numeric)


36
37
38
# File 'uu_adk-0.28.16/lib/uu/os/vuc/view.rb', line 36

def component_type
  @component_type
end

- (UU::OS::VUC::Context) context (readonly)

Use case context.



44
45
46
# File 'uu_adk-0.28.16/lib/uu/os/vuc/view.rb', line 44

def context
  @context
end

- (UU::OS::VUC::Event) event (readonly)

Incoming event.

Returns:



40
41
42
# File 'uu_adk-0.28.16/lib/uu/os/vuc/view.rb', line 40

def event
  @event
end

- (String) id (readonly)

Unique view ID.

Returns:

  • (String)


19
20
21
# File 'uu_adk-0.28.16/lib/uu/os/vuc/view.rb', line 19

def id
  @id
end

- (String) name (readonly)

View name.

Returns:

  • (String)


27
28
29
# File 'uu_adk-0.28.16/lib/uu/os/vuc/view.rb', line 27

def name
  @name
end

What should form do next.



48
49
50
# File 'uu_adk-0.28.16/lib/uu/os/vuc/view.rb', line 48

def navigation
  @navigation
end

- (Object) result

The result of the VUC. Setting the value to anything other than nil means that the VUC has finished and the user can be navigated elsewhere.

By convention, setting "false" means that the VUC was cancelled. The result will be passed to the parent VUC if the current VUC runs in a dialog window. Otherwise, if the value is an URI, it'll be used for navigation. Otherwise, the user will be navigated to the previous UC.



58
59
60
# File 'uu_adk-0.28.16/lib/uu/os/vuc/view.rb', line 58

def result
  @result
end

- (Numeric) status

HTTP status code of processed request (possible values are available on HTTPStatus).

Parameters:

  • (Numeric)

Returns:

  • (Numeric)


32
33
34
# File 'uu_adk-0.28.16/lib/uu/os/vuc/view.rb', line 32

def status
  @status
end

- (UU::OS::VUC::ViewTemplate) view_template (readonly)

Note:

View template can be set only in on_before_init method, if you set data_uri in another method, it will have no effect.

View template that can be used for setting different sheet that will be rendered as form. Read UU::OS::VUC::ViewTemplate#data_uri for more info.

Examples:

# uri of default VUC
UCR_URI = "ues:UNI:CDS.GUESTBOOK/COMMENT/CREATE"

# code of sheet with extended form
EXTENDED_FORM_CODE = "EXTENDED_FORM"

def on_before_init(ctx)

  # get default view template => main sheet on VUC
  view_template_uri = ctx.view_template.data_uri # String ues:UNI:CDS.GUESTBOOK/COMMENT/CREATE:DEFAULT_FORM

  use_extended_form = ... # some logic to find out if use can see extended form

  if use_extended_form
    # set new sheet with extended form
    ctx.view_template.data_uri = UU::OS::UESURIBuilder.parse_uesuri(UCR_URI).set_object_code(EXTENDED_FORM_CODE).to_uesuri
  end

  # if you do not set data_uri so default is used

end

Returns:

See Also:



89
90
91
# File 'uu_adk-0.28.16/lib/uu/os/vuc/view.rb', line 89

def view_template
  @view_template
end

Instance Method Details

- (String) to_response

Serializes view to JSON.

Returns:

  • (String)

    Serialized view



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'uu_adk-0.28.16/lib/uu/os/vuc/view.rb', line 122

def to_response
  response = {}
  response[:id] = @id
  response[:code] = @code
  response[:name] = @name
  response[:status] = @status
  response[:componentType] = @component_type
  response[:event] = @event.raw_attrs if (@event.raw_attrs) && (!@event.raw_attrs.empty?)
  response[:context] = @context.raw_attrs if (@context.raw_attrs) && (!@context.raw_attrs.empty?)
  if (@components) && (@components.values.size > 0)
    response[:components] = []
    @components.values.each do |component|
      response[:components] << component.attributes
    end
  end
  if (@messages) && (@messages.size > 0)
    response[:messages] = []
    @messages.each do |message|
      response[:messages] << message.raw_attrs
    end
  end
  response[:navigation] = @navigation.raw_attrs if (@navigation.raw_attrs) && (!@navigation.raw_attrs.empty?)
  response[:focusOn] = @focus_on if @focus_on
  response[:result] = @result if !@result.nil?
  response[:viewTemplate] = @view_template.raw_attrs if (@view_template.raw_attrs) && (!@view_template.raw_attrs.empty?)
  response.to_json
end