be519897e2dfd28f0e14cab212bf80e64227615e
[laas.git] / src / templates / dashboard / searchable_select_multiple.html
1 <div id="search_select_outer" class="d-flex flex-column">
2     {% if incompatible == "true" %}
3         <div class="alert alert-danger" role="alert">
4             <h3>Warning: Incompatible Configuration</h3>
5             <p>Please make a different selection, as the current config conflicts with the selected pod</p>
6         </div>
7     {% endif %}
8     <div id="added_counter" class="text-center">
9         <span id="added_number">0</span>
10         <span id="addable_limit">/ {% if selectable_limit > -1 %} {{ selectable_limit }} {% else %} &infin; {% endif %}added</span>
11     </div>
12
13     <div id="added_list" class="pb-2">
14
15     </div>
16
17     <input id="user_field" name="ignore_this" class="form-control" autocomplete="off" type="text" placeholder="{{placeholder}}" value="" oninput="searchable_select_multiple_widget.search(this.value)"
18     {% if disabled %} disabled {% endif %}
19     >
20     </input>
21
22     <input type="hidden" id="selector" name="{{ name }}" class="form-control d-none"
23     {% if disabled %} disabled {% endif %}
24     >
25     </input>
26
27     <div id="scroll_restrictor" class="d-flex pb-4 position-relative">
28         <div id="drop_results" class="list-group w-100 z-2 overflow-auto position-absolute mh-30vh"></div>
29     </div>
30 </div>
31
32 <script type="text/javascript">
33     function searchableSelectMultipleWidgetEntry() {
34         let format_vars = {
35             "show_from_noentry": {{show_from_noentry|yesno:"true,false"}},
36             "show_x_results": {{show_x_results|default:-1}},
37             "results_scrollable": {{results_scrollable|yesno:"true,false"}},
38             "selectable_limit": {{selectable_limit|default:-1}},
39             "placeholder": "{{placeholder|default:"begin typing"}}"
40         };
41
42         let field_dataset = {{items|safe}};
43
44         let field_initial = {{ initial|safe }};
45
46         //global
47         searchable_select_multiple_widget = new SearchableSelectMultipleWidget(format_vars, field_dataset, field_initial);
48     }
49
50     searchableSelectMultipleWidgetEntry();
51
52     /*
53     var show_from_noentry = context(show_from_noentry|yesno:"true,false") // whether to show any results before user starts typing
54     var show_x_results = context(show_x_results|default:-1) // how many results to show at a time, -1 shows all results
55     var results_scrollable = {{results_scrollable|yesno:"true,false") // whether list should be scrollable
56     var selectable_limit = {{selectable_limit|default:-1) // how many selections can be made, -1 allows infinitely many
57     var placeholder = "context(placeholder|default:"begin typing")" // placeholder that goes in text box
58
59     needed info
60     var items = context(items|safe) // items to add to trie. Type is a dictionary of dictionaries with structure:
61         {
62             id# : {
63                 "id": any, identifiable on backend
64                 "small_name": string, displayed first (before separator), searchable (use for e.g. username)
65                 "expanded_name": string, displayed second (after separator), searchable (use for e.g. email address)
66                 "string": string, not displayed, still searchable
67             }
68         }
69
70      used later:
71     context(selectable_limit): changes what number displays for field
72     context(name): form identifiable name, relevant for backend
73         // when submitted, form will contain field data in post with name as the key
74     context(placeholder): "greyed out" contents put into search field initially to guide user as to what they're searching for
75     context(initial): in search_field_init(), marked safe, an array of id's each referring to an id from items
76     */
77 </script>