Skip to content

Commit

Permalink
Issue #26 Content Path Auto-Suggest
Browse files Browse the repository at this point in the history
Added the ability to have the autosuggest on the content paths.

Currently does not work for cloned paths.

Closes #26
  • Loading branch information
Zoramite committed Jun 10, 2010
1 parent a3e41d0 commit 88c95e4
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions content/config/plugin.json.cfm
Expand Up @@ -8,6 +8,7 @@
"parserTWiki": "cf-compendium.inc.resource.parse.parseTWiki"
},
"applicationTransients": {
"apiContentForContent": "plugins.content.inc.api.apiContent",
"cacheContentForContent": "cf-compendium.inc.resource.storage.cache",
"modAttributeForContent": "plugins.content.inc.model.modAttribute",
"modAttributeOptionForContent": "plugins.content.inc.model.modAttributeOption",
Expand Down
2 changes: 2 additions & 0 deletions content/extend/admin/content/content/procEdit.cfm
Expand Up @@ -36,3 +36,5 @@

<cfset theURL.redirectRedirect() />
</cfif>

<cfset template.addScripts('../plugins/content/script/contentEdit.js') />
25 changes: 25 additions & 0 deletions content/inc/api/apiContent.cfc
@@ -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();
}
}
3 changes: 3 additions & 0 deletions content/inc/service/servContent.cfc
Expand Up @@ -344,6 +344,9 @@
<cfelseif structKeyExists(arguments.filter, 'alongPath')>
<!--- Find any content along the path --->
AND LOWER(p."path") IN (<cfqueryparam cfsqltype="cf_sql_varchar" value="#lcase(createPathList(cleanPath(arguments.filter.alongPath)))#" list="true" />)
<cfelseif structKeyExists(arguments.filter, 'searchPath')>
<!--- Match a path part --->
AND LOWER(p."path") LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#lcase(arguments.filter.searchPath)#%" />
<cfelseif structKeyExists(arguments.filter, 'path')>
<!--- Match a specific path --->
AND LOWER(p."path") = <cfqueryparam cfsqltype="cf_sql_varchar" value="#lcase(cleanPath(arguments.filter.path))#" />
Expand Down
59 changes: 59 additions & 0 deletions content/script/contentEdit.js
@@ -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);

0 comments on commit 88c95e4

Please sign in to comment.