2011-06-29 15:36:14 +00:00
|
|
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
|
|
|
|
|
|
var associateProfileFields = {
|
|
|
|
|
|
|
|
/* *** Initial page setup *** */
|
|
|
|
|
|
|
|
onLoad: function() {
|
2011-07-05 20:37:44 +00:00
|
|
|
//console.log('Here we are');
|
2011-06-29 15:36:14 +00:00
|
|
|
if (this.disableFormInUnsupportedBrowsers()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-07-01 16:19:53 +00:00
|
|
|
|
2011-06-29 15:36:14 +00:00
|
|
|
this.mixIn();
|
|
|
|
this.initObjects();
|
|
|
|
this.initPage();
|
|
|
|
},
|
|
|
|
|
|
|
|
disableFormInUnsupportedBrowsers: function() {
|
|
|
|
var disableWrapper = $('#ie67DisableWrapper');
|
|
|
|
|
|
|
|
// Check for unsupported browsers only if the element exists on the page
|
|
|
|
if (disableWrapper.length) {
|
|
|
|
if (vitro.browserUtils.isIELessThan8()) {
|
|
|
|
disableWrapper.show();
|
|
|
|
$('.noIE67').hide();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
mixIn: function() {
|
|
|
|
$.extend(this, associateProfileFieldsData);
|
|
|
|
},
|
|
|
|
|
|
|
|
// On page load, create references for easy access to form elements.
|
|
|
|
initObjects: function() {
|
|
|
|
this.form = $('#userAccountForm');
|
|
|
|
|
|
|
|
// The external auth ID field and messages
|
|
|
|
this.externalAuthIdField = $('#externalAuthId');
|
|
|
|
this.externalAuthIdInUseMessage = $('#externalAuthIdInUse');
|
|
|
|
|
|
|
|
// We have an associated profile
|
|
|
|
this.associatedArea = $('#associated');
|
|
|
|
this.associatedProfileNameSpan = $('#associatedProfileName');
|
|
|
|
this.verifyAssociatedProfileLink = $('#verifyProfileLink');
|
2011-07-01 16:19:53 +00:00
|
|
|
this.changeAssociatedProfileLink = $('#changeProfileLink');
|
2011-06-29 15:36:14 +00:00
|
|
|
this.associatedProfileUriField = $('#associatedProfileUri')
|
|
|
|
|
|
|
|
// We want to associate a profile
|
|
|
|
this.associationOptionsArea = $('#associationOptions');
|
2011-07-01 16:19:53 +00:00
|
|
|
this.associateProfileNameField = $('#associateProfileName');
|
2011-06-29 15:36:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Initial page setup. Called only at page load.
|
|
|
|
initPage: function() {
|
|
|
|
this.checkForAssociatedProfile();
|
|
|
|
this.bindEventListeners();
|
2011-07-01 16:19:53 +00:00
|
|
|
this.initAutocomplete();
|
2011-06-29 15:36:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
bindEventListeners: function() {
|
2011-07-05 21:20:13 +00:00
|
|
|
//console.log('bindEventListeners');
|
2011-06-29 15:36:14 +00:00
|
|
|
|
|
|
|
this.externalAuthIdField.change(function() {
|
|
|
|
associateProfileFields.checkForAssociatedProfile();
|
|
|
|
});
|
|
|
|
this.externalAuthIdField.keyup(function() {
|
|
|
|
associateProfileFields.checkForAssociatedProfile();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.verifyAssociatedProfileLink.click(function() {
|
|
|
|
associateProfileFields.openVerifyWindow();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-07-01 16:19:53 +00:00
|
|
|
this.changeAssociatedProfileLink.click(function() {
|
|
|
|
associateProfileFields.associatedProfileUriField.val('');
|
|
|
|
associateProfileFields.associateProfileNameField.val('');
|
|
|
|
associateProfileFields.showExternalAuthIdNotRecognized();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-06-29 15:36:14 +00:00
|
|
|
},
|
|
|
|
|
2011-07-01 16:19:53 +00:00
|
|
|
initAutocomplete: function() {
|
|
|
|
this.associateProfileNameField.autocomplete({
|
|
|
|
minLength: 3,
|
|
|
|
source: function(request, response) {
|
|
|
|
$.ajax({
|
|
|
|
url: associateProfileFields.ajaxUrl,
|
|
|
|
dataType: 'json',
|
|
|
|
data: {
|
|
|
|
function: "autoCompleteProfile",
|
|
|
|
term: request.term,
|
|
|
|
externalAuthId: associateProfileFields.externalAuthIdField.val()
|
|
|
|
},
|
|
|
|
complete: function(xhr, status) {
|
2011-07-05 21:20:13 +00:00
|
|
|
//console.log('response text' + xhr.responseText);
|
2011-07-01 16:19:53 +00:00
|
|
|
var results = jQuery.parseJSON(xhr.responseText);
|
|
|
|
response(results);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
select: function(event, ui) {
|
|
|
|
associateProfileFields.showSelectedProfile(ui.item);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2011-06-29 15:36:14 +00:00
|
|
|
checkForAssociatedProfile: function() {
|
|
|
|
$.ajax({
|
|
|
|
url: associateProfileFields.ajaxUrl,
|
|
|
|
dataType: "json",
|
|
|
|
data: {
|
|
|
|
function: "checkExternalAuth",
|
2011-07-01 16:19:53 +00:00
|
|
|
userAccountUri: associateProfileFields.userUri,
|
2011-06-29 15:36:14 +00:00
|
|
|
externalAuthId: associateProfileFields.externalAuthIdField.val()
|
|
|
|
},
|
|
|
|
complete: function(xhr, status) {
|
|
|
|
var results = $.parseJSON(xhr.responseText);
|
|
|
|
if (results.idInUse) {
|
|
|
|
associateProfileFields.showExternalAuthIdInUse()
|
|
|
|
} else if (results.matchesProfile) {
|
2011-07-01 16:19:53 +00:00
|
|
|
associateProfileFields.showExternalAuthIdMatchesProfile(results.profileUri, results.profileUrl, results.profileLabel)
|
2011-06-29 15:36:14 +00:00
|
|
|
} else {
|
|
|
|
associateProfileFields.showExternalAuthIdNotRecognized()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
openVerifyWindow: function() {
|
|
|
|
window.open(this.verifyUrl, 'verifyMatchWindow', 'width=640,height=640,scrollbars=yes,resizable=yes,status=yes,toolbar=no,menubar=no,location=no');
|
|
|
|
},
|
|
|
|
|
|
|
|
showExternalAuthIdInUse: function() {
|
|
|
|
this.externalAuthIdInUseMessage.show();
|
|
|
|
this.associatedArea.hide();
|
|
|
|
this.associationOptionsArea.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
showExternalAuthIdMatchesProfile: function(profileUri, profileUrl, profileLabel) {
|
2011-07-05 21:20:13 +00:00
|
|
|
//console.log('showExternalAuthIdMatchesProfile: profileUri=' + profileUri + ', profileUrl=' + profileUrl + ', profileLabel='+ profileLabel);
|
2011-06-29 15:36:14 +00:00
|
|
|
|
|
|
|
this.externalAuthIdInUseMessage.hide();
|
|
|
|
this.associatedArea.show();
|
|
|
|
this.associationOptionsArea.hide();
|
|
|
|
|
|
|
|
this.associatedProfileNameSpan.html(profileLabel);
|
|
|
|
this.associatedProfileUriField.val(profileUri);
|
|
|
|
this.verifyUrl = profileUrl;
|
|
|
|
},
|
|
|
|
|
|
|
|
showExternalAuthIdNotRecognized: function() {
|
|
|
|
this.externalAuthIdInUseMessage.hide();
|
|
|
|
this.associatedArea.hide();
|
|
|
|
|
2011-07-01 16:19:53 +00:00
|
|
|
if (this.associationEnabled && this.externalAuthIdField.val().length > 0) {
|
2011-06-29 15:36:14 +00:00
|
|
|
this.associationOptionsArea.show();
|
|
|
|
} else {
|
|
|
|
this.associationOptionsArea.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-07-01 16:19:53 +00:00
|
|
|
showSelectedProfile: function(item) {
|
|
|
|
this.showExternalAuthIdMatchesProfile(item.uri, item.url, item.label);
|
|
|
|
},
|
|
|
|
|
2011-06-29 15:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
associateProfileFields.onLoad();
|
|
|
|
});
|
2011-07-05 20:37:44 +00:00
|
|
|
|