diff --git a/frontend/plugin_init.rb b/frontend/plugin_init.rb new file mode 100644 index 0000000..1ca3371 --- /dev/null +++ b/frontend/plugin_init.rb @@ -0,0 +1,32 @@ +Rails.application.config.after_initialize do + + AppConfig[:large_index_notes_threshold] = 100 unless AppConfig.has_key?(:large_index_notes_threshold) + + unless AppConfig[:large_index_notes_threshold].is_a?(Integer) + raise "large_index_notes plugin configuration error: AppConfig[:large_index_notes_threshold] must be an integer!" + end + + module AspaceFormHelper + def define_final_template(name, definition = nil, &block) + @templates ||= {} + + @templates[name] = { + :final => true, + :block => block, + :definition => (definition || BaseDefinition.new), + } + end + + def define_template(name, definition = nil, &block) + @templates ||= {} + + return if @templates[name] && @templates[name][:final] + + @templates[name] = { + :final => false, + :block => block, + :definition => (definition || BaseDefinition.new), + } + end + end +end diff --git a/frontend/views/_top_of_basic_information_resource.html.erb b/frontend/views/_top_of_basic_information_resource.html.erb new file mode 100644 index 0000000..93c1fd1 --- /dev/null +++ b/frontend/views/_top_of_basic_information_resource.html.erb @@ -0,0 +1,64 @@ +<% define_final_template "note_index", jsonmodel_definition(:note_index) do |form| %> +
+

<%= I18n.t("note.note_index") %>

+
+ <%= form.hidden_input(:jsonmodel_type, "note_index") %> + <%= form.hidden_input("ingest_problem") %> + <%= form.label_and_textfield("persistent_id") %> + <%= form.label_and_textfield("label") %> + <% form.emit_template("content_items", :required => form.required?('content')) %> + <%= form.label_and_boolean("publish", {}, user_prefs["publish"]) %> + +
+

+ <%= I18n.t("note_index.items") %> + <% if not form.readonly? %> + + <% end %> +

+
+ + <% if form["items"] && form["items"].count > AppConfig[:large_index_notes_threshold] %> + + + + + + + + + <%= form.list_for(form["items"], "items[]") do |item| %> + <% form.emit_template("note_index_item_table", item) %> + <% end %> +
<%= t('note_index_item.value') %> <%= t('note_index_item.type') %> <%= t('note_index_item.reference') %> <%= t('note_index_item.reference_text') %>
+ <% else %> + <%= form.list_for(form["items"], "items[]") do |item| %> + <% form.emit_template("note_index_item", item) %> + <% end %> + <% end %> +
+
+
+
+<% end %> + +<% define_template "note_index_item_table", jsonmodel_definition(:note_index_item) do |form| %> + <% + # calling I18n.t thousands of times is slow - let's cache em + @type_enum ||= {} + @type_enum[form["type"]] ||= t('enums.note_index_item_type.' + form["type"]) if form["type"] + %> + + <%= form.hidden_input(:jsonmodel_type, "note_index_item") %> + <%= form.hidden_input("value", form["value"]) %> + <%= form.hidden_input("type", form["type"]) %> + <%= form.hidden_input("reference", form["reference"]) %> + <%= form.hidden_input("reference_text", form["reference_text"]) %> + + + <%= form["value"] %> + <%= @type_enum[form["type"]] %> + <%= form["reference"] %> + <%= form["reference_text"] %> + +<% end %>