<commit_before>/**
 * @properties={typeid:35,uuid:"D30001EE-2E04-408B-87BA-0DE1CFC32E23",variableType:4}
 */
var _refresh = null;

/**
 * @properties={typeid:35,uuid:"04fde543-69cc-4de9-af47-7f7c22221f66"}
 */
var _license_dsa_mosaic_WEB_cms = 'Module: _dsa_mosaic_WEB_cms \
									Copyright (C) 2011 Data Mosaic \
									MIT Licensed';

/**
 *
 * @properties={typeid:24,uuid:"F33F8765-2F83-4103-8FF0-D067E37DC3FD"}
 */
function ACTIONS_list() {
	
	//custom page methods
		//MEMO: the relations below are sorted alphabetically so actions will be sorted that way too
	var pageActions = new Array()
	
	//a site is selected
	if (utils.hasRecords(forms.WEB_0F_site.foundset)) {
		//this site has blocks
		if (utils.hasRecords(forms.WEB_0F_site.web_site_to_block_type)) {
			for (var i = 1; i <= forms.WEB_0F_site.web_site_to_block_type.getSize(); i++) {
				var blockType = forms.WEB_0F_site.web_site_to_block_type.getRecord(i)
				
				//this block has client actions
				if (utils.hasRecords(blockType.web_block_type_to_block_action_client)) {
					for (var j = 1; j <= blockType.web_block_type_to_block_action_client.getSize(); j++) {
						var clientAction = blockType.web_block_type_to_block_action_client.getRecord(j)
						
						//only work with page actions
						if (clientAction.action_type == 'Page') {
							//create popup with action attached
							if (globals.CODE_servoy_object_exists(clientAction.method_name,blockType.form_name)) {
								pageActions.push(plugins.popupmenu.createMenuItem(((blockType.block_name) ? blockType.block_name.toUpperCase() : 'BLOCK') + ': ' + clientAction.input_name, forms[blockType.form_name][clientAction.method_name]))
							}
							//create popup without action attached and disable it
							else {
								pageActions.push(plugins.popupmenu.createMenuItem(((blockType.block_name) ? blockType.block_name.toUpperCase() : 'BLOCK') + ': ' + clientAction.input_name, ACTIONS_list_control))
								pageActions[pageActions.length - 1].setEnabled(false)
							}
						}
					}
				}
			}
		}
	}
	
		
	//get menu list from a value list
	var valueList = [
			'Duplicate record',
			'Update theme...',
			'Reset theme...',
			'-',
			'Toggle open',
			'Toggle closed',
			'-',
			'Delete record',
			'-',
			'Delete all unnamed pages'
		]
	
	//build menu
	var menu = new Array
	for ( var i = 0 ; i < valueList.length ; i++ ) {
		menu[i] = plugins.popupmenu.createMenuItem(valueList[i] + "", ACTIONS_list_control)
	}
	
	//set menu method arguments
	var x = 0
	while (menu[x]) {
		//pass arguments
		menu[x].setMethodArguments(x)
		
		//disable dividers
		if (valueList[x] == '-' || valueList[x] == '----' ||
			(x == 0 && !globals.TRIGGER_registered_action_authenticate('cms page duplicate')) ||
			((x == 5 || x == 7) && !globals.TRIGGER_registered_action_authenticate('cms page delete')) ) {
			menu[x].setEnabled(false)
		}
		
		x++
	}
	
	//tack on custom page methods
	if (pageActions.length) {
		//divider
		menu.push(plugins.popupmenu.createMenuItem("-", ACTIONS_list_control))
		menu[menu.length - 1].setEnabled(false)
		
		//submenu with page actions
		menu.push(plugins.popupmenu.createMenuItem("Page actions", pageActions))
	}
	
	//pop up the popup menu
	var elem = elements[application.getMethodTriggerElementName()]
	if (elem != null) {
	    plugins.popupmenu.showPopupMenu(elem, menu)
	}

}

/**
 *
 * @properties={typeid:24,uuid:"C271B727-FA9C-49A1-BBFC-C1EABE4BEB36"}
 */
