2012-05-16 21:13:33 +00:00
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
var pageManagementUtils = {
2012-05-29 21:40:09 +00:00
dataGetterLabelToURI : null , //initialized by custom data
2012-06-13 19:37:04 +00:00
dataGetterURIToLabel : null , //initialized from custom data
2012-05-29 21:40:09 +00:00
processDataGetterUtils : processDataGetterUtils , //an external class that should exist before this one
2012-05-31 21:44:39 +00:00
dataGetterMap : null ,
2012-06-13 19:37:04 +00:00
menuAction : null ,
2012-05-16 21:13:33 +00:00
// on initial page setup
onLoad : function ( ) {
if ( this . disableFormInUnsupportedBrowsers ( ) ) {
return ;
}
this . mixIn ( ) ;
2012-06-13 19:37:04 +00:00
this . initReverseURIToLabel ( ) ;
this . initDataGetterProcessors ( ) ;
2012-05-16 21:13:33 +00:00
this . initObjects ( ) ;
this . bindEventListeners ( ) ;
this . initDisplay ( ) ;
2012-06-13 19:37:04 +00:00
//if edit, then generate existing content
2012-06-19 21:12:49 +00:00
if ( this . isEdit ( ) ) {
2012-06-13 19:37:04 +00:00
this . initExistingContent ( ) ;
}
} ,
2012-06-19 21:12:49 +00:00
isEdit : function ( ) {
if ( pageManagementUtils . menuAction != null && pageManagementUtils . menuAction == "Edit" ) {
return true ;
}
return false ;
} ,
isAdd : function ( ) {
if ( pageManagementUtils . menuAction != null && pageManagementUtils . menuAction == "Add" ) {
return true ;
}
return false ;
} ,
2012-06-25 00:19:33 +00:00
isAddMenuItem : function ( ) {
if ( pageManagementUtils . addMenuItem != null && pageManagementUtils . addMenuItem == "true" ) {
return true ;
}
return false ;
} ,
2012-06-13 19:37:04 +00:00
initExistingContent : function ( ) {
this . generateExistingContentSections ( ) ;
2012-06-14 14:20:27 +00:00
//display more content button - will need to review how to hit save etc.
//Don't need to display this b/c already in appended section
//pageManagementUtils.moreContentButton.show();
//Need to have additional save button
2012-06-13 19:37:04 +00:00
} ,
initReverseURIToLabel : function ( ) {
if ( this . dataGetterLabelToURI != null ) {
this . dataGetterURIToLabel = { } ;
for ( var label in this . dataGetterLabelToURI ) {
if ( label != undefined ) {
var uri = this . dataGetterLabelToURI [ label ] ;
this . dataGetterURIToLabel [ uri ] = label ;
}
}
} else {
//Error condition.
}
} ,
2012-05-29 21:40:09 +00:00
initDataGetterProcessors : function ( ) {
//data getter processor map should come in from custom data
//Go through each and initialize with their class
if ( pageManagementUtils . processDataGetterUtils != null ) {
2012-05-31 21:44:39 +00:00
var dataGetterProcessorMap = pageManagementUtils . dataGetterProcessorMap = pageManagementUtils . processDataGetterUtils . dataGetterProcessorMap ;
2012-05-29 21:40:09 +00:00
$ . each ( dataGetterProcessorMap , function ( key , dataGetterProcessorObject ) {
//passes class name from data getter label to uri to processor
dataGetterProcessorObject . initProcessor ( pageManagementUtils . dataGetterLabelToURI [ key ] ) ;
} )
}
} ,
2012-05-16 21:13:33 +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 ( ) {
2012-05-29 21:40:09 +00:00
//Data getter process list input should be retrieved from the custom data
2012-05-16 21:13:33 +00:00
// Mix in the custom form utility methods
$ . extend ( this , vitro . customFormUtils ) ;
// Get the custom form data from the page
$ . extend ( this , customFormData ) ;
2013-06-11 12:25:01 -04:00
$ . extend ( this , i18nStrings ) ;
2012-05-16 21:13:33 +00:00
} ,
initObjects : function ( ) {
this . counter = 0 ;
2012-05-31 21:44:39 +00:00
this . contentTypeSelect = $ ( "select#typeSelect" ) ;
2012-05-16 21:13:33 +00:00
//list of options
this . contentTypeSelectOptions = $ ( 'select#typeSelect option' ) ;
2012-05-29 21:40:09 +00:00
this . classGroupSection = $ ( "section#browseClassGroup" ) ;
this . sparqlQuerySection = $ ( "section#sparqlQuery" ) ;
this . fixedHTMLSection = $ ( "section#fixedHtml" ) ;
2014-04-23 14:20:14 -04:00
this . searchIndividualsSection = $ ( "section#searchIndividuals" ) ;
2012-05-19 01:38:54 +00:00
//From original menu management edit
this . defaultTemplateRadio = $ ( 'input.default-template' ) ;
this . customTemplateRadio = $ ( 'input.custom-template' ) ;
2012-08-03 14:29:56 +00:00
this . selfContainedTemplateRadio = $ ( 'input.selfContained-template' ) ;
2012-05-19 01:38:54 +00:00
this . customTemplate = $ ( '#custom-template' ) ;
//In this version, these don't exist but we can consider this later
// this.changeContentType = $('#changeContentType');
2012-08-03 14:29:56 +00:00
// this.selectContentType = $('#selectContentType');
2012-05-19 01:38:54 +00:00
// this.existingContentType = $('#existingContentType');
2012-05-31 21:44:39 +00:00
this . selectClassGroupDropdown = $ ( 'select#selectClassGroup' ) ;
this . classesForClassGroup = $ ( 'section#classesInSelectedGroup' ) ;
2012-05-19 01:38:54 +00:00
this . selectedGroupForPage = $ ( '#selectedContentTypeValue' ) ;
this . allClassesSelectedCheckbox = $ ( '#allSelected' ) ;
2013-10-14 15:46:47 -04:00
2012-05-19 01:38:54 +00:00
this . displayInternalMessage = $ ( '#internal-class label em' ) ;
this . pageContentSubmissionInputs = $ ( "#pageContentSubmissionInputs" ) ;
2012-05-29 21:40:09 +00:00
this . headerBar = $ ( "section#headerBar" ) ;
2012-06-24 21:23:12 +00:00
this . doneButton = $ ( "input#doneWithContent" ) ;
2012-06-25 19:59:18 +00:00
this . cancelLink = $ ( "a#cancelContentLink" ) ;
2012-05-29 21:40:09 +00:00
this . isMenuCheckbox = $ ( "input#menuCheckbox" ) ;
2012-06-25 17:34:25 +00:00
this . menuLinkText = $ ( "input#menuLinkText" ) ;
2012-05-29 21:40:09 +00:00
this . menuSection = $ ( "section#menu" ) ;
2012-06-25 17:34:25 +00:00
this . pageNameInput = $ ( "input#pageName" ) ;
this . pageSaveButton = $ ( "input#pageSave" ) ;
2012-05-29 21:40:09 +00:00
this . leftSideDiv = $ ( "div#leftSide" ) ;
2012-06-22 17:56:02 +00:00
this . rightSideDiv = $ ( "div#rightSide" ) ;
//contentDivs container where content added/existing placed
this . savedContentDivs = $ ( "section#contentDivs" ) ;
2014-04-23 14:20:14 -04:00
//for search individuals data getter
this . searchAllClassesDropdown = $ ( "select#vclassUri" ) ;
2012-05-16 21:13:33 +00:00
} ,
initDisplay : function ( ) {
//right side components
this . contentTypeSelectOptions . eq ( 0 ) . attr ( 'selected' , 'selected' ) ;
$ ( 'select#selectClassGroup option' ) . eq ( 0 ) . attr ( 'selected' , 'selected' ) ;
//Why would you want to hide this? This hides everything
// $("section#pageDetails").hide();
2012-05-29 21:40:09 +00:00
this . headerBar . hide ( ) ;
2012-05-16 21:13:33 +00:00
this . classGroupSection . hide ( ) ;
2012-05-29 21:40:09 +00:00
this . sparqlQuerySection . hide ( ) ;
this . fixedHTMLSection . hide ( ) ;
2014-04-23 14:20:14 -04:00
this . searchIndividualsSection . hide ( ) ;
2012-05-29 21:40:09 +00:00
this . classesForClassGroup . addClass ( 'hidden' ) ;
2012-05-16 21:13:33 +00:00
//left side components
2012-06-19 21:12:49 +00:00
//These depend on whether or not this is an existing item or not
2012-06-25 17:34:25 +00:00
if ( this . isAdd ( ) ) {
2012-06-19 21:12:49 +00:00
this . defaultTemplateRadio . attr ( 'checked' , true ) ;
2012-06-25 17:34:25 +00:00
//disable save button
this . disablePageSave ( ) ;
if ( ! this . isAddMenuItem ( ) ) {
this . isMenuCheckbox . attr ( 'checked' , false ) ;
this . menuSection . hide ( ) ;
}
2012-06-19 21:12:49 +00:00
}
2014-04-23 14:20:14 -04:00
//populates the dropdown of classes for the search individuals template
2013-10-14 15:46:47 -04:00
//dropdown now populated in template/from form specific data instead of ajax request
2014-04-23 14:20:14 -04:00
//this.populateClassForSearchDropdown();
2013-10-14 15:46:47 -04:00
} ,
//this method can be utilized if using an ajax request to get the vclasses
/ *
2014-04-23 14:20:14 -04:00
//for search individuals - remember this populates the template class dropdown
populateClassForSearchDropdown : function ( ) {
2012-05-16 21:13:33 +00:00
2013-10-14 15:46:47 -04:00
//Run ajax query
var url = "dataservice?getAllVClasses=1" ;
//Make ajax call to retrieve vclasses
$ . getJSON ( url , function ( results ) {
//Moved the function to processClassGroupDataGetterContent
//Should probably remove this entire method and copy there
2014-04-23 14:20:14 -04:00
pageManagementUtils . displayAllClassesForSearchDropdown ( results ) ;
2013-10-14 15:46:47 -04:00
} ) ;
2012-05-16 21:13:33 +00:00
} ,
2014-04-23 14:20:14 -04:00
displayAllClassesForSearchDropdown : function ( results ) {
2013-10-14 15:46:47 -04:00
if ( results . classes . length == 0 ) {
} else {
var appendHtml = "" ;
$ . each ( results . classes , function ( i , item ) {
var thisClass = results . classes [ i ] ;
var thisClassName = thisClass . name ;
//Create options for the dropdown
appendHtml += "<option value='" + thisClass . URI + "'>" + thisClassName + "</option>" ;
} ) ;
//if there are options to add
if ( appendHtml != "" ) {
2014-04-23 14:20:14 -04:00
pageManagementUtils . searchAllClassesDropdown . html ( appendHtml ) ;
2013-10-14 15:46:47 -04:00
}
}
} , * /
2012-05-16 21:13:33 +00:00
bindEventListeners : function ( ) {
2012-05-29 21:40:09 +00:00
this . defaultTemplateRadio . click ( function ( ) {
2012-06-01 21:32:56 +00:00
pageManagementUtils . customTemplate . addClass ( 'hidden' ) ;
//Also clear custom template value so as not to submit it
pageManagementUtils . clearInputs ( pageManagementUtils . customTemplate ) ;
2012-08-03 14:29:56 +00:00
pageManagementUtils . rightSideDiv . show ( ) ;
2013-12-05 16:20:55 -05:00
//Check to see if there is already content on page, in which case save should be enabled
var pageContentSections = $ ( "section[class='pageContent']" ) ;
if ( pageContentSections . length == 0 ) {
pageManagementUtils . disablePageSave ( ) ;
}
2012-05-16 21:13:33 +00:00
} ) ;
2012-05-29 21:40:09 +00:00
this . customTemplateRadio . click ( function ( ) {
2013-12-05 16:20:55 -05:00
pageManagementUtils . handleSelectCustomTemplate ( ) ;
2012-05-16 21:13:33 +00:00
} ) ;
2012-08-03 14:29:56 +00:00
this . selfContainedTemplateRadio . click ( function ( ) {
pageManagementUtils . customTemplate . removeClass ( 'hidden' ) ;
pageManagementUtils . rightSideDiv . hide ( ) ;
pageManagementUtils . enablePageSave ( ) ;
} ) ;
2012-05-29 21:40:09 +00:00
this . isMenuCheckbox . click ( function ( ) {
if ( pageManagementUtils . menuSection . is ( ':hidden' ) ) {
pageManagementUtils . menuSection . show ( ) ;
2012-05-16 21:13:33 +00:00
}
else {
2012-05-29 21:40:09 +00:00
pageManagementUtils . menuSection . hide ( ) ;
2012-05-16 21:13:33 +00:00
}
} ) ;
//Collapses the current content and creates a new section of content
//Resets the content to be cloned to default settings
2012-06-24 21:23:12 +00:00
this . doneButton . click ( function ( ) {
2012-06-25 17:34:25 +00:00
pageManagementUtils . handleClickDone ( ) ;
2012-05-16 21:13:33 +00:00
} ) ;
2012-06-25 19:59:18 +00:00
this . cancelLink . click ( function ( ) {
pageManagementUtils . clearSourceTemplateValues ( ) ;
pageManagementUtils . headerBar . hide ( ) ;
pageManagementUtils . classGroupSection . hide ( ) ;
pageManagementUtils . fixedHTMLSection . hide ( ) ;
pageManagementUtils . sparqlQuerySection . hide ( ) ;
pageManagementUtils . contentTypeSelectOptions . eq ( 0 ) . attr ( 'selected' , 'selected' ) ;
pageManagementUtils . contentTypeSelect . focus ( ) ;
2012-08-03 14:29:56 +00:00
pageManagementUtils . adjustSaveButtonHeight ( ) ;
pageManagementUtils . checkSelfContainedRadio ( ) ;
2012-06-25 19:59:18 +00:00
} ) ;
2012-05-19 01:38:54 +00:00
//replacing with menu management edit version which is extended with some of the logic below
2013-10-14 15:46:47 -04:00
//This is technically content specific and should be moved into the individual processor classes somehow
2012-05-19 01:38:54 +00:00
this . selectClassGroupDropdown . change ( function ( ) {
pageManagementUtils . chooseClassGroup ( ) ;
} ) ;
2012-05-31 21:44:39 +00:00
2013-10-14 15:46:47 -04:00
2012-05-31 21:44:39 +00:00
this . contentTypeSelect . change ( function ( ) {
2012-06-22 17:56:02 +00:00
pageManagementUtils . handleContentTypeSelect ( ) ;
2012-05-16 21:13:33 +00:00
} ) ;
2012-05-19 01:38:54 +00:00
//Submission: validate as well as create appropriate hidden json inputs
2012-05-31 21:44:39 +00:00
$ ( "form" ) . submit ( function ( event ) {
2012-06-25 17:34:25 +00:00
pageManagementUtils . handleFormSubmission ( event ) ;
2012-05-19 01:38:54 +00:00
} ) ;
2012-05-16 21:13:33 +00:00
2012-05-31 21:44:39 +00:00
} ,
2013-12-05 16:20:55 -05:00
handleSelectCustomTemplate : function ( ) {
pageManagementUtils . customTemplate . removeClass ( 'hidden' ) ;
pageManagementUtils . rightSideDiv . show ( ) ;
//Check to see if there is already content on page, in which case save should be enabled
var pageContentSections = $ ( "section[class='pageContent']" ) ;
if ( pageContentSections . length == 0 ) {
pageManagementUtils . disablePageSave ( ) ;
}
} ,
2012-06-25 17:34:25 +00:00
handleClickDone : function ( ) {
var selectedType = pageManagementUtils . contentTypeSelect . val ( ) ;
var selectedTypeText = $ ( "#typeSelect option:selected" ) . text ( ) ;
//Hide all sections
pageManagementUtils . classGroupSection . hide ( ) ;
pageManagementUtils . fixedHTMLSection . hide ( ) ;
pageManagementUtils . sparqlQuerySection . hide ( ) ;
2014-04-23 14:20:14 -04:00
pageManagementUtils . searchIndividualsSection . hide ( ) ;
2012-06-25 17:34:25 +00:00
//Reset main content type drop-down
pageManagementUtils . contentTypeSelectOptions . eq ( 0 ) . attr ( 'selected' , 'selected' ) ;
if ( pageManagementUtils . leftSideDiv . css ( "height" ) != undefined ) {
pageManagementUtils . leftSideDiv . css ( "height" , "" ) ;
if ( pageManagementUtils . leftSideDiv . height ( ) < pageManagementUtils . rightSideDiv . height ( ) ) {
pageManagementUtils . leftSideDiv . css ( "height" , pageManagementUtils . rightSideDiv . height ( ) + "px" ) ;
}
}
pageManagementUtils . headerBar . hide ( ) ;
pageManagementUtils . headerBar . text ( "" ) ;
pageManagementUtils . cloneContentArea ( selectedType , selectedTypeText ) ;
//Reset class group section AFTER cloning not before
pageManagementUtils . resetClassGroupSection ( ) ;
//Clear all inputs values
pageManagementUtils . clearSourceTemplateValues ( ) ;
//If adding browse classgroup, need to remove the classgroup option from the dropdown
if ( selectedType == "browseClassGroup" ) {
pageManagementUtils . handleAddBrowseClassGroupPageContent ( ) ;
}
//Enable save button now that some content has been selected
pageManagementUtils . enablePageSave ( ) ;
pageManagementUtils . contentTypeSelect . focus ( ) ;
} ,
//Form submission
handleFormSubmission : function ( event ) {
var validationError = pageManagementUtils . validateMenuItemForm ( ) ;
2012-08-03 14:29:56 +00:00
//Add any errors from page content sections if necessary
// Only validate the content sections if the self contained template section is NOT selected tlw72
2012-08-03 15:24:58 +00:00
if ( ! pageManagementUtils . isSelfContainedTemplateChecked ( ) ) {
2012-08-03 14:29:56 +00:00
validationError += pageManagementUtils . validatePageContentSections ( ) ;
}
2012-06-25 17:34:25 +00:00
if ( validationError == "" ) {
//Check if menu label needs to be page title
pageManagementUtils . checkMenuTitleSubmission ( ) ;
2012-08-03 14:29:56 +00:00
//Create the appropriate json objects if necessary
2012-06-25 17:34:25 +00:00
pageManagementUtils . createPageContentForSubmission ( ) ;
2012-08-03 15:24:58 +00:00
//pageManagementUtils.mapCustomTemplateName();
pageManagementUtils . setUsesSelfContainedTemplateInput ( ) ;
2012-06-25 17:34:25 +00:00
return true ;
} else {
$ ( '#error-alert' ) . removeClass ( 'hidden' ) ;
$ ( '#error-alert p' ) . html ( validationError ) ;
event . preventDefault ( ) ;
return false ;
}
} ,
checkMenuTitleSubmission : function ( ) {
var isMenu = pageManagementUtils . isMenuCheckbox . is ( ":checked" ) ;
var linkText = pageManagementUtils . menuLinkText . val ( ) ;
if ( isMenu && linkText == "" ) {
//substitute with page title instead
var pageName = pageManagementUtils . pageNameInput . val ( ) ;
pageManagementUtils . menuLinkText . val ( pageName ) ;
}
2012-09-06 14:52:54 +00:00
if ( ! isMenu && linkText . length > 0 ) {
// if the isMenuCheckbox is unchecked, we need to clear the
// menuLinkText field; otherwise, the page remains a menu
pageManagementUtils . menuLinkText . val ( "" ) ;
}
2012-06-25 17:34:25 +00:00
} ,
2013-10-14 15:46:47 -04:00
//Select content type - this is content type specific
//TODO: Find better way to refactor this and/or see if any of this display functionality can be moved into content type processing
2012-06-22 17:56:02 +00:00
handleContentTypeSelect : function ( ) {
_this = pageManagementUtils ;
pageManagementUtils . clearSourceTemplateValues ( ) ;
if ( _this . contentTypeSelect . val ( ) == "browseClassGroup" ) {
pageManagementUtils . classGroupSection . show ( ) ;
pageManagementUtils . fixedHTMLSection . hide ( ) ;
pageManagementUtils . sparqlQuerySection . hide ( ) ;
2014-04-23 14:20:14 -04:00
pageManagementUtils . searchIndividualsSection . hide ( ) ;
2013-06-11 12:25:01 -04:00
pageManagementUtils . headerBar . text ( pageManagementUtils . browseClassGroup + " - " ) ;
2012-06-22 17:56:02 +00:00
pageManagementUtils . headerBar . show ( ) ;
2012-08-03 14:29:56 +00:00
$ ( 'div#selfContainedDiv' ) . hide ( ) ;
2012-06-22 17:56:02 +00:00
}
2014-04-23 14:20:14 -04:00
if ( _this . contentTypeSelect . val ( ) == "fixedHtml" || _this . contentTypeSelect . val ( ) == "sparqlQuery" || _this . contentTypeSelect . val ( ) == "searchIndividuals" ) {
2012-06-22 17:56:02 +00:00
pageManagementUtils . classGroupSection . hide ( ) ;
//if fixed html show that, otherwise show sparql results
if ( _this . contentTypeSelect . val ( ) == "fixedHtml" ) {
2013-06-11 12:25:01 -04:00
pageManagementUtils . headerBar . text ( pageManagementUtils . fixedHtml + " - " ) ;
2012-06-22 17:56:02 +00:00
pageManagementUtils . fixedHTMLSection . show ( ) ;
pageManagementUtils . sparqlQuerySection . hide ( ) ;
2014-04-23 14:20:14 -04:00
pageManagementUtils . searchIndividualsSection . hide ( ) ;
2012-06-22 17:56:02 +00:00
}
2013-10-14 15:46:47 -04:00
else if ( _this . contentTypeSelect . val ( ) == "sparqlQuery" ) {
2013-06-11 12:25:01 -04:00
pageManagementUtils . headerBar . text ( pageManagementUtils . sparqlResults + " - " ) ;
2012-06-22 17:56:02 +00:00
pageManagementUtils . sparqlQuerySection . show ( ) ;
pageManagementUtils . fixedHTMLSection . hide ( ) ;
2014-04-23 14:20:14 -04:00
pageManagementUtils . searchIndividualsSection . hide ( ) ;
2013-10-14 15:46:47 -04:00
} else {
2014-04-23 14:20:14 -04:00
//search individuals
pageManagementUtils . headerBar . text ( pageManagementUtils . searchIndividuals + " - " ) ;
2013-10-14 15:46:47 -04:00
pageManagementUtils . sparqlQuerySection . hide ( ) ;
pageManagementUtils . fixedHTMLSection . hide ( ) ;
2014-04-23 14:20:14 -04:00
pageManagementUtils . searchIndividualsSection . show ( ) ;
2012-06-22 17:56:02 +00:00
}
pageManagementUtils . headerBar . show ( ) ;
pageManagementUtils . classesForClassGroup . addClass ( 'hidden' ) ;
2012-08-03 14:29:56 +00:00
$ ( 'div#selfContainedDiv' ) . hide ( ) ;
2012-06-22 17:56:02 +00:00
}
if ( _this . contentTypeSelect . val ( ) == "" ) {
pageManagementUtils . classGroupSection . hide ( ) ;
pageManagementUtils . fixedHTMLSection . hide ( ) ;
pageManagementUtils . sparqlQuerySection . hide ( ) ;
2014-04-23 14:20:14 -04:00
pageManagementUtils . searchIndividualsSection . hide ( ) ;
2012-06-22 17:56:02 +00:00
pageManagementUtils . classesForClassGroup . addClass ( 'hidden' ) ;
pageManagementUtils . headerBar . hide ( ) ;
pageManagementUtils . headerBar . text ( "" ) ;
2012-08-03 14:29:56 +00:00
pageManagementUtils . checkSelfContainedRadio ( ) ;
2012-06-22 17:56:02 +00:00
}
//Collapse any divs for existing content if it exists
pageManagementUtils . collapseAllExistingContent ( ) ;
//adjust save button height
2012-06-25 17:34:25 +00:00
pageManagementUtils . adjustSaveButtonHeight ( ) ;
//Disable save button until the user has clicked done or cancel from the addition
pageManagementUtils . disablePageSave ( ) ;
2013-12-05 16:20:55 -05:00
//If the default template is selected, there is already content on the page, and the user is selecting new content
//display alert message that they must select a custom template and select
pageManagementUtils . checkTemplateForMultipleContent ( _this . contentTypeSelect . val ( ) ) ;
2012-06-25 17:34:25 +00:00
} ,
disablePageSave : function ( ) {
pageManagementUtils . pageSaveButton . attr ( "disabled" , "disabled" ) ;
pageManagementUtils . pageSaveButton . addClass ( "disabledSubmit" ) ;
} ,
enablePageSave : function ( ) {
pageManagementUtils . pageSaveButton . removeAttr ( "disabled" ) ;
pageManagementUtils . pageSaveButton . removeClass ( "disabledSubmit" ) ;
2012-06-22 17:56:02 +00:00
} ,
collapseAllExistingContent : function ( ) {
var spanArrows = pageManagementUtils . savedContentDivs . find ( "span.pageContentExpand div.arrow" ) ;
spanArrows . removeClass ( "collapseArrow" ) ;
spanArrows . addClass ( "expandArrow" ) ;
pageManagementUtils . savedContentDivs . find ( "div.pageContentContainer div.pageContentWrapper" ) . slideUp ( 222 ) ;
} ,
2012-05-31 21:44:39 +00:00
//Clear values in content areas that are cloned to create the page content type specific sections
//i.e. reset sparql query/class group areas
//TODO: Check if reset is more what we need here?
clearSourceTemplateValues : function ( ) {
//inputs, textareas
pageManagementUtils . clearInputs ( pageManagementUtils . fixedHTMLSection ) ;
pageManagementUtils . clearInputs ( pageManagementUtils . sparqlQuerySection ) ;
pageManagementUtils . clearInputs ( pageManagementUtils . classGroupSection ) ;
2014-04-23 14:20:14 -04:00
pageManagementUtils . clearInputs ( pageManagementUtils . searchIndividualsSection ) ;
2012-05-31 21:44:39 +00:00
} ,
clearInputs : function ( $el ) {
2012-06-24 21:23:12 +00:00
// jquery selector :input selects all input text area select and button elements
$el . find ( "input" ) . each ( function ( ) {
if ( $ ( this ) . attr ( 'id' ) != "doneWithContent" ) {
$ ( this ) . val ( "" ) ;
}
} ) ;
2012-05-31 21:44:39 +00:00
$el . find ( "textarea" ) . val ( "" ) ;
//resetting class group section as well so selection is reset if type changes
$el . find ( "select option:eq(0)" ) . attr ( "selected" , "selected" ) ;
2012-05-16 21:13:33 +00:00
} ,
2013-12-05 16:20:55 -05:00
checkTemplateForMultipleContent : function ( contentTypeSelected ) {
if ( contentTypeSelected != "" ) {
var pageContentSections = $ ( "section[class='pageContent']" ) ;
var selectedTemplateValue = $ ( 'input:radio[name=selectedTemplate]:checked' ) . val ( ) ;
//A new section hasn't been added yet so check to see if there is at least one content type already on page
if ( selectedTemplateValue == "default" && pageContentSections . length >= 1 ) {
//alert the user that they should be picking custom template instead
alert ( pageManagementUtils . multipleContentWithDefaultTemplateError ) ;
//pick custom template
$ ( 'input:radio[name=selectedTemplate][value="custom"]' ) . attr ( "checked" , true ) ;
pageManagementUtils . handleSelectCustomTemplate ( ) ;
}
}
} ,
2012-05-16 21:13:33 +00:00
//Clone content area
2012-06-25 17:34:25 +00:00
//When adding a new content type, this function will copy the values from the new content form and generate
//the content for the new section containing the content
2012-05-16 21:13:33 +00:00
cloneContentArea : function ( contentType , contentTypeLabel ) {
var ctr = pageManagementUtils . counter ;
var counter = pageManagementUtils . counter ;
2012-05-29 21:40:09 +00:00
var varOrClass ;
2012-05-16 21:13:33 +00:00
2012-05-29 21:40:09 +00:00
//Clone the object, renaming ids and copying text area values as well
$newContentObj = pageManagementUtils . createCloneObject ( contentType , counter ) ;
2012-06-25 19:59:18 +00:00
// Get rid of the cancel link; it'll be replaced by a delete link
$newContentObj . find ( 'span#cancelContent' + counter ) . html ( '' ) ;
2012-05-16 21:13:33 +00:00
2014-04-23 14:20:14 -04:00
if ( contentType == "sparqlQuery" || contentType == "fixedHtml" || contentType == "searchIndividuals" ) {
2012-06-04 21:36:04 +00:00
varOrClass = $newContentObj . find ( 'input[name="saveToVar"]' ) . val ( ) ;
}
2012-05-16 21:13:33 +00:00
else if ( contentType == "browseClassGroup" ) {
2012-05-29 21:40:09 +00:00
$newContentObj . find ( 'section#classesInSelectedGroup' + counter ) . removeClass ( 'hidden' ) ;
varOrClass = $newContentObj . find ( 'select#selectClassGroup' + counter + ' option:selected' ) . text ( ) ;
2012-05-16 21:13:33 +00:00
}
2012-06-13 19:37:04 +00:00
//For cases where varOrClass might be empty, pass an empty string
if ( varOrClass == null || varOrClass == undefined ) {
varOrClass = "" ;
}
2012-06-20 21:20:55 +00:00
//Attach event handlers if they exist
pageManagementUtils . bindClonedContentEventHandlers ( $newContentObj ) ;
2012-05-29 21:40:09 +00:00
pageManagementUtils . createClonedContentContainer ( $newContentObj , counter , contentTypeLabel , varOrClass ) ;
//previously increased by 10, just increasing by 1 here
2012-05-31 21:44:39 +00:00
pageManagementUtils . counter ++ ;
2012-05-29 21:40:09 +00:00
} ,
2012-06-25 17:34:25 +00:00
2012-06-20 21:20:55 +00:00
//For binding content type specific event handlers should they exist
bindClonedContentEventHandlers : function ( $newContentObj ) {
var dataGetterProcessorObj = pageManagementUtils . getDataGetterProcessorObject ( $newContentObj ) ;
if ( $ . isFunction ( dataGetterProcessorObj . bindEventHandlers ) ) {
dataGetterProcessorObj . bindEventHandlers ( $newContentObj ) ;
}
2012-06-25 00:19:33 +00:00
//Bind done event as the done button is within the cloned content
pageManagementUtils . bindClonedContentDoneEvent ( $newContentObj ) ;
2012-06-20 21:20:55 +00:00
} ,
2012-05-29 21:40:09 +00:00
createClonedContentContainer : function ( $newContentObj , counter , contentTypeLabel , varOrClass ) {
2012-05-16 21:13:33 +00:00
//Create the container for the new content
$newDivContainer = $ ( "<div></div>" , {
id : "divContainer" + counter ,
"class" : "pageContentContainer" ,
html : "<span class='pageContentTypeLabel'>" + contentTypeLabel + " - " + varOrClass
+ "</span><span id='clickable" + counter
2012-09-06 14:52:54 +00:00
+ "' class='pageContentExpand'><div id='woof' class='arrow expandArrow'></div></span><div id='innerContainer" + counter
2013-06-11 12:25:01 -04:00
+ "' class='pageContentWrapper'><span class='deleteLinkContainer'> " + pageManagementUtils . orString + " <a id='remove" + counter // changed button to a link
+ "' href='' >" + pageManagementUtils . deleteString + "</a></span></div>"
2012-05-16 21:13:33 +00:00
} ) ;
2012-05-29 21:40:09 +00:00
//Hide inner div
2012-05-16 21:13:33 +00:00
var $innerDiv = $newDivContainer . children ( 'div#innerContainer' + counter ) ;
$innerDiv . hide ( ) ;
2012-05-29 21:40:09 +00:00
//Bind event listers for the new content for display/removal etc.
pageManagementUtils . bindClonedContentContainerEvents ( $newDivContainer , counter ) ;
//Append the new container to the section storing these containers
$newDivContainer . appendTo ( $ ( 'section#contentDivs' ) ) ;
2012-06-24 21:23:12 +00:00
//place new content object
2012-05-29 21:40:09 +00:00
$newContentObj . prependTo ( $innerDiv ) ;
} ,
2012-06-25 00:19:33 +00:00
bindClonedContentDoneEvent : function ( $newContentObj ) {
//Done button should just collapse the cloned content
$newContentObj . find ( "input[name='doneWithContent']" ) . click ( function ( ) {
var thisInnerDiv = $ ( this ) . closest ( "div.pageContentWrapper" ) ;
2012-09-06 14:52:54 +00:00
var thisClickableSpan = thisInnerDiv . prev ( "span.pageContentExpand" ) ;
2012-06-25 00:19:33 +00:00
var thisArrowDiv = thisClickableSpan . find ( 'div.arrow' ) ;
2012-09-06 14:52:54 +00:00
thisInnerDiv . slideUp ( 222 ) ;
2012-06-25 00:19:33 +00:00
thisArrowDiv . removeClass ( "collapseArrow" ) ;
thisArrowDiv . addClass ( "expandArrow" ) ;
2012-09-06 14:52:54 +00:00
window . setTimeout ( 'pageManagementUtils.adjustSaveButtonHeight()' , 223 ) ;
2012-06-25 00:19:33 +00:00
} ) ;
} ,
2012-05-29 21:40:09 +00:00
bindClonedContentContainerEvents : function ( $newDivContainer , counter ) {
var $clickableSpan = $newDivContainer . children ( 'span#clickable' + counter ) ;
var $innerDiv = $newDivContainer . children ( 'div#innerContainer' + counter ) ;
//Expand/collapse toggle
2012-05-16 21:13:33 +00:00
$clickableSpan . click ( function ( ) {
if ( $innerDiv . is ( ':visible' ) ) {
$innerDiv . slideUp ( 222 ) ;
//$clickableSpan.find('img').attr("src","arrow-down.gif");
var arrowDiv = $clickableSpan . find ( 'div.arrow' ) ;
arrowDiv . removeClass ( "collapseArrow" ) ;
arrowDiv . addClass ( "expandArrow" ) ;
}
else {
$innerDiv . slideDown ( 222 ) ;
//$clickableSpan.find('img').attr("src","arrow-up.gif");
var arrowDiv = $clickableSpan . find ( 'div.arrow' ) ;
arrowDiv . removeClass ( "expandArrow" ) ;
arrowDiv . addClass ( "collapseArrow" ) ;
}
window . setTimeout ( 'pageManagementUtils.adjustSaveButtonHeight()' , 223 ) ;
} ) ;
2012-06-25 00:19:33 +00:00
2012-05-29 21:40:09 +00:00
//remove button
2012-08-03 14:29:56 +00:00
$newRemoveLink = $innerDiv . find ( 'a#remove' + counter ) ;
2012-06-22 17:56:02 +00:00
//remove the content entirely
2012-06-25 00:19:33 +00:00
$newRemoveLink . click ( function ( event ) {
2012-06-22 17:56:02 +00:00
//if content type of what is being deleted is browse class group, then
//add browse classgroup back to set of options
var contentType = $innerDiv . find ( "section.pageContent" ) . attr ( "contentType" ) ;
if ( pageManagementUtils . processDataGetterUtils . isRelatedToBrowseClassGroup ( contentType ) ) {
pageManagementUtils . handleRemoveBrowseClassGroupPageContent ( ) ;
}
//remove the section
2012-06-18 21:15:22 +00:00
$innerDiv . parent ( "div" ) . remove ( ) ;
2012-05-16 21:13:33 +00:00
pageManagementUtils . adjustSaveButtonHeight ( ) ;
2012-08-03 14:29:56 +00:00
pageManagementUtils . checkSelfContainedRadio ( ) ;
2012-06-25 00:19:33 +00:00
//Because this is now a link, have to prevent default action of navigating to link
event . preventDefault ( ) ;
2012-05-16 21:13:33 +00:00
} ) ;
} ,
2012-06-25 17:34:25 +00:00
//clones and returns cloned object for content type
createCloneObject : function ( contentType , counter ) {
var originalObjectPath = 'section#' + contentType ;
var $newContentObj = $ ( originalObjectPath ) . clone ( ) ;
2012-08-03 14:29:56 +00:00
$newContentObj . removeClass ( "contentSectionContainer" ) ;
2012-06-25 17:34:25 +00:00
$newContentObj . addClass ( "pageContent" ) ;
$newContentObj . attr ( "contentNumber" , counter ) ;
//Save content type
$newContentObj . attr ( "contentType" , contentType ) ;
//Set id for object
$newContentObj . attr ( "id" , contentType + counter ) ;
$newContentObj . show ( ) ;
pageManagementUtils . renameIdsInClone ( $newContentObj , counter ) ;
// pageManagementUtils.cloneTextAreaValues(originalObjectPath, $newContentObj);
return $newContentObj ;
} ,
//This is specifically for cloning text area values
//May not need this if implementing the jquery fix
///would need a similar function for select as well
cloneTextAreaValues : function ( originalAncestorPath , $newAncestorObject ) {
$ ( originalAncestorPath + " textarea" ) . each ( function ( index , el ) {
var originalTextAreaValue = $ ( this ) . val ( ) ;
var originalTextAreaName = $ ( this ) . attr ( "name" ) ;
$newAncestorObject . find ( "textarea[name='" + originalTextAreaName + "']" ) . val ( originalTextAreaValue ) ;
} ) ;
} ,
//given an object and a counter, rename all the ids
renameIdsInClone : function ( $newContentObj , counter ) {
$newContentObj . find ( "[id]" ) . each ( function ( index , el ) {
var originalId = $ ( this ) . attr ( "id" ) ;
var newId = originalId + counter ;
$ ( this ) . attr ( "id" , newId ) ;
} ) ;
} ,
/**Existing Content**/
//For edit, need to have text passed in
//Returns new content object itself
cloneContentAreaForEdit : function ( contentType , contentTypeLabel , labelText ) {
var counter = pageManagementUtils . counter ;
//Clone the object, renaming ids and copying text area values as well
$newContentObj = pageManagementUtils . createCloneObject ( contentType , counter ) ;
//Attach done event
//Bind done event as the done button is within the cloned content
pageManagementUtils . bindClonedContentDoneEvent ( $newContentObj ) ;
//create cloned content container
pageManagementUtils . createClonedContentContainer ( $newContentObj , counter , contentTypeLabel , labelText ) ;
//previously increased by 10, just increasing by 1 here
pageManagementUtils . counter ++ ;
return $newContentObj ;
} ,
//To actually generate the content for existing values
generateExistingContentSections : function ( ) {
if ( pageManagementUtils . menuAction == "Edit" ) {
var $existingContent = $ ( "#existingPageContentUnits" ) ;
//create json object from string version json2.
if ( $existingContent . length > 0 ) {
var jsonObjectString = $existingContent . val ( ) ;
//this returns an array
var JSONContentObjectArray = JSON . parse ( jsonObjectString ) ;
var len = JSONContentObjectArray . length ;
var i ;
for ( i = 0 ; i < len ; i ++ ) {
//Get the type of data getter and create the appropriate section/populate
var JSONContentObject = JSONContentObjectArray [ i ] ;
var dataGetterClass = JSONContentObject [ "dataGetterClass" ] ;
if ( dataGetterClass != null ) {
//Get the Label for the URI
var contentType = pageManagementUtils . dataGetterURIToLabel [ dataGetterClass ] ;
var contentTypeForCloning = pageManagementUtils . processDataGetterUtils . getContentTypeForCloning ( contentType ) ;
//Get the processor class for this type
var dataGetterProcessorObject = pageManagementUtils . processDataGetterUtils . dataGetterProcessorMap [ contentType ] ;
var contentTypeLabel = dataGetterProcessorObject . retrieveContentLabel ( ) ;
var additionalLabelText = dataGetterProcessorObject . retrieveAdditionalLabelText ( JSONContentObject ) ;
//Clone the appropriate section for the label
var $newContentObj = pageManagementUtils . cloneContentAreaForEdit ( contentTypeForCloning , contentTypeLabel , additionalLabelText ) ;
//Populate the section with the values
dataGetterProcessorObject . populatePageContentSection ( JSONContentObject , $newContentObj ) ;
//Also include a hidden input with data getter URI
pageManagementUtils . includeDataGetterURI ( JSONContentObject , $newContentObj ) ;
//If content type is browseClassGroup or other 'related types' that are derived from it
if ( pageManagementUtils . processDataGetterUtils . isRelatedToBrowseClassGroup ( contentType ) ) {
pageManagementUtils . handleAddBrowseClassGroupPageContent ( ) ;
}
} else {
//error condition
}
}
}
}
} ,
//What's the label of the content type from the drop down
getContentTypeLabelFromSelect : function ( contentType ) {
var text = pageManagementUtils . contentTypeSelect . find ( "option[value='" + contentType + "']" ) . text ( ) ;
if ( text == null ) {
text = "" ;
}
return text ;
} ,
includeDataGetterURI : function ( JSONContentObject , $newContentObj ) {
var uri = JSONContentObject [ "URI" ] ;
if ( uri != null ) {
$ ( "<input type='hidden' name='URI' value='" + uri + "'>" ) . appendTo ( $newContentObj ) ;
}
2012-05-16 21:13:33 +00:00
} ,
2012-06-25 17:34:25 +00:00
2012-05-16 21:13:33 +00:00
//Adjust save button height
adjustSaveButtonHeight : function ( ) {
if ( $ ( "div#leftSide" ) . css ( "height" ) != undefined ) {
$ ( "div#leftSide" ) . css ( "height" , "" ) ;
if ( $ ( "div#leftSide" ) . height ( ) < $ ( "div#rightSide" ) . height ( ) ) {
$ ( "div#leftSide" ) . css ( "height" , $ ( "div#rightSide" ) . height ( ) + "px" ) ;
}
}
2012-05-19 01:38:54 +00:00
} ,
2012-06-25 17:34:25 +00:00
/***Class group selection***/
2012-05-19 01:38:54 +00:00
//Copied from menu management edit javascript
2012-06-25 17:34:25 +00:00
//Class group
resetClassGroupSection : function ( ) {
//doing this in clear inputs instead which will be triggered
//every time content type is changed AS well as on more content button after
//original content is cloned and stored
//$('select#selectClassGroup option').eq(0).attr('selected', 'selected');
pageManagementUtils . classesForClassGroup . addClass ( 'hidden' ) ;
} ,
2012-05-19 01:38:54 +00:00
chooseClassGroup : function ( ) {
var url = "dataservice?getVClassesForVClassGroup=1&classgroupUri=" ;
var vclassUri = this . selectClassGroupDropdown . val ( ) ;
url += encodeURIComponent ( vclassUri ) ;
//Make ajax call to retrieve vclasses
$ . getJSON ( url , function ( results ) {
2012-06-18 21:15:22 +00:00
//Moved the function to processClassGroupDataGetterContent
//Should probably remove this entire method and copy there
2012-06-20 21:20:55 +00:00
pageManagementUtils . displayClassesForClassGroup ( results ) ;
2012-06-18 21:15:22 +00:00
} ) ;
} ,
displayClassesForClassGroup : function ( results ) {
if ( results . classes . length == 0 ) {
} else {
//update existing content type with correct class group name and hide class group select again
// pageManagementUtils.hideClassGroups();
pageManagementUtils . selectedGroupForPage . html ( results . classGroupName ) ;
//update content type in message to "display x within my institution"
//SPECIFIC TO VIVO: So include in internal CLASS section instead
pageManagementUtils . updateInternalClassMessage ( results . classGroupName ) ;
//retrieve classes for class group and display with all selected
var selectedClassesList = pageManagementUtils . classesForClassGroup . children ( 'ul#selectedClasses' ) ;
selectedClassesList . empty ( ) ;
2013-06-11 12:25:01 -04:00
selectedClassesList . append ( '<li class="ui-state-default"> <input type="checkbox" name="allSelected" id="allSelected" value="all" checked="checked" /> <label class="inline" for="All"> ' + pageManagementUtils . allCapitalized + '</label> </li>' ) ;
2012-06-18 21:15:22 +00:00
$ . each ( results . classes , function ( i , item ) {
var thisClass = results . classes [ i ] ;
var thisClassName = thisClass . name ;
//For the class group, ALL classes should be selected
appendHtml = ' <li class="ui-state-default">' +
'<input type="checkbox" checked="checked" name="classInClassGroup" value="' + thisClass . URI + '" />' +
'<label class="inline" for="' + thisClassName + '"> ' + thisClassName + '</label>' +
'</li>' ;
selectedClassesList . append ( appendHtml ) ;
} ) ;
pageManagementUtils . toggleClassSelection ( ) ;
//From NEW code
if ( pageManagementUtils . selectClassGroupDropdown . val ( ) == "" ) {
pageManagementUtils . classesForClassGroup . addClass ( 'hidden' ) ;
$ ( "div#leftSide" ) . css ( "height" , "" ) ;
2012-05-19 01:38:54 +00:00
}
else {
2012-05-31 21:44:39 +00:00
pageManagementUtils . classesForClassGroup . removeClass ( 'hidden' ) ;
2012-05-19 01:38:54 +00:00
if ( $ ( "div#leftSide" ) . height ( ) < $ ( "div#rightSide" ) . height ( ) ) {
$ ( "div#leftSide" ) . css ( "height" , $ ( "div#rightSide" ) . height ( ) + "px" ) ;
}
}
2012-06-18 21:15:22 +00:00
}
2012-05-19 01:38:54 +00:00
} ,
toggleClassSelection : function ( ) {
// Check/unckeck all classes for selection
$ ( 'input:checkbox[name=allSelected]' ) . click ( function ( ) {
if ( this . checked ) {
2012-06-01 21:32:56 +00:00
// if checked, select all the checkboxes for this particular section
$ ( this ) . closest ( "ul" ) . find ( 'input:checkbox[name=classInClassGroup]' ) . attr ( 'checked' , 'checked' ) ;
//$('input:checkbox[name=classInClassGroup]').attr('checked','checked');
2012-05-19 01:38:54 +00:00
} else {
// if not checked, deselect all the checkboxes
2012-06-01 21:32:56 +00:00
$ ( this ) . closest ( "ul" ) . find ( 'input:checkbox[name=classInClassGroup]' ) . removeAttr ( 'checked' ) ;
// $('input:checkbox[name=classInClassGroup]').removeAttr('checked');
2012-05-19 01:38:54 +00:00
}
} ) ;
$ ( 'input:checkbox[name=classInClassGroup]' ) . click ( function ( ) {
2012-06-20 21:20:55 +00:00
$ ( this ) . closest ( "ul" ) . find ( 'input:checkbox[name=allSelected]' ) . removeAttr ( 'checked' ) ;
2012-05-19 01:38:54 +00:00
} ) ;
} , //This is SPECIFIC to VIVO so should be moved there
updateInternalClassMessage : function ( classGroupName ) { //User has changed content type
//Set content type within internal class message
this . displayInternalMessage . filter ( ":first" ) . html ( classGroupName ) ;
} ,
2012-06-25 17:34:25 +00:00
/**On submission**/
//On submission, generates the content for the input that will return the serialized JSON objects representing
//each of the content types
2012-05-19 01:38:54 +00:00
createPageContentForSubmission : function ( ) {
//Iterate through the page content and create the appropriate json object and save
var pageContentSections = $ ( "section[class='pageContent']" ) ;
$ . each ( pageContentSections , function ( i ) {
var id = $ ( this ) . attr ( "id" ) ;
var jo = pageManagementUtils . processPageContentSection ( $ ( this ) ) ;
var jsonObjectString = JSON . stringify ( jo ) ;
//Create a new hidden input with a specific name and assign value per page content
pageManagementUtils . createPageContentInputForSubmission ( jsonObjectString ) ;
} ) ;
2012-08-03 15:24:58 +00:00
//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 ( "" ) ;
}
2012-05-19 01:38:54 +00:00
} ,
createPageContentInputForSubmission : function ( inputValue ) {
2012-08-03 15:24:58 +00:00
//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 ) ;
2012-05-19 01:38:54 +00:00
} ,
2012-05-29 21:40:09 +00:00
//returns a json object with the data getter information required
2012-05-19 01:38:54 +00:00
processPageContentSection : function ( pageContentSection ) {
2012-05-29 21:40:09 +00:00
//This processing should be specific to the type and so that content type's specific processor will
//return the json object required
if ( pageManagementUtils . processDataGetterUtils != null ) {
var dataGetterType = pageManagementUtils . processDataGetterUtils . selectDataGetterType ( pageContentSection ) ;
2012-05-31 21:44:39 +00:00
if ( pageManagementUtils . dataGetterProcessorMap != null ) {
var dataGetterProcessor = pageManagementUtils . dataGetterProcessorMap [ dataGetterType ] ;
//the content type specific processor will create the json object to be returned
var jsonObject = dataGetterProcessor . processPageContentSection ( pageContentSection ) ;
2012-06-21 20:44:42 +00:00
//if data getter uri included, include that as well
if ( pageContentSection . find ( "input[name='URI']" ) . length > 0 ) {
var uriValue = pageContentSection . find ( "input[name='URI']" ) . val ( ) ;
jsonObject [ "URI" ] = uriValue ;
}
2012-05-31 21:44:39 +00:00
return jsonObject ;
2012-05-29 21:40:09 +00:00
} else {
//ERROR handling
2013-06-11 12:25:01 -04:00
alert ( pageManagementUtils . mapProcessorError ) ;
2012-05-29 21:40:09 +00:00
return null ;
}
}
2013-06-11 12:25:01 -04:00
alert ( pageManagementUtils . codeProcessingError ) ;
2012-05-29 21:40:09 +00:00
//Error handling here
return null ;
} ,
2012-06-25 17:34:25 +00:00
2012-06-20 21:20:55 +00:00
//Get the data getter processor
getDataGetterProcessorObject : function ( pageContentSection ) {
var dataGetterType = pageManagementUtils . processDataGetterUtils . selectDataGetterType ( pageContentSection ) ;
var dataGetterProcessor = null ;
if ( pageManagementUtils . dataGetterProcessorMap != null ) {
dataGetterProcessor = pageManagementUtils . dataGetterProcessorMap [ dataGetterType ] ;
}
return dataGetterProcessor ;
2012-06-22 17:56:02 +00:00
} ,
handleAddBrowseClassGroupPageContent : function ( ) {
//if browse class group content has been added, then remove browse classgroup option from dropdown
if ( pageManagementUtils . contentTypeSelect . find ( "option[value='browseClassGroup']" ) . length > 0 ) {
pageManagementUtils . contentTypeSelect . find ( "option[value='browseClassGroup']" ) . remove ( ) ;
}
} ,
handleRemoveBrowseClassGroupPageContent : function ( ) {
if ( pageManagementUtils . contentTypeSelect . find ( "option[value='browseClassGroup']" ) . length == 0 ) {
//if removed, add browse class group back
var classGroupOption = '<option value="browseClassGroup">Browse Class Group</option>' ;
2012-06-24 01:39:58 +00:00
pageManagementUtils . contentTypeSelect . find ( 'option:eq(0)' ) . after ( classGroupOption ) ;
}
} ,
//get label of page content section
getPageContentSectionLabel : function ( pageContentSection ) {
var label = pageContentSection . closest ( "div.pageContentContainer" ) . find ( "span.pageContentTypeLabel" ) . html ( ) ;
if ( label == null ) {
label = "" ;
2012-06-22 17:56:02 +00:00
}
2012-06-24 01:39:58 +00:00
return label ;
} ,
2012-06-25 17:34:25 +00:00
/***Validation***/
validateMenuItemForm : function ( ) {
var validationError = "" ;
// Check menu name
if ( $ ( 'input[type=text][name=pageName]' ) . val ( ) == "" ) {
2013-06-11 12:25:01 -04:00
validationError += pageManagementUtils . supplyName + "<br />" ;
2012-06-25 17:34:25 +00:00
}
// Check pretty url
if ( $ ( 'input[type=text][name=prettyUrl]' ) . val ( ) == "" ) {
2013-06-11 12:25:01 -04:00
validationError += pageManagementUtils . supplyPrettyUrl + "<br />" ;
2012-06-25 17:34:25 +00:00
}
if ( $ ( 'input[type=text][name=prettyUrl]' ) . val ( ) . charAt ( 0 ) != "/" ) {
2013-06-11 12:25:01 -04:00
validationError += pageManagementUtils . startUrlWithSlash + "<br />" ;
2012-06-25 17:34:25 +00:00
}
2012-08-03 15:24:58 +00:00
// Check custom template and self contained template
var selectedTemplateValue = $ ( 'input:radio[name=selectedTemplate]:checked' ) . val ( ) ;
if ( selectedTemplateValue == "custom" || selectedTemplateValue == "selfContained" ) {
2012-06-25 17:34:25 +00:00
if ( $ ( 'input[name=customTemplate]' ) . val ( ) == "" ) {
2013-06-11 12:25:01 -04:00
validationError += pageManagementUtils . supplyTemplate + "<br />" ;
2012-06-25 17:34:25 +00:00
}
}
return validationError ;
} ,
2012-06-24 01:39:58 +00:00
//Validation across different content types
validatePageContentSections : function ( ) {
//Get all page content sections
var pageContentSections = $ ( "section[class='pageContent']" ) ;
var validationErrorMsg = "" ;
2012-06-25 17:34:25 +00:00
//If there ARE not contents selected, then error message should indicate user needs to add them
if ( pageContentSections . length == 0 ) {
2013-06-11 12:25:01 -04:00
validationErrorMsg = pageManagementUtils . selectContentType + " <br /> " ;
2012-06-25 17:34:25 +00:00
} else {
2013-12-05 16:20:55 -05:00
//If there are multiple content types, and the default template option is selected, then display error message
2013-12-09 11:03:58 -05:00
if ( pageContentSections . length > 1 ) {
var selectedTemplateValue = $ ( 'input:radio[name=selectedTemplate]:checked' ) . val ( ) ;
if ( selectedTemplateValue == "default" ) {
validationErrorMsg += pageManagementUtils . multipleContentWithDefaultTemplateError + "<br/>" ;
}
2013-12-05 16:20:55 -05:00
}
//For each, based on type, validate if a validation function exists
2012-06-25 17:34:25 +00:00
$ . each ( pageContentSections , function ( i ) {
if ( pageManagementUtils . processDataGetterUtils != null ) {
var dataGetterType = pageManagementUtils . processDataGetterUtils . selectDataGetterType ( $ ( this ) ) ;
if ( pageManagementUtils . dataGetterProcessorMap != null ) {
var dataGetterProcessor = pageManagementUtils . dataGetterProcessorMap [ dataGetterType ] ;
//the content type specific processor will create the json object to be returned
if ( $ . isFunction ( dataGetterProcessor . validateFormSubmission ) ) {
//Get label of page content section
var label = pageManagementUtils . getPageContentSectionLabel ( $ ( this ) ) ;
validationErrorMsg += dataGetterProcessor . validateFormSubmission ( $ ( this ) , label ) ;
}
}
}
} ) ;
}
2012-06-24 01:39:58 +00:00
return validationErrorMsg ;
2012-08-03 14:29:56 +00:00
} ,
//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 ( ) {
2012-08-03 15:24:58 +00:00
if ( pageManagementUtils . selfContainedTemplateRadio . is ( ':checked' ) ) {
2012-08-03 14:29:56 +00:00
$ ( "input[name='selfContainedTemplate']" ) . val ( $ ( "input[name='customTemplate']" ) . val ( ) ) ;
}
} ,
2012-08-03 15:24:58 +00:00
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" ) ) ;
}
} ,
2012-08-03 14:29:56 +00:00
//If any content is defined, keep the selContained radio button hidden
checkSelfContainedRadio : function ( ) {
if ( pageManagementUtils . savedContentDivs . html ( ) . length == 0 ) {
$ ( 'div#selfContainedDiv' ) . show ( ) ;
}
2012-08-03 15:24:58 +00:00
} ,
isSelfContainedTemplateChecked : function ( ) {
return pageManagementUtils . selfContainedTemplateRadio . is ( ':checked' ) ;
2012-05-16 21:13:33 +00:00
}
2012-06-24 21:23:12 +00:00
}
2012-05-16 21:13:33 +00:00
$ ( document ) . ready ( function ( ) {
pageManagementUtils . onLoad ( ) ;
2012-05-17 22:03:36 +00:00
} ) ;