2011-06-29 15:36:14 +00:00
|
|
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
|
|
|
|
|
|
var associateProfileFields = {
|
|
|
|
onLoad: function() {
|
|
|
|
if (this.disableFormInUnsupportedBrowsers()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-07-01 16:19:53 +00:00
|
|
|
|
2011-06-29 15:36:14 +00:00
|
|
|
this.mixIn();
|
2011-07-09 18:51:35 +00:00
|
|
|
this.initObjectReferences();
|
|
|
|
this.bindEventListeners();
|
|
|
|
this.setInitialState();
|
2011-06-29 15:36:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
2011-07-09 18:51:35 +00:00
|
|
|
initObjectReferences: function() {
|
2011-06-29 15:36:14 +00:00
|
|
|
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-07-12 14:23:34 +00:00
|
|
|
this.newProfileClassSelector = $('#newProfileClassUri');
|
2011-07-09 18:51:35 +00:00
|
|
|
|
2011-07-08 20:47:31 +00:00
|
|
|
// Container <div> elements to provide background shading -- tlw72
|
|
|
|
this.associateProfileBackgroundOneArea = $('#associateProfileBackgroundOne');
|
2011-06-29 15:36:14 +00:00
|
|
|
},
|
|
|
|
|
2011-07-09 18:51:35 +00:00
|
|
|
bindEventListeners: function() {
|
2011-07-14 19:15:31 +00:00
|
|
|
this.idCache = {};
|
2011-06-29 15:36:14 +00:00
|
|
|
this.externalAuthIdField.change(function() {
|
2011-07-09 18:51:35 +00:00
|
|
|
associateProfileFields.externalAuthIdFieldHasChanged();
|
2011-06-29 15:36:14 +00:00
|
|
|
});
|
|
|
|
this.externalAuthIdField.keyup(function() {
|
2011-07-09 18:51:35 +00:00
|
|
|
associateProfileFields.externalAuthIdFieldHasChanged();
|
2011-06-29 15:36:14 +00:00
|
|
|
});
|
2011-07-11 15:19:39 +00:00
|
|
|
this.externalAuthIdField.bind("propertychange", function() {
|
|
|
|
associateProfileFields.externalAuthIdFieldHasChanged();
|
|
|
|
});
|
|
|
|
this.externalAuthIdField.bind("input", function() {
|
|
|
|
associateProfileFields.externalAuthIdFieldHasChanged();
|
|
|
|
});
|
|
|
|
|
2011-06-29 15:36:14 +00:00
|
|
|
this.verifyAssociatedProfileLink.click(function() {
|
|
|
|
associateProfileFields.openVerifyWindow();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-07-01 16:19:53 +00:00
|
|
|
this.changeAssociatedProfileLink.click(function() {
|
2011-07-09 18:51:35 +00:00
|
|
|
associateProfileFields.showAssociatingOptionsArea();
|
2011-07-01 16:19:53 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-07-09 18:51:35 +00:00
|
|
|
this.newProfileClassSelector.change(function() {
|
|
|
|
associateProfileFields.newProfileClassHasChanged();
|
|
|
|
});
|
|
|
|
|
2011-07-14 19:15:31 +00:00
|
|
|
this.acCache = {};
|
2011-07-01 16:19:53 +00:00
|
|
|
this.associateProfileNameField.autocomplete({
|
|
|
|
minLength: 3,
|
|
|
|
source: function(request, response) {
|
2011-07-14 19:15:31 +00:00
|
|
|
if (request.term in associateProfileFields.acCache) {
|
|
|
|
response(associateProfileFields.acCache[request.term]);
|
|
|
|
return;
|
|
|
|
}
|
2011-07-01 16:19:53 +00:00
|
|
|
$.ajax({
|
|
|
|
url: associateProfileFields.ajaxUrl,
|
|
|
|
dataType: 'json',
|
|
|
|
data: {
|
2011-07-08 19:47:57 +00:00
|
|
|
action: "autoCompleteProfile",
|
2011-07-01 16:19:53 +00:00
|
|
|
term: request.term,
|
|
|
|
externalAuthId: associateProfileFields.externalAuthIdField.val()
|
|
|
|
},
|
|
|
|
complete: function(xhr, status) {
|
|
|
|
var results = jQuery.parseJSON(xhr.responseText);
|
2011-07-14 19:15:31 +00:00
|
|
|
associateProfileFields.acCache[request.term] = results;
|
2011-07-01 16:19:53 +00:00
|
|
|
response(results);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
select: function(event, ui) {
|
2011-07-09 18:51:35 +00:00
|
|
|
associateProfileFields.showAssociatedProfileArea(ui.item.label, ui.item.uri, ui.item.url);
|
2011-07-01 16:19:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-07-09 18:51:35 +00:00
|
|
|
|
2011-07-01 16:19:53 +00:00
|
|
|
},
|
2011-07-09 18:51:35 +00:00
|
|
|
|
|
|
|
setInitialState: function() {
|
|
|
|
if (this.externalAuthIdField.val().length == 0) {
|
|
|
|
this.hideAllOptionals();
|
|
|
|
} else if (this.associatedProfileInfo) {
|
|
|
|
this.showAssociatedProfileArea(this.associatedProfileInfo.label, this.associatedProfileInfo.uri, this.associatedProfileInfo.url);
|
|
|
|
} else {
|
|
|
|
this.showAssociatingOptionsArea();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
externalAuthIdFieldHasChanged: function() {
|
2011-07-14 19:15:31 +00:00
|
|
|
var externalAuthId = this.externalAuthIdField.val();
|
|
|
|
|
|
|
|
if (externalAuthId.length == 0) {
|
2011-07-09 18:51:35 +00:00
|
|
|
this.hideAllOptionals();
|
|
|
|
return;
|
|
|
|
}
|
2011-07-14 19:15:31 +00:00
|
|
|
|
|
|
|
if (externalAuthId in this.idCache) {
|
|
|
|
var results = this.idCache[externalAuthId];
|
|
|
|
this.applyAjaxResultsForExternalAuthIdField(results)
|
|
|
|
return;
|
|
|
|
}
|
2011-07-01 16:19:53 +00:00
|
|
|
|
2011-06-29 15:36:14 +00:00
|
|
|
$.ajax({
|
|
|
|
url: associateProfileFields.ajaxUrl,
|
|
|
|
dataType: "json",
|
|
|
|
data: {
|
2011-07-08 19:47:57 +00:00
|
|
|
action: "checkExternalAuth",
|
2011-07-01 16:19:53 +00:00
|
|
|
userAccountUri: associateProfileFields.userUri,
|
2011-07-14 19:15:31 +00:00
|
|
|
externalAuthId: externalAuthId
|
2011-06-29 15:36:14 +00:00
|
|
|
},
|
|
|
|
complete: function(xhr, status) {
|
|
|
|
var results = $.parseJSON(xhr.responseText);
|
2011-07-14 19:15:31 +00:00
|
|
|
associateProfileFields.idCache[externalAuthId] = results;
|
|
|
|
associateProfileFields.applyAjaxResultsForExternalAuthIdField(results);
|
2011-06-29 15:36:14 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2011-07-14 19:15:31 +00:00
|
|
|
|
|
|
|
applyAjaxResultsForExternalAuthIdField: function(results) {
|
|
|
|
if (results.idInUse) {
|
|
|
|
this.showExternalAuthInUseMessage()
|
|
|
|
} else if (results.matchesProfile) {
|
|
|
|
this.showAssociatedProfileArea(results.profileLabel, results.profileUri, results.profileUrl)
|
|
|
|
} else {
|
|
|
|
this.showAssociatingOptionsArea();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-06-29 15:36:14 +00:00
|
|
|
openVerifyWindow: function() {
|
|
|
|
window.open(this.verifyUrl, 'verifyMatchWindow', 'width=640,height=640,scrollbars=yes,resizable=yes,status=yes,toolbar=no,menubar=no,location=no');
|
|
|
|
},
|
2011-07-09 18:51:35 +00:00
|
|
|
|
|
|
|
newProfileClassHasChanged: function() {
|
|
|
|
if (this.newProfileClassSelector.val().length == 0) {
|
2011-07-11 15:19:39 +00:00
|
|
|
this.associateProfileNameField.attr("disabled","");
|
2011-07-09 18:51:35 +00:00
|
|
|
} else {
|
|
|
|
this.associateProfileNameField.val('');
|
2011-07-11 15:19:39 +00:00
|
|
|
this.associateProfileNameField.attr("disabled","disabled");
|
2011-07-09 18:51:35 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
hideAllOptionals: function() {
|
|
|
|
this.hideExternalAuthInUseMessage();
|
|
|
|
this.hideAssociatedProfileArea();
|
|
|
|
this.hideAssociatingOptionsArea();
|
|
|
|
},
|
|
|
|
|
|
|
|
hideExternalAuthInUseMessage: function() {
|
|
|
|
this.externalAuthIdInUseMessage.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
hideAssociatedProfileArea: function() {
|
2011-06-29 15:36:14 +00:00
|
|
|
this.associatedArea.hide();
|
2011-07-11 15:19:39 +00:00
|
|
|
this.associateProfileBackgroundOneArea.css("background-color","#fff");
|
|
|
|
this.associateProfileBackgroundOneArea.css("border","none");
|
2011-07-09 18:51:35 +00:00
|
|
|
this.associatedProfileUriField.val('');
|
|
|
|
},
|
|
|
|
|
|
|
|
hideAssociatingOptionsArea: function() {
|
2011-06-29 15:36:14 +00:00
|
|
|
this.associationOptionsArea.hide();
|
2011-07-11 15:19:39 +00:00
|
|
|
this.associateProfileBackgroundOneArea.css("background-color","#fff");
|
|
|
|
this.associateProfileBackgroundOneArea.css("border","none");
|
2011-07-09 18:51:35 +00:00
|
|
|
this.associateProfileNameField.val('');
|
2011-07-11 15:19:39 +00:00
|
|
|
this.newProfileClassSelector.get(0).selectedIndex = 0;
|
2011-06-29 15:36:14 +00:00
|
|
|
},
|
2011-07-09 18:51:35 +00:00
|
|
|
|
|
|
|
showExternalAuthInUseMessage: function() {
|
|
|
|
this.hideAssociatedProfileArea();
|
|
|
|
this.hideAssociatingOptionsArea();
|
2011-06-29 15:36:14 +00:00
|
|
|
|
2011-07-09 18:51:35 +00:00
|
|
|
this.externalAuthIdInUseMessage.show();
|
2011-06-29 15:36:14 +00:00
|
|
|
},
|
2011-07-09 18:51:35 +00:00
|
|
|
|
|
|
|
showAssociatedProfileArea: function(name, uri, url) {
|
|
|
|
this.hideExternalAuthInUseMessage();
|
|
|
|
this.hideAssociatingOptionsArea();
|
|
|
|
|
|
|
|
if (this.associationEnabled) {
|
|
|
|
this.associatedProfileNameSpan.html(name);
|
|
|
|
this.associatedProfileUriField.val(uri);
|
|
|
|
this.verifyUrl = url;
|
|
|
|
this.associatedArea.show();
|
2011-07-11 15:19:39 +00:00
|
|
|
this.associateProfileBackgroundOneArea.css("background-color","#f1f2ee");
|
|
|
|
this.associateProfileBackgroundOneArea.css("border","1px solid #ccc");
|
2011-06-29 15:36:14 +00:00
|
|
|
}
|
|
|
|
},
|
2011-07-09 18:51:35 +00:00
|
|
|
|
|
|
|
showAssociatingOptionsArea: function() {
|
|
|
|
this.hideExternalAuthInUseMessage();
|
|
|
|
this.hideAssociatedProfileArea();
|
2011-06-29 15:36:14 +00:00
|
|
|
|
2011-07-09 18:51:35 +00:00
|
|
|
if (this.associationEnabled) {
|
|
|
|
this.newProfileClassHasChanged();
|
|
|
|
this.associationOptionsArea.show();
|
2011-07-11 15:19:39 +00:00
|
|
|
this.associateProfileBackgroundOneArea.css("background-color","#f1f2ee");
|
|
|
|
this.associateProfileBackgroundOneArea.css("border","1px solid #ccc");
|
2011-07-09 18:51:35 +00:00
|
|
|
}
|
2011-07-11 18:57:46 +00:00
|
|
|
}
|
2011-07-01 16:19:53 +00:00
|
|
|
|
2011-06-29 15:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
associateProfileFields.onLoad();
|
|
|
|
});
|
2011-07-05 20:37:44 +00:00
|
|
|
|