From 406eae642dc4fff27a78d038778c3d8d02525efc Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 17 Dec 2014 13:57:55 +0100 Subject: [PATCH] Improved contenteditabe for user and org attributes. --- .../organization_profile.js.coffee | 34 ++++++------ .../app/controllers/user_profile.js.coffee | 34 ++++++------ .../controllers/widget/organization.js.coffee | 51 +++++++----------- .../app/controllers/widget/user.js.coffee | 53 +++++++------------ .../app/views/organization_profile.jst.eco | 6 +-- .../app/views/user_profile.jst.eco | 6 +-- .../app/views/widget/organization.jst.eco | 32 ++++------- .../javascripts/app/views/widget/user.jst.eco | 4 +- 8 files changed, 92 insertions(+), 128 deletions(-) diff --git a/app/assets/javascripts/app/controllers/organization_profile.js.coffee b/app/assets/javascripts/app/controllers/organization_profile.js.coffee index df1acc6f9..3cee3374e 100644 --- a/app/assets/javascripts/app/controllers/organization_profile.js.coffee +++ b/app/assets/javascripts/app/controllers/organization_profile.js.coffee @@ -1,6 +1,6 @@ class App.OrganizationProfile extends App.Controller events: - 'focusout [data-type=update]': 'update' + 'focusout [contenteditable]': 'update' constructor: (params) -> super @@ -50,22 +50,20 @@ class App.OrganizationProfile extends App.Controller # get display data organizationData = [] - for item2 in App.Organization.configure_attributes - item = _.clone( item2 ) + for attributeName, attributeConfig of App.Organization.attributesGet('view') # check if value for _id exists - itemNameValue = item.name - itemNameValueNew = itemNameValue.substr( 0, itemNameValue.length - 3 ) - if itemNameValueNew of organization - item.name = itemNameValueNew + name = attributeName + nameNew = name.substr( 0, name.length - 3 ) + if nameNew of organization + name = nameNew # 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() - if item.name isnt 'name' - if item.info - organizationData.push item + if name isnt 'name' + organizationData.push attributeConfig @html App.view('organization_profile')( organization: organization @@ -120,12 +118,14 @@ class App.OrganizationProfile extends App.Controller ) update: (e) => - console.log('update') - note = $(e.target).ceg() - org = App.Organization.find( @organization_id ) - if org.note isnt note - org.updateAttributes( note: note ) - @log 'notice', 'update', e, note, org + name = $(e.target).attr('data-name') + value = $(e.target).html() + org = App.Organization.find( @organization_id ) + if org[name] isnt value + data = {} + data[name] = value + org.updateAttributes( data ) + @log 'notice', 'update', name, value, org class Router extends App.ControllerPermanent constructor: (params) -> diff --git a/app/assets/javascripts/app/controllers/user_profile.js.coffee b/app/assets/javascripts/app/controllers/user_profile.js.coffee index 8ba02efc1..f58d6d316 100644 --- a/app/assets/javascripts/app/controllers/user_profile.js.coffee +++ b/app/assets/javascripts/app/controllers/user_profile.js.coffee @@ -1,6 +1,6 @@ class App.UserProfile extends App.Controller events: - 'focusout [data-type=update]': 'update' + 'focusout [contenteditable]': 'update' constructor: (params) -> super @@ -49,22 +49,20 @@ class App.UserProfile extends App.Controller # get display data userData = [] - for item2 in App.User.configure_attributes - item = _.clone( item2 ) + for attributeName, attributeConfig of App.User.attributesGet('view') # check if value for _id exists - itemNameValue = item.name - itemNameValueNew = itemNameValue.substr( 0, itemNameValue.length - 3 ) - if itemNameValueNew of user - item.name = itemNameValueNew + name = attributeName + nameNew = name.substr( 0, name.length - 3 ) + if nameNew of user + name = nameNew # 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() - if item.name isnt 'firstname' && item.name isnt 'lastname' && item.name isnt 'organization' - if item.info - userData.push item + if name isnt 'firstname' && name isnt 'lastname' && name isnt 'organization' + userData.push attributeConfig @html App.view('user_profile')( user: user @@ -120,12 +118,14 @@ class App.UserProfile extends App.Controller ) update: (e) => - console.log('update') - note = $(e.target).ceg() - user = App.User.find( @user_id ) - if user.note isnt note - user.updateAttributes( note: note ) - @log 'notice', 'update', e, note, user + name = $(e.target).attr('data-name') + value = $(e.target).html() + user = App.User.find( @user_id ) + if user[name] isnt value + data = {} + data[name] = value + user.updateAttributes( data ) + @log 'notice', 'update', name, value, user class Router extends App.ControllerPermanent constructor: (params) -> diff --git a/app/assets/javascripts/app/controllers/widget/organization.js.coffee b/app/assets/javascripts/app/controllers/widget/organization.js.coffee index 3d6fcffb7..c5c1be3e8 100644 --- a/app/assets/javascripts/app/controllers/widget/organization.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/organization.js.coffee @@ -1,7 +1,6 @@ class App.WidgetOrganization extends App.Controller events: - 'focusout [data-type=update-org]': 'update', - 'click [data-type=edit-org]': 'edit' + 'focusout [contenteditable]': 'update' constructor: -> super @@ -18,22 +17,20 @@ class App.WidgetOrganization extends App.Controller # get display data organizationData = [] - for item2 in App.Organization.configure_attributes - item = _.clone( item2 ) + for attributeName, attributeConfig of App.Organization.attributesGet('view') # check if value for _id exists - itemNameValue = item.name - itemNameValueNew = itemNameValue.substr( 0, itemNameValue.length - 3 ) - if itemNameValueNew of organization - item.name = itemNameValueNew + name = attributeName + nameNew = name.substr( 0, name.length - 3 ) + if nameNew of organization + name = nameNew # 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() - if item.name isnt 'name' - if item.info - organizationData.push item + # do not show firstname and lastname / already show via diplayName() + if name isnt 'name' + organizationData.push attributeConfig # insert userData @html App.view('widget/organization')( @@ -41,7 +38,7 @@ class App.WidgetOrganization extends App.Controller organizationData: organizationData ) - @$('div [contenteditable]').ce( + @$('[contenteditable]').ce( mode: 'textonly' multiline: true maxlength: 250 @@ -59,21 +56,11 @@ class App.WidgetOrganization extends App.Controller ### update: (e) => - note = $(e.target).ceg() - organization = App.Organization.find( @organization_id ) - if organization.note isnt note - organization.updateAttributes( note: note ) - @log 'notice', 'update', e, note, organization - - edit: (e) => - e.preventDefault() - new App.ControllerGenericEdit( - id: @organization_id, - genericObject: 'Organization', - pageData: { - title: 'Organizations', - object: 'Organization', - objects: 'Organizations', - }, - callback: @render - ) + name = $(e.target).attr('data-name') + value = $(e.target).html() + org = App.Organization.find( @organization_id ) + if org[name] isnt value + data = {} + data[name] = value + org.updateAttributes( data ) + @log 'notice', 'update', name, value, org diff --git a/app/assets/javascripts/app/controllers/widget/user.js.coffee b/app/assets/javascripts/app/controllers/widget/user.js.coffee index 510327e3d..a0aa76512 100644 --- a/app/assets/javascripts/app/controllers/widget/user.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/user.js.coffee @@ -1,7 +1,6 @@ class App.WidgetUser extends App.Controller events: - 'focusout [data-type=update]': 'update', - 'click [data-type=edit]': 'edit' + 'focusout [contenteditable]': 'update' constructor: -> super @@ -20,22 +19,20 @@ class App.WidgetUser extends App.Controller # get display data userData = [] - for item2 in App.User.configure_attributes - item = _.clone( item2 ) + for attributeName, attributeConfig of App.User.attributesGet('view') # check if value for _id exists - itemNameValue = item.name - itemNameValueNew = itemNameValue.substr( 0, itemNameValue.length - 3 ) - if itemNameValueNew of user - item.name = itemNameValueNew + name = attributeName + nameNew = name.substr( 0, name.length - 3 ) + if nameNew of user + name = nameNew # 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() - if item.name isnt 'firstname' && item.name isnt 'lastname' - if item.info - userData.push item + if name isnt 'firstname' && name isnt 'lastname' && name isnt 'organization' + userData.push attributeConfig if user.preferences items = [] @@ -67,13 +64,13 @@ class App.WidgetUser extends App.Controller # insert userData @html App.view('widget/user')( - header: 'Customer' - edit: true + header: 'Customer' + edit: true user: user userData: userData ) - @$('div[contenteditable]').ce( + @$('[contenteditable]').ce( mode: 'textonly' multiline: true maxlength: 250 @@ -86,21 +83,11 @@ class App.WidgetUser extends App.Controller ) update: (e) => - note = $(e.target).ceg() - user = App.User.find( @user_id ) - if user.note isnt note - user.updateAttributes( note: note ) - @log 'notice', 'update', e, note, user - - edit: (e) => - e.preventDefault() - new App.ControllerGenericEdit( - id: @user_id - genericObject: 'User' - screen: 'edit' - pageData: - title: 'Users' - object: 'User' - objects: 'Users' - callback: @render - ) + name = $(e.target).attr('data-name') + value = $(e.target).html() + user = App.User.find( @user_id ) + if user[name] isnt value + data = {} + data[name] = value + user.updateAttributes( data ) + @log 'notice', 'update', name, value, user diff --git a/app/assets/javascripts/app/views/organization_profile.jst.eco b/app/assets/javascripts/app/views/organization_profile.jst.eco index 996059cee..df887d366 100644 --- a/app/assets/javascripts/app/views/organization_profile.jst.eco +++ b/app/assets/javascripts/app/views/organization_profile.jst.eco @@ -12,7 +12,7 @@
<% for row in @organizationData: %> <% if @organization[row.name]: %> - <% if row.tag isnt 'textarea': %> + <% if row.tag isnt 'richtext': %>
<%- @L( @P( @organization[row.name] ) ) %> @@ -21,10 +21,10 @@ <% end %> <% end %> <% for row in @organizationData: %> - <% if row.tag is 'textarea': %> + <% if row.tag is 'richtext': %>
-
<%= @organization[row.name] %>
+
<%- @organization[row.name] %>
<% end %> <% end %> diff --git a/app/assets/javascripts/app/views/user_profile.jst.eco b/app/assets/javascripts/app/views/user_profile.jst.eco index 1c5c2dd1f..f2098d183 100644 --- a/app/assets/javascripts/app/views/user_profile.jst.eco +++ b/app/assets/javascripts/app/views/user_profile.jst.eco @@ -14,7 +14,7 @@
<% for row in @userData: %> <% if @user[row.name]: %> - <% if row.tag isnt 'textarea': %> + <% if row.tag isnt 'richtext': %>
<%- @L( @P( @user[row.name] ) ) %> @@ -23,10 +23,10 @@ <% end %> <% end %> <% for row in @userData: %> - <% if row.tag is 'textarea': %> + <% if row.tag is 'richtext': %>
-
<%= @user[row.name] %>
+
<%- @user[row.name] %>
<% end %> <% end %> diff --git a/app/assets/javascripts/app/views/widget/organization.jst.eco b/app/assets/javascripts/app/views/widget/organization.jst.eco index af2dc8a56..073832c20 100644 --- a/app/assets/javascripts/app/views/widget/organization.jst.eco +++ b/app/assets/javascripts/app/views/widget/organization.jst.eco @@ -5,17 +5,17 @@
<% for row in @organizationData: %> -<% if @organization[row.name] || row.name is 'note': %> - -<% end %> + <% if @organization[row.name] || row.name is 'note': %> + + <% end %> <% end %> <% if @organization.members: %> @@ -29,16 +29,6 @@ <%= user.displayName() %> -
  • - <%- user.avatar("40") %> - - <%= user.displayName() %> - -
  • - <%- user.avatar("40") %> - - <%= user.displayName() %> - <% end %>
  • diff --git a/app/assets/javascripts/app/views/widget/user.jst.eco b/app/assets/javascripts/app/views/widget/user.jst.eco index 48e8e2f04..865f0752a 100644 --- a/app/assets/javascripts/app/views/widget/user.jst.eco +++ b/app/assets/javascripts/app/views/widget/user.jst.eco @@ -8,12 +8,12 @@ <% for row in @userData: %> <% if @user[row.name] || row.name is 'note': %> <% end %>