diff --git a/app/dictionaries/dictionary.rb b/app/dictionaries/dictionary.rb index fa71f9253..70bb91051 100644 --- a/app/dictionaries/dictionary.rb +++ b/app/dictionaries/dictionary.rb @@ -78,7 +78,11 @@ def keys private def load_dictionary - YAML.safe_load(File.read(dictionary_filepath)).with_indifferent_access + if File.exist?(dictionary_filepath) + YAML.safe_load(File.read(dictionary_filepath)).with_indifferent_access + else + {} + end end def get_file_path(config_file, default_file) diff --git a/app/dictionaries/keywords_dictionary.rb b/app/dictionaries/keywords_dictionary.rb new file mode 100644 index 000000000..17f9236f6 --- /dev/null +++ b/app/dictionaries/keywords_dictionary.rb @@ -0,0 +1,10 @@ +# Dictionary of Keywords +class KeywordsDictionary < Dictionary + + DEFAULT_FILE = 'keywords.yml' + + def dictionary_filepath + get_file_path 'keywords', DEFAULT_FILE + end + +end \ No newline at end of file diff --git a/app/dictionaries/target_audience_dictionary.rb b/app/dictionaries/target_audience_dictionary.rb index daa1d21e2..aa37b6805 100644 --- a/app/dictionaries/target_audience_dictionary.rb +++ b/app/dictionaries/target_audience_dictionary.rb @@ -3,8 +3,6 @@ class TargetAudienceDictionary < Dictionary DEFAULT_FILE = 'target_audience.yml' - private - def dictionary_filepath get_file_path 'target_audience', DEFAULT_FILE end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8c1ef2d02..d7a2483bd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -362,6 +362,7 @@ def field_lock(name, _options = {}) def dropdown(name, options = {}) existing_values = object.send(name.to_sym) existing = options[:options].select { |_label, value| existing_values.include?(value) } + visibility_toggle = options[:visibility_toggle] || [] @template.render(partial: 'common/dropdown', locals: { field_name: name, f: self, model_name: options[:model_name], resource: object, @@ -370,7 +371,8 @@ def dropdown(name, options = {}) field_label: options[:label], required: options[:required], errors: options[:errors], - title: options[:title] }) + title: options[:title], + hidden: hidden?(name, visibility_toggle) }) end def hidden?(name, visibility_toggle) diff --git a/app/views/common/_dropdown.html.erb b/app/views/common/_dropdown.html.erb index fb5401501..2b96604cf 100644 --- a/app/views/common/_dropdown.html.erb +++ b/app/views/common/_dropdown.html.erb @@ -25,13 +25,6 @@ render :partial => 'common/dropdown', options ||= format_for_dropdown(field_name.capitalize.constantize.all) existing ||= format_for_dropdown(resource.send(field_name.pluralize)) - # Remove existing objects from the pool of options - options = options - existing - dropdown_toggle_button_name ||= '' - if dropdown_toggle_button_name.blank? - dropdown_toggle_button_name = "Add #{field_name.to_s.sub(/_ids?\z/, '').humanize}" - end - # show the required label? required ||= false @@ -43,9 +36,17 @@ render :partial => 'common/dropdown', # check title title ||= '' + + # Remove existing objects from the pool of options + options = options - existing + dropdown_toggle_button_name ||= '' + if dropdown_toggle_button_name.blank? + dropdown_toggle_button_name = "Add #{field_label.to_s.sub(/_ids?\z/, '').humanize}" + end + %> -