Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ability to have the autosuggest on the content paths. Currently does not work for cloned paths. Closes #26
- Loading branch information
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
component extends="plugins.api.inc.resource.base.api" { | ||
public component function searchPath() { | ||
var i = ''; | ||
var filter = {}; | ||
var servContent = ''; | ||
var results = ''; | ||
|
||
// Validate required arguments | ||
if( !structKeyExists(variables.apiRequestBody, 'path') ) { | ||
throw('validation', 'Missing search path', 'The search requires a path'); | ||
} | ||
|
||
filter.searchPath = variables.apiRequestBody.path; | ||
|
||
servContent = variables.transport.theApplication.factories.transient.getServContentForContent(variables.transport.theApplication.managers.singleton.getApplication().getDSUpdate(), variables.transport); | ||
|
||
// Retrieve the search results | ||
variables.apiResponseBody = servContent.getPaths( filter ); | ||
|
||
// Send back some of the request | ||
variables.apiResponseHead['path'] = variables.apiRequestBody.path; | ||
|
||
return getApiResponse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* | ||
*/ | ||
;(function($){ | ||
$(function(){ | ||
// Setup a cache for the search terms | ||
var searchCache = {}; | ||
|
||
// Find the path form fields | ||
paths = $('input[name^=path]'); | ||
|
||
paths.autocomplete({ | ||
source: function(request, response) { | ||
// Check if the term has already been searched for | ||
if ( request.term in searchCache ) { | ||
response( searchCache[ request.term ] ); | ||
|
||
return; | ||
} | ||
|
||
$.ajax({ | ||
url: $.algid.admin.options.base.url + $.algid.admin.options.base.api, | ||
dataType: 'json', | ||
type: 'post', | ||
data: { | ||
HEAD: JSON.stringify({ | ||
plugin: 'content', | ||
service: 'content', | ||
action: 'searchPath' | ||
}), | ||
BODY: JSON.stringify({ | ||
path: request.term | ||
}) | ||
}, | ||
success: function( data ) { | ||
if(data.HEAD.result) { | ||
// Convert for use with the autocomplete | ||
for(var i = 0; i < data.BODY.length; i++) { | ||
data.BODY[i].value = data.BODY[i].path; | ||
data.BODY[i].label = data.BODY[i].path; | ||
} | ||
|
||
searchCache[ request.term ] = data.BODY; | ||
|
||
window.console.log(data.BODY); | ||
|
||
response( data.BODY ); | ||
} else { | ||
window.console.error(data.HEAD.errors); | ||
|
||
response( [] ); | ||
} | ||
} | ||
}); | ||
}, | ||
minLength: 0 | ||
}); | ||
}); | ||
})(jQuery); |