diff --git a/README.md b/README.md index 7d5baf2..8662688 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,14 @@ Add an entry to your `config.rb` like this: AppConfig[:user_defined_in_basic] = { 'accessions' => ['boolean_1', 'enum_2', 'real_2'], 'digital_objects' => [], - 'resources' => ['string_2', 'date_1', 'boolean_1'] + 'resources' => ['string_2', 'date_1', 'boolean_1'], + 'hide_user_defined_section' => true } If you don't have a `:user_defined_in_basic` entry the plugin won't do anything. It will log a warning at startup. -The three keys shown (`accessions`, `resources`, and `digital_objects`) are the +The three keys, `accessions`, `resources`, and `digital_objects`, are the record types that can have a `user_defined` subrecord. For each key specified a `user_defined` subrecord will be automatically added when a new record is created through the staff UI, or will be added to an existing record when @@ -53,3 +54,8 @@ to see in the `Basic Information`. The fields specified will be moved to the If you specify a field that doesn't exist in the `user_defined` record, a warning will be logged at startup. +The `hide_user_defined_section` key is optional. If specified with a value of +`true`, then the User Defined section will be hidden in View and Edit modes. +This will give a cleaner display, but it means it will only be possible to +edit the user defined fields that have been moved to the Basic Information +section. diff --git a/frontend/assets/user_defined_in_basic.js b/frontend/assets/user_defined_in_basic.js index a21ed49..8d593c6 100644 --- a/frontend/assets/user_defined_in_basic.js +++ b/frontend/assets/user_defined_in_basic.js @@ -1,7 +1,7 @@ function UserDefinedInBasic() { } -UserDefinedInBasic.prototype.init = function(fields, read_only_view) { +UserDefinedInBasic.prototype.init = function(fields, read_only_view, hide_user_defined_section) { var bi = $("#basic_information"); if (bi.length == 0) { @@ -15,10 +15,20 @@ UserDefinedInBasic.prototype.init = function(fields, read_only_view) { var remove_btn = user_defined_section.find('.subrecord-form-remove'); if (remove_btn.length == 0) { user_defined_section.find('.btn-default').filter(':visible').click(); - user_defined_section.find('.subrecord-form-remove').attr('disabled', 'disabled'); window.scrollTo(0,0); + } + + // hide the remains of the user defined section if configured thus + if (hide_user_defined_section) { + if (read_only_view) { + $('section[id$=_user_defined_]').hide(); + } else { + user_defined_section.hide(); + } } else { - remove_btn.attr('disabled', 'disabled'); + if (!read_only_view) { + user_defined_section.find('.subrecord-form-remove').attr('disabled', 'disabled'); + } } fields.map(function (field) { diff --git a/frontend/plugin_init.rb b/frontend/plugin_init.rb index 552bd05..23edb21 100644 --- a/frontend/plugin_init.rb +++ b/frontend/plugin_init.rb @@ -3,14 +3,17 @@ # check configuration if AppConfig.has_key?(:user_defined_in_basic) AppConfig[:user_defined_in_basic].each do |keys, fields| - fields.each do |field| - unless JSONModel(:user_defined).schema['properties'].include?(field) - $stderr.puts "WARNING: user_defined_in_basic plugin configuration includes " + - "a field (#{fld}) in the list for #{k} which is not a user_defined field. " + - "That's ok, we're just concerned you might have intended to refer to an actual field." + if fields.respond_to?(:each) + fields.each do |field| + unless JSONModel(:user_defined).schema['properties'].include?(field) + $stderr.puts "WARNING: user_defined_in_basic plugin configuration includes " + + "a field (#{fld}) in the list for #{k} which is not a user_defined field. " + + "That's ok, we're just concerned you might have intended to refer to an actual field." + end end end end + AppConfig[:user_defined_in_basic]['hide_user_defined_section'] ||= false else $stderr.puts "WARNING: user_defined_in_basic plugin is active but not configured. " + "That's ok, it just won't do anything." diff --git a/frontend/views/layout_head.html.erb b/frontend/views/layout_head.html.erb index cfa4a16..890da59 100644 --- a/frontend/views/layout_head.html.erb +++ b/frontend/views/layout_head.html.erb @@ -12,14 +12,15 @@ end