PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/libs/sencha-io/src/io/ux/AuthFacebook.js

https://bitbucket.org/vdthutech/sencha-touch-2-sencha.io-example
JavaScript | 145 lines | 80 code | 27 blank | 38 comment | 4 complexity | 7cf655b273058541773f4b1b302e9f4f MD5 | raw file
Possible License(s): GPL-3.0, MIT, BSD-3-Clause
  1. /**
  2. * Default Facebook login panel. Ext.io.Controller will automatically display this panel if the application is configured to use Facebook as its login type.
  3. *
  4. */
  5. if (!Ext.getVersion('extjs')) {
  6. Ext.define("Ext.io.ux.AuthFacebook", {
  7. extend: 'Ext.Container',
  8. requires: ["Ext.TitleBar","Ext.form.Panel", "Ext.form.FieldSet", "Ext.field.Password", "Ext.field.Email"],
  9. /**
  10. * @event loginUser
  11. * Fired when the user has entered their auth credentials.
  12. * {Ext.io.Controller} listens for this event and will attempt to login
  13. * the user with the passed credentials.
  14. * @param {Object} auth Key/values given by the user to authenticate with.
  15. */
  16. /**
  17. * @event cancel
  18. * Fired when the user doesn't want to login.
  19. * {Ext.io.Controller} listens for this event and will
  20. * close the login pannel.
  21. */
  22. /**
  23. * @private
  24. * config
  25. */
  26. config: {
  27. id: "loginpanel",
  28. fullscreen: true,
  29. control: {
  30. "button[action=cancellogin]": {
  31. tap: "hideLogin"
  32. }
  33. },
  34. items: [
  35. {
  36. docked: 'top',
  37. xtype: 'titlebar',
  38. title: 'Login',
  39. items: [
  40. {
  41. text: "cancel",
  42. action: "cancellogin"
  43. }
  44. ]
  45. },
  46. {
  47. xtype: "panel",
  48. html: "To use this application please sign in with your Facebook account.",
  49. padding: "20%",
  50. align: "center"
  51. },
  52. {
  53. xtype: "button",
  54. text: "Login with Facebook",
  55. disabled: true,
  56. width: "80%",
  57. action: "fblogin",
  58. ui: 'action',
  59. margin: "20%",
  60. align: "center"
  61. }
  62. ]
  63. },
  64. /**
  65. * Login button tapped
  66. */
  67. loginButtonTapped: function(button) {
  68. console.log("argum", arguments);
  69. button.setDisabled(true);
  70. document.location.href=this.redirectUrl;
  71. },
  72. /**
  73. * Initialize
  74. */
  75. initialize: function() {
  76. var fbConf = this.group.getData().fb;
  77. if(!fbConf) {
  78. console.error("Facebook not configured for group.", group);
  79. allback.call(scope, false);
  80. }
  81. var facebookAppId = fbConf.appId;
  82. this.redirectUrl = "https://m.facebook.com/dialog/oauth?" + Ext.Object.toQueryString({
  83. redirect_uri: window.location.protocol + "//" + window.location.host + window.location.pathname,
  84. client_id: facebookAppId,
  85. response_type: 'token',
  86. bustCache: new Date().getTime()
  87. });
  88. var button = this.query("button[action=fblogin]")[0];
  89. if(button) {
  90. button.on({
  91. tap: this.loginButtonTapped,
  92. scope: this
  93. });
  94. button.setDisabled(false)
  95. } else {
  96. console.error("Could not find a button[action=fblogin] in the AuthFacebook view. User won't be able to login.");
  97. }
  98. },
  99. /**
  100. * Reset the form to its default state.
  101. */
  102. resetForm: function() {
  103. //NA
  104. },
  105. /**
  106. * {Ext.io.Controller} will call this method when login fails.
  107. */
  108. showLoginErrors: function() {
  109. //NA //Ext.Msg.alert('Login Error', 'Invalid username or passsword', Ext.emptyFn);
  110. },
  111. /**
  112. * @private
  113. */
  114. hideLogin: function() {
  115. this.fireEvent("cancel");
  116. }
  117. });
  118. }