<commit_before>/* Class: mop.cms.CMS */
mop.modules.CMS = new Class({
	/* Constructor: initialize */
	Extends: mop.modules.Module,
	pageLoadCount: 0,
	objectId: null,
	pageContent: null,
	pageIdToLoad: null,
	scriptsLoaded: null,
	scriptsTotal: null,
	currentPageLoadIndex: null,
	titleText: "",
	titleElement: null,
	editSlugLink: null,
	deletePageLink: null,

	initialize: function( anElement, options ){
//        console.log( "CMS INIT", this.childModules );
		this.parent( anElement, null, options );		
		this.objectId = this.getValueFromClassName( "objectId" );
	},
	
	build: function(){
		this.pageContent = $("nodeContent");
		this.initModules( this.element );
	},
	
	toString: function(){
		return "[ object, mop.modules.CMS ]";
	},

	loadPage: function ( pageId ){
//		console.log( this.toString(), "loadPage", pageId );
		this.pageIdToLoad = pageId;
		this.clearPage();
		this.pageContent.spin();
		var url = mop.util.getAppURL() + "cms/ajax/getPage/" + pageId;
		mop.util.JSONSend( url, null, { onSuccess: this.onPageLoaded.bind( this ) } );
 		mop.util.setObjectId( pageId );
	},
	
	clearPage: function(){
	    console.log( "clearPage" );
		this.destroyChildModules( this.pageContent );
		this.destroyUIElements();
		this.pageContent.empty();
	},

	/*
		Function: onPageLoaded
		Callback to getPage, loops through supplied JSON object and attached css, html, js, in that order then looks through #pageContent and initialize modules therein....
		Arguments:
			pageJSON - Object : { css: [ "pathToCSSFile", "pathToCSSFile", ... ], js: [ "pathToJSFile", "pathToJSFile", "pathToJSFile", ... ], html: "String" }
	*/
	onPageLoaded: function( pageJSON ){

		var pageData = new Hash( pageJSON );
		pageData.css.each( function( element, index ){ mop.util.loadStyleSheet( element ); });

		$("nodeContent").unspin();

		var scripts = pageData.js;
		this.scriptsLoaded = 0;
		this.scriptsTotal = scripts.length;
		this.currentPageLoadIndex = this.pageLoadCount++;

		if( this.scriptsTotal && this.scriptsTotal > 0 ){
			scripts.each( function( urlString ){
				mop.util.loadJS( urlString, { type: "text/javascript", onload: this.onJSLoaded.bind( this, [ pageData.html, this.currentPageLoadIndex ] ) } );
			}, this);			
		}else{
			this.populate( pageData.html );
		}

	},
	
	onJSLoaded: function( pageHTML, pageLoadCount ){
		// keeps any callbacks from previous pageloads from registering
		if( pageLoadCount != this.currentPageLoadIndex ) return;
		
		this.scriptsLoaded++;
		
		if( this.scriptsLoaded == this.scriptsTotal ){
			
			this.scriptsTotal = null;
			this.populate( pageHTML );

		}
	},
	
	
	populate: function( html ){
		
		this.pageContent.set( 'html', html );

		this.uiElements = this.initUI( this.pageContent );
		this.initModules( this.pageContent );		

		this.titleElement = this.element.getElement( ".pageTitle" );
		
        
		if( this.titleElement ){

			this.titleText = this.titleElement.getElement( "h2" ).get( "text" );
			this.deletePageLink = this.titleElement.getElement( "a.deleteLink" );

    		this.editSlugLink = this.titleElement.getElement( ".field-slug" );
			if( this.editSlugLink ){
				this.editSlugLink.addEvent( "click", this.revealSlugEditField.bindWithEvent( this ) );
				this.titleElement.getElement( ".field-slug" ).retrieve( "Class" ).registerOnLeaveEditModeCallback( this.onSlugEdit.bind( this ) );
			}
			
			this.titleElement.getElement( ".field-title" ).retrieve( "Class").registerOnCompleteCallBack( this.renameNode.bind( this ) );

			if( this.deletePageLink ) this.deletePageLink.addEvent( "click", this.onDeleteNodeReleased.bindWithEvent( this ) );
			
		
		}
		

	},
	
	onSlugEdit: function(){
		this.titleElement.getElement( ".field-slug .ipe" ).addClass("hidden");
	},
	<commit_msg>modules : cms : #288<commit_after>/* Class: mop.cms.CMS */
mop.modules.CMS = new Class({
	/* Constructor: initialize */
	Extends: mop.modules.Module,
	pageLoadCount: 0,
	objectId: null,
	pageContent: null,
	pageIdToLoad: null,
	scriptsLoaded: null,
	scriptsTotal: null,
	currentPageLoadIndex: null,
	titleText: "",
	titleElement: null,
	editSlugLink: null,
	deletePageLink: null,

	initialize: function( anElement, options ){
//        console.log( "CMS INIT", this.childModules );
		this.parent( anElement, null, options );		
		this.objectId = this.getValueFromClassName( "objectId" );
	},
	
	build: function(){
		this.pageContent = $("nodeContent");
		this.initModules( this.element );
	},
	
	toString: function(){
		return "[ object, mop.modules.CMS ]";
	},

	loadPage: function ( pageId ){
//		console.log( this.toString(), "loadPage", pageId );
		this.pageIdToLoad = pageId;
		this.clearPage();
		this.pageContent.spin();
		var url = mop.util.getAppURL() + "cms/ajax/getPage/" + pageId;
		mop.util.JSONSend( url, null, { onSuccess: this.onPageLoaded.bind( this ) } );
 		mop.util.setObjectId( pageId );
	},
	
	clearPage: function(){
	    console.log( "clearPage" );
		this.destroyChildModules( this.pageContent );
		this.destroyUIElements();
		this.pageContent.empty();
	},

	/*
		Function: onPageLoaded
		Callback to getPage, loops through supplied JSON object and attached css, html, js, in that order then looks through #pageContent and initialize modules therein....
		Arguments:
			pageJSON - Object : { css: [ "pathToCSSFile", "pathToCSSFile", ... ], js: [ "pathToJSFile", "pathToJSFile", "pathToJSFile", ... ], html: "String" }
	*/
	onPageLoaded: function( pageJSON ){

		var pageData = new Hash( pageJSON );
		pageData.css.each( function( element, index ){ mop.util.loadStyleSheet( element ); });

		$("nodeContent").unspin();

		var scripts = pageData.js;
		this.scriptsLoaded = 0;
		this.scriptsTotal = scripts.length;
		this.currentPageLoadIndex = this.pageLoadCount++;

		if( this.scriptsTotal && this.scriptsTotal > 0 ){
			scripts.each( function( urlString ){
				mop.util.loadJS( urlString, { type: "text/javascript", onload: this.onJSLoaded.bind( this, [ pageData.html, this.currentPageLoadIndex ] ) } );
			}, this);			
		}else{
			this.populate( pageData.html );
		}

	},
	
	onJSLoaded: function( pageHTML, pageLoadCount ){
		// keeps any callbacks from previous pageloads from registering
		if( pageLoadCount != this.currentPageLoadIndex ) return;
		
		this.scriptsLoaded++;
		
		if( this.scriptsLoaded == this.scriptsTotal ){
			
			this.scriptsTotal = null;
			this.populate( pageHTML );

		}
	},
	
	
	populate: function( html ){
		
		this.pageContent.set( 'html', html );

		this.uiElements = this.initUI( this.pageContent );
		this.initModules( this.pageContent );		

		this.titleElement = this.element.getElement( ".pageTitle" );
		
        
		if( this.titleElement ){

			this.titleText = this.titleElement.getElement( "h2" ).get( "text" );
			this.deletePageLink = this.titleElement.getElement( "a.deleteLink" );

    		this.editSlugLink = this.titleElement.getElement( ".field-slug" );
			if( this.editSlugLink ){
				this.editSlugLink.addEvent( "click", this.revealSlugEditField.bindWithEvent( this ) );
				this.titleElement.getElement( ".field-slug" ).retrieve( "Class" ).registerOnLeaveEditModeCallback( this.onSlugEdit.bind( this ) );
			}
			
			if( this.titleElement.getElement( ".field-title" ).retrieve("Class") ) this.titleElement.getElement( ".field-title" ).retrieve( "Class").registerOnCompleteCallBack( this.renameNode.bind( this ) );

			if( this.deletePageLink ) this.deletePageLink.addEvent( "click", this.onDeleteNodeReleased.bindWithEvent( this ) );
			
		
		}
		

	},
	
	onSlugEdit: function(){
		this.titleElement.getElement( ".field-slug .ipe" ).addClass("hidden");
	},
	
{'fraction_non_alphanumeric': 0.14923402007395667, 'fraction_numerical': 0.0014527205493924987, 'mean_word_length': 3.901618122977346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5368175', 'n_tokens_mistral': 2719, 'n_tokens_neox': 2458, 'n_words': 512}