-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
64 changes: 64 additions & 0 deletions
64
frontend/views/_top_of_basic_information_resource.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<% define_final_template "note_index", jsonmodel_definition(:note_index) do |form| %> | ||
<div class="subrecord-form-fields" data-type="note_index"> | ||
<h3 class="subrecord-form-heading"><%= I18n.t("note.note_index") %></h3> | ||
<div class="subrecord-form-container"> | ||
<%= 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"]) %> | ||
|
||
<section class="subrecord-form"> | ||
<h4 class="subrecord-form-heading"> | ||
<%= I18n.t("note_index.items") %> | ||
<% if not form.readonly? %> | ||
<button class="btn btn-xs btn-default pull-right add-item-btn"><%= I18n.t("note._frontend.action.add_note_index_item") %></button> | ||
<% end %> | ||
</h4> | ||
<div class="subrecord-form-container"> | ||
|
||
<% if form["items"] && form["items"].count > AppConfig[:large_index_notes_threshold] %> | ||
<table class="table table-striped table-bordered table-condensed"> | ||
<tr> | ||
<th> <%= t('note_index_item.value') %> </th> | ||
<th> <%= t('note_index_item.type') %> </th> | ||
<th> <%= t('note_index_item.reference') %> </th> | ||
<th> <%= t('note_index_item.reference_text') %> </th> | ||
</tr> | ||
|
||
<%= form.list_for(form["items"], "items[]") do |item| %> | ||
<% form.emit_template("note_index_item_table", item) %> | ||
<% end %> | ||
</table> | ||
<% else %> | ||
<%= form.list_for(form["items"], "items[]") do |item| %> | ||
<% form.emit_template("note_index_item", item) %> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
</section> | ||
</div> | ||
</div> | ||
<% 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"]) %> | ||
|
||
<tr> | ||
<td> <%= form["value"] %> </td> | ||
<td style="white-space:nowrap;"> <%= @type_enum[form["type"]] %> </td> | ||
<td> <%= form["reference"] %> </td> | ||
<td width="50%"> <%= form["reference_text"] %> </td> | ||
</tr> | ||
<% end %> |