FEATURE: Adding existing documents now works

This commit is contained in:
Andrew O'Neil 2012-08-07 14:42:03 +12:00
parent 9e9cc995b3
commit 0e65cb2f1e
2 changed files with 18 additions and 2 deletions

View File

@ -160,13 +160,21 @@ class DMSDocumentAddController extends LeftAndMain {
$return = array();
foreach($data as $doc) {
$return[] = $doc->ID . ' - ' . $doc->Title;
$return[] = array(
'label' => $doc->ID . ' - ' . $doc->Title,
'value' => $doc->ID
);
}
return json_encode($return);
}
public function linkdocument() {
$page = $this->currentPage();
$document = DataObject::get_by_id('DMSDocument', (int) $_GET['documentID']);
$document->addPage($page);
}
}

View File

@ -2,7 +2,15 @@
$('.document-add-existing .document-autocomplete').entwine({
onmatch: function() {
$(this).autocomplete({
source: 'admin/pages/adddocument/documentautocomplete'
source: 'admin/pages/adddocument/documentautocomplete',
select: function(event, ui) {
if(ui.item) {
var page_id = $(this).closest('form').find(':input[name=ID]').val();
var document_id = ui.item.value;
jQuery.ajax('admin/pages/adddocument/linkdocument?ID=' + page_id + '&documentID=' + document_id);
}
}
});
}
});