done (for now) with the my account screen

This commit is contained in:
did 2011-12-02 01:43:49 +01:00
parent 99d756f550
commit fb0e87c64d
12 changed files with 129 additions and 20 deletions

View File

@ -1 +1,11 @@
class Locomotive.Models.Account extends Backbone.Model
paramRoot: 'account'
urlRoot: "#{Locomotive.mount_on}/accounts"
class Locomotive.Models.CurrentAccount extends Locomotive.Models.Account
url: "#{Locomotive.mount_on}/my_account"

View File

@ -0,0 +1,26 @@
#= require ../shared/form_view
Locomotive.Views.MyAccount ||= {}
class Locomotive.Views.MyAccount.EditView extends Locomotive.Views.Shared.FormView
el: '#content'
events:
'submit': 'save'
initialize: ->
@model = new Locomotive.Models.CurrentAccount(@options.account)
Backbone.ModelBinding.bind @
window.foo = @model
render: ->
super()
save: (event) ->
if @model.get('locale') == window.locale
@save_in_ajax(event)

View File

@ -84,6 +84,8 @@ form.formtastic {
color: #17171D;
font-size: 14px;
font-weight: bold;
@include locomotive-link;
}
.editable {
@ -373,6 +375,43 @@ form.formtastic {
}
} // > li#site_memberships_input
&#account_locale_input {
.entry {
float: left;
width: 212px;
margin-right: 10px;
&:nth-child(3n) {
margin-right: 0px;
}
label {
float: none;
display: inline-block;
width: auto;
position: relative;
padding-left: 31px;
margin-left: 8px;
img {
position: absolute;
top: 2px;
left: 0px;
}
}
}
} // > li#account_locale_input
&#account_sites_input {
.entry {
strong {
margin-right: 10px;
}
}
} // > li#account_sites_input
} // > li
} //ol

View File

@ -17,7 +17,7 @@ module Locomotive
before_filter :set_current_thread_variables
helper_method :sections, :current_site_public_url, :site_url, :public_page_url, :current_ability
helper_method :sections, :current_site_public_url, :switch_to_site_url, :public_page_url, :current_ability
# https://rails.lighthouseapp.com/projects/8994/tickets/1905-apphelpers-within-plugin-not-being-mixed-in
helper Locomotive::BaseHelper, Locomotive::ContentTypesHelper #, Locomotive::BoxHelper
@ -82,7 +82,7 @@ module Locomotive
request.protocol + request.host_with_port
end
def site_url(site, options = {})
def switch_to_site_url(site, options = {})
options = { :fullpath => true, :protocol => true }.merge(options)
url = "#{site.subdomain}.#{Locomotive.config.domain}"

View File

@ -1,6 +1,8 @@
module Locomotive
class LocaleInput < Formtastic::Inputs::TextInput
include Formtastic::Inputs::Base::Choices
def to_html
input_wrapping do
label_html <<
@ -18,10 +20,19 @@ module Locomotive
def locale_to_html(locale)
text = I18n.t("locomotive.my_account.edit.#{locale}")
builder.radio_button(:locale, locale) +
builder.radio_button(:locale, locale, :id => choice_input_dom_id(locale)) +
template.content_tag(:label,
template.image_tag("locomotive/icons/flags/#{locale}.png", :alt => text) +
text)
text, :for => choice_input_dom_id(locale))
end
def choice_input_dom_id(choice)
[
builder.custom_namespace,
sanitized_object_name,
association_primary_key || method,
choice_html_safe_value(choice)
].compact.reject { |i| i.blank? }.join("_")
end
end

View File

@ -45,7 +45,7 @@ module Locomotive
end
def as_json(options = {})
super((options || {}).merge(:only => [:name, :email, :memberships]))
Locomotive::AccountPresenter.new(self, options).as_json
end
protected

View File

@ -0,0 +1,11 @@
module Locomotive
class AccountPresenter < BasePresenter
delegate :name, :email, :locale, :to => :source
def included_methods
super + %w(name email locale)
end
end
end

