Added in place edit of customer.
This commit is contained in:
parent
038570fa20
commit
7a9cf505d6
4 changed files with 28 additions and 12 deletions
|
@ -422,7 +422,7 @@ class App.ControllerModal extends App.Controller
|
|||
# @callback.success = options.success
|
||||
# if options.error
|
||||
# @callback.error = options.error
|
||||
|
||||
|
||||
super(options)
|
||||
|
||||
modalShow: (params) =>
|
||||
|
@ -443,7 +443,7 @@ class App.ControllerModal extends App.Controller
|
|||
# navigate back
|
||||
if params && params.navigateBack
|
||||
window.history.back()
|
||||
|
||||
|
||||
# remove modal from dom
|
||||
$('.modal').remove();
|
||||
)
|
||||
|
@ -452,7 +452,7 @@ class App.ControllerModal extends App.Controller
|
|||
if e
|
||||
e.preventDefault()
|
||||
@el.modal('hide')
|
||||
|
||||
|
||||
submit: (e) =>
|
||||
e.preventDefault()
|
||||
@log 'You need to implement your own "submit" method!'
|
||||
|
|
|
@ -68,7 +68,7 @@ class App.ControllerGenericEdit extends App.ControllerModal
|
|||
@render()
|
||||
@genericObject.unbind 'refresh'
|
||||
@genericObject.fetch( id: params.id)
|
||||
|
||||
|
||||
render: ->
|
||||
@html App.view('generic/admin/edit')( head: @pageData.object )
|
||||
|
||||
|
@ -76,6 +76,7 @@ class App.ControllerGenericEdit extends App.ControllerModal
|
|||
el: @el.find('#object_edit'),
|
||||
model: @genericObject,
|
||||
params: @item,
|
||||
required: @required,
|
||||
autofocus: true,
|
||||
)
|
||||
|
||||
|
@ -85,7 +86,7 @@ class App.ControllerGenericEdit extends App.ControllerModal
|
|||
e.preventDefault()
|
||||
params = @formParam(e.target)
|
||||
@item.load(params)
|
||||
|
||||
|
||||
# validate
|
||||
errors = @item.validate()
|
||||
if errors
|
||||
|
@ -97,6 +98,7 @@ class App.ControllerGenericEdit extends App.ControllerModal
|
|||
# save object
|
||||
@item.save(
|
||||
success: =>
|
||||
@log 'lll', @callback(@item), @required
|
||||
@modalHide()
|
||||
error: =>
|
||||
@log 'errors'
|
||||
|
|
|
@ -2,7 +2,8 @@ $ = jQuery.sub()
|
|||
|
||||
class App.UserInfo extends App.Controller
|
||||
events:
|
||||
'focusout [data-type=edit]': 'update',
|
||||
'focusout [data-type=update]': 'update',
|
||||
'click [data-type=edit]': 'edit'
|
||||
|
||||
constructor: ->
|
||||
super
|
||||
|
@ -28,11 +29,24 @@ class App.UserInfo extends App.Controller
|
|||
user_id: user.id,
|
||||
)
|
||||
|
||||
# update changes
|
||||
update: (e) =>
|
||||
|
||||
# update changes
|
||||
note = $(e.target).parent().find('[data-type=edit]').val()
|
||||
note = $(e.target).parent().find('[data-type=update]').val()
|
||||
user = App.Collection.find( 'User', @user_id )
|
||||
if user.note isnt note
|
||||
user.updateAttributes( note: note )
|
||||
@log 'update', e, note, user
|
||||
|
||||
edit: (e) =>
|
||||
e.preventDefault()
|
||||
new App.ControllerGenericEdit(
|
||||
id: @user_id,
|
||||
genericObject: App.User,
|
||||
required: 'quick',
|
||||
pageData: {
|
||||
title: 'Users',
|
||||
object: 'User',
|
||||
objects: 'Users',
|
||||
},
|
||||
callback: @render
|
||||
)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<div class="well">
|
||||
<h3><%- T('Customer') %></h3>
|
||||
<h3><%- T('Customer') %> <small><a href="#" data-type="edit" class="icon-edit"></a></small></h3>
|
||||
<% if @user.image: %>
|
||||
<img class="thumbnail" src="<%- @user.image %>" alt="">
|
||||
<% end %>
|
||||
<div class="row">
|
||||
<div class="customer-info" title="<%- Ti('Name') %>"><%= @user['realname'] %></div>
|
||||
<div class="customer-info" title="<%- Ti('Name') %>"><%= @user.displayName() %></div>
|
||||
</div>
|
||||
<% for row in @data: %>
|
||||
<% if @user[row.name] || row.name is 'note': %>
|
||||
|
@ -14,7 +14,7 @@
|
|||
<% else: %>
|
||||
<div class="customer-info" title="<%- Ti(row.display) %>">
|
||||
<strong><%- T(row.display) %></strong><br/>
|
||||
<textarea class="customer-info" rows="3" name="<%= row.name %>" data-type=edit><%= @user[row.name] %></textarea>
|
||||
<textarea class="customer-info" rows="3" name="<%= row.name %>" data-type="update"><%= @user[row.name] %></textarea>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue