Skip to content

Commit

Permalink
Updated batch edit for Omeka S 1.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed May 27, 2018
1 parent 93e1ea4 commit d8bbd6e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
12 changes: 7 additions & 5 deletions asset/js/zotero-import.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Kept for compatibility with Omeka < 1.2.
Omeka.zoteroImportManageSelectedActions = function() {
var selectedOptions = $('[value="update-selected"], [value="delete-selected"], #batch-form .batch-inputs [data-select=selected]');
var selectedOptions = $('[value="update-selected"], [value="delete-selected"], #batch-form .batch-inputs .batch-selected');
if ($('.batch-edit td input[type="checkbox"]:checked').length > 0) {
selectedOptions.removeAttr('disabled');
} else {
Expand All @@ -15,23 +16,24 @@ Omeka.zoteroImportManageSelectedActions = function() {

var batchSelect = $('#batch-form .batch-actions-select');
batchSelect.append(
$('<option data-select="selected" disabled="disabled"></option>').val('zotero-selected').html(Omeka.jsTranslate('Export selected to Zotero'))
$('<option class="batch-selected" disabled></option>').val('zotero-selected').html(Omeka.jsTranslate('Export selected to Zotero'))
);
batchSelect.append(
$('<option data-select="all"></option>').val('zotero-all').html(Omeka.jsTranslate('Export all to Zotero'))
$('<option></option>').val('zotero-all').html(Omeka.jsTranslate('Export all to Zotero'))
);
var batchActions = $('#batch-form .batch-actions');
batchActions.append(
$('<input type="submit" class="zotero-selected" name="zotero_selected" formaction="zotero/export">').val(Omeka.jsTranslate('Go'))
$('<input type="submit" class="zotero-selected" formaction="zotero/export">').val(Omeka.jsTranslate('Go'))
);
batchActions.append(
$('<input type="submit" class="zotero-all" name="zotero_all" formaction="zotero/export">').val(Omeka.jsTranslate('Go'))
$('<input type="submit" class="zotero-all" formaction="zotero/export">').val(Omeka.jsTranslate('Go'))
);
var resourceType = window.location.pathname.split("/").pop();
batchActions.append(
$('<input type="hidden" name="resource_type">').val(resourceType)
);

// Kept for compatibility with Omeka < 1.2.
$('.select-all').change(function() {
Omeka.zoteroImportManageSelectedActions();
});
Expand Down
13 changes: 10 additions & 3 deletions src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ public function exportAction()
{
if ($this->getRequest()->isGet()) {
$params = $this->params()->fromQuery();
}
elseif ($this->getRequest()->isPost()) {
} elseif ($this->getRequest()->isPost()) {
$params = $this->params()->fromPost();
} else {
return $this->redirect()->toRoute('admin');
Expand All @@ -140,8 +139,12 @@ public function exportAction()
}

$resource = $resourceTypeMap[$resourceType];
$resourceIds = $params['resource_ids'] ?: [];
$resourceIds = $params['resource_ids']
? (is_array($params['resource_ids']) ? $params['resource_ids'] : explode(',', $params['resource_ids']))
: [];
$params['resource_ids'] = $resourceIds;
$selectAll = $params['batch_action'] ? $params['batch_action'] === 'zotero-all' : (bool) $params['zotero_all'];
$params['batch_action'] = $selectAll ? 'zotero-all' : 'zotero-selected';

$query = null;
$resources = [];
Expand Down Expand Up @@ -298,6 +301,10 @@ public function exportAction()
}

$this->messenger()->addFormErrors($form);
} else {
// Keep hidden the values from the browse page.
$params['resource_ids'] = implode(',', $params['resource_ids']);
$form->setData($params);
}

$view = new ViewModel;
Expand Down
17 changes: 17 additions & 0 deletions src/Form/ExportForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ class ExportForm extends Form
{
public function init()
{
$this->add([
'name' => 'batch_action',
'type' => Element\Hidden::class,
]);
$this->add([
'name' => 'resource_type',
'type' => Element\Hidden::class,
]);
$this->add([
'name' => 'resource_ids',
'type' => Element\Hidden::class,
]);
$this->add([
'name' => 'query',
'type' => Element\Hidden::class,
]);

$this->add([
'name' => 'type',
'type' => Element\Radio::class,
Expand Down
7 changes: 0 additions & 7 deletions view/zotero-import/index/export.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ $this->htmlElement('body')->appendAttribute('class', 'zotero export items');

<?php echo $this->form()->openTag($form); ?>

<input type="hidden" name="batch_action" value="<?php echo $selectAll ? 'zotero-all' : 'zotero-selected'; ?>">
<input type="hidden" name="resource_type" value="<?php echo $resourceType; ?>">
<?php foreach ($resourceIds as $resourceId): ?>
<input type="hidden" name="resource_ids[]" value="<?php echo $resourceId; ?>">
<?php endforeach; ?>
<input type="hidden" name="query" value="<?php echo $this->escapeHtml(json_encode($query, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); ?>">

<div id="page-actions">
<input type="submit" name="batch_process" value="<?php echo $this->escapeHtml($translate('Export')); ?>">
</div>
Expand Down

0 comments on commit d8bbd6e

Please sign in to comment.