diff --git a/ItemRelationsPlugin.php b/ItemRelationsPlugin.php index 5ba2dd1..ca43fd1 100644 --- a/ItemRelationsPlugin.php +++ b/ItemRelationsPlugin.php @@ -616,9 +616,6 @@ public function filterAdminNavigationMain($nav) public function filterAdminItemsFormTabs($tabs, $args) { $item = $args['item']; - echo ""; $tabs['Item Relations'] = get_view()->itemRelationsForm($item); return $tabs; } diff --git a/controllers/LookupController.php b/controllers/LookupController.php index aa0fec9..8c56191 100644 --- a/controllers/LookupController.php +++ b/controllers/LookupController.php @@ -137,4 +137,56 @@ public function indexAction() $this->_helper->json($metadata); } + + public function listItemTypesAction() + { + $itemTypesList = array( + '' => '- ' . __('All') . ' -', + ); + $itemTypesList += $this->_getUsedItemTypes(); + // Convert to a pseudo-associative array to keep order of ids. + $json = array( + 'id' => array_keys($itemTypesList), + 'label' => array_values($itemTypesList), + ); + $this->_helper->json($json); + } + + public function listCollectionsAction() + { + $collections = get_table_options('Collection'); + // Convert to a pseudo-associative array to keep order of ids. + $json = array( + 'id' => array_keys($collections), + 'label' => array_values($collections), + ); + $this->_helper->json($json); + } + + /** + * Get the list of used item types for select form. + * + * @return array + */ + protected function _getUsedItemTypes() + { + $db = get_db(); + + $itemTypesTable = $db->getTable('ItemType'); + $itemTypesAlias = $itemTypesTable->getTableAlias(); + + $select = $itemTypesTable->getSelect() + ->reset(Zend_Db_Select::COLUMNS) + ->from(array(), array($itemTypesAlias . '.id', $itemTypesAlias . '.name')) + ->joinInner(array('items' => $db->Item), "items.item_type_id = $itemTypesAlias.id", array()) + ->group($itemTypesAlias . '.id') + ->order($itemTypesAlias . '.name ASC'); + + $permissions = new Omeka_Db_Select_PublicPermissions('Items'); + $permissions->apply($select, 'items'); + + $itemTypes = $db->fetchPairs($select); + + return $itemTypes; + } } diff --git a/views/helpers/ItemRelationsForm.php b/views/helpers/ItemRelationsForm.php index a08b037..768347c 100644 --- a/views/helpers/ItemRelationsForm.php +++ b/views/helpers/ItemRelationsForm.php @@ -15,18 +15,11 @@ public function itemRelationsForm($item) $view = $this->view; $db = get_db(); - // Prepare list of used item types for the select form. - $itemTypesList = array( - '-1' => '- ' . __('All') . ' -', - ); - $itemTypesList += $this->_getUsedItemTypes(); - $html = $view->partial('common/item-relations-form.php', array( 'item' => $item, 'provideRelationComments' => get_option('item_relations_provide_relation_comments'), 'formSelectProperties' => get_table_options('ItemRelationsProperty'), 'allRelations' => ItemRelationsPlugin::prepareAllRelations($item), - 'itemTypesList' => $itemTypesList, )); if (!defined("LITYLOADED")) { @@ -35,36 +28,12 @@ public function itemRelationsForm($item) DEFINE("LITYLOADED", 1); } $html .= ''; - $html .= ''; + $html .= ''; $html .= js_tag('item-relations'); return $html; } - - /** - * Get the list of used item types for select form. - * - * @return array - */ - protected function _getUsedItemTypes() - { - $db = get_db(); - - $itemTypesTable = $db->getTable('ItemType'); - $itemTypesAlias = $itemTypesTable->getTableAlias(); - - $select = $itemTypesTable->getSelect() - ->reset(Zend_Db_Select::COLUMNS) - ->from(array(), array($itemTypesAlias . '.id', $itemTypesAlias . '.name')) - ->joinInner(array('items' => $db->Item), "items.item_type_id = $itemTypesAlias.id", array()) - ->group($itemTypesAlias . '.id') - ->order($itemTypesAlias . '.name ASC'); - - $permissions = new Omeka_Db_Select_PublicPermissions('Items'); - $permissions->apply($select, 'items'); - - $itemTypes = $db->fetchPairs($select); - - return $itemTypes; - } } diff --git a/views/shared/common/item-relations-form.php b/views/shared/common/item-relations-form.php index 423423a..eb2315b 100644 --- a/views/shared/common/item-relations-form.php +++ b/views/shared/common/item-relations-form.php @@ -181,7 +181,7 @@
formSelect('new_relation_object_item_type_id', - null, array('multiple' => false), $itemTypesList); ?> + null, array('multiple' => false), array()); ?>
@@ -190,7 +190,7 @@
formSelect('new_relation_object_collection_id', - null, array('multiple' => false), get_table_options('Collection')); ?> + null, array('multiple' => false), array()); ?>
diff --git a/views/shared/javascripts/item-relations.js b/views/shared/javascripts/item-relations.js index a2daf54..213a12f 100644 --- a/views/shared/javascripts/item-relations.js +++ b/views/shared/javascripts/item-relations.js @@ -83,6 +83,36 @@ jQuery(document).ready(function () { } } }); + + // Update the list of item types. + $.ajax({ + url: url + 'list-item-types', + dataType: 'json', + success: function (data) { + _loadList('select#new_relation_object_item_type_id', data); + } + }); + + // Update the list of collections. + $.ajax({ + url: url + 'list-collections', + dataType: 'json', + success: function (data) { + _loadList('select#new_relation_object_collection_id', data); + } + }); + } + + function _loadList(element, data) { + var currentValue = $(element).val(); + $(element).empty(); + $.each(data['id'], function(i, id) { + $(element).append( + $('') + .val(id) + .html(data['label'][i])); + }); + $(element).val(currentValue); } function updateAddButton() {