Fixed race condition if saving avatar image. Added image attribute in avatar observer controller.

This commit is contained in:
Martin Edenhofer 2016-05-19 00:06:55 +02:00
parent 054ad6ced3
commit cb7d10fb1f
5 changed files with 17 additions and 14 deletions

View file

@ -5,7 +5,7 @@ class App.ControllerGenericNew extends App.ControllerModal
headPrefix: 'New'
content: =>
@head = @pageData.object
@head = @pageData.head || @pageData.object
@controller = new App.ControllerForm(
model: App[ @genericObject ]
params: @item
@ -53,7 +53,7 @@ class App.ControllerGenericEdit extends App.ControllerModal
content: =>
@item = App[ @genericObject ].find( @id )
@head = @pageData.object
@head = @pageData.head || @pageData.object
@controller = new App.ControllerForm(
model: App[ @genericObject ]
@ -1116,9 +1116,8 @@ class App.ObserverController extends App.Controller
if active
currentAttributes[key] = object[key]
if @observeNot
attributes = object.attributes()
for key, value of attributes
if !@observeNot[key]
for key, value of object
if !@observeNot[key] && !_.isFunction(value)
currentAttributes[key] = value
if !@lastAttributres

View file

@ -5,6 +5,7 @@ class App.WidgetAvatar extends App.ObserverController
firstname: true
lastname: true
email: true
image: true
render: (user) =>
@html(user.avatar @size, @position, undefined, false, false, @type)

View file

@ -6,7 +6,7 @@ class App.WidgetOrganization extends App.Controller
super
# subscribe and reload data / fetch new data if triggered
@subscribeId = App.Organization.full( @organization_id, @render, false, true )
@subscribeId = App.Organization.full(@organization_id, @render, false, true)
release: =>
App.Organization.unsubscribe(@subscribeId)
@ -58,9 +58,9 @@ class App.WidgetOrganization extends App.Controller
update: (e) =>
name = $(e.target).attr('data-name')
value = $(e.target).html()
org = App.Organization.find( @organization_id )
org = App.Organization.find(@organization_id)
if org[name] isnt value
data = {}
data[name] = value
org.updateAttributes( data )
org.updateAttributes(data)
@log 'notice', 'update', name, value, org

View file

@ -6,7 +6,7 @@ class App.WidgetUser extends App.Controller
super
# subscribe and reload data / fetch new data if triggered
@subscribeId = App.User.full( @user_id, @render, false, true )
@subscribeId = App.User.full(@user_id, @render, false, true)
release: =>
App.User.unsubscribe(@subscribeId)
@ -85,9 +85,9 @@ class App.WidgetUser extends App.Controller
update: (e) =>
name = $(e.target).attr('data-name')
value = $(e.target).html()
user = App.User.find( @user_id )
user = App.User.find(@user_id)
if user[name] isnt value
data = {}
data[name] = value
user.updateAttributes( data )
user.updateAttributes(data)
@log 'notice', 'update', name, value, user

View file

@ -733,7 +733,8 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
)
# update user link
current_user.update_attributes(image: avatar.store_hash)
user = User.find(current_user.id)
user.update_attributes(image: avatar.store_hash)
render json: { avatar: avatar }, status: :ok
end
@ -751,7 +752,8 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
avatar = Avatar.set_default('User', current_user.id, params[:id])
# update user link
current_user.update_attributes(image: avatar.store_hash)
user = User.find(current_user.id)
user.update_attributes(image: avatar.store_hash)
render json: {}, status: :ok
end
@ -770,7 +772,8 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
# update user link
avatar = Avatar.get_default('User', current_user.id)
current_user.update_attributes(image: avatar.store_hash)
user = User.find(current_user.id)
user.update_attributes(image: avatar.store_hash)
render json: {}, status: :ok
end