aboutsummaryrefslogtreecommitdiffstats
path: root/public/js/setup.js
blob: 56b2f0674ff22bfac2428cc75a5f544d0b73046f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
(function() {
  var g;

  g = typeof exports !== "undefined" && exports !== null ? exports : this;

  g.proceed = false;

  $(function() {
    $('#title').focus();
    return $.getJSON("/js/rates.json", function(data) {
      var currencies, user;
      currencies = Object.keys(data);
      currencies = currencies.sort();
      currencies.pop();
      $.each(currencies, function(i, v) {
        return $('#currency').append("<option value='" + v + "'>" + v + "</option>");
      });
      $("#currency option[value='CAD']").attr('selected', 'selected');
      user = $('#username').val();
      $('#currency').change(function() {
        var symbol, symbols;
        $('#symbol option').remove();
        symbol = $(this).val();
        if (!symbol) {
          return;
        }
        symbols = Object.keys(data[symbol]);
        $.each(symbols, function(i, v) {
          return $('#symbol').append("<option value='" + v + "'>" + v + " bid price</option>");
        });
        switch ($(this).val()) {
          case 'CAD':
            return $("#symbol option[value='quadrigacx']").attr('selected', 'selected');
          case 'USD':
            return $("#symbol option[value='bitstamp']").attr('selected', 'selected');
        }
      }).change();
      $('#address').change(function() {
        if (check_address($(this).val())) {
          return $(this).css('color', 'black');
        } else {
          return $(this).css('color', 'red');
        }
      });
      $('#confirm').blur(function() {
        $('#confirm_error').remove();
        if ($('#password').val() !== $('#confirm').val()) {
          $('#password, #confirm').parent().addClass('has-error');
          return $('#confirm').parent().after('<div id="confirm_error" class="alert alert-danger">Passwords don\'t match</div>');
        } else {
          return $('#password, #confirm').parent().removeClass('has-error');
        }
      });
      $('#setup').submit(function() {
        if ($('.has-error').length()) {
          return false;
        }
      });
      if (user) {
        $('#setup').attr('action', "/" + user + "/update").attr('method', 'post');
        return $.getJSON("/" + user + ".json", function(data) {
          $('#title').val(data.title);
          $('#logo').val(data.logo);
          $('#address').val(data.address);
          $("#symbol option[value='" + data.symbol + "']").attr('selected', 'selected');
          return $('#commission').val(data.commission);
        });
      }
    });
  });

}).call(this);