ymdp 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.4
1
+ 0.8.5
@@ -0,0 +1,92 @@
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
+ window.ABTesting =
5
+ on: true
6
+
7
+ languages: <%= english_languages.to_json %>
8
+
9
+ enable: ->
10
+ ABTesting.on = true
11
+
12
+ disable: ->
13
+ ABTesting.on = false
14
+
15
+ randomAB: ->
16
+ Math.floor(Math.random()*2) ? "a" : "b"
17
+
18
+ get: (content_id) ->
19
+ url = "ymdp/experiment"
20
+
21
+ OIB.get url,
22
+ "domain": View.domain
23
+ , (response) ->
24
+ ABTesting.success(content_id, response)
25
+ , (response) ->
26
+ ABTesting.error(response)
27
+
28
+
29
+ post: (params) ->
30
+ params = params || {}
31
+ OIB.post "ymdp/view", params, (response) ->
32
+ Debug.log("ABTesting.post success", response)
33
+ , (response) ->
34
+ Debug.error("ABTesting.post error", response)
35
+
36
+
37
+ postView: (experimentId) ->
38
+ params =
39
+ "var": ABTesting.variable
40
+
41
+ if typeof(experimentId) != 'undefined'
42
+ params["experiment_id"] = experimentId
43
+
44
+ Debug.log("ABTesting.postView: ", params)
45
+ ABTesting.post(params)
46
+
47
+
48
+ setVariable: (value) ->
49
+ ABTesting.variable = value
50
+
51
+ apply: (content_id, language) ->
52
+ if (ABTesting.on && $.inArray(language, ABTesting.languages) >= 0)
53
+ index = ABTesting.randomAB()
54
+ ABTesting.setVariable(index)
55
+
56
+ ABTesting.get(content_id)
57
+ else
58
+ YMDP.Init.showAndFinish()
59
+
60
+ error: (data) ->
61
+ Debug.log("applyError", data)
62
+ if data.error != 3002
63
+ Debug.error("Received body contents fetch error on page " + View.name + ": " + data.error + ' - ' + data.errorMsg)
64
+
65
+ YMDP.Init.showAndFinish()
66
+
67
+ success: (content_id, response) ->
68
+ Debug.log("ABTesting.success", response)
69
+
70
+ experiment = response.experiment
71
+
72
+ if typeof(experiment) != 'undefined'
73
+ content = ABTesting.content(experiment)
74
+ experimentId = response.experiment.id
75
+
76
+ ABTesting.postView(experimentId)
77
+ ABTesting.replaceContents(content_id, content)
78
+ else
79
+ Debug.log("No experiment running")
80
+
81
+ YMDP.Init.showAndFinish()
82
+
83
+ replaceContents: (content_id, content) ->
84
+ openmail.Application.filterHTML
85
+ html: content, (response) ->
86
+ if typeof(response.html) != 'undefined' && response.html != ''
87
+ $("#" + content_id).html(response.html)
88
+
89
+ YMDP.Init.showAndFinish()
90
+
91
+ content: (experiment) ->
92
+ experiment["content_" + ABTesting.variable]
@@ -0,0 +1,134 @@
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
+ window.OIB =
17
+ get: (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
+ post: (oib_path, params, success_function, error_function, base_url) ->
22
+ params.method = "POST"
23
+ OIB.call(oib_path, params, success_function, error_function, base_url)
24
+
25
+ call: (oib_path, params, success_function, error_function, base_url) ->
26
+ success = (response) ->
27
+ response = JSON.parse(response.data)
28
+ if (response.error)
29
+ if (error_function)
30
+ error_function(response)
31
+ else
32
+ YMDP.showError
33
+ "method": "OIB.call"
34
+ "description": "error callback"
35
+ else
36
+ if (success_function)
37
+ success_function(response)
38
+ else
39
+ YMDP.showError
40
+ "method": "OIB.call"
41
+ "description": "success callback error"
42
+
43
+ OIB.request(oib_path, params, success, error_function, base_url)
44
+
45
+ ajax_response: false
46
+
47
+ ajax: (url, method, params, success_function, error_function) ->
48
+ params = params || {}
49
+ params["application"] = View.application
50
+
51
+ debug = !params["_hide_debug"]
52
+
53
+ if (debug)
54
+ Debug.log "OIB.ajax: About to call openmail.Application.callWebService: ",
55
+ "method": method,
56
+ "url": url + "?" + $.param(params)
57
+
58
+ openmail.Application.callWebService
59
+ url: url,
60
+ method: method,
61
+ parameters: params
62
+ , (response) ->
63
+ # response from Ajax call was a 200 response
64
+ #
65
+ if debug
66
+ Debug.log("inside response from openMail.Application.callWebService", response)
67
+
68
+ if response.error
69
+ # response has a parameter called "error"
70
+ #
71
+ if error_function
72
+ error_function(response)
73
+ else if debug
74
+ OIB.error(url, params, response)
75
+ else
76
+ # SUCCESSFUL RESPONSE
77
+ #
78
+ # response doesn't have a parameter called "error"
79
+ #
80
+ success_function(response)
81
+
82
+ request: (oib_path, params, success_function, error_function, base_url) ->
83
+ debug = !params["_hide_debug"]
84
+ Debug.log("inside OIB.request: ", {"oib_path": oib_path, "params": JSON.stringify(params)}) if debug
85
+
86
+ oib_url = OIB.url_from_path(oib_path, params, base_url)
87
+ method = OIB.method_from_params(params)
88
+
89
+ Debug.log("about to call OIB.ajax") if debug
90
+ OIB.ajax(oib_url, method, params, success_function, error_function)
91
+
92
+ method_from_params: (params) ->
93
+ method = "GET"
94
+ if !params.format
95
+ params.format = 'json'
96
+ if params.method
97
+ method = params.method
98
+ delete params.method
99
+
100
+ params.version = params.version || "<%= @version %>"
101
+
102
+ method
103
+
104
+ url_from_path: (oib_path, params, base_url) ->
105
+ oib_url = base_url || YMDP.Constants.base_url
106
+
107
+ if !(oib_path && typeof(oib_path) == "string")
108
+ throw("OIB.request must define oib_path")
109
+
110
+ if !(params && typeof(params) == "object")
111
+ throw("OIB.request must define params")
112
+
113
+ oib_url + oib_path
114
+
115
+ # overwrite this function locally if you need to
116
+ #
117
+ error: (url, params, response) ->
118
+ debug = !params["_hide_debug"]
119
+
120
+ if debug
121
+ message = "OIB.error: " + JSON.stringify(response) + " calling url: " + url + "?" + $.param(params)
122
+ Debug.error(message)
123
+
124
+ # advance the user to the next state in the signup process
125
+ #
126
+ advance: (success_function, error_function) ->
127
+ OIB.post "ymdp/state", {}, (response) ->
128
+ Debug.log("Scanning.next success", response)
129
+ if (success_function)
130
+ success_function(response)
131
+ , (response) ->
132
+ Debug.error("Scanning.next error", response)
133
+ if (error_function)
134
+ error_function(response)
@@ -0,0 +1,86 @@
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
+ ###
10
+ GLOBAL CONSTANTS
11
+ ###
12
+
13
+ window.View =
14
+ application: "<%= @application_name %>"
15
+ domain: "<%= @domain %>"
16
+ page_loaded: false
17
+
18
+ authorized: (user) ->
19
+ return (user[View.application + "_user"])
20
+
21
+
22
+ window.unixTimeToDate = (unixtime) ->
23
+ new Date(unixtime * 1000)
24
+
25
+ window.formatUnixDate = (unixtime) ->
26
+ date = unixTimeToDate(unixtime)
27
+ date.toString("MMMM d, yyyy")
28
+
29
+ String.prototype.capitalize = () ->
30
+ this.charAt(0).toUpperCase() + this.slice(1)
31
+
32
+
33
+
34
+ window.YMDP =
35
+ Constants: {}
36
+
37
+ # Shows the error view.
38
+ #
39
+ # YMDP.showError({
40
+ # heading: "optional heading text can overwrite the error view's heading",
41
+ # message: "optional message can overwrite the view's first paragraph",
42
+ # retry: "hide"
43
+ # })
44
+ #
45
+ # Set the "retry" option to "hide" to hide the Retry button.
46
+ #
47
+
48
+ showError: (options) ->
49
+ options = options || {}
50
+
51
+ if options["heading"]
52
+ $("#error_1").html(options["heading"])
53
+ if options["message"]
54
+ $("#error_2").html(options["message"])
55
+ if options["retry"] && options["retry"] == "hide"
56
+ $("#retry_button_container").hide()
57
+
58
+ params =
59
+ "description": options["description"]
60
+ "method_name": options["method"]
61
+ "error": JSON.stringify(options["error"])
62
+ "page": View.name
63
+
64
+ Reporter.error(YMDP.guid, params)
65
+ $('#main').hide()
66
+ $('#utility').show()
67
+ $('#loading').hide()
68
+ $('#error').show()
69
+
70
+ showLoading: () ->
71
+ $('#main').hide()
72
+ $('#utility').show()
73
+ $('#error').hide()
74
+ $('#loading').show()
75
+
76
+ setTimeoutInSeconds: (callback_function, interval) ->
77
+ setTimeout(callback_function, interval * 1000)
78
+
79
+ showTranslations: () ->
80
+ Debug.log("begin YMDP.showTranslations")
81
+ I18n.findAndTranslateAll()
82
+
83
+ # define I18n.localTranslations in the view template
84
+ I18n.localTranslations()
85
+
86
+ Debug.log("end YMDP.showTranslations")
@@ -0,0 +1,101 @@
1
+ ###
2
+ AUTHORIZE USER
3
+
4
+ Authorize and sign in the user.
5
+ ###
6
+
7
+ window.Authorize =
8
+ init: (guid, default_state, params) ->
9
+ Debug.log("Authorize.init")
10
+ params = params || {}
11
+ if Params.get("invitation")
12
+ params["invitation"] = Params.get("invitation")
13
+
14
+ params["application"] = View.application
15
+ Authorize.url = YMDP.Constants.controller_url + "/authorize/" + guid
16
+ Authorize.locale = params.locale
17
+ Authorize.default_state = default_state
18
+
19
+ Authorize.params = params
20
+ Debug.log("end of Authorize.init")
21
+
22
+ assignUrl: (url) ->
23
+ url = url || Authorize.url
24
+ url = url + "?" + $.param(Authorize.params)
25
+
26
+ $("#get_started_1").attr("href", url).attr("target", "_blank")
27
+ $("#get_started_2").attr("href", url).attr("target", "_blank")
28
+ $(".get_started").attr("href", url).attr("target", "_blank")
29
+
30
+ authorize: ->
31
+ Debug.log("Authorize.authorize")
32
+ User.getState (response) ->
33
+ if Authorize.authorized(response)
34
+ Authorize.confirm()
35
+ else
36
+ Debug.log("About to startScanning")
37
+ Authorize.startScanning()
38
+
39
+ startScanning: ->
40
+ Debug.log("Authorize.startScanning", Authorize.scanner)
41
+ if !Authorize.scanner
42
+ Debug.log("Authorize.scanner doesnt exist", Authorize.scanner)
43
+ Authorize.scanner = window.setInterval(Authorize.scan, 5000)
44
+ else
45
+ Debug.log("Authorize.scanner does exist", Authorize.scanner)
46
+
47
+ authorized: (response) ->
48
+ Debug.log("Authorize.authorized", response)
49
+ return !!(response.state != Authorize.default_state && View.authorized(response))
50
+
51
+ confirm: User.confirm
52
+
53
+ scan: ->
54
+ Debug.log("Authorize.scan")
55
+ if Authorize.stop_scanning
56
+ Debug.log("Authorize.stop_scanning is true", Authorize.stop_scanning)
57
+ window.clearInterval(Authorize.scanner)
58
+ else
59
+ Debug.log("Authorize.stop_scanning is not true", Authorize.stop_scanning)
60
+
61
+ Debug.log("About to getUserState")
62
+
63
+ User.getState Authorize.scanResponse, (response) ->
64
+ # error function
65
+ Debug.error("Error in Authorize.scan's getUserState", response)
66
+
67
+ if Authorize.scanner
68
+ window.clearInterval(Authorize.scanner)
69
+
70
+ scanResponse: (response) ->
71
+ Debug.log("inside Authorize.scan's getUserState callback", response)
72
+ if response.state != Authorize.default_state
73
+ Debug.log("not default state, about to Authorize.confirm()")
74
+
75
+ Authorize.confirm()
76
+ if Authorize.scanner
77
+ window.clearInterval(Authorize.scanner)
78
+
79
+ Authorize.scanner = undefined
80
+ Debug.log("just set Authorize.scanner to undefined")
81
+
82
+ addBehaviors: ->
83
+ Debug.log("Authorize.addBehaviors")
84
+ $("#get_started_1").click(Authorize.authorize)
85
+ $("#get_started_2").click(Authorize.authorize)
86
+ $(".get_started").click(Authorize.authorize)
87
+
88
+ verify: ->
89
+ # call /ymdp/verify and return data about the user
90
+ User.verify (user) ->
91
+ Debug.log("inside User.verify callback", user)
92
+
93
+ YMDP.user = user
94
+ YMDP.login = user.login
95
+ YMDP.Init.switchOnState(user)
96
+ , (response) ->
97
+ # call to ymdp/verify was not a 200 response, show error
98
+ YMDP.showError
99
+ "method_name": "User.verify",
100
+ "description": "error response"
101
+
@@ -0,0 +1,25 @@
1
+ window.Browser =
2
+ version: (v) ->
3
+ app_version = navigator.appVersion
4
+ Debug.log("Browser app_version: ", app_version)
5
+
6
+ if app_version.match("MSIE 6.0")
7
+ version = 6.0
8
+
9
+ if v
10
+ version == v
11
+ else
12
+ version
13
+
14
+ ie: ->
15
+ navigator.appName.match("Internet Explorer")
16
+
17
+ ie6: ->
18
+ Browser.ie() && Browser.version(6.0)
19
+
20
+ ie7: ->
21
+ Browser.ie() && Browser.version(7.0)
22
+
23
+ ie8: ->
24
+ Browser.ie() && Browser.version(8.0)
25
+
@@ -0,0 +1,50 @@
1
+ window.Data =
2
+ # values cannot be longer than 255 chars
3
+ #
4
+ store: (data, success_function, error_function) ->
5
+ Debug.log("Data.store", data)
6
+
7
+ keys =
8
+ "keys": data
9
+
10
+ openmail.Application.setData keys, (response) ->
11
+ Debug.log("openmail.Application.setData response", response)
12
+
13
+ if typeof(response.error) != 'undefined' && response.error != YAHOO.openmail.ERR_NONE
14
+ # storage error detected
15
+ Debug.error("Error saving data", response)
16
+
17
+ if typeof(error_function) != 'undefined'
18
+ error_function(response)
19
+ else
20
+ if typeof(success_function) != 'undefined'
21
+ success_function(response)
22
+
23
+ # keys must be an array
24
+ #
25
+ fetch: (keys, success_function, error_function) ->
26
+ Debug.log("Data.fetch", keys)
27
+
28
+ keys =
29
+ "keys": keys
30
+
31
+ openmail.Application.getData keys, (response) ->
32
+ Debug.log("Inside openmail.Application.getData callback", response)
33
+
34
+ if typeof(response.error) != 'undefined' && (response.error != YAHOO.openmail.ERR_NONE)
35
+ Debug.error("Error retrieving data", response)
36
+ if typeof(error_function) != 'undefined'
37
+ error_function(response)
38
+ else
39
+ Debug.log("success in openmail.Application.getData", response)
40
+ if typeof(success_function) != 'undefined'
41
+ success_function(response)
42
+
43
+ clear: ->
44
+ Data.store
45
+ "ymail_wssid": null
46
+ , (response) ->
47
+ YMDP.guid = null
48
+ YMDP.ymail_wssid = null
49
+
50
+
@@ -0,0 +1,76 @@
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
+ window.Debug =
6
+ on: false
7
+ console: true
8
+ logs: false
9
+
10
+ consoleOn: ->
11
+ typeof window['console'] != 'undefined' && this.console
12
+
13
+ call: ->
14
+ args = [].slice.call(arguments,0)
15
+ level = args.shift()
16
+
17
+ message = this.message.apply(Debug, args)
18
+
19
+ if this.consoleOn()
20
+ console[level](message)
21
+
22
+ Logger.observe(message)
23
+
24
+ log: ->
25
+ args = [].slice.call(arguments,0)
26
+ args.unshift("log")
27
+ this.call.apply(this, args)
28
+
29
+ error: ->
30
+ args = [].slice.call(arguments,0)
31
+ args.unshift("error")
32
+ this.call.apply(this, args)
33
+
34
+ message: ->
35
+ args = [].slice.call(arguments,0)
36
+ parts = []
37
+
38
+ parts.push(this.timestamp())
39
+ parts.push(this.generalInfo())
40
+
41
+ $(args).each (i, arg) ->
42
+ parts.push(Debug.object(arg))
43
+
44
+ message = parts.join(" ")
45
+
46
+ message
47
+
48
+ object: (obj) ->
49
+ if (typeof obj == "string")
50
+ obj
51
+ else if (obj == undefined)
52
+ "undefined"
53
+ else if (obj == null)
54
+ "null"
55
+ else if (obj.inspect)
56
+ obj.inspect()
57
+ else
58
+ JSON.stringify(obj)
59
+
60
+ checktime: (i) ->
61
+ if i<10
62
+ i="0" + i
63
+
64
+ i
65
+
66
+ timestamp: ->
67
+ time = new Date()
68
+ hour = this.checktime(time.getHours())
69
+ minute = this.checktime(time.getMinutes())
70
+ second = this.checktime(time.getSeconds())
71
+
72
+ hour + ":" + minute + ":" + second
73
+
74
+ generalInfo: ->
75
+ "[<%= @version %> <%= @sprint_name %>]"
76
+
@@ -0,0 +1,160 @@
1
+ ###
2
+
3
+ INITIALIZER CODE
4
+
5
+ ###
6
+
7
+ # Adds behaviors/observers to elements on the page
8
+ #
9
+
10
+ YMDP.Init = {}
11
+
12
+ YMDP.Init.addBehaviors = ->
13
+ # overwrite this function locally
14
+
15
+
16
+ # hide the loading screen and show the main body of the summary
17
+ YMDP.Init.show = ->
18
+ Debug.log("YMDP.Init.show")
19
+ $('#utility').hide()
20
+ $('#error').hide()
21
+ $('#loading').hide()
22
+ $('#main').show()
23
+
24
+
25
+ # Local initializer. When your page starts up, this method will be called after fetching the user's guid and ymail wssid.
26
+ #
27
+ YMDP.Init.local = ->
28
+ throw("This hasn't been overwritten.")
29
+ # overwrite this function locally
30
+
31
+
32
+ # To be run before any other initializers have run.
33
+ #
34
+ YMDP.Init.before = ->
35
+ # overwrite this function locally
36
+
37
+ # Main startup code. Overwrite this function to execute after YMDP.Init.before and before YMDP.Init.after.
38
+ #
39
+ YMDP.Init.startup = ->
40
+ Debug.log("init.startup")
41
+ # gets the user
42
+ User.getGuid (guid) ->
43
+ Reporter.reportCurrentView(guid)
44
+ callback = ->
45
+ try
46
+ YMDP.Init.local()
47
+ catch omg
48
+ Debug.error("Error in YMDP.Init.local", omg)
49
+ YMDP.showError()
50
+
51
+ User.getState(callback, callback)
52
+
53
+
54
+ YMDP.Init.abTesting = ->
55
+ # to enable abTesting in your view, overwrite this file locally.
56
+ #
57
+ # be sure to finish your post-Ajax callback with YMDP.Init.show()
58
+ #
59
+ YMDP.Init.show()
60
+ YMDP.Init.after()
61
+
62
+
63
+ # Finishing code. Runs after startup, executes translations and behaviors. Shows the page and then
64
+ # runs the A/B testing callback, which in turn will execute the last callbacks.
65
+ #
66
+ YMDP.Init.finish = ->
67
+ Debug.log("init.finish for view " + View.name)
68
+ YMDP.showTranslations()
69
+ YMDP.Init.addBehaviors()
70
+ YMDP.Init.abTesting()
71
+ View.page_loaded = true
72
+ Debug.log("finished init.finish for view " + View.name)
73
+
74
+
75
+ # Post-initalizer. Very last thing that runs, after content has been shown.
76
+ #
77
+ YMDP.Init.after = ->
78
+ # overwrite this function locally
79
+
80
+
81
+ YMDP.setJSON = ->
82
+ if typeof(JSON) != 'undefined'
83
+ true
84
+
85
+ if typeof(YUI) != 'undefined'
86
+ YUI().use 'json', (Y) ->
87
+ window.JSON = Y.JSON
88
+
89
+ else if typeof(YAHOO) != 'undefined' && typeof(YAHOO.lang) != 'undefined'
90
+ window.JSON = YAHOO.lang.JSON
91
+
92
+
93
+ # Execute the before, startup and after methods. Do not overwrite. (Change YMDP.Init.startup to create a custom initializer.)
94
+ YMDP.init = ->
95
+ try
96
+ YMDP.setJSON() # must set JSON first because Debug uses it
97
+ Debug.log("OIB.init for view " + View.name, "<%= @message %>")
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 omg
108
+ Debug.error(omg.message)
109
+
110
+
111
+
112
+ YMDP.Init.browser = ->
113
+ if $.browser.webkit
114
+ $('body').addClass('webkit')
115
+
116
+
117
+ YMDP.Init.resources = ->
118
+ Debug.log("about to call I18n.setResources")
119
+
120
+ I18n.availableLanguages = <%= supported_languages.to_json %>
121
+
122
+ I18n.currentLanguage = OpenMailIntl.findBestLanguage(I18n.availableLanguages)
123
+
124
+ I18n.setResources()
125
+
126
+ Debug.log("finished calling I18n.setResources")
127
+
128
+
129
+ # Contains the last two callbacks, to show the page contents and run post-show function. Do not overwrite.
130
+ YMDP.Init.showAndFinish = ->
131
+ Debug.log("YMDP.Init.showAndFinish")
132
+ YMDP.Init.show()
133
+ YMDP.Init.after()
134
+
135
+ YMDP.Init.upgradeCheck = (success_callback, failure_callback) ->
136
+ # test for Minty
137
+ #
138
+ openmail.Application.getParameters (response) ->
139
+ if response.version == "2"
140
+ # Minty-only code goes here
141
+
142
+ Debug.log("Minty found")
143
+
144
+ success_callback()
145
+ else
146
+ # non-Minty
147
+
148
+ if failure_callback
149
+ failure_callback()
150
+ else
151
+ YMDP.Init.upgrade()
152
+
153
+ YMDP.Init.upgrade = () ->
154
+ YMDP.showTranslations()
155
+
156
+ View.page_loaded = true
157
+
158
+ $('#loading').hide()
159
+ $('#error').hide()
160
+ $('#upgrade').show()
@@ -0,0 +1,112 @@
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
+ window.Launcher = {}
12
+
13
+ Launcher.launch = (view, title, type) ->
14
+ openmail.Application.getParameters (response) ->
15
+ title = I18n.t("APPLICATION_NAME")
16
+ # don't try to relaunch current tab
17
+ if response.data == null || response.data.view != view
18
+ openmail.Application.openView
19
+ id: view
20
+ view: view
21
+ target: type
22
+ title: title
23
+ parameters:
24
+ launchParams: Params.parameters
25
+ view: view
26
+
27
+ openmail.Application.closeView(null)
28
+
29
+ Launcher.launchView = (launch_view) ->
30
+ user = YMDP.user || {"state": "active"}
31
+
32
+ switch user.state
33
+ when "scanning"
34
+ # formerly known as 'inspect'
35
+ Launcher.launchScanning()
36
+ when "summary"
37
+ Launcher.launchSummary()
38
+ when "authorized"
39
+ # authorized but not yet 'signed in'
40
+ YMDP.signInUser()
41
+ when "new_active", "processing", "active"
42
+ # activated but we have synced fewer than 80% of their messages
43
+ # active, launch the view this method was intended for
44
+ launch_view()
45
+ else
46
+ # other
47
+ Launcher.launchAuthorize()
48
+
49
+
50
+ Launcher.launchTab = (view, title) ->
51
+ Launcher.launch(view, title, "tab")
52
+
53
+ # User must be signed in for this page, we'll
54
+ # sign them in if they don't have an OIB cookie
55
+ #
56
+ Launcher.launchActiveTab = (view, title) ->
57
+ Launcher.launchTab(view, title)
58
+
59
+
60
+ Launcher.launchAuthorize = ->
61
+ Launcher.launchTab("authorize", "Authorize")
62
+
63
+ Launcher.launchDeactivate = ->
64
+ Launcher.launchHidden("deactivate", "Deactivate")
65
+
66
+ Launcher.launchHidden = (view, title) ->
67
+ Launcher.launch(view, title, "hidden")
68
+
69
+ Launcher.l = (view) ->
70
+ view = "launch" + view.capitalize()
71
+ Launcher[view]()
72
+
73
+ Launcher.launchGoodbye = ->
74
+ Launcher.launchTab("goodbye", "Goodbye")
75
+
76
+ Launcher.relaunchAuthorize = Launcher.launchAuthorize
77
+
78
+ Launcher.launchMaintenance = ->
79
+ Launcher.launchTab("maintenance", "Maintenance")
80
+
81
+ Launcher.launchReauthorize = ->
82
+ Launcher.launchTab("reauthorize", "Reauthorize")
83
+
84
+ Launcher.launchView = (launch_view) ->
85
+ # get Yahoo! user's guid and ymail_wssid
86
+ User.getGuidAndYmailWssid (guid, ymail_wssid) ->
87
+
88
+ # call /ymdp/verify and return data about the user
89
+ User.verify (user) ->
90
+
91
+ YMDP.login = user.login
92
+
93
+ switch user.state
94
+ when "scanning"
95
+ # formerly known as 'inspect'
96
+ Launcher.launchScanning()
97
+ when "summary"
98
+ Launcher.launchSummary()
99
+ when "authorized"
100
+ # authorized but not yet 'signed in'
101
+ YMDP.signInUser()
102
+ when "new_active", "processing", "active"
103
+ # no messages processed yet
104
+ # activated but we have synced fewer than 80% of their messages
105
+ # active, launch the view this method was intended for
106
+ launch_view()
107
+ else
108
+ # other
109
+ Launcher.launchAuthorize()
110
+
111
+ Launcher.launchMain = ->
112
+ Launcher.launchView(Launcher.launchFolders)
@@ -0,0 +1,18 @@
1
+ window.Logger =
2
+ on: false
3
+
4
+ init: ->
5
+ OIB.get "ymdp/state", {}, (response) ->
6
+ Logger.on = response.observe;
7
+
8
+ observe: (message) ->
9
+ if this.on
10
+ this.log(message);
11
+
12
+ log: (message) ->
13
+ # console.log("LOGGING " + message);
14
+
15
+ OIB.post "ymdp/logs",
16
+ "_hide_debug": true,
17
+ "log": message
18
+ , ->
@@ -0,0 +1,22 @@
1
+ window.Params =
2
+ names: ["invitation", "page", "cc"]
3
+ parameters: {}
4
+
5
+ init: (launchParams) ->
6
+ launchParams = launchParams || {}
7
+ Debug.log("Params.init", launchParams)
8
+
9
+ if launchParams
10
+ Params.parameters = launchParams
11
+ else
12
+ Params.parameters = {}
13
+
14
+ get: (name) ->
15
+ Debug.log("Params.get", name)
16
+
17
+ index = $.inArray(name, Params.names)
18
+
19
+ if index >= 0
20
+ result = Params.parameters["param" + index]
21
+
22
+ result
@@ -0,0 +1,40 @@
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
+ # Reports pageviews to OIB for tracking counts of each pageview.
5
+ #
6
+ # The main interface to this class is located in "header.js" where it can
7
+ # make use of the current view name.
8
+ #
9
+ # == Usage
10
+ #
11
+ # Reporter.reportCurrentView(guid)
12
+ #
13
+ window.Reporter =
14
+ error: (guid, params) ->
15
+ # Debug.log("Reporter.error", params)
16
+ Reporter.report(guid, "error", params)
17
+
18
+ reportCurrentView: (guid) ->
19
+ Reporter.report(guid, View.name)
20
+
21
+ # Report the Ymail guid and page view name to OIB.
22
+ #
23
+ report: (guid, view, params) ->
24
+ params = params || {}
25
+
26
+ params["ymail_guid"] = guid
27
+ params["view"] = view
28
+
29
+ # Debug.log("Reporting guid " + guid + ", view " + view)
30
+ Reporter.post(params)
31
+
32
+ # Post data back to OIB, to the URL /ymdp/report.
33
+ #
34
+ post: (params) ->
35
+ params = params || {}
36
+ OIB.post "ymdp/report", params,
37
+ (response) ->
38
+ # Debug.log("Reported page view", params)
39
+ , (response) ->
40
+ # Debug.error("Error reporting page view with params", response)
@@ -0,0 +1,178 @@
1
+ window.User =
2
+
3
+ # gets user's state info from /ymdp/state
4
+ # including the user's OIB login
5
+ #
6
+ getState: (success_function, error_function) ->
7
+ Debug.log("User.getState")
8
+
9
+ success = (response) ->
10
+ Debug.log("User.getState callback", response)
11
+ User.setVariables(response)
12
+
13
+ if success_function
14
+ Debug.log("User.getState: About to success function")
15
+ success_function(response)
16
+ error = ->
17
+ Debug.log("Failed to get user's state")
18
+ error_function() if error_function
19
+
20
+ OIB.get "ymdp/state", {}, success, error
21
+
22
+
23
+ setVariables: (response) ->
24
+ YMDP.response = response
25
+ try
26
+ YMDP.since_date = formatUnixDate(YMDP.response.since_date.s)
27
+ catch omg
28
+ YMDP.since_date = 1294869484
29
+
30
+ YMDP.login = response.login
31
+ YMDP.state = response.state
32
+
33
+ ###
34
+ User.verify
35
+
36
+ global to all views. calls the 'verify' action on ymdp controller and executes
37
+ a function with the result.
38
+
39
+ Sends the server the user's guid and 'ymail_wssid', which signs the user in if the
40
+ values match what we have in the database.
41
+ ###
42
+
43
+ verify: (success_function, error_function) ->
44
+ Debug.log("User.verify")
45
+
46
+ params =
47
+ ymail_guid: YMDP.guid,
48
+ ymail_wssid: YMDP.ymail_wssid
49
+ success = (response) ->
50
+ YMDP.user = response
51
+ Debug.log("User.verify YMDP.user", YMDP.user)
52
+ if success_function
53
+ Debug.log("User.verify: About to success function")
54
+ success_function(YMDP.user)
55
+
56
+ OIB.get "ymdp/verify", params, success, error_function
57
+
58
+
59
+ ###
60
+ AUTHENTICATION
61
+ ###
62
+
63
+ # Gets the ymail_wssid which is stored in the database on the remote server
64
+ # for the current user.
65
+ #
66
+ confirm: ->
67
+ Debug.log("User.confirm")
68
+ OIB.get "ymdp/signin",
69
+ "ymail_guid": YMDP.guid
70
+ , User.confirmation
71
+
72
+ # Handle response from User.confirm
73
+ #
74
+ confirmation: (response) ->
75
+ Debug.log("inside ymdp/signin callback", response)
76
+
77
+ if response.ymail_wssid
78
+ Debug.log("YMDP.response wasn't false", response.ymail_wssid)
79
+ User.storeYmailWssid(response.ymail_wssid)
80
+
81
+ # now that we've got their ymail_wssid, we can sign them in:
82
+ User.verify(Launcher.launchMain)
83
+ else
84
+ # signin didn't work properly, display an error
85
+ Debug.log("YMDP.response was false")
86
+ YMDP.showError
87
+ "method": "User.confirm",
88
+ "description": "no ymail_wssid"
89
+
90
+ # Store ymail_wssid in permanent store.
91
+ #
92
+ storeYmailWssid: (ymail_wssid) ->
93
+ raw_wssid = ymail_wssid || ""
94
+ sliced_wssid = raw_wssid.slice(0, 255)
95
+
96
+ data =
97
+ "ymail_wssid": sliced_wssid
98
+
99
+ Debug.log("About to call Data.store", data)
100
+
101
+ Data.store(data)
102
+ YMDP.ymail_wssid = ymail_wssid
103
+
104
+ # gets both guid and ymail_wssid and stores them then runs the callback_function
105
+ #
106
+ # YMDP.ymail_wssid
107
+ # YMDP.guid
108
+ #
109
+ getGuidAndYmailWssid: (callback_function) ->
110
+ Debug.log("User.getGuidAndYmailWssid")
111
+ User.getGuid (guid) ->
112
+ User.getYmailWssid (ymail_wssid) ->
113
+ callback_function(guid, ymail_wssid)
114
+
115
+ # gets the ymail_wssid from the permanent store and executes the callback function
116
+ # if there is a ymail_wssid, and the error callback if it's undefined
117
+ #
118
+ # YMDP.ymail_wssid
119
+ #
120
+ getYmailWssid: (success_function, error_function) ->
121
+ Debug.log("User.getYmailWssid")
122
+
123
+ # this function will show the error page if the ymail_wssid has not been set
124
+ #
125
+ show_error = ->
126
+ if !YMDP.ymail_wssid
127
+ Debug.log("No YMDP.ymail_wssid")
128
+
129
+ YMDP.showError
130
+ "retry": "hide"
131
+
132
+ # retrieve the user's ymail_wssid and store it in YMDP.ymail_wssid
133
+ #
134
+ Data.fetch ["ymail_wssid"], (response) ->
135
+ Debug.log("Inside Data.fetch callback")
136
+ YMDP.ymail_wssid = response.data.ymail_wssid
137
+
138
+ Debug.log("YMDP.ymail_wssid is defined", YMDP.ymail_wssid)
139
+
140
+ success_function(YMDP.ymail_wssid)
141
+
142
+ # gets the guid from the Yahoo! environment and executes the success callback
143
+ # if there is a guid, and the error callback if it's undefined
144
+ #
145
+ # YMDP.guid
146
+ #
147
+ getGuid: (success_function, error_function) ->
148
+ Debug.log("User.getGuid")
149
+
150
+ openmail.Application.getParameters (response) ->
151
+ Debug.log("getParameters callback")
152
+ YMDP.guid = response.user.guid
153
+
154
+ Debug.log("User.getGuid getParameters response", response)
155
+
156
+ params = {}
157
+ if response.data
158
+ params = response.data.launchParams
159
+
160
+ Params.init(params)
161
+
162
+ if YMDP.guid != undefined
163
+ success_function(YMDP.guid)
164
+ else
165
+ error_function()
166
+
167
+ deactivate: ->
168
+ User.getGuidAndYmailWssid (guid, ymail_wssid) ->
169
+ Data.clear()
170
+
171
+ params =
172
+ "ymail_guid": guid,
173
+ "ymail_wssid": ymail_wssid
174
+
175
+ OIB.post "/ymdp/deactivate", params,
176
+ (response) ->
177
+ if View.name != "deactivate"
178
+ Launcher.launchGoodbye()
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ymdp}
8
- s.version = "0.8.4"
8
+ s.version = "0.8.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Isaac Priestley"]
12
- s.date = %q{2011-07-06}
12
+ s.date = %q{2011-07-11}
13
13
  s.description = %q{Framework for developing applications in the Yahoo! Mail Development Platform.}
