link_name = link_uuid
if opts[:friendly_name]
- begin
- link_name = resource_class.find(link_uuid).friendly_link_name
- rescue RuntimeError
- # If that lookup failed, the link will too. So don't make one.
- return attrvalue
+ if attrvalue.respond_to? :friendly_link_name
+ link_name = attrvalue.friendly_link_name
+ else
+ begin
+ link_name = resource_class.find(link_uuid).friendly_link_name
+ rescue RuntimeError
+ # If that lookup failed, the link will too. So don't make one.
+ return attrvalue
+ end
end
end
if opts[:with_class_name]
end
def render_editable_subattribute(object, attr, subattr, template, htmloptions={})
- attrvalue = object.send(attr)
- subattr.each do |k|
- attrvalue = attrvalue[k]
+ if object
+ attrvalue = object.send(attr)
+ subattr.each do |k|
+ if attrvalue and attrvalue.is_a? Hash
+ attrvalue = attrvalue[k]
+ else
+ break
+ end
+ end
end
datatype = nil
+ required = true
if template
+ #puts "Template is #{template.class} #{template.is_a? Hash} #{template}"
if template.is_a? Hash
if template[:output_of]
- return "Output of \"#{template[:output_of]}\""
- elsif template[:datatype]
- datatype = template[:datatype]
+ return raw("<span class='label label-default'>#{template[:output_of]}</span>")
+ end
+ if template[:dataclass]
+ dataclass = template[:dataclass]
+ end
+ if template[:optional] != nil
+ required = (template[:optional] != "true")
+ end
+ if template[:required] != nil
+ required = template[:required]
end
- elsif attrvalue == nil
- attrvalue = template
end
end
- return attrvalue if !object.attribute_editable? attr
+ rsc = template
+ if template.is_a? Hash
+ if template[:value]
+ rsc = template[:value]
+ elsif template[:default]
+ rsc = template[:default]
+ end
+ end
+
+ return link_to_if_arvados_object(rsc) if !object
+ return link_to_if_arvados_object(attrvalue) if !object.attribute_editable? attr
+
+ if dataclass
+ begin
+ dataclass = dataclass.constantize
+ rescue NameError
+ end
+ else
+ dataclass = ArvadosBase.resource_class_for_uuid(rsc)
+ end
- if not datatype
- dataclass = ArvadosBase.resource_class_for_uuid(attrvalue)
- if dataclass
- datatype = 'select'
- else
- if /^\d+$/.match(attrvalue)
+ if dataclass && dataclass.is_a?(Class)
+ datatype = 'select'
+ elsif dataclass == 'number'
+ datatype = 'number'
+ else
+ if template.is_a? Array
+ # ?!?
+ elsif template.is_a? String
+ if /^\d+$/.match(template)
datatype = 'number'
- elsif
+ else
datatype = 'text'
end
end
end
- subattr.insert(0, attr)
id = "#{object.uuid}-#{subattr.join('-')}"
+ dn = "[#{attr}]"
+ subattr.each do |a|
+ dn += "[#{a}]"
+ end
+
+ if attrvalue.is_a? String
+ attrvalue = attrvalue.strip
+ end
+
+ if dataclass and dataclass.is_a? Class
+ items = []
+ if attrvalue and !attrvalue.empty?
+ items.append({name: attrvalue, uuid: attrvalue, type: dataclass.to_s})
+ end
+ #dataclass.where(uuid: attrvalue).each do |item|
+ # items.append({name: item.uuid, uuid: item.uuid, type: dataclass.to_s})
+ #end
+ dataclass.limit(10).each do |item|
+ items.append({name: item.uuid, uuid: item.uuid, type: dataclass.to_s})
+ end
+ end
lt = link_to attrvalue, '#', {
"data-emptytext" => "none",
"data-placement" => "bottom",
"data-type" => datatype,
"data-url" => url_for(action: "update", id: object.uuid, controller: object.class.to_s.pluralize.underscore),
- "data-title" => "Update #{subattr[-1].to_s.titleize}",
- "data-name" => subattr.to_json,
+ "data-title" => "Set value for #{subattr[-1].to_s}",
+ "data-name" => dn,
"data-pk" => "{id: \"#{object.uuid}\", key: \"#{object.class.to_s.underscore}\"}",
- :class => "editable",
+ "data-showbuttons" => "false",
+ "data-value" => attrvalue,
+ :class => "editable #{'required' if required}",
:id => id
}.merge(htmloptions)
- lt += raw(%{
-<script>
- $('##{id}').editable({source: select_#{dataclass}_source});
-</script>})
+ lt += raw("\n<script>")
+
+ if items and items.length > 0
+ lt += raw("add_form_selection_sources(#{items.to_json});\n")
+ end
+
+ lt += raw("$('##{id}').editable({source: function() { return select_form_sources('#{dataclass}'); } });\n")
+
+ lt += raw("</script>")
lt
end