PageRenderTime 28ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

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