Get selected date from equipment schedule

I’m trying to create a Vision window that shows scheduled events using the equipment schedule, which is pulling its dataset from a SQL table.
Displaying the data is all fine and dandy, but how on earth can we create a new event by interacting directly with the equipment schedule component?

The onPopupTrigger seems like the perfect place to define a “Create Event” function, but none of the attributes available are any use for doing so, as there is no reference to the date the mouse is clicking.
It only provides the itemId, which seems fairly useless.

I’m thinking along the lines of having the user being able to double click or right click an empty day in the scheduler, and for them to easily create a new event.

It’s possible, but non-obvious. Here’s code from an equipment schedule component that lets me add a row to a postgres table. The code toward the top calculates the point in time that was clicked (or, close enough for my purposes). It also calculates a minimum event width that’s based on the current time span of the component. The rest of the code is just gathering more info for packaging into the SQL row, should the popup option be clicked.

	s = event.source.getSize().width
	c = event.getX()
	rangeStart = system.date.parse(self.startDate)
	rangeEnd = system.date.parse(self.endDate)
	rangeMinutes = system.date.minutesBetween(rangeStart, rangeEnd)
	halfRangeNewEvent = rangeMinutes * .01
	timePointClicked = system.date.addMinutes(rangeStart, int(((float(c)/s)*rangeMinutes)))
	newEventStart = system.date.format(system.date.addMinutes(timePointClicked, -1*(int(halfRangeNewEvent))),"yyyy-MM-dd HH:mm:ssX")
	newEventEnd = system.date.format(system.date.addMinutes(timePointClicked, int(halfRangeNewEvent)),"yyyy-MM-dd HH:mm:ssX")
	

	def addEvent(evt):
		db = 'postgres'
		#get segment for time stamp clicked
		segmentRunning = system.tag.queryTagHistory(paths=['[default]Tiny/BasicInfo/Current Segment'], startDate=timePointClicked, endDate=timePointClicked, returnSize=1, aggregationMode="LastValue", returnFormat='Wide')
		segmentRunning = int(segmentRunning.getValueAt(0,1))
		#get recipe number for segment running
		query = "SELECT COALESCE((SELECT recipe_number FROM tiny_recipes WHERE segment_range @> ?),99999)"
		args = [segmentRunning]
		currentRecipe = system.db.runPrepQuery(query, args, db)
		currentRecipe = currentRecipe.getValueAt(0,0)
		query = "INSERT INTO tiny_loads (equip_tagpath, recipe_running, load_timerange) VALUES (?,?,tstzrange(?::timestamptz,?::timestamptz));"
		args = [itemId, currentRecipe, newEventStart, newEventEnd]
		insertResult = system.db.runPrepUpdate(query, args, db)
		system.db.refresh(self,"scheduledEvents")
		container = self.parent.getComponent('loadDetailsContainer')
		system.db.refresh(container, "LoadDetailsDataset")
	
	#if the newEventEnd date is in the past, show the popup menu
	#using newEventEnd instead of timePointClicked to avoid creating closed events in the future.  The other scripts expect to see a NULL value for currently occuring events.
	if system.date.parse(newEventEnd) < system.date.now() and "canEditFurnaceLoadHistory" in system.security.getRoles():
		menu = system.gui.createPopupMenu(['Add Load Here'],[addEvent])
		menu.show(event)