ymdp 0.6.0 → 0.7.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.
Files changed (41) hide show
  1. data/VERSION +1 -1
  2. data/lib/ymdp/configuration/config.rb +10 -0
  3. data/lib/ymdp/javascripts/jquery/ab_testing.js +130 -0
  4. data/lib/ymdp/javascripts/jquery/ajax.js +185 -0
  5. data/lib/ymdp/javascripts/jquery/application.js +139 -0
  6. data/lib/ymdp/javascripts/jquery/authorization.js +119 -0
  7. data/lib/ymdp/javascripts/{browser.js → jquery/browser.js} +0 -0
  8. data/lib/ymdp/javascripts/jquery/data.js +67 -0
  9. data/lib/ymdp/javascripts/jquery/debug.js +98 -0
  10. data/lib/ymdp/javascripts/jquery/education.js +168 -0
  11. data/lib/ymdp/javascripts/jquery/flash.js +76 -0
  12. data/lib/ymdp/javascripts/jquery/help.js +79 -0
  13. data/lib/ymdp/javascripts/jquery/i18n.js +293 -0
  14. data/lib/ymdp/javascripts/jquery/init.js +140 -0
  15. data/lib/ymdp/javascripts/jquery/launcher.js +153 -0
  16. data/lib/ymdp/javascripts/{logger.js → jquery/logger.js} +0 -0
  17. data/lib/ymdp/javascripts/{params.js → jquery/params.js} +0 -0
  18. data/lib/ymdp/javascripts/{reporter.js → jquery/reporter.js} +0 -0
  19. data/lib/ymdp/javascripts/jquery/tag_helper.js +180 -0
  20. data/lib/ymdp/javascripts/jquery/user.js +210 -0
  21. data/lib/ymdp/javascripts/{ab_testing.js → prototype/ab_testing.js} +0 -0
  22. data/lib/ymdp/javascripts/{ajax.js → prototype/ajax.js} +0 -0
  23. data/lib/ymdp/javascripts/{application.js → prototype/application.js} +0 -0
  24. data/lib/ymdp/javascripts/{authorization.js → prototype/authorization.js} +0 -0
  25. data/lib/ymdp/javascripts/prototype/browser.js +36 -0
  26. data/lib/ymdp/javascripts/{data.js → prototype/data.js} +0 -0
  27. data/lib/ymdp/javascripts/{debug.js → prototype/debug.js} +0 -0
  28. data/lib/ymdp/javascripts/{education.js → prototype/education.js} +0 -0
  29. data/lib/ymdp/javascripts/{flash.js → prototype/flash.js} +0 -0
  30. data/lib/ymdp/javascripts/{help.js → prototype/help.js} +0 -0
  31. data/lib/ymdp/javascripts/{i18n.js → prototype/i18n.js} +0 -0
  32. data/lib/ymdp/javascripts/{init.js → prototype/init.js} +0 -0
  33. data/lib/ymdp/javascripts/{launcher.js → prototype/launcher.js} +0 -0
  34. data/lib/ymdp/javascripts/prototype/logger.js +27 -0
  35. data/lib/ymdp/javascripts/prototype/params.js +35 -0
  36. data/lib/ymdp/javascripts/prototype/reporter.js +47 -0
  37. data/lib/ymdp/javascripts/{tag_helper.js → prototype/tag_helper.js} +0 -0
  38. data/lib/ymdp/javascripts/{user.js → prototype/user.js} +0 -0
  39. data/lib/ymdp/view/application_view.rb +5 -1
  40. data/ymdp.gemspec +38 -20
  41. metadata +40 -22
