/templates/display_base.mako

https://bitbucket.org/cistrome/cistrome-harvard/ · Mako · 370 lines · 304 code · 43 blank · 23 comment · 15 complexity · e0fdf4a0b2b4074fb15cbeaeb2fef4a0 MD5 · raw file

  1. <%!
  2. def inherit( context ):
  3. if context.get('no_panels'):
  4. return '/base.mako'
  5. else:
  6. return '/webapps/galaxy/base_panels.mako'
  7. from galaxy.model import History, StoredWorkflow, Page
  8. from galaxy.web.framework.helpers import iff
  9. %>
  10. <%inherit file="${inherit( context )}"/>
  11. <%namespace file="/tagging_common.mako" import="render_individual_tagging_element, render_community_tagging_element" />
  12. <%namespace file="/display_common.mako" import="*" />
  13. <%namespace file="webapps/galaxy/history/history_panel.mako" import="history_panel_javascripts" />
  14. ##
  15. ## Functions used by base.mako and base_panels.mako to display content.
  16. ##
  17. <%def name="title()">
  18. Galaxy / Cistrome | ${iff( item.published, "Published ", iff( item.importable , "Accessible ", iff( item.users_shared_with, "Shared ", "Private " ) ) ) + get_class_display_name( item.__class__ )} | ${get_item_name( item ) | h}
  19. </%def>
  20. <%def name="init()">
  21. <%
  22. self.has_left_panel=False
  23. self.has_right_panel=True
  24. self.message_box_visible=False
  25. self.active_view="shared"
  26. self.overlay_visible=False
  27. %>
  28. </%def>
  29. <%def name="javascripts()">
  30. ${parent.javascripts()}
  31. ${h.js( "libs/jquery/jstorage", "libs/jquery/jquery.autocomplete", "libs/jquery/jquery.rating",
  32. "galaxy.autocom_tagging" )}
  33. ${history_panel_javascripts()}
  34. ${h.js( "galaxy.panels", "libs/jquery/jstorage", "libs/jquery/jquery.event.drag", "libs/jquery/jquery.event.hover",
  35. "libs/jquery/jquery.mousewheel", "libs/jquery/jquery-ui", "libs/require", "libs/farbtastic" )}
  36. <script type="text/javascript">
  37. // Handle click on community tag.
  38. function community_tag_click(tag_name, tag_value) {
  39. <% controller_name = get_controller_name( item ) %>
  40. var href = '${h.url_for ( controller='/' + controller_name , action='list_published')}';
  41. href = href + "?f-tags=" + tag_name;
  42. if (tag_value != undefined && tag_value != "") {
  43. href = href + ":" + tag_value;
  44. }
  45. self.location = href;
  46. }
  47. // Map item rating to number of stars to show.
  48. function map_rating_to_num_stars(rating) {
  49. if (rating <= 0)
  50. return 0;
  51. else if (rating > 0 && rating <= 1.5)
  52. return 1;
  53. else if (rating > 1.5 && rating <= 2.5)
  54. return 2;
  55. else if (rating > 2.5 && rating <= 3.5)
  56. return 3;
  57. else if (rating > 3.5 && rating <= 4.5)
  58. return 4;
  59. else if (rating > 4.5)
  60. return 5;
  61. }
  62. // Init. on document load.
  63. $(function() {
  64. // Set links to Galaxy screencasts to open in overlay.
  65. $(this).find("a[href^='http://screencast.g2.bx.psu.edu/']").each( function() {
  66. $(this).click( function() {
  67. var href = $(this).attr('href');
  68. show_in_overlay(
  69. {
  70. url: href,
  71. width: 640,
  72. height: 480,
  73. scroll: 'no'
  74. }
  75. );
  76. return false;
  77. });
  78. });
  79. // Init history boxes.
  80. //init_history_items( $("div.historyItemWrapper"), false, "nochanges" );
  81. // Init user item rating.
  82. $('.user_rating_star').rating({
  83. callback: function(rating, link) {
  84. $.ajax({
  85. type: "GET",
  86. url: "${h.url_for ( controller='/' + controller_name , action='rate_async' )}",
  87. data: { id : "${trans.security.encode_id( item.id )}", rating : rating },
  88. dataType: 'json',
  89. error: function() { alert( "Rating submission failed" ); },
  90. success: function( community_data ) {
  91. $('#rating_feedback').show();
  92. $('#num_ratings').text(Math.round(community_data[1]*10)/10);
  93. $('#ave_rating').text(community_data[0]);
  94. $('.community_rating_star').rating('readOnly', false);
  95. $('.community_rating_star').rating('select', map_rating_to_num_stars(community_data[0])-1);
  96. $('.community_rating_star').rating('readOnly', true);
  97. }
  98. });
  99. },
  100. required: true // Hide cancel button.
  101. });
  102. });
  103. </script>
  104. </%def>
  105. <%def name="stylesheets()">
  106. ${parent.stylesheets()}
  107. ${h.css( "autocomplete_tagging", "embed_item", "jquery.rating" )}
  108. ${h.css( "autocomplete_tagging", "trackster", "library",
  109. "jquery-ui/smoothness/jquery-ui" )}
  110. <style type="text/css">
  111. .page-body {
  112. padding: 10px;
  113. ## float: left;
  114. ## width: 65%;
  115. }
  116. .page-meta {
  117. float: right;
  118. width: 27%;
  119. padding: 0.5em;
  120. margin: 0.25em;
  121. vertical-align: text-top;
  122. border: 2px solid #DDDDDD;
  123. border-top: 4px solid #DDDDDD;
  124. }
  125. ## Make sure that history items and workflow steps do not get too long.
  126. .historyItemContainer, .toolForm {
  127. max-width: 500px;
  128. }
  129. ## Space out tool forms in workflows.
  130. div.toolForm{
  131. margin-top: 10px;
  132. margin-bottom: 10px;
  133. }
  134. ## Add border to history item container.
  135. .historyItemContainer {
  136. padding-right: 3px;
  137. border-right-style: solid;
  138. border-right-color: #66AA66;
  139. }
  140. </style>
  141. </%def>
  142. <%def name="render_item_links( item )">
  143. ## Override.
  144. </%def>
  145. <%def name="render_item_header( item )">
  146. <h3>Galaxy / Cistrome ${get_class_display_name( item.__class__ )} '${get_item_name( item )| h}'</h3>
  147. %if hasattr( item, "annotation") and item.annotation is not None:
  148. <div class="annotation">Annotation: ${item.annotation}</div>
  149. %endif
  150. <hr/>
  151. </%def>
  152. <%def name="render_item( item, item_data=None )">
  153. ## Override.
  154. </%def>
  155. ## For base.mako
  156. <%def name="body()">
  157. ${self.render_content()}
  158. </%def>
  159. ## For base_panels.mako
  160. <%def name="center_panel()">
  161. ${self.render_content()}
  162. </%def>
  163. ##
  164. ## Render page content. Pages that inherit this page should override render_item_links() and render_item()
  165. ##
  166. <%def name="render_content()">
  167. ## Get URL to other published items owned by user that owns this item.
  168. <%
  169. ##TODO: is there a better way to create this URL? Can't use 'f-username' as a key b/c it's not a valid identifier.
  170. controller_name = get_controller_name( item )
  171. item_plural = get_item_plural( item )
  172. href_to_all_items = h.url_for( controller='/' + controller_name, action='list_published')
  173. href_to_user_items = h.url_for( controller='/' + controller_name, action='list_published', xxx=item.user.username)
  174. href_to_user_items = href_to_user_items.replace( 'xxx', 'f-username')
  175. %>
  176. <div class="unified-panel-header" unselectable="on">
  177. <div class="unified-panel-header-inner">
  178. %if item.published:
  179. <a href="${href_to_all_items}">Published ${item_plural}</a> |
  180. <a href="${href_to_user_items}">${item.user.username}</a>
  181. %elif item.importable:
  182. Accessible ${get_class_display_name( item.__class__ )}
  183. %elif item.users_shared_with:
  184. Shared ${get_class_display_name( item.__class__ )}
  185. %else:
  186. Private ${get_class_display_name( item.__class__ )}
  187. %endif
  188. | ${get_item_name( item )}
  189. <div style="float: right">
  190. ${self.render_item_links( item )}
  191. </div>
  192. </div>
  193. </div>
  194. <div class="unified-panel-body">
  195. <div style="overflow: auto; height: 100%;">
  196. <div class="page-body">
  197. <div>
  198. ${self.render_item_header( item )}
  199. </div>
  200. ${self.render_item( item, item_data )}
  201. </div>
  202. </div>
  203. </div>
  204. </%def>
  205. <%def name="right_panel()">
  206. <%
  207. ## FIXME: duplicated from above for now
  208. controller_name = get_controller_name( item )
  209. item_plural = get_item_plural( item )
  210. href_to_all_items = h.url_for( controller='/' + controller_name, action='list_published')
  211. href_to_user_items = h.url_for( controller='/' + controller_name, action='list_published', xxx=item.user.username)
  212. href_to_user_items = href_to_user_items.replace( 'xxx', 'f-username')
  213. %>
  214. <div class="unified-panel-header" unselectable="on">
  215. <div class="unified-panel-header-inner">
  216. About this ${get_class_display_name( item.__class__ )}
  217. </div>
  218. </div>
  219. <div class="unified-panel-body">
  220. <div style="overflow: auto; height: 100%;">
  221. <div style="padding: 10px;">
  222. <div style="float: right;"><img src="https://secure.gravatar.com/avatar/${h.md5(item.user.email)}?d=identicon"></div>
  223. <h4>Author</h4>
  224. <p>${item.user.username | h}</p>
  225. ## Related items.
  226. <h4>Related ${item_plural}</h4>
  227. <p>
  228. <a href="${href_to_all_items}">All published ${item_plural.lower()}</a><br>
  229. <a href="${href_to_user_items}">Published ${item_plural.lower()} by ${item.user.username | h}</a>
  230. ## Rating.
  231. <h4>Rating</h4>
  232. <%
  233. label = "ratings"
  234. if num_ratings == 1:
  235. label = "rating"
  236. %>
  237. <div style="padding-bottom: 0.75em; float: left">
  238. Community<br>
  239. <span style="font-size:80%">
  240. (<span id="num_ratings">${num_ratings}</span> ${label},
  241. <span id="ave_rating">${"%.1f" % ave_item_rating}</span> average)
  242. <span>
  243. </div>
  244. <div style="float: right">
  245. <input name="star1" type="radio" class="community_rating_star star" disabled="disabled" value="1"
  246. %if ave_item_rating > 0 and ave_item_rating <= 1.5:
  247. checked="checked"
  248. %endif
  249. />
  250. <input name="star1" type="radio" class="community_rating_star star" disabled="disabled" value="2"
  251. %if ave_item_rating > 1.5 and ave_item_rating <= 2.5:
  252. checked="checked"
  253. %endif
  254. />
  255. <input name="star1" type="radio" class="community_rating_star star" disabled="disabled" value="3"
  256. %if ave_item_rating > 2.5 and ave_item_rating <= 3.5:
  257. checked="checked"
  258. %endif
  259. />
  260. <input name="star1" type="radio" class="community_rating_star star" disabled="disabled" value="4"
  261. %if ave_item_rating > 3.5 and ave_item_rating <= 4.5:
  262. checked="checked"
  263. %endif
  264. />
  265. <input name="star1" type="radio" class="community_rating_star star" disabled="disabled" value="5"
  266. %if ave_item_rating > 4.5:
  267. checked="checked"
  268. %endif
  269. />
  270. </div>
  271. <div style="clear: both;"></div>
  272. %if trans.get_user():
  273. <div style="float: left">
  274. Yours<br><span id="rating_feedback" style="font-size:80%; display: none">(thanks!)</span>
  275. </div>
  276. <div style="float: right">
  277. <input name="star2" type="radio" class="user_rating_star" value="1"
  278. %if user_item_rating == 1:
  279. checked="checked"
  280. %endif
  281. />
  282. <input name="star2" type="radio" class="user_rating_star" value="2"
  283. %if user_item_rating == 2:
  284. checked="checked"
  285. %endif
  286. />
  287. <input name="star2" type="radio" class="user_rating_star" value="3"
  288. %if user_item_rating == 3:
  289. checked="checked"
  290. %endif
  291. />
  292. <input name="star2" type="radio" class="user_rating_star" value="4"
  293. %if user_item_rating == 4:
  294. checked="checked"
  295. %endif
  296. />
  297. <input name="star2" type="radio" class="user_rating_star" value="5"
  298. %if user_item_rating == 5:
  299. checked="checked"
  300. %endif
  301. />
  302. </div>
  303. %endif
  304. <div style="clear: both;"></div>
  305. ## Tags.
  306. <h4>Tags</h4>
  307. <p>
  308. ## Community tags.
  309. <div>
  310. Community:
  311. ${render_community_tagging_element( tagged_item=item, tag_click_fn='community_tag_click', use_toggle_link=False )}
  312. %if len ( item.tags ) == 0:
  313. none
  314. %endif
  315. </div>
  316. ## Individual tags.
  317. %if trans.get_user():
  318. <p>
  319. <div>
  320. Yours:
  321. ${render_individual_tagging_element( user=trans.get_user(), tagged_item=item, elt_context='view.mako', use_toggle_link=False, tag_click_fn='community_tag_click' )}
  322. </div>
  323. %endif
  324. </div>
  325. </div>
  326. </div>
  327. </%def>