/templates/requests/common/common.mako

https://bitbucket.org/cistrome/cistrome-harvard/ · Mako · 722 lines · 683 code · 15 blank · 24 comment · 11 complexity · 76197468d7204c1fc9697163bd656c98 MD5 · raw file

  1. <%namespace file="/requests/common/sample_state.mako" import="render_sample_state" />
  2. <%namespace file="/message.mako" import="render_msg" />
  3. <%def name="javascripts()">
  4. ${self.common_javascripts()}
  5. </%def>
  6. <%def name="common_javascripts()">
  7. <script type="text/javascript">
  8. function showContent(vThis)
  9. {
  10. // http://www.javascriptjunkie.com
  11. // alert(vSibling.className + " " + vDef_Key);
  12. vParent = vThis.parentNode;
  13. vSibling = vParent.nextSibling;
  14. while (vSibling.nodeType==3) {
  15. // Fix for Mozilla/FireFox Empty Space becomes a TextNode or Something
  16. vSibling = vSibling.nextSibling;
  17. };
  18. if(vSibling.style.display == "none")
  19. {
  20. vThis.src="/static/images/silk/resultset_bottom.png";
  21. vThis.alt = "Hide";
  22. vSibling.style.display = "block";
  23. } else {
  24. vSibling.style.display = "none";
  25. vThis.src="/static/images/silk/resultset_next.png";
  26. vThis.alt = "Show";
  27. }
  28. return;
  29. }
  30. $(document).ready(function(){
  31. //hide the all of the element with class msg_body
  32. $(".msg_body").hide();
  33. //toggle the component with class msg_body
  34. $(".msg_head").click(function(){
  35. $(this).next(".msg_body").slideToggle(0);
  36. });
  37. });
  38. function checkAllFields()
  39. {
  40. var chkAll = document.getElementById('checkAll');
  41. var checks = document.getElementsByTagName('input');
  42. var boxLength = checks.length;
  43. var allChecked = false;
  44. var totalChecked = 0;
  45. if ( chkAll.checked == true )
  46. {
  47. for ( i=0; i < boxLength; i++ )
  48. {
  49. if ( checks[i].name.indexOf( 'select_sample_' ) != -1)
  50. {
  51. checks[i].checked = true;
  52. }
  53. }
  54. }
  55. else
  56. {
  57. for ( i=0; i < boxLength; i++ )
  58. {
  59. if ( checks[i].name.indexOf( 'select_sample_' ) != -1)
  60. {
  61. checks[i].checked = false
  62. }
  63. }
  64. }
  65. }
  66. // Sample State Updater
  67. //
  68. // Looks for changes in sample states using an async request. Keeps
  69. // calling itself (via setTimeout) until all samples are in a terminal
  70. // state.
  71. var sample_state_updater = function ( sample_states ) {
  72. // Check if there are any items left to track
  73. var empty = true;
  74. for ( i in sample_states ) {
  75. empty = false;
  76. break;
  77. }
  78. if ( ! empty ) {
  79. setTimeout( function() { sample_state_updater_callback( sample_states ) }, 3000 );
  80. }
  81. };
  82. var sample_state_updater_callback = function ( sample_states ) {
  83. // Build request data
  84. var ids = []
  85. var states = []
  86. $.each( sample_states, function ( id, state ) {
  87. ids.push( id );
  88. states.push( state );
  89. });
  90. // Make ajax call
  91. $.ajax( {
  92. type: "POST",
  93. url: "${h.url_for( controller='requests_common', action='sample_state_updates' )}",
  94. dataType: "json",
  95. data: { ids: ids.join( "," ), states: states.join( "," ) },
  96. success : function ( data ) {
  97. $.each( data, function( id, val ) {
  98. // Replace sample state HTML
  99. var cell1 = $("#sampleState-" + id);
  100. cell1.html( val.html_state );
  101. sample_states[ parseInt( id ) ] = val.state;
  102. });
  103. sample_state_updater( sample_states );
  104. },
  105. error: function() {
  106. // Just retry, like the old method, should try to be smarter
  107. sample_state_updater( sample_states );
  108. }
  109. });
  110. };
  111. // Sample Datasets Updater
  112. //
  113. // Looks for changes in the number sample datasets using an async request. Keeps
  114. // calling itself (via setTimeout) until all samples are in a terminal
  115. // state.
  116. var sample_datasets_updater = function ( sample_datasets ) {
  117. // Check if there are any items left to track
  118. var empty = true;
  119. for ( i in sample_datasets ) {
  120. empty = false;
  121. break;
  122. }
  123. if ( ! empty ) {
  124. setTimeout( function() { sample_datasets_updater_callback( sample_datasets ) }, 3000 );
  125. }
  126. };
  127. var sample_datasets_updater_callback = function ( sample_datasets ) {
  128. // Build request data
  129. var ids = []
  130. var datasets = []
  131. $.each( sample_datasets, function ( id, num_of_datasets ) {
  132. ids.push( id );
  133. datasets.push( num_of_datasets );
  134. });
  135. // Make ajax call
  136. $.ajax( {
  137. type: "POST",
  138. url: "${h.url_for( controller='requests_common', action='sample_datasets_updates' )}",
  139. dataType: "json",
  140. data: { ids: ids.join( "," ), datasets: datasets.join( "," ) },
  141. success : function ( data ) {
  142. $.each( data, function( id, val ) {
  143. // Replace sample datasets HTML
  144. var cell2 = $("#sampleDatasets-" + id);
  145. cell2.html( val.html_datasets );
  146. sample_datasets[ parseInt( id ) ] = val.datasets;
  147. });
  148. sample_datasets_updater( sample_datasets );
  149. },
  150. error: function() {
  151. // Just retry, like the old method, should try to be smarter
  152. sample_datasets_updater( sample_datasets );
  153. }
  154. });
  155. };
  156. // Sample Dataset Transfer Status Updater
  157. //
  158. // It is used to update the transfer status on Manage Datasets page for a sample
  159. // of a sequencing request
  160. // Looks for changes in sample dataset transfer status using an async request. Keeps
  161. // calling itself (via setTimeout) until transfer_status is complete
  162. var dataset_transfer_status_updater = function ( dataset_transfer_status_list ) {
  163. // Check if there are any items left to track
  164. var empty = true;
  165. for ( i in dataset_transfer_status_list ) {
  166. empty = false;
  167. break;
  168. }
  169. if ( ! empty ) {
  170. setTimeout( function() { dataset_transfer_status_updater_callback( dataset_transfer_status_list ) }, 3000 );
  171. }
  172. };
  173. var dataset_transfer_status_updater_callback = function ( dataset_transfer_status_list ) {
  174. // Build request data
  175. var ids = []
  176. var transfer_status_list = []
  177. $.each( dataset_transfer_status_list, function ( id, dataset_transfer_status ) {
  178. ids.push( id );
  179. transfer_status_list.push( dataset_transfer_status );
  180. });
  181. // Make ajax call
  182. $.ajax( {
  183. type: "POST",
  184. url: "${h.url_for( controller='requests_common', action='dataset_transfer_status_updates' )}",
  185. dataType: "json",
  186. data: { ids: ids.join( "," ), transfer_status_list: transfer_status_list.join( "," ) },
  187. success : function ( data ) {
  188. $.each( data, function( id, val ) {
  189. // Replace HTML
  190. var cell1 = $("#datasetTransferStatus-" + id);
  191. cell1.html( val.html_status );
  192. dataset_transfer_status_list[ id ] = val.status;
  193. });
  194. dataset_transfer_status_updater( dataset_transfer_status_list );
  195. },
  196. error: function() {
  197. // Just retry, like the old method, should try to be smarter
  198. dataset_transfer_status_updater( dataset_transfer_status_list );
  199. }
  200. });
  201. };
  202. </script>
  203. </%def>
  204. <%def name="transfer_status_updater()">
  205. <%
  206. can_update = False
  207. if query.count():
  208. # Get the first sample dataset to get to the parent sample
  209. sample_dataset = query[0]
  210. sample = sample_dataset.sample
  211. is_complete = sample.request.is_complete
  212. is_submitted = sample.request.is_submitted
  213. can_update = is_complete or is_submitted and sample.untransferred_dataset_files
  214. %>
  215. %if can_update:
  216. <script type="text/javascript">
  217. // Sample dataset transfer status updater
  218. dataset_transfer_status_updater( {${ ",".join( [ '"%s" : "%s"' % ( trans.security.encode_id( sd.id ), sd.status ) for sd in query ] ) }});
  219. </script>
  220. %endif
  221. </%def>
  222. <%def name="render_editable_sample_row( cntrller, request, sample, sample_widget_index, sample_widget, encoded_selected_sample_ids, adding_new_samples=False )">
  223. <%
  224. trans.sa_session.refresh( request )
  225. is_admin = cntrller == 'requests_admin' and trans.user_is_admin()
  226. is_rejected = request.is_rejected
  227. is_complete = request.is_complete
  228. is_submitted = request.is_submitted
  229. is_unsubmitted = request.is_unsubmitted
  230. if sample:
  231. can_delete_samples = not adding_new_samples and request.samples and ( ( is_admin and not is_complete ) or is_unsubmitted )
  232. display_checkboxes = not adding_new_samples and ( is_complete or is_rejected or is_submitted )
  233. display_datasets = request.samples and ( is_complete or is_submitted )
  234. else:
  235. can_delete_samples = False
  236. display_checkboxes = False
  237. display_datasets = False
  238. display_bar_code = request.samples and ( is_complete or is_rejected or is_submitted )
  239. %>
  240. <%
  241. if display_checkboxes and trans.security.encode_id( sample.id ) in encoded_selected_sample_ids:
  242. checked_str = "checked"
  243. else:
  244. checked_str = ""
  245. %>
  246. %if display_checkboxes:
  247. <td valign="top"><input type="checkbox" name=select_sample_${sample.id} id="sample_checkbox" value="true" ${checked_str}/><input type="hidden" name=select_sample_${sample.id} id="sample_checkbox" value="true"/></td>
  248. %endif
  249. <td valign="top">
  250. <input type="text" name="sample_${sample_widget_index}_name" value="${sample_widget['name']}" size="10"/>
  251. <div class="toolParamHelp" style="clear: both;">
  252. <i>${' (required)' }</i>
  253. </div>
  254. </td>
  255. %if display_bar_code:
  256. <td valign="top">
  257. %if is_admin and is_submitted:
  258. <input type="text" name="sample_${sample_widget_index}_bar_code" value="${sample_widget['bar_code']}" size="10"/>
  259. %else:
  260. ${sample_widget['bar_code']}
  261. <input type="hidden" name="sample_${sample_widget_index}_bar_code" value="${sample_widget['bar_code']}"/>
  262. %endif
  263. </td>
  264. %endif
  265. %if sample:
  266. %if is_unsubmitted:
  267. <td>Unsubmitted</td>
  268. %else:
  269. <td valign="top"><a href="${h.url_for( controller='requests_common', action='view_sample_history', cntrller=cntrller, sample_id=trans.security.encode_id( sample.id ) )}">${sample.state.name}</a></td>
  270. %endif
  271. %else:
  272. <td></td>
  273. %endif
  274. <td valign="top">${sample_widget['library_select_field'].get_html()}</td>
  275. <td valign="top">${sample_widget['folder_select_field'].get_html()}</td>
  276. <td valign="top">${sample_widget['history_select_field'].get_html()}</td>
  277. <td valign="top">
  278. ${sample_widget['workflow_select_field'][0].get_html()}
  279. %if len(sample_widget['workflow_select_field']) > 1:
  280. <br/>
  281. ${'<br/>'.join(["%s:<br/>%s" % (w_l, w_i.get_html()) for w_l, w_i in sample_widget['workflow_select_field'][1:]])}
  282. %endif
  283. </td>
  284. %if display_datasets:
  285. <td valign="top">
  286. ## An admin can select the datasets to transfer, while a non-admin can only view what has been selected
  287. %if is_admin:
  288. ## This link will direct the admin to a page allowing them to manage datasets.
  289. <a id="sampleDatasets-${sample.id}" href="${h.url_for( controller='requests_admin', action='manage_datasets', cntrller=cntrller, sample_id=trans.security.encode_id( sample.id ) )}">${len( sample.datasets )}</a>
  290. %elif sample.datasets:
  291. ## Since this is a regular user, only display a link if there is at least 1
  292. ## selected dataset for the sample.
  293. <a id="sampleDatasets-${sample.id}" href="${h.url_for( controller='requests_common', action='view_sample_datasets', cntrller=cntrller, sample_id=trans.security.encode_id( sample.id ) )}">${len( sample.datasets )}</a>
  294. %else:
  295. ## Since this is a regular user, do not display a link if there are no datasets.
  296. <a id="sampleDatasets-${sample.id}">${len( sample.datasets )}</a>
  297. %endif
  298. </td>
  299. %endif
  300. %if can_delete_samples:
  301. ## Delete button
  302. <td valign="top"><a class="action-button" confirm="This sample is not recoverable after deletion. Click Ok to delete." href="${h.url_for( controller='requests_common', action='delete_sample', cntrller=cntrller, request_id=trans.security.encode_id( request.id ), sample_id=sample_widget_index )}"><img src="${h.url_for('/static/images/delete_icon.png')}" style="cursor:pointer;"/></a></td>
  303. %endif
  304. </%def>
  305. <%def name="render_samples_grid( cntrller, request, displayable_sample_widgets, action, adding_new_samples=False, encoded_selected_sample_ids=[], render_buttons=False, grid_header='<h3>Samples</h3>' )">
  306. ## Displays the "Samples" grid
  307. <%
  308. trans.sa_session.refresh( request )
  309. is_admin = cntrller == 'requests_admin' and trans.user_is_admin()
  310. is_complete = request.is_complete
  311. is_rejected = request.is_rejected
  312. is_submitted = request.is_submitted
  313. is_unsubmitted = request.is_unsubmitted
  314. if is_admin:
  315. can_add_samples = not is_complete
  316. else:
  317. can_add_samples = is_unsubmitted
  318. can_delete_samples = not adding_new_samples and request.samples and ( ( is_admin and not is_complete ) or is_unsubmitted )
  319. can_edit_samples = request.samples and ( is_admin or not is_complete )
  320. can_select_datasets = is_admin and displayable_sample_widgets and ( is_submitted or is_complete )
  321. can_transfer_datasets = is_admin and request.samples and not request.is_rejected
  322. display_checkboxes = not adding_new_samples and ( is_complete or is_rejected or is_submitted )
  323. display_bar_code = request.samples and ( is_complete or is_rejected or is_submitted )
  324. display_datasets = request.samples and ( is_complete or is_submitted )
  325. %>
  326. ${grid_header}
  327. %if render_buttons and ( can_add_samples or can_edit_samples ):
  328. <ul class="manage-table-actions">
  329. %if can_add_samples:
  330. <li><a class="action-button" href="${h.url_for( controller='requests_common', action='add_sample', cntrller=cntrller, request_id=trans.security.encode_id( request.id ), add_sample_button='Add sample' )}">Add sample</a></li>
  331. %endif
  332. %if can_edit_samples:
  333. <li><a class="action-button" href="${h.url_for( controller='requests_common', action='edit_samples', cntrller=cntrller, id=trans.security.encode_id( request.id ) )}">Edit samples</a></li>
  334. %endif
  335. </ul>
  336. %endif
  337. <table class="grid">
  338. <thead>
  339. <tr>
  340. %if display_checkboxes:
  341. <th><input type="checkbox" id="checkAll" name=select_all_samples_checkbox value="true" onclick='checkAllFields(1);'/><input type="hidden" name=select_all_samples_checkbox value="true"/></th>
  342. %endif
  343. <th>Name</th>
  344. %if display_bar_code:
  345. <th>Barcode</th>
  346. %endif
  347. <th>State</th>
  348. <th>Data Library</th>
  349. <th>Folder</th>
  350. <th>History</th>
  351. <th>Workflow</th>
  352. %if display_datasets:
  353. <th>Run Datasets</th>
  354. %endif
  355. <th>
  356. %if can_delete_samples:
  357. Delete
  358. %endif
  359. </th>
  360. </tr>
  361. <thead>
  362. <tbody>
  363. <% trans.sa_session.refresh( request ) %>
  364. ## displayable_sample_widgets is a dictionary whose keys are:
  365. ## id, name, bar_code, library, folder, field_values, library_select_field, folder_select_field
  366. ## A displayable_sample_widget will have an id == None if the widget's associated sample has not
  367. ## yet been saved (i.e., the use clicked the "Add sample" button but has not yet clicked the
  368. ## "Save" button.
  369. %for sample_widget_index, sample_widget in enumerate( displayable_sample_widgets ):
  370. <%
  371. sample_widget_name = sample_widget[ 'name' ]
  372. sample_widget_bar_code = sample_widget[ 'bar_code' ]
  373. sample_widget_library = sample_widget[ 'library' ]
  374. sample_widget_history = sample_widget[ 'history' ]
  375. sample_widget_workflow = sample_widget[ 'workflow' ]
  376. if sample_widget_library:
  377. if cntrller == 'requests':
  378. library_cntrller = 'library'
  379. elif is_admin:
  380. library_cntrller = 'library_admin'
  381. else:
  382. library_cntrller = None
  383. sample_widget_folder = sample_widget[ 'folder' ]
  384. try:
  385. sample = request.samples[ sample_widget_index ]
  386. except:
  387. sample = None
  388. %>
  389. %if not adding_new_samples:
  390. <tr>${render_editable_sample_row( cntrller, request, sample, sample_widget_index, sample_widget, encoded_selected_sample_ids, adding_new_samples=False )}</tr>
  391. %elif sample:
  392. <tr>
  393. <td>
  394. %if sample.state and ( can_select_datasets or can_transfer_datasets ):
  395. ## A sample will have a state only after the request has been submitted.
  396. <%
  397. encoded_id = trans.security.encode_id( sample.id )
  398. transferred_dataset_files = sample.transferred_dataset_files
  399. if not transferred_dataset_files:
  400. transferred_dataset_files = []
  401. %>
  402. <div style="float: left; margin-left: 2px;" class="menubutton split popup" id="sample-${sample.id}-popup">
  403. <a class="view-info" href="${h.url_for( controller='requests_common', action='view_sample', cntrller=cntrller, id=trans.security.encode_id( sample.id ) )}">${sample.name}</a>
  404. </div>
  405. <div popupmenu="sample-${sample.id}-popup">
  406. %if can_select_datasets:
  407. %for external_service in sample.request.type.get_external_services_for_manual_data_transfer( trans ):
  408. <%
  409. menu_item_label = "Select datasets to transfer using %s" % external_service.name
  410. %>
  411. <li><a class="action-button" href="${h.url_for( controller='requests_admin', action='select_datasets_to_transfer', external_service_id=trans.security.encode_id( external_service.id ), request_id=trans.security.encode_id( request.id ), sample_id=trans.security.encode_id( sample.id ) )}">${menu_item_label}</a></li>
  412. %endfor
  413. %endif
  414. %if sample.datasets and len( sample.datasets ) > len( transferred_dataset_files ) and sample.library and sample.folder:
  415. <li><a class="action-button" href="${h.url_for( controller='requests_admin', action='manage_datasets', sample_id=trans.security.encode_id( sample.id ) )}">Manage selected datasets</a></li>
  416. %elif sample.datasets and len(sample.datasets ) == len( transferred_dataset_files ):
  417. <li><a class="action-button" href="${h.url_for( controller='requests_common', action='view_sample_datasets', cntrller=cntrller, sample_id=trans.security.encode_id( sample.id ), transfer_status=trans.model.SampleDataset.transfer_status.COMPLETE )}">View transferred datasets</a></li>
  418. %endif
  419. </div>
  420. %else:
  421. ${sample_widget_name}
  422. %endif
  423. </td>
  424. %if display_bar_code:
  425. <td>${sample_widget_bar_code}</td>
  426. %endif
  427. %if is_unsubmitted:
  428. <td>Unsubmitted</td>
  429. %else:
  430. <td><a id="sampleState-${sample.id}" href="${h.url_for( controller='requests_common', action='view_sample_history', cntrller=cntrller, sample_id=trans.security.encode_id( sample.id ) )}">${render_sample_state( sample )}</a></td>
  431. %endif
  432. %if sample_widget_library and library_cntrller is not None:
  433. <td><a href="${h.url_for( controller='library_common', action='browse_library', cntrller=library_cntrller, id=trans.security.encode_id( sample_widget_library.id ) )}">${sample_widget_library.name}</a></td>
  434. %else:
  435. <td></td>
  436. %endif
  437. %if sample_widget_folder:
  438. <td>${sample_widget_folder.name}</td>
  439. %else:
  440. <td></td>
  441. %endif
  442. %if sample_widget_history:
  443. %if trans.user == sample_widget_history.user:
  444. <td>
  445. <a target='_parent' href="${h.url_for( controller='history', action='list', operation="Switch", id=trans.security.encode_id(sample_widget_history.id), use_panels=False )}">
  446. ${sample_widget_history.name}
  447. </a>
  448. </td>
  449. %else:
  450. <td>${sample_widget_history.name}</td>
  451. %endif
  452. %else:
  453. <td></td>
  454. %endif
  455. %if sample_widget_workflow:
  456. %if trans.user == sample_widget_workflow.stored_workflow.user:
  457. <td>
  458. <a target='_parent' href="${h.url_for( controller='workflow', action='editor', id=trans.security.encode_id(sample_widget_workflow.stored_workflow.id) )}">
  459. ${sample_widget_workflow.name}
  460. </a>
  461. </td>
  462. %else:
  463. <td>${sample_widget_workflow.name}</td>
  464. %endif
  465. %else:
  466. <td></td>
  467. %endif
  468. %if is_submitted or is_complete:
  469. <td>
  470. ## An admin can select the datasets to transfer, while a non-admin can only view what has been selected
  471. %if sample.library and is_admin:
  472. ## This link will direct the admin to a page allowing them to manage datasets.
  473. <a id="sampleDatasets-${sample.id}" href="${h.url_for( controller='requests_admin', action='manage_datasets', cntrller=cntrller, sample_id=trans.security.encode_id( sample.id ) )}">${len( sample.datasets )}</a>
  474. %elif sample.library and sample.datasets:
  475. ## Since this is a regular user, only display a link if there is at least 1
  476. ## selected dataset for the sample.
  477. <a id="sampleDatasets-${sample.id}" href="${h.url_for( controller='requests_common', action='view_sample_datasets', cntrller=cntrller, sample_id=trans.security.encode_id( sample.id ) )}">${len( sample.datasets )}</a>
  478. %else:
  479. ## Since this is a regular user, do not display a link if there are no datasets.
  480. <a id="sampleDatasets-${sample.id}">${len( sample.datasets )}</a>
  481. %endif
  482. </td>
  483. %endif
  484. </tr>
  485. %else:
  486. ## The Add sample button was clicked for this sample_widget
  487. <tr>${render_editable_sample_row( cntrller, request, None, sample_widget_index, sample_widget, encoded_selected_sample_ids, adding_new_samples=True )}</tr>
  488. %endif
  489. %endfor
  490. </tbody>
  491. </table>
  492. </%def>
  493. <%def name="render_sample_form( index, sample_name, sample_values, fields_dict, display_only )">
  494. <tr>
  495. <td>${sample_name}</td>
  496. %for field_index, field in fields_dict.items():
  497. <%
  498. field_type = field[ 'type' ]
  499. field_name = field[ 'name' ]
  500. field_value = sample_values[ field_name ]
  501. %>
  502. <td>
  503. %if display_only:
  504. %if field_value:
  505. %if field_type == 'WorkflowField':
  506. %if str( field_value ) != 'none':
  507. <% workflow = trans.sa_session.query( trans.app.model.StoredWorkflow ).get( int( field_value ) ) %>
  508. <a href="${h.url_for( controller='workflow', action='run', id=trans.security.encode_id( workflow.id ) )}">${workflow.name}</a>
  509. %endif
  510. %else:
  511. ${field_value}
  512. %endif
  513. %else:
  514. <i>None</i>
  515. %endif
  516. %else:
  517. %if field_type == 'TextField':
  518. <input type="text" name="sample_${index}_field_${field_index}" value="${field_value}" size="7"/>
  519. %elif field_type == 'SelectField':
  520. <select name="sample_${index}_field_${field_index}" last_selected_value="2">
  521. %for option_index, option in enumerate(field[ 'selectlist' ]):
  522. %if option == field_value:
  523. <option value="${option}" selected>${option}</option>
  524. %else:
  525. <option value="${option}">${option}</option>
  526. %endif
  527. %endfor
  528. </select>
  529. %elif field_type == 'WorkflowField':
  530. <select name="sample_${index}_field_${field_index}">
  531. %if str( field_value ) == 'none':
  532. <option value="none" selected>Select one</option>
  533. %else:
  534. <option value="none">Select one</option>
  535. %endif
  536. %for option_index, option in enumerate(request.user.stored_workflows):
  537. %if not option.deleted:
  538. %if str( option.id ) == str( field_value ):
  539. <option value="${option.id}" selected>${option.name}</option>
  540. %else:
  541. <option value="${option.id}">${option.name}</option>
  542. %endif
  543. %endif
  544. %endfor
  545. </select>
  546. %elif field_type == 'WorkflowMappingField':
  547. ##DBTODO Make this useful, use form_builder approach to displaying this stuff.
  548. <select name="sample_${index}_field_${field_index}">
  549. %if str( field_value ) == 'none':
  550. <option value="none" selected>Select one</option>
  551. %else:
  552. <option value="none">Select one</option>
  553. %endif
  554. %for option_index, option in enumerate(request.user.stored_workflows):
  555. %if not option.deleted:
  556. %if str( option.id ) == str( field_value ):
  557. <option value="${option.id}" selected>${option.name}</option>
  558. %else:
  559. <option value="${option.id}">${option.name}</option>
  560. %endif
  561. %endif
  562. %endfor
  563. </select>
  564. %elif field_type == 'HistoryField':
  565. <select name="sample_${index}_field_${field_index}">
  566. %if str( field_value ) == 'none':
  567. <option value="none" selected>Select one</option>
  568. %else:
  569. <option value="none">Select one</option>
  570. %endif
  571. %for option_index, option in enumerate(request.user.histories):
  572. %if not option.deleted:
  573. %if str( option.id ) == str( field_value ):
  574. <option value="${option.id}" selected>${option.name}</option>
  575. %else:
  576. <option value="${option.id}">${option.name}</option>
  577. %endif
  578. %endif
  579. %endfor
  580. </select>
  581. %elif field_type == 'CheckboxField':
  582. %if field_value is True:
  583. <input type="checkbox" name="sample_${index}_field_${field_index}" value="Yes" checked="checked"/><input type="hidden" name="sample_${index}_field_${field_index}" value="Yes"/>
  584. %else:
  585. <input type="checkbox" name="sample_${index}_field_${field_index}" value="Yes"/><input type="hidden" name="sample_${index}_field_${field_index}" value="Yes"/>
  586. %endif
  587. %endif
  588. <div class="toolParamHelp" style="clear: both;">
  589. <i>${'('+field['required']+')' }</i>
  590. </div>
  591. %endif
  592. </td>
  593. %endfor
  594. </tr>
  595. </%def>
  596. <%def name="render_request_type_sample_form_grids( grid_index, grid_name, fields_dict, displayable_sample_widgets, show_saved_samples_read_only )">
  597. <%
  598. if not grid_name:
  599. grid_name = "Sample form layout %s" % str( grid_index )
  600. %>
  601. <h4><img src="/static/images/silk/resultset_next.png" alt="Hide" onclick="showContent(this);" style="cursor:pointer;"/> ${grid_name}</h4>
  602. <div style="display:none;">
  603. <table class="grid">
  604. <thead>
  605. <tr>
  606. <th>Name</th>
  607. %for index, field in fields_dict.items():
  608. <th>
  609. <a class="display tooltip" title="${field['helptext']}" >${field['label']}</a>
  610. </th>
  611. %endfor
  612. <th></th>
  613. </tr>
  614. <thead>
  615. <tbody>
  616. <% trans.sa_session.refresh( request ) %>
  617. %for sample_index, sample in enumerate( displayable_sample_widgets ):
  618. <%
  619. if not show_saved_samples_read_only or sample_index >= len( request.samples ):
  620. display_only = False
  621. else:
  622. display_only = True
  623. %>
  624. ${render_sample_form( sample_index, sample['name'], sample['field_values'], fields_dict, display_only )}
  625. %endfor
  626. </tbody>
  627. </table>
  628. </div>
  629. </%def>
  630. <%def name="render_sample_datasets( cntrller, sample, sample_datasets, title )">
  631. ## The list of sample_datasets may not be the same as sample.datasets because it may be
  632. ## filtered by a transfer_status value. The value of title changes based on this filter.
  633. %if sample_datasets:
  634. <%
  635. trans.sa_session.refresh( sample )
  636. is_admin = cntrller == 'requests_admin' and trans.user_is_admin()
  637. is_complete = sample.request.is_complete
  638. is_submitted = sample.request.is_submitted
  639. can_select_datasets = is_admin and ( is_complete or is_submitted )
  640. can_transfer_datasets = is_admin and sample.untransferred_dataset_files
  641. %>
  642. ## The transfer status should update only when the request has been submitted or complete
  643. ## and when the sample has in-progress datasets.
  644. %if ( is_complete or is_submitted ) and sample.inprogress_dataset_files:
  645. <script type="text/javascript">
  646. // Sample dataset transfer status updater
  647. dataset_transfer_status_updater( {${ ",".join( [ '"%s" : "%s"' % ( trans.security.encode_id( sd.id ), sd.status ) for sd in sample_datasets ] ) }});
  648. </script>
  649. %endif
  650. <h3>${title}</h3>
  651. <table class="grid">
  652. <thead>
  653. <tr>
  654. <th>Name</th>
  655. <th>Size</th>
  656. <th>Data library</th>
  657. <th>Folder</th>
  658. <th>Transfer status</th>
  659. </tr>
  660. <thead>
  661. <tbody>
  662. %for dataset in sample_datasets:
  663. <% encoded_id = trans.security.encode_id( dataset.id ) %>
  664. <tr>
  665. <td>
  666. %if is_admin:
  667. <span class="expandLink dataset-${dataset}-click"><span class="rowIcon"></span>
  668. <div style="float: left; margin-left: 2px;" class="menubutton split popup" id="dataset-${dataset.id}-popup">
  669. <a class="dataset-${encoded_id}-click" href="${h.url_for( controller='requests_admin', action='manage_datasets', operation='view', id=trans.security.encode_id( dataset.id ) )}">${dataset.name}</a>
  670. </div>
  671. </span>
  672. <div popupmenu="dataset-${dataset.id}-popup">
  673. %if can_transfer_datasets and dataset in sample.untransferred_dataset_files:
  674. <li><a class="action-button" href="${h.url_for( controller='requests_admin', action='initiate_data_transfer', sample_id=trans.security.encode_id( sample.id ), sample_dataset_id=trans.security.encode_id( dataset.id ) )}">Transfer</a></li>
  675. %endif
  676. </div>
  677. %else:
  678. ${dataset.name}
  679. %endif
  680. </td>
  681. <td>${dataset.size}</td>
  682. <td><a href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( sample.library.id ) )}">${dataset.sample.library.name}</a></td>
  683. <td>${dataset.sample.folder.name}</td>
  684. <td id="datasetTransferStatus-${encoded_id}">${dataset.status}</td>
  685. </tr>
  686. %endfor
  687. </tbody>
  688. </table>
  689. %else:
  690. No datasets for this sample.
  691. %endif
  692. </%def>
  693. <%def name="render_samples_messages( request, is_admin=False, is_submitted=False, message=None, status=None)">
  694. %if request.is_rejected:
  695. <div class='errormessage'>
  696. ${request.last_comment}
  697. </div><br/>
  698. %endif
  699. %if is_admin and is_submitted and request.samples_without_library_destinations:
  700. <div class='infomessage'>
  701. Select a target data library and folder for a sample before selecting it's datasets to transfer from the external service.
  702. </div><br/>
  703. %endif
  704. %if message:
  705. ${render_msg( message, status )}
  706. %endif
  707. </%def>