Improved contenteditabe for user and org attributes.

This commit is contained in:
Martin Edenhofer 2014-12-17 13:57:55 +01:00
parent 449f0a69c4
commit 406eae642d
8 changed files with 92 additions and 128 deletions

View file

@ -1,6 +1,6 @@
class App.OrganizationProfile extends App.Controller class App.OrganizationProfile extends App.Controller
events: events:
'focusout [data-type=update]': 'update' 'focusout [contenteditable]': 'update'
constructor: (params) -> constructor: (params) ->
super super
@ -50,22 +50,20 @@ class App.OrganizationProfile extends App.Controller
# get display data # get display data
organizationData = [] organizationData = []
for item2 in App.Organization.configure_attributes for attributeName, attributeConfig of App.Organization.attributesGet('view')
item = _.clone( item2 )
# check if value for _id exists # check if value for _id exists
itemNameValue = item.name name = attributeName
itemNameValueNew = itemNameValue.substr( 0, itemNameValue.length - 3 ) nameNew = name.substr( 0, name.length - 3 )
if itemNameValueNew of organization if nameNew of organization
item.name = itemNameValueNew name = nameNew
# add to show if value exists # add to show if value exists
if organization[item.name] || item.tag is 'textarea' if organization[name] && attributeConfig.shown
# do not show firstname and lastname / already show via diplayName() # do not show firstname and lastname / already show via diplayName()
if item.name isnt 'name' if name isnt 'name'
if item.info organizationData.push attributeConfig
organizationData.push item
@html App.view('organization_profile')( @html App.view('organization_profile')(
organization: organization organization: organization
@ -120,12 +118,14 @@ class App.OrganizationProfile extends App.Controller
) )
update: (e) => update: (e) =>
console.log('update') name = $(e.target).attr('data-name')
note = $(e.target).ceg() value = $(e.target).html()
org = App.Organization.find( @organization_id ) org = App.Organization.find( @organization_id )
if org.note isnt note if org[name] isnt value
org.updateAttributes( note: note ) data = {}
@log 'notice', 'update', e, note, org data[name] = value
org.updateAttributes( data )
@log 'notice', 'update', name, value, org
class Router extends App.ControllerPermanent class Router extends App.ControllerPermanent
constructor: (params) -> constructor: (params) ->

View file

@ -1,6 +1,6 @@
class App.UserProfile extends App.Controller class App.UserProfile extends App.Controller
events: events:
'focusout [data-type=update]': 'update' 'focusout [contenteditable]': 'update'
constructor: (params) -> constructor: (params) ->
super super
@ -49,22 +49,20 @@ class App.UserProfile extends App.Controller
# get display data # get display data
userData = [] userData = []
for item2 in App.User.configure_attributes for attributeName, attributeConfig of App.User.attributesGet('view')
item = _.clone( item2 )
# check if value for _id exists # check if value for _id exists
itemNameValue = item.name name = attributeName
itemNameValueNew = itemNameValue.substr( 0, itemNameValue.length - 3 ) nameNew = name.substr( 0, name.length - 3 )
if itemNameValueNew of user if nameNew of user
item.name = itemNameValueNew name = nameNew
# add to show if value exists # add to show if value exists
if user[item.name] || item.tag is 'textarea' if user[name] && attributeConfig.shown
# do not show firstname and lastname / already show via diplayName() # do not show firstname and lastname / already show via diplayName()
if item.name isnt 'firstname' && item.name isnt 'lastname' && item.name isnt 'organization' if name isnt 'firstname' && name isnt 'lastname' && name isnt 'organization'
if item.info userData.push attributeConfig
userData.push item
@html App.view('user_profile')( @html App.view('user_profile')(
user: user user: user
@ -120,12 +118,14 @@ class App.UserProfile extends App.Controller
) )
update: (e) => update: (e) =>
console.log('update') name = $(e.target).attr('data-name')
note = $(e.target).ceg() value = $(e.target).html()
user = App.User.find( @user_id ) user = App.User.find( @user_id )
if user.note isnt note if user[name] isnt value
user.updateAttributes( note: note ) data = {}
@log 'notice', 'update', e, note, user data[name] = value
user.updateAttributes( data )
@log 'notice', 'update', name, value, user
class Router extends App.ControllerPermanent class Router extends App.ControllerPermanent
constructor: (params) -> constructor: (params) ->

View file

