Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bmichotte conflict #1

Merged
merged 9 commits into from
Jul 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ nbproject
.sass-cache
.idea
.dat*.*
Gemfile.lock
Gemfile.lock
.ruby-version
26 changes: 20 additions & 6 deletions app/controllers/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,40 +45,54 @@ def viewDidLoad
end
end

# Sheet with no message
acs.append(UIButton, :alert_controller_no_message).on(:tap) do
rmq.app.alert(message: nil, style: :sheet, actions: :yes_no_cancel ) do |action_type|
puts "you clicked #{action_type}"
end
end

##############################
# Field examples
##############################

# Text field example with :input style.
acs.append(UIButton, :alert_controller_fields_one).on(:tap) do
rmq.app.alert(title: "Text Field", message: "My style is :input", style: :input) do |action_type, fields|
puts "you entered '#{fields[:text].text}"
puts "you entered '#{fields[:text].text}'"
end
end

# Text field example with :secure style.
# Text field example with :input style and placeholder.
acs.append(UIButton, :alert_controller_fields_two).on(:tap) do
rmq.app.alert(title: "Text Field", message: "My style is :input", style: :input, placeholder: "Some Placeholder") do |action_type, fields|
puts "you entered '#{fields[:text].text}'"
end
end

# Text field example with :secure style.
acs.append(UIButton, :alert_controller_fields_three).on(:tap) do
rmq.app.alert(title: "Text Field", message: "My style is :secure", style: :secure) do |action_type, fields|
puts "you entered '#{fields[:text].text}'"
end
end

# Text field example with :login style.
acs.append(UIButton, :alert_controller_fields_three).on(:tap) do
acs.append(UIButton, :alert_controller_fields_four).on(:tap) do
rmq.app.alert(title: "Text Field", message: "My style is :login", style: :login) do |action_type, fields|
puts "you entered '#{fields[:login].text}' as the login and '#{fields[:password].text}' as the password"
end
end

# Text field example with :change_password style.
acs.append(UIButton, :alert_controller_fields_four).on(:tap) do
acs.append(UIButton, :alert_controller_fields_five).on(:tap) do
rmq.app.alert(title: "Text Field", message: "My style is :change_password", style: :change_password) do |action_type, fields|
puts "you entered '#{fields[:current_password].text}' as the current password and '#{fields[:new_password].text}' as the new password"
end
end

# Text field example with :custom style.
acs.append(UIButton, :alert_controller_fields_five).on(:tap) do
acs.append(UIButton, :alert_controller_fields_six).on(:tap) do
rmq.app.alert(title: "Text Field", message: "My style is :custom", style: :custom, fields:
{phone: {placeholder: 'Phone', keyboard_type: :phone_pad},
email: {placeholder: 'Email', secure: false, keyboard_type: :email_address}}) do |action_type, fields|
Expand Down Expand Up @@ -139,7 +153,7 @@ def viewDidLoad

# Alert from popover
acs.append(UIButton, :alert_from_popover).on(:tap) do |sender|
rmq.app.alert(title: "Popover", message: "Presented from popover", actions: [:ok], popover: sender)
rmq.app.alert(title: "Popover", message: "Presented from popover (if iPad)", actions: [:ok], popover: sender)
end

acs.append(UILabel, :template_tour)
Expand Down
18 changes: 14 additions & 4 deletions app/stylesheets/main_stylesheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,37 @@ def alert_controller_four st
st.text = "Title and :sheet Style"
end

def alert_controller_no_message st
basic_button(st)
st.text = ":sheet Style with no message"
end

def alert_controller_fields_one st
basic_button(st)
st.text = "Fields :input Style"
end

def alert_controller_fields_two st
basic_button(st)
st.text = "Fields :secure Style"
st.text = "Fields :input w/ placeholder"
end

def alert_controller_fields_three st
basic_button(st)
st.text = "Fields :login Style"
st.text = "Fields :secure Style"
end

def alert_controller_fields_four st
basic_button(st)
st.text = "Fields :change_password Style"
st.text = "Fields :login Style"
end

def alert_controller_fields_five st
basic_button(st)
st.text = "Fields :change_password Style"
end

def alert_controller_fields_six st
basic_button(st)
st.text = "Fields :custom Style"
end
Expand All @@ -105,7 +115,7 @@ def custom_actions_helper_sheet st

def alert_from_popover st
basic_button(st)
st.text = "Alert From Popover"
st.text = "Alert From Popover on iPad"
end

def usage_tour st
Expand Down
6 changes: 3 additions & 3 deletions lib/project/field_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class App
# 2 - Add the test
# 3 - Add symbol to the README.md list

