Skip to content

Commit

Permalink
Added required cms tag to publications. Added user edit account parag…
Browse files Browse the repository at this point in the history
…raph. Added country_select to styled form builder. Various fixes for user registration paragraph.
  • Loading branch information
Doug Youch committed Feb 17, 2010
1 parent 25ec5ce commit 99f2404
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 37 deletions.
137 changes: 134 additions & 3 deletions app/controllers/editor/auth_controller.rb
Expand Up @@ -14,6 +14,8 @@ class Editor::AuthController < ParagraphController #:nodoc:all

editor_for :user_activation, :name => 'User Activation', :feature => 'user_activation', :triggers => [ ['Successful Activation','action'] ]

editor_for :user_edit_account, :name => 'User Edit Account', :feature => 'user_edit_account', :triggers => [ ['Edit Account','action' ]]

editor_for :edit_account, :name => 'Edit Account', :triggers => [ ['Edit Profile','action' ]]


Expand Down Expand Up @@ -69,7 +71,7 @@ def available_field_list
:middle_name => ['Middle Name'.t,:text_field,:middle_name],
:last_name => ['Last Name'.t,:text_field,:last_name],
:gender => ['Gender'.t, :radio_buttons, :gender, { :options => [ ['Male'.t,'m'],['Female'.t,'f' ] ] } ],
:introduction => ['Introduction'.t, :radio_buttons, :gender, { :options => [ ['Mr.'.t,'Mr.'],['Mrs.'.t,'Mrs' ], ['Ms.'.t, 'Ms'] ] } ],
:introduction => ['Introduction'.t, :radio_buttons, :introduction, { :options => [ ['Mr.'.t,'Mr.'],['Mrs.'.t,'Mrs.' ], ['Ms.'.t, 'Ms.'] ] } ],
:username => [ 'Username'.t,:text_field, :username ],
:salutation => [ 'Salutation'.t,:text_field, :salutation ]
}
Expand All @@ -94,7 +96,7 @@ def all_field_list
def any_field_list
flds = available_field_list
fields = (self.required_fields + self.optional_fields).uniq
['password','password_confirmation','email'].each do |fld|
['password_confirmation','password','email'].each do |fld|
fields.unshift(fld) if !fields.include?(fld)
end
fields.map { |elm| flds[elm.to_sym] ? [ elm.to_sym, flds[elm.to_sym] ] : nil }.compact
Expand Down Expand Up @@ -129,7 +131,8 @@ def available_address_field_list
:address_2 => [ 'Address (Line 2)'.t, :text_field,:address_2],
:city => [ 'City'.t, :text_field,:city],
:state => [ 'State'.t, :select,:state,{ :options => ContentModel.state_select_options } ],
:zip => [ 'Zip Code'.t, :text_field,:zip]
:zip => [ 'Zip Code'.t, :text_field,:zip],
:country => [ 'Country'.t, :country_select, :country]
}
end

Expand Down Expand Up @@ -183,6 +186,134 @@ class UserActivationOptions < HashModel
boolean_options :require_acceptance, :login_after_activation
end

class UserEditAccountOptions < HashModel

# For feature stuff
include HandlerActions


attributes :required_fields => [ ],
:optional_fields => [ 'first_name','last_name'],
:success_page_id => nil,
:include_subscriptions => [], :country => 'United States', :add_tags => '',
:work_address_required_fields => [],
:address_required_fields => [],
:content_publication_id => nil, :content_publication_user_field => nil

page_options :success_page_id

def validate
if self.content_publication_id
errors.add(:content_publication_user_field) unless self.content_publication_user_field
end
end

def available_field_list
{ :email => [ 'Email'.t,:text_field, :email ],
:password => [ 'Reset Password'.t, :password_field, :password ],
:password_confirmation => [ 'Confirm Password'.t, :password_field, :password_confirmation ],
:first_name => ['First Name'.t,:text_field,:first_name],
:middle_name => ['Middle Name'.t,:text_field,:middle_name],
:last_name => ['Last Name'.t,:text_field,:last_name],
:gender => ['Gender'.t, :radio_buttons, :gender, { :options => [ ['Male'.t,'m'],['Female'.t,'f' ] ] } ],
:introduction => ['Introduction'.t, :radio_buttons, :introduction, { :options => [ ['Mr.'.t,'Mr.'],['Mrs.'.t,'Mrs.' ], ['Ms.'.t, 'Ms.'] ] } ],
:username => [ 'Username'.t,:text_field, :username ],
:salutation => [ 'Salutation'.t,:text_field, :salutation ]
}
end

