def __call__(self, field: TreeField, **kwargs: Any) -> TreeSelect:
     from openatlas.models.node import NodeMapper
     selection = ''
     selected_ids = []
     if field.data:
         field.data = field.data[0] if type(
             field.data) is 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()"
             readonly="readonly" value="{selection}" placeholder="{change_label}">
         <a id="{name}-clear" {clear_style} class="button"
             onclick="clearSelect('{name}');">{clear_label}</a>
         <div id="{name}-overlay" class="overlay">
             <div id="{name}-dialog" class="overlay-container">
                 <input class="tree-filter" id="{name}-tree-search" placeholder="{filter}">
                 <div id="{name}-tree"></div>
             </div>
         </div>
         <script>
             $(document).ready(function () {{
                 createOverlay("{name}","{title}",false,);
                 $("#{name}-tree").jstree({{
                     "core" : {{"check_callback" : true, 'data':[{tree_data}]}},
                     "search": {{"case_insensitive": true, "show_only_matches": 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,
         title=g.nodes[int(field.id)].name,
         change_label=uc_first(_('change')),
         clear_label=uc_first(_('clear')),
         selection=selection,
         tree_data=NodeMapper.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
Esempio n. 2
0
 def __call__(self, field, **kwargs):
     from openatlas.models.node import NodeMapper
     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)
     try:
         hierarchy_id = int(field.id)
     except ValueError:
         hierarchy_id = NodeMapper.get_hierarchy_by_name(uc_first(field.id)).id
     root = g.nodes[hierarchy_id]
     html = """
         <input id="{name}-button" name="{name}-button" type="text"
             class="table-select {required}" onfocus="this.blur()"
             readonly="readonly" value="{selection}" placeholder="{change_label}" />
         <a id="{name}-clear" {clear_style} class="button"
             onclick="clearSelect('{name}');">{clear_label}</a>
         <div id="{name}-overlay" class="overlay">
             <div id="{name}-dialog" class="overlay-container">
                 <input class="tree-filter" id="{name}-tree-search" placeholder="Filter" />
                 <div id="{name}-tree"></div>
             </div>
         </div>
         <script>
             $(document).ready(function () {{
                 createOverlay("{name}","{title}",false,);
                 $("#{name}-tree").jstree({{
                     "core" : {{"check_callback" : true, 'data':[{tree_data}]}},
                     "search": {{"case_insensitive": true, "show_only_matches": 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() {{
                     $("#{name}-tree").jstree("search", $(this).val());
                 }});
             }});
         </script>""".format(
         name=field.id,
         title=root.name,
         change_label=uc_first(_('change')),
         clear_label=uc_first(_('clear')),
         selection=selection,
         tree_data=NodeMapper.get_tree_data(hierarchy_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, **kwargs):
     from openatlas.models.node import NodeMapper
     selection = ''
     selected_ids = []
     if field.data:
         field.data = field.data[0] if type(field.data) is 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()"
             readonly="readonly" value="{selection}" placeholder="{change_label}" />
         <a id="{name}-clear" {clear_style} class="button"
             onclick="clearSelect('{name}');">{clear_label}</a>
         <div id="{name}-overlay" class="overlay">
             <div id="{name}-dialog" class="overlay-container">
                 <input class="tree-filter" id="{name}-tree-search" placeholder="{filter}" />
                 <div id="{name}-tree"></div>
             </div>
         </div>
         <script>
             $(document).ready(function () {{
                 createOverlay("{name}","{title}",false,);
                 $("#{name}-tree").jstree({{
                     "core" : {{"check_callback" : true, 'data':[{tree_data}]}},
                     "search": {{"case_insensitive": true, "show_only_matches": 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());
                     }}
                 }});
             }});
         </script>""".format(
         filter=uc_first(_('type to search')),
         min_chars=session['settings']['minimum_jstree_search'],
         name=field.id,
         title=g.nodes[int(field.id)].name,
         change_label=uc_first(_('change')),
         clear_label=uc_first(_('clear')),
         selection=selection,
         tree_data=NodeMapper.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:
         # Somehow field.data can be a string after a failed form validation, so fix that below
         field.data = ast.literal_eval(
             field.data) if type(field.data) is 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">{change_label}</span>
         <div id="{name}-selection" style="text-align:left;">{selection}</div>
         <div id="{name}-overlay" class="overlay">
            <div id="{name}-dialog" class="overlay-container">
                <input class="tree-filter" id="{name}-tree-search" placeholder="{filter}">
                <div id="{name}-tree"></div>
            </div>
         </div>
         <script>
             createOverlay("{name}", "{title}", true, "tree");
             $("#{name}-tree").jstree({{
                 "core" : {{ "check_callback" : true, 'data':[{tree_data}] }},
                 "search": {{"case_insensitive": true, "show_only_matches": 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,
         title=root.name,
         selection=selection,
         change_label=uc_first(_('change')),
         tree_data=NodeMapper.get_tree_data(int(field.id), selected_ids))
     return super(TreeMultiSelect, self).__call__(field, **kwargs) + html
 def __call__(self, field, **kwargs):
     selection = ''
     selected_ids = []
     root = g.nodes[int(field.id)]
     if field.data:
         # Somehow field.data can be a string after a failed form validation, so fix that below
         field.data = ast.literal_eval(field.data) if type(field.data) is 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">{change_label}</span>
         <div id="{name}-selection" style="text-align:left;">{selection}</div>
         <div id="{name}-overlay" class="overlay">
            <div id="{name}-dialog" class="overlay-container">
                <input class="tree-filter" id="{name}-tree-search" placeholder="{filter}" />
                <div id="{name}-tree"></div>
            </div>
         </div>
         <script>
             createOverlay("{name}", "{title}", true, "tree");
             $("#{name}-tree").jstree({{
                 "core" : {{ "check_callback" : true, 'data':[{tree_data}] }},
                 "search": {{"case_insensitive": true, "show_only_matches": 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());
                 }}
             }});
         </script>""".format(
         filter=uc_first(_('type to search')),
         min_chars=session['settings']['minimum_jstree_search'],
         name=field.id,
         title=root.name,
         selection=selection,
         change_label=uc_first(_('change')),
         tree_data=NodeMapper.get_tree_data(int(field.id), selected_ids))
     return super(TreeMultiSelect, self).__call__(field, **kwargs) + html
Esempio n. 6
0
 def __call__(self, field, **kwargs):
     selection = ''
     selected_ids = []
     root = g.nodes[int(field.id)]
     if field.data:
         if isinstance(field.data, str):
             field.data = ast.literal_eval(field.data)
         for entity_id in field.data:
             entity = g.nodes[entity_id]
             selected_ids.append(entity.id)
     html = """
         <span id="{name}-button" class="button">{change_label}</span>
         <div id="{name}-selection" style="text-align:left;">{selection}</div>
         <div id="{name}-overlay" class="overlay">
            <div id="{name}-dialog" class="overlay-container">
                <input class="tree-filter" id="{name}-tree-search" placeholder="Filter" />
                <div id="{name}-tree"></div>
            </div>
         </div>
         <script>
             createOverlay("{name}", "{title}", true, "tree");
             $("#{name}-tree").jstree({{
                 "core" : {{ "check_callback" : true, 'data':[{tree_data}] }},
                 "search": {{"case_insensitive": true, "show_only_matches": true}},
                 "plugins": ["search", "checkbox"],
                 "checkbox": {{"three_state": false}}
             }});
             $("#{name}-tree-search").keyup(function(){{
                 $("#{name}-tree").jstree("search", $(this).val());
             }});
         </script>""".format(
         name=field.id,
         title=root.name,
         selection=selection,
         change_label=uc_first(_('change')),
         tree_data=NodeMapper.get_tree_data(int(field.id), selected_ids))
     return super(TreeMultiSelect, self).__call__(field, **kwargs) + html