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,119 @@
1
+ /*
2
+ AUTHORIZE USER
3
+
4
+ Authorize and sign in the user.
5
+ */
6
+
7
+ var Authorize;
8
+
9
+ Authorize = {
10
+ init: function(guid, default_state, params) {
11
+ Debug.log("Authorize.init");
12
+ params = params || {};
13
+ if (Params.get("invitation")) {
14
+ params["invitation"] = Params.get("invitation");
15
+ }
16
+ params["application"] = View.application;
17
+ Authorize.url = YMDP.Constants.controller_url + "/authorize/" + guid;
18
+ Authorize.locale = params.locale;
19
+ Authorize.default_state = default_state;
20
+
21
+ Authorize.params = params;
22
+ },
23
+
24
+ assignUrl: function(url) {
25
+ url = url || Authorize.url;
26
+ url = url + "?" + $.param(Authorize.params);
27
+
28
+ $("#get_started_1").attr("href", url).attr("target", "_blank");
29
+ $("#get_started_2").attr("href", url).attr("target", "_blank");
30
+ $(".get_started").attr("href", url).attr("target", "_blank");
31
+ },
32
+
33
+ authorize: function() {
34
+ Debug.log("Authorize.authorize");
35
+ YMDP.getUserState(function(response) {
36
+ if (Authorize.authorized(response)) {
37
+ Authorize.confirm();
38
+ } else {
39
+ Debug.log("About to startScanning");
40
+ Authorize.startScanning();
41
+ }
42
+ });
43
+ },
44
+
45
+ startScanning: function() {
46
+ Debug.log("Authorize.startScanning", Authorize.scanner);
47
+ if (!Authorize.scanner) {
48
+ Debug.log("Authorize.scanner doesnt exist", Authorize.scanner);
49
+ Authorize.scanner = window.setInterval(Authorize.scan, 5000);
50
+ } else {
51
+ Debug.log("Authorize.scanner does exist", Authorize.scanner);
52
+ }
53
+ },
54
+
55
+ authorized: function(response) {
56
+ Debug.log("Authorize.authorized", response);
57
+ return !!(response.state !== Authorize.default_state && View.authorized(response));
58
+ },
59
+
60
+ confirm: YMDP.confirm,
61
+
62
+ scan: function() {
63
+ Debug.log("Authorize.scan");
64
+ if (Authorize.stop_scanning) {
65
+ Debug.log("Authorize.stop_scanning is true", Authorize.stop_scanning);
66
+ window.clearInterval(Authorize.scanner);
67
+ } else {
68
+ Debug.log("Authorize.stop_scanning is not true", Authorize.stop_scanning);
69
+ }
70
+
71
+ Debug.log("About to getUserState");
72
+
73
+ YMDP.getUserState(function(response) {
74
+ Debug.log("inside Authorize.scan's getUserState callback", response);
75
+ if (response.state !== Authorize.default_state) {
76
+ Debug.log("not default state, about to Authorize.confirm()");
77
+
78
+ Authorize.confirm();
79
+ if (Authorize.scanner) {
80
+ window.clearInterval(Authorize.scanner);
81
+ }
82
+ Authorize.scanner = undefined;
83
+ Debug.log("just set Authorize.scanner to undefined");
84
+ }
85
+ }, function(response) {
86
+ // error function
87
+ Debug.error("Error in Authorize.scan's getUserState", response);
88
+
89
+ if (Authorize.scanner) {
90
+ window.clearInterval(Authorize.scanner);
91
+ }
92
+ });
93
+ },
94
+
95
+ addBehaviors: function() {
96
+ Debug.log("Authorize.addBehaviors");
97
+ $("#get_started_1").click(Authorize.authorize);
98
+ $("#get_started_2").click(Authorize.authorize);
99
+ $(".get_started").click(Authorize.authorize);
100
+ },
101
+
102
+ verify: function() {
103
+ // call /ymdp/verify and return data about the user
104
+ YMDP.verifyUser(function(user) {
105
+ Debug.log("inside YMDP.verifyUser callback", user);
106
+
107
+ YMDP.user = user;
108
+ YMDP.login = user.login;
109
+ YMDP.Init.switchOnState(user);
110
+ }, function(response) {
111
+ // call to ymdp/verify was not a 200 response, show error
112
+ YMDP.showError({
113
+ "method_name": "YMDP.verifyUser",
114
+ "description": "error response"
115
+ });
116
+ });
117
+ }
118
+ };
119
+
@@ -0,0 +1,67 @@
1
+ var Data;
2
+
3
+ Data = {
4
+ // values cannot be longer than 255 chars
5
+ //
6
+ store: function(data, success_function, error_function) {
7
+ Debug.log("Data.store", data);
8
+
9
+ var keys = {
10
+ "keys": data
11
+ };
12
+ openmail.Application.setData(keys, function(response) {
13
+ Debug.log("openmail.Application.setData response", response);
14
+
15
+ if (response.error && (response.error !== YAHOO.openmail.ERR_NONE)) {
16
+ // storage error detected
17
+ Debug.error("Error saving data", response);
18
+ if (error_function) {
19
+ error_function(response);
20
+ }
21
+ } else {
22
+ if (success_function) {
23
+ success_function(response);
24
+ }
25
+ }
26
+ });
27
+ },
28
+
29
+ // keys must be an array
30
+ //
31
+ fetch: function(keys, success_function, error_function) {
32
+ Debug.log("Data.fetch", keys);
33
+
34
+ keys = {
35
+ "keys": keys
36
+ };
37
+
38
+ openmail.Application.getData(keys, function(response) {
39
+ try {
40
+ Debug.log("Inside openmail.Application.getData callback", response);
41
+
42
+ if (response.error && (response.error !== YAHOO.openmail.ERR_NONE)) {
43
+ Debug.error("Error retrieving data", response);
44
+ if (error_function) {
45
+ error_function(response);
46
+ }
47
+ } else {
48
+ Debug.log("success in openmail.Application.getData", response);
49
+ if (success_function) {
50
+ success_function(response);
51
+ }
52
+ }
53
+ } catch(omg) {
54
+ Debug.error(omg);
55
+ }
56
+ });
57
+ },
58
+
59
+ clear: function() {
60
+ Data.store({
61
+ "ymail_wssid": null
62
+ }, function(response) {
63
+ YMDP.guid = null;
64
+ YMDP.ymail_wssid = null;
65
+ });
66
+ }
67
+ };
@@ -0,0 +1,98 @@
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 Debug;
6
+
7
+ Debug = {
8
+ on: false,
9
+ console: true,
10
+ logs: false,
11
+
12
+ consoleOn: function() {
13
+ return (typeof window['console'] !== 'undefined' && this.console);
14
+ },
15
+
16
+ call: function() {
17
+ var level, message;
18
+ var args = [].slice.call(arguments,0);
19
+ level = args.shift();
20
+
21
+ message = this.message.apply(Debug, args);
22
+
23
+ if (this.consoleOn()) {
24
+ console[level](message);
25
+ }
26
+ Logger.observe(message);
27
+ },
28
+
29
+ log: function() {
30
+ var args = [].slice.call(arguments,0);
31
+ args.unshift("log");
32
+ this.call.apply(this, args);
33
+ },
34
+
35
+ error: function() {
36
+ var args = [].slice.call(arguments,0);
37
+ args.unshift("error");
38
+ this.call.apply(this, args);
39
+ },
40
+
41
+ message: function() {
42
+ var parts, message;
43
+ parts = [];
44
+
45
+ parts.push(this.timestamp());
46
+ parts.push(this.generalInfo());
47
+
48
+ var args = [].slice.call(arguments,0);
49
+
50
+ $(args).each(function(i, arg) {
51
+ parts.push(Debug.object(arg));
52
+ });
53
+
54
+ message = parts.join(" ");
55
+
56
+ return message;
57
+ },
58
+
59
+ object: function(obj) {
60
+ if (typeof obj === "string") {
61
+ return obj;
62
+ } else if (obj === undefined) {
63
+ return "undefined";
64
+ } else if (obj === null) {
65
+ return "null";
66
+ } else if (obj.inspect) {
67
+ return(obj.inspect());
68
+ } else {
69
+ return(JSON.stringify(obj));
70
+ }
71
+ },
72
+
73
+ checktime: function(i) {
74
+ if (i<10) {
75
+ i="0" + i;
76
+ }
77
+ return i;
78
+ },
79
+
80
+ timestamp: function() {
81
+ var time, hour, minute, second, timestamp, checktime;
82
+
83
+ time = new Date();
84
+ hour = this.checktime(time.getHours());
85
+ minute = this.checktime(time.getMinutes());
86
+ second = this.checktime(time.getSeconds());
87
+
88
+ // timestamp = month + "/" + date + "/" + year + " " +
89
+
90
+ timestamp = hour + ":" + minute + ":" + second;
91
+
92
+ return timestamp;
93
+ },
94
+
95
+ generalInfo: function() {
96
+ return "[<%= @version %> <%= @sprint_name %>]";
97
+ }
98
+ };
@@ -0,0 +1,168 @@
1
+ var Education;
2
+
3
+ Education = {
4
+ init: function(name) {
5
+ try {
6
+ Debug.log("Education.init", name);
7
+ var m;
8
+
9
+ Education.name = name;
10
+
11
+ m = "";
12
+ m = m + Tags.linkToFunction("Close", "Education.educate(); return false;", {"class": "close"});
13
+ m = m + Education.educationModule();
14
+
15
+ Education.container().insert(m);
16
+ Education.container().insert({"after": Education.forcedEducation()});
17
+
18
+ Education.load();
19
+ } catch(omg) {
20
+ Debug.error(omg);
21
+ }
22
+ },
23
+
24
+ educationModule: function() {
25
+ var m;
26
+
27
+ m = Tags.div(Education.ol(), {"id": Education.name, "class": "education_module"});
28
+
29
+ return m;
30
+ },
31
+
32
+ forcedEducation: function() {
33
+ var m;
34
+
35
+ m = Tags.div(Education.minForcedEducation(), {"id": "forced_education", "style": "display: none;"});
36
+
37
+ return m;
38
+ },
39
+
40
+ minForcedEducation: function() {
41
+ var m, id;
42
+
43
+ id = "min_" + Education.name + "_education";
44
+ Debug.log("getting min forced education key", id);
45
+ m = Tags.div(I18n.t(id), {"id": id});
46
+
47
+ Debug.log("got key", m);
48
+
49
+ return m;
50
+ },
51
+
52
+ ol: function() {
53
+ var m, entries;
54
+
55
+ entries = Education.entries();
56
+
57
+ entries = entries.join("");
58
+ m = Tags.ol(entries);
59
+
60
+ return m;
61
+ },
62
+
63
+ entries: function() {
64
+ var m, entries, entry, i;
65
+ entries = [];
66
+
67
+ i = 0;
68
+
69
+ do {
70
+ i = i + 1;
71
+ entry = Education.entry(i);
72
+ entries.push(entry);
73
+ } while(entry);
74
+
75
+ return entries;
76
+ },
77
+
78
+ entry: function(index) {
79
+ var m, text, id;
80
+
81
+ id = Education.name + "_" + String(index);
82
+ text = I18n.t(id);
83
+
84
+ if (text) {
85
+ m = Tags.li(text, {"id": id});
86
+ }
87
+ return m;
88
+ },
89
+
90
+ show: function(educations) {
91
+ Debug.log('Education.init');
92
+ Education.educations = educations;
93
+ Debug.log("Educations.educations: ", educations);
94
+ if (Education.container() !== null) {
95
+ Education.getModules();
96
+ }
97
+ },
98
+
99
+ get: function(params, success_function, error_function) {
100
+ Debug.log('Education.get. About to call OIB.get');
101
+ OIB.get("educations/", params, success_function, error_function);
102
+ },
103
+
104
+ post: function(params, success_function, error_function) {
105
+ Debug.log('Education.post');
106
+ OIB.post("educations/create", params, success_function, error_function);
107
+ },
108
+
109
+ educate: function() {
110
+ // Grab the children divs of $('education') with the class education_module that are NOT HIDDEN
111
+ // For each education module returned, post the id and view as params[:title] and params[:page_name]
112
+
113
+ $('.education_module').each(function(index, element) {
114
+ element = $(element);
115
+ if (!element.hasClass('educated')) {
116
+ Education.post({"page_name": View.name, "title": element.attr("id")}, function(response) {
117
+ Debug.log("Response: " + response);
118
+ });
119
+ }
120
+ });
121
+ Education.container().hide();
122
+ $('#forced_education').show();
123
+ },
124
+
125
+ getModules: function() {
126
+ var showContainer = false;
127
+ $('.education_module').each(function(index, element) {
128
+ Education.educations.each(function(education) {
129
+ if (element.attr("id") === education.title && View.name.toLowerCase() === education.page_name.toLowerCase()) {
130
+ element.addClass('educated');
131
+ }
132
+ });
133
+ });
134
+
135
+ $('.education_module').each(function(i) {
136
+ var element = $(this);
137
+ if(!element.hasClass('educated')) {
138
+ showContainer = true;
139
+ }
140
+ });
141
+
142
+ if (showContainer) {
143
+ Education.container().show();
144
+ } else {
145
+ $('forced_education').show();
146
+ }
147
+ },
148
+
149
+ container: function() {
150
+ return $('#education');
151
+ },
152
+
153
+ load: function() {
154
+ try {
155
+ Debug.log('Education.load');
156
+ Education.get({}, function(response) {
157
+ Education.show(response);
158
+ });
159
+ } catch(err) {
160
+ YMDP.showError({
161
+ "method": "Education.load",
162
+ "type": "exception caught",
163
+ "error": err
164
+ });
165
+ Debug.error(err);
166
+ }
167
+ }
168
+ };