NIHVIVO-725, NIHVIVO-629 Javascript for one-step, two-step versions of form

This commit is contained in:
rjy7 2010-07-12 00:33:21 +00:00
parent 8eea64d949
commit b8cf560daa
3 changed files with 25 additions and 27 deletions

View file

@ -58,11 +58,11 @@ This is intended to create a set of statements like:
String subjectName = ((Individual) request.getAttribute("subject")).getName(); String subjectName = ((Individual) request.getAttribute("subject")).getName();
if ( ((String)request.getAttribute("predicateUri")).endsWith("hasPrincipalInvestigatorRole") ) { %> if ( ((String)request.getAttribute("predicateUri")).endsWith("hasPrincipalInvestigatorRole") ) { %>
<v:jsonset var="roleType">http://vivoweb.org/ontology/core#PrincipalInvestigatorRole</v:jsonset> <v:jsonset var="roleType">http://vivoweb.org/ontology/core#PrincipalInvestigatorRole</v:jsonset>
<c:set var="submitButtonLabel">Create principal investigator</c:set> <c:set var="submitButtonLabel">Principal Investigator</c:set>
<c:set var="formHeading">Create a new principal investigator entry for <%= subjectName %></c:set> <c:set var="formHeading">Create a new principal investigator entry for <%= subjectName %></c:set>
<% }else{ %> <% }else{ %>
<v:jsonset var="roleType">http://vivoweb.org/ontology/core#CoPrincipalInvestigatorRole</v:jsonset> <v:jsonset var="roleType">http://vivoweb.org/ontology/core#CoPrincipalInvestigatorRole</v:jsonset>
<c:set var="submitButtonLabel">Create co-principal investigator</c:set> <c:set var="submitButtonLabel">Co-Principal Investigator</c:set>
<c:set var="formHeading">Create a new co-principal investigator entry for <%= subjectName %></c:set> <c:set var="formHeading">Create a new co-principal investigator entry for <%= subjectName %></c:set>
<% } %> <% } %>

View file