def available_optional_field_options
opts = available_field_list
opts.delete(:email)
opts.delete(:password)
opts.delete(:password_confirmation)
opts.map { |elm| [ elm[1][0],elm[0].to_s ] }.sort
end

def available_field_options
available_field_list.to_a.map { |elm| [ elm[1][0],elm[0].to_s ] }.sort
end

def all_field_list
available_field_list.to_a
end

def any_field_list
flds = available_field_list
fields = (self.required_fields + self.optional_fields).uniq
['password_confirmation','password','email'].each do |fld|
fields.unshift(fld) if !fields.include?(fld)
end
fields.map { |elm| flds[elm.to_sym] ? [ elm.to_sym, flds[elm.to_sym] ] : nil }.compact
end

def always_required_fields
flds = [ 'email', 'password', 'password_confirmation' ]
end

def required_field_list
flds = available_field_list
fields = (self.required_fields).uniq
['password_confirmation','password','email'].each do |fld|
fields.unshift(fld) if !fields.include?(fld)
end
fields.map { |elm| flds[elm.to_sym] ? [ elm.to_sym, flds[elm.to_sym] ] : nil }.compact
end

def optional_field_list
flds = available_field_list
fields = (self.optional_fields).uniq
fields.map { |elm| flds[elm.to_sym] ? [ elm.to_sym, flds[elm.to_sym] ] : nil }.compact
end

def available_address_field_list
{
:company => [ 'Company'.t, :text_field,:company],
:phone => [ 'Phone'.t, :text_field,:phone],
:fax => [ 'Fax'.t, :text_field,:fax],
:address => [ 'Address'.t, :text_field,:address],
:address_2 => [ 'Address (Line 2)'.t, :text_field,:address_2],
:city => [ 'City'.t, :text_field,:city],
:state => [ 'State'.t, :select,:state,{ :options => ContentModel.state_select_options } ],
:zip => [ 'Zip Code'.t, :text_field,:zip],
:country => [ 'Country'.t, :country_select, :country]
}
end

def available_address_field_options(business = false)
flds = available_address_field_list
if(!business)
flds.delete(:company)
end
flds.to_a.map { |elm| [ elm[1][0],elm[0].to_s ] }.sort
end

def address_field_list
hsh = available_address_field_list
hsh.delete(:company)
hsh.to_a
end

def business_address_field_list
available_address_field_list.to_a
end

def content_model
if publication
@content_mode ||= @pub.conten_model
else
nil
end
end

def publication
@pub ||= ContentPublication.find_by_id(self.content_publication_id)
end

def publication_field_options
self.publication.content_model.content_model_fields.find(:all, :conditions => "field_type = 'belongs_to' AND field_module = 'content/core_field'").collect { |elm| [elm.name, elm.field] } if self.publication
end
end

class LoginOptions < HashModel
default_options :login_type => 'email',:success_page => nil, :forward_login => 'no',:failure_page => nil
Expand Down
80 changes: 74 additions & 6 deletions app/controllers/editor/auth_feature.rb
Expand Up @@ -11,14 +11,14 @@ class Editor::AuthFeature < ParagraphFeature #:nodoc:all
<!-- enter form elements directly -->
<div class='item'>
<cms:email_error><div class='error'><cms:value/></div></cms:email_error>
<div class='label'>Email:</div>
<div class='label'>Email*:</div>
<div class='field'><cms:email/></div>
</div>
<cms:any_field except='email'>
<div class='item'>
<cms:error><div class='error'><cms:value/></div></cms:error>
<div class='label'><cms:label/>*:</div>
<div class='label'><cms:label/><cms:required>*</cms:required>:</div>
<div class='field'><cms:control/></div>
</div>
</cms:any_field>
Expand All @@ -44,18 +44,18 @@ def user_register_feature(data)
end

