From a14b49e59e6764b6b7764ee3bc95d0d049bf21f8 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 13 May 2015 22:57:53 +0200 Subject: Turned javascript into coffeescript --- src/js/Botleagues.coffee | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/js/Botleagues.coffee (limited to 'src/js/Botleagues.coffee') diff --git a/src/js/Botleagues.coffee b/src/js/Botleagues.coffee new file mode 100644 index 0000000..06ace76 --- /dev/null +++ b/src/js/Botleagues.coffee @@ -0,0 +1,54 @@ +$.cookie.json = true + +@Botleagues = + + url: 'https://api.local.botleagues.camilstaps.nl' + + cookie_login_email: 'botleagues_login_email' + cookie_login_user_id: 'botleagues_login_user_id' + cookie_login_token: 'botleagues_login_token' + cookie_login_valid_till: 'botleagues_login_valid_till' + + request: (user_options) -> + callback = user_options.callback + + options = + method: 'GET' + dataType: 'json' + complete: (data) -> + callback data.responseJSON + + url = Botleagues.url + '/' + user_options.endpoint + delete user_options.callback + delete user_options.endpoint + + for key, option of user_options + options[key] = option + + jQuery.ajax url, options + + return + + login: (email, password) -> + Botleagues.request + endpoint: 'user_token' + method: 'POST' + callback: BotleaguesCallback.login + headers: + 'Authorization': 'Basic ' + btoa(email + ':' + password) + + $.cookie Botleagues.cookie_login_email, email + + return + + logout: -> + Botleagues.clearLoginCookies() + window.location = '/' + return + + clearLoginCookies: -> + $.removeCookie Botleagues.cookie_login_email + $.removeCookie Botleagues.cookie_login_user_id + $.removeCookie Botleagues.cookie_login_token + $.removeCookie Botleagues.cookie_login_valid_till + return \ No newline at end of file -- cgit v1.2.3