Skip to content

Commit

Permalink
added show_on_list for create and backfilled tests for create
Browse files Browse the repository at this point in the history
  • Loading branch information
yairgo committed Dec 26, 2008
1 parent 6d3f163 commit 501611f
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
9 changes: 4 additions & 5 deletions frontends/default/views/create.rjs
@@ -1,5 +1,4 @@
cancel_selector = "##{element_form_id(:action => :create)} a.cancel".to_json

new_link_selector = "##{action_link_id('new', nil)}".to_json
if controller.send :successful?
if @insert_row
page.insert_html :top, active_scaffold_tbody_id, :partial => 'list_record', :locals => {:record => @record}
Expand All @@ -9,16 +8,16 @@ if controller.send :successful?
end

if (active_scaffold_config.create.persistent)
page << "$$(#{cancel_selector}).first().link.reload();"
page << "$$(#{new_link_selector}).first().action_link.reload();"
else
page << "$$(#{cancel_selector}).first().link.close#{'_with_refresh' unless @insert_row}();"
page << "$$(#{new_link_selector}).first().action_link.close#{'_with_refresh' unless @insert_row}();"
end
if (active_scaffold_config.create.edit_after_create)
page << "var link = $('#{action_link_id 'edit', @record.id}');"
page << "if (link) (function() { link.action_link.open() }).defer();"
end
else
page << "l = $$(#{cancel_selector}).first().link;"
page << "l = $$(#{new_link_selector}).first().action_link;"
page.replace element_form_id(:action => :create), :partial => 'create_form'
page << "l.register_cancel_hooks();"
end
7 changes: 7 additions & 0 deletions frontends/default/views/list.rhtml
Expand Up @@ -23,3 +23,10 @@ ActiveScaffold.server_error_response = '<p class="error-message message">'
+ '</a>'
+ '</p>';
</script>
<% if active_scaffold_config.create.show_on_list %>
<script type="text/javascript">
<% link = action_link_id('new', nil) %>
$$("#<%= link %>").first().action_link.open()
</script>
<% end %>

8 changes: 8 additions & 0 deletions lib/active_scaffold/config/create.rb
Expand Up @@ -4,6 +4,7 @@ class Create < Form
def initialize(*args)
super
self.persistent = self.class.persistent
self.show_on_list = self.class.show_on_list
self.edit_after_create = self.class.edit_after_create
end

Expand All @@ -18,6 +19,10 @@ def self.link=(val)
end
@@link = ActiveScaffold::DataStructures::ActionLink.new('new', :label => 'Create New', :type => :table, :security_method => :create_authorized?)

# whether the create form is initially displayed on list or not
cattr_accessor :show_on_list
@@show_on_list = false

# whether the form stays open after a create or not
cattr_accessor :persistent
@@persistent = false
Expand All @@ -33,6 +38,9 @@ def label
@label ? as_(@label) : as_('Create %s', @core.label.singularize)
end

# whether the create form is initially displayed on list or not
attr_accessor :show_on_list

# whether the form stays open after a create or not
attr_accessor :persistent

Expand Down
61 changes: 61 additions & 0 deletions test/config/create_test.rb
@@ -0,0 +1,61 @@
require File.join(File.dirname(__FILE__), '../test_helper.rb')

class Config::CreateTest < Test::Unit::TestCase
def setup
@config = ActiveScaffold::Config::Core.new :model_stub
@default_link = @config.create.link
end

def teardown
@config.create.link = @default_link
end

def test_default_options
assert !@config.create.show_on_list
assert !@config.create.persistent
assert !@config.create.edit_after_create
assert_equal 'Create Model Stub', @config.create.label
end

def test_link_defaults
link = @config.create.link
assert !link.page?
assert !link.popup?
assert !link.confirm?
assert_equal "new", link.action
assert_equal "Create New", link.label
assert link.inline?
blank = {}
assert_equal blank, link.html_options
assert_equal :get, link.method
assert_equal :table, link.type
assert_equal :create, link.crud_type
assert_equal :create_authorized?, link.security_method
end

def test_setting_link
@config.create.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys')
assert_not_equal(@default_link, @config.create.link)
end

def test_label
label = 'create new monkeys'
@config.create.label = label
assert_equal label, @config.create.label
end

def test_show_on_list
@config.create.show_on_list = true
assert @config.create.show_on_list
end

def test_persistent
@config.create.persistent = true
assert @config.create.persistent
end

def test_edit_after_create
@config.create.edit_after_create = true
assert @config.create.edit_after_create
end
end

0 comments on commit 501611f

Please sign in to comment.