espenmn
(Espen)
November 21, 2019, 11:08am
1
I have a use case that is similar to this (the real use case is more complicated and not about chess):
1 Lets say I have a folders content type, lets call it:
ChessPlayer
2 Inside Chessplayer I have content types of
Chess Game
3 In Chess Game schema I have a relation to the 'ChessPlayer' (the opponent )
4 Now, If the other ChessPlayer does not exist, I need to add it before making the relation
5 I would prefer a behavior where I could suggest the Player name (Autocomplete widget maybe), but if I write a name that does not exist, the opponent (ChessPlayer content type) was 'automagically' added.
Any suggestions on how to achieve this ?
flipmcf
(flipmcf)
November 21, 2019, 5:34pm
2
I would use this!
Maybe you have to wait until the Chess Game save happens, and handle the magic ChessPlayer creation during the IObjectCreated event
espenmn
(Espen)
November 21, 2019, 6:24pm
3
I was thinking about doing it all on save, maybe something like this:
@button.buttonAndHandler(u'Save it')
def handleApply(self, action):
data, errors = self.extractData()
if errors:
self.status = self.formErrorsMessage
return
player2 = data['player2']
relation = api.content.get(UID=player2)
if relation:
new_title = relation.Title()
else:
new_title = player2
new_player = api.content.create(
type='Player',
container=portal,
title=new_title,
)
player = new_player.UID()
new_game = api.content.create(
type='Game',
container=self.context,
title=new_title,
relation=player,
)
#new_game.relation=player
I assume this should work, and I could use a schema.TextLine for Player and AjaxWidget, maybe
directives.widget(
'player',
AjaxSelectFieldWidget,
source=FindAllPLayersHere,
)
player = schema.TextLine(
title=_(u'Oponent / player 2 '),
)
Not sure if that is the correct syntax for 'Single Choice' or if another widget is better
djay
(Dylan Jay)
November 22, 2019, 2:39am
4
We have this in Plomino with a relation field with datagrid widget and the add feature enabled.
IMO once you start getting into reusing a CMS as a DB then you get into more and more issues where a web content publishing model is too opinionated and you need something designed for data. Plomino is better at modelling these kind of relationships I think. You no longer have to deal with folder structures for a start.
jensens
(Jens W. Klein)
November 22, 2019, 11:04am
5
You can fiddle with the widgets toolbar-template and add a button for creation there, i.e by providing an own JS/pattern here.
The custom template can be provided as a pattern option
* selectableTypes(array): If the value is null all types are selectable. Otherwise, provide a list of strings to match item types that are selectable. (null)
* separator(string): Select2 option. String which separates multiple items. (',')
* sortOn(string): Index on which to sort on. If null, will default to term relevance (no sort) when searching and folder order (getObjPositionInParent) when browsing. (null)
* sortOrder(string): Sort ordering. ('ascending')
* tokenSeparators(array): Select2 option, refer to select2 documentation. ([",", " "])
* upload(boolen): Allow file and image uploads from within the related items widget.
* uploadAllowView(string): View, which returns a JSON response in the form of {allowUpload: true}, if upload is allowed in the current context.
* width(string): Specify a width for the widget. ('100%')
* breadcrumbTemplate(string): Template to use for a single item in the breadcrumbs.
* breadcrumbTemplateSelector(string): Select an element from the DOM from which to grab the breadcrumbTemplate. (null)
* toolbarTemplate(string): Template for element to which toolbar items will be appended.
* toolbarTemplateSelector(string): Select an element from the DOM from which to grab the toolbarTemplate. (null)
* resultTemplate(string): Template for an item in the in the list of results. Refer to source for default. (Refer to source)
* resultTemplateSelector(string): Select an element from the DOM from which to grab the resultTemplate. (null)
* selectionTemplate(string): Template for element that will be used to construct a selected item. (Refer to source)
* selectionTemplateSelector(string): Select an element from the DOM from which to grab the selectionTemplate. (null)
*
* Documentation:
* The Related Items pattern is based on Select2 so many of the same options will work here as well.
*
* # Default, mode "search"
espenmn
(Espen)
November 22, 2019, 11:14am
6
It is a long time since I looked at Plomingo and in general I think you are right.
But for my use case I need a 'very simple UI' (that means: without the toolbar) mostly for Phones.
If i remember right, that was difficult with Plomino.
If I remember right, Plomino uses a lot of tables in the 'layouts' (?)
espenmn
(Espen)
November 22, 2019, 9:42pm
7
For reference:
Looks like one needs an ID to control the number of items that can be selected with javascript. This was the only I could get to work
$('#formfield-form-widgets-player input').select({
maximumSelectionSize: 1
}).on('select2-opening', function(e) {
if ($(this).select2('val').length > 0) {
e.preventDefault();
}
});
Netroxen
(Jesse Stippel)
November 25, 2019, 8:02am
8
I would create a dynamic vocabulary which calls and returns a list of chess players. On the schema definition you can define if new items are allowable, doing this in combination with an IObjectCreatedEvent
would be my plan of attack for something like this.