You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

89 rivejä
1.8 KiB

  1. define([
  2. 'js/system/events',
  3. 'js/system/client',
  4. 'ui/factory',
  5. 'html!ui/templates/login/template',
  6. 'css!ui/templates/login/styles',
  7. 'js/rendering/renderer'
  8. ], function(
  9. events,
  10. client,
  11. uiFactory,
  12. template,
  13. styles,
  14. renderer
  15. ) {
  16. return {
  17. tpl: template,
  18. centered: true,
  19. postRender: function() {
  20. this.onEvent('onHandshake', this.onHandshake.bind(this));
  21. this.on('.btnLogin', 'click', this.onLoginClick.bind(this));
  22. this.on('.btnRegister', 'click', this.onRegisterClick.bind(this));
  23. this.find('.extra, .version')
  24. .appendTo($('<div class="uiLoginExtra"></div>>').appendTo('.ui-container'));
  25. $('.uiLoginExtra').find('.button').on('click', this.redirect.bind(this));
  26. this.find('input')
  27. .on('keyup', this.onKeyDown.bind(this))
  28. .eq(0).focus();
  29. renderer.buildTitleScreen();
  30. },
  31. redirect: function(e) {
  32. var location = $(e.target).attr('location');
  33. window.open(location, '_blank');
  34. },
  35. onKeyDown: function(e) {
  36. if (e.keyCode == 13)
  37. this.onLoginClick();
  38. },
  39. onHandshake: function() {
  40. this.show();
  41. },
  42. onLoginClick: function() {
  43. this.el.addClass('disabled');
  44. client.request({
  45. cpn: 'auth',
  46. method: 'login',
  47. data: {
  48. username: this.val('.txtUsername'),
  49. password: this.val('.txtPassword')
  50. },
  51. callback: this.onLogin.bind(this)
  52. });
  53. },
  54. onLogin: function(res) {
  55. this.el.removeClass('disabled');
  56. if (!res) {
  57. uiFactory.build('characters', {});
  58. $('.uiLoginExtra').remove();
  59. this.el.remove();
  60. } else
  61. this.el.find('.message').html(res);
  62. },
  63. onRegisterClick: function() {
  64. this.el.addClass('disabled');
  65. client.request({
  66. cpn: 'auth',
  67. method: 'register',
  68. data: {
  69. username: this.val('.txtUsername'),
  70. password: this.val('.txtPassword')
  71. },
  72. callback: this.onLogin.bind(this)
  73. });
  74. }
  75. };
  76. });