Skip to content

Commit 3090c4a

Browse files
committed
add config option to hide user defined section
1 parent 1d9a40d commit 3090c4a

4 files changed

Lines changed: 32 additions & 12 deletions

File tree

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ Add an entry to your `config.rb` like this:
2929
AppConfig[:user_defined_in_basic] = {
3030
'accessions' => ['boolean_1', 'enum_2', 'real_2'],
3131
'digital_objects' => [],
32-
'resources' => ['string_2', 'date_1', 'boolean_1']
32+
'resources' => ['string_2', 'date_1', 'boolean_1'],
33+
'hide_user_defined_section' => true
3334
}
3435

3536
If you don't have a `:user_defined_in_basic` entry the plugin won't do anything.
3637
It will log a warning at startup.
3738

38-
The three keys shown (`accessions`, `resources`, and `digital_objects`) are the
39+
The three keys, `accessions`, `resources`, and `digital_objects`, are the
3940
record types that can have a `user_defined` subrecord. For each key specified
4041
a `user_defined` subrecord will be automatically added when a new record
4142
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
5354
If you specify a field that doesn't exist in the `user_defined` record,
5455
a warning will be logged at startup.
5556

57+
The `hide_user_defined_section` key is optional. If specified with a value of
58+
`true`, then the User Defined section will be hidden in View and Edit modes.
59+
This will give a cleaner display, but it means it will only be possible to
60+
edit the user defined fields that have been moved to the Basic Information
61+
section.

frontend/assets/user_defined_in_basic.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function UserDefinedInBasic() {
22
}
33

4-
UserDefinedInBasic.prototype.init = function(fields, read_only_view) {
4+
UserDefinedInBasic.prototype.init = function(fields, read_only_view, hide_user_defined_section) {
55
var bi = $("#basic_information");
66

77
if (bi.length == 0) {
@@ -15,10 +15,20 @@ UserDefinedInBasic.prototype.init = function(fields, read_only_view) {
1515
var remove_btn = user_defined_section.find('.subrecord-form-remove');
1616
if (remove_btn.length == 0) {
1717
user_defined_section.find('.btn-default').filter(':visible').click();
18-
user_defined_section.find('.subrecord-form-remove').attr('disabled', 'disabled');
1918
window.scrollTo(0,0);
19+
}
20+
21+
// hide the remains of the user defined section if configured thus
22+
if (hide_user_defined_section) {
23+
if (read_only_view) {
24+
$('section[id$=_user_defined_]').hide();
25+
} else {
26+
user_defined_section.hide();
27+
}
2028
} else {
21-
remove_btn.attr('disabled', 'disabled');
29+
if (!read_only_view) {
30+
user_defined_section.find('.subrecord-form-remove').attr('disabled', 'disabled');
31+
}
2232
}
2333

2434
fields.map(function (field) {

frontend/plugin_init.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
# check configuration
44
if AppConfig.has_key?(:user_defined_in_basic)
55
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."
6+
if fields.respond_to?(:each)
7+
fields.each do |field|
8+
unless JSONModel(:user_defined).schema['properties'].include?(field)
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
1113
end
1214
end
1315
end
16+
AppConfig[:user_defined_in_basic]['hide_user_defined_section'] ||= false
1417
else
1518
$stderr.puts "WARNING: user_defined_in_basic plugin is active but not configured. " +
1619
"That's ok, it just won't do anything."

frontend/views/layout_head.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ end
1212
<script>
1313
var fields = <%= ASUtils.to_json(map_user_defined_to_labels(AppConfig[:user_defined_in_basic].fetch(controller.controller_name, []))).html_safe %>;
1414
var read_only_view = <%= controller.action_name == 'show' %>;
15-
15+
var hide_user_defined_section = <%= AppConfig[:user_defined_in_basic]['hide_user_defined_section'] %>;
16+
1617
var init = function () {
1718
// Funny setTimeout here to move our initialization to the
1819
// end of the page load. We need this to run after the user
1920
// defined field subform is in and its buttons have been wired
2021
// up.
2122
setTimeout(function () {
22-
new UserDefinedInBasic().init(fields, read_only_view);
23+
new UserDefinedInBasic().init(fields, read_only_view, hide_user_defined_section);
2324
}, 0);
2425
}
2526

0 commit comments

Comments
 (0)