@ -228,7 +228,7 @@ PREFIX core: <${vivoCore}> SELECT ?individual WHERE {<${subjectUri}> core:author
</div> </div>
</div> </div>
<p class="submit"><v:input type="submit" id="submit" value="Create Publication" cancel="true" /></p> <p class="submit"><v:input type="submit" id="submit" value="Publication" cancel="true" /></p>
<p id="requiredLegend" class="requiredHint">* required fields</p> <p id="requiredLegend" class="requiredHint">* required fields</p>
</form> </form>

View file

@ -22,17 +22,10 @@ var customForm = {
this.form = $('#content form'); this.form = $('#content form');
this.fullViewOnly = $('#fullViewOnly'); this.fullViewOnly = $('#fullViewOnly');
this.button = $('#submit'); this.button = $('#submit');
this.baseButtonText = this.button.val();
this.requiredLegend = $('#requiredLegend'); this.requiredLegend = $('#requiredLegend');
this.typeSelector = this.form.find('#typeSelector'); this.typeSelector = this.form.find('#typeSelector');
if (!this.typeSelector) {
this.formSteps = 1;
// there's also going to be a 3-step form
} else {
this.formSteps = 2;
}
// This is the label element for the field with name 'label' // This is the label element for the field with name 'label'
this.labelFieldLabel = $('label[for=' + $('#label').attr('id') + ']'); this.labelFieldLabel = $('label[for=' + $('#label').attr('id') + ']');
// Get this on page load, so we can prepend to it. We can't just prepend to the current label text, // Get this on page load, so we can prepend to it. We can't just prepend to the current label text,
@ -45,6 +38,7 @@ var customForm = {
// These are classed rather than id'd in case we want more than one autocomplete on a form. // These are classed rather than id'd in case we want more than one autocomplete on a form.
this.acSelector = this.form.find('.acSelector'); this.acSelector = this.form.find('.acSelector');
this.acSelection = this.form.find('.acSelection'); this.acSelection = this.form.find('.acSelection');
this.acReceiver = this.form.find('.acReceiver');
$.extend(this, customFormData); $.extend(this, customFormData);
@ -53,11 +47,18 @@ var customForm = {
// Set up the form on page load // Set up the form on page load
initPage: function() { initPage: function() {
if (!this.typeSelector.length) {
this.formSteps = 1;
// there's also going to be a 3-step form
} else {
this.formSteps = 2;
}
this.bindEventListeners(); this.bindEventListeners();
this.initAutocomplete(); this.initAutocomplete();
if (this.findValidationErrors() || this.formSteps == 1) { if (this.formSteps == 1 || this.findValidationErrors()) {
this.initFormFullView(); this.initFormFullView();
} else { } else {
this.initFormTypeView(); this.initFormTypeView();
@ -72,9 +73,7 @@ var customForm = {
this.requiredLegend.hide(); this.requiredLegend.hide();
this.or.hide(); this.or.hide();
if( this.formSteps > 1 ){
this.cancel.unbind('click'); this.cancel.unbind('click');
}
}, },
initFormFullView: function() { initFormFullView: function() {
@ -83,7 +82,7 @@ var customForm = {
this.or.show(); this.or.show();
this.requiredLegend.show(); this.requiredLegend.show();
this.button.show(); this.button.show();
this.button.val('Create Publication'); this.button.val('Create ' + this.baseButtonText);
if( this.formSteps > 1 ){ if( this.formSteps > 1 ){
this.cancel.unbind('click'); this.cancel.unbind('click');
@ -119,7 +118,6 @@ var customForm = {
this.getAcFilter(); this.getAcFilter();
this.acCache = {}; this.acCache = {};
//this.baseAcUrl = customFormData.acUrl;
this.acSelector.autocomplete({ this.acSelector.autocomplete({
minLength: 3, minLength: 3,
@ -160,10 +158,10 @@ var customForm = {
getAcFilter: function() { getAcFilter: function() {
$.ajax({ $.ajax({
url: customFormData.sparqlQueryUrl, url: customForm.sparqlQueryUrl,
data: { data: {
resultFormat: 'RS_JSON', resultFormat: 'RS_JSON',
query: customFormData.sparqlForAcFilter query: customForm.sparqlForAcFilter
}, },
success: function(data, status, xhr) { success: function(data, status, xhr) {
// Not sure why, but we need an explicit json parse here. jQuery // Not sure why, but we need an explicit json parse here. jQuery
@ -188,12 +186,12 @@ var customForm = {
} }
$.each(results, function() { $.each(results, function() {
if ($.inArray(this.uri, customForm.acFilter) == -1) { if ($.inArray(this.uri, customForm.acFilter) == -1) {
console.log("adding " + this.label + " to filtered results"); // console.log("adding " + this.label + " to filtered results");
filteredResults.push(this); filteredResults.push(this);
} }
else { // else {
console.log("filtering out " + this.label); // console.log("filtering out " + this.label);
} // }
}); });
return filteredResults; return filteredResults;
}, },
@ -205,7 +203,7 @@ var customForm = {
this.acUrl = this.baseAcUrl + glue + 'type=' + typeVal; this.acUrl = this.baseAcUrl + glue + 'type=' + typeVal;
// Flush autocomplete cache when type is reset, since the cached values // Flush autocomplete cache when type is reset, since the cached values
// are relevant only to the previous type. // pertain only to the previous type.
this.acCache = {}; this.acCache = {};
}, },
@ -220,7 +218,7 @@ var customForm = {
this.acReceiver.val(ui.item.uri); this.acReceiver.val(ui.item.uri);
this.acSelectionInfo.html(ui.item.label); this.acSelectionInfo.html(ui.item.label);
this.button.val('Add Publication'); this.button.val('Add ' + this.baseButtonText);
if( this.formSteps > 1){ if( this.formSteps > 1){
this.cancel.unbind('click'); this.cancel.unbind('click');