|
2 | 2 |
|
3 | 3 | # check configuration |
4 | 4 | if AppConfig.has_key?(:user_defined_in_basic) |
5 | | - AppConfig[:user_defined_in_basic].keys.each do |k| |
6 | | - if ['accession', 'resource', 'digital_object'].include?(k) |
7 | | - AppConfig[:user_defined_in_basic][k].each do |fld| |
8 | | - unless JSONModel(:user_defined).schema['properties'].include?(fld) |
9 | | - $stderr.puts "WARNING: user_defined_in_basic plugin configuration includes " + |
10 | | - "a field (#{fld}) in the list for #{k} which is not a user_defined field. " + |
11 | | - "That's ok, we're just concerned you might have intended to refer to an actual field." |
12 | | - end |
| 5 | + AppConfig[:user_defined_in_basic].each do |keys, fields| |
| 6 | + fields.each do |field| |
| 7 | + unless JSONModel(:user_defined).schema['properties'].include?(field) |
| 8 | + $stderr.puts "WARNING: user_defined_in_basic plugin configuration includes " + |
| 9 | + "a field (#{fld}) in the list for #{k} which is not a user_defined field. " + |
| 10 | + "That's ok, we're just concerned you might have intended to refer to an actual field." |
13 | 11 | end |
14 | | - else |
15 | | - $stderr.puts "WARNING: user_defined_in_basic plugin configuration includes an unexpected key: #{k}. " + |
16 | | - "That's ok, it just occurred to us that it might be a typo. " + |
17 | | - "Supported keys are: accession, resource, and digital_object" |
18 | 12 | end |
19 | 13 | end |
20 | 14 | else |
21 | 15 | $stderr.puts "WARNING: user_defined_in_basic plugin is active but not configured. " + |
22 | 16 | "That's ok, it just won't do anything." |
23 | 17 | end |
24 | 18 |
|
25 | | - |
26 | | - |
27 | | - AspaceFormHelper.class_eval do |
28 | | - |
29 | | - PROPERTIES_TO_EXCLUDE_FROM_READ_ONLY_VIEW = ["jsonmodel_type", "lock_version", "_resolved", "uri", "ref", "create_time", "system_mtime", "user_mtime", "created_by", "last_modified_by", "sort_name_auto_generate", "suppressed", "display_string", "file_uri"] |
30 | | - |
31 | | - # This is a copy of read_only_view in the AspaceFormHelper |
32 | | - # The only significant difference is that it adds a 'for' attribute to |
33 | | - # the control-label so that the js can tell which field it belongs to |
34 | | - # cut and paste coding - sorry, bad |
35 | | - def awesomer_read_only_view(hash, opts = {}) |
36 | | - jsonmodel_type = hash["jsonmodel_type"] |
37 | | - schema = JSONModel(jsonmodel_type).schema |
38 | | - prefix = opts[:plugin] ? 'plugins.' : '' |
39 | | - html = "<div class='form-horizontal'>" |
40 | | - |
41 | | - hash.reject {|k,v| PROPERTIES_TO_EXCLUDE_FROM_READ_ONLY_VIEW.include?(k)}.each do |property, value| |
42 | | - |
43 | | - if schema and schema["properties"].has_key?(property) |
44 | | - if (schema["properties"][property].has_key?('dynamic_enum')) |
45 | | - value = I18n.t("#{prefix}enumerations.#{schema["properties"][property]["dynamic_enum"]}.#{value}", :default => value) |
46 | | - elsif schema["properties"][property].has_key?("enum") |
47 | | - value = I18n.t("#{prefix}#{jsonmodel_type.to_s}.#{property}_#{value}", :default => value) |
48 | | - elsif schema["properties"][property]["type"] === "boolean" |
49 | | - value = value === true ? "True" : "False" |
50 | | - elsif schema["properties"][property]["type"] === "date" |
51 | | - value = value.blank? ? "" : Date.strptime(value, "%Y-%m-%d") |
52 | | - elsif schema["properties"][property]["type"] === "array" |
53 | | - # this view doesn't support arrays |
54 | | - next |
55 | | - elsif value.kind_of? Hash |
56 | | - # can't display an object either |
57 | | - next |
58 | | - end |
59 | | - end |
60 | | - |
61 | | - html << "<div class='form-group'>" |
62 | | - html << "<div class='control-label col-sm-2' for='#{opts['parent']}_#{jsonmodel_type.to_s}__#{property}_'>#{I18n.t("#{prefix}#{jsonmodel_type.to_s}.#{property}")}</div>" |
63 | | - html << "<div class='label-only col-md-9'>#{value}</div>" |
64 | | - html << "</div>" |
65 | | - |
66 | | - end |
67 | | - |
68 | | - html << "</div>" |
69 | | - |
70 | | - html.html_safe |
71 | | - end |
72 | | - |
73 | | - end |
74 | | - |
75 | 19 | end |
0 commit comments