FEATURE: Autocomplete for add document

This commit is contained in:
Andrew O'Neil 2012-08-07 13:44:42 +12:00
parent 5025813d09
commit e30a34eedb
4 changed files with 30 additions and 1 deletions

View File

@ -151,6 +151,22 @@ class DMSDocumentAddController extends LeftAndMain {
return singleton('CMSPagesController')->Link().'edit/show/'.$pageID; return singleton('CMSPagesController')->Link().'edit/show/'.$pageID;
} }
public function documentautocomplete() {
$term = $_GET['term'];
$term_sql = Convert::raw2sql($term);
$data = DataList::create('DMSDocument');
$data->where("(\"ID\" LIKE '%$term_sql%' OR \"Filename\" LIKE '%$term_sql%' OR \"Title\" LIKE '%$term_sql%')");
$data->limit(20);
$return = array();
foreach($data as $doc) {
$return[] = $doc->ID . ' - ' . $doc->Title;
}
return json_encode($return);
}
} }

View File

@ -30,6 +30,8 @@ class DMSDocumentAddExistingField extends FormField {
} }
public function Field($properties = array()) { public function Field($properties = array()) {
Requirements::javascript('dms/javascript/DMSDocumentAddExistingField.js');
return $this->renderWith('DMSDocumentAddExistingField'); return $this->renderWith('DMSDocumentAddExistingField');
} }
} }

View File

@ -0,0 +1,9 @@
(function($) {
$('.document-add-existing .document-autocomplete').entwine({
onmatch: function() {
$(this).autocomplete({
source: 'admin/pages/adddocument/documentautocomplete'
});
}
});
}(jQuery));

View File

@ -1,4 +1,4 @@
<div class="field"> <div class="document-add-existing field">
<h3> <h3>
<span class="step-label"> <span class="step-label">
@ -6,6 +6,8 @@
<span class="title">Link a Document</span> <span class="title">Link a Document</span>
</span> </span>
</h3> </h3>
<input class="document-autocomplete" placeholder="Search by ID or filename" />
</div> </div>
<div> <div>