ymdp 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,242 @@
1
+
2
+ // DO NOT USE the @view instance variable in any files in /app/javascripts/base.
3
+ // The way they are cached makes it not safe to do so.
4
+
5
+ /*
6
+ I18N
7
+
8
+ global to every view.
9
+
10
+ Methods and constants dealing with internationalization.
11
+ */
12
+
13
+ var I18N, I18n;
14
+
15
+ /* set asset version */
16
+
17
+ I18N = {
18
+ VERSION: "<%= @hash %>",
19
+ MESSAGE: "<%= @message %>",
20
+ DEPLOYED: <%= Time.now.to_i %>,
21
+ DEPLOYED_STRING: "<%= Time.now.to_s %>"
22
+ };
23
+
24
+
25
+ I18n = {};
26
+
27
+ I18n.setResources = function() {
28
+ var scope, asset_path;
29
+
30
+ Debug.log("begin I18n.setResources for language " + I18n.currentLanguage);
31
+ try {
32
+ asset_path = "<%= @assets_directory %>/yrb/";
33
+ I18n.keys = I18n.keys || OpenMailIntl.getResources(asset_path, "keys", I18n.currentLanguage);
34
+ if (I18n.currentLanguage !== "en-US") {
35
+ I18n.default_keys = OpenMailIntl.getResources(asset_path, "keys", "en-US");
36
+ } else {
37
+ I18n.default_keys = I18n.keys;
38
+ }
39
+ } catch(err) {
40
+ Debug.error("error in I18n.setResources: " + err);
41
+ }
42
+ I18n.scope = "keys";
43
+ };
44
+
45
+ I18n.english = function() {
46
+ return I18n.currentLanguage.match(/^en/);
47
+ };
48
+
49
+
50
+ // I18n.translate(key, [args])
51
+ // I18n.t(key, [args])
52
+ //
53
+ // Using .translate with a single key argument will return the simple translated string for that key
54
+ //
55
+ // Using a key argument with values after it will insert the values into the placeholders in
56
+ // the returned translated string
57
+ //
58
+ I18n.translate = function(key, args) {
59
+ var m;
60
+
61
+ key = key.toUpperCase();
62
+ key = key.replace(" ", "_");
63
+
64
+ if (args) {
65
+ m = I18n.translate_sentence(key, args);
66
+ } else
67
+ {
68
+ m = I18n.translate_phrase(key);
69
+ if (!m) {
70
+ m = I18n.default_keys[key];
71
+ }
72
+ }
73
+ return m;
74
+ };
75
+ I18n.t = I18n.translate;
76
+
77
+ I18n.translate_phrase = function(key) {
78
+ return I18n["keys"][key];
79
+ };
80
+
81
+ I18n.translate_sentence = function(key, args) {
82
+ return OpenMailIntl.formatMessage(I18n.keys[key], args, I18n.currentLanguage);
83
+ };
84
+
85
+ // I18n.update(id, scope, key, args)
86
+ //
87
+ // updates an element with the given _id_ with the
88
+ // translation from scope, key and optional args
89
+ //
90
+ // only updates the element if the translation is not blank
91
+ //
92
+ I18n.update = function(id, key, args) {
93
+ Try.these(function() {
94
+ var message;
95
+ message = I18n.t(key, args);
96
+ if (message) {
97
+ $(id).update(message);
98
+ }
99
+ }, function() {
100
+ Debug.error("Error in i18n.update: " + Object.toJSON({
101
+ id: id,
102
+ key: key,
103
+ args: args
104
+ }));
105
+ });
106
+ };
107
+
108
+ // I18n.u(id, args)
109
+ //
110
+ // updates an element with a local YRB key of the same name
111
+ //
112
+ // given an id of "messages" it will look for a YRB key named "MESSAGES"
113
+ // within the local scope of the current view, and update the element with
114
+ // that translation
115
+ //
116
+ I18n.u = function(id, args) {
117
+ Try.these(
118
+ function() {
119
+ id.each(I18n.u);
120
+ },
121
+ function() {
122
+ var key;
123
+ key = id.toUpperCase();
124
+ I18n.update(id, key, args);
125
+ },
126
+ function() {
127
+ Debug.error("Error in i18n.u: " + Object.toJSON({
128
+ id: id,
129
+ args: args
130
+ }));
131
+ });
132
+ };
133
+
134
+
135
+ // I18n.updateValue(id, key, args)
136
+ //
137
+ // updates an element with the given _id_ with the
138
+ // translation from scope, key and optional args
139
+ //
140
+ // only updates the element if the translation is not blank
141
+ //
142
+ I18n.updateValue = function(id, key, args) {
143
+ Try.these(function() {
144
+ var message;
145
+ message = I18n.t(key, args);
146
+ if (message) {
147
+ $(id).value = message;
148
+ }
149
+ }, function() {
150
+ Debug.error("Error in i18n.updateValue: " + Object.toJSON({
151
+ id: id,
152
+ key: key,
153
+ args: args
154
+ }));
155
+ });
156
+ };
157
+
158
+
159
+ // I18n.v(id, args)
160
+ //
161
+ // updates the value of an element with a local YRB key of the same name
162
+ //
163
+ // given an id of "messages" it will look for a YRB key named "MESSAGES"
164
+ // within the local scope of the current view, and update the element's value with
165
+ // that translation
166
+ //
167
+ I18n.v = function(id, args) {
168
+ Try.these(
169
+ function() {
170
+ id.each(I18n.v);
171
+ },
172
+ function() {
173
+ var key;
174
+ key = id.toUpperCase();
175
+ I18n.updateValue(id, key, args);
176
+ },
177
+ function() {
178
+ Debug.error("Error in i18n.v: " + Object.toJSON({
179
+ id: id,
180
+ args: args
181
+ }));
182
+ });
183
+ };
184
+
185
+ I18n.translateError = function() {
186
+ I18n.update('error_1', 'ERROR_1');
187
+ I18n.update('error_2', 'ERROR_2');
188
+ I18n.update('retry', 'RETRY');
189
+ };
190
+
191
+ I18n.translateLoading = function() {
192
+ I18n.update('loading_subhead', 'LOADING_SUBHEAD');
193
+ I18n.update('loading_paragraph_1', 'LOADING_PARAGRAPH_1');
194
+ };
195
+
196
+ I18n.addLanguageToBody = function() {
197
+ Try.these(function() {
198
+ $$('body').first().addClassName(I18n.currentLanguage);
199
+ });
200
+ };
201
+
202
+ I18n.findAndTranslateAll = function() {
203
+ Debug.log("I18n.findAndTranslateAll");
204
+ Element.addMethods({
205
+ translate: function(element) {
206
+ element = $(element);
207
+
208
+ var e;
209
+ e = element.inspect();
210
+ if (e.match(/<input/)) {
211
+ I18n.v(element.identify());
212
+ } else {
213
+ if (e.match(/<img/)) {
214
+ I18n.src(element.identify());
215
+ } else {
216
+ I18n.u(element.identify());
217
+ }
218
+ }
219
+ }
220
+ });
221
+
222
+ $$('.t').each(function(element) {
223
+ try {
224
+ element.translate();
225
+ } catch(e) {
226
+ Debug.error("Translation error for element: " + e);
227
+ }
228
+ });
229
+ };
230
+
231
+ I18n.translateSidebar = function() {
232
+ I18n.u('faq_q1');
233
+ var link;
234
+ link = Tags.a(I18n.t('faq_link1'), {"href": 'http://go.otherinbox.com/q-custom-sender', "target": "_blank"});
235
+ I18n.u('faq_a1', [link]);
236
+
237
+ I18n.u('faq_q2');
238
+ link = Tags.a(I18n.t('faq_link2'), {"href": 'http://go.otherinbox.com/q-stop-sender', "target": "_blank"});
239
+ I18n.u('faq_a2', [link]);
240
+ };
241
+
242
+
@@ -0,0 +1,159 @@
1
+ /*
2
+
3
+ INITIALIZER CODE
4
+
5
+ */
6
+
7
+ // Adds behaviors/observers to elements on the page
8
+ //
9
+ YAHOO.init.addBehaviors = function() {
10
+ // overwrite this function locally
11
+ };
12
+
13
+ // hide the loading screen and show the main body of the summary
14
+ YAHOO.init.show = function() {
15
+ Debug.log("YAHOO.init.show");
16
+ try {
17
+ $('utility').hide();
18
+ $('error').hide();
19
+ $('loading').hide();
20
+ $('main').show();
21
+ } catch(e) {
22
+ Debug.error("Error in YAHOO.init.show", e);
23
+ }
24
+ };
25
+
26
+
27
+ // Local initializer. When your page starts up, this method will be called after fetching the user's guid and ymail wssid.
28
+ //
29
+ YAHOO.init.local = function() {
30
+ throw("This hasn't been overwritten.");
31
+ // overwrite this function locally
32
+ };
33
+
34
+ // To be run before any other initializers have run.
35
+ //
36
+ YAHOO.init.before = function() {
37
+ // overwrite this function locally
38
+ };
39
+
40
+ // Main startup code. Overwrite this function to execute after YAHOO.init.before and before YAHOO.init.after.
41
+ //
42
+ YAHOO.init.startup = function() {
43
+ Debug.log("init.startup");
44
+ // gets the user
45
+ YAHOO.oib.getGuid(function(guid) {
46
+ try {
47
+ Reporter.reportCurrentView(guid);
48
+ } catch(omg) {
49
+ Debug.error(omg);
50
+ }
51
+ YAHOO.init.local();
52
+ });
53
+ };
54
+
55
+ YAHOO.init.abTesting = function() {
56
+ // to enable abTesting in your view, overwrite this file locally.
57
+ //
58
+ // be sure to finish your post-Ajax callback with YAHOO.init.show()
59
+ //
60
+ Try.these(YAHOO.init.show);
61
+ Try.these(YAHOO.init.after);
62
+ };
63
+
64
+ // Finishing code. Runs after startup, executes translations and behaviors. Shows the page and then
65
+ // runs the A/B testing callback, which in turn will execute the last callbacks.
66
+ //
67
+ YAHOO.init.finish = function() {
68
+ try {
69
+ Debug.log("init.finish for view " + View.name);
70
+ Try.these(YAHOO.oib.showTranslations);
71
+ Try.these(YAHOO.init.addBehaviors);
72
+ Try.these(YAHOO.init.abTesting);
73
+ YAHOO.oib.page_loaded = true;
74
+ Debug.log("finished init.finish for view " + View.name);
75
+ } catch(omg) {
76
+ Debug.error("Error in YAHOO.init.finish", omg);
77
+ YAHOO.oib.showError({
78
+ "method": "YAHOO.init.finish",
79
+ "description": "exception caught in YAHOO.init.finish",
80
+ "error": omg
81
+ });
82
+ }
83
+ };
84
+
85
+ // Post-initalizer. Very last thing that runs, after content has been shown.
86
+ //
87
+ YAHOO.init.after = function() {
88
+ // overwrite this function locally
89
+ };
90
+
91
+ // Execute the before, startup and after methods. Do not overwrite. (Change YAHOO.init.startup to create a custom initializer.)
92
+ YAHOO.oib.init = function() {
93
+ Debug.log("OIB.init for view " + View.name, "<%= @message %>");
94
+ try {
95
+ YAHOO.init.browser();
96
+ YAHOO.init.resources();
97
+ I18n.addLanguageToBody();
98
+ I18n.translateLoading();
99
+ I18n.translateError();
100
+ YAHOO.init.before();
101
+ YAHOO.init.startup();
102
+ } catch(err_f) {
103
+ YAHOO.oib.showError({
104
+ "method": "YAHOO.oib.init",
105
+ "description": "exception caught in YAHOO.oib.init",
106
+ "error": err_f
107
+ });
108
+ Debug.error("Error in YAHOO.oib.init", err_f);
109
+ }
110
+ };
111
+
112
+ YAHOO.init.browser = function() {
113
+ if (Prototype.Browser.WebKit) {
114
+ $$('body').first().addClassName('webkit');
115
+ }
116
+ };
117
+
118
+ YAHOO.init.resources = function() {
119
+ Debug.log("about to call I18n.setResources");
120
+
121
+ I18n.availableLanguages = <%= supported_languages.to_json %>;
122
+
123
+ I18n.currentLanguage = OpenMailIntl.findBestLanguage(I18n.availableLanguages);
124
+
125
+ I18n.setResources();
126
+
127
+ Debug.log("finished calling I18n.setResources");
128
+ };
129
+
130
+ // Contains the last two callbacks, to show the page contents and run post-show function. Do not overwrite.
131
+ YAHOO.init.showAndFinish = function() {
132
+ Debug.log("YAHOO.init.showAndFinish");
133
+ YAHOO.init.show();
134
+ YAHOO.init.after();
135
+ };
136
+
137
+ YAHOO.init.translateToolbar = function() {
138
+ Debug.log("begin YAHOO.init.translateToolbar");
139
+ // will we have a toolbar?
140
+ Debug.log("end YAHOO.init.translateToolbar");
141
+ };
142
+
143
+ YAHOO.init.translateGreeting = function() {
144
+ Debug.log("begin YAHOO.init.translateGreeting");
145
+ };
146
+
147
+ YAHOO.init.translateSubhead = function() {
148
+ Debug.log("YAHOO.init.translateSubhead");
149
+ };
150
+
151
+
152
+ YAHOO.init.translateFooter = function() {
153
+ I18n.update('copyright', 'COPYRIGHT');
154
+ I18n.update('about_link', 'ABOUT');
155
+ I18n.update('support_link', 'SUPPORT');
156
+ I18n.update('contact_link', 'CONTACT');
157
+ I18n.update('privacy_link', 'PRIVACY');
158
+ I18n.update('terms_and_conditions_link', 'TERMS_AND_CONDITIONS');
159
+ };
@@ -0,0 +1,131 @@
1
+ /*
2
+ LAUNCHING
3
+
4
+ global to every view. launches new views and closes the current one.
5
+
6
+ // DO NOT USE the @view instance variable in any files in /app/javascripts/base.
7
+ // The way they are cached makes it not safe to do so.
8
+
9
+ */
10
+
11
+ /* set asset version */
12
+
13
+ var LAUNCHER, Launcher;
14
+
15
+ LAUNCHER = {
16
+ VERSION: "<%= @hash %>",
17
+ MESSAGE: "<%= @message %>",
18
+ DEPLOYED: <%= Time.now.to_i %>,
19
+ DEPLOYED_STRING: "<%= Time.now.to_s %>"
20
+ };
21
+
22
+ YAHOO.namespace("launcher");
23
+
24
+
25
+ YAHOO.launcher.launch = function(view, title, type) {
26
+ openmail.Application.getParameters(function(response) {
27
+ title = I18n.t("APPLICATION_NAME");
28
+ // don't try to relaunch current tab
29
+ if (response.data === null || response.data.view !== view) {
30
+ openmail.Application.openView(
31
+ {
32
+ id: view,
33
+ view: view,
34
+ target: type,
35
+ title: title,
36
+ parameters: {
37
+ launchParams: Params.parameters,
38
+ view: view
39
+ }
40
+ });
41
+ openmail.Application.closeView(null);
42
+ }
43
+ });
44
+ };
45
+
46
+
47
+ YAHOO.launcher.launchTab = function(view, title) {
48
+ YAHOO.launcher.launch(view, title, "tab");
49
+ };
50
+
51
+ // User must be signed in for this page, we'll
52
+ // sign them in if they don't have an OIB cookie
53
+ //
54
+ YAHOO.launcher.launchActiveTab = function(view, title) {
55
+ YAHOO.launcher.launchView(function() {
56
+ YAHOO.launcher.launchTab(view, title);
57
+ });
58
+ };
59
+
60
+
61
+ YAHOO.launcher.launchView = function(launch_view) {
62
+ // get Yahoo! user's guid and ymail_wssid
63
+ YAHOO.oib.getGuidAndYmailWssid(function(guid, ymail_wssid) {
64
+
65
+ // call /ymdp/verify and return data about the user
66
+ YAHOO.oib.verifyUser(function(user) {
67
+
68
+ YAHOO.oib.login = user.login;
69
+
70
+ switch(user.state) {
71
+ case "scanning":
72
+ // formerly known as 'inspect'
73
+ YAHOO.launcher.launchMain();
74
+ break;
75
+ case "authorized":
76
+ // authorized but not yet 'signed in'
77
+ YAHOO.oib.signInUser();
78
+ break;
79
+ case "new_active":
80
+ // no messages processed yet
81
+ case "processing":
82
+ // activated but we have synced fewer than 80% of their messages
83
+ case "active":
84
+ // active, launch the view this method was intended for
85
+ if (View.authorized(user)) {
86
+ launch_view();
87
+ } else {
88
+ YAHOO.launcher.launchAuthorize();
89
+ }
90
+ break;
91
+ default:
92
+ // other
93
+ YAHOO.launcher.launchAuthorize();
94
+ }
95
+ });
96
+ });
97
+ };
98
+
99
+
100
+ YAHOO.launcher.launchAuthorize = function() {
101
+ YAHOO.launcher.launchTab("authorize", "Authorize");
102
+ };
103
+
104
+ YAHOO.launcher.launchDeactivate = function() {
105
+ YAHOO.launcher.launchHidden("deactivate", "Deactivate");
106
+ };
107
+
108
+ YAHOO.launcher.launchHidden = function(view, title) {
109
+ YAHOO.launcher.launch(view, title, "hidden");
110
+ };
111
+
112
+ YAHOO.launcher.l = function(view) {
113
+ view = "launch" + view.capitalize();
114
+ YAHOO.launcher[view]();
115
+ };
116
+
117
+ YAHOO.launcher.launchGoodbye = function() {
118
+ YAHOO.launcher.launchTab("goodbye", "Goodbye");
119
+ };
120
+
121
+ YAHOO.launcher.relaunchAuthorize = YAHOO.launcher.launchAuthorize;
122
+
123
+ YAHOO.launcher.launchMaintenance = function() {
124
+ YAHOO.launcher.launchTab("maintenance", "Maintenance");
125
+ };
126
+
127
+ YAHOO.launcher.launchReauthorize = function() {
128
+ YAHOO.launcher.launchTab("reauthorize", "Reauthorize");
129
+ };
130
+
131
+ Launcher = YAHOO.launcher;