@ -1,7 +1,6 @@
class App.WidgetOrganization extends App.Controller class App.WidgetOrganization extends App.Controller
events: events:
'focusout [data-type=update-org]': 'update', 'focusout [contenteditable]': 'update'
'click [data-type=edit-org]': 'edit'
constructor: -> constructor: ->
super super
@ -18,22 +17,20 @@ class App.WidgetOrganization extends App.Controller
# get display data # get display data
organizationData = [] organizationData = []
for item2 in App.Organization.configure_attributes for attributeName, attributeConfig of App.Organization.attributesGet('view')
item = _.clone( item2 )
# check if value for _id exists # check if value for _id exists
itemNameValue = item.name name = attributeName
itemNameValueNew = itemNameValue.substr( 0, itemNameValue.length - 3 ) nameNew = name.substr( 0, name.length - 3 )
if itemNameValueNew of organization if nameNew of organization
item.name = itemNameValueNew name = nameNew
# add to show if value exists # add to show if value exists
if organization[item.name] || item.tag is 'textarea' if organization[name] && attributeConfig.shown
# do not show name / already show via diplayName() # do not show firstname and lastname / already show via diplayName()
if item.name isnt 'name' if name isnt 'name'
if item.info organizationData.push attributeConfig
organizationData.push item
# insert userData # insert userData
@html App.view('widget/organization')( @html App.view('widget/organization')(
@ -41,7 +38,7 @@ class App.WidgetOrganization extends App.Controller
organizationData: organizationData organizationData: organizationData
) )
@$('div [contenteditable]').ce( @$('[contenteditable]').ce(
mode: 'textonly' mode: 'textonly'
multiline: true multiline: true
maxlength: 250 maxlength: 250
@ -59,21 +56,11 @@ class App.WidgetOrganization extends App.Controller
### ###
update: (e) => update: (e) =>
note = $(e.target).ceg() name = $(e.target).attr('data-name')
organization = App.Organization.find( @organization_id ) value = $(e.target).html()
if organization.note isnt note org = App.Organization.find( @organization_id )
organization.updateAttributes( note: note ) if org[name] isnt value
@log 'notice', 'update', e, note, organization data = {}
data[name] = value
edit: (e) => org.updateAttributes( data )
e.preventDefault() @log 'notice', 'update', name, value, org
new App.ControllerGenericEdit(
id: @organization_id,
genericObject: 'Organization',
pageData: {
title: 'Organizations',
object: 'Organization',
objects: 'Organizations',
},
callback: @render
)

View file

@ -1,7 +1,6 @@
class App.WidgetUser extends App.Controller class App.WidgetUser extends App.Controller
events: events:
'focusout [data-type=update]': 'update', 'focusout [contenteditable]': 'update'
'click [data-type=edit]': 'edit'
constructor: -> constructor: ->
super super
@ -20,22 +19,20 @@ class App.WidgetUser extends App.Controller
# get display data # get display data
userData = [] userData = []
for item2 in App.User.configure_attributes for attributeName, attributeConfig of App.User.attributesGet('view')
item = _.clone( item2 )
# check if value for _id exists # check if value for _id exists
itemNameValue = item.name name = attributeName
itemNameValueNew = itemNameValue.substr( 0, itemNameValue.length - 3 ) nameNew = name.substr( 0, name.length - 3 )
if itemNameValueNew of user if nameNew of user
item.name = itemNameValueNew name = nameNew
# add to show if value exists # add to show if value exists
if user[item.name] || item.tag is 'textarea' if user[name] && attributeConfig.shown
# do not show firstname and lastname / already show via diplayName() # do not show firstname and lastname / already show via diplayName()
if item.name isnt 'firstname' && item.name isnt 'lastname' if name isnt 'firstname' && name isnt 'lastname' && name isnt 'organization'
if item.info userData.push attributeConfig
userData.push item
if user.preferences if user.preferences
items = [] items = []
@ -67,13 +64,13 @@ class App.WidgetUser extends App.Controller
# insert userData # insert userData
@html App.view('widget/user')( @html App.view('widget/user')(
header: 'Customer' header: 'Customer'
edit: true edit: true
user: user user: user
userData: userData userData: userData
) )
@$('div[contenteditable]').ce( @$('[contenteditable]').ce(
mode: 'textonly' mode: 'textonly'
multiline: true multiline: true
maxlength: 250 maxlength: 250
@ -86,21 +83,11 @@ class App.WidgetUser extends App.Controller
) )
update: (e) => update: (e) =>
note = $(e.target).ceg() name = $(e.target).attr('data-name')
user = App.User.find( @user_id ) value = $(e.target).html()
if user.note isnt note user = App.User.find( @user_id )
user.updateAttributes( note: note ) if user[name] isnt value
@log 'notice', 'update', e, note, user data = {}
data[name] = value
edit: (e) => user.updateAttributes( data )
e.preventDefault() @log 'notice', 'update', name, value, user
new App.ControllerGenericEdit(
id: @user_id
genericObject: 'User'
screen: 'edit'
pageData:
title: 'Users'
object: 'User'
objects: 'Users'
callback: @render
)

View file

@ -12,7 +12,7 @@
<div class="profile-details horizontal wrap"> <div class="profile-details horizontal wrap">
<% for row in @organizationData: %> <% for row in @organizationData: %>
<% if @organization[row.name]: %> <% if @organization[row.name]: %>
<% if row.tag isnt 'textarea': %> <% if row.tag isnt 'richtext': %>
<div class="profile-detailsEntry"> <div class="profile-detailsEntry">
<label><%- @Ti( row.display ) %></label> <label><%- @Ti( row.display ) %></label>
<%- @L( @P( @organization[row.name] ) ) %> <%- @L( @P( @organization[row.name] ) ) %>
@ -21,10 +21,10 @@
<% end %> <% end %>
<% end %> <% end %>
<% for row in @organizationData: %> <% for row in @organizationData: %>
<% if row.tag is 'textarea': %> <% if row.tag is 'richtext': %>
<div class="profile-detailsEntry" style="width: 100%;"> <div class="profile-detailsEntry" style="width: 100%;">
<label><%- @Ti( row.display ) %></label> <label><%- @Ti( row.display ) %></label>
<div contenteditable="true" data-name="<%= row.name %>" data-type="update" data-placeholder="<%- @T('Add a Note') %>"><%= @organization[row.name] %></div> <div contenteditable="true" data-name="<%= row.name %>" data-type="update" data-placeholder="<%- @T('Add a Note') %>"><%- @organization[row.name] %></div>
</div> </div>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -14,7 +14,7 @@
<div class="profile-details horizontal wrap"> <div class="profile-details horizontal wrap">
<% for row in @userData: %> <% for row in @userData: %>
<% if @user[row.name]: %> <% if @user[row.name]: %>
<% if row.tag isnt 'textarea': %> <% if row.tag isnt 'richtext': %>
<div class="profile-detailsEntry"> <div class="profile-detailsEntry">
<label><%- @Ti( row.display ) %></label> <label><%- @Ti( row.display ) %></label>
<%- @L( @P( @user[row.name] ) ) %> <%- @L( @P( @user[row.name] ) ) %>
@ -23,10 +23,10 @@
<% end %> <% end %>
<% end %> <% end %>
<% for row in @userData: %> <% for row in @userData: %>
<% if row.tag is 'textarea': %> <% if row.tag is 'richtext': %>
<div class="profile-detailsEntry" style="width: 100%;"> <div class="profile-detailsEntry" style="width: 100%;">
<label><%- @Ti( row.display ) %></label> <label><%- @Ti( row.display ) %></label>
<div contenteditable="true" data-name="<%= row.name %>" data-type="update" data-placeholder="<%- @T('Add a Note') %>"><%= @user[row.name] %></div> <div contenteditable="true" data-name="<%= row.name %>" data-type="update" data-placeholder="<%- @T('Add a Note') %>"><%- @user[row.name] %></div>
</div> </div>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -5,17 +5,17 @@
</div> </div>
<% for row in @organizationData: %> <% for row in @organizationData: %>
<% if @organization[row.name] || row.name is 'note': %> <% if @organization[row.name] || row.name is 'note': %>
<div class="sidebar-block"> <div class="sidebar-block">
<% if row.tag isnt 'textarea': %> <% if row.tag isnt 'richtext': %>
<label><%- @T( row.display ) %></label> <label><%- @T( row.display ) %></label>
<%- @L( @P( @organization[row.name] ) ) %> <%- @L( @P( @organization[row.name] ) ) %>
<% else: %> <% else: %>
<label><%- @T( row.display ) %></label> <label><%- @T( row.display ) %></label>
<div contenteditable="true" data-name="<%= row.name %>" data-type="update-org" data-placeholder="<%- @T('Add a Note') %>"><%= @organization[row.name] %></div> <div contenteditable="true" data-name="<%= row.name %>" data-type="update-org" data-placeholder="<%- @T('Add a Note') %>"><%- @organization[row.name] %></div>
<% end %> <% end %>
</div> </div>
<% end %> <% end %>
<% end %> <% end %>
<% if @organization.members: %> <% if @organization.members: %>
@ -29,16 +29,6 @@
<a href="<%- user.uiUrl() %>" class="user-popover" data-id="<%- user.id %>"> <a href="<%- user.uiUrl() %>" class="user-popover" data-id="<%- user.id %>">
<%= user.displayName() %> <%= user.displayName() %>
</a> </a>
<li>
<%- user.avatar("40") %>
<a href="<%- user.uiUrl() %>" class="user-popover" data-id="<%- user.id %>">
<%= user.displayName() %>
</a>
<li>
<%- user.avatar("40") %>
<a href="<%- user.uiUrl() %>" class="user-popover" data-id="<%- user.id %>">
<%= user.displayName() %>
</a>
<% end %> <% end %>
</ul> </ul>
</div> </div>

View file

@ -8,12 +8,12 @@
<% for row in @userData: %> <% for row in @userData: %>
<% if @user[row.name] || row.name is 'note': %> <% if @user[row.name] || row.name is 'note': %>
<div class="sidebar-block"> <div class="sidebar-block">
<% if row.tag isnt 'textarea': %> <% if row.tag isnt 'richtext': %>
<label><%- @T( row.display ) %></label> <label><%- @T( row.display ) %></label>
<%- @L( @P( @user[row.name] ) ) %> <%- @L( @P( @user[row.name] ) ) %>
<% else: %> <% else: %>
<label><%- @T( row.display ) %></label> <label><%- @T( row.display ) %></label>
<div contenteditable="true" data-name="<%= row.name %>" data-type="update" data-placeholder="<%- @T('Add a Note') %>"><%= @user[row.name] %></div> <div contenteditable="true" data-name="<%= row.name %>" data-type="update" data-placeholder="<%- @T('Add a Note') %>"><%- @user[row.name] %></div>
<% end %> <% end %>
</div> </div>
<% end %> <% end %>