Class: AspaceFormHelper::FormContext::JSONModelDefinition
- Inherits:
-
BaseDefinition
- Object
- BaseDefinition
- AspaceFormHelper::FormContext::JSONModelDefinition
- Defined in:
- frontend/app/helpers/aspace_form_helper.rb
Instance Method Summary collapse
-
#allowable_types_for(name) ⇒ Object
-
#default_for(name) ⇒ Object
-
#initialize(jsonmodel, root) ⇒ JSONModelDefinition
constructor
A new instance of JSONModelDefinition.
-
#options_for(context, property, add_empty_options = false, opts = {}) ⇒ Object
-
#record_type ⇒ Object
-
#required?(name) ⇒ Boolean
Constructor Details
#initialize(jsonmodel, root) ⇒ JSONModelDefinition
Returns a new instance of JSONModelDefinition.
1078 1079 1080 1081 |
# File 'frontend/app/helpers/aspace_form_helper.rb', line 1078 def initialize(jsonmodel, root) @jsonmodel = jsonmodel @root = root end |
Instance Method Details
#allowable_types_for(name) ⇒ Object
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 |
# File 'frontend/app/helpers/aspace_form_helper.rb', line 1106 def allowable_types_for(name) defn = jsonmodel_schema_definition(name) if defn ASUtils.extract_nested_strings(defn).map {|s| ref = JSONModel.parse_jsonmodel_ref(s) ref.first.to_s if ref }.compact else [] end end |
#default_for(name) ⇒ Object
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 |
# File 'frontend/app/helpers/aspace_form_helper.rb', line 1090 def default_for(name) if jsonmodel_schema_definition(name) if jsonmodel_schema_definition(name).has_key?('dynamic_enum') if jsonmodel_schema_definition(name)['default'] Rails.logger.warn("Superfluous default value at: #{@jsonmodel}.#{name} ") end JSONModel.enum_default_value(jsonmodel_schema_definition(name)['dynamic_enum']) else jsonmodel_schema_definition(name)['default'] end else nil end end |
#options_for(context, property, add_empty_options = false, opts = {}) ⇒ Object
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 |
# File 'frontend/app/helpers/aspace_form_helper.rb', line 1120 def (context, property, = false, opts = {}) = [] .push([(opts[:empty_label] || ""), ""]) if defn = jsonmodel_schema_definition(property) jsonmodel_enum_for(property).each do |v| if opts[:include] && !opts[:include].include?(v) next end if opts[:exclude] && opts[:exclude].include?(v) next end if opts.has_key?(:i18n_path_for) && opts[:i18n_path_for].has_key?(v) i18n_path = opts[:i18n_path_for][v] elsif opts.has_key?(:i18n_prefix) i18n_path = "#{opts[:i18n_prefix]}.#{v}" elsif defn.has_key?('dynamic_enum') i18n_path = "enumerations.#{defn['dynamic_enum']}.#{v}" else i18n_path = context.i18n_for("#{Array(property).last}_#{v}") end .push([I18n.t(i18n_path, :default => v), v]) end end |
#record_type ⇒ Object
1147 1148 1149 |
# File 'frontend/app/helpers/aspace_form_helper.rb', line 1147 def record_type @jsonmodel.record_type end |
#required?(name) ⇒ Boolean
1084 1085 1086 1087 |
# File 'frontend/app/helpers/aspace_form_helper.rb', line 1084 def required?(name) ((jsonmodel_schema_definition(name) && jsonmodel_schema_definition(name)['ifmissing'] === 'error')) end |