mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-25 00:12:08 +08:00
Adding add, edit, delete and undelete features for manage user information page
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
/** Add and Edit address */
|
||||
define( [ 'mvc/form/form-view', 'mvc/ui/ui-misc' ], function( Form, Ui ) {
|
||||
var AddEditAddress = Backbone.View.extend({
|
||||
initialize: function ( $el, app, options ) {
|
||||
var self = this;
|
||||
this.model = options && options.model || new Backbone.Model( options );
|
||||
this.addressform = new Form({
|
||||
title : options ? 'Edit address' : 'Add new address',
|
||||
inputs : [{ name: 'short_desc', label: 'Short Description:', type: 'text', value: options ? options.address_obj["desc"] : "",
|
||||
help: 'Required' },
|
||||
{ name: 'name', label: 'Name:', type: 'text',value: options ? options.address_obj["name"] : "", help: 'Required' },
|
||||
{ name: 'institution', label: 'Institution:', type: 'text', value: options ? options.address_obj["institution"] : "",
|
||||
help: 'Required' },
|
||||
{ name: 'address', label: 'Address:', type: 'text', value: options ? options.address_obj["address"] : "",
|
||||
help: 'Required' },
|
||||
{ name: 'city', label: 'City:', type: 'text', value: options ? options.address_obj["city"] : "", help: 'Required' },
|
||||
{ name: 'state', label: 'State/Province/Region:', type: 'text', value: options ? options.address_obj["state"] : "",
|
||||
help: 'Required' },
|
||||
{ name: 'postal_code', label: 'Postal Code:', type: 'text', value: options ? options.address_obj["postal_code"] : "",
|
||||
help: 'Required' },
|
||||
{ name: 'country', label: 'Country:', type: 'text', value: options ? options.address_obj["country"] : "",
|
||||
help: 'Required' },
|
||||
{ name: 'phone', label: 'Phone:', type: 'text', value: options ? options.address_obj["phone"] : "" }
|
||||
],
|
||||
operations : {
|
||||
'back' : new Ui.ButtonIcon({
|
||||
icon : 'fa-caret-left',
|
||||
tooltip : 'Return to manage user information',
|
||||
title : 'Return to manage user information',
|
||||
onclick : function() {
|
||||
self.addressform.$el.remove();
|
||||
app.callManageInfo();
|
||||
}
|
||||
})
|
||||
},
|
||||
buttons : {
|
||||
'save' : new Ui.Button({
|
||||
tooltip : 'Save',
|
||||
title : 'Save',
|
||||
cls : 'ui-button btn btn-primary',
|
||||
floating: 'clear',
|
||||
onclick : function() { self._saveAddress( self, app, options ) }
|
||||
})
|
||||
}
|
||||
});
|
||||
$el.append( self.addressform.$el );
|
||||
},
|
||||
|
||||
/** save the address */
|
||||
_saveAddress: function( self, app, options ) {
|
||||
var url = "",
|
||||
data = {};
|
||||
// save the address after edit
|
||||
if( options ) {
|
||||
url = Galaxy.root + 'api/user_preferences/edit_address/';
|
||||
data = self.addressform.data.create();
|
||||
data.edit_address_button = true;
|
||||
data.address_id = options.address_id;
|
||||
}
|
||||
else { // saves new address
|
||||
url = Galaxy.root + 'api/user_preferences/new_address/';
|
||||
data = self.addressform.data.create();
|
||||
}
|
||||
$.getJSON( url, data, function( response ) {
|
||||
// show error in the same form
|
||||
if( response.status === 'error' ) {
|
||||
self.addressform.message.update({
|
||||
message : response.message,
|
||||
status : response.status === 'error' ? 'danger' : 'success',
|
||||
});
|
||||
}
|
||||
else {
|
||||
// if success, redirect to manage user information page
|
||||
self.addressform.$el.remove();
|
||||
app.callManageInfo( { message: response.message, status: response.status } );
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
AddEditAddress: AddEditAddress
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
/** Edits user information */
|
||||
define( [ 'mvc/form/form-view', 'mvc/ui/ui-misc' ], function( Form, Ui ) {
|
||||
define( [ 'mvc/form/form-view',
|
||||
'mvc/ui/ui-misc',
|
||||
'mvc/user/add-edit-address' ],
|
||||
function( Form, Ui, Address ) {
|
||||
var ManageUserInformation = Backbone.View.extend({
|
||||
initialize: function ( app, $el, options ) {
|
||||
var self = this,
|
||||
filter = null;
|
||||
initialize: function ( app, $el, options, address_message ) {
|
||||
var self = this;
|
||||
this.model = options && options.model || new Backbone.Model( options );
|
||||
this.original_email = options["email"];
|
||||
this.original_username = options["username"];
|
||||
@@ -36,13 +38,20 @@ define( [ 'mvc/form/form-view', 'mvc/ui/ui-misc' ], function( Form, Ui ) {
|
||||
// address display form
|
||||
this.addressform = self._buildAddressForm( self, options, app, $el );
|
||||
$el.append( self.addressform.$el );
|
||||
// show message if an address is added or updated
|
||||
if( address_message ) {
|
||||
self.addressform.message.update({
|
||||
message : address_message.message,
|
||||
status : address_message.status === 'error' ? 'danger' : 'success',
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/** build form for user addresses */
|
||||
_buildAddressForm: function( self, options, app, $el ) {
|
||||
return new Form({
|
||||
title : 'User Addresses',
|
||||
inputs : self._buildAddressInputs( self, options ),
|
||||
inputs : self._buildAddressInputs( self, options, $el, app ),
|
||||
buttons : {
|
||||
'addaddress': new Ui.ButtonIcon({
|
||||
id : 'add-address',
|
||||
@@ -52,7 +61,7 @@ define( [ 'mvc/form/form-view', 'mvc/ui/ui-misc' ], function( Form, Ui ) {
|
||||
title : 'Add new address',
|
||||
icon : 'fa-plus',
|
||||
floating : 'clear',
|
||||
onclick : function() { self._addAddress( self ); }
|
||||
onclick : function() { self._addAddress( self, $el, app ); }
|
||||
})
|
||||
},
|
||||
onchange: function() {
|
||||
@@ -61,22 +70,26 @@ define( [ 'mvc/form/form-view', 'mvc/ui/ui-misc' ], function( Form, Ui ) {
|
||||
});
|
||||
},
|
||||
/** apply address filter */
|
||||
_applyAddressFilter: function( app, $parentEl, self ) {
|
||||
_applyAddressFilter: function( app, $el, self ) {
|
||||
var field = null,
|
||||
active_filter = "";
|
||||
active_filter = self.addressform.data.create()["address_filters"];
|
||||
// fetch the addresses based on the selected filter
|
||||
$.getJSON( Galaxy.root + 'api/user_preferences/manage_user_info/', { 'show_filter': active_filter }, function( response ) {
|
||||
// remove the previous forms
|
||||
self.addressform.$el.remove();
|
||||
self.addressform = self._buildAddressForm( self, response, app, $parentEl );
|
||||
$parentEl.append( self.addressform.$el );
|
||||
self._updateAddressForm( app, $el, self, response );
|
||||
// get and set the active filter's value
|
||||
field = self.addressform.field_list[ self.addressform.data.match( 'address_filters' ) ];
|
||||
field.value( active_filter );
|
||||
});
|
||||
},
|
||||
|
||||
/** update address form with new data */
|
||||
_updateAddressForm: function( app, $el, self, response ) {
|
||||
self.addressform.$el.remove();
|
||||
self.addressform = self._buildAddressForm( self, response, app, $el );
|
||||
$el.append( self.addressform.$el );
|
||||
},
|
||||
|
||||
/** build inputs for user login information form */
|
||||
_buildLoginInputs: function( self, data ) {
|
||||
var all_inputs = [],
|
||||
@@ -137,7 +150,7 @@ define( [ 'mvc/form/form-view', 'mvc/ui/ui-misc' ], function( Form, Ui ) {
|
||||
},
|
||||
|
||||
/** builds inputs for displaying address */
|
||||
_buildAddressInputs: function( self, data ) {
|
||||
_buildAddressInputs: function( self, data, $el, app ) {
|
||||
var all_inputs = [],
|
||||
labels = {};
|
||||
|
||||
@@ -171,35 +184,35 @@ define( [ 'mvc/form/form-view', 'mvc/ui/ui-misc' ], function( Form, Ui ) {
|
||||
help: this['desc'] + ': <br>' + this['html']
|
||||
} );
|
||||
if( !item_object['deleted'] ) {
|
||||
|
||||
all_inputs.push( {
|
||||
id: 'edit_' + this['address_id'],
|
||||
type: 'submit', title: 'Edit', tooltip: 'Edit',
|
||||
onclick: function() { self._editAddress.call( _self ); },
|
||||
type: 'submit',
|
||||
title: 'Edit',
|
||||
tooltip: 'Edit',
|
||||
onclick: function() { self._editAddress.call( _self, self, $el, app ); },
|
||||
icon: 'fa-pencil-square-o'
|
||||
} );
|
||||
|
||||
all_inputs.push( {
|
||||
id: 'delete_' + this['address_id'],
|
||||
type: 'submit',
|
||||
title: 'Delete',
|
||||
tooltip: 'Delete',
|
||||
onclick: function() { self._deleteAddress.call( _self ); },
|
||||
onclick: function() { self._deleteAddress.call( _self, self, $el, app ); },
|
||||
icon: 'fa-remove'
|
||||
} );
|
||||
}
|
||||
else {
|
||||
all_inputs.push( {
|
||||
id: 'undelete_' + this['address_id'],
|
||||
type: 'submit', title: 'Undelete',
|
||||
type: 'submit',
|
||||
title: 'Undelete',
|
||||
tooltip: 'Undelete',
|
||||
onclick: function() { self._undeleteAddress.call( _self ); },
|
||||
onclick: function() { self._undeleteAddress.call( _self, self, $el, app ); },
|
||||
icon: 'fa-reply'
|
||||
} );
|
||||
}
|
||||
// adds a horizontal line at the end of each address section
|
||||
all_inputs.push( { id: '', title: '', type: 'hidden', help: '<hr class="docutils">' } );
|
||||
|
||||
} ).call( data["addresses"][item] );
|
||||
}
|
||||
}
|
||||
@@ -207,26 +220,43 @@ define( [ 'mvc/form/form-view', 'mvc/ui/ui-misc' ], function( Form, Ui ) {
|
||||
},
|
||||
|
||||
/** edit address */
|
||||
_editAddress: function() {
|
||||
//console.log('edit clicked');
|
||||
//console.log( this );
|
||||
_editAddress: function( self, $el, app ) {
|
||||
self.loginform.$el.remove();
|
||||
self.addressform.$el.remove();
|
||||
$.getJSON( Galaxy.root + 'api/user_preferences/edit_address/', {'address_id': this['address_id'] }, function( response ) {
|
||||
address = new Address.AddEditAddress( $el, app, response );
|
||||
});
|
||||
},
|
||||
|
||||
/** delete address */
|
||||
_deleteAddress: function() {
|
||||
//console.log('delete clicked');
|
||||
//console.log( this );
|
||||
_deleteAddress: function( self, $el, app ) {
|
||||
var active_filter = self.addressform.data.create()["address_filters"];
|
||||
$.getJSON( Galaxy.root + 'api/user_preferences/delete_address/', { 'address_id': this["address_id"] }, function( response ) {
|
||||
self._updateAddressForm( app, $el, self, response );
|
||||
self.addressform.message.update({
|
||||
message : response.message,
|
||||
status : response.status === 'error' ? 'danger' : 'success',
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/** revert the delete status */
|
||||
_undeleteAddress: function() {
|
||||
//console.log('undelete clicked');
|
||||
//console.log( this );
|
||||
_undeleteAddress: function( self, $el, app ) {
|
||||
$.getJSON( Galaxy.root + 'api/user_preferences/undelete_address/', { 'address_id': this["address_id"] }, function( response ) {
|
||||
self._updateAddressForm( app, $el, self, response );
|
||||
self.addressform.message.update({
|
||||
message : response.message,
|
||||
status : response.status === 'error' ? 'danger' : 'success',
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/** adds new address */
|
||||
_addAddress: function() {
|
||||
//console.log( "add address" );
|
||||
/** add new address */
|
||||
_addAddress: function( self, $el, app ) {
|
||||
var address;
|
||||
self.loginform.$el.remove();
|
||||
self.addressform.$el.remove();
|
||||
address = new Address.AddEditAddress( $el, app );
|
||||
},
|
||||
|
||||
/** renders message */
|
||||
|
||||
@@ -14,14 +14,14 @@ var UserPreferences = Backbone.View.extend({
|
||||
},
|
||||
|
||||
/** redirects to manage user information view */
|
||||
callManageInfo: function( e ) {
|
||||
callManageInfo: function( message ) {
|
||||
var userInfo = null,
|
||||
url = Galaxy.root + 'api/user_preferences/manage_user_info',
|
||||
self = this,
|
||||
$el = $( '.user-preferences-all' );
|
||||
$( '.user-pref' ).hide();
|
||||
$.getJSON( url, function( data ) {
|
||||
userInfo = new Manage.ManageUserInformation( self, $el, data );
|
||||
userInfo = new Manage.ManageUserInformation( self, $el, data, message );
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -433,55 +433,54 @@ class UserPreferencesAPIController( BaseAPIController, BaseUIController, UsesTag
|
||||
ok = True
|
||||
if not trans.app.config.allow_user_creation and not is_admin:
|
||||
return trans.show_error_message( 'User registration is disabled. Please contact your local Galaxy administrator for an account.' )
|
||||
if params.get( 'new_address_button', False ):
|
||||
if not short_desc:
|
||||
ok = False
|
||||
message = 'Enter a short description for this address'
|
||||
elif not name:
|
||||
ok = False
|
||||
message = 'Enter the name'
|
||||
elif not institution:
|
||||
ok = False
|
||||
message = 'Enter the institution associated with the user'
|
||||
elif not address:
|
||||
ok = False
|
||||
message = 'Enter the address'
|
||||
elif not city:
|
||||
ok = False
|
||||
message = 'Enter the city'
|
||||
elif not state:
|
||||
ok = False
|
||||
message = 'Enter the state/province/region'
|
||||
elif not postal_code:
|
||||
ok = False
|
||||
message = 'Enter the postal code'
|
||||
elif not country:
|
||||
ok = False
|
||||
message = 'Enter the country'
|
||||
if ok:
|
||||
user_address = trans.model.UserAddress( user=user,
|
||||
desc=short_desc,
|
||||
name=name,
|
||||
institution=institution,
|
||||
address=address,
|
||||
city=city,
|
||||
state=state,
|
||||
postal_code=postal_code,
|
||||
country=country,
|
||||
phone=phone )
|
||||
trans.sa_session.add( user_address )
|
||||
trans.sa_session.flush()
|
||||
message = 'Address (%s) has been added' % escape( user_address.desc )
|
||||
new_kwd = dict( message=message, status=status )
|
||||
if is_admin:
|
||||
new_kwd[ 'id' ] = trans.security.encode_id( user.id )
|
||||
return self.user_info(cntrller, trans, new_kwd)
|
||||
else:
|
||||
return {
|
||||
'user_id': user_id,
|
||||
'message': escape( message ),
|
||||
'status': 'error'
|
||||
}
|
||||
if not short_desc:
|
||||
ok = False
|
||||
message = 'Enter a short description for this address'
|
||||
elif not name:
|
||||
ok = False
|
||||
message = 'Enter the name'
|
||||
elif not institution:
|
||||
ok = False
|
||||
message = 'Enter the institution associated with the user'
|
||||
elif not address:
|
||||
ok = False
|
||||
message = 'Enter the address'
|
||||
elif not city:
|
||||
ok = False
|
||||
message = 'Enter the city'
|
||||
elif not state:
|
||||
ok = False
|
||||
message = 'Enter the state/province/region'
|
||||
elif not postal_code:
|
||||
ok = False
|
||||
message = 'Enter the postal code'
|
||||
elif not country:
|
||||
ok = False
|
||||
message = 'Enter the country'
|
||||
if ok:
|
||||
user_address = trans.model.UserAddress( user=user,
|
||||
desc=short_desc,
|
||||
name=name,
|
||||
institution=institution,
|
||||
address=address,
|
||||
city=city,
|
||||
state=state,
|
||||
postal_code=postal_code,
|
||||
country=country,
|
||||
phone=phone )
|
||||
trans.sa_session.add( user_address )
|
||||
trans.sa_session.flush()
|
||||
message = 'Address (%s) has been added' % escape( user_address.desc )
|
||||
new_kwd = dict( message=message, status=status )
|
||||
if is_admin:
|
||||
new_kwd[ 'id' ] = trans.security.encode_id( user.id )
|
||||
return self.user_info(cntrller, trans, new_kwd)
|
||||
else:
|
||||
return {
|
||||
'user_id': user_id,
|
||||
'message': escape( message ),
|
||||
'status': 'error'
|
||||
}
|
||||
|
||||
@expose_api
|
||||
def change_password( self, trans, password=None, confirm=None, current=None, token=None, **kwd):
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,2 +1,2 @@
|
||||
webpackJsonp([4],[function(e,r,n){(function(e){var r=n(1),a=r,i=n(44).GalaxyApp,o=n(10),t=n(4),l=n(46);window.app=function(n,c){window.Galaxy=new i(n,c),Galaxy.debug("login app");var d=encodeURI(n.redirect);if(!n.show_welcome_with_login){var w=r.param({use_panels:"True",redirect:d});return void(window.location.href=Galaxy.root+"user/login?"+w)}var p=new l.PageLayoutView(e.extend(n,{el:"body",center:new o.CenterPanel({el:"#center"}),right:new o.RightPanel({title:t("Login required"),el:"#right"})}));a(function(){var e=r.param({redirect:d}),a=Galaxy.root+"user/login?"+e;p.render(),p.center.$("#galaxy_main").prop("src",n.welcome_url),p.right.$(".unified-panel-body").css("overflow","hidden").html('<iframe src="'+a+'" frameborder="0" style="width: 100%; height: 100%;"/>')})}}).call(r,n(2))}]);
|
||||
webpackJsonp([4],[function(e,r,n){(function(e){var r=n(1),a=r,i=n(44).GalaxyApp,o=n(11),t=n(4),l=n(46);window.app=function(n,c){window.Galaxy=new i(n,c),Galaxy.debug("login app");var d=encodeURI(n.redirect);if(!n.show_welcome_with_login){var w=r.param({use_panels:"True",redirect:d});return void(window.location.href=Galaxy.root+"user/login?"+w)}var p=new l.PageLayoutView(e.extend(n,{el:"body",center:new o.CenterPanel({el:"#center"}),right:new o.RightPanel({title:t("Login required"),el:"#right"})}));a(function(){var e=r.param({redirect:d}),a=Galaxy.root+"user/login?"+e;p.render(),p.center.$("#galaxy_main").prop("src",n.welcome_url),p.right.$(".unified-panel-body").css("overflow","hidden").html('<iframe src="'+a+'" frameborder="0" style="width: 100%; height: 100%;"/>')})}}).call(r,n(2))}]);
|
||||
//# sourceMappingURL=login.bundled.js.map
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user