Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions ItemRelationsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,6 @@ public function filterAdminNavigationMain($nav)
public function filterAdminItemsFormTabs($tabs, $args)
{
$item = $args['item'];
echo "<script>
var itemRelationsSearchAndSelect = '".__('[Search and Select Below]')."';
</script>";
$tabs['Item Relations'] = get_view()->itemRelationsForm($item);
return $tabs;
}
Expand Down
52 changes: 52 additions & 0 deletions controllers/LookupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
39 changes: 4 additions & 35 deletions views/helpers/ItemRelationsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -35,36 +28,12 @@ public function itemRelationsForm($item)
DEFINE("LITYLOADED", 1);
}
$html .= '<link href="' . css_src('item-relations') . '" rel="stylesheet">';
$html .= '<script type="text/javascript">var url = ' . json_encode(url('item-relations/lookup/')) . '</script>';
$html .= '<script type="text/javascript">';
$html .= 'var url = ' . json_encode(url('item-relations/lookup/')) . ';';
$html .= 'var itemRelationsSearchAndSelect = ' . json_encode(__('[Search and Select Below]')) . ';';
$html .= '</script>';
$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;
}
}
4 changes: 2 additions & 2 deletions views/shared/common/item-relations-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
</div>
<div class="inputs nine columns omega">
<?php echo $this->formSelect('new_relation_object_item_type_id',
null, array('multiple' => false), $itemTypesList); ?>
null, array('multiple' => false), array()); ?>
</div>
</div>
<div class="field">
Expand All @@ -190,7 +190,7 @@
</div>
<div class="inputs nine columns omega">
<?php echo $this->formSelect('new_relation_object_collection_id',
null, array('multiple' => false), get_table_options('Collection')); ?>
null, array('multiple' => false), array()); ?>
</div>
</div>

Expand Down
30 changes: 30 additions & 0 deletions views/shared/javascripts/item-relations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
$('<option></option>')
.val(id)
.html(data['label'][i]));
});
$(element).val(currentValue);
}

function updateAddButton() {
Expand Down