done (for now) with the my account screen
This commit is contained in:
parent
99d756f550
commit
fb0e87c64d
@ -1 +1,11 @@
|
|||||||
class Locomotive.Models.Account extends Backbone.Model
|
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"
|
||||||
|
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
|
@ -84,6 +84,8 @@ form.formtastic {
|
|||||||
color: #17171D;
|
color: #17171D;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
|
||||||
|
@include locomotive-link;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editable {
|
.editable {
|
||||||
@ -373,6 +375,43 @@ form.formtastic {
|
|||||||
}
|
}
|
||||||
} // > li#site_memberships_input
|
} // > 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
|
} // > li
|
||||||
|
|
||||||
} //ol
|
} //ol
|
||||||
|
@ -17,7 +17,7 @@ module Locomotive
|
|||||||
|
|
||||||
before_filter :set_current_thread_variables
|
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
|
# https://rails.lighthouseapp.com/projects/8994/tickets/1905-apphelpers-within-plugin-not-being-mixed-in
|
||||||
helper Locomotive::BaseHelper, Locomotive::ContentTypesHelper #, Locomotive::BoxHelper
|
helper Locomotive::BaseHelper, Locomotive::ContentTypesHelper #, Locomotive::BoxHelper
|
||||||
@ -82,7 +82,7 @@ module Locomotive
|
|||||||
request.protocol + request.host_with_port
|
request.protocol + request.host_with_port
|
||||||
end
|
end
|
||||||
|
|
||||||
def site_url(site, options = {})
|
def switch_to_site_url(site, options = {})
|
||||||
options = { :fullpath => true, :protocol => true }.merge(options)
|
options = { :fullpath => true, :protocol => true }.merge(options)
|
||||||
|
|
||||||
url = "#{site.subdomain}.#{Locomotive.config.domain}"
|
url = "#{site.subdomain}.#{Locomotive.config.domain}"
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
module Locomotive
|
module Locomotive
|
||||||
class LocaleInput < Formtastic::Inputs::TextInput
|
class LocaleInput < Formtastic::Inputs::TextInput
|
||||||
|
|
||||||
|
include Formtastic::Inputs::Base::Choices
|
||||||
|
|
||||||
def to_html
|
def to_html
|
||||||
input_wrapping do
|
input_wrapping do
|
||||||
label_html <<
|
label_html <<
|
||||||
@ -18,10 +20,19 @@ module Locomotive
|
|||||||
def locale_to_html(locale)
|
def locale_to_html(locale)
|
||||||
text = I18n.t("locomotive.my_account.edit.#{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.content_tag(:label,
|
||||||
template.image_tag("locomotive/icons/flags/#{locale}.png", :alt => text) +
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -45,7 +45,7 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
|
|
||||||
def as_json(options = {})
|
def as_json(options = {})
|
||||||
super((options || {}).merge(:only => [:name, :email, :memberships]))
|
Locomotive::AccountPresenter.new(self, options).as_json
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
11
app/presenters/locomotive/account_presenter.rb
Normal file
11
app/presenters/locomotive/account_presenter.rb
Normal 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
|
@ -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
|
- content_for :backbone_view_data do
|
||||||
:plain
|
:plain
|
||||||
@ -25,16 +25,16 @@
|
|||||||
= f.input :password_confirmation, :input_html => { :autocomplete => 'off' }
|
= f.input :password_confirmation, :input_html => { :autocomplete => 'off' }
|
||||||
|
|
||||||
- if multi_sites?
|
- if multi_sites?
|
||||||
= f.inputs :name => :sites, :class => "sites inputs foldable #{'folded' if inputs_folded?(@account)}" do
|
= f.inputs :name => :sites, :class => "sites inputs foldable" do
|
||||||
%li.input.empty.no-label.last
|
%li#account_sites_input.input.empty.no-label.last
|
||||||
.list
|
.list
|
||||||
- @account.sites.each do |site|
|
- @account.sites.each do |site|
|
||||||
.entry
|
.entry
|
||||||
%strong= link_to site.name, site_url(site)
|
%strong= link_to site.name, switch_to_site_url(site)
|
||||||
%em= site.domains.join(', ')
|
%em= site.domains.join(', ')
|
||||||
|
|
||||||
- if admin_on?(site) && site != current_site
|
- if admin_on?(site) && site != current_site
|
||||||
%span{ :class => 'actions' }
|
%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
|
= render 'locomotive/shared/form_actions', :button_label => :update
|
||||||
|
@ -46,6 +46,7 @@ en:
|
|||||||
_slug: Permalink
|
_slug: Permalink
|
||||||
account:
|
account:
|
||||||
edit:
|
edit:
|
||||||
|
locale: UI Language
|
||||||
password: New password
|
password: New password
|
||||||
password_confirmation: New password confirmation
|
password_confirmation: New password confirmation
|
||||||
page:
|
page:
|
||||||
|
@ -47,6 +47,7 @@ fr:
|
|||||||
_slug: Permalink
|
_slug: Permalink
|
||||||
account:
|
account:
|
||||||
edit:
|
edit:
|
||||||
|
locale: Langue UI
|
||||||
password: Nouveau mot de passe
|
password: Nouveau mot de passe
|
||||||
password_confirmation: Confirmation nouveau mot de passe
|
password_confirmation: Confirmation nouveau mot de passe
|
||||||
page:
|
page:
|
||||||
|
14
doc/TODO
14
doc/TODO
@ -14,15 +14,15 @@ x editable_short_text => tinymce
|
|||||||
x menu / submenu in full css3 (no images)
|
x menu / submenu in full css3 (no images)
|
||||||
x fix css in firefox
|
x fix css in firefox
|
||||||
x update page in ajax
|
x update page in ajax
|
||||||
|
x edit my site
|
||||||
|
x css
|
||||||
|
x robots.txt
|
||||||
|
x domains
|
||||||
|
x roles
|
||||||
|
x save
|
||||||
- fix other sections
|
- fix other sections
|
||||||
x edit my site
|
|
||||||
x css
|
|
||||||
x robots.txt
|
|
||||||
x domains
|
|
||||||
x roles
|
|
||||||
x save
|
|
||||||
- create a new site
|
|
||||||
- edit my account
|
- edit my account
|
||||||
|
- create a new site
|
||||||
- theme assets
|
- theme assets
|
||||||
- content types
|
- content types
|
||||||
|
|
||||||
|
@ -285,6 +285,16 @@ Backbone.ModelBinding = (function(Backbone, _, $){
|
|||||||
var element = view.$(this);
|
var element = view.$(this);
|
||||||
|
|
||||||
var group_name = config.getBindingValue(element, 'radio');
|
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]) {
|
if (!foundElements[group_name]) {
|
||||||
foundElements[group_name] = true;
|
foundElements[group_name] = true;
|
||||||
var bindingAttr = config.getBindingAttr('radio');
|
var bindingAttr = config.getBindingAttr('radio');
|
||||||
@ -305,7 +315,7 @@ Backbone.ModelBinding = (function(Backbone, _, $){
|
|||||||
var elementChange = function(ev){
|
var elementChange = function(ev){
|
||||||
var element = view.$(ev.currentTarget);
|
var element = view.$(ev.currentTarget);
|
||||||
if (element.is(":checked")){
|
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);
|
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) {
|
if (typeof attr_value !== "undefined" && attr_value !== null) {
|
||||||
// set the default value on the form, from the model
|
// set the default value on the form, from the model
|
||||||
var value_selector = "input[type=radio][" + bindingAttr + "=" + group_name + "][value=" + attr_value + "]";
|
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
|
// set the model to the currently selected radio button
|
||||||
var value_selector = "input[type=radio][" + bindingAttr + "=" + group_name + "]:checked";
|
var value_selector = "input[type=radio][" + bindingAttr + "=" + group_name + "]:checked";
|
||||||
var value = view.$(value_selector).val();
|
var value = view.$(value_selector).val();
|
||||||
setModelValue(group_name, value);
|
setModelValue(attribute_name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user