Project

General

Profile

« Previous | Next » 

Revision 7391

ajax-ify the call to perform identity mapping (including errors)

View differences:

index.jsp
69 69
<script language="javascript" type="text/javascript" src="<%=STYLE_COMMON_URL%>/jquery/jquery.js"></script>
70 70
<script language="javascript" type="text/javascript" src="<%=STYLE_COMMON_URL%>/jquery/jqueryui/js/jquery-ui-1.8.6.custom.min.js"></script>
71 71
<script type="text/javascript">
72
var portalURL = "https://cn-dev.dataone.org/portal/identity";
73 72

  
73

  
74
function makeAjaxCall(url, formId, divId, callback) {
75
	$('#' + divId).load(
76
		url, //url
77
		$("#" + formId).serialize(), //data
78
		function(response, status, xhr) {
79
			if (status == "error") {
80
				var msg = "Sorry but there was an error: ";
81
				$("#error").html(msg + response);
82
				$("#error").dialog('open');
83
			} else {
84
				// call the callback
85
				if (callback) {
86
					setTimeout(callback, 0);
87
				}
88
			}
89
		}
90
	);
91
}
92
function performMapping() {
93
	$('#mapForm [name="action"]').val('mapIdentity');
94
	makeAjaxCall(
95
			'performMapping.jsp', 
96
			'mapForm', 
97
			'result', 
98
			function() { $("#result").dialog('open'); });
99
	
100
}
74 101
function lookupToken() {
75 102
	var data = $('#tokenFrame').contents();
76 103
	$('#mapForm [name="token"]').val(data);
......
84 111
	$('#mapForm [name="primarySubject"]').val(data);
85 112
	alert('Loaded subject: ' + data);
86 113
}
114
function initDialogs() {
115
	// make the result section a dialog (popup)
116
	$("#result").dialog(
117
			{	autoOpen: false,
118
				title: "Results",
119
				width: 450
120
			}
121
		);
122
	$("#error").dialog(
123
			{	autoOpen: false,
124
				title: "Error",
125
				width: 450
126
			}
127
		);
128
}
87 129
function initTabs() {
88 130
	$(function() {
89 131
		$("#tabs").tabs();
......
92 134
}
93 135
function init() {
94 136
	initTabs();
137
	initDialogs();
95 138
	//lookupToken();
96 139
	//lookupSubject();
97 140
}
......
104 147
	<h1></h1>
105 148
</div>
106 149

  
150
<!-- load AJAX results here -->
151
<div id="result"></div>
152
<div id="error"></div>
153

  
107 154
<div id="tabs">
108 155
	<!-- place holder for tabs -->
109 156
	<ul></ul>
......
132 179
		
133 180
		
134 181

  
135
		<form action="performMapping.jsp" target="right" method="POST" id="mapForm">
182
		<form action="" method="POST" id="mapForm">
136 183
			2. Enter your DataONE token:
137 184
			<br/>
138 185
			<input type="text" name="token" size="50">
139 186
			<input type="hidden" name="secondarySubject" value="<%=userName %>">
140 187
			<input type="hidden" name="action" value="mapIdentity">
141
			<input type="submit" value="Map Identity">
188
			<input type="button" value="Map Identity" onclick="performMapping()">
142 189
		</form>
143 190

  
144 191
		<hr/>

Also available in: Unified diff