PageRenderTime 31ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/templates/tool_form.mako

https://bitbucket.org/cistrome/cistrome-harvard/
Mako | 317 lines | 290 code | 25 blank | 2 comment | 6 complexity | 5a67d99763052b94a541efa2a127431c MD5 | raw file
  1<%inherit file="/base.mako"/>
  2<%namespace file="/base_panels.mako" import="overlay" />
  3
  4<%def name="stylesheets()">
  5    ${h.css( "autocomplete_tagging", "base", "panel_layout", "library" )}
  6    <style type="text/css">
  7        html, body {
  8            background-color: #fff;
  9        }
 10    </style>
 11</%def>
 12
 13<%def name="javascripts()">
 14    ${h.js( "jquery", "galaxy.panels", "galaxy.base", "jquery.autocomplete", "jstorage" )}
 15    <script type="text/javascript">
 16    $(function() {
 17        $(window).bind("refresh_on_change", function() {
 18            $(':file').each( function() {
 19                var file = $(this);
 20                var file_value = file.val();
 21                if (file_value) {
 22                    // disable file input, since we don't want to upload the file on refresh
 23                    var file_name = $(this).attr("name");
 24                    file.attr( { name: 'replaced_file_input_' + file_name, disabled: true } );
 25                    // create a new hidden field which stores the filename and has the original name of the file input
 26                    var new_file_input = $(document.createElement('input'));
 27                    new_file_input.attr( { "type": "hidden", "value": file_value, "name": file_name } );
 28                    file.after(new_file_input);
 29                }
 30            });
 31        });
 32
 33        // For drilldown parameters: add expand/collapse buttons and collapse initially-collapsed elements
 34        $( 'li ul.toolParameterExpandableCollapsable' ).each( function() {
 35            var el = $(this),
 36                parent_li = el.parent('li'),
 37                sub_ul = el.remove();
 38
 39            parent_li.find( 'span' ).wrapInner( '<a/>' ).find( 'a' ).click( function() {
 40                sub_ul.toggle();
 41                (this).html( sub_ul.is(":hidden") ? '[+]' : '[-]' );
 42            });
 43            parent_li.append( sub_ul );
 44        });
 45
 46        $( 'ul ul.toolParameterExpandableCollapsable' ).each( function(i) {
 47            var el = $(this);
 48            if (el.attr("default_state") === "collapsed") {
 49                el.hide();
 50            }
 51        });
 52
 53        function checkUncheckAll( name, check ) {
 54            $("input[name='" + name + "'][type='checkbox']").attr('checked', !!check);
 55        }
 56
 57        // Inserts the Select All / Unselect All buttons for checkboxes
 58        $("div.checkUncheckAllPlaceholder").each( function() {
 59            var check_name = $(this).attr("checkbox_name");
 60            select_link = $("<a class='action-button'></a>").text("Select All").click(function() {
 61               checkUncheckAll(check_name, true);
 62            });
 63            unselect_link = $("<a class='action-button'></a>").text("Unselect All").click(function() {
 64               checkUncheckAll(check_name, false);
 65            });
 66            $(this).append(select_link).append(" ").append(unselect_link);
 67        });
 68        
 69        $(".add-librarydataset").live("click", function() {
 70            var link = $(this);
 71            $.ajax({
 72                url: "/tracks/list_libraries",
 73                error: function(xhr, ajaxOptions, thrownError) { alert( "Grid failed" ); console.log(xhr, ajaxOptions, thrownError); },
 74                success: function(table_html) {
 75                    show_modal(
 76                        "Select Library Dataset",
 77                        table_html, {
 78                            "Cancel": function() {
 79                                hide_modal();
 80                            },
 81                            "Select": function() {
 82                                var names = [];
 83                                var ids = [];
 84                                counter = 1;
 85                                $('input[name=ldda_ids]:checked').each(function() {
 86                                    var name = $.trim( $(this).siblings("label").text() );
 87                                    var id = $(this).val();
 88                                    names.push( counter + ". " + name );
 89                                    counter += 1;
 90                                    ids.push(id);
 91                                });
 92                                link.html( names.join("<br/>") );
 93                                link.siblings("input[type=hidden]").val( ids.join("||") );
 94                                hide_modal();
 95                            }
 96                        }
 97                    );
 98                }
 99            });
100        });
101    });
102
103    %if not add_frame.debug:
104        if( window.name != "galaxy_main" ) {
105            location.replace( '${h.url_for( controller='root', action='index', tool_id=tool.id )}' );
106        }
107    %endif
108
109    </script>
110
111</%def>
112
113<%def name="do_inputs( inputs, tool_state, errors, prefix, other_values=None )">
114    <%
115    from galaxy.util.expressions import ExpressionContext
116    other_values = ExpressionContext( tool_state, other_values )
117    %>
118    %for input_index, input in enumerate( inputs.itervalues() ):
119        %if not input.visible:
120            <% pass %>
121        %elif input.type == "repeat":
122          <div class="repeat-group">
123              <div class="form-title-row"><strong>${input.title_plural}</strong></div>
124              <% repeat_state = tool_state[input.name] %>
125              %for i in range( len( repeat_state ) ):
126                <div class="repeat-group-item">
127                    <%
128                    if input.name in errors:
129                        rep_errors = errors[input.name][i]
130                    else:
131                        rep_errors = dict()
132                    index = repeat_state[i]['__index__']
133                    %>
134                    <div class="form-title-row"><strong>${input.title} ${i + 1}</strong></div>
135                    ${do_inputs( input.inputs, repeat_state[i], rep_errors, prefix + input.name + "_" + str(index) + "|", other_values )}
136                    <div class="form-row"><input type="submit" name="${prefix}${input.name}_${index}_remove" value="Remove ${input.title} ${i+1}"></div>
137                </div>
138                %if rep_errors.has_key( '__index__' ):
139                    <div><img style="vertical-align: middle;" src="${h.url_for('/static/style/error_small.png')}">&nbsp;<span style="vertical-align: middle;">${rep_errors['__index__']}</span></div>
140                %endif
141              %endfor
142              <div class="form-row"><input type="submit" name="${prefix}${input.name}_add" value="Add new ${input.title}"></div>
143          </div>
144        %elif input.type == "conditional":
145            <%
146            group_state = tool_state[input.name]
147            group_errors = errors.get( input.name, {} )
148            current_case = group_state['__current_case__']
149            group_prefix = prefix + input.name + "|"
150            %>
151            %if input.value_ref_in_group:
152                ${row_for_param( group_prefix, input.test_param, group_state, group_errors, other_values )}
153            %endif
154            ${do_inputs( input.cases[current_case].inputs, group_state, group_errors, group_prefix, other_values )}
155        %elif input.type == "upload_dataset":
156            %if input.get_datatype( trans, other_values ).composite_type is None: #have non-composite upload appear as before
157                <%
158                if input.name in errors:
159                    rep_errors = errors[input.name][0]
160                else:
161                    rep_errors = dict()
162                %>
163              ${do_inputs( input.inputs, tool_state[input.name][0], rep_errors, prefix + input.name + "_" + str( 0 ) + "|", other_values )}
164            %else:
165                <div class="repeat-group">
166                    <div class="form-title-row"><strong>${input.group_title( other_values )}</strong></div>
167                    <%
168                    repeat_state = tool_state[input.name]
169                    %>
170                    %for i in range( len( repeat_state ) ):
171                      <div class="repeat-group-item">
172                      <%
173                      if input.name in errors:
174                          rep_errors = errors[input.name][i]
175                      else:
176                          rep_errors = dict()
177                      index = repeat_state[i]['__index__']
178                      %>
179                      <div class="form-title-row"><strong>File Contents for ${input.title_by_index( trans, i, other_values )}</strong></div>
180                      ${do_inputs( input.inputs, repeat_state[i], rep_errors, prefix + input.name + "_" + str(index) + "|", other_values )}
181                      ##<div class="form-row"><input type="submit" name="${prefix}${input.name}_${index}_remove" value="Remove ${input.title} ${i+1}"></div>
182                      </div>
183                    %endfor
184                    ##<div class="form-row"><input type="submit" name="${prefix}${input.name}_add" value="Add new ${input.title}"></div>
185                </div>
186            %endif
187        %else:
188            ${row_for_param( prefix, input, tool_state, errors, other_values )}
189        %endif
190    %endfor
191</%def>
192
193<%def name="row_for_param( prefix, param, parent_state, parent_errors, other_values )">
194    <%
195    if parent_errors.has_key( param.name ):
196        cls = "form-row form-row-error"
197    else:
198        cls = "form-row"
199
200    label = param.get_label()
201
202    field = param.get_html_field( trans, parent_state[ param.name ], other_values )
203    field.refresh_on_change = param.refresh_on_change
204
205    # Field may contain characters submitted by user and these characters may be unicode; handle non-ascii characters gracefully.
206    field_html = field.get_html( prefix )
207    if type( field_html ) is not unicode:
208        field_html = unicode( field_html, 'utf-8' )
209
210    if param.type == "hidden":
211        return field_html
212    %>
213    <div class="${cls}">
214        %if label:
215            <label for="${param.name}">${label}:</label>
216        %endif
217        <div class="form-row-input">${field_html}</div>
218        %if parent_errors.has_key( param.name ):
219            <div class="form-row-error-message">
220                <div><img style="vertical-align: middle;" src="${h.url_for('/static/style/error_small.png')}">&nbsp;<span style="vertical-align: middle;">${parent_errors[param.name]}</span></div>
221            </div>
222        %endif
223
224        %if param.help:
225            <div class="toolParamHelp" style="clear: both;">
226                ${param.help}
227            </div>
228        %endif
229
230        <div style="clear: both;"></div>
231
232    </div>
233</%def>
234
235<% overlay(visible=False) %>
236
237%if add_frame.from_noframe:
238    <div class="warningmessage">
239        <strong>Welcome to Galaxy</strong>
240        <hr/>
241        It appears that you found this tool from a link outside of Galaxy.
242        If you're not familiar with Galaxy, please consider visiting the
243        <a href="${h.url_for( controller='root' )}" target="_top">welcome page</a>.
244        To learn more about what Galaxy is and what it can do for you, please visit
245        the <a href="$add_frame.wiki_url" target="_top">Galaxy wiki</a>.
246    </div>
247    <br/>
248%endif
249
250<%
251    # Render an error message if a dynamically generated select list is missing a required
252    # index file or entry in the tool_data_table_conf.xml file.
253    message = ""
254    params_with_missing_data_table_entry = tool.params_with_missing_data_table_entry
255    params_with_missing_index_file = tool.params_with_missing_index_file
256    if params_with_missing_data_table_entry:
257        param = params_with_missing_data_table_entry[0]
258        message += "Data table named '%s' is required by tool but not configured.  " % param.options.missing_tool_data_table_name
259    if tool.params_with_missing_index_file:
260        param = params_with_missing_index_file[0]
261        message += "Index file named '%s' is required by tool but not available.  " % param.options.missing_index_file
262
263    # Handle calculating the redirect url for the special case where we have nginx proxy
264    # upload and need to do url_for on the redirect portion of the tool action.
265    try:
266        tool_url = h.url_for(tool.action)
267    except AttributeError:
268        assert len(tool.action) == 2
269        tool_url = tool.action[0] + h.url_for(tool.action[1])
270%>
271%if message:
272    <div class="errormessage">${message}</div>
273    <br/>
274%endif
275<div class="toolForm" id="${tool.id}">
276    %if tool.has_multiple_pages:
277        <div class="toolFormTitle">${tool.name} (step ${tool_state.page+1} of ${tool.npages})</div>
278    %else:
279        <div class="toolFormTitle">${tool.name} (version ${tool.version})</div>
280    %endif
281    <div class="toolFormBody">
282        <form id="tool_form" name="tool_form" action="${tool_url}" enctype="${tool.enctype}" target="${tool.target}" method="${tool.method}">
283            <input type="hidden" name="tool_id" value="${tool.id}">
284            <input type="hidden" name="tool_state" value="${util.object_to_string( tool_state.encode( tool, app ) )}">
285            %if tool.display_by_page[tool_state.page]:
286                ${trans.fill_template_string( tool.display_by_page[tool_state.page], context=tool.get_param_html_map( trans, tool_state.page, tool_state.inputs ) )}
287                <input type="submit" class="primary-button" name="runtool_btn" value="Execute">
288            %else:
289                ${do_inputs( tool.inputs_by_page[ tool_state.page ], tool_state.inputs, errors, "" )}
290                <div class="form-row">
291                    %if tool_state.page == tool.last_page:
292                        <input type="submit" class="primary-button" name="runtool_btn" value="Execute">
293                    %else:
294                        <input type="submit" class="primary-button" name="runtool_btn" value="Next step">
295                    %endif
296                </div>
297            %endif
298        </form>
299    </div>
300</div>
301%if tool.help:
302    <div class="toolHelp">
303        <div class="toolHelpBody">
304            <%
305                if tool.has_multiple_pages:
306                    tool_help = tool.help_by_page[tool_state.page]
307                else:
308                    tool_help = tool.help
309
310                # Convert to unicode to display non-ascii characters.
311                if type( tool_help ) is not unicode:
312                    tool_help = unicode( tool_help, 'utf-8')
313            %>
314            ${tool_help}
315        </div>
316    </div>
317%endif