From 7a187e6a9aa8ec925f82d02e9f8e71010f686edc Mon Sep 17 00:00:00 2001 From: Gavin Cornwell Date: Fri, 26 Jan 2007 15:26:59 +0000 Subject: [PATCH] - Updated OpenSearch UI after Linton review - Multiple OpenSearch clients can now be added to a single page - Configured OpenSearch as a dashlet - Made the lookup for beans in portal session more rigorous for AJAX invoke command - Updated paging graphics git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4942 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/messages/webclient.properties | 5 +- config/alfresco/web-api-config.xml | 2 +- config/alfresco/web-client-config.xml | 2 + .../web/app/servlet/ajax/InvokeCommand.java | 20 +- .../ui/common/component/data/UIDataPager.java | 6 +- .../web/ui/repo/component/UIOpenSearch.java | 56 +- source/web/css/main.css | 2 +- source/web/css/opensearch.css | 49 +- source/web/images/icons/FirstPage.gif | Bin 330 -> 582 bytes .../images/icons/FirstPage_unavailable.gif | Bin 327 -> 374 bytes source/web/images/icons/LastPage.gif | Bin 332 -> 583 bytes .../web/images/icons/LastPage_unavailable.gif | Bin 330 -> 373 bytes source/web/images/icons/NextPage.gif | Bin 188 -> 361 bytes .../web/images/icons/NextPage_unavailable.gif | Bin 289 -> 357 bytes source/web/images/icons/PreviousPage.gif | Bin 287 -> 359 bytes .../images/icons/PreviousPage_unavailable.gif | Bin 188 -> 355 bytes .../web/images/icons/opensearch_controls.gif | Bin 0 -> 317 bytes source/web/images/parts/os-background.gif | Bin 1685 -> 0 bytes .../jsp/dashboards/dashlets/opensearch.jsp | 22 + source/web/jsp/sidebar/opensearch.jsp | 2 +- source/web/scripts/ajax/common.js | 25 + source/web/scripts/ajax/opensearch.js | 1115 ++++++++--------- 22 files changed, 689 insertions(+), 617 deletions(-) create mode 100644 source/web/images/icons/opensearch_controls.gif delete mode 100644 source/web/images/parts/os-background.gif create mode 100644 source/web/jsp/dashboards/dashlets/opensearch.jsp diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index a629c8f681..c6024f9831 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -1297,10 +1297,13 @@ workflow_duration=Duration: workflow_duration_ms=ms # OpenSearch messages +show=Show opensearch=OpenSearch opensearch_desc=Provides ability to search across multiple OpenSearch supported search engines. -perform_search_in=Perform Search In +search_in=Search In no_engines_registered=Failed to find any registered OpenSearch engines! +current_repo=Current Alfresco Repository +toggle_options=Toggle Options # UI Page Titles title_about=About Alfresco diff --git a/config/alfresco/web-api-config.xml b/config/alfresco/web-api-config.xml index e70897c44f..0fb5ee0fa3 100644 --- a/config/alfresco/web-api-config.xml +++ b/config/alfresco/web-api-config.xml @@ -22,7 +22,7 @@ - + /service/search/textsearchdescription.xml diff --git a/config/alfresco/web-client-config.xml b/config/alfresco/web-client-config.xml index a0351696ec..0902b0e62c 100644 --- a/config/alfresco/web-client-config.xml +++ b/config/alfresco/web-client-config.xml @@ -211,6 +211,8 @@ + false diff --git a/source/java/org/alfresco/web/app/servlet/ajax/InvokeCommand.java b/source/java/org/alfresco/web/app/servlet/ajax/InvokeCommand.java index beb03b1e38..077129ed28 100644 --- a/source/java/org/alfresco/web/app/servlet/ajax/InvokeCommand.java +++ b/source/java/org/alfresco/web/app/servlet/ajax/InvokeCommand.java @@ -93,20 +93,21 @@ public class InvokeCommand extends BaseAjaxCommand " on variable " + variableName + " with method " + methodName); - // retrieve the managed bean, this is really weak but if the - // request comes from a portal server the bean we need to get - // is in the session with a prefix chosen by the portal vendor, - // to cover this scenario we have to go through the names of - // all the objects in the session to find the bean we want. - Object bean = null; - + Object bean = null; if (Application.inPortalServer()) { + // retrieve the managed bean, this is really weak but if the + // request comes from a portal server the bean we need to get + // is in the session with a prefix chosen by the portal vendor, + // to cover this scenario we have to go through the names of + // all the objects in the session to find the bean we want. + + String beanNameSuffix = "?" + variableName; Enumeration enumNames = request.getSession().getAttributeNames(); while (enumNames.hasMoreElements()) { String name = (String)enumNames.nextElement(); - if (name.endsWith(variableName)) + if (name.endsWith(beanNameSuffix)) { bean = request.getSession().getAttribute(name); @@ -118,8 +119,7 @@ public class InvokeCommand extends BaseAjaxCommand } } - // if we didn't find the bean it may be a request scope bean, in which - // case go through the variable resolver to create it. + // if we don't have the bean yet try and get it via the variable resolver if (bean == null) { VariableResolver vr = facesContext.getApplication().getVariableResolver(); diff --git a/source/java/org/alfresco/web/ui/common/component/data/UIDataPager.java b/source/java/org/alfresco/web/ui/common/component/data/UIDataPager.java index 05a3a85f7e..517b866b46 100644 --- a/source/java/org/alfresco/web/ui/common/component/data/UIDataPager.java +++ b/source/java/org/alfresco/web/ui/common/component/data/UIDataPager.java @@ -111,7 +111,7 @@ public class UIDataPager extends UICommand Integer.toString(pageCount) })); - buf.append(" "); + buf.append("  "); // output HTML links or labels to render the paging controls // first page @@ -128,6 +128,8 @@ public class UIDataPager extends UICommand buf.append(Utils.buildImageTag(context, WebResources.IMAGE_FIRSTPAGE_NONE, 16, 16, null)); } + buf.append(" "); + // previous page if (currentPage != 0) { @@ -228,6 +230,8 @@ public class UIDataPager extends UICommand buf.append(Utils.buildImageTag(context, WebResources.IMAGE_NEXTPAGE_NONE, 16, 16, null)); } + buf.append(" "); + // last page if ((dataContainer.getCurrentPage() < dataContainer.getPageCount() - 1) == true) { diff --git a/source/java/org/alfresco/web/ui/repo/component/UIOpenSearch.java b/source/java/org/alfresco/web/ui/repo/component/UIOpenSearch.java index 05f60c779f..a8a4c73139 100644 --- a/source/java/org/alfresco/web/ui/repo/component/UIOpenSearch.java +++ b/source/java/org/alfresco/web/ui/repo/component/UIOpenSearch.java @@ -55,7 +55,7 @@ public class UIOpenSearch extends SelfRenderingComponent return; } - String clientId = this.getClientId(context); + String clientId = this.getId(); // output the scripts required by the component (checks are // made to make sure the scripts are only written once) @@ -78,17 +78,17 @@ public class UIOpenSearch extends SelfRenderingComponent // write out the javascript initialisation required out.write("\n"); // write out the HTML - out.write("
\n"); + out.write("
"); out.write(""); out.write("
"); + out.write("-search-term' type='text' size='30' onkeyup='return "); + out.write(clientId); + out.write(".handleKeyPress(event);' />"); out.write("
\n"); + out.write("
"); out.write(Application.getMessage(context, "options")); - out.write("' />
\n"); - out.write("
"); + out.write("\n"); + + out.write("
"); + out.write(Application.getMessage(context, "show")); out.write(""); + out.write("-page-size' type='text' value='5' style='width: 25px; margin-left: 5px; margin-right: 5px;' />"); out.write(Application.getMessage(context, "items_per_page")); - out.write("
"); - out.write(Application.getMessage(context, "perform_search_in")); + out.write("
"); + out.write(Application.getMessage(context, "search_in")); out.write(":
"); for (OpenSearchEngine engine : engines) { out.write(""); } - out.write("
"); out.write(""); out.write(engine.getLabel()); out.write("
\n"); - out.write("
\n
\n"); + out.write("
\n"); + + out.write("
\n
\n"); } /** diff --git a/source/web/css/main.css b/source/web/css/main.css index 842e4f4bc9..05ce5f20c4 100644 --- a/source/web/css/main.css +++ b/source/web/css/main.css @@ -435,7 +435,7 @@ a.topToolbarLinkHighlight, a.topToolbarLinkHighlight:link, a.topToolbarLinkHighl .pager { - padding: 3px; + padding: 6px 4px 3px 4px; border: 1px dotted #cccccc; } diff --git a/source/web/css/opensearch.css b/source/web/css/opensearch.css index 1f82e578d3..a54dee9732 100644 --- a/source/web/css/opensearch.css +++ b/source/web/css/opensearch.css @@ -1,59 +1,60 @@ .osSidebarPanel { - min-width: 190px; + background-color: #f5f5f5; + padding: 4px; + min-width: 212px; *width: 100%; } .osPanel { - margin: 4px; + margin-bottom: 3px; +} + +.osControls +{ + padding: 4px; + background-color: white; + border: 1px solid #babfc5; + -moz-border-radius: 7px; } .osOptions { - margin: 6px; - display: none; + margin-top: 6px; + margin-left: 4px; } .osResults { margin-top: 6px; padding: 3px; - background: url(../images/parts/os-background.gif) 0 0 repeat-x; + background-color: white; + border: 1px solid #babfc5; + -moz-border-radius: 7px; + *width: 100%; } .osEngineTitle { + padding: 1px 2px 2px 2px; margin-bottom: 2px; - border-bottom: 1px dashed #bbb; -} - -.osEngineTitleText -{ font-weight: bold; - color: #003366; - padding-bottom: 2px; -} - -.osResultsPosition -{ - font-size: 9px; - text-align: right; - padding-right: 2px; - _padding-right: 6px; + color: #004488; + white-space: nowrap; + border-bottom: 1px dotted #bbb; } .osResultsPaging { + padding: 6px 4px 4px 4px; font-size: 9px; text-align: right; - padding: 4px; - padding-top: 6px; } -.osResultsPaging a, .osResultsPaging a:hover, .osResultsPaging a:link, .osResultsPaging a:visited +.osResultsPaging img { - font-size: 9px; + vertical-align: -4px; } .osResultNoMatch diff --git a/source/web/images/icons/FirstPage.gif b/source/web/images/icons/FirstPage.gif index e3b74d83bc21ab0cfe396488251b715123836c96..21c965fde8addfa79ba7af5284d7424e09877a2c 100644 GIT binary patch literal 582 zcmZ?wbhEHb6krfwc*Xz%|Ns9Fj7rTZsoQh#xQkz;M^LO!SYkj_YG8C)NL*%IMsa0h zS8Z!wOV8B)Y4a8=U%zADQQz>yu!O9rl)T8~+}QNO_>97g!m5JGru>S=lG?Vm{u!;k zQx~t=ICshF73;UH-Mn-E(bGHj9oe$$z^U_BPM*7b;_Ri%H|}1%cKhbthabQGeD&_r z^VjbmKY#t;$%}iBo;7w&nzwB2wmk<=UATJu?4@I8E*?I4?$C*|`;VU5uw&nyhflBG zx_9pK^&fx!fBpIA-KVb`w(t4y^#{-wVBZWeLh&aHBLjmogAT~upg3V*U)*|_| z@NP4Z6%{q#)~u(eB+R3yF2!})@^G`hJ`1O`K0n8G4wehe*4D~Gl6U3VpD5pL*3wd8 zV}ALHiB08YvyF`-tHjr@7UGUyn>B;xa2P5taBO5`{~B>(gQBx=v%{1b9vdIIaLBMo M-m=K>P++hI00sZTnE(I) literal 330 zcmZ?wbhEHb6krfwxXJ(m|Ns9NDOkjiHj_DX4qMKAuEHh!r7MN2)`}G`m8{<+QM^Q| ze5G9L4w>q8vNh`z8aK;Vtyb>btK7Onv1W}*+YXKXL+agowfYWe^&iribWEdpv;MS` zdQ*-WOgm*X^Q_U#GltVo>38ll?AdMHyT^9MF}s<^oo1hMnSaJ((RsfW*MipE4BK!w zdh5g3?T_PkJPBNLBY54dgx$}R_P$8o`y&0|n~Xzmfi48Q6bqsFlZBCi!JI({BnR>n z16%rm*##atQvL21*i%x(EY17`pQvPINGY8VGm46u_VC&@L$5HQhdZVjng#VrXQ);0 z)N^z7R7^jbpe5?Yp~B%Lr=hMU;KnY^?ku6K#P7x?$mSv}!sEuu&Fad>>Bhp$;>P5$ KdX0x8gEas$cz8nq diff --git a/source/web/images/icons/FirstPage_unavailable.gif b/source/web/images/icons/FirstPage_unavailable.gif index cf91b77df1d721af15ca8d67ac75a52f4fa638c7..c027850a1484a01f841e2013a62f38d10eb5f108 100644 GIT binary patch delta 352 zcmV-m0iXWI0`>xbM@dFFIbje05CGKx00000|NsBn-{jZZ;L_IH(bd||)7Z|^*X{B4 z=+s^{>*3|<;Nh9&~?d0g}pN7oQZK>#~~qs5T` delta 283 zcmV+$0p$Mn0>=V>M@dFFIbje05CGKx00000|NsBc&(O27v#YABjf{=_{QctMQ@;PF%Eube!0`NY{v$4+0keBpKsgym=bw*Xf4uwjb;tfA&tAU+`Uvc^AwVepWMO1raA(i~ zxfK*A4D3r9^yH;mTH9J=nv}G9di#1zWu#r4rcRqat;KovoVjybTwGjT7cMpC(p=c0 zt*sy`w`L8u7}J^-H#bFLVSVczh9VX_T6A<|1y6{o>lg@G9c^)R2g3!ve?V79WPl6B`r{ a^UBLD&~V(i=%|pq9f#Es!A0E;4Aua5lF9A> literal 332 zcmZ?wbhEHb6krfwxXJ(m|NsAINSn!=IfpH0K3Cxq{?e7gRcpnHmrB-ek|88aFG{ZIG{8t=zd+rEQ05+YXKXL+agoRqEGk^&iribWE%7fJXCX z{b?ulrX16sdR(V{yV1rFfYgHg#K4w$U}k}bj#R(<#6XcC zG1vJ??$-?aQluBDEivi{qfHXVMmMyT=4?O;~I^=fYk#%h1)v%h1Ef&DY%F(AC<{)Y;C{*v-<{($?C` z&(rn!{qy(x@%8!e^!V@d_wMrc?C|vK@AK#D@8;_6<>~D(h$&Y-Qwoj z-{aZd;@I8c&(zq?)7R(h@c8`y_xt|z`1|ws`v3p`k+B?q001HR1OWg5H2^FC0000G z01yBG29m&3W?Y2MG`O`7ZW9fL?0gmhY%kx6DE*E2?;Gk5e=IN6DONQAt4kK z1`4Mk7!xQfr$izm1O&9WuMf0D3ckO#~& C7spEg literal 330 zcmZ?wbhEHb6krfwxXJ(m|NsAgaR0%D^A}dHTHV{zyMONOuee!P3{ z-qvl~7A#y?Q(N=#)5ph89`8S}fAyNx)22^*@#6XE)29v|JTPn4%+Ah^FP}f(x_R@$ z`Sa7KP5b-z@6Vq=TDqCas2r4W5Eu_*QzXUgP1& GU=0Ae>7DKX diff --git a/source/web/images/icons/NextPage.gif b/source/web/images/icons/NextPage.gif index 784fbe91c4f5a03a0276dd2804e3edc264523fcd..7609c90e3a843eb6d3cd375a615bb24245989108 100644 GIT binary patch literal 361 zcmZ?wbhEHb6krfwxXJ(m|NsAwNi8^X^1OFwf`4R6aBN0+VoqXK$@F>4CeK>5VEKCY z!04E?g8YicqUx5m{uyn3)27Z{I(yN|SqoPzS-olTs*UrPtzEHx+lKA?mapA>>im_H z=PsW(d+FHe3*UeLfA#LuJC z-osv)Au{ZUeg!C!zS0g^_{5ltBli0^}zK zwzdO-tWG*ookEGv4(C|S)ZkS4wkm3Um{QK^w`H9h3*M**&rWukAeE9CaIHWo*KfBB zU%yDLAJ0!`VYVhF*?L76y-qz&)?N3l#+4pCuv2#9$2of`LnF diff --git a/source/web/images/icons/NextPage_unavailable.gif b/source/web/images/icons/NextPage_unavailable.gif index 12c6a5c1546dc2eb97b811267b56ac31a6db5e7e..4ee968e844770729d25d3748c4c21965d117119a 100644 GIT binary patch delta 311 zcmV-70m%NL0_6gKM@dFFIbje05CGKx00000|NsBn-{jfd;@8{Y)!E+8(%0?r_UY~N z=+t64@8sz1-s0!T&CGjRr%xR`cwpA7nVp>-Up{}nb@S$h^XLEm{rmm<_t&pqU%h(u;>C;S z&!0bW;>59I#||7guxHPnwQJY5w6p-N09!?ULh&aHBLjmHgAT}Oke?XX>>MT*c<4y= zdjzUwo(Y+8#F2qXw1`P8U~9ol8Kny>$2JOh%-~^BU2Lf?I@|sD+?)!#FDeHo__zJ? MYzS=*aAdFs00rM{SO5S3 diff --git a/source/web/images/icons/PreviousPage.gif b/source/web/images/icons/PreviousPage.gif index 96ff132f0a1f4b6554e79f71e19de2a0a34a0a41..877c6daee85137a15cef477f1187df4c9f789b13 100644 GIT binary patch delta 337 zcmV-X0j~a^0_OsMM@dFFIbje05CGKx00000|NsA3VQj?7&qq;QOI2V`S!7dPXk~7A zm!77er>|IIY+Pn=W^Z_gkC=vzmX)2Qke8mDqN$ppsFj?fq^q){spiSe`YHX+orXQT?PeZ#ntjS;{u#d&*TOd3jotn@e#eu*H8+CS z-AdT~JZbNX^n-6Q4!s4M54MLUgyK&YMg|5&1|5*;AU`p%*&LWq;GrYce?m!RWsFg) zK)@5pt|l4(*UJyKR9MYAv#9%Fj$YUE!$AvWR`hfpao|-HYN=XbaG{;0uF>6*!5RPx C09P*n diff --git a/source/web/images/icons/PreviousPage_unavailable.gif b/source/web/images/icons/PreviousPage_unavailable.gif index 05f9588d961983bdcb8e9ea2a35c3c1e5fbc19d7..be2f939ccac7f188a4264d550dcb3cf1f444c819 100644 GIT binary patch literal 355 zcmZ?wbhEHb6krfwxXJ(m|NsBL^Wf?2`%iA(eRSi_!|S&nT)cYg{N)>OKYn}h=Hv6% zAD+E>fBM4JW2Y}1K5_QawOgmpU;g^@@0TBcK7arH@$1hIUw*v*{QcdhZ*M+)dHw$L zt9PHCy?Xcb<=gK+et!A-?e3#zx9&f_dGFDUyAQA4x_9#2rRQ%x+^(6h3$jf{=_{QctMzAAxlwK5^Ssa>G8lG1km0uNCQkPiXm|ESM zS>Kt{)Kkztp{R3GS@+cP-su(nGixW$ZJfSv!h#Kpx7}I2=l;5V54IhByyMuDUB{mu zIQ#s_g_p-KzB+U5^`%?yuH1ch?cVzv4?f&`^6A0z&yQYwee&w-%Xi;jz5D*=!;g0# zf4u+v^V8Q~U%vhR^8MGh@4vtQ{PXkIpI^WK{`vFo&)vgMw}r4?odtF44@<}L_r^_poSzRG6r(J-|@ zNrs415z8+wk6M1^D5Fe`2xongWO1pfzNU(Ttdw|;xtW2Ms-m2N4i6MGl2n zj;V3ZaAiTqW>KdG#T166lqoZI9R2V2m$Hu@Is4!5BjgNydP+@?L=pn|9 zARNYt38QfW0~Kp>a$;f<0YYIy4>4&1;V_xaCInp6%;qWd5auZmj;U9#rVwyZLz7^pB%%)WjN#z2LE;`Q7d7y}gsiaCn~jDZRRg~e(GW1wQ$ zY*wocW3_>B*z9(j&5nTz1BHEl9*h9tm|s|!pI^X0g@Iz>&6@=TT-1;j7r_{)FiTe6$Xm`Lwo{+{sKXD5hQAmm_-m|f=t~&7?gw?*^`>YqK}<8Ly0RX_=ZSP zxqCACSq5dV^n*3t31WqkG}z$vsfPa%iR@0HhZvd+CsIAA{!v>y*52&UH3#thUMSdZ zRh~@2cBQh(jY11b$oo_C)0V1h!AZ3igH%SPvo~Mx&`GvZ=-jmGCGXpUnr?26{LX%k zsKzJUb~&=1>@n(hoF1LulG=5~e|^59nDnJ+BJhInu3EeNz)LIKrLLx5RGAqYHvfD% zyDf40sY3Ehp}Tlw^}6Izv$CE$uqG(^pm{juUXnF5`Ixt6{l;E(SZt-6?08>KOFW_8!NgfC)ZBH0Eh zc@vxEm;EvOl<#L^w#YX-OVZ+-l~q6L7jQ)E5s+VyBJ%${tNv8=7kP(UPwgm{iu_~t zNksuMPlr7Mci%KW2;6gQR1~fG+a_2JBtJ%ee?lJ+hY^N`~3KIXxW-n4ZG6js$Q2cBPv2s-+RlpcKiK0Q6S z>@jJexlGNj3a*V~rnkxel@7GmzLHQvj~crMg1?`sr-Xi2t{LcPZ+Kf3dcr~yhqjTg zmxQ{cgpZnaTpOkClo_v1vnnh*sO$ESkOF2gq$&__k)x5@>(^2ist-`2Z zFX?SjS1w%FXs`Ac#7AA#cG|VSYx%V3Yn@}B{6G5jn&|6lA6m3Rol~aI+H!yvb5mV7 z#Ls<_Llflxoih}(^V__f4=tTo#4Y6>?=*p$1gRyfF#c?s2w+)UvB<3?s&KhLc@PUCk& zYyR!Ft2SPnbi*rtNa^a1f3*3DSAs6V?lsqw&UIRJ+vDpJ^;;Y7CH|8qTb=kQckk+r VPYdEd**KglTY2+*udg?e{2! +<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> +<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> +<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %> +<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %> + + \ No newline at end of file diff --git a/source/web/jsp/sidebar/opensearch.jsp b/source/web/jsp/sidebar/opensearch.jsp index 0ee0966b75..de7196e82b 100644 --- a/source/web/jsp/sidebar/opensearch.jsp +++ b/source/web/jsp/sidebar/opensearch.jsp @@ -21,6 +21,6 @@
- +
\ No newline at end of file diff --git a/source/web/scripts/ajax/common.js b/source/web/scripts/ajax/common.js index e1e83cdadb..6242ee3cbe 100644 --- a/source/web/scripts/ajax/common.js +++ b/source/web/scripts/ajax/common.js @@ -3,8 +3,33 @@ // Gavin Cornwell 14-07-2006 // +// Global Alfresco namespace object +if (typeof Alfresco == "undefined") +{ + var Alfresco = {}; +} + var _alfContextPath = null; +/** + * Error handler for errors caught in a catch block + */ +function handleCaughtError(err) +{ + var msg = null; + + if (err.message) + { + msg = err.message; + } + else + { + msg = err; + } + + alert("An error occurred: " + msg); +} + /** * Default handler for errors when using the dojo toolkit */ diff --git a/source/web/scripts/ajax/opensearch.js b/source/web/scripts/ajax/opensearch.js index fafd737c64..c8172a01d6 100644 --- a/source/web/scripts/ajax/opensearch.js +++ b/source/web/scripts/ajax/opensearch.js @@ -1,5 +1,5 @@ // -// Alfresco OpenSearch library +// Alfresco OpenSearch client library // Gavin Cornwell 09-01-2007 // // NOTE: This script relies on common.js so therefore needs to be loaded @@ -7,25 +7,19 @@ var _OS_NS_PREFIX = "opensearch"; var _OS_NS_URI = "http://a9.com/-/spec/opensearch/1.1/"; - -var _searchTermFieldId = null; -var _pageSizeFieldId = null; - -var _resultsDivId = "os-results"; -var _optionsDivId = "os-options"; -var _resultSetPanelId = "-osresults-panel"; -var _resultSetListId = "-osresults-list"; -var _resultSetPositionId = "-osresults-position"; -var _resultSetPagingId = "-osresults-paging"; - -var _engineEnabledId = "-engine-enabled"; -var _engines = []; -var _enginesById = []; +var _RESULTS_DIV_ID_SUFFIX = "-os-results"; +var _OPTIONS_DIV_ID_SUFFIX = "-os-options"; +var _RESULTSET_PANEL_DIV_ID_SUFFIX = "-osresults-panel"; +var _RESULTSET_LIST_DIV_ID_SUFFIX = "-osresults-list"; +var _RESULTSET_PAGING_DIV_ID_SUFFIX = "-osresults-paging"; +var _ENGINE_ENABLED_FIELD_ID = "-engine-enabled"; +var _SEARCH_TERM_FIELD_ID = "-search-term"; +var _PAGE_SIZE_FIELD_ID = "-page-size"; /** - * Define an object to hold the definition of an OpenSearch engine + * Constructor for an object to hold the definition of an OpenSearch engine */ -function OpenSearchEngine(id, label, url) +Alfresco.OpenSearchEngine = function(id, label, url) { this.id = id; this.label = label; @@ -33,211 +27,573 @@ function OpenSearchEngine(id, label, url) } /** - * Sets the field id of the search term input control + * Constructor for an OpenSearchClient object */ -function setSearchTermFieldId(id) +Alfresco.OpenSearchClient = function(id) { - _searchTermFieldId = id; + this.id = id; + this.engines = []; + this.enginesById = []; } -/** - * Sets the field id of the page size input control - */ -function setPageSizeFieldId(id) +Alfresco.OpenSearchClient.prototype = { - _pageSizeFieldId = id; -} - -/** - * Registers an OpenSearch engine to be called when performing queries - */ -function registerOpenSearchEngine(id, label, url) -{ - var se = new OpenSearchEngine(id, label, url); - _engines[_engines.length] = se; - _enginesById[id] = se; -} - - -/** - * Handles the key press event, if ENTER is pressed execute the query - */ -function handleKeyPress(e) -{ - var keycode; + id: null, - // get the keycode - if (window.event) + engines: null, + + enginesById: null, + + /** + * Registers an OpenSearch engine to be called when performing queries + */ + registerOpenSearchEngine: function(id, label, url) { - keycode = window.event.keyCode; - } - else if (e) - { - keycode = e.which; - } - - // if ENTER was pressed execute the query - if (keycode == 13) - { - executeQuery(); - return false; - } - - return true; -} + var se = new Alfresco.OpenSearchEngine(id, label, url); + this.engines[this.engines.length] = se; + this.enginesById[id] = se; + }, -/** - * Toggles the visibility of the options panel - */ -function toggleOptions(icon) -{ - var currentState = icon.className; - var optionsDiv = document.getElementById(_optionsDivId); - - if (currentState == "collapsed") + /** + * Handles the key press event, if ENTER is pressed execute the query + */ + handleKeyPress: function(e) { - icon.src = getContextPath() + "/images/icons/expanded.gif"; - icon.className = "expanded"; + var keycode; - // show the div holding the options - if (optionsDiv != null) + // get the keycode + if (window.event) { - optionsDiv.style.display = "block"; + keycode = window.event.keyCode; + } + else if (e) + { + keycode = e.which; } - } - else - { - icon.src = getContextPath() + "/images/icons/collapsed.gif"; - icon.className = "collapsed"; - // hide the div holding the options - if (optionsDiv != null) - { - optionsDiv.style.display = "none"; + // if ENTER was pressed execute the query + if (keycode == 13) + { + this.executeQuery(); + return false; } - } -} + + return true; + }, -/** - * Executes the query against all the registered and selected opensearch engines - */ -function executeQuery() -{ - // gather the required parameters - var term = document.getElementById(_searchTermFieldId).value; - var count = document.getElementById(_pageSizeFieldId).value; - - // default the count if its invalid - if (count.length == 0 || isNaN(count)) + /** + * Toggles the visibility of the options panel + */ + toggleOptions: function(icon) { - count = 5; - } - - // issue the queries if there is enough search criteria - if (term != null && term.length > 1) - { - // issue the search request for each enabled engine - for (var e = 0; e < _engines.length; e++) + var currentState = icon.className; + var optionsDiv = document.getElementById(this.id + _OPTIONS_DIV_ID_SUFFIX); + + if (currentState == "collapsed") { - // get the checkbox for the current engine - var ose = _engines[e]; - var engCheckbox = document.getElementById(ose.id + _engineEnabledId); - if (engCheckbox != null && engCheckbox.checked) + icon.src = getContextPath() + "/images/icons/expanded.gif"; + icon.className = "expanded"; + + // show the div holding the options + if (optionsDiv != null) { - issueSearchRequest(ose, term, count); + optionsDiv.style.display = "block"; } } - } -} + else + { + icon.src = getContextPath() + "/images/icons/collapsed.gif"; + icon.className = "collapsed"; + + // hide the div holding the options + if (optionsDiv != null) + { + optionsDiv.style.display = "none"; + } + } + }, -/** - * Issues an Ajax request for the given OpenSearchEngine - * using the given search term and page size. - */ -function issueSearchRequest(ose, term, pageSize) -{ - // generate the search url - var searchUrl = generateSearchUrl(ose.url, term, pageSize); - - // issue the request - if (searchUrl != null) + /** + * Executes the query against all the registered and selected opensearch engines + */ + executeQuery: function() { - YAHOO.util.Connect.asyncRequest("GET", searchUrl, + // gather the required parameters + var term = document.getElementById(this.id + _SEARCH_TERM_FIELD_ID).value; + var count = document.getElementById(this.id + _PAGE_SIZE_FIELD_ID).value; + + // default the count if its invalid + if (count.length == 0 || isNaN(count)) + { + count = 5; + } + + // issue the queries if there is enough search criteria + if (term != null && term.length > 1) + { + // remove previous results (if necessary) + var resultsPanel = document.getElementById(this.id + _RESULTS_DIV_ID_SUFFIX); + if (resultsPanel != null) + { + while (resultsPanel.firstChild) + { + resultsPanel.removeChild(resultsPanel.firstChild); + }; + } + + // issue the search request for each enabled engine + for (var e = 0; e < this.engines.length; e++) + { + // get the checkbox for the current engine + var ose = this.engines[e]; + var engCheckbox = document.getElementById(this.id + "-" + ose.id + _ENGINE_ENABLED_FIELD_ID); + if (engCheckbox != null && engCheckbox.checked) + { + this.issueSearchRequest(ose, term, count); + } + } + } + }, + + /** + * Issues an Ajax request for the given OpenSearchEngine + * using the given search term and page size. + */ + issueSearchRequest: function(ose, term, pageSize) + { + // generate the search url + var searchUrl = this.calculateSearchUrl(ose.url, term, pageSize); + + // issue the request + if (searchUrl != null) + { + YAHOO.util.Connect.asyncRequest("GET", searchUrl, + { + success: Alfresco.processSearchResults, + failure: Alfresco.handleSearchError, + argument: [ose.id, this] + }, + null); + } + else + { + handleErrorYahoo("Failed to generate url for search engine '" + ose.label + + "'.\n\nThis is probably caused by missing required parameters, check the template url for the search engine."); + } + }, + + /** + * Shows another page of the current search results for the + * given engineId + */ + showPage: function(engineId, url) + { + // execute the query and process the results + YAHOO.util.Connect.asyncRequest("GET", url, { - success: processSearchResults, - failure: handleSearchError, - argument: [ose.id] + success: Alfresco.processShowPageResults, + failure: Alfresco.handleSearchError, + argument: [engineId, this] }, null); - } - else - { - handleErrorYahoo("Failed to generate url for search engine '" + ose.label + - "'.\n\nThis is probably caused by missing required parameters, check the template url for the search engine."); - } -} + }, -/** - * Generates a concrete url for the given template url and parameters. - * - * All parameters (inside { and }) have to be replaced. We only need to populate - * the 'searchTerms' and 'count' parameters, all optional ones will use the - * empty string. If there is a mandatory parameter present (other than searchTerms - * and count) null will be returned. - */ -function generateSearchUrl(templateUrl, term, count) -{ - var searchUrl = null; - - // define regex pattern to look for params - var pattern = /\{+\w*\}+|\{+\w*\?\}+|\{+\w*:\w*\}+|\{+\w*:\w*\?\}+/g; - - var params = templateUrl.match(pattern); - if (params != null && params.length > 0) + /** + * Generates a concrete url for the given template url and parameters. + * + * All parameters (inside { and }) have to be replaced. We only need to populate + * the 'searchTerms' and 'count' parameters, all optional ones will use the + * empty string. If there is a mandatory parameter present (other than searchTerms + * and count) null will be returned. + */ + calculateSearchUrl: function(templateUrl, term, count) { - searchUrl = templateUrl; + var searchUrl = null; - // go through the parameters and replace the searchTerms and count - // parameters with the given values and then replace all optional - // parameters with an empty string. - for (var p = 0; p < params.length; p++) + // define regex pattern to look for params + var pattern = /\{+\w*\}+|\{+\w*\?\}+|\{+\w*:\w*\}+|\{+\w*:\w*\?\}+/g; + + var params = templateUrl.match(pattern); + if (params != null && params.length > 0) { - var param = params[p]; + searchUrl = templateUrl; - if (param == "{searchTerms}") + // go through the parameters and replace the searchTerms and count + // parameters with the given values and then replace all optional + // parameters with an empty string. + for (var p = 0; p < params.length; p++) { - searchUrl = searchUrl.replace(param, term); - } - else if (param == "{count}" || param == "{count?}") - { - searchUrl = searchUrl.replace(param, count); - } - else if (param.indexOf("?") != -1) - { - // replace the optional parameter with "" - searchUrl = searchUrl.replace(param, ""); - } - else - { - // an unknown manadatory parameter return - searchUrl = null; - break; + var param = params[p]; + + if (param == "{searchTerms}") + { + searchUrl = searchUrl.replace(param, term); + } + else if (param == "{count}" || param == "{count?}") + { + searchUrl = searchUrl.replace(param, count); + } + else if (param.indexOf("?") != -1) + { + // replace the optional parameter with "" + searchUrl = searchUrl.replace(param, ""); + } + else + { + // an unknown manadatory parameter return + searchUrl = null; + break; + } } } - } + + return searchUrl; + }, + + /** + * Renders the results for the given feed element. + */ + renderSearchResults: function(engineId, feed) + { + // look up the label from the osengine registry + var engineLabel = this.enginesById[engineId].label; + + // create the div to hold the results and the header bar + var sb = []; + sb[sb.length] = "
"; + sb[sb.length] = "
"; + sb[sb.length] = engineLabel; + sb[sb.length] = "
"; + + // create the actual results to display, start with the containing div + sb[sb.length] = "
"; + sb[sb.length] = this.generateResultsListHTML(feed); + sb[sb.length] = "
"; + + // create the paging controls + sb[sb.length] = "
"; + sb[sb.length] = this.generatePagingHTML(engineId, feed); + sb[sb.length] = "
"; - return searchUrl; + // close the containing div + sb[sb.length] = "
"; + + // create a div element to hold the results + var d = document.createElement("div"); + d.innerHTML = sb.join(""); + + // return the div + return d; + }, + + /** + * Generates the HTML to display the search results from the + * given feed. + */ + generateResultsListHTML: function(feed) + { + var isAtom = true; + + // if the name of the feed element is "channel" this is an RSS feed + if (feed.tagName == "channel") + { + isAtom = false; + } + + var results = null; + if (isAtom) + { + results = feed.getElementsByTagName("entry"); + } + else + { + results = feed.getElementsByTagName("item"); + } + + if (results == null || results.length == 0) + { + return "
No results
"; + } + else + { + var sb = []; + sb[sb.length] = ""; + + for (var x = 0; x < results.length; x++) + { + // get the current entry + var elResult = results[x]; + + // get the title, icon and summary + var title = getElementTextByTagName(elResult, "title"); + var icon = getElementTextByTagName(elResult, "icon"); + var summary = null; + if (isAtom) + { + summary = getElementTextByTagName(elResult, "summary"); + } + else + { + summary = getElementTextByTagName(elResult, "description"); + } + + // get the link href + var link = null; + var elLink = getElementByTagName(elResult, "link"); + if (elLink != null) + { + if (isAtom) + { + link = elLink.getAttribute("href"); + } + else + { + link = getElementText(elLink); + } + } + + // generate the row to represent the result + sb[sb.length] = ""; + } + + // close the table + sb[sb.length] = "
"; + if (icon != null) + { + sb[sb.length] = ""; + } + sb[sb.length] = "
"; + if (title != null) + { + if (link != null) + { + sb[sb.length] = ""; + } + sb[sb.length] = title; + if (link != null) + { + sb[sb.length] = ""; + } + } + sb[sb.length] = "
"; + if (summary != null) + { + sb[sb.length] = summary; + } + sb[sb.length] = "
"; + + return sb.join(""); + } + }, + + /** + * Generates the HTML to display the paging information i.e. the first, next, previous + * and last buttons and the position info i.e. "x - y of z". + */ + generatePagingHTML: function(engineId, feed) + { + var totalResults = 0; + var pageSize = 5; + var startIndex = 0; + + // check there are results + var elTotalResults = getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "totalResults"); + if (elTotalResults != null) + { + totalResults = getElementText(elTotalResults); + } + + // if there are no results return an empty string + if (totalResults == 0) + { + return ""; + } + + var elStartIndex = getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "startIndex"); + if (elStartIndex != null) + { + startIndex = getElementText(elStartIndex); + } + + var elItemsPerPage = getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "itemsPerPage"); + if (elItemsPerPage != null) + { + pageSize = getElementText(elItemsPerPage); + } + + // calculate the number of pages the results span + /*var noPages = Math.floor(totalResults / pageSize); + var remainder = totalResults % pageSize; + if (remainder != 0) + { + noPages++; + }*/ + + var endIndex = (Number(startIndex) + Number(pageSize)) - 1; + if (endIndex > totalResults) + { + endIndex = totalResults; + } + + // extract the navigation urls + var firstUrl = null; + var nextUrl = null; + var previousUrl = null; + var lastUrl = null; + + var links = feed.getElementsByTagName("link"); + if (links != null && links.length > 0) + { + for (var x = 0; x < links.length; x++) + { + var elNavLink = links[x]; + var linkType = elNavLink.getAttribute("rel"); + if (linkType == "first") + { + firstUrl = elNavLink.getAttribute("href"); + } + else if (linkType == "next") + { + nextUrl = elNavLink.getAttribute("href"); + } + else if (linkType == "previous") + { + previousUrl = elNavLink.getAttribute("href"); + } + else if (linkType == "last") + { + lastUrl = elNavLink.getAttribute("href"); + } + } + } + + var sb = []; + + if (firstUrl != null) + { + sb[sb.length] = ""; + } + else + { + sb[sb.length] = ""; + } + + sb[sb.length] = " "; + + if (previousUrl != null) + { + sb[sb.length] = ""; + } + else + { + sb[sb.length] = ""; + } + + sb[sb.length] = "  "; + sb[sb.length] = startIndex; + sb[sb.length] = " - "; + sb[sb.length] = endIndex; + sb[sb.length] = " of "; + sb[sb.length] = totalResults; + sb[sb.length] = "  "; + + if (nextUrl != null) + { + sb[sb.length] = ""; + } + else + { + sb[sb.length] = ""; + } + + sb[sb.length] = " "; + + if (lastUrl != null) + { + sb[sb.length] = ""; + } + else + { + sb[sb.length] = ""; + } + + return sb.join(""); + } } +/*********************************/ +/** Handlers for AJAX callbacks **/ +/*********************************/ + /** * Processes the XML search results */ -function processSearchResults(ajaxResponse) +Alfresco.processSearchResults = function(ajaxResponse) { try { // render the results from the Ajax response var engineId = ajaxResponse.argument[0]; + var clientInstance = ajaxResponse.argument[1]; var feed = ajaxResponse.responseXML.documentElement; // if the name of the feed element is "rss", get the channel child element @@ -246,18 +602,12 @@ function processSearchResults(ajaxResponse) feed = getElementByTagName(feed, "channel"); } - var resultsDiv = renderSearchResults(engineId, feed); + var resultsDiv = clientInstance.renderSearchResults(engineId, feed); // create the div to hold the results and add the results - var resultsPanel = document.getElementById(_resultsDivId); + var resultsPanel = document.getElementById(clientInstance.id + _RESULTS_DIV_ID_SUFFIX); if (resultsPanel != null) { - // first remove any existing results - while (resultsPanel.firstChild) - { - resultsPanel.removeChild(resultsPanel.firstChild); - }; - // add the new results resultsPanel.appendChild(resultsDiv); } @@ -269,87 +619,22 @@ function processSearchResults(ajaxResponse) } catch (e) { - handleError(e); + handleCaughtError(e); } } -/** - * Renders the results for the given feed element. - */ -function renderSearchResults(engineId, feed) -{ - // look up the label from the osengine registry - var engineLabel = _enginesById[engineId].label; - - // create the div to hold the results and the header bar - var sb = []; - sb[sb.length] = "
"; - sb[sb.length] = "
"; - sb[sb.length] = "
"; - sb[sb.length] = engineLabel; - sb[sb.length] = ""; - sb[sb.length] = generatePostionHTML(feed); - sb[sb.length] = "
"; - - // create the actual results to display, start with the containing div - sb[sb.length] = "
"; - sb[sb.length] = generateResultsListHTML(feed); - sb[sb.length] = "
"; - - // create the paging controls - sb[sb.length] = "
"; - sb[sb.length] = generatePagingHTML(engineId, feed); - sb[sb.length] = "
"; - - // close the containing div - sb[sb.length] = "
"; - - // create a div element to hold the results - var d = document.createElement("div"); - d.innerHTML = sb.join(""); - - // return the div - return d; -} - -/** - * Shows another page of the current search results for the - * given engineId - */ -function showPage(engineId, url) -{ - // execute the query and process the results - YAHOO.util.Connect.asyncRequest("GET", url, - { - success: processShowPageResults, - failure: handleSearchError, - argument: [engineId] - }, - null); -} /** * Processes the search results and updates the postion, result list * and paging controls. */ -function processShowPageResults(ajaxResponse) +Alfresco.processShowPageResults = function(ajaxResponse) { try { // render the results from the Ajax response var engineId = ajaxResponse.argument[0]; + var clientInstance = ajaxResponse.argument[1]; var feed = ajaxResponse.responseXML.documentElement; // if the name of the feed element is "rss", get the channel child element @@ -357,330 +642,38 @@ function processShowPageResults(ajaxResponse) { feed = getElementByTagName(feed, "channel"); } - - // find the position div and update the count - var positionDiv = document.getElementById(engineId + _resultSetPositionId); - if (positionDiv != null) - { - positionDiv.innerHTML = generatePostionHTML(feed); - } // append the results list to the results list div - var resultsListDiv = document.getElementById(engineId + _resultSetListId); + var resultsListDiv = document.getElementById(clientInstance.id + "-" + + engineId + _RESULTSET_LIST_DIV_ID_SUFFIX); if (resultsListDiv != null) { - resultsListDiv.innerHTML = generateResultsListHTML(feed); + resultsListDiv.innerHTML = clientInstance.generateResultsListHTML(feed); } - // update the paging div with new urls - var pagingDiv = document.getElementById(engineId + _resultSetPagingId); + // update the paging div with new urls and position info + var pagingDiv = document.getElementById(clientInstance.id + "-" + + engineId + _RESULTSET_PAGING_DIV_ID_SUFFIX); if (pagingDiv != null) { - pagingDiv.innerHTML = generatePagingHTML(engineId, feed); + pagingDiv.innerHTML = clientInstance.generatePagingHTML(engineId, feed); } } catch (e) { - handleError(e); + handleCaughtError(e); } } -/** - * Generates the HTML required to display the current position i.e. "x - y of z". - */ -function generatePostionHTML(feed) -{ - var totalResults = 0; - var pageSize = 5; - var startIndex = 0; - - // extract position information from results - var elTotalResults = getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "totalResults"); - if (elTotalResults != null) - { - totalResults = getElementText(elTotalResults); - } - - // if there are no results just return an empty string - if (totalResults == 0) - { - return ""; - } - - var elStartIndex = getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "startIndex"); - if (elStartIndex != null) - { - startIndex = getElementText(elStartIndex); - } - - var elItemsPerPage = getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "itemsPerPage"); - if (elItemsPerPage != null) - { - pageSize = getElementText(elItemsPerPage); - } - - // calculate the number of pages the results span - /*var noPages = Math.floor(totalResults / pageSize); - var remainder = totalResults % pageSize; - if (remainder != 0) - { - noPages++; - }*/ - - // calculate the endIndex for this set of results - var endIndex = (Number(startIndex) + Number(pageSize)) - 1; - if (endIndex > totalResults) - { - endIndex = totalResults; - } - - // make sure the startIndex is correct - if (totalResults == 0) - { - startIndex = 0; - } - - var sb = []; - sb[sb.length] = startIndex; - sb[sb.length] = " - "; - sb[sb.length] = endIndex; - sb[sb.length] = " of "; - sb[sb.length] = totalResults; - - return sb.join(""); -} - -/** - * Generates the HTML to display the search results from the - * given feed. - */ -function generateResultsListHTML(feed) -{ - var isAtom = true; - - // if the name of the feed element is "channel" this is an RSS feed - if (feed.tagName == "channel") - { - isAtom = false; - } - - var results = null; - if (isAtom) - { - results = feed.getElementsByTagName("entry"); - } - else - { - results = feed.getElementsByTagName("item"); - } - - if (results == null || results.length == 0) - { - return "
No results
"; - } - else - { - var sb = []; - sb[sb.length] = ""; - - for (var x = 0; x < results.length; x++) - { - // get the current entry - var elResult = results[x]; - - // get the title, icon and summary - var title = getElementTextByTagName(elResult, "title"); - var icon = getElementTextByTagName(elResult, "icon"); - var summary = null; - if (isAtom) - { - summary = getElementTextByTagName(elResult, "summary"); - } - else - { - summary = getElementTextByTagName(elResult, "description"); - } - - // get the link href - var link = null; - var elLink = getElementByTagName(elResult, "link"); - if (elLink != null) - { - if (isAtom) - { - link = elLink.getAttribute("href"); - } - else - { - link = getElementText(elLink); - } - } - - // generate the row to represent the result - sb[sb.length] = ""; - } - - // close the table - sb[sb.length] = "
"; - if (icon != null) - { - sb[sb.length] = ""; - } - sb[sb.length] = "
"; - if (title != null) - { - if (link != null) - { - sb[sb.length] = ""; - } - sb[sb.length] = title; - if (link != null) - { - sb[sb.length] = ""; - } - } - sb[sb.length] = "
"; - if (summary != null) - { - sb[sb.length] = summary; - } - sb[sb.length] = "
"; - - return sb.join(""); - } -} - -/** - * Generates the HTML to display the paging links i.e. first, next, previous and last. - */ -function generatePagingHTML(engineId, feed) -{ - // check there are results - var totalResults = 0; - var elTotalResults = getElementByTagNameNS(feed, _OS_NS_URI, _OS_NS_PREFIX, "totalResults"); - if (elTotalResults != null) - { - totalResults = getElementText(elTotalResults); - } - - // if there are no results return an empty string - if (totalResults == 0) - { - return ""; - } - - // extract the navigation urls - var firstUrl = null; - var nextUrl = null; - var previousUrl = null; - var lastUrl = null; - - var links = feed.getElementsByTagName("link"); - if (links != null && links.length > 0) - { - for (var x = 0; x < links.length; x++) - { - var elNavLink = links[x]; - var linkType = elNavLink.getAttribute("rel"); - if (linkType == "first") - { - firstUrl = elNavLink.getAttribute("href"); - } - else if (linkType == "next") - { - nextUrl = elNavLink.getAttribute("href"); - } - else if (linkType == "previous") - { - previousUrl = elNavLink.getAttribute("href"); - } - else if (linkType == "last") - { - lastUrl = elNavLink.getAttribute("href"); - } - } - } - - var sb = []; - - if (firstUrl != null) - { - sb[sb.length] = "first | "; - } - if (previousUrl != null) - { - sb[sb.length] = "previous"; - if (nextUrl != null) - { - sb[sb.length] = " | "; - } - } - if (nextUrl != null) - { - sb[sb.length] = "next | "; - } - if (lastUrl != null) - { - sb[sb.length] = "last"; - } - - return sb.join(""); -} - -/** - * Error handler for errors caught in a catch block - */ -function handleError(o) -{ - var msg = null; - - if (e.message) - { - msg = e.message; - } - else - { - msg = e; - } - - alert("Error occurred processing search results: " + msg); -} - /** * Error handler for Ajax call to search engine */ -function handleSearchError(o) +Alfresco.handleSearchError = function(ajaxResponse) { - // TODO: find out which search engine results could not be found! - - handleErrorYahoo("Error: Failed to retrieve search results"); -} - -/** - * Error handler for Ajax call to initialise component - */ -function handleInitError(o) -{ - handleErrorYahoo("Failed to initialise OpenSearch component: " + - o.status + " " + o.statusText); + var engineId = ajaxResponse.argument[0]; + var clientInstance = ajaxResponse.argument[1]; + var engineLabel = clientInstance.enginesById[engineId].label; + + handleErrorYahoo("Failed to retrieve search results for '" + engineLabel + + "': " + ajaxResponse.status + " " + ajaxResponse.statusText); }