function ACTIONS_list_control() {
	
	switch (arguments[0]) {
		case 0: //duplicate record
			REC_duplicate()
			break
	
		case 1: //update theme
			forms.WEB_0F_page__design__content_1L_area.AREA_add_missing()
			break
		
		case 2: //reset theme
			forms.WEB_0F_page__design__content_1L_area.AREA_reset()
			break
			
		case 4: //toggle open
			TOGGLE_nodes(1)
			break
		
		case 5: //toggle closed
			TOGGLE_nodes(0)
			break
		
		case 7:	//delete record
			REC_delete()
			break	
		
		case 9: //delete all unnamed
			var fsPages = forms.WEB_0F_site.web_site_to_page
			
			var input = plugins.dialogs.showQuestionDialog(
						'Delete record?',
						'Do you want to delete all unnamed records from this site?',
						'Yes',
						'No'
				)
			
			if (input == 'Yes') {
				var flagDidSomething
				
				for (var i = 1; i <= fsPages.getSize(); i++) {
					var record = fsPages.getRecord(i)
					
					if (!record.page_name) {
						REC_delete(record)
						i--
						flagDidSomething = true
					}
				}
				
				//reload tree view
				if (flagDidSomething) {
					TREE_refresh()
				}
			}
			break
	}
}

/**
 *
 * @properties={typeid:24,uuid:"F7A1A519-2335-4471-8CDF-3BA8F7822C93"}
 */
