PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/templates/sharing_base.mako

https://bitbucket.org/cistrome/cistrome-harvard/
Mako | 271 lines | 213 code | 40 blank | 18 comment | 9 complexity | e7069dcfeacbbe8e43970bfad56db2e2 MD5 | raw file
  1##
  2## Base template for sharing or publishing an item. Template expects the following parameters:
  3## (a) item - item to be shared.
  4##
  5<%!
  6    def inherit(context):
  7        if context.get('use_panels', False) == True:
  8            if context.get('webapp'):
  9                webapp = context.get('webapp')
 10            else:
 11                webapp = 'galaxy'
 12            return '/webapps/%s/base_panels.mako' % webapp
 13        else:
 14            return '/base.mako'
 15%>
 16<%inherit file="${inherit(context)}"/>
 17
 18<%namespace file="/display_common.mako" import="*" />
 19<%namespace file="/message.mako" import="render_msg" />
 20
 21##
 22## Page methods.
 23##
 24
 25<%def name="init()">
 26<%
 27    self.has_left_panel=False
 28    self.has_right_panel=False
 29    self.message_box_visible=False
 30    self.overlay_visible=False
 31    self.message_box_class=""
 32    self.active_view=""
 33    self.body_class=""
 34%>
 35</%def>
 36
 37<%def name="title()">
 38    Sharing and Publishing ${get_class_display_name( item.__class__ )} '${get_item_name( item )}'
 39</%def>
 40
 41<%def name="javascripts()">
 42    ${parent.javascripts()}
 43    <script type="text/javascript">
 44    $(document).ready( function() {
 45        //
 46        // Set up slug-editing functionality.
 47        //
 48        var on_start = function( text_elt ) {
 49            // Replace URL with URL text.
 50            $('#item-url').hide();
 51            $('#item-url-text').show();
 52            
 53            // Allow only lowercase alphanumeric and '-' characters in slug.
 54            text_elt.keyup(function(){
 55                text_elt.val( $(this).val().replace(/\s+/g,'-').replace(/[^a-zA-Z0-9\-]/g,'').toLowerCase() )
 56            });
 57        };
 58        
 59        var on_finish = function( text_elt ) {
 60            // Replace URL text with URL.
 61            $('#item-url-text').hide();
 62            $('#item-url').show();
 63            
 64            // Set URL to new value.
 65            var new_url = $('#item-url-text').text();
 66            var item_url_obj = $('#item-url');
 67            item_url_obj.attr( "href", new_url );
 68            item_url_obj.text( new_url );
 69        };
 70        
 71        <% controller_name = get_controller_name( item ) %>
 72        async_save_text("edit-identifier", "item-identifier", "${h.url_for( controller=controller_name, action='set_slug_async', id=trans.security.encode_id( item.id ) )}", "new_slug", null, false, 0, on_start, on_finish); 
 73    });
 74    </script>
 75</%def>
 76
 77<%def name="stylesheets()">
 78    ${parent.stylesheets()}
 79    <style>
 80        ## Put some whitespace before each section header.
 81        h3 {
 82            margin-top: 2em;
 83        }
 84        input.action-button {
 85            margin-left: 0;
 86        }
 87        ## If page is displayed in panels, pad from edges for readability.
 88        %if context.get('use_panels'):
 89            div#center {
 90                padding: 10px;
 91            }
 92        %endif
 93    </style>
 94</%def>
 95
 96<%def name="center_panel()">
 97    ${self.body()}
 98</%def>
 99
