Fix bug: users can now be saved
This commit is contained in:
parent
0a6efeb0a2
commit
d9d7099da6
|
@ -0,0 +1,12 @@
|
||||||
|
module Panel::UserHelper
|
||||||
|
|
||||||
|
def show_user_attribute(object, key, locale = '')
|
||||||
|
attribute = object.attribute_values.detect {|av| av.key.to_s.eql?(key.to_s) || av[locale.to_s].eql?(locale.to_s) }
|
||||||
|
if locale.to_s.blank?
|
||||||
|
attribute['key']
|
||||||
|
else
|
||||||
|
attribute[locale.to_s]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -11,7 +11,7 @@ class AttributeModel
|
||||||
field :built_in, :type => Boolean, :default => false
|
field :built_in, :type => Boolean, :default => false
|
||||||
field :disabled, :type => Boolean, :default => false
|
field :disabled, :type => Boolean, :default => false
|
||||||
|
|
||||||
embedded_in :user_attribute_model, :inverse_of => :attribute_models
|
embedded_in :user_attribute_model
|
||||||
validates_uniqueness_of :key
|
validates_uniqueness_of :key
|
||||||
|
|
||||||
# Destroy the i18n_variable
|
# Destroy the i18n_variable
|
||||||
|
|
|
@ -7,7 +7,7 @@ class UserAttribute
|
||||||
has_many :attribute_values
|
has_many :attribute_values
|
||||||
|
|
||||||
# Update or create the attribute_value records
|
# Update or create the attribute_value records
|
||||||
def attributes=(*args)
|
def attribute_values=(*args)
|
||||||
args[0].each do |value|
|
args[0].each do |value|
|
||||||
if value[:id].blank?
|
if value[:id].blank?
|
||||||
attribute_values.build(value)
|
attribute_values.build(value)
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
<td><%= attr.i18n_variable[I18n.locale] %></td>
|
<td><%= attr.i18n_variable[I18n.locale] %></td>
|
||||||
<td>
|
<td>
|
||||||
<% if attr["locale"] && attr["markup"] == 'text_field' %>
|
<% if attr["locale"] && attr["markup"] == 'text_field' %>
|
||||||
<%= show_user_attribute["#{attr.key}_#{I18n.locale}"] rescue nil %>
|
<%= show_user_attribute(object, attr.key, I18n.locale) %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= show_user_attribute["#{attr.key}"] rescue nil %>
|
<%= show_user_attribute(object, attr.key) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -14,23 +14,23 @@
|
||||||
|
|
||||||
<% ua.get_enabled_attribute_models.each do |attr| %>
|
<% ua.get_enabled_attribute_models.each do |attr| %>
|
||||||
<% value = user_attribute.attribute_values.detect{|v| v.key == attr.key } %>
|
<% value = user_attribute.attribute_values.detect{|v| v.key == attr.key } %>
|
||||||
<%= hidden_field_tag "user[user_#{type}s][][attributes][][id]", value.id rescue nil %>
|
<%= hidden_field_tag "user[user_#{type}s][][attribute_values][][id]", value.id rescue nil %>
|
||||||
<%= hidden_field_tag "user[user_#{type}s][][attributes][][key]", attr.key %>
|
<%= hidden_field_tag "user[user_#{type}s][][attribute_values][][key]", attr.key %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= attr.i18n_variable[I18n.locale] %></td>
|
<td><%= attr.i18n_variable[I18n.locale] %></td>
|
||||||
<% if attr["locale"] && attr["markup"] == 'text_field' %>
|
<% if attr["locale"] && attr["markup"] == 'text_field' %>
|
||||||
<%= hidden_field_tag "user[user_#{type}s][][attributes][][non_locale]", nil %>
|
<%= hidden_field_tag "user[user_#{type}s][][attribute_values][][non_locale]", nil %>
|
||||||
<% @site_valid_locales.each do |locale| %>
|
<% @site_valid_locales.each do |locale| %>
|
||||||
<td>
|
<td>
|
||||||
<%= text_field_tag "user[user_#{type}s][][attributes][][#{locale}]", (value[locale] rescue nil) %>
|
<%= text_field_tag "user[user_#{type}s][][attribute_values][][#{locale}]", (value[locale] rescue nil) %>
|
||||||
</td>
|
</td>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% else %>
|
<% else %>
|
||||||
<td colspan=<%= @site_valid_locales.size %>>
|
<td colspan=<%= @site_valid_locales.size %>>
|
||||||
<% if attr["markup"] == "text_field" %>
|
<% if attr["markup"] == "text_field" %>
|
||||||
<%= text_field_tag "user[user_#{type}s][][attributes][][non_locale]", (value['non_locale'] rescue nil) %>
|
<%= text_field_tag "user[user_#{type}s][][attribute_values][][non_locale]", (value['non_locale'] rescue nil) %>
|
||||||
<% elsif attr["markup"] == "select" %>
|
<% elsif attr["markup"] == "select" %>
|
||||||
<%= select_tag "user[user_#{type}s][][attributes][][non_locale]", options_for_select(attr["options"], value['non_locale']) %>
|
<%= select_tag "user[user_#{type}s][][attribute_values][][non_locale]", options_for_select(attr["options"], value['non_locale']) %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
</td>
|
</td>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
|
@ -14,9 +14,7 @@
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><%= t('panel.infos') %></legend>
|
<legend><%= t('panel.infos') %></legend>
|
||||||
<% @user_info_models.each do |am| %>
|
<% @user_info_models.each do |am| %>
|
||||||
<%= render :partial => 'show_user_attribute',
|
<%= render :partial => 'show_user_attribute', :locals => {:am => am, :object => @user.get_info_from_model_key(am.key)} %>
|
||||||
:object => @user.get_info_from_model_key(am.key),
|
|
||||||
:locals => {:am => am} %>
|
|
||||||
<% end -%>
|
<% end -%>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -25,9 +23,7 @@
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><%= t('panel.roles') %></legend>
|
<legend><%= t('panel.roles') %></legend>
|
||||||
<% @user.get_active_role_models.each do |am| %>
|
<% @user.get_active_role_models.each do |am| %>
|
||||||
<%= render :partial => 'show_user_attribute',
|
<%= render :partial => 'show_user_attribute', :locals => {:am => am, :object => @user.get_role_from_model_key(am.key)} %>
|
||||||
:object => @user.get_role_from_model_key(am.key),
|
|
||||||
:locals => {:am => am} %>
|
|
||||||
<% end -%>
|
<% end -%>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -31,8 +31,8 @@ class CentralServerExchangeApp < Sinatra::Base
|
||||||
post '/purchase/design' do
|
post '/purchase/design' do
|
||||||
begin
|
begin
|
||||||
private_key = OpenSSL::PKey::RSA.new(@site.private_key)
|
private_key = OpenSSL::PKey::RSA.new(@site.private_key)
|
||||||
design = PDesign.new.from_json(private_key.private_decrypt(request.params['purchase']))
|
p_design = PDesign.new.from_json(private_key.private_decrypt(request.params['purchase']))
|
||||||
design.save
|
p_design.save
|
||||||
body 'true'
|
body 'true'
|
||||||
rescue
|
rescue
|
||||||
body 'false'
|
body 'false'
|
||||||
|
|
Loading…
Reference in New Issue