function FIND_path(input) {
	
	/*
	 *	TITLE    :	FIND_path
	 *			  	<commit_msg>add action to cms page wheel to hard flush the cache (will affect headless client)<commit_after>/**
 * @properties={typeid:35,uuid:"D30001EE-2E04-408B-87BA-0DE1CFC32E23",variableType:4}
 */
var _refresh = null;

/**
 * @properties={typeid:35,uuid:"04fde543-69cc-4de9-af47-7f7c22221f66"}
 */
var _license_dsa_mosaic_WEB_cms = 'Module: _dsa_mosaic_WEB_cms \
									Copyright (C) 2011 Data Mosaic \
									MIT Licensed';

/**
 *
 * @properties={typeid:24,uuid:"F33F8765-2F83-4103-8FF0-D067E37DC3FD"}
 */
function ACTIONS_list() {
	
	//custom page methods
		//MEMO: the relations below are sorted alphabetically so actions will be sorted that way too
	var pageActions = new Array()
	
	//a site is selected
	if (utils.hasRecords(forms.WEB_0F_site.foundset)) {
		//this site has blocks
		if (utils.hasRecords(forms.WEB_0F_site.web_site_to_block_type)) {
			for (var i = 1; i <= forms.WEB_0F_site.web_site_to_block_type.getSize(); i++) {
				var blockType = forms.WEB_0F_site.web_site_to_block_type.getRecord(i)
				
				//this block has client actions
				if (utils.hasRecords(blockType.web_block_type_to_block_action_client)) {
					for (var j = 1; j <= blockType.web_block_type_to_block_action_client.getSize(); j++) {
						var clientAction = blockType.web_block_type_to_block_action_client.getRecord(j)
						
						//only work with page actions
						if (clientAction.action_type == 'Page') {
							//create popup with action attached
							if (globals.CODE_servoy_object_exists(clientAction.method_name,blockType.form_name)) {
								pageActions.push(plugins.popupmenu.createMenuItem(((blockType.block_name) ? blockType.block_name.toUpperCase() : 'BLOCK') + ': ' + clientAction.input_name, forms[blockType.form_name][clientAction.method_name]))
							}
							//create popup without action attached and disable it
							else {
								pageActions.push(plugins.popupmenu.createMenuItem(((blockType.block_name) ? blockType.block_name.toUpperCase() : 'BLOCK') + ': ' + clientAction.input_name, ACTIONS_list_control))
								pageActions[pageActions.length - 1].setEnabled(false)
							}
						}
					}
				}
			}
		}
	}
	
		
	//get menu list from a value list
	var valueList = [
			'Duplicate record',
			'Update theme...',
			'Reset theme...',
			'-',
			'Toggle open',
			'Toggle closed',
			'-',
			'Delete record',
			'-',
			'Delete all unnamed pages',
			'-',
			'Flush client cache'
		]
	
	//build menu
	var menu = new Array
	for ( var i = 0 ; i < valueList.length ; i++ ) {
		menu[i] = plugins.popupmenu.createMenuItem(valueList[i] + "", ACTIONS_list_control)
	}
	
	//set menu method arguments
	var x = 0
	while (menu[x]) {
		//pass arguments
		menu[x].setMethodArguments(x)
		
		//disable dividers
		if (valueList[x] == '-' || valueList[x] == '----' ||
			(x == 0 && !globals.TRIGGER_registered_action_authenticate('cms page duplicate')) ||
			((x == 5 || x == 7) && !globals.TRIGGER_registered_action_authenticate('cms page delete')) ) {
			menu[x].setEnabled(false)
		}
		
		x++
	}
	
	//tack on custom page methods
	if (pageActions.length) {
		//divider
		menu.push(plugins.popupmenu.createMenuItem("-", ACTIONS_list_control))
		menu[menu.length - 1].setEnabled(false)
		
		//submenu with page actions
		menu.push(plugins.popupmenu.createMenuItem("Page actions", pageActions))
	}
	
	//pop up the popup menu
	var elem = elements[application.getMethodTriggerElementName()]
	if (elem != null) {
	    plugins.popupmenu.showPopupMenu(elem, menu)
	}

}

/**
 *
 * @properties={typeid:24,uuid:"C271B727-FA9C-49A1-BBFC-C1EABE4BEB36"}
 */
function ACTIONS_list_control() {
	
	switch (arguments[0]) {
		case 0: //duplicate record
			REC_duplicate()
			break
	
		case 1: //update theme
			forms.WEB_0F_page__design__content_1L_area.AREA_add_missing()
			break
		
		case 2: //reset theme
			forms.WEB_0F_page__design__content_1L_area.AREA_reset()
			break
			
		case 4: //toggle open
			TOGGLE_nodes(1)
			break
		
		case 5: //toggle closed
			TOGGLE_nodes(0)
			break
		
		case 7:	//delete record
			REC_delete()
			break	
		
		case 9: //delete all unnamed
			var fsPages = forms.WEB_0F_site.web_site_to_page
			
			var input = plugins.dialogs.showQuestionDialog(
						'Delete record?',
						'Do you want to delete all unnamed records from this site?',
						'Yes',
						'No'
				)
			
			if (input == 'Yes') {
				var flagDidSomething
				
				for (var i = 1; i <= fsPages.getSize(); i++) {
					var record = fsPages.getRecord(i)
					
					if (!record.page_name) {
						REC_delete(record)
						i--
						flagDidSomething = true
					}
				}
				
				//reload tree view
				if (flagDidSomething) {
					TREE_refresh()
				}
			}
			break
			
		case 11: //flush client cache
			//TODO: a progressbar indicator...better yet, spawn a headless client on the server
			globals.CODE_cursor_busy(true)
			var tables = databaseManager.getTableNames('sutra_cms')
			for (var i = 0; i < tables.length; i++) {
				plugins.rawSQL.flushAllClientsCache('sutra_cms', tables[i])
			}
			globals.CODE_cursor_busy(false)
			break
			
	}
}

/**
 *
 * @properties={typeid:24,uuid:"F7A1A519-2335-4471-8CDF-3BA8F7822C93"}
 */
function FIND_path(input) {
	
	/*
	 *	TITLE    :	FIND_path
	 *			  	
{'fraction_non_alphanumeric': 0.13154701718907988, 'fraction_numerical': 0.028614762386248736, 'mean_word_length': 3.154136917261655, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 3, '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': '4726176', 'n_tokens_mistral': 4379, 'n_tokens_neox': 3467, 'n_words': 691}