venice-dynamo-rewrite/venice-data/scripts/find_communities.js
2003-05-31 05:01:48 +00:00

155 lines
5.6 KiB
JavaScript

// The contents of this file are subject to the Mozilla Public License Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
// WARRANTY OF ANY KIND, either express or implied. See the License for the specific
// language governing rights and limitations under the License.
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
importPackage(java.lang);
importClass(Packages.com.silverwrist.dynamo.Namespaces);
importPackage(Packages.com.silverwrist.dynamo.iface);
importPackage(Packages.com.silverwrist.dynamo.util);
importClass(Packages.com.silverwrist.venice.CommunitySearchField);
importClass(Packages.com.silverwrist.venice.SearchMode);
importClass(Packages.com.silverwrist.venice.VeniceNamespaces);
importPackage(Packages.com.silverwrist.venice.community);
importPackage(Packages.com.silverwrist.venice.content);
importPackage(Packages.com.silverwrist.venice.iface);
req = bsf.lookupBean("request"); // get request
rhelp = bsf.lookupBean("request_help"); // get request helper
session = rhelp.getSession(); // get the session
user = vlib.getUser(session); // get user
// Tell the session we visited this page last.
session.setObject("/find.js.vs","last.visited","find_communities.js.vs");
// Get the user's configured page size.
pagesize = cast.toInteger(user.getObject(VeniceNamespaces.USER_SETTINGS_NAMESPACE,"search.result.count"));
// Get the "use categories" flag.
globals = vcast.getGlobalPropertiesStore(req);
opts = cast.toOptionSet(globals.getObject(VeniceNamespaces.COMMUNITY_GLOBALS_NAMESPACE,"options"));
use_categories = opts.get(0);
field = CommunitySearchField.NAME;
mode = SearchMode.PREFIX;
term = "";
ofs = 0;
fcount = -1;
results = null;
category = null;
rc = null;
if (rhelp.isVerb("POST"))
{ // Read the form parameters
field = CommunitySearchField.getEnum(rhelp.getParameter("field"));
mode = SearchMode.getEnum(rhelp.getParameter("mode"));
term = rhelp.getParameter("term");
ofs = rhelp.getParameterInt("ofs",0);
fcount = rhelp.getParameterInt("fcount",-1);
if (use_categories && rhelp.hasParameter("cat"))
{ // get the current category
catsvc = vcast.queryCategoryService(rhelp.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"categories"));
category = catsvc.getCategory(rhelp.getParameterInt("cat",-1));
} // end if
// Adjust offset based on the button that was clicked.
if (rhelp.isImageButtonClicked("search"))
{ // beginning of a new search
ofs = 0;
fcount = -1;
} // end if
else if (rhelp.isImageButtonClicked("previous"))
ofs = Math.max(ofs - pagesize,0);
else if (rhelp.isImageButtonClicked("next"))
ofs += pagesize;
// Get the community service object.
commsvc = vcast.queryCommunityService(rhelp.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"communities"));
try
{ // search for communities!
if (category!=null)
{ // look in the category
if (fcount<0)
fcount = commsvc.getNumCommunitiesInCategory(user,category);
results = commsvc.getCommunitiesInCategory(user,category,ofs,pagesize);
} // end if
else
{ // do a normal search
if (fcount<0)
fcount = commsvc.getSearchCommunityCount(user,field,mode,term);
results = commsvc.searchForCommunities(user,field,mode,term,ofs,pagesize);
} // end else
} // end try
catch (e)
{ // exception thrown
rc = new ErrorBox("Database Error",e,"SERVLET","find_communities.js.vs");
} // end catch
} // end if
else if (use_categories)
{ // get the category we're loading
catsvc = vcast.queryCategoryService(rhelp.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"categories"));
commsvc = vcast.queryCommunityService(rhelp.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"communities"));
try
{ // get the category and listings
category = catsvc.getCategory(rhelp.getParameterInt("cat",-1));
fcount = commsvc.getNumCommunitiesInCategory(user,category);
results = commsvc.getCommunitiesInCategory(user,category,0,pagesize);
if (results.isEmpty())
results = null;
} // end try
catch (e)
{ // exception thrown
rc = new ErrorBox("Database Error",e,"SERVLET","find_communities.js.vs");
} // end catch
} // end else
if (rc==null)
{ // create the VelocityView for the output
rc = new VelocityView("Find Communities","find_communities.vm");
rc.setParameter("field",field.getName());
rc.setParameter("mode",mode.getName());
rc.setParameter("term",term.toString());
rc.setParameter("ofs",cast.toIntegerObject(ofs));
rc.setParameter("fcount",cast.toIntegerObject(fcount));
rc.setParameter("pagesize",cast.toIntegerObject(pagesize));
if (category!=null)
rc.setParameter("category",category);
if (results!=null)
rc.setParameter("results",results);
// Load the profile menu.
mprov = vcast.queryMenuProvider(rhelp.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"venice-menus"));
menu = mprov.getInlineMenu(user,VeniceNamespaces.CONTENT_LAF_NAMESPACE,"find.menu",cast.newIntArray(0));
ndx = menu.getItemContainingLinkText("find_communities.js.vs");
menu.setSelectedIndex(ndx);
if (use_categories)
menu.setVariable("use_categories",Boolean.TRUE);
rc.setParameter("menu",menu);
} // end if
dynamo.scriptOutput(rc);