Skip to content

Commit 74030a8

Browse files
committed
add duration to extent types and add time based fields
1 parent 6e381b6 commit 74030a8

File tree

6 files changed

+140
-1
lines changed

6 files changed

+140
-1
lines changed

frontend/assets/extent_duration.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
$(function() {
2+
3+
var initExtentForm = function(subform) {
4+
5+
var $that = $("[name$='[extent_type]']", subform);
6+
if ($that.val() === 'duration') {
7+
8+
var values = {};
9+
10+
if ($(".extent-subform", subform).length) {
11+
values = $(".extent-subform", subform).serializeObject();
12+
$(".extent-subform", subform).remove();
13+
}
14+
15+
var index = $that.parents("[data-index]:first").data("index");
16+
17+
var template_data = {
18+
path: AS.quickTemplate($that.parents("[data-name-path]:first").data("name-path"), {index: index}),
19+
id_path: AS.quickTemplate($that.parents("[data-id-path]:first").data("id-path"), {index: index}),
20+
index: index
21+
};
22+
23+
var template_name = 'template_extent_duration';
24+
25+
var $extent_subform = $(AS.renderTemplate(template_name, template_data));
26+
27+
$that.parents(".control-group:first").after($extent_subform);
28+
29+
$extent_subform.setValuesFromObject(values);
30+
31+
};
32+
33+
34+
$("[name$='[extent_type]']", subform).change(function(event) {
35+
var type = $(this).val();
36+
37+
var values = {};
38+
39+
if ($(".extent-subform", subform).length) {
40+
values = $(".extent-subform", subform).serializeObject();
41+
$(".extent-subform", subform).remove();
42+
}
43+
44+
var index = $(this).parents("[data-index]:first").data("index");
45+
46+
var template_data = {
47+
path: AS.quickTemplate($(this).parents("[data-name-path]:first").data("name-path"), {index: index}),
48+
id_path: AS.quickTemplate($(this).parents("[data-id-path]:first").data("id-path"), {index: index}),
49+
index: index
50+
};
51+
52+
var template_name = (type === 'duration') ? "template_extent_duration" : "template_extent_number";
53+
54+
var $extent_subform = $(AS.renderTemplate(template_name, template_data));
55+
56+
$(this).parents(".control-group:first").after($extent_subform);
57+
58+
$extent_subform.setValuesFromObject(values);
59+
60+
$(document).triggerHandler("subrecordcreated.aspace", ["extent_type", $extent_subform]);
61+
});
62+
};
63+
64+
65+
$(document).bind("subrecordcreated.aspace", function(event, object_name, subform) {
66+
if (object_name === "extent") {
67+
initExtentForm($(subform));
68+
}
69+
});
70+
71+
});

frontend/locales/en.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ en:
44
label: AV Space
55
enumerations:
66
container_type:
7-
video_cartridge : Video Cartridge
7+
video_cartridge: Video Cartridge
88
videocassette: Videocassette
99
videodisc: Videodisc
1010
videotape_reel: Videotape Reel
1111
other: Other
12+
extent_extent_type:
13+
duration: Duration
14+
extent_duration:
15+
hours: Hours
16+
minutes: Minutes
17+
seconds: Seconds
18+
extent_number:
19+
number: Number
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<% define_template "extent", jsonmodel_definition(:extent) do |form| %>
2+
<div class="subrecord-form-fields">
3+
<%= form.label_and_select("portion", form.possible_options_for("portion", true)) %>
4+
<%= form.label_and_select("extent_type", form.possible_options_for("extent_type", true)) %>
5+
<%form.emit_template("extent_number") %>
6+
<hr/>
7+
<%= form.label_and_textarea("container_summary") %>
8+
<%= form.label_and_textarea("physical_details") %>
9+
<%= form.label_and_textarea("dimensions") %>
10+
</div>
11+
<% end %>
12+
13+
<% define_template "extent_number", jsonmodel_definition(:extent) do |form| %>
14+
<div class="inline-subform extent-subform">
15+
<%= form.label_and_textfield("number") %>
16+
<%= form.hidden_input("hours") %>
17+
<%= form.hidden_input("minutes") %>
18+
<%= form.hidden_input("seconds") %>
19+
</div>
20+
<% end %>
21+
22+
23+
<% define_template "extent_duration", jsonmodel_definition(:extent) do |form| %>
24+
<div class="inline-subform extent-subform">
25+
<%= form.label_and_textfield("hours") %>
26+
<%= form.label_and_textfield("minutes") %>
27+
<%= form.label_and_textfield("seconds") %>
28+
<%= form.hidden_input("number") %>
29+
</div>
30+
<% end %>

frontend/views/layout_head.html.erb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<% if ['accessions', 'resources', 'archival_objects', 'digital_objects', 'digital_object_components'].include?(controller.controller_name) && ['edit', 'new', 'create'].include?(controller.action_name) %>
2+
<%= javascript_include_tag "#{@base_url}/assets/extent_duration.js" %>
3+
<% end %>
4+

migrations/002_add_extent_duration.rb

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Sequel.migration do
2+
3+
4+
up do
5+
6+
enum_id = self[:enumeration].filter(:name => 'extent_extent_type').select(:id)
7+
8+
id = self[:enumeration_value].insert(:enumeration_id => enum_id, :value => "duration", :readonly => 0)
9+
10+
alter_table(:extent) do
11+
add_column(:hours, String, :null => true)
12+
add_column(:minutes, String, :null => true)
13+
add_column(:seconds, String, :null => true)
14+
15+
set_column_allow_null :number
16+
end
17+
18+
end
19+
end
20+

schemas/extent_ext.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"hours" => {"type" => "string", "required" => false},
3+
"minutes" => {"type" => "string", "required" => false},
4+
"seconds" => {"type" => "string", "required" => false},
5+
"number" => {"type" => "string", "maxLength" => 255, "minLength" => 1, "required" => false, "ifmissing" => nil}
6+
}

0 commit comments

Comments
 (0)