/
user-preferences.js
232 lines (220 loc) · 10.9 KB
/
user-preferences.js
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/** User Preferences view */
define( [ 'mvc/form/form-view', 'mvc/ui/ui-misc' ], function( Form, Ui ) {
/** Contains descriptive dictionaries describing user forms */
var Model = Backbone.Model.extend({
initialize: function( options ) {
options = options || {};
options.user_id = options.user_id || Galaxy.user.id;
this.set({
'user_id' : options.user_id,
'information': {
title : 'Manage information',
description : 'Edit your email, addresses and custom parameters or change your username.',
url : 'api/users/' + options.user_id + '/information/inputs',
icon : 'fa-user'
},
'password': {
title : 'Change password',
description : 'Allows you to change your login credentials.',
icon : 'fa-unlock-alt',
url : 'api/users/' + options.user_id + '/password/inputs',
submit_title : 'Save password',
},
'communication': {
title : 'Change communication settings',
description : 'Enable or disable the communication feature to chat with other users.',
url : 'api/users/' + options.user_id + '/communication/inputs',
icon : 'fa-comments-o'
},
'permissions': {
title : 'Set dataset permissions for new histories',
description : 'Grant others default access to newly created histories. Changes made here will only affect histories created after these settings have been stored.',
url : 'api/users/' + options.user_id + '/permissions/inputs',
icon : 'fa-users',
submit_title : 'Save permissions'
},
'api_key': {
title : 'Manage API key',
description : 'Access your current API key or create a new one.',
url : 'api/users/' + options.user_id + '/api_key/inputs',
icon : 'fa-key',
submit_title : 'Create a new key',
submit_icon : 'fa-check'
},
'toolbox_filters': {
title : 'Manage Toolbox filters',
description : 'Customize your Toolbox by displaying or omitting sets of Tools.',
url : 'api/users/' + options.user_id + '/toolbox_filters/inputs',
icon : 'fa-filter',
submit_title : 'Save filters'
},
'openids': {
title : 'Manage OpenIDs',
description : 'Associate OpenIDs with your account.',
icon : 'fa-openid',
onclick : function() {
window.location.href = Galaxy.root + 'user/openid_manage?cntrller=user&use_panels=True';
}
},
'custom_builds': {
title : 'Manage custom builds',
description : 'Add or remove custom builds using history datasets.',
icon : 'fa-cubes',
onclick : function() {
window.location.href = Galaxy.root + 'custom_builds';
}
},
'configure_menu': {
title : 'Configure workflow menu',
description : 'Configure your workflow items which appear in the Tool panel.',
icon : 'fa-cog',
onclick : function() {
window.location.href = Galaxy.root + 'workflow/configure_menu';
}
},
'logout': {
title : 'Sign out',
description : 'Click here to sign out of all sessions.',
icon : 'fa-sign-out',
onclick : function() {
Galaxy.modal.show({
title : 'Sign out',
body : 'Do you want to continue and sign out of all active sessions?',
buttons : {
'Cancel' : function() { Galaxy.modal.hide(); },
'Sign out' : function() { window.location.href = Galaxy.root + 'user/logout'; }
}
});
}
}
});
}
});
/** View of the main user preference panel with links to individual user forms */
var View = Backbone.View.extend({
initialize: function() {
this.model = new Model();
this.message = new Ui.Message();
this.setElement( '<div/>' );
this.render();
},
render: function() {
var self = this;
var config = Galaxy.config;
$.getJSON( Galaxy.root + 'api/users/' + Galaxy.user.id, function( data ) {
self.$preferences = $( '<div/>' ).addClass( 'ui-panel' )
.append( self.message.$el )
.append( $( '<h2/>' ).append( 'User preferences' ) )
.append( $( '<p/>' ).append( 'You are logged in as <strong>' + _.escape( data.email ) + '</strong>.' ) )
.append( self.$table = $( '<table/>' ).addClass( 'ui-panel-table' ) );
if( !config.use_remote_user ) {
self._addLink( 'information' );
self._addLink( 'password' );
}
if( config.enable_communication_server ) {
self._addLink( 'communication' );
}
self._addLink( 'custom_builds' );
self._addLink( 'permissions' );
self._addLink( 'api_key' );
if( config.has_user_tool_filters ) {
self._addLink( 'toolbox_filters' );
}
if( config.enable_openid && !config.use_remote_user ) {
self._addLink( 'openids' );
}
self._addLink( 'configure_menu' );
self._addLink( 'logout' );
self.$preferences.append( self._templateFooter( data ) );
self.$el.empty().append( self.$preferences );
});
},
_addLink: function( action ) {
var options = this.model.get( action );
var $row = $( this._templateLink( options ) );
var $a = $row.find( 'a' );
if ( options.onclick ) {
$a.on( 'click', function() { options.onclick() } );
} else {
$a.attr( 'href', Galaxy.root + 'user/' + action );
}
this.$table.append( $row );
},
_templateLink: function( options ) {
return '<tr>' +
'<td>' +
'<div class="ui-panel-icon fa ' + options.icon + '">' +
'</td>' +
'<td>' +
'<a class="ui-panel-anchor" href="javascript:void(0)">' + options.title + '</a>' +
'<div class="ui-form-info">' + options.description + '</div>' +
'</td>' +
'</tr>';
},
_templateFooter: function( options ) {
return '<p class="ui-panel-footer">' +
'You are using <strong>' + options.nice_total_disk_usage + '</strong> of disk space in this Galaxy instance. ' +
( Galaxy.config.enable_quotas ? 'Your disk quota is: <strong>' + options.quota + '</strong>. ' : '' ) +
'Is your usage more than expected? See the <a href="https://galaxyproject.org/learn/managing-datasets/" target="_blank">documentation</a> for tips on how to find all of the data in your account.' +
'</p>';
}
});
/** View of individual user forms */
var Forms = Backbone.View.extend({
initialize: function( options ) {
this.model = new Model( options );
this.page = this.model.get( options.form_id );
this.setElement( '<div/>' );
this.render();
},
render: function() {
var self = this;
$.ajax({
url : Galaxy.root + this.page.url,
type : 'GET'
}).done( function( response ) {
var options = $.extend( {}, self.page, response );
var form = new Form({
title : options.title,
icon : options.icon,
inputs : options.inputs,
operations: {
'submit': new Ui.ButtonIcon({
tooltip : options.submit_tooltip,
title : options.submit_title || 'Save settings',
icon : options.submit_icon || 'fa-save',
onclick : function() { self._submit( form, options ) }
})
}
});
self.$el.empty().append( form.$el );
}).fail( function( response ) {
self.$el.empty().append( new Ui.Message({
message : 'Failed to load resource ' + self.page.url + '.',
status : 'danger',
persistent : true
}).$el );
});
},
_submit: function( form, options ) {
var self = this;
$.ajax( {
url : Galaxy.root + options.url,
data : JSON.stringify( form.data.create() ),
type : 'PUT',
contentType : 'application/json'
}).done( function( response ) {
form.data.matchModel( response, function ( input, input_id ) {
form.field_list[ input_id ].value( input.value );
});
form.message.update( { message: response.message, status: 'success' } );
}).fail( function( response ) {
form.message.update( { message: response.responseJSON.err_msg, status: 'danger' } );
});
}
});
return {
View : View,
Forms : Forms
};
});