def self.add_template_fieldset(template)
def self.add_template_fieldset(template, opts={})

login = NSLocalizedString("Login", nil)
password = NSLocalizedString("Password", nil)
Expand All @@ -19,13 +19,13 @@ def self.add_template_fieldset(template)
fieldset[:alert_view_style] = UIAlertViewStylePlainTextInput
fieldset[:fields] =
[
rmq.app.make_field(:text, keyboard_type: :default, secure_text_entry: false, placeholder: '')
rmq.app.make_field(:text, keyboard_type: :default, secure_text_entry: false, placeholder: opts.fetch(:placeholder,''))
]
when :secure
fieldset[:alert_view_style] = UIAlertViewStyleSecureTextInput
fieldset[:fields] =
[
rmq.app.make_field(:text, keyboard_type: :default, secure_text_entry: true, placeholder: '')
rmq.app.make_field(:text, keyboard_type: :default, secure_text_entry: true, placeholder: opts.fetch(:placeholder,''))
]
when :login
fieldset[:alert_view_style] = UIAlertViewStyleLoginAndPasswordInput
Expand Down
11 changes: 8 additions & 3 deletions lib/project/red_alert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ def alert(opts={}, &block)
# ------------------------------------
opts = {message: opts} if opts.is_a? String
opts = {style: :alert, animated: true, show_now: true}.merge(opts)
opts[:message] = opts[:message] ? opts[:message].to_s : NSLocalizedString("Alert!", nil)
# Ability to make no message
opts[:message] = if opts.has_key?(:message)
opts[:message].nil? ? nil : opts[:message].to_s
else
NSLocalizedString("Alert!", nil)
end

style = VALID_STYLES.include?(opts[:style]) ? opts[:style] : :alert
# force the style to :sheet if :popover
# force the style to :sheet if :popover on ipad (needed for popover)
style = :sheet if opts[:popover] and rmq.device.ipad?
opts[:style] = style
opts[:fields] = opts[:style] == :custom && opts[:fields] ? opts[:fields] : {text: {placeholder: ''}}
Expand Down Expand Up @@ -51,7 +56,7 @@ def alert(opts={}, &block)
fieldset = {alert_view_style: UIAlertViewStyleDefault, fields: []}

if TEMPLATE_FIELD_STYLES.include?(opts[:style])
fieldset = add_template_fieldset(opts[:style])
fieldset = add_template_fieldset(opts[:style], opts)
elsif opts[:style] == :custom
fieldset = custom_fieldset(opts[:api], opts[:fields])
end
Expand Down
20 changes: 16 additions & 4 deletions spec/field_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
field.placeholder.should == ""
end

it "should have a placeholder when specified" do
a = RubyMotionQuery::App.add_template_fieldset(:input, {placeholder: "test placeholder"})
field = a[:fields].first
field.placeholder.should == "test placeholder"
end

end

describe ":secure" do
Expand All @@ -29,6 +35,12 @@
field.placeholder.should == ""
end

it "should have a placeholder when specified" do
a = RubyMotionQuery::App.add_template_fieldset(:secure, {placeholder: "secure test placeholder"})
field = a[:fields].first
field.placeholder.should == "secure test placeholder"
end

end

describe ":login" do
Expand All @@ -42,11 +54,11 @@
login.name.should == :login
login.keyboard_type.should == :email_address
login.secure_text_entry.should == false
login.placeholder.should == "Login"
login.placeholder.should == NSLocalizedString("Login", nil)
password.name.should == :password
password.keyboard_type.should == :default
password.secure_text_entry.should == true
password.placeholder.should == "Password"
password.placeholder.should == NSLocalizedString("Password", nil)
end

end
Expand All @@ -62,11 +74,11 @@
current_password.name.should == :current_password
current_password.keyboard_type.should == :default
current_password.secure_text_entry.should == true
current_password.placeholder.should == "Current Password"
current_password.placeholder.should == NSLocalizedString("Current Password", nil)
new_password.name.should == :new_password
new_password.keyboard_type.should == :default
new_password.secure_text_entry.should == true
new_password.placeholder.should == "New Password"
new_password.placeholder.should == NSLocalizedString("New Password", nil)
end

end
Expand Down
4 changes: 4 additions & 0 deletions spec/red_alert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
@provider.alert_controller.message.should == "hello"
end

it "allows an empty message" do
@provider = rmq.app.alert(message: nil, show_now: false, animated: false)
@provider.alert_controller.message.should == nil
end
end

describe "UIActionSheet Hosted" do
Expand Down