@@ -0,0 +1,140 @@
1
+ /*
2
+
3
+ INITIALIZER CODE
4
+
5
+ */
6
+
7
+ // Adds behaviors/observers to elements on the page
8
+ //
9
+ YMDP.Init.addBehaviors = function() {
10
+ // overwrite this function locally
11
+ };
12
+
13
+ // hide the loading screen and show the main body of the summary
14
+ YMDP.Init.show = function() {
15
+ Debug.log("YMDP.Init.show");
16
+ try {
17
+ $('#utility').hide();
18
+ $('#error').hide();
19
+ $('#loading').hide();
20
+ $('#main').show();
21
+ } catch(e) {
22
+ Debug.error("Error in YMDP.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
+ YMDP.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
+ YMDP.Init.before = function() {
37
+ // overwrite this function locally
38
+ };
39
+
40
+ // Main startup code. Overwrite this function to execute after YMDP.Init.before and before YMDP.Init.after.
41
+ //
42
+ YMDP.Init.startup = function() {
43
+ Debug.log("init.startup");
44
+ // gets the user
45
+ YMDP.getGuid(function(guid) {
46
+ try {
47
+ Reporter.reportCurrentView(guid);
48
+ } catch(omg) {
49
+ Debug.error(omg);
50
+ }
51
+ YMDP.getUserState(YMDP.Init.local, YMDP.Init.local);
52
+ });
53
+ };
54
+
55
+ YMDP.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 YMDP.Init.show()
59
+ //
60
+ YMDP.Init.show();
61
+ YMDP.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
+ YMDP.Init.finish = function() {
68
+ // try {
69
+ Debug.log("init.finish for view " + View.name);
70
+ YMDP.showTranslations();
71
+ Debug.log("addBehaviors:");
72
+ YMDP.Init.addBehaviors();
73
+ Debug.log("abTesting:");
74
+ YMDP.Init.abTesting();
75
+ Debug.log("page_loaded = true:");
76
+ View.page_loaded = true;
77
+ Debug.log("finished init.finish for view " + View.name);
78
+ // } catch(omg) {
79
+ // Debug.error("Error in YMDP.Init.finish", omg);
80
+ // YMDP.showError({
81
+ // "method": "YMDP.Init.finish",
82
+ // "description": "exception caught in YMDP.Init.finish",
83
+ // "error": omg
84
+ // });
85
+ // }
86
+ };
87
+
88
+ // Post-initalizer. Very last thing that runs, after content has been shown.
89
+ //
90
+ YMDP.Init.after = function() {
91
+ // overwrite this function locally
92
+ };
93
+
94
+ // Execute the before, startup and after methods. Do not overwrite. (Change YMDP.Init.startup to create a custom initializer.)
95
+ YMDP.init = function() {
96
+ Debug.log("OIB.init for view " + View.name, "<%= @message %>");
97
+ try {
98
+ Logger.init();
99
+ Tags.init();
100
+ YMDP.Init.browser();
101
+ YMDP.Init.resources();
102
+ I18n.addLanguageToBody();
103
+ I18n.translateLoading();
104
+ I18n.translateError();
105
+ YMDP.Init.before();
106
+ YMDP.Init.startup();
107
+ } catch(err_f) {
108
+ YMDP.showError({
109
+ "method": "YMDP.init",
110
+ "description": "exception caught in YMDP.init",
111
+ "error": err_f
112
+ });
113
+ Debug.error("Error in YMDP.init", err_f);
114
+ }
115
+ };
116
+
117
+ YMDP.Init.browser = function() {
118
+ if ($.browser.webkit) {
119
+ $('body').addClass('webkit');
120
+ }
121
+ };
122
+
123
+ YMDP.Init.resources = function() {
124
+ Debug.log("about to call I18n.setResources");
125
+
126
+ I18n.availableLanguages = <%= supported_languages.to_json %>;
127
+
128
+ I18n.currentLanguage = OpenMailIntl.findBestLanguage(I18n.availableLanguages);
129
+
130
+ I18n.setResources();
131
+
132
+ Debug.log("finished calling I18n.setResources");
133
+ };
134
+
135
+ // Contains the last two callbacks, to show the page contents and run post-show function. Do not overwrite.
136
+ YMDP.Init.showAndFinish = function() {
137
+ Debug.log("YMDP.Init.showAndFinish");
138
+ YMDP.Init.show();
139
+ YMDP.Init.after();
140
+ };
@@ -0,0 +1,153 @@
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;
14
+
15
+ Launcher = {};
16
+
17
+ Launcher.launch = function(view, title, type) {
18
+ openmail.Application.getParameters(function(response) {
19
+ title = I18n.t("APPLICATION_NAME");
20
+ // don't try to relaunch current tab
21
+ if (response.data === null || response.data.view !== view) {
22
+ openmail.Application.openView(
23
+ {
24
+ id: view,
25
+ view: view,
26
+ target: type,
27
+ title: title,
28
+ parameters: {
29
+ launchParams: Params.parameters,
30
+ view: view
31
+ }
32
+ });
33
+ openmail.Application.closeView(null);
34
+ }
35
+ });
36
+ };
37
+
38
+
39
+ Launcher.launchView = function(launch_view) {
40
+ var user;
41
+
42
+ user = YMDP.user || {"state": "active"};
43
+
44
+ switch(user.state) {
45
+ case "scanning":
46
+ // formerly known as 'inspect'
47
+ Launcher.launchScanning();
48
+ break;
49
+ case "summary":
50
+ Launcher.launchSummary();
51
+ break;
52
+ case "authorized":
53
+ // authorized but not yet 'signed in'
54
+ YMDP.signInUser();
55
+ break;
56
+ case "new_active":
57
+ // no messages processed yet
58
+ case "processing":
59
+ // activated but we have synced fewer than 80% of their messages
60
+ case "active":
61
+ // active, launch the view this method was intended for
62
+ launch_view();
63
+ break;
64
+ default:
65
+ // other
66
+ Launcher.launchAuthorize();
67
+ }
68
+ };
69
+
70
+
71
+ Launcher.launchTab = function(view, title) {
72
+ Launcher.launch(view, title, "tab");
73
+ };
74
+
75
+ // User must be signed in for this page, we'll
76
+ // sign them in if they don't have an OIB cookie
77
+ //
78
+ Launcher.launchActiveTab = function(view, title) {
79
+ Launcher.launchTab(view, title);
80
+ };
81
+
82
+
83
+ Launcher.launchAuthorize = function() {
84
+ Launcher.launchTab("authorize", "Authorize");
85
+ };
86
+
87
+ Launcher.launchDeactivate = function() {
88
+ Launcher.launchHidden("deactivate", "Deactivate");
89
+ };
90
+
91
+ Launcher.launchHidden = function(view, title) {
92
+ Launcher.launch(view, title, "hidden");
93
+ };
94
+
95
+ Launcher.l = function(view) {
96
+ view = "launch" + view.capitalize();
97
+ Launcher[view]();
98
+ };
99
+
100
+ Launcher.launchGoodbye = function() {
101
+ Launcher.launchTab("goodbye", "Goodbye");
102
+ };
103
+
104
+ Launcher.relaunchAuthorize = Launcher.launchAuthorize;
105
+
106
+ Launcher.launchMaintenance = function() {
107
+ Launcher.launchTab("maintenance", "Maintenance");
108
+ };
109
+
110
+ Launcher.launchReauthorize = function() {
111
+ Launcher.launchTab("reauthorize", "Reauthorize");
112
+ };
113
+
114
+ Launcher.launchView = function(launch_view) {
115
+ // get Yahoo! user's guid and ymail_wssid
116
+ YMDP.getGuidAndYmailWssid(function(guid, ymail_wssid) {
117
+
118
+ // call /ymdp/verify and return data about the user
119
+ YMDP.verifyUser(function(user) {
120
+
121
+ YMDP.login = user.login;
122
+
123
+ switch(user.state) {
124
+ case "scanning":
125
+ // formerly known as 'inspect'
126
+ Launcher.launchScanning();
127
+ break;
128
+ case "summary":
129
+ Launcher.launchSummary();
130
+ break;
131
+ case "authorized":
132
+ // authorized but not yet 'signed in'
133
+ YMDP.signInUser();
134
+ break;
135
+ case "new_active":
136
+ // no messages processed yet
137
+ case "processing":
138
+ // activated but we have synced fewer than 80% of their messages
139
+ case "active":
140
+ // active, launch the view this method was intended for
141
+ launch_view();
142
+ break;
143
+ default:
144
+ // other
145
+ Launcher.launchAuthorize();
146
+ }
147
+ });
148
+ });
149
+ };
150
+
151
+ Launcher.launchMain = function() {
152
+ Launcher.launchView(Launcher.launchFolders);
153
+ };
@@ -0,0 +1,180 @@
1
+ /* TAG HELPERS */
2
+
3
+
4
+ // DO NOT USE the @view instance variable in any files in /app/javascripts/base.
5
+ // The way they are cached makes it not safe to do so.
6
+
7
+ var Tags;
8
+
9
+ function tagHelper(tag_name, text, options) {
10
+ var m, opts;
11
+
12
+ m = "";
13
+ opts = "";
14
+
15
+ Object.keys(options).each(function(key) {
16
+ opts = opts + " " + key + "='" + options[key] + "'";
17
+ });
18
+
19
+ m = m + "<" + tag_name + " " + opts + ">";
20
+ m = m + text;
21
+ m = m + "<\/" + tag_name + ">";
22
+ return m;
23
+ }
24
+
25
+ function optionTag(text, options) {
26
+ return tagHelper("option", text, options);
27
+ }
28
+
29
+ function selectTag(text, options) {
30
+ return tagHelper("select", text, options);
31
+ }
32
+
33
+ function spanTag(text, options) {
34
+ return tagHelper("span", text, options);
35
+ }
36
+
37
+ function liTag(text, options) {
38
+ return tagHelper("li", text, options);
39
+ }
40
+
41
+ function divTag(text, options) {
42
+ return tagHelper("div", text, options);
43
+ }
44
+
45
+ function tdTag(text, options) {
46
+ return tagHelper("td", text, options);
47
+ }
48
+
49
+ function inputTag(value, options) {
50
+ options['value'] = value;
51
+ return tagHelper("input", "", options);
52
+ }
53
+
54
+ function textField(value, options) {
55
+ return inputTag(value, options);
56
+ }
57
+
58
+ function submitTag(value, options) {
59
+ options['type'] = 'submit';
60
+ return inputTag(value, options);
61
+ }
62
+
63
+ function optionsForSelect(options, selected) {
64
+ var m;
65
+ m = "";
66
+ options.each(function(option) {
67
+ var key, value, opts;
68
+
69
+ if (Object.isArray(option)) {
70
+ key = option[0];
71
+ value = option[1];
72
+ } else {
73
+ key = option;
74
+ value = option;
75
+ }
76
+
77
+ opts = {
78
+ value: value
79
+ };
80
+
81
+ if (key === selected) {
82
+ opts.selected = 'selected';
83
+ }
84
+
85
+ m = m + optionTag(key, opts);
86
+ });
87
+ return m;
88
+ }
89
+
90
+ Tags = {
91
+ create: function(tag_name, text, options) {
92
+ options = options || {};
93
+ var m, opts;
94
+
95
+ m = "";
96
+ opts = "";
97
+
98
+ Object.keys(options).each(function(key) {
99
+ if (options[key]) {
100
+ opts = opts + " " + key + "='" + options[key] + "'";
101
+ }
102
+ });
103
+
104
+ m = m + "<" + tag_name + " " + opts + ">";
105
+ m = m + text;
106
+ m = m + "<\/" + tag_name + ">";
107
+ return m;
108
+ },
109
+
110
+ input: function(value, options) {
111
+ options = options || {};
112
+ options["value"] = value;
113
+ options["name"] = options["name"] || "";
114
+ options["id"] = options["id"] || options["name"];
115
+
116
+ return Tags.create("input", "", options);
117
+ },
118
+
119
+ hiddenInput: function(value, options) {
120
+ options = options || {};
121
+ options["type"] = "hidden";
122
+ return Tags.input(value, options);
123
+ },
124
+
125
+ checkBox: function(name, options) {
126
+ options = options || {};
127
+ var check_box, hidden_options, hidden_check_box;
128
+
129
+ options["type"] = "checkbox";
130
+ options["name"] = name;
131
+
132
+ if (options["checked"]) {
133
+ options["checked"] = "checked";
134
+ } else {
135
+ options["checked"] = undefined;
136
+ }
137
+
138
+ check_box = Tags.input("1", options);
139
+
140
+ hidden_options = {
141
+ "name": name
142
+ };
143
+ hidden_check_box = Tags.hiddenInput("0", hidden_options);
144
+
145
+ return check_box + " " + hidden_check_box;
146
+ },
147
+
148
+ submit: function(value, options) {
149
+ options = options || {};
150
+ options["value"] = value;
151
+ options["id"] = options["id"] || options["name"];
152
+ options["type"] = "submit";
153
+ return Tags.input(value, options);
154
+ },
155
+
156
+ linkToFunction: function(value, onclick, options) {
157
+ options = options || {};
158
+ var jv;
159
+
160
+ jv = "#";
161
+ options["href"] = options["href"] || jv;
162
+ options["onclick"] = onclick;
163
+ return Tags.a(value, options);
164
+ },
165
+
166
+ div: function(text, options) {
167
+ return new Element('div', options).update(text);
168
+ },
169
+
170
+ init: function() {
171
+ for (tag_name in ["li", "ol", "ul", "span", "div", "p", "a", "option", "select", "strong", "table", "th", "tr", "td"]) {
172
+ Tags[tag_name] = function(text, options) {
173
+ options = options || {};
174
+ return Tags.create(tag_name, text, options);
175
+ };
176
+ };
177
+ }
178
+ };
179
+
180
+ /* END TAG HELPERS */