ymdp 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/ymdp/javascripts/ab_testing.js +130 -0
- data/lib/ymdp/javascripts/ajax.js +165 -0
- data/lib/ymdp/javascripts/application.js +139 -0
- data/lib/ymdp/javascripts/browser.js +36 -0
- data/lib/ymdp/javascripts/data.js +67 -0
- data/lib/ymdp/javascripts/debug.js +109 -0
- data/lib/ymdp/javascripts/education.js +166 -0
- data/lib/ymdp/javascripts/flash.js +100 -0
- data/lib/ymdp/javascripts/help.js +79 -0
- data/lib/ymdp/javascripts/i18n.js +242 -0
- data/lib/ymdp/javascripts/init.js +159 -0
- data/lib/ymdp/javascripts/launcher.js +131 -0
- data/lib/ymdp/javascripts/logger.js +64 -0
- data/lib/ymdp/javascripts/params.js +35 -0
- data/lib/ymdp/javascripts/reporter.js +47 -0
- data/lib/ymdp/javascripts/tag_helper.js +182 -0
- data/lib/ymdp/javascripts/user.js +207 -0
- data/lib/ymdp/view/application_view.rb +34 -4
- data/ymdp.gemspec +19 -2
- metadata +22 -5
@@ -0,0 +1,64 @@
|
|
1
|
+
/*
|
2
|
+
YMDP LOGGER
|
3
|
+
|
4
|
+
Send logging messages to OIB.
|
5
|
+
|
6
|
+
Messages are saved in log/ymdp.log
|
7
|
+
|
8
|
+
|
9
|
+
// DO NOT USE the @view instance variable in any files in /app/javascripts/base.
|
10
|
+
// The way they are cached makes it not safe to do so.
|
11
|
+
|
12
|
+
*/
|
13
|
+
|
14
|
+
|
15
|
+
/* set asset version */
|
16
|
+
|
17
|
+
var LOGGER, Logger;
|
18
|
+
|
19
|
+
LOGGER = {
|
20
|
+
VERSION: "<%= @hash %>",
|
21
|
+
MESSAGE: "<%= @message %>",
|
22
|
+
DEPLOYED: <%= Time.now.to_i %>,
|
23
|
+
DEPLOYED_STRING: "<%= Time.now.to_s %>"
|
24
|
+
};
|
25
|
+
|
26
|
+
YAHOO.namespace("logger");
|
27
|
+
|
28
|
+
YAHOO.logger.write = function(level, message) {
|
29
|
+
if (YAHOO.oib.login) {
|
30
|
+
message = "[login: " + YAHOO.oib.login + "] " + message;
|
31
|
+
}
|
32
|
+
if (YAHOO.oib.guid) {
|
33
|
+
message = "[guid: " + YAHOO.oib.guid + "] " + message;
|
34
|
+
}
|
35
|
+
OIB.post("ymdp/log",
|
36
|
+
{
|
37
|
+
level: level,
|
38
|
+
message: message
|
39
|
+
},
|
40
|
+
function(response) {
|
41
|
+
// log message written successfully
|
42
|
+
});
|
43
|
+
};
|
44
|
+
|
45
|
+
YAHOO.logger.debug = function(message) {
|
46
|
+
YAHOO.logger.write("debug", message);
|
47
|
+
};
|
48
|
+
YAHOO.logger.info = function(message) {
|
49
|
+
YAHOO.logger.write("info", message);
|
50
|
+
};
|
51
|
+
YAHOO.logger.warn = function(message) {
|
52
|
+
YAHOO.logger.write("warn", message);
|
53
|
+
};
|
54
|
+
YAHOO.logger.error = function(message) {
|
55
|
+
YAHOO.logger.write("warn", message);
|
56
|
+
};
|
57
|
+
YAHOO.logger.fatal = function(message) {
|
58
|
+
YAHOO.logger.write("fatal", message);
|
59
|
+
};
|
60
|
+
|
61
|
+
|
62
|
+
Logger = YAHOO.logger;
|
63
|
+
|
64
|
+
// END YMDP LOGGER
|
@@ -0,0 +1,35 @@
|
|
1
|
+
var Params = {
|
2
|
+
names: ["invitation", "page"],
|
3
|
+
parameters: {},
|
4
|
+
|
5
|
+
init: function(launchParams) {
|
6
|
+
launchParams = launchParams || {};
|
7
|
+
Debug.log("Params.init", launchParams);
|
8
|
+
|
9
|
+
try {
|
10
|
+
if (launchParams) {
|
11
|
+
Params.parameters = launchParams;
|
12
|
+
} else {
|
13
|
+
Params.parameters = {};
|
14
|
+
}
|
15
|
+
} catch(wtf) {
|
16
|
+
Debug.error(wtf);
|
17
|
+
}
|
18
|
+
},
|
19
|
+
|
20
|
+
get: function(name) {
|
21
|
+
Debug.log("Params.get", name);
|
22
|
+
var index, result;
|
23
|
+
|
24
|
+
try {
|
25
|
+
index = Params.names.indexOf(name);
|
26
|
+
|
27
|
+
if (index >= 0) {
|
28
|
+
result = Params.parameters["param" + index];
|
29
|
+
}
|
30
|
+
} catch(wtf) {
|
31
|
+
Debug.error(wtf);
|
32
|
+
}
|
33
|
+
return result;
|
34
|
+
}
|
35
|
+
};
|
@@ -0,0 +1,47 @@
|
|
1
|
+
// DO NOT USE the @view instance variable in any files in /app/javascripts/base.
|
2
|
+
// The way they are cached makes it not safe to do so.
|
3
|
+
|
4
|
+
var Reporter;
|
5
|
+
|
6
|
+
// Reports pageviews to OIB for tracking counts of each pageview.
|
7
|
+
//
|
8
|
+
// The main interface to this class is located in "header.js" where it can
|
9
|
+
// make use of the current view name.
|
10
|
+
//
|
11
|
+
// == Usage
|
12
|
+
//
|
13
|
+
// Reporter.reportCurrentView(guid);
|
14
|
+
//
|
15
|
+
Reporter = {
|
16
|
+
error: function(guid, params) {
|
17
|
+
Debug.log("Reporter.error", params);
|
18
|
+
Reporter.report(guid, "error", params);
|
19
|
+
},
|
20
|
+
|
21
|
+
reportCurrentView: function(guid) {
|
22
|
+
Reporter.report(guid, View.name);
|
23
|
+
},
|
24
|
+
|
25
|
+
// Report the Ymail guid and page view name to OIB.
|
26
|
+
//
|
27
|
+
report: function(guid, view, params) {
|
28
|
+
params = params || {};
|
29
|
+
|
30
|
+
params["ymail_guid"] = guid;
|
31
|
+
params["view"] = view;
|
32
|
+
|
33
|
+
Debug.log("Reporting guid " + guid + ", view " + view);
|
34
|
+
// Reporter.post(params);
|
35
|
+
},
|
36
|
+
|
37
|
+
// Post data back to OIB, to the URL /ymdp/report.
|
38
|
+
//
|
39
|
+
post: function(params) {
|
40
|
+
params = params || {};
|
41
|
+
OIB.post("ymdp/report", params, function(response) {
|
42
|
+
Debug.log("Reported page view", params);
|
43
|
+
}, function(response) {
|
44
|
+
Debug.error("Error reporting page view with params", response);
|
45
|
+
});
|
46
|
+
},
|
47
|
+
};
|
@@ -0,0 +1,182 @@
|
|
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
|
+
$w("li ol ul span div p a option select strong table th tr td").each(function(tag_name) {
|
172
|
+
Tags[tag_name] = function(text, options) {
|
173
|
+
options = options || {};
|
174
|
+
return Tags.create(tag_name, text, options);
|
175
|
+
};
|
176
|
+
});
|
177
|
+
}
|
178
|
+
};
|
179
|
+
|
180
|
+
Tags.init();
|
181
|
+
|
182
|
+
/* END TAG HELPERS */
|
@@ -0,0 +1,207 @@
|
|
1
|
+
// gets both guid and ymail_wssid and stores them then runs the callback_function
|
2
|
+
//
|
3
|
+
// YAHOO.oib.ymail_wssid
|
4
|
+
// YAHOO.oib.guid
|
5
|
+
//
|
6
|
+
YAHOO.oib.getGuidAndYmailWssid = function(callback_function) {
|
7
|
+
Debug.log("YAHOO.oib.getGuidAndYmailWssid");
|
8
|
+
YAHOO.oib.getGuid(function(guid) {
|
9
|
+
YAHOO.oib.getYmailWssid(function(ymail_wssid) {
|
10
|
+
callback_function(guid, ymail_wssid);
|
11
|
+
});
|
12
|
+
});
|
13
|
+
};
|
14
|
+
|
15
|
+
// gets user's state info from /ymdp/state
|
16
|
+
// including the user's OIB login
|
17
|
+
//
|
18
|
+
YAHOO.oib.getUserState = function(success_function) {
|
19
|
+
Debug.log("YAHOO.oib.getUserState");
|
20
|
+
OIB.get("ymdp/state", {}, function(response) {
|
21
|
+
Debug.log("YAHOO.oib.getUserState callback", response);
|
22
|
+
YAHOO.oib.response = response;
|
23
|
+
try {
|
24
|
+
YAHOO.oib.since_date = formatUnixDate(YAHOO.oib.response.since_date.s);
|
25
|
+
} catch(omg) {
|
26
|
+
YAHOO.oib.since_date = 1294869484;
|
27
|
+
}
|
28
|
+
YAHOO.oib.login = response.login;
|
29
|
+
YAHOO.oib.state = response.state;
|
30
|
+
|
31
|
+
if (success_function) {
|
32
|
+
Debug.log("YAHOO.oib.getUserState: About to success function")
|
33
|
+
success_function(response);
|
34
|
+
}
|
35
|
+
},
|
36
|
+
function() {
|
37
|
+
YAHOO.logger.error("Failed to get user's state");
|
38
|
+
});
|
39
|
+
};
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
/*
|
44
|
+
YAHOO.oib.verifyUser
|
45
|
+
|
46
|
+
global to all views. calls the 'verify' action on ymdp controller and executes
|
47
|
+
a function with the result.
|
48
|
+
*/
|
49
|
+
YAHOO.oib.verifyUser = function(success_function, error_function) {
|
50
|
+
Debug.log("YAHOO.oib.verifyUser");
|
51
|
+
|
52
|
+
OIB.get("ymdp/verify", {
|
53
|
+
ymail_guid: YAHOO.oib.guid,
|
54
|
+
ymail_wssid: YAHOO.oib.ymail_wssid,
|
55
|
+
application: View.application
|
56
|
+
}, function(response) {
|
57
|
+
YAHOO.oib.user = response;
|
58
|
+
Debug.log("YAHOO.oib.verifyUser YAHOO.oib.user", YAHOO.oib.user);
|
59
|
+
if (success_function) {
|
60
|
+
Debug.log("YAHOO.oib.verifyUser: About to success function");
|
61
|
+
success_function(YAHOO.oib.user);
|
62
|
+
}
|
63
|
+
}, error_function);
|
64
|
+
};
|
65
|
+
|
66
|
+
|
67
|
+
/*
|
68
|
+
AUTHENTICATION
|
69
|
+
*/
|
70
|
+
|
71
|
+
YAHOO.oib.signInUser = function() {
|
72
|
+
Debug.log("YAHOO.oib.signInUser");
|
73
|
+
OIB.get("ymdp/signin", {}, function(response) {
|
74
|
+
Debug.log("inside ymdp/signin callback", response);
|
75
|
+
Debug.log("YAHOO.oib.response", YAHOO.oib.response);
|
76
|
+
if (response.ymail_wssid === "false") {
|
77
|
+
// signin didn't work properly, display an error
|
78
|
+
Debug.log("YAHOO.oib.response was false");
|
79
|
+
YAHOO.oib.showError({
|
80
|
+
"method": "YAHOO.oib.signInUser",
|
81
|
+
"description": "no ymail_wssid"
|
82
|
+
});
|
83
|
+
} else {
|
84
|
+
Debug.log("YAHOO.oib.response wasn't false");
|
85
|
+
// store ymail_wssid in permanent store
|
86
|
+
|
87
|
+
var raw_wssid = response.ymail_wssid || "";
|
88
|
+
var sliced_wssid = raw_wssid.slice(0, 255);
|
89
|
+
|
90
|
+
var data = {
|
91
|
+
"ymail_wssid": sliced_wssid
|
92
|
+
};
|
93
|
+
|
94
|
+
Debug.log("About to call Data.sore", data);
|
95
|
+
|
96
|
+
Data.store(data);
|
97
|
+
YAHOO.oib.ymail_wssid = response.ymail_wssid;
|
98
|
+
|
99
|
+
YAHOO.oib.verifyUser(YAHOO.launcher.launchMain);
|
100
|
+
}
|
101
|
+
});
|
102
|
+
};
|
103
|
+
|
104
|
+
|
105
|
+
// gets the guid from the Yahoo! environment and executes the success callback
|
106
|
+
// if there is a guid, and the error callback if it's undefined
|
107
|
+
//
|
108
|
+
// YAHOO.oib.guid
|
109
|
+
//
|
110
|
+
YAHOO.oib.getGuid = function(success_function, error_function) {
|
111
|
+
Debug.log("YAHOO.oib.getGuid");
|
112
|
+
|
113
|
+
openmail.Application.getParameters(function(response) {
|
114
|
+
YAHOO.oib.guid = response.user.guid;
|
115
|
+
try {
|
116
|
+
Debug.log("YAHOO.oib.getGuid getParameters response", response);
|
117
|
+
|
118
|
+
var params = {};
|
119
|
+
if (response.data) {
|
120
|
+
params = response.data.launchParams;
|
121
|
+
}
|
122
|
+
Params.init(params);
|
123
|
+
} catch(omg) {
|
124
|
+
Debug.error("error getting parameters: " + omg);
|
125
|
+
}
|
126
|
+
if (YAHOO.oib.guid !== undefined) {
|
127
|
+
Try.these(
|
128
|
+
function() { success_function(YAHOO.oib.guid); }
|
129
|
+
);
|
130
|
+
}
|
131
|
+
else {
|
132
|
+
Try.these(error_function);
|
133
|
+
}
|
134
|
+
});
|
135
|
+
};
|
136
|
+
|
137
|
+
|
138
|
+
// gets the ymail_wssid from the permanent store and executes the callback function
|
139
|
+
// if there is a ymail_wssid, and the error callback if it's undefined
|
140
|
+
//
|
141
|
+
// YAHOO.oib.ymail_wssid
|
142
|
+
//
|
143
|
+
YAHOO.oib.getYmailWssid = function(success_function, error_function) {
|
144
|
+
Debug.log("YAHOO.oib.getYmailWssid");
|
145
|
+
|
146
|
+
// this function will show the error page if the ymail_wssid has not been set
|
147
|
+
//
|
148
|
+
var show_error = function() {
|
149
|
+
if (YAHOO.oib.ymail_wssid === undefined) {
|
150
|
+
Debug.log("No YAHOO.oib.ymail_wssid");
|
151
|
+
|
152
|
+
YAHOO.oib.showError({
|
153
|
+
"retry": "hide"
|
154
|
+
});
|
155
|
+
} else {
|
156
|
+
Debug.log("YAHOO.oib.ymail_wssid does exist", YAHOO.oib.ymail_wssid);
|
157
|
+
}
|
158
|
+
};
|
159
|
+
|
160
|
+
// run the show_error function after 5 seconds
|
161
|
+
//
|
162
|
+
Debug.log("Set timeout for error function to 5 seconds");
|
163
|
+
YAHOO.oib.setTimeoutInSeconds(show_error, 5);
|
164
|
+
Debug.log("About to call Data.fetch");
|
165
|
+
|
166
|
+
// retrieve the user's ymail_wssid and store it in YAHOO.oib.ymail_wssid
|
167
|
+
//
|
168
|
+
Data.fetch(["ymail_wssid"], function(response) {
|
169
|
+
Debug.log("Inside Data.fetch callback");
|
170
|
+
YAHOO.oib.ymail_wssid = response.data.ymail_wssid;
|
171
|
+
if (YAHOO.oib.ymail_wssid !== undefined) {
|
172
|
+
Debug.log("YAHOO.oib.ymail_wssid is defined", YAHOO.oib.ymail_wssid);
|
173
|
+
|
174
|
+
try {
|
175
|
+
success_function(YAHOO.oib.ymail_wssid);
|
176
|
+
} catch(omg) {
|
177
|
+
Debug.error("Error in YAHOO.oib.getYmailWssid getData callback", omg);
|
178
|
+
}
|
179
|
+
|
180
|
+
}
|
181
|
+
else {
|
182
|
+
Try.these(error_function);
|
183
|
+
}
|
184
|
+
});
|
185
|
+
};
|
186
|
+
|
187
|
+
YAHOO.oib.deactivateUser = function() {
|
188
|
+
YAHOO.oib.getGuidAndYmailWssid(function() {
|
189
|
+
var guid, ymail_wssid;
|
190
|
+
|
191
|
+
guid = YAHOO.oib.guid;
|
192
|
+
ymail_wssid = YAHOO.oib.ymail_wssid;
|
193
|
+
|
194
|
+
Data.clear();
|
195
|
+
|
196
|
+
OIB.post("/ymdp/deactivate", {
|
197
|
+
"ymail_guid": guid,
|
198
|
+
"ymail_wssid": ymail_wssid
|
199
|
+
},
|
200
|
+
function(response) {
|
201
|
+
// YAHOO.logger.info("Finished deactivating user");
|
202
|
+
if (View.name !== "deactivate") {
|
203
|
+
YAHOO.launcher.launchGoodbye();
|
204
|
+
}
|
205
|
+
});
|
206
|
+
});
|
207
|
+
};
|