def __call__(self, field: TreeField, **kwargs: Any) -> TreeMultiSelect: data: List[int] = [] if field.data: data = ast.literal_eval(field.data) \ if isinstance(field.data, str) else field.data html = render_template('forms/tree_multi_select.html', field=field, root=g.nodes[int(field.id)], selection=sorted( [g.nodes[id_].name for id_ in data]), data=Node.get_tree_data(int(field.id), data)) return super(TreeMultiSelect, self).__call__(field, **kwargs) + html
def __call__(self, field: TreeField, **kwargs: Any) -> TreeSelect: selection = '' selected_ids = [] if field.data: field.data = field.data[0] \ if isinstance(field.data, list) else field.data selection = g.nodes[int(field.data)].name selected_ids.append(g.nodes[int(field.data)].id) html = render_template('forms/tree_select.html', field=field, selection=selection, data=Node.get_tree_data(int(field.id), selected_ids)) return super(TreeSelect, self).__call__(field, **kwargs) + html
def __call__(self, field: TreeField, **kwargs: Any) -> TreeSelect: from openatlas.models.node import Node selection = '' selected_ids = [] if field.data: field.data = field.data[0] if isinstance(field.data, list) else field.data selection = g.nodes[int(field.data)].name selected_ids.append(g.nodes[int(field.data)].id) html = """ <input id="{name}-button" name="{name}-button" type="text" class="table-select {required}" onfocus="this.blur()" onclick="$('#{name}-modal').modal('show')" readonly="readonly" value="{selection}" placeholder="{change_label}"> <a href="#" id="{name}-clear" {clear_style} class="{button_class}" onclick="clearSelect('{name}');"> {clear_label} </a> <div id="{name}-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">{title}</h5> <button type="button" class="btn btn-outline-primary btn-sm" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <input class="tree-filter" id="{name}-tree-search" placeholder="{filter}" type="text"> <div id="{name}-tree" style="text-align: left!important;"></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-outline-primary btn-sm" data-dismiss="modal"> {close_label} </button> </div> </div> </div> </div> <script> $(document).ready(function () {{ $("#{name}-tree").jstree({{ "core" : {{"check_callback": true, "data": {tree_data}}}, "search": {{"case_insensitive": true, "show_only_matches": true, "show_only_matches_children": true}}, "plugins" : ["search"], }}); $("#{name}-tree").on("select_node.jstree", function (e, data) {{ selectFromTree("{name}", data.node.id, data.node.text); }}); $("#{name}-tree-search").keyup(function() {{ if (this.value.length >= {min_chars}) {{ $("#{name}-tree").jstree("search", $(this).val()); }} else if (this.value.length == 0) {{ $("#{name}-tree").jstree("search", $(this).val()); $("#{name}-tree").jstree(true).show_all(); }} }}); }}); </script>""".format( filter=uc_first(_('type to search')), min_chars=session['settings']['minimum_jstree_search'], name=field.id, button_class=app.config['CSS']['button']['secondary'], title=uc_first(g.nodes[int(field.id)].name), change_label=uc_first(_('change')), clear_label=uc_first(_('clear')), close_label=uc_first(_('close')), selection=selection, tree_data=Node.get_tree_data(int(field.id), selected_ids), clear_style='' if selection else ' style="display: none;" ', required=' required' if field.flags.required else '') return super(TreeSelect, self).__call__(field, **kwargs) + html
def __call__(self, field: TreeField, **kwargs: Any) -> TreeMultiSelect: selection = '' selected_ids = [] root = g.nodes[int(field.id)] if field.data: field.data = ast.literal_eval(field.data) if isinstance( field.data, str) else field.data for entity_id in field.data: selected_ids.append(entity_id) selection += g.nodes[entity_id].name + '<br>' html = """ <span id="{name}-button" class="{button_class}" onclick="$('#{name}-modal').modal('show')"> {change_label} </span> <div id="{name}-selection" style="text-align:left;"> {selection} </div> <div id="{name}-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">{title}</h5> <button type="button" class="btn btn-outline-primary btn-sm" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <input class="tree-filter" id="{name}-tree-search" placeholder="{filter}" type="text"> <div id="{name}-tree" style="text-align: left!important;"></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-outline-primary btn-sm" data-dismiss="modal" onclick="selectFromTreeMulti({name})"> {close_label} </button> </div> </div> </div> </div> <script> $("#{name}-tree").jstree({{ "core" : {{ "check_callback": true, "data": {tree_data} }}, "search": {{"case_insensitive": true, "show_only_matches": true, "show_only_matches_children": true}}, "plugins": ["search", "checkbox"], "checkbox": {{"three_state": false}} }}); $("#{name}-tree-search").keyup(function(){{ if (this.value.length >= {min_chars}) {{ $("#{name}-tree").jstree("search", $(this).val()); }} else if (this.value.length == 0) {{ $("#{name}-tree").jstree("search", $(this).val()); $("#{name}-tree").jstree(true).show_all(); }} }}); </script>""".format( filter=uc_first(_('type to search')), min_chars=session['settings']['minimum_jstree_search'], name=field.id, button_class=app.config['CSS']['button']['secondary'], title=uc_first(root.name), selection=selection, change_label=uc_first(_('change')), close_label=uc_first(_('close')), tree_data=Node.get_tree_data(int(field.id), selected_ids)) return super(TreeMultiSelect, self).__call__(field, **kwargs) + html