X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=turbot%2Fblocks.py;h=cdce64a2f99aa3b83aa230418e0338f4589e9211;hb=465eb019a7e380590df492762b9c904ece977069;hp=dde2cfb913d3bcddd76e1c44da9f465587aeb081;hpb=4f287a0e6b54f57529162c555c2502b3726d1edd;p=turbot diff --git a/turbot/blocks.py b/turbot/blocks.py index dde2cfb..cdce64a 100644 --- a/turbot/blocks.py +++ b/turbot/blocks.py @@ -29,6 +29,42 @@ def actions_block(*elements): "elements": list(elements) } +def checkbox_block(label, text, name, checked=False): + + element = { + "type": "checkboxes", + "action_id": name, + "options": [ + { + "value": name, + "text": { + "type": "plain_text", + "text": text + } + } + ] + } + + if checked: + element["initial_options"] = [{ + "value": name, + "text": { + "type": "plain_text", + "text": text + } + }] + + return { + "type": "input", + "block_id": name, + "element": element, + "optional": True, + "label": { + "type": "plain_text", + "text": label + } + } + def button_block(label, name, extra=None): block = { @@ -54,28 +90,35 @@ def accessory_block(main, accessory): } } -def input_block(label, name, placeholder, optional=False): +def input_block(label, name, placeholder, initial_value=None, optional=False): + + element = { + "type": "plain_text_input", + "action_id": name, + "placeholder": { + "type": "plain_text", + "text": placeholder, + } + } + + if initial_value: + element["initial_value"] = initial_value + return { "type": "input", "block_id": name, "optional": optional, - "element": { - "type": "plain_text_input", - "action_id": name, - "placeholder": { - "type": "plain_text", - "text": placeholder, - } - }, + "element": element, "label": { "type": "plain_text", "text": label } } -def multi_select_block(label, name, placeholder, options, default=None): +def multi_select_block(label, name, placeholder, options, + initial_options=None): - multi_select = { + multi_select = { "action_id": name, "type": "multi_static_select", "placeholder": { @@ -93,6 +136,17 @@ def multi_select_block(label, name, placeholder, options, default=None): ] } + if initial_options: + multi_select["initial_options"] = [ + { + "text": { + "type": "plain_text", + "text": option + }, + "value": option + } for option in initial_options + ] + return accessory_block( section_block(text_block("*{}*".format(label)), block_id=name), multi_select