oauthController.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. define([ 'models/oauthModel' ], function( OAuthModel ) {
  2. var controller = Marionette.Object.extend( {
  3. initialize: function() {
  4. this.oauth = new OAuthModel();
  5. nfRadio.channel( 'dashboard' ).reply( 'get:oauth', this.getOAuth, this );
  6. nfRadio.channel( 'dashboard' ).reply( 'disconnect:oauth', this.disconnect, this );
  7. nfRadio.channel( 'dashboard' ).reply( 'oauth:learn-more', this.learnMoreModal, this );
  8. this.initOAuth();
  9. },
  10. getOAuth: function() {
  11. return this.oauth;
  12. },
  13. /*
  14. * Fetch the OAuth Model add and notify via nfRadio.
  15. */
  16. initOAuth: function() {
  17. this.oauth.fetch({
  18. success: function( model ){
  19. nfRadio.channel( 'dashboard' ).trigger( 'fetch:oauth' );
  20. }
  21. });
  22. },
  23. /**
  24. * Confirm disconnecting services, then POST to the server to to disconnect.
  25. */
  26. disconnect: function() {
  27. var that = this;
  28. new jBox('Confirm', {
  29. width: 750,
  30. content: nfi18n.oauthDisconnectContent,
  31. confirmButton: nfi18n.oauthDisconnectConfirm,
  32. cancelButton: nfi18n.oauthDisconnectCancel,
  33. closeOnConfirm: true,
  34. confirm: function(){
  35. jQuery.ajax({
  36. type: "POST",
  37. url: ajaxurl + '?action=nf_oauth_disconnect',
  38. success: function( response ){
  39. console.log( response );
  40. that.initOAuth();
  41. }
  42. });
  43. }
  44. }).open();
  45. },
  46. /**
  47. * Show a Learn More modal.
  48. */
  49. learnMoreModal: function() {
  50. var that = this;
  51. new jBox('Modal', {
  52. width: 500,
  53. content: nfi18n.oauthLearnMoreContent,
  54. }).open();
  55. }
  56. });
  57. return controller;
  58. } );