updates for handling single and double quotes as well as enabling self contained template option for page management
This commit is contained in:
parent
6a63de6144
commit
8225bcf91f
7 changed files with 97 additions and 20 deletions
|
@ -91,6 +91,9 @@ owl:versionInfo
|
|||
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#requiresBodyTemplate>
|
||||
a owl:DatatypeProperty .
|
||||
|
||||
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#isSelfContainedTemplate>
|
||||
a owl:DatatypeProperty .
|
||||
|
||||
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#menuPosition>
|
||||
a owl:DatatypeProperty ;
|
||||
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#displayLimitAnnot>
|
||||
|
|
|
@ -256,7 +256,7 @@ var pageManagementUtils = {
|
|||
var validationError = pageManagementUtils.validateMenuItemForm();
|
||||
//Add any errors from page content sections if necessary
|
||||
// Only validate the content sections if the self contained template section is NOT selected tlw72
|
||||
if ( !pageManagementUtils.selfContainedTemplate.is(':checked') ) {
|
||||
if ( !pageManagementUtils.isSelfContainedTemplateChecked() ) {
|
||||
validationError += pageManagementUtils.validatePageContentSections();
|
||||
}
|
||||
if (validationError == "") {
|
||||
|
@ -264,7 +264,8 @@ var pageManagementUtils = {
|
|||
pageManagementUtils.checkMenuTitleSubmission();
|
||||
//Create the appropriate json objects if necessary
|
||||
pageManagementUtils.createPageContentForSubmission();
|
||||
pageManagementUtils.mapCustomTemplateName();
|
||||
//pageManagementUtils.mapCustomTemplateName();
|
||||
pageManagementUtils.setUsesSelfContainedTemplateInput();
|
||||
return true;
|
||||
} else{
|
||||
$('#error-alert').removeClass('hidden');
|
||||
|
@ -698,10 +699,22 @@ var pageManagementUtils = {
|
|||
//Create a new hidden input with a specific name and assign value per page content
|
||||
pageManagementUtils.createPageContentInputForSubmission(jsonObjectString);
|
||||
});
|
||||
|
||||
//For the case where the template only selection is picked, there will be
|
||||
//no page contents, but the hidden input still needs to be created as it is expected
|
||||
//to exist by the edit configuration, this creates the hidden input with an empty value
|
||||
if (pageManagementUtils.isSelfContainedTemplateChecked() ) {
|
||||
//An empty string as no content selected
|
||||
pageManagementUtils.createPageContentInputForSubmission("");
|
||||
}
|
||||
},
|
||||
createPageContentInputForSubmission: function(inputValue) {
|
||||
$("<input type='hidden' name='pageContentUnit' value='" + inputValue + "'>").appendTo(pageManagementUtils.pageContentSubmissionInputs);
|
||||
//Previously, this code created the hidden input and included the value inline
|
||||
//but this was converting html encoding for quotes/single quotes into actual quotes
|
||||
//which prevented correct processing as the html thought the string had ended
|
||||
//Creating the input and then using the val() method preserved the encoding
|
||||
var pageContentUnit = $("<input type='hidden' name='pageContentUnit'>");
|
||||
pageContentUnit.val(inputValue);
|
||||
pageContentUnit.appendTo(pageManagementUtils.pageContentSubmissionInputs);
|
||||
},
|
||||
//returns a json object with the data getter information required
|
||||
processPageContentSection:function(pageContentSection) {
|
||||
|
@ -776,8 +789,9 @@ var pageManagementUtils = {
|
|||
validationError += "The pretty URL must begin with a leading forward slash<br />";
|
||||
}
|
||||
|
||||
// Check custom template
|
||||
if ($('input:radio[name=selectedTemplate]:checked').val() == "custom") {
|
||||
// Check custom template and self contained template
|
||||
var selectedTemplateValue = $('input:radio[name=selectedTemplate]:checked').val();
|
||||
if (selectedTemplateValue == "custom" || selectedTemplateValue == "selfContained") {
|
||||
if ($('input[name=customTemplate]').val() == "") {
|
||||
validationError += "You must supply a template<br />";
|
||||
}
|
||||
|
@ -817,17 +831,27 @@ var pageManagementUtils = {
|
|||
//If the selfContained-template radio is checked, copy the custom template name to the hidden
|
||||
//selfContainedTemplate input element. We need that for edit mode to select the correct radio button.
|
||||
mapCustomTemplateName:function() {
|
||||
if ( this.selfContainedTemplateRadio.is(':checked') ) {
|
||||
if ( pageManagementUtils.selfContainedTemplateRadio.is(':checked') ) {
|
||||
$("input[name='selfContainedTemplate']").val($("input[name='customTemplate']").val());
|
||||
}
|
||||
},
|
||||
|
||||
setUsesSelfContainedTemplateInput:function() {
|
||||
//On form submission attach hidden input to form if the custom template selection is picked
|
||||
if ( pageManagementUtils.isSelfContainedTemplateChecked() ) {
|
||||
$("<input name='isSelfContainedTemplate' value='true'>").appendTo($("form"));
|
||||
}
|
||||
},
|
||||
|
||||
//If any content is defined, keep the selContained radio button hidden
|
||||
checkSelfContainedRadio:function() {
|
||||
if ( pageManagementUtils.savedContentDivs.html().length == 0 ) {
|
||||
$('div#selfContainedDiv').show();
|
||||
}
|
||||
|
||||
},
|
||||
isSelfContainedTemplateChecked:function() {
|
||||
return pageManagementUtils.selfContainedTemplateRadio.is(':checked');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,10 @@ var processFixedHTMLDataGetterContent = {
|
|||
processPageContentSection:function(pageContentSection) {
|
||||
var saveToVarValue = pageContentSection.find("input[name='saveToVar']").val();
|
||||
var htmlValue = pageContentSection.find("textarea[name='htmlValue']").val();
|
||||
//query model should also be an input
|
||||
//JSON parsing on the server side does not handle single quotes, as it appears it thinks the string has
|
||||
//ended. Different data getter types may handle apostrophes/single quotes differently
|
||||
//In this case, this is HTML so it simply html Encodes any apostrophes
|
||||
htmlValue = processFixedHTMLDataGetterContent.replaceSingleQuote(htmlValue);
|
||||
var returnObject = {saveToVar:saveToVarValue, htmlValue:htmlValue, dataGetterClass:this.dataGetterClass};
|
||||
return returnObject;
|
||||
},
|
||||
|
@ -38,13 +41,30 @@ var processFixedHTMLDataGetterContent = {
|
|||
//Check that query and saveToVar have been input
|
||||
var variableValue = pageContentSection.find("input[name='saveToVar']").val();
|
||||
if(variableValue == "") {
|
||||
validationError += pageContentSectionLabel + ": You must supply a variable to save HTML content. <br />"
|
||||
validationError += pageContentSectionLabel + ": You must supply a variable to save HTML content. <br />";
|
||||
}
|
||||
if(processFixedHTMLDataGetterContent.stringHasSingleQuote(variableValue)) {
|
||||
validationError += pageContentSectionLabel + ": The variable name should not have an apostrophe . <br />";
|
||||
}
|
||||
if(processFixedHTMLDataGetterContent.stringHasDoubleQuote(variableValue)) {
|
||||
validationError += pageContentSectionLabel + ": The variable name should not have a double quote . <br />";
|
||||
}
|
||||
var htmlValue = pageContentSection.find("textarea[name='htmlValue']").val();
|
||||
if(htmlValue == "") {
|
||||
validationError += pageContentSectionLabel + ": You must supply some HTML or text. <br />";
|
||||
}
|
||||
return validationError;
|
||||
},
|
||||
replaceSingleQuote:function(inputStr) {
|
||||
return inputStr.replace(/'/g, ''').replace(/"/g, '"');
|
||||
},
|
||||
//For the variable name, no single quote should be allowed
|
||||
//This can be extended for other special characters
|
||||
stringHasSingleQuote:function(inputStr) {
|
||||
return(inputStr.indexOf("'") != -1);
|
||||
},
|
||||
stringHasDoubleQuote:function(inputStr) {
|
||||
return(inputStr.indexOf("\"") != -1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<#assign menuItem = lvf.getFormFieldValue(editSubmission, editConfiguration, "menuItem")/>
|
||||
<#assign menuLinkText = lvf.getFormFieldValue(editSubmission, editConfiguration, "menuLinkText")/>
|
||||
<#assign customTemplate = lvf.getFormFieldValue(editSubmission, editConfiguration, "customTemplate")/>
|
||||
<#assign selfContainedTemplate = lvf.getFormFieldValue(editSubmission, editConfiguration, "selfContainedTemplate")/>
|
||||
<#assign selfContainedTemplate = lvf.getFormFieldValue(editSubmission, editConfiguration, "isSelfContainedTemplate")/>
|
||||
<#assign pageHeading = "Edit Page" />
|
||||
<#if customTemplate?has_content>
|
||||
<#if selfContainedTemplate?has_content>
|
||||
|
@ -67,7 +67,7 @@
|
|||
<h2>${pageHeading}</h2>
|
||||
<!--Drop down for the types of content possible-->
|
||||
<section id="floatRight">
|
||||
<div id="rightSide">
|
||||
<div id="rightSide" <#if selectedTemplateType="selfContained">style="display:none;"</#if>>
|
||||
<section id="addPageOne" role="region" >
|
||||
<label for="contentType">Content Type<span class="requiredHint"> *</span></label>
|
||||
<select id="typeSelect" name="typeSelect" >
|
||||
|
@ -104,7 +104,7 @@
|
|||
<br /><div id="selfContainedDiv">
|
||||
<input type="radio" name="selectedTemplate" class="selfContained-template" value="selfContained" <#if selectedTemplateType = "selfContained">checked="checked"</#if> role="input" />
|
||||
<label class="inline" for="selfContained"> Custom template containing all content</label></div>
|
||||
<section id="custom-template" <#if selectedTemplateType != 'custom'>class="hidden" </#if>role="region">
|
||||
<section id="custom-template" <#if selectedTemplateType ="default">class="hidden" </#if>role="region">
|
||||
<input type="text" name="customTemplate" value="${customTemplate!''}" size="33" role="input" /><span class="requiredHint"> *</span>
|
||||
<input type="hidden" name="selfContainedTemplate" value="${selfContainedTemplate!''}"/>
|
||||
</section>
|
||||
|
@ -140,7 +140,9 @@
|
|||
<!--For existing content, will have div to save existing content-->
|
||||
<div id="existingPageContent" style="display:none">
|
||||
<#if pageData.existingPageContentUnits?has_content>
|
||||
<input type='hidden' id='existingPageContentUnits' value='${pageData.existingPageContentUnits}'/>
|
||||
<!--Using the ?html ensures that single and double quotes are html encoded - double quotes
|
||||
if left unencoded will break the html and lead to errors-->
|
||||
<input type='hidden' id='existingPageContentUnits' value='${pageData.existingPageContentUnits?html}'/>
|
||||
</#if>
|
||||
</div>
|
||||
</form>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue