forked from galaxyproject/galaxy
/
ind_share_base.mako
195 lines (180 loc) · 6.31 KB
/
ind_share_base.mako
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
##
## Base template for sharing an item with an individual user. Template expects the following parameters:
## (a) item - item to be shared.
##
<%!
def inherit(context):
if context.get('use_panels'):
if context.get('webapp'):
app_name = context.get('webapp')
elif context.get('app'):
app_name = context.get('app').name
else:
app_name = 'galaxy'
return '/webapps/%s/base_panels.mako' % app_name
else:
return '/base.mako'
%>
<%inherit file="${inherit(context)}"/>
<%namespace file="./display_common.mako" import="*" />
##
## Page methods.
##
<%def name="init()">
<%
self.has_left_panel=False
self.has_right_panel=False
self.message_box_visible=False
self.overlay_visible=False
self.message_box_class=""
self.active_view=""
self.body_class=""
%>
</%def>
<%def name="stylesheets()">
${parent.stylesheets()}
<style>
## If page is displayed in panels, pad from edges for readabilit.
%if context.get('use_panels'):
div#center
{
padding: 10px;
}
%endif
</style>
</%def>
<%def name="center_panel()">
${self.body()}
</%def>
<%def name="body()">
%if message:
<%
if messagetype is UNDEFINED:
mt = "done"
else:
mt = messagetype
%>
<p />
<div class="${mt}message">
${message}
</div>
<p />
%endif
<%
#
# Setup and variables needed for page.
#
# Get class name strings.
item_class_name = get_class_display_name( item.__class__ )
item_class_name_lc = item_class_name.lower()
item_class_plural_name = get_class_plural_display_name( item.__class__ )
item_class_plural_name_lc = item_class_plural_name.lower()
item_controller = get_controller_name(item)
# Get item name.
item_name = get_item_name(item)
%>
<div class="toolForm">
<div class="toolFormTitle">Share ${item_class_name} '${item_name | h}' with Another User</div>
<div class="toolFormBody">
<form action="${h.url_for(controller=item_controller, action='share', id=trans.security.encode_id( item.id ) )}" method="POST">
<div class="form-row">
<label>
Email address of user to share with
</label>
<div style="float: left; width: 100%; margin-right: 10px;">
<input type="hidden" id="email_select" name="email" >
</input>
</div>
<div style="clear: both"></div>
</div>
<div class="form-row">
<input type="submit" value="Share"></input>
</div>
<div class="form-row">
<a href="${h.url_for(controller=item_controller, action="sharing", id=trans.security.encode_id( item.id ) )}">Back to ${item_class_name}'s Sharing Home</a>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript">
/* This should be ripped out and made generic at some point for the
* various API bindings available, and once the API can filter list
* queries (term, below) */
var user_id = "${trans.security.encode_id(trans.user.id)}";
function item_to_label(item){
var text = "";
if(typeof(item.username) === "string" && typeof(item.email) === "string"){
text = item.username + " <" + item.email + ">";
}else if(typeof(item.username) === "string"){
text = item.username;
}else{
text = item.email;
}
return text;
//return "id:" + item.id + "|e:" + item.email + "|u:" + item.username;
}
$("#email_select").select2({
placeholder: "Select a user",
width: "33%",
multiple: false,
initSelection: function(element, callback) {
var data = [];
callback(data);
},
// Required for initSelection
id: function(object) {
return object.id;
},
ajax: {
url: "${h.url_for(controller="/api/users", action="index")}",
data: function (term) {
return {
f_any: term,
};
},
dataType: 'json',
quietMillis: 250,
results: function (data) {
var results = [];
// For every user returned by the API call,
$.each(data, function(index, item){
// If they aren't the requesting user, add to the
// list that will populate the select
if(item.id != "${trans.security.encode_id(trans.user.id)}"){
// Because we "share-by-email", we can ONLY add a
// result if we can see the email. Hopefully someday
// someone will allow sharing by Galaxy user ID (or
// something else "opaque" and people will be able to
// share-by-username.)
if(item.email !== undefined){
results.push({
id: item.email,
name: item.username,
text: item_to_label(item),
});
}
}
});
return {
results: results
};
}
},
createSearchChoice: function(term, data) {
// Check for a user with a matching email.
var matches = _.filter(data, function(user){
return user.text.indexOf(term) > -1;
});
// If there aren't any users with matching object labels, then
// display a "default" entry with whatever text they're entering.
// id is set to term as that will be used in
if(matches.length == 0){
return {id: term, text:term};
}else{
// No extra needed
}
}
});
</script>
</%def>