mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-06-16 01:31:39 +02:00
FEATURE: Autocomplete for add document
This commit is contained in:
parent
5025813d09
commit
e30a34eedb
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
9
javascript/DMSDocumentAddExistingField.js
Normal file
9
javascript/DMSDocumentAddExistingField.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
(function($) {
|
||||||
|
$('.document-add-existing .document-autocomplete').entwine({
|
||||||
|
onmatch: function() {
|
||||||
|
$(this).autocomplete({
|
||||||
|
source: 'admin/pages/adddocument/documentautocomplete'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}(jQuery));
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user