<commit_before>if(!jsBackend) { var jsBackend = new Object(); }

jsBackend.pages = {
	init: function() {
		// load the tree
		jsBackend.pages.tree.init();

		// are we adding or editing?
		if(typeof templates != 'undefined') {
			// load stuff for the page
			jsBackend.pages.template.init();
			jsBackend.pages.extras.init();

			// manage templates
			jsBackend.pages.manageTemplates.init();
		}
		
		// do meta
		if($('#title').length > 0) $('#title').doMeta();
	},
	
	// end
	eoo: true
}

// all methods related to the controls (buttons, ...)
jsBackend.pages.extras = {
	init: function() {
		// bind events
		$('#extraType').change(jsBackend.pages.extras.populateExtraModules);
		$('#extraModule').change(jsBackend.pages.extras.populateExtraIds);
	
		// bind buttons
		$('a.chooseExtra').live('click', jsBackend.pages.extras.showExtraDialog);
		
		// load initial data, or initialize the dialogs
		jsBackend.pages.extras.load();
	},
	
	// load initial data, or initialize the dialogs
	load: function() {
		// initialize the modal for choosing an extra
		if($('#chooseExtra').length > 0) {
			$('#chooseExtra').dialog({ autoOpen: false, draggable: false, resizable: false, modal: true, 
				buttons: { '{$lblOK|ucfirst}': function() {
											// change the extra for real
											jsBackend.pages.extras.changeExtra();
							
											// close dialog
											$(this).dialog('close');
										},
							'{$lblCancel|ucfirst}': function() {
												// empty the extraForBlock
												$('#extraForBlock').val('');
														
												// close the dialog
												$(this).dialog('close'); 
											}
							}
			 });
		}

		if($('#chooseTemplate').length > 0) {
			$('#chooseTemplate').dialog({ autoOpen: false, draggable: false, resizable: false, modal: true, width: 500,
				buttons: { '{$lblOK|ucfirst}': function() {
													// change the template for real
													jsBackend.pages.template.changeTemplate();
				
													// close dialog
													$(this).dialog('close');
												},
						   '{$lblCancel|ucfirst}': function() {
														// close the dialog
														$(this).dialog('close'); 
													}
						 }
			 });
		}
	},
	
	// change the extra for a block
	showExtraDialog: function(evt) {
		// prevent the default action
		evt.preventDefault();
		
		// get the block wherefor we will change the extra
		var blockId = $(this).attr('rel');

		// get selected extra id
		var selectedExtraId = $('#block_extra_id_'+ blockId).val();
		
		// populate the hidden field, so we know for which block we are changing
		$('#extraForBlock').val(blockId);

		// init var
		var hasModules = false;
		
		// check if there already blocks linked
		$('.linkedExtra input:hidden').each(function() {
			var id = $(this).val();
			if(id != '' && extrasById[id].type == 'block') hasModules = true;
		});

		// blocks linked?
		if(hasModules) {
			// show warning
			$('#extraWarningAlreadyBlock').show();
			
			// disable blocks
			$('#extraType option[value="block"]').attr('disabled', 'disabled');
		}
		
		// hide warning
		else $('#extraWarningAlreadyBlock').hide();
		
		// any extra selected before? And if so, does the extra still exists?
		if(typeof extrasById[selectedExtraId] != 'undefined') {
			// set type
			$('#extraType').val(extrasById[selectedExtraId].type);
			
			// populate the modules
			jsBackend.pages.extras.populateExtraModules();
			
			// set module
			$('#extraModule').val(extrasById[selectedExtraId].module);
			
			// populate the ids
			jsBackend.pages.extras.populateExtraIds();
			<commit_msg>Extra validation<commit_after>if(!jsBackend) { var jsBackend = new Object(); }

jsBackend.pages = {
	init: function() {
		// load the tree
		jsBackend.pages.tree.init();

		// are we adding or editing?
		if(typeof templates != 'undefined') {
			// load stuff for the page
			jsBackend.pages.template.init();
			jsBackend.pages.extras.init();

			// manage templates
			jsBackend.pages.manageTemplates.init();
		}
		
		// do meta
		if($('#title').length > 0) $('#title').doMeta();
	},
	
	// end
	eoo: true
}

// all methods related to the controls (buttons, ...)
jsBackend.pages.extras = {
	init: function() {
		// bind events
		$('#extraType').change(jsBackend.pages.extras.populateExtraModules);
		$('#extraModule').change(jsBackend.pages.extras.populateExtraIds);
	
		// bind buttons
		$('a.chooseExtra').live('click', jsBackend.pages.extras.showExtraDialog);
		
		// load initial data, or initialize the dialogs
		jsBackend.pages.extras.load();
	},
	
	// load initial data, or initialize the dialogs
	load: function() {
		// initialize the modal for choosing an extra
		if($('#chooseExtra').length > 0) {
			$('#chooseExtra').dialog({ autoOpen: false, draggable: false, resizable: false, modal: true, 
				buttons: { '{$lblOK|ucfirst}': function() {
											// change the extra for real
											jsBackend.pages.extras.changeExtra();
							
											// close dialog
											$(this).dialog('close');
										},
							'{$lblCancel|ucfirst}': function() {
												// empty the extraForBlock
												$('#extraForBlock').val('');
														
												// close the dialog
												$(this).dialog('close'); 
											}
							}
			 });
		}

		if($('#chooseTemplate').length > 0) {
			$('#chooseTemplate').dialog({ autoOpen: false, draggable: false, resizable: false, modal: true, width: 500,
				buttons: { '{$lblOK|ucfirst}': function() {
													// change the template for real
													jsBackend.pages.template.changeTemplate();
				
													// close dialog
													$(this).dialog('close');
												},
						   '{$lblCancel|ucfirst}': function() {
														// close the dialog
														$(this).dialog('close'); 
													}
						 }
			 });
		}
	},
	
	// change the extra for a block
	showExtraDialog: function(evt) {
		// prevent the default action
		evt.preventDefault();
		
		// get the block wherefor we will change the extra
		var blockId = $(this).attr('rel');

		// get selected extra id
		var selectedExtraId = $('#block_extra_id_'+ blockId).val();
		
		// populate the hidden field, so we know for which block we are changing
		$('#extraForBlock').val(blockId);

		// init var
		var hasModules = false;
		
		// check if there already blocks linked
		$('.linkedExtra input:hidden').each(function() {
			var id = $(this).val();
			if(id != '' && typeof extrasById[id] != 'undefined' && extrasById[id].type == 'block') hasModules = true;
		});

		// blocks linked?
		if(hasModules) {
			// show warning
			$('#extraWarningAlreadyBlock').show();
			
			// disable blocks
			$('#extraType option[value="block"]').attr('disabled', 'disabled');
		}
		
		// hide warning
		else $('#extraWarningAlreadyBlock').hide();
		
		// any extra selected before? And if so, does the extra still exists?
		if(typeof extrasById[selectedExtraId] != 'undefined') {
			// set type
			$('#extraType').val(extrasById[selectedExtraId].type);
			
			// populate the modules
			jsBackend.pages.extras.populateExtraModules();
			
			// set module
			$('#extraModule').val(extrasById[selectedExtraId].module);
			
			// populate the ids
			jsBackend.pages.extras.populateExtraIds();
			
{'fraction_non_alphanumeric': 0.16008863038360338, 'fraction_numerical': 0.0016618196925633569, 'mean_word_length': 2.6309703368526898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5927275', 'n_tokens_mistral': 2868, 'n_tokens_neox': 2159, 'n_words': 516}