summaryrefslogtreecommitdiff
path: root/Postman/Postman-Configuration/postman_manual_config.js
blob: 293df28a6ed915c0417a6269ba062398b4d7e8a1 (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var transports = [];

jQuery(document).ready(
		function($) {

			// display password on entry
			enablePasswordDisplayOnEntry('input_basic_auth_password',
					'togglePasswordField');

			// tabs
			jQuery("#config_tabs").tabs();

			// on first viewing, determine whether to show password or
			// oauth section
			reloadOauthSection();

			// add an event on the transport input field
			// when the user changes the transport, determine whether
			// to show or hide the SMTP Settings
			jQuery('select#input_transport_type').change(function() {
				hide('#wizard_oauth2_help');
				reloadOauthSection();
				switchBetweenPasswordAndOAuth();
			});

			jQuery('select#input_notification_service').change(function() {
				var selected = $( this ).val();

				if ( selected == 'default' ) {
					$('#slack_cred').fadeOut('fast');
					$('#pushover_cred').fadeOut('fast');
				}

				if ( selected == 'pushover' ) {
					$('#slack_cred').fadeOut('fast');
					$('#pushover_cred').fadeIn();
				}

				if ( selected == 'slack' ) {
					$('#pushover_cred').fadeOut('fast');
					$('#slack_cred').fadeIn();
				}
			});
			

			// add an event on the authentication input field
			// on user changing the auth type, determine whether to show
			// password or oauth section
			jQuery('select#input_auth_type').change(function() {
				switchBetweenPasswordAndOAuth();
				doneTyping();
			});

			// setup before functions
			var typingTimer; // timer identifier
			var doneTypingInterval = 250; // time in ms, 5 second for
			// example

			// add an event on the hostname input field
			// on keyup, start the countdown
			jQuery(postman_hostname_element_name).keyup(function() {
				clearTimeout(typingTimer);
				if (jQuery(postman_hostname_element_name).val) {
					typingTimer = setTimeout(doneTyping, doneTypingInterval);
				}
			});

			// user is "finished typing," do something
			function doneTyping() {
				if (jQuery(postman_input_auth_type).val() == 'oauth2') {
					reloadOauthSection();
				}
			}
		});

function reloadOauthSection() {
	var hostname = jQuery(postman_hostname_element_name).val();
	var transport = jQuery('#input_transport_type').val();
	var authtype = jQuery('select#input_auth_type').val();
	var data = {
		'action' : 'manual_config',
		'auth_type' : authtype,
		'hostname' : hostname,
		'transport' : transport,
	};
	jQuery.post(ajaxurl, data, function(response) {
		if (response.success) {
			handleConfigurationResponse(response);
		}
	}).fail(function(response) {
		ajaxFailed(response);
	});
}
function switchBetweenPasswordAndOAuth() {
	var transportName = jQuery('select#input_transport_type').val();
	transports.forEach(function(item) {
		item.handleTransportChange(transportName);
	});
}