diff --git a/views/shared/common/item-relations-form.php b/views/shared/common/item-relations-form.php
index 94617ad..8b689b1 100644
--- a/views/shared/common/item-relations-form.php
+++ b/views/shared/common/item-relations-form.php
@@ -18,110 +18,218 @@
- id;
- $colspan = ($provideRelationComments ? 4 : 3);
- $lastVocab = -1;
- foreach ($allRelations as $relation) {
- if ($lastVocab != $relation["vocabulary_id"]) {
- echo ""
- .""
- .$relation["vocabulary"]
- ." | |
";
- $lastVocab = $relation["vocabulary_id"];
- }
- $subjectRelation = ( $relation['subject_item_id']==$thisItemId );
- $objectRelation = ( $relation['object_item_id']==$thisItemId );
- echo "";
- echo "" .
- ( $subjectRelation ? __('This Item')
- : "".
- $relation['subject_item_title'] . ""
- ) .
- " | ";
- echo "";
+ id;
+ $colspan = ($provideRelationComments ? 4 : 3);
+ $lastVocab = -1;
+ foreach ($allRelations as $relation) {
+ if ($lastVocab != $relation['vocabulary_id']) {
+ echo " |
"
+ . ""
+ . $relation['vocabulary']
+ . " | |
";
+ $lastVocab = $relation['vocabulary_id'];
+ }
+ $subjectRelation = $relation['subject_item_id'] == $thisItemId;
+ $objectRelation = $relation['object_item_id'] == $thisItemId;
+ echo '';
+ echo ''
+ . ($subjectRelation
+ ? __('This Item')
+ : '' . $relation['subject_item_title'] . ''
+ )
+ . ' | ';
+ echo '';
if ($subjectRelation) {
- echo get_view()->formSelect('item_relations_subject_property['.$relation['item_relation_id'].']',
- $relation['relation_property'],
- array( 'id' => 'item_relations_subject_property_'.$relation['item_relation_id'],
- 'multiple' => false,
- 'style' => 'width: 150px;'),
- array_slice($formSelectProperties,1));
+ echo $this->formSelect('item_relations_subject_property[' . $relation['item_relation_id'] . ']',
+ $relation['relation_property'],
+ array(
+ 'id' => 'item_relations_subject_property_' . $relation['item_relation_id'],
+ 'multiple' => false,
+ 'style' => 'width: 150px;',
+ ),
+ array_slice($formSelectProperties, 1));
+ }
+ else {
+ echo '' . $relation['relation_text'] . '';
}
- else { echo "" . $relation['relation_text'] . ""; }
- echo " | ";
- echo "" .
- ( $objectRelation ? __('This Item')
- : "".
- $relation['object_item_title'] . ""
- ).
- " | ";
- if ($provideRelationComments) {
- echo "";
- if ($subjectRelation) { ?>
-
- ";
- }
- ?>
+ echo ' | ';
+ echo ''
+ . ($objectRelation
+ ? __('This Item')
+ : '' . $relation['object_item_title'] . ''
+ )
+ . ' | ';
+ if ($provideRelationComments) {
+ echo '';
+ if ($subjectRelation) { ?>
+
+ ';
+ } ?>
| |
";
- }
- /* */
- ?>
-
+ echo '
';
+ } ?>
+
+
+
+ |
+ |
+
|
- |
+
+ formSelect('item_relations_subject_property[]',
+ null,
+ array(
+ 'multiple' => false,
+ 'style' => 'width: 150px;',
+ ),
+ array_slice($formSelectProperties, 1));
+ ?>
+ |
. |
-
- |
-
-
-
-
- formSelect('new_relation_property_id',
- null, array('multiple' => false), $formSelectProperties); ?>
-
- formSelect('new_relation_object_item_type_id',
- null, array('multiple' => false), $itemTypesList); ?>
+
+
+
+ formLabel('new_relation_property_id', __('This Subject')); ?>
+
+
+ id) ? '' : 'data-subject-id="' . $item->id . '"'; ?>>id) ? __('[New]') : '#' . $item->id; ?>
+
+
+ id) ? '' : metadata('item', array('Dublin Core', 'Title')); ?>
+
+
+
+
+ formLabel('new_relation_property_id', __('Is Related By')); ?>
+
+
+ formSelect('new_relation_property_id',
+ null, array('multiple' => false), $formSelectProperties); ?>
+
+
+
+
+ formLabel('object_title', __('With Object')); ?>
+
+
+
+
+
+
+
+
-
:
-
-
+
+
+
+ formLabel('relation_comment', __('Comment')); ?>
+
+
+ formText('relation_comment', null); ?>
+
+
+
-
:
-
-
-
-
+
-
-
+
+
+
+
+
+
+ formLabel('new_relation_object_item_type_id', __('By Item Types')); ?>
+
+
+ formSelect('new_relation_object_item_type_id',
+ null, array('multiple' => false), $itemTypesList); ?>
+
+
+
+
+ formLabel('new_relation_object_collection_id', __('By Collection')); ?>
+
+
+ formSelect('new_relation_object_collection_id',
+ null, array('multiple' => false), get_table_options('Collection')); ?>
+
+
-
-
-
: formText('relation_comment', null, array('size' => 10, 'maxlength' => 60)); ?>
-
+
+
+ formLabel('partial_object_title', __('By Partial Title')); ?>
+
+
+ formText('partial_object_title', null, array('size' => 10, 'maxlength' => 60)); ?>
+
+
+
+
+
+ formLabel('new_relation_item_sort', __('Sort By')); ?>
+
+
+
+
+
+
-
+
diff --git a/views/shared/css/item-relations.css b/views/shared/css/item-relations.css
index 98cc848..525bb27 100644
--- a/views/shared/css/item-relations.css
+++ b/views/shared/css/item-relations.css
@@ -1,3 +1,10 @@
+.subject-id,
+.object-id {
+ font-style: italic;
+}
+tr.new {
+ background-color: #f3f3e7;
+}
.pg_disabled {
visibility: hidden;
}
diff --git a/views/shared/javascripts/item-relations.js b/views/shared/javascripts/item-relations.js
index 0aa677a..12fab58 100644
--- a/views/shared/javascripts/item-relations.js
+++ b/views/shared/javascripts/item-relations.js
@@ -2,15 +2,31 @@ jQuery(document).ready(function () {
var $ = jQuery;
var options = {};
+ init();
+
+ function init() {
+ resetOptions();
+
+ $('#new_relation_object_item_id').val('');
+ $('#object_id').html('');
+ $('#object_title').html('
' + '[Search and Select Below]' + '');
+ $('#new_relation_property_id').val('');
+ $('#relation_comment').val('');
+ $('#new_relation_object_item_type_id').val(-1);
+ $('#new_relation_object_collection_id').val('');
+ $('#partial_object_title').val('');
+ $('input[name=itemsListSort]:checked').val('timestamp');
+
+ updateChoices();
+ updateAddButton();
+ }
+
function resetOptions() {
- options['partial'] = '';
- options['item_type'] = -1;
- options['sort'] = 'mod_desc';
- options['page'] = 0;
- options['per_page'] = 15;
options = {
+ subject_id: $('#subject_id').attr('data-subject-id'),
partial: '',
item_type: -1,
+ collection: -1,
sort: 'mod_desc',
page: 0,
per_page: 15,
@@ -18,12 +34,10 @@ jQuery(document).ready(function () {
};
}
- resetOptions();
- updateChoices();
-
function updateChoices() {
options['partial'] = $('#partial_object_title').val();
options['item_type'] = $('#new_relation_object_item_type_id').val();
+ options['collection'] = $('#new_relation_object_collection_id').val();
if ($('input[name=itemsListSort]:checked').val() === 'timestamp') {
options['sort'] = 'mod_desc';
}
@@ -71,18 +85,93 @@ jQuery(document).ready(function () {
});
}
+ function updateAddButton() {
+ var addButton = $('#add-relation');
+ if ($('#new_relation_property_id').val() && $('#new_relation_object_item_id').val()) {
+ addButton.removeProp('disabled');
+ addButton.removeAttr('disabled');
+ }
+ else {
+ addButton.prop('disabled', true);
+ addButton.attr('disabled', true);
+ }
+ }
+
+ function updateNewRelationHiddenProperty() {
+ var entry = $(this).closest('tr.item-relations-entry');
+ var hiddenInput = entry.find(".item-relations-hidden input[name='item_relations_property_id[]']");
+ hiddenInput.val($(this).val());
+ };
+
+ function updateNewRelationHiddenComment() {
+ var entry = $(this).closest('tr.item-relations-entry');
+ var hiddenInput = entry.find(".item-relations-hidden input[name='item_relations_item_relation_relation_comment[]']");
+ hiddenInput.val($(this).val());
+ };
+
+ function deleteNewRelation() {
+ $(this).closest('tr.item-relations-entry').remove();
+ return false;
+ };
+
+ /* Edit existing relations. */
+
+ $("select[id^='item_relations_subject_property_']").change(function(e) {
+ e.preventDefault();
+ var id = this.id;
+ var suffix = this.id.match(/\d+/);
+ $("#item_relations_subject_property_" + suffix).siblings('span').remove();
+ $("#item_relations_subject_property_" + suffix).parent().append('
'
+ + ''
+ + '');
+ });
+
+ $("input[id^='item_relations_subject_comment_']").change(function(e) {
+ e.preventDefault();
+ var provideSubjectComments = ($("input[id^='item_relations_subject_comment_']").length > 0);
+ if (provideSubjectComments) {
+ var id = $(this).attr('id');
+ var suffix = this.id.match(/\d+/);
+ $("#item_relations_subject_comment_" + suffix).siblings('span').remove();
+ $("#item_relations_subject_comment_" + suffix).parent().append('
'
+ + ''
+ + '');
+ }
+ });
+
+ /* Add new relations. */
+
$('#add-relation').click(function () {
+ if ($('#add-relation').prop('disabled')) {
+ return false;
+ }
+
+ // Set visible row.
var oldRow = $('.item-relations-entry').last();
var newRow = oldRow.clone();
- var provideRelationComments = ($('#relation_comment').length > 0);
+ var provideRelationComments = ($('#relation_comment').length > 0);
newRow.toggleClass('hidden');
- newRow.find('.item-relations-property').html($('#new_relation_property_id').find(':selected').html());
+ newRow.find("select[name='item_relations_subject_property[]']").val($('#new_relation_property_id').val());
var new_url = newRow.find('.item-relations-object a').attr('href');
newRow.find('.item-relations-object a').attr('href', new_url + $('#new_relation_object_item_id').val());
newRow.find('.item-relations-object a').text($('#object_title').text());
- if (provideRelationComments) {
- newRow.find('.item-relations-comment').text($('#relation_comment').val());
- }
+ if (provideRelationComments) {
+ newRow.find("input[name='item_relations_subject_comment[]']").val($('#relation_comment').val());
+ }
+
+ // Set hidden row for data.
+ var hidden = _createHiddenNewRelation();
+ newRow.find('.item-relations-hidden').html(hidden);
+ oldRow.before(newRow);
+
+ $(".delete-new-relation").bind('click', deleteNewRelation);
+ $("select[name='item_relations_subject_property[]'").bind('change', updateNewRelationHiddenProperty);
+ $("input[name='item_relations_subject_comment[]'").bind('change', updateNewRelationHiddenComment);
+
+ init();
+ });
+
+ function _createHiddenNewRelation() {
var hidden = [];
hidden.push('
');
- if (provideRelationComments) {
- hidden.push('
');
- }
- newRow.find('.item-relations-hidden').html(hidden.join(''));
- oldRow.before(newRow);
- });
+ if ($('#relation_comment').length > 0) {
+ hidden.push('
');
+ }
+ return hidden.join('');
+ };
- $('#lookup-results').on('click', 'li', function () {
- $('#new_relation_object_item_id').val($(this).attr('data-value'));
- $('#object_title').html($(this).html());
- });
+ /* Search and select an object to create a new relation. */
- $('#selector-previous-page').click(function () {
- if (0 < options['page']) {
- options['page']--;
- updateChoices();
- }
+ $('#refresh-results').click(function () {
+ updateChoices();
});
- $('#selector-next-page').click(function () {
- if (options['page'] < options['max_page']) {
- options['page']++;
- updateChoices();
- }
+ $('#new_relation_object_item_type_id').change(function () {
+ updateChoices();
});
- $('#new_relation_object_item_type_id').change(function () {
+ $('#new_relation_object_collection_id').change(function () {
updateChoices();
});
@@ -134,26 +213,28 @@ jQuery(document).ready(function () {
updateChoices();
});
- $("input[id^='item_relations_subject_comment_']").change(function(e) {
- e.preventDefault();
- var provideSubjectComments = ($("input[id^='item_relations_subject_comment_']").length > 0);
- if (provideSubjectComments) {
- var id = $(this).attr('id');
- var suffix = this.id.match(/\d+/);
- $("#item_relations_subject_comment_"+suffix).siblings('span').remove();
- $("#item_relations_subject_comment_"+suffix).parent().append('
'+
- ''
- +'');
- }
+ $('#selector-previous-page').click(function () {
+ if (0 < options['page']) {
+ options['page']--;
+ updateChoices();
+ }
});
- $("select[id^='item_relations_subject_property_']").change(function(e) {
- e.preventDefault();
- var id = this.id;
- var suffix = this.id.match(/\d+/);
- $("#item_relations_subject_property_"+suffix).siblings('span').remove();
- $("#item_relations_subject_property_"+suffix).parent().append('
'+
- ''
- +'');
+ $('#selector-next-page').click(function () {
+ if (options['page'] < options['max_page']) {
+ options['page']++;
+ updateChoices();
+ }
+ });
+
+ $('#lookup-results').on('click', 'li', function () {
+ $('#new_relation_object_item_id').val($(this).attr('data-value'));
+ $('#object_id').html('
#' + $(this).attr('data-value') + '');
+ $('#object_title').html($(this).html());
+ updateAddButton();
+ });
+
+ $('#new_relation_property_id').change(function () {
+ updateAddButton();
});
-} );
+});