100<%def name="body()">
101    ## Set use_panels var for use in page's URLs.
102    <% use_panels = context.get('use_panels', False)  %>
103    <% controller_name = get_controller_name( item ) %>
104
105    ## Render message.
106    %if message:
107        ${render_msg( message, status )}
108    %endif
109
110    <%
111        #
112        # Setup and variables needed for page.
113        #
114    
115        # Get class name strings.
116        item_class_name = get_class_display_name( item.__class__ ) 
117        item_class_name_lc = item_class_name.lower()
118        item_class_plural_name = get_class_plural_display_name( item.__class__ )
119        item_class_plural_name_lc = item_class_plural_name.lower()
120        
121        # Get item name.
122        item_name = get_item_name(item)
123    %>
124
125    <h2>Share or Publish ${item_class_name} '${item_name}'</h2>
126
127    ## Require that user have a public username before sharing or publishing an item.
128    %if trans.get_user().username is None or trans.get_user().username is "":
129        <p>To make a ${item_class_name_lc} accessible via link or publish it, you must create a public username:</p>
130        
131        <form action="${h.url_for( controller=controller_name, action='set_public_username', id=trans.security.encode_id( item.id ) )}"     
132                method="POST">
133            <div class="form-row">
134                <label>Public Username:</label>
135                <div class="form-row-input">
136                    <input type="text" name="username" size="40"/>
137                </div>
138            </div>
139            <div style="clear: both"></div>
140            <div class="form-row">
141                <input class="action-button" type="submit" name="Set Username" value="Set Username"/>
142            </div>
143        </form>
144    %else:
145        ## User has a public username, so private sharing and publishing options.
146        <h3>Make ${item_class_name} Accessible via Link and Publish It</h3>
147    
148            <div>
149                %if item.importable:
150                    <% 
151                        item_status = "accessible via link" 
152                        if item.published:
153                            item_status = item_status + " and published"    
154                    %>
155                    This ${item_class_name_lc} is currently <strong>${item_status}</strong>. 
156                    <div>
157                        <p>Anyone can view and import this ${item_class_name_lc} by visiting the following URL:
158
159                        <blockquote>
160                            <% 
161                                url = h.url_for( controller=controller_name, action='display_by_username_and_slug', username=trans.get_user().username, slug=item.slug, qualified=True ) 
162                                url_parts = url.split("/")
163                            %>
164                            <a id="item-url" href="${url}" target="_top">${url}</a>
165                            <span id="item-url-text" style="display: none">
166                                ${"/".join( url_parts[:-1] )}/<span id='item-identifier'>${url_parts[-1]}</span>
167                            </span>
168                            
169                            <a href="#" id="edit-identifier"><img src="${h.url_for('/static/images/fugue/pencil.png')}"/></a>
170                        </blockquote>
171        
172                        %if item.published:
173                            This ${item_class_name_lc} is publicly listed and searchable in Galaxy's <a href='${h.url_for( controller=controller_name, action='list_published' )}' target="_top">Published ${item_class_plural_name}</a> section.
174                        %endif
175                    </div>
176        
177                    <p>You can:
178                    <div>
179                    <form action="${h.url_for( controller=controller_name, action='sharing', id=trans.security.encode_id( item.id ) )}" method="POST">
180                        %if not item.published:
181                            ## Item is importable but not published. User can disable importable or publish.
182                            <input class="action-button" type="submit" name="disable_link_access" value="Disable Access to ${item_class_name} Link">
183                            <div class="toolParamHelp">Disables ${item_class_name_lc}'s link so that it is not accessible.</div>
184                            <br />
185                            <input class="action-button" type="submit" name="publish" value="Publish ${item_class_name}" method="POST">
186                            <div class="toolParamHelp">Publishes the ${item_class_name_lc} to Galaxy's <a href='${h.url_for( controller=controller_name, action='list_published' )}' target="_top">Published ${item_class_plural_name}</a> section, where it is publicly listed and searchable.</div>
187
188                        <br />
189                        %else: ## item.published == True
190                            ## Item is importable and published. User can unpublish or disable import and unpublish.
191                            <input class="action-button" type="submit" name="unpublish" value="Unpublish ${item_class_name}">
192                            <div class="toolParamHelp">Removes this ${item_class_name_lc} from Galaxy's <a href='${h.url_for(controller=controller_name, action='list_published' )}' target="_top">Published ${item_class_plural_name}</a> section so that it is not publicly listed or searchable.</div>
193                            <br />
194                            <input class="action-button" type="submit" name="disable_link_access_and_unpublish" value="Disable Access to ${item_class_name} via Link and Unpublish">
195                            <div class="toolParamHelp">Disables this ${item_class_name_lc}'s link so that it is not accessible and removes ${item_class_name_lc} from Galaxy's <a href='${h.url_for(controller=controller_name, action='list_published' )}' target='_top'>Published ${item_class_plural_name}</a> section so that it is not publicly listed or searchable.</div>
196                        %endif
197                    </form>
198                    </div>
199   
200                %else:
201   
202                    <p>This ${item_class_name_lc} is currently restricted so that only you and the users listed below can access it. You can:</p>
203                    
204                    <form action="${h.url_for(controller=controller_name, action='sharing', id=trans.security.encode_id(item.id) )}" method="POST">
205                        <input class="action-button" type="submit" name="make_accessible_via_link" value="Make ${item_class_name} Accessible via Link">
206                        <div class="toolParamHelp">Generates a web link that you can share with other people so that they can view and import the ${item_class_name_lc}.</div>
207        
208                        <br />
209                        <input class="action-button" type="submit" name="make_accessible_and_publish" value="Make ${item_class_name} Accessible and Publish" method="POST">
210                        <div class="toolParamHelp">Makes the ${item_class_name_lc} accessible via link (see above) and publishes the ${item_class_name_lc} to Galaxy's <a href='${h.url_for(controller=controller_name, action='list_published' )}' target='_top'>Published ${item_class_plural_name}</a> section, where it is publicly listed and searchable.</div>
211                    </form>
212       
213                %endif
214
215        ##
216        ## Sharing with Galaxy users.
217        ##
218        <h3>Share ${item_class_name} with Individual Users</h3>
219
220            <div>
221                %if item.users_shared_with:
222
223                    <p>
224                        The following users will see this ${item_class_name_lc} in their ${item_class_name_lc} list and will be
225                        able to view, import, and run it.
226                    </p>
227            
228                    <table class="colored" border="0" cellspacing="0" cellpadding="0" width="100%">
229                        <tr class="header">
230                            <th>Email</th>
231                            <th></th>
232                        </tr>
233                        %for i, association in enumerate( item.users_shared_with ):
234                            <% user = association.user %>
235                            <tr>
236                                <td>
237                                    <div class="menubutton popup" id="user-${i}-popup">${user.email}</div>
238                                </td>
239                                <td>
240                                    <div popupmenu="user-${i}-popup">
241                                    <a class="action-button" href="${h.url_for(controller=controller_name, action='sharing', id=trans.security.encode_id( item.id ), unshare_user=trans.security.encode_id( user.id ), use_panels=use_panels )}">Unshare</a>
242                                    </div>
243                                </td>
244                            </tr>    
245                        %endfor
246                    </table>
247    
248                    <p>
249                    <a class="action-button" 
250                       href="${h.url_for(controller=controller_name, action='share', id=trans.security.encode_id(item.id), use_panels=use_panels )}">
251                        <span>Share with another user</span>
252                    </a>
253
254                %else:
255
256                    <p>You have not shared this ${item_class_name_lc} with any users.</p>
257    
258                    <a class="action-button" 
259                       href="${h.url_for(controller=controller_name, action='share', id=trans.security.encode_id(item.id), use_panels=use_panels )}">
260                        <span>Share with a user</span>
261                    </a>
262                    <br />
263    
264                %endif
265            </div>
266        </div>
267    %endif
268
269    <br /><br />
270    <a href="${h.url_for(controller=controller_name, action="list" )}">Back to ${item_class_plural_name} List</a>
271</%def>