snippets / common.js

Language: Javascript - First posted by chad_ydl on 2008-02-29 10:08 (8 months, 3 weeks)
Link to the snippet: http://www.friendsnippets.org/snippet/196/

The alerts should be removed. The onFailure should be the way you commonly handle error in the project. The onLoadRequest() function can be called in line 981 of the main.js example:

"[HTML_REMOVED][HTML_REMOVED]"+getResourceString("SearchBox.clearrecent",1)+"[HTML_REMOVED]";

javascript.SearchBox.clearrecent=Clear {0} Recent Searches

 1 var outputResourceBundleObj;
2 var outputCommonSettingsObj;
3 var outputSpecificClientSettingsObj;
4
5 function onLoadRequest() {
6 new Ajax.Request(getResourceBundleUrl, {
7 method : 'post',
8 onComplete : function(xh) {
9 outputResourceBundleObj = JSON.parse(xh.responseText);
10 try {
11 alert("Example how to display resource:\n" + getResourceString("converter.wvaddress.invalidWVAddress", "","user1@"));
12 } catch (e) {
13 alert(e);
14 }
15 parametersGetCommonSettings = "getCommonSettings=";
16 new Ajax.Request(getConfigUrl, {
17 method : 'post',
18 onComplete : function(xh) {
19 outputCommonSettingsObj = JSON.parse(xh.responseText);
20
21 parametersGetSpecificClientSettings = "getSpecificClientSettings=";
22 new Ajax.Request(getConfigUrl, {
23 method : 'post',
24 onComplete : function(xh) {
25 outputSpecificClientSettingsObj = JSON.parse(xh.responseText);
26 return true;
27 },
28 parameters : parametersGetSpecificClientSettings,
29 onFailure : function() { alert('parametersGetSpecificClientSetting')}
30 })
31 },
32 parameters : parametersGetCommonSettings,
33 onFailure : function() { alert('parametersGetCommonSetting')}
34 })
35 },
36 parameters : null,
37 onFailure : function() { alert('getResourceBundleUrl')}
38 });
39 }
40
41 function getResourceString(key) {
42 var s = outputResourceBundleObj[key];
43 if (!s) return "undefine: "+ key;
44 for (var i = 1; i < arguments.length; i++) {
45 s = s.replace("{" + (i-1) + "}", arguments[i]);
46 }
47 return s;
48 }
In order to post a comment, you should have a friendsnippet account. Please sign-in.

1 comments

  • February 29th 2008 at 10:18

    Add this in settings.js. Suggesting in line 41: {var getResourceBundleUrl = 'ClientResourceBundle.action';}

Feb '08
  • The alerts should be removed. The onFailure should be the way you commonly handle error in the project. The onLoadRequest() function can be called in line 981 of the main.js example: "

    "+getResourceString("SearchBox.clearrecent",1)+"
    "; --- javascript.SearchBox.clearrecent=Clear {0} Recent Searches

Common Tags



snippet History

Feb '08