14
14
  s.email = %q{progressions@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -55,23 +55,36 @@ Gem::Specification.new do |s|
55
55
  "lib/ymdp/generator/templates/translation.pres",
56
56
  "lib/ymdp/generator/templates/view.html.haml",
57
57
  "lib/ymdp/javascripts/jquery/ab_testing.js",
58
+ "lib/ymdp/javascripts/jquery/ab_testing.js.coffee",
58
59
  "lib/ymdp/javascripts/jquery/ajax.js",
60
+ "lib/ymdp/javascripts/jquery/ajax.js.coffee",
59
61
  "lib/ymdp/javascripts/jquery/application.js",
62
+ "lib/ymdp/javascripts/jquery/application.js.coffee",
60
63
  "lib/ymdp/javascripts/jquery/authorization.js",
64
+ "lib/ymdp/javascripts/jquery/authorization.js.coffee",
61
65
  "lib/ymdp/javascripts/jquery/browser.js",
66
+ "lib/ymdp/javascripts/jquery/browser.js.coffee",
62
67
  "lib/ymdp/javascripts/jquery/data.js",
68
+ "lib/ymdp/javascripts/jquery/data.js.coffee",
63
69
  "lib/ymdp/javascripts/jquery/debug.js",
70
+ "lib/ymdp/javascripts/jquery/debug.js.coffee",
64
71
  "lib/ymdp/javascripts/jquery/education.js",
65
72
  "lib/ymdp/javascripts/jquery/flash.js",
66
73
  "lib/ymdp/javascripts/jquery/help.js",
67
74
  "lib/ymdp/javascripts/jquery/i18n.js",
68
75
  "lib/ymdp/javascripts/jquery/init.js",
76
+ "lib/ymdp/javascripts/jquery/init.js.coffee",
69
77
  "lib/ymdp/javascripts/jquery/launcher.js",
78
+ "lib/ymdp/javascripts/jquery/launcher.js.coffee",
70
79
  "lib/ymdp/javascripts/jquery/logger.js",
80
+ "lib/ymdp/javascripts/jquery/logger.js.coffee",
71
81
  "lib/ymdp/javascripts/jquery/params.js",
82
+ "lib/ymdp/javascripts/jquery/params.js.coffee",
72
83
  "lib/ymdp/javascripts/jquery/reporter.js",
84
+ "lib/ymdp/javascripts/jquery/reporter.js.coffee",
73
85
  "lib/ymdp/javascripts/jquery/tag_helper.js",
74
86
  "lib/ymdp/javascripts/jquery/user.js",
87
+ "lib/ymdp/javascripts/jquery/user.js.coffee",
75
88
  "lib/ymdp/javascripts/prototype/ab_testing.js",
76
89
  "lib/ymdp/javascripts/prototype/ajax.js",
77
90
  "lib/ymdp/javascripts/prototype/application.js",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ymdp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 4
10
- version: 0.8.4
9
+ - 5
10
+ version: 0.8.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Isaac Priestley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-06 00:00:00 -05:00
18
+ date: 2011-07-11 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -588,23 +588,36 @@ files:
588
588
  - lib/ymdp/generator/templates/translation.pres
589
589
  - lib/ymdp/generator/templates/view.html.haml
590
590
  - lib/ymdp/javascripts/jquery/ab_testing.js
591
+ - lib/ymdp/javascripts/jquery/ab_testing.js.coffee
591
592
  - lib/ymdp/javascripts/jquery/ajax.js
593
+ - lib/ymdp/javascripts/jquery/ajax.js.coffee
592
594
  - lib/ymdp/javascripts/jquery/application.js
595
+ - lib/ymdp/javascripts/jquery/application.js.coffee
593
596
  - lib/ymdp/javascripts/jquery/authorization.js
597
+ - lib/ymdp/javascripts/jquery/authorization.js.coffee
594
598
  - lib/ymdp/javascripts/jquery/browser.js
599
+ - lib/ymdp/javascripts/jquery/browser.js.coffee
595
600
  - lib/ymdp/javascripts/jquery/data.js
601
+ - lib/ymdp/javascripts/jquery/data.js.coffee
596
602
  - lib/ymdp/javascripts/jquery/debug.js
603
+ - lib/ymdp/javascripts/jquery/debug.js.coffee
597
604
  - lib/ymdp/javascripts/jquery/education.js
598
605
  - lib/ymdp/javascripts/jquery/flash.js
599
606
  - lib/ymdp/javascripts/jquery/help.js
600
607
  - lib/ymdp/javascripts/jquery/i18n.js
601
608
  - lib/ymdp/javascripts/jquery/init.js
609
+ - lib/ymdp/javascripts/jquery/init.js.coffee
602
610
  - lib/ymdp/javascripts/jquery/launcher.js
611
+ - lib/ymdp/javascripts/jquery/launcher.js.coffee
603
612
  - lib/ymdp/javascripts/jquery/logger.js
613
+ - lib/ymdp/javascripts/jquery/logger.js.coffee
604
614
  - lib/ymdp/javascripts/jquery/params.js
615
+ - lib/ymdp/javascripts/jquery/params.js.coffee
605
616
  - lib/ymdp/javascripts/jquery/reporter.js
617
+ - lib/ymdp/javascripts/jquery/reporter.js.coffee
606
618
  - lib/ymdp/javascripts/jquery/tag_helper.js
607
619
  - lib/ymdp/javascripts/jquery/user.js
620
+ - lib/ymdp/javascripts/jquery/user.js.coffee
608
621
  - lib/ymdp/javascripts/prototype/ab_testing.js
609
622
  - lib/ymdp/javascripts/prototype/ajax.js
610
623
  - lib/ymdp/javascripts/prototype/application.js