|
62 | 62 | qiita_websocket.add_callback('clear', clear_from_html);
|
63 | 63 | $('#clear-button').on('click', clear);
|
64 | 64 | {% if sel_data %}$('#no-selected').hide(){% end %}
|
| 65 | + |
| 66 | + var common_sample_fields = {% raw list(common['sample']) %}; |
| 67 | + var common_prep_fields = {% raw list(common['prep']) %}; |
| 68 | + |
| 69 | + $.each($(".chosen-select"), function (_, element){ |
| 70 | + var is_sample = element.id.startsWith('sample-metadata'); |
| 71 | + $.each(element.options, function (_, option){ |
| 72 | + if (is_sample) { |
| 73 | + if (jQuery.inArray(option.text, common_sample_fields) >= 0) { |
| 74 | + option.selected=true; |
| 75 | + $('#analysis-metadata').append( |
| 76 | + $('<option>', { value: option.value, text: option.text, |
| 77 | + selected: true})); |
| 78 | + } |
| 79 | + } else { |
| 80 | + if (jQuery.inArray(option.text, common_prep_fields) >= 0) { |
| 81 | + option.selected=true; |
| 82 | + $('#analysis-metadata').append( |
| 83 | + $('<option>', { value: option.value, text: option.text, |
| 84 | + selected: true})); |
| 85 | + } |
| 86 | + } |
| 87 | + }); |
| 88 | + }); |
| 89 | + |
| 90 | + $('#analysis-metadata').chosen({ |
| 91 | + width: "95%" |
| 92 | + }); |
| 93 | + |
| 94 | + $(".chosen-select").chosen({ |
| 95 | + width: "95%", |
| 96 | + no_results_text: "Oops, nothing found!", |
| 97 | + display_disabled_options: false, |
| 98 | + display_selected_options: false, |
| 99 | + }).change(function(event, object) { |
| 100 | + var item = $(this).attr('id'); |
| 101 | + var key = Object.keys(object)[0]; |
| 102 | + var toggle = key == 'selected'; |
| 103 | + var selection = object[key]; |
| 104 | + |
| 105 | + if (toggle) { |
| 106 | + $('#analysis-metadata').append( |
| 107 | + $('<option>', { value: selection, text: selection, |
| 108 | + selected: true})); |
| 109 | + } else { |
| 110 | + $(".analysis-metadata option[value='" + selection + "']").remove(); |
| 111 | + } |
| 112 | + // we need to update the chosen element AKA this line is needed for |
| 113 | + // things to work fine |
| 114 | + $("#analysis-metadata").trigger("chosen:updated"); |
| 115 | + |
| 116 | + if (jQuery.inArray(object[key], common_sample_fields) >= 0) { |
| 117 | + $.each($(".chosen-select"), function (_, element){ |
| 118 | + if (item != element.id) { |
| 119 | + $.each(element.options, function (_, option){ |
| 120 | + if (option.text == selection) { |
| 121 | + option.selected=toggle; |
| 122 | + } |
| 123 | + }); |
| 124 | + } |
| 125 | + }); |
| 126 | + } else if (jQuery.inArray(object[key], common_sample_fields) >= 0) { |
| 127 | + $.each($(".chosen-select"), function (_, element){ |
| 128 | + if (item != element.id) { |
| 129 | + $.each(element.options, function (_, option){ |
| 130 | + if (option.text == selection) { |
| 131 | + option.selected=toggle; |
| 132 | + } |
| 133 | + }); |
| 134 | + } |
| 135 | + }); |
| 136 | + } |
| 137 | + }); |
65 | 138 | });
|
66 | 139 | </script>
|
67 | 140 | {% end %}
|
68 | 141 |
|
| 142 | + |
69 | 143 | {% block content %}
|
70 | 144 | <h1>Selected Samples</h1>
|
71 | 145 | <span id="ws-error" style="color:red"></span>
|
@@ -139,6 +213,27 @@ <h4 class="modal-title" id="myModalLabel">Processed Data {{pid}}</h4>
|
139 | 213 | {% end %}
|
140 | 214 | {% end %}
|
141 | 215 | </table>
|
| 216 | + <hr> |
| 217 | + <h4>Metadata Selection <small>Common fields for all studies are preselected</small></h4> |
| 218 | + <table border="0" style="width: 100%;"> |
| 219 | + <tr> |
| 220 | + <td style="width: 50%;"> |
| 221 | + Sample Information |
| 222 | + <select data-placeholder="Choose Sample Metadata..." multiple class="chosen-select" id="sample-metadata-{{study.id}}"> |
| 223 | + {% for field in sorted(metadata[study.id]['sample']) %} |
| 224 | + <option value="{{field}}">{{field}}</option> |
| 225 | + {% end %} |
| 226 | + </select> |
| 227 | + </td> |
| 228 | + <td style="width: 50%;"> |
| 229 | + Preparation Information |
| 230 | + <select data-placeholder="Choose Preparation Metadata..." multiple class="chosen-select" id="prep-metadata-{{study.id}}"> |
| 231 | + {% for field in sorted(metadata[study.id]['prep']) %} |
| 232 | + <option value="{{field}}">{{field}}</option> |
| 233 | + {% end %} |
| 234 | + </td> |
| 235 | + </tr> |
| 236 | + </table> |
142 | 237 | </div>
|
143 | 238 | </div>
|
144 | 239 | {% end %}
|
@@ -167,10 +262,14 @@ <h4 class="modal-title" id="myModalLabel">Create new analysis</h4>
|
167 | 262 | <label for="description">Merge samples with the same name <br/><small>useful when merging multiple preparation artifacts</small></label>
|
168 | 263 | <input type="checkbox" class="form-control" id="merge_duplicated_sample_ids" name="merge_duplicated_sample_ids">
|
169 | 264 | </div>
|
| 265 | + <div class="form-group"> |
| 266 | + <label for="description">Metadata selected <small>(to update use the main page)</small></label> |
| 267 | + <select name="analysis-metadata" id="analysis-metadata" class="analysis-metadata" multiple disabled></select> |
| 268 | + </div> |
170 | 269 | </div>
|
171 | 270 | </div>
|
172 | 271 | <div class="modal-footer">
|
173 |
| - <button type="submit" class="btn btn-primary">Create analysis</button> |
| 272 | + <button type="submit" onclick="$('#analysis-metadata').removeAttr('disabled');" "class="btn btn-primary">Create analysis</button> |
174 | 273 | </div>
|
175 | 274 | </form>
|
176 | 275 | </div>
|
|
0 commit comments