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