Sha256: fd434de1228e844c5c6bed1dbc9bd37a0ac7cd3c3e342ec1e68171fc692b9604

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

var SlackRubyBotServer = {};

$(document).ready(function() {

  SlackRubyBotServer.message = function(text) {
    $('#messages').fadeOut('slow', function() {
      $('#messages').fadeIn('slow').html(text)
    });
  };

  SlackRubyBotServer.error = function(xhr) {
    try {
      var message;
      if (xhr.responseText) {
        var rc = JSON.parse(xhr.responseText);
        if (rc && rc.message) {
          message = rc.message;
          if (message == 'invalid_code') {
            message = 'The code returned from the OAuth workflow was invalid.'
          } else if (message == 'code_already_used') {
            message = 'The code returned from the OAuth workflow has already been used.'
          }
        }
      }

      SlackRubyBotServer.message(message || xhr.statusText || xhr.responseText || 'Unexpected Error');

    } catch(err) {
      SlackRubyBotServer.message(err.message);
    }
  };

  // Slack OAuth
  var code = $.url('?code')
  var state = $.url('?state')
  if (code) {
    SlackRubyBotServer.message('Working, please wait ...');
    $('#register').hide();
    $.ajax({
      type: "POST",
      url: "/api/teams",
      data: {
        code: code,
        state: state
      },
      success: function(data) {
        SlackRubyBotServer.message('Team successfully registered!<br><br>DM <b>@bot</b> or create a <b>#channel</b> and invite <b>@bot</b> to it.');
      },
      error: SlackRubyBotServer.error
    });
  }
});

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slack-ruby-bot-server-0.11.1 public/scripts/register.js
slack-ruby-bot-server-0.11.0 public/scripts/register.js
slack-ruby-bot-server-0.10.0 public/scripts/register.js