View File

@ -1,4 +1,4 @@
- title link_to(@account.name.blank? ? @account.name_was : @account.name, '#', :rel => 'my_account_name', :title => t('.ask_for_name'), :class => 'editable')
- title link_to(@account.name.blank? ? @account.name_was : @account.name, '#', :rel => 'account_name', :title => t('.ask_for_name'), :class => 'editable')
- content_for :backbone_view_data do
:plain
@ -25,16 +25,16 @@
= f.input :password_confirmation, :input_html => { :autocomplete => 'off' }
- if multi_sites?
= f.inputs :name => :sites, :class => "sites inputs foldable #{'folded' if inputs_folded?(@account)}" do
%li.input.empty.no-label.last
= f.inputs :name => :sites, :class => "sites inputs foldable" do
%li#account_sites_input.input.empty.no-label.last
.list
- @account.sites.each do |site|
.entry
%strong= link_to site.name, site_url(site)
%strong= link_to site.name, switch_to_site_url(site)
%em= site.domains.join(', ')
- if admin_on?(site) && site != current_site
%span{ :class => 'actions' }
= link_to 'x', site_url(site), :class => 'remove first', :confirm => t('locomotive.messages.confirm'), :method => :delete
= link_to 'x', site_url(site), :class => 'remove', :confirm => t('locomotive.messages.confirm'), :method => :delete
= render 'locomotive/shared/form_actions', :button_label => :update

View File

@ -46,6 +46,7 @@ en:
_slug: Permalink
account:
edit:
locale: UI Language
password: New password
password_confirmation: New password confirmation
page:

View File

@ -47,6 +47,7 @@ fr:
_slug: Permalink
account:
edit:
locale: Langue UI
password: Nouveau mot de passe
password_confirmation: Confirmation nouveau mot de passe
page:

View File

@ -14,15 +14,15 @@ x editable_short_text => tinymce
x menu / submenu in full css3 (no images)
x fix css in firefox
x update page in ajax
- fix other sections
x edit my site
x css
x robots.txt
x domains
x roles
x save
- create a new site
- fix other sections
- edit my account
- create a new site
- theme assets
- content types

View File

@ -285,6 +285,16 @@ Backbone.ModelBinding = (function(Backbone, _, $){
var element = view.$(this);
var group_name = config.getBindingValue(element, 'radio');
// HACK (Did)
var attribute_name = group_name;
if (model.paramRoot) {
regexp = new RegExp('^' + model.paramRoot + "\\[");
attribute_name = attribute_name.replace(regexp, '').replace(/\]$/, '');
}
// console.log(attribute_name);
// console.log(group_name);
if (!foundElements[group_name]) {
foundElements[group_name] = true;
var bindingAttr = config.getBindingAttr('radio');
@ -305,7 +315,7 @@ Backbone.ModelBinding = (function(Backbone, _, $){
var elementChange = function(ev){
var element = view.$(ev.currentTarget);
if (element.is(":checked")){
setModelValue(group_name, element.val());
setModelValue(attribute_name, element.val());
}
};
@ -315,7 +325,7 @@ Backbone.ModelBinding = (function(Backbone, _, $){
modelBinder.registerElementBinding(groupEl, elementChange);
});
var attr_value = model.get(group_name);
var attr_value = model.get(attribute_name);
if (typeof attr_value !== "undefined" && attr_value !== null) {
// set the default value on the form, from the model
var value_selector = "input[type=radio][" + bindingAttr + "=" + group_name + "][value=" + attr_value + "]";
@ -324,7 +334,7 @@ Backbone.ModelBinding = (function(Backbone, _, $){
// set the model to the currently selected radio button
var value_selector = "input[type=radio][" + bindingAttr + "=" + group_name + "]:checked";
var value = view.$(value_selector).val();
setModelValue(group_name, value);
setModelValue(attribute_name, value);
}
}
});