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.
- data/VERSION +1 -1
- data/lib/ymdp/configuration/config.rb +10 -0
- data/lib/ymdp/javascripts/jquery/ab_testing.js +130 -0
- data/lib/ymdp/javascripts/jquery/ajax.js +185 -0
- data/lib/ymdp/javascripts/jquery/application.js +139 -0
- data/lib/ymdp/javascripts/jquery/authorization.js +119 -0
- data/lib/ymdp/javascripts/{browser.js → jquery/browser.js} +0 -0
- data/lib/ymdp/javascripts/jquery/data.js +67 -0
- data/lib/ymdp/javascripts/jquery/debug.js +98 -0
- data/lib/ymdp/javascripts/jquery/education.js +168 -0
- data/lib/ymdp/javascripts/jquery/flash.js +76 -0
- data/lib/ymdp/javascripts/jquery/help.js +79 -0
- data/lib/ymdp/javascripts/jquery/i18n.js +293 -0
- data/lib/ymdp/javascripts/jquery/init.js +140 -0
- data/lib/ymdp/javascripts/jquery/launcher.js +153 -0
- data/lib/ymdp/javascripts/{logger.js → jquery/logger.js} +0 -0
- data/lib/ymdp/javascripts/{params.js → jquery/params.js} +0 -0
- data/lib/ymdp/javascripts/{reporter.js → jquery/reporter.js} +0 -0
- data/lib/ymdp/javascripts/jquery/tag_helper.js +180 -0
- data/lib/ymdp/javascripts/jquery/user.js +210 -0
- data/lib/ymdp/javascripts/{ab_testing.js → prototype/ab_testing.js} +0 -0
- data/lib/ymdp/javascripts/{ajax.js → prototype/ajax.js} +0 -0
- data/lib/ymdp/javascripts/{application.js → prototype/application.js} +0 -0
- data/lib/ymdp/javascripts/{authorization.js → prototype/authorization.js} +0 -0
- data/lib/ymdp/javascripts/prototype/browser.js +36 -0
- data/lib/ymdp/javascripts/{data.js → prototype/data.js} +0 -0
- data/lib/ymdp/javascripts/{debug.js → prototype/debug.js} +0 -0
- data/lib/ymdp/javascripts/{education.js → prototype/education.js} +0 -0
- data/lib/ymdp/javascripts/{flash.js → prototype/flash.js} +0 -0
- data/lib/ymdp/javascripts/{help.js → prototype/help.js} +0 -0
- data/lib/ymdp/javascripts/{i18n.js → prototype/i18n.js} +0 -0
- data/lib/ymdp/javascripts/{init.js → prototype/init.js} +0 -0
- data/lib/ymdp/javascripts/{launcher.js → prototype/launcher.js} +0 -0
- data/lib/ymdp/javascripts/prototype/logger.js +27 -0
- data/lib/ymdp/javascripts/prototype/params.js +35 -0
- data/lib/ymdp/javascripts/prototype/reporter.js +47 -0
- data/lib/ymdp/javascripts/{tag_helper.js → prototype/tag_helper.js} +0 -0
- data/lib/ymdp/javascripts/{user.js → prototype/user.js} +0 -0
- data/lib/ymdp/view/application_view.rb +5 -1
- data/ymdp.gemspec +38 -20
- metadata +40 -22
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
@@ -67,6 +67,8 @@ module YMDP
|
|
67
67
|
|
68
68
|
attr_accessor :external_assets
|
69
69
|
|
70
|
+
attr_accessor :javascript_library
|
71
|
+
|
70
72
|
def initialize #:nodoc:
|
71
73
|
@paths = {}
|
72
74
|
@content_variables = {}
|
@@ -91,6 +93,14 @@ module YMDP
|
|
91
93
|
path = "#{path}.yml"
|
92
94
|
@content_variables = YAML.load_file(path)
|
93
95
|
end
|
96
|
+
|
97
|
+
def prototype
|
98
|
+
@javascript_library = "prototype"
|
99
|
+
end
|
100
|
+
|
101
|
+
def jquery
|
102
|
+
@javascript_library = "jquery"
|
103
|
+
end
|
94
104
|
end
|
95
105
|
|
96
106
|
class Base
|
@@ -0,0 +1,130 @@
|
|
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
|
+
var ABTesting;
|
6
|
+
|
7
|
+
ABTesting = {
|
8
|
+
on: true,
|
9
|
+
languages: <%= english_languages.to_json %>,
|
10
|
+
|
11
|
+
enable: function() {
|
12
|
+
ABTesting.on = true;
|
13
|
+
},
|
14
|
+
|
15
|
+
disable: function() {
|
16
|
+
ABTesting.on = false;
|
17
|
+
},
|
18
|
+
|
19
|
+
randomAB: function() {
|
20
|
+
return Math.floor(Math.random()*2) ? "a" : "b";
|
21
|
+
},
|
22
|
+
|
23
|
+
get: function(content_id) {
|
24
|
+
var url, host;
|
25
|
+
|
26
|
+
url = "ymdp/experiment";
|
27
|
+
|
28
|
+
OIB.get(url, {
|
29
|
+
"domain": View.domain
|
30
|
+
}, function(response) {
|
31
|
+
ABTesting.success(content_id, response);
|
32
|
+
}, function(response) {
|
33
|
+
ABTesting.error(response);
|
34
|
+
});
|
35
|
+
},
|
36
|
+
|
37
|
+
post: function(params) {
|
38
|
+
params = params || {};
|
39
|
+
OIB.post("ymdp/view", params, function(response) {
|
40
|
+
Debug.log("ABTesting.post success", response);
|
41
|
+
}, function(response) {
|
42
|
+
Debug.error("ABTesting.post error", response);
|
43
|
+
});
|
44
|
+
},
|
45
|
+
|
46
|
+
postView: function(experimentId) {
|
47
|
+
var params;
|
48
|
+
|
49
|
+
params = {
|
50
|
+
"var": ABTesting.variable
|
51
|
+
};
|
52
|
+
if (experimentId) {
|
53
|
+
params["experiment_id"] = experimentId;
|
54
|
+
}
|
55
|
+
Debug.log("ABTesting.postView: ", params);
|
56
|
+
ABTesting.post(params);
|
57
|
+
},
|
58
|
+
|
59
|
+
setVariable: function(value) {
|
60
|
+
ABTesting.variable = value;
|
61
|
+
},
|
62
|
+
|
63
|
+
apply: function(content_id, language) {
|
64
|
+
try {
|
65
|
+
if (ABTesting.on && $.inArray(language, ABTesting.languages) >= 0) {
|
66
|
+
var index;
|
67
|
+
|
68
|
+
index = ABTesting.randomAB();
|
69
|
+
ABTesting.setVariable(index);
|
70
|
+
|
71
|
+
ABTesting.get(content_id);
|
72
|
+
} else {
|
73
|
+
YMDP.Init.showAndFinish();
|
74
|
+
}
|
75
|
+
}
|
76
|
+
catch(e) {
|
77
|
+
Debug.log(e);
|
78
|
+
YMDP.Init.showAndFinish();
|
79
|
+
}
|
80
|
+
},
|
81
|
+
|
82
|
+
error: function(data) {
|
83
|
+
Debug.log("applyError", data);
|
84
|
+
if (data.error !== 3002) {
|
85
|
+
Debug.error("Received body contents fetch error on page " + View.name + ": " + data.error + ' - ' + data.errorMsg);
|
86
|
+
}
|
87
|
+
YMDP.Init.showAndFinish();
|
88
|
+
},
|
89
|
+
|
90
|
+
success: function(content_id, response) {
|
91
|
+
try {
|
92
|
+
var content, experiment, experimentId;
|
93
|
+
Debug.log("ABTesting.success", response);
|
94
|
+
|
95
|
+
experiment = response.experiment;
|
96
|
+
|
97
|
+
if (experiment) {
|
98
|
+
content = ABTesting.content(experiment);
|
99
|
+
experimentId = response.experiment.id;
|
100
|
+
|
101
|
+
ABTesting.postView(experimentId);
|
102
|
+
ABTesting.replaceContents(content_id, content);
|
103
|
+
} else {
|
104
|
+
Debug.log("No experiment running");
|
105
|
+
}
|
106
|
+
|
107
|
+
YMDP.Init.showAndFinish();
|
108
|
+
} catch(e) {
|
109
|
+
Debug.log("ABTesting.success error" + e);
|
110
|
+
}
|
111
|
+
},
|
112
|
+
|
113
|
+
replaceContents: function(content_id, content) {
|
114
|
+
openmail.Application.filterHTML({html: content}, function(response) {
|
115
|
+
if (response.html && response.html !== '') {
|
116
|
+
try {
|
117
|
+
$("#" + content_id).html(response.html);
|
118
|
+
} catch(omg) {
|
119
|
+
Debug.error(omg);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
YMDP.Init.showAndFinish();
|
123
|
+
});
|
124
|
+
},
|
125
|
+
|
126
|
+
content: function(experiment) {
|
127
|
+
return experiment["content_" + ABTesting.variable];
|
128
|
+
}
|
129
|
+
};
|
130
|
+
|
@@ -0,0 +1,185 @@
|
|
1
|
+
/*
|
2
|
+
CALL OIB
|
3
|
+
|
4
|
+
global to every view. sends Ajax call to OtherInbox.
|
5
|
+
*/
|
6
|
+
|
7
|
+
// send an Ajax call to OtherInbox.
|
8
|
+
// takes as parameters:
|
9
|
+
// - the path to call
|
10
|
+
// - any additional query string params
|
11
|
+
// - a callback function to run when the Ajax call is a success
|
12
|
+
// - an optional error function
|
13
|
+
// - a base URL to use, if you don't want this call going to YMDP.Constants.base_url
|
14
|
+
// TODO refactor this function to take a second params hash where we could stick success_function, error_function, and base_url
|
15
|
+
|
16
|
+
OIB = {
|
17
|
+
get: function(oib_path, params, success_function, error_function, base_url) {
|
18
|
+
params.method = "GET";
|
19
|
+
OIB.call(oib_path, params, success_function, error_function, base_url);
|
20
|
+
},
|
21
|
+
|
22
|
+
post: function(oib_path, params, success_function, error_function, base_url) {
|
23
|
+
params.method = "POST";
|
24
|
+
OIB.call(oib_path, params, success_function, error_function, base_url);
|
25
|
+
},
|
26
|
+
|
27
|
+
call: function(oib_path, params, success_function, error_function, base_url) {
|
28
|
+
var success;
|
29
|
+
|
30
|
+
success = function(response) {
|
31
|
+
response = JSON.parse(response.data);
|
32
|
+
if (response.error) {
|
33
|
+
if (error_function) {
|
34
|
+
error_function(response);
|
35
|
+
} else {
|
36
|
+
YMDP.showError(
|
37
|
+
{
|
38
|
+
"method": "OIB.call",
|
39
|
+
"description": "error callback"
|
40
|
+
}
|
41
|
+
); // OIB.call response: error
|
42
|
+
}
|
43
|
+
} else {
|
44
|
+
if (success_function) {
|
45
|
+
success_function(response);
|
46
|
+
} else {
|
47
|
+
YMDP.showError(
|
48
|
+
{
|
49
|
+
"method": "OIB.call",
|
50
|
+
"description": "success callback error"
|
51
|
+
}
|
52
|
+
); // OIB.call response: success error
|
53
|
+
}
|
54
|
+
}
|
55
|
+
};
|
56
|
+
OIB.request(oib_path, params, success, error_function, base_url);
|
57
|
+
},
|
58
|
+
|
59
|
+
ajax_response: false,
|
60
|
+
|
61
|
+
ajax: function(url, method, params, success_function, error_function) {
|
62
|
+
var debug;
|
63
|
+
|
64
|
+
params = params || {};
|
65
|
+
params["application"] = View.application;
|
66
|
+
|
67
|
+
debug = !params["_hide_debug"];
|
68
|
+
|
69
|
+
if (debug) {
|
70
|
+
Debug.log("OIB.ajax: About to call openmail.Application.callWebService: ", {
|
71
|
+
"method": method,
|
72
|
+
"url": url + "?" + $.param(params)
|
73
|
+
});
|
74
|
+
}
|
75
|
+
|
76
|
+
openmail.Application.callWebService(
|
77
|
+
{
|
78
|
+
url: url,
|
79
|
+
method: method,
|
80
|
+
parameters: params
|
81
|
+
},
|
82
|
+
function(response) {
|
83
|
+
// response from Ajax call was a 200 response
|
84
|
+
//
|
85
|
+
if (debug) {
|
86
|
+
Debug.log("inside response from openMail.Application.callWebService", response);
|
87
|
+
}
|
88
|
+
if (response.error) {
|
89
|
+
// response has a parameter called "error"
|
90
|
+
//
|
91
|
+
if (error_function) {
|
92
|
+
error_function(response);
|
93
|
+
} else {
|
94
|
+
if (debug) {
|
95
|
+
OIB.error(url, params, response);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
} else {
|
99
|
+
// SUCCESSFUL RESPONSE
|
100
|
+
//
|
101
|
+
// response doesn't have a parameter called "error"
|
102
|
+
//
|
103
|
+
try {
|
104
|
+
success_function(response);
|
105
|
+
} catch(e) {
|
106
|
+
if (debug) {
|
107
|
+
Debug.log("Error in OIB.request success function", e);
|
108
|
+
}
|
109
|
+
YMDP.showError({
|
110
|
+
"method": "OIB.request",
|
111
|
+
"description": "exception caught in OIB.request success callback",
|
112
|
+
"error": e
|
113
|
+
});
|
114
|
+
}
|
115
|
+
}
|
116
|
+
});
|
117
|
+
},
|
118
|
+
|
119
|
+
request: function(oib_path, params, success_function, error_function, base_url) {
|
120
|
+
var oib_url, method, debug;
|
121
|
+
|
122
|
+
debug = !params["_hide_debug"];
|
123
|
+
|
124
|
+
if (debug) {
|
125
|
+
Debug.log("inside OIB.request: ", {
|
126
|
+
"oib_path": oib_path,
|
127
|
+
"params": JSON.stringify(params)
|
128
|
+
});
|
129
|
+
}
|
130
|
+
|
131
|
+
oib_url = base_url ? base_url : YMDP.Constants.base_url;
|
132
|
+
|
133
|
+
if (!(oib_path && typeof(oib_path) === "string")) {
|
134
|
+
throw("OIB.request must define oib_path");
|
135
|
+
}
|
136
|
+
if (!(params && typeof(params) === "object")) {
|
137
|
+
throw("OIB.request must define params");
|
138
|
+
}
|
139
|
+
|
140
|
+
oib_url = oib_url + oib_path;
|
141
|
+
method = "GET";
|
142
|
+
if (!params.format) {
|
143
|
+
params.format = 'json';
|
144
|
+
}
|
145
|
+
if (params.method) {
|
146
|
+
method = params.method;
|
147
|
+
delete params.method;
|
148
|
+
}
|
149
|
+
params.version = params.version || <%= @version %>;
|
150
|
+
|
151
|
+
if (debug) {
|
152
|
+
Debug.log("about to call OIB.ajax");
|
153
|
+
}
|
154
|
+
|
155
|
+
OIB.ajax(oib_url, method, params, success_function, error_function);
|
156
|
+
},
|
157
|
+
|
158
|
+
// overwrite this function locally if you need to
|
159
|
+
error: function(url, params, response) {
|
160
|
+
var message, debug;
|
161
|
+
|
162
|
+
debug = !params["_hide_debug"];
|
163
|
+
|
164
|
+
if (debug) {
|
165
|
+
message = "OIB.error: " + JSON.stringify(response) + " calling url: " + url + "?" + $.param(params);
|
166
|
+
Debug.error(message);
|
167
|
+
}
|
168
|
+
},
|
169
|
+
|
170
|
+
// advance the user to the next state in the signup process
|
171
|
+
//
|
172
|
+
advance: function(success_function, error_function) {
|
173
|
+
OIB.post("ymdp/state", {}, function(response) {
|
174
|
+
Debug.log("Scanning.next success", response);
|
175
|
+
if (success_function) {
|
176
|
+
success_function(response);
|
177
|
+
}
|
178
|
+
}, function(response) {
|
179
|
+
Debug.error("Scanning.next error", response);
|
180
|
+
if (error_function) {
|
181
|
+
error_function(response);
|
182
|
+
}
|
183
|
+
});
|
184
|
+
}
|
185
|
+
};
|
@@ -0,0 +1,139 @@
|
|
1
|
+
/*
|
2
|
+
APPLICATION
|
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
|
+
*/
|
8
|
+
|
9
|
+
var OIB, YMDP;
|
10
|
+
|
11
|
+
/*
|
12
|
+
GLOBAL CONSTANTS
|
13
|
+
*/
|
14
|
+
|
15
|
+
var View = {
|
16
|
+
application: "<%= @application_name %>",
|
17
|
+
domain: "<%= @domain %>",
|
18
|
+
page_loaded: false,
|
19
|
+
|
20
|
+
authorized: function(user) {
|
21
|
+
return (user[View.application + "_user"]);
|
22
|
+
}
|
23
|
+
};
|
24
|
+
|
25
|
+
var YMDP = {
|
26
|
+
Constants: {},
|
27
|
+
Init: {}
|
28
|
+
};
|
29
|
+
|
30
|
+
function unixTimeToDate(unixtime) {
|
31
|
+
return new Date(unixtime * 1000);
|
32
|
+
}
|
33
|
+
|
34
|
+
function formatUnixDate(unixtime) {
|
35
|
+
var date;
|
36
|
+
date = unixTimeToDate(unixtime);
|
37
|
+
return date.toString("MMMM d, yyyy");
|
38
|
+
}
|
39
|
+
|
40
|
+
// Shows the error view.
|
41
|
+
//
|
42
|
+
// YMDP.showError({
|
43
|
+
// heading: "optional heading text can overwrite the error view's heading",
|
44
|
+
// message: "optional message can overwrite the view's first paragraph",
|
45
|
+
// retry: "hide"
|
46
|
+
// });
|
47
|
+
//
|
48
|
+
// Set the "retry" option to "hide" to hide the Retry button.
|
49
|
+
//
|
50
|
+
|
51
|
+
YMDP.showError = function(options) {
|
52
|
+
var params;
|
53
|
+
|
54
|
+
options = options || {};
|
55
|
+
|
56
|
+
if (options["heading"]) {
|
57
|
+
$("#error_1").html(options["heading"]);
|
58
|
+
}
|
59
|
+
if (options["message"]) {
|
60
|
+
$("#error_2").html(options["message"]);
|
61
|
+
}
|
62
|
+
if (options["retry"] && options["retry"] === "hide") {
|
63
|
+
$("#retry_button_container").hide();
|
64
|
+
}
|
65
|
+
|
66
|
+
params = {};
|
67
|
+
params["description"] = options["description"];
|
68
|
+
params["method_name"] = options["method"];
|
69
|
+
params["error"] = JSON.stringify(options["error"]);
|
70
|
+
params["page"] = View.name;
|
71
|
+
|
72
|
+
Reporter.error(YMDP.guid, params);
|
73
|
+
$('#main').hide();
|
74
|
+
$('#utility').show();
|
75
|
+
$('#loading').hide();
|
76
|
+
$('#error').show();
|
77
|
+
};
|
78
|
+
|
79
|
+
YMDP.showLoading = function() {
|
80
|
+
$('#main').hide();
|
81
|
+
$('#utility').show();
|
82
|
+
$('#error').hide();
|
83
|
+
$('#loading').show();
|
84
|
+
};
|
85
|
+
|
86
|
+
YMDP.Init.upgradeCheck = function(success_callback, failure_callback) {
|
87
|
+
// test for Minty
|
88
|
+
//
|
89
|
+
openmail.Application.getParameters(function(response) {
|
90
|
+
if (response.version === "2") {
|
91
|
+
|
92
|
+
// Minty-only code goes here
|
93
|
+
|
94
|
+
try {
|
95
|
+
Debug.log("Minty found");
|
96
|
+
|
97
|
+
success_callback();
|
98
|
+
} catch(wtf) {
|
99
|
+
Debug.error(wtf);
|
100
|
+
}
|
101
|
+
} else {
|
102
|
+
// non-Minty
|
103
|
+
|
104
|
+
if (failure_callback) {
|
105
|
+
failure_callback();
|
106
|
+
} else {
|
107
|
+
YMDP.Init.upgrade();
|
108
|
+
}
|
109
|
+
}
|
110
|
+
});
|
111
|
+
};
|
112
|
+
|
113
|
+
YMDP.Init.upgrade = function() {
|
114
|
+
YMDP.showTranslations();
|
115
|
+
|
116
|
+
View.page_loaded = true;
|
117
|
+
|
118
|
+
$('#loading').hide();
|
119
|
+
$('#error').hide();
|
120
|
+
$('#upgrade').show();
|
121
|
+
};
|
122
|
+
|
123
|
+
YMDP.setTimeoutInSeconds = function(callback_function, interval) {
|
124
|
+
setTimeout(callback_function, interval * 1000);
|
125
|
+
};
|
126
|
+
|
127
|
+
YMDP.showTranslations = function() {
|
128
|
+
Debug.log("begin YMDP.showTranslations");
|
129
|
+
I18n.findAndTranslateAll();
|
130
|
+
|
131
|
+
// define I18n.localTranslations in the view template
|
132
|
+
I18n.localTranslations();
|
133
|
+
|
134
|
+
Debug.log("end YMDP.showTranslations");
|
135
|
+
};
|
136
|
+
|
137
|
+
String.prototype.capitalize = function() {
|
138
|
+
return this.charAt(0).toUpperCase() + this.slice(1);
|
139
|
+
}
|