['any_field','required_field','optional_field'].each do |fields|
user_fields_helper('register',c,fields,data)
user_fields_helper('register',c,fields,data,(data[:options].always_required_fields + data[:options].required_fields))
end

c.fields_for_tag('register:address',:address) { |t| data[:address] ? data[:address] : nil }
user_fields_helper('register:address',c,'address_field',data)
user_fields_helper('register:address',c,'address_field',data,data[:options].address_required_fields)

data[:options].address_field_list.each do |fld|
c.field_tag("register:address:#{fld[0]}",{ :control => fld[1][1]}.merge(fld[1][3]||{}))
end

c.fields_for_tag('register:business',:business) { |t| data[:business] ? data[:business] : nil }
user_fields_helper('register:business',c,'business_address_field',data)
user_fields_helper('register:business',c,'business_address_field',data,data[:options].work_address_required_fields)

data[:options].business_address_field_list.each do |fld|
c.field_tag("register:business:#{fld[0]}",{ :control => fld[1][1]}.merge(fld[1][3]||{}))
Expand All @@ -75,10 +75,75 @@ def user_register_feature(data)
end


feature :user_edit_account, :default_feature => <<-FEATURE
<cms:edit>
<cms:updated>Account Updated.</cms:updated>
<!-- enter form elements directly -->
<div class='item'>
<cms:email_error><div class='error'><cms:value/></div></cms:email_error>
<div class='label'>Email*:</div>
<div class='field'><cms:email/></div>
</div>
<cms:any_field except='email'>
<div class='item'>
<cms:error><div class='error'><cms:value/></div></cms:error>
<div class='label'><cms:label/><cms:required>*</cms:required>:</div>
<div class='field'><cms:control/></div>
</div>
</cms:any_field>
<!-- optional fields except='field1' or fields="field1,field2" options work too -->
<cms:submit/>
</cms:edit>
FEATURE

def user_edit_account_feature(data)
webiva_custom_feature(:user_edit_account,data) do |c|6
c.form_for_tag('edit',:user) { |t| data[:usr] ? data[:usr] : nil }

c.expansion_tag('edit:errors') { |t| data[:failed] }
c.expansion_tag('edit:updated') { |t| data[:updated] }

data[:options].all_field_list.each do |fld|
c.field_tag("edit:#{fld[0]}",{ :control => fld[1][1]}.merge(fld[1][3]||{}))
end

['any_field','required_field','optional_field'].each do |fields|
user_fields_helper('edit',c,fields,data,(data[:options].always_required_fields + data[:options].required_fields))
end

c.fields_for_tag('edit:address',:address) { |t| data[:address] ? data[:address] : nil }
user_fields_helper('edit:address',c,'address_field',data,data[:options].address_required_fields)

data[:options].address_field_list.each do |fld|
c.field_tag("edit:address:#{fld[0]}",{ :control => fld[1][1]}.merge(fld[1][3]||{}))
end

c.fields_for_tag('edit:business',:business) { |t| data[:business] ? data[:business] : nil }
user_fields_helper('edit:business',c,'business_address_field',data,data[:options].work_address_required_fields)

data[:options].business_address_field_list.each do |fld|
c.field_tag("edit:business:#{fld[0]}",{ :control => fld[1][1]}.merge(fld[1][3]||{}))
end

def user_fields_helper(prefix,c,fields_name,data)
if data[:options].publication
c.fields_for_tag('edit:publication',:model) { |t| data[:model] }
c.publication_field_tags("edit:publication",data[:options].publication)
end

c.button_tag('edit:submit')
end
end



def user_fields_helper(prefix,c,fields_name,data,required_fields=[])
c.loop_tag("#{prefix}:#{fields_name}") do |t|
fields = data[:options].send("#{fields_name}_list") || []
if t.attr['except']
Expand All @@ -101,6 +166,9 @@ def user_fields_helper(prefix,c,fields_name,data)
c.value_tag("#{prefix}:#{fields_name}:error") do |t|
c.form_field_error_tag_helper(t,t.locals.form, t.locals.send(fields_name)[0].to_s)
end
c.expansion_tag("#{prefix}:#{fields_name}:required") do |t|
required_fields.include? t.locals.send(fields_name)[0].to_s
end
end


Expand Down

0 comments on commit 99f2404

Please sign in to comment.