typus 3.0.10 → 3.0.11.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/Gemfile +9 -5
- data/README.md +17 -53
- data/app/assets/vendor/typus/javascripts/application.js +2 -0
- data/app/assets/vendor/typus/javascripts/jquery.application.js +29 -0
- data/app/assets/vendor/typus/javascripts/jquery.rails.autocomplete.js +32 -0
- data/app/assets/vendor/typus/javascripts/jquery.rails.js +158 -0
- data/app/assets/vendor/typus/javascripts/jquery.searchField.js +91 -0
- data/app/assets/vendor/typus/stylesheets/application.css +11 -0
- data/app/assets/vendor/typus/stylesheets/reset.css +48 -0
- data/app/assets/vendor/typus/stylesheets/screen.css +361 -0
- data/app/assets/vendor/typus/vendor/jquery-tokeninput/css/token-input-facebook.css +122 -0
- data/app/assets/vendor/typus/vendor/jquery-tokeninput/css/token-input-mac.css +204 -0
- data/app/assets/vendor/typus/vendor/jquery-tokeninput/css/token-input.css +120 -0
- data/app/assets/vendor/typus/vendor/jquery-tokeninput/js/jquery.tokeninput.js +736 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/css/ui-lightness/jquery-ui-1.8.12.custom.css +578 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/index.html +367 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/js/jquery-1.5.1.min.js +16 -0
- data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/js/jquery-ui-1.8.12.custom.min.js +783 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/blank.gif +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_close.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_loading.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_nav_left.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_nav_right.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_e.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_n.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_ne.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_nw.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_s.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_se.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_sw.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_w.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_title_left.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_title_main.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_title_over.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancy_title_right.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancybox-x.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancybox-y.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/fancybox.png +0 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/jquery.easing-1.3.pack.js +72 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.css +359 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.js +1156 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js +46 -0
- data/app/assets/vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox/jquery.mousewheel-3.0.4.pack.js +14 -0
- data/app/controllers/admin/account_controller.rb +2 -2
- data/app/controllers/admin/base_controller.rb +4 -0
- data/app/controllers/admin/resources_controller.rb +8 -83
- data/app/controllers/admin/session_controller.rb +10 -2
- data/app/helpers/admin/file_preview_helper.rb +15 -1
- data/app/helpers/admin/filters_helper.rb +4 -4
- data/app/helpers/admin/relationships_helper.rb +11 -6
- data/app/helpers/admin/resources_helper.rb +4 -1
- data/app/helpers/admin/table_helper.rb +6 -3
- data/app/views/admin/dashboard/_sidebar.html.erb +1 -3
- data/app/views/admin/helpers/table/_table.html.erb +0 -8
- data/app/views/admin/resources/index.html.erb +3 -1
- data/app/views/admin/shared/_head.html.erb +30 -0
- data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +23 -4
- data/app/views/admin/templates/_relate_form.html.erb +1 -1
- data/app/views/admin/templates/_selector.html.erb +5 -1
- data/app/views/layouts/admin/base.html.erb +1 -30
- data/app/views/layouts/admin/headless.html.erb +1 -30
- data/app/views/layouts/admin/session.html.erb +1 -19
- data/doc/mongo_db.md +10 -0
- data/lib/generators/typus/typus_generator.rb +0 -5
- data/lib/support/active_record.rb +8 -0
- data/lib/typus.rb +2 -1
- data/lib/typus/controller/actions.rb +7 -0
- data/lib/typus/controller/acts_as.rb +22 -0
- data/lib/typus/controller/associations.rb +66 -0
- data/lib/typus/controller/autocomplete.rb +1 -1
- data/lib/typus/controller/format.rb +1 -1
- data/lib/typus/engine.rb +7 -2
- data/lib/typus/orm/active_record/class_methods.rb +1 -1
- data/lib/typus/version.rb +1 -1
- data/test/app/controllers/admin/assets_controller_test.rb +8 -5
- data/test/app/controllers/admin/pages_controller_test.rb +2 -2
- data/test/app/controllers/admin/posts_controller_test.rb +27 -2
- data/test/app/controllers/admin/views_controller_test.rb +36 -0
- data/test/app/helpers/admin/file_preview_helper_test.rb +9 -1
- data/test/app/helpers/admin/filters_helper_test.rb +5 -0
- data/test/app/helpers/admin/resources_helper_test.rb +2 -2
- data/test/app/helpers/admin/table_helper_test.rb +26 -0
- data/test/factories.rb +11 -0
- data/test/fixtures/rails_app/app/controllers/admin/hits_controller.rb +0 -3
- data/test/fixtures/rails_app/app/controllers/admin/views_controller.rb +6 -0
- data/test/fixtures/rails_app/app/models/asset.rb +16 -4
- data/test/fixtures/rails_app/app/models/site.rb +16 -0
- data/test/fixtures/rails_app/app/models/view.rb +2 -0
- data/test/fixtures/rails_app/config/typus/crud_extended.yml +2 -2
- data/test/fixtures/rails_app/db/schema.rb +15 -0
- data/test/lib/support/active_record_test.rb +24 -0
- data/test/lib/typus/orm/active_record/class_methods_test.rb +4 -4
- data/test/lib/typus_test.rb +1 -1
- metadata +68 -190
- data/.gemtest +0 -0
- data/doc/hudson_setup.md +0 -19
- data/lib/generators/typus/assets_generator.rb +0 -19
- data/test/fixtures/rails_app/app/views/layouts/admin/headless.html.erb +0 -38
@@ -1,10 +1,29 @@
|
|
1
|
+
<% content_for :javascripts do %>
|
2
|
+
<% label = "#{@item.class.model_name.underscore.gsub("/","_")}_#{related_fk}" %>
|
3
|
+
<script type="text/javascript">
|
4
|
+
$(document).ready(function () {
|
5
|
+
$("#tokenInput_for_<%= related_fk %>").tokenInput("/admin/<%= association.name.to_s.pluralize %>/autocomplete", {
|
6
|
+
hintText: "",
|
7
|
+
queryParam: 'term',
|
8
|
+
tokenLimit: 1,
|
9
|
+
<% if (item = @item.send(attribute)) %>
|
10
|
+
prePopulate: [ { id: <%= item.id %>, name: "<%= item.to_label %>" } ],
|
11
|
+
<% end %>
|
12
|
+
onAdd: function(item) {
|
13
|
+
$("#<%= label %>").val(item.id);
|
14
|
+
},
|
15
|
+
onDelete: function (item) {
|
16
|
+
$("#<%= label %>").val("");
|
17
|
+
}
|
18
|
+
});
|
19
|
+
});
|
20
|
+
</script>
|
21
|
+
<% end %>
|
22
|
+
|
1
23
|
<li id="<%= attribute %>">
|
2
24
|
<%= form.label related_fk, "#{label_text} <small>#{message}</small>".html_safe %>
|
3
25
|
<%= form.hidden_field related_fk %>
|
4
|
-
<input
|
5
|
-
id="autocomplete"
|
6
|
-
id_element="#<%= "#{@item.class.model_name.downcase}_#{related_fk}" %>"
|
7
|
-
name="autocomplete"
|
26
|
+
<input id="tokenInput_for_<%= related_fk %>"
|
8
27
|
size="30"
|
9
28
|
type="text"
|
10
29
|
value="<%= @item.send(attribute).try(:to_label) %>" />
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<%= form_tag :action => :relate, :id => @item.id do %>
|
2
2
|
<%= hidden_field :related, :model, :value => model_to_relate %>
|
3
3
|
<%= hidden_field :related, :association_name, :value => association_name %>
|
4
|
-
<p><%= select :related, :id, items_to_relate.map { |f| [f.to_label, f.id] } %> <%= submit_tag Typus::I18n.t("Assign"), :class => "button", :disable_with => Typus::I18n.t("Sending data ...") %></p>
|
4
|
+
<p><%= select :related, :id, items_to_relate.map { |f| [f.to_label, f.id] }, { :include_blank => true } %> <%= submit_tag Typus::I18n.t("Assign"), :class => "button", :disable_with => Typus::I18n.t("Sending data ...") %></p>
|
5
5
|
<% end %>
|
@@ -3,36 +3,7 @@
|
|
3
3
|
<html lang="<%= I18n.locale %>">
|
4
4
|
|
5
5
|
<head>
|
6
|
-
|
7
|
-
<meta charset="utf-8" />
|
8
|
-
<meta name="apple-mobile-web-app-capable" content="yes" />
|
9
|
-
<meta name="generator" content="Typus <%= Typus::VERSION %>" />
|
10
|
-
|
11
|
-
<%= favicon_link_tag %>
|
12
|
-
|
13
|
-
<title><%= Typus.admin_title %> — <%= yield :title %></title>
|
14
|
-
|
15
|
-
<%= stylesheet_link_tag "/vendor/typus/stylesheets/reset",
|
16
|
-
"/vendor/jquery-ui-1.8.9.custom/css/ui-lightness/jquery-ui-1.8.9.custom.css",
|
17
|
-
"/vendor/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.css",
|
18
|
-
"/vendor/typus/stylesheets/screen",
|
19
|
-
"/vendor/typus/stylesheets/application" %>
|
20
|
-
|
21
|
-
<%= yield :stylesheets -%>
|
22
|
-
|
23
|
-
<%= javascript_include_tag "/vendor/jquery-ui-1.8.9.custom/js/jquery-1.4.4.min.js",
|
24
|
-
"/vendor/jquery-ui-1.8.9.custom/js/jquery-ui-1.8.9.custom.min.js",
|
25
|
-
"/vendor/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js",
|
26
|
-
"/vendor/typus/javascripts/jquery.searchField.js",
|
27
|
-
"/vendor/typus/javascripts/jquery.rails.js",
|
28
|
-
"/vendor/typus/javascripts/jquery.rails.autocomplete.js",
|
29
|
-
"/vendor/typus/javascripts/jquery.application.js",
|
30
|
-
"/vendor/typus/javascripts/application" %>
|
31
|
-
|
32
|
-
<%= yield :javascripts -%>
|
33
|
-
|
34
|
-
<%= csrf_meta_tag %>
|
35
|
-
|
6
|
+
<%= render 'admin/shared/head' %>
|
36
7
|
</head>
|
37
8
|
|
38
9
|
<body>
|
@@ -3,36 +3,7 @@
|
|
3
3
|
<html lang="<%= I18n.locale %>">
|
4
4
|
|
5
5
|
<head>
|
6
|
-
|
7
|
-
<meta charset="utf-8" />
|
8
|
-
<meta name="apple-mobile-web-app-capable" content="yes" />
|
9
|
-
<meta name="generator" content="Typus <%= Typus::VERSION %>" />
|
10
|
-
|
11
|
-
<%= favicon_link_tag %>
|
12
|
-
|
13
|
-
<title><%= Typus.admin_title %> — <%= yield :title %></title>
|
14
|
-
|
15
|
-
<%= stylesheet_link_tag "/vendor/typus/stylesheets/reset",
|
16
|
-
"/vendor/jquery-ui-1.8.9.custom/css/ui-lightness/jquery-ui-1.8.9.custom.css",
|
17
|
-
"/vendor/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.css",
|
18
|
-
"/vendor/typus/stylesheets/screen",
|
19
|
-
"/vendor/typus/stylesheets/application" %>
|
20
|
-
|
21
|
-
<%= yield :stylesheets -%>
|
22
|
-
|
23
|
-
<%= javascript_include_tag "/vendor/jquery-ui-1.8.9.custom/js/jquery-1.4.4.min.js",
|
24
|
-
"/vendor/jquery-ui-1.8.9.custom/js/jquery-ui-1.8.9.custom.min.js",
|
25
|
-
"/vendor/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js",
|
26
|
-
"/vendor/typus/javascripts/jquery.searchField.js",
|
27
|
-
"/vendor/typus/javascripts/jquery.rails.js",
|
28
|
-
"/vendor/typus/javascripts/jquery.rails.autocomplete.js",
|
29
|
-
"/vendor/typus/javascripts/jquery.application.js",
|
30
|
-
"/vendor/typus/javascripts/application" %>
|
31
|
-
|
32
|
-
<%= yield :javascripts -%>
|
33
|
-
|
34
|
-
<%= csrf_meta_tag %>
|
35
|
-
|
6
|
+
<%= render 'admin/shared/head' %>
|
36
7
|
</head>
|
37
8
|
|
38
9
|
<body>
|
@@ -3,25 +3,7 @@
|
|
3
3
|
<html lang="<%= I18n.locale %>">
|
4
4
|
|
5
5
|
<head>
|
6
|
-
|
7
|
-
<meta charset="utf-8" />
|
8
|
-
<meta name="apple-mobile-web-app-capable" content="yes" />
|
9
|
-
<meta name="generator" content="Typus <%= Typus::VERSION %>" />
|
10
|
-
|
11
|
-
<%= favicon_link_tag %>
|
12
|
-
|
13
|
-
<title><%= Typus.admin_title %> — <%= yield :title %></title>
|
14
|
-
|
15
|
-
<%= stylesheet_link_tag "/vendor/typus/stylesheets/reset",
|
16
|
-
"/vendor/typus/stylesheets/screen",
|
17
|
-
"/vendor/typus/stylesheets/application" %>
|
18
|
-
|
19
|
-
<%= javascript_include_tag "/vendor/jquery-ui-1.8.9.custom/js/jquery-1.4.4.min.js",
|
20
|
-
"/vendor/typus/javascripts/jquery.rails.js",
|
21
|
-
"/vendor/typus/javascripts/application" %>
|
22
|
-
|
23
|
-
<%= csrf_meta_tag %>
|
24
|
-
|
6
|
+
<%= render 'admin/shared/head' %>
|
25
7
|
</head>
|
26
8
|
|
27
9
|
<body id="account">
|
data/doc/mongo_db.md
ADDED
@@ -1,6 +1,5 @@
|
|
1
1
|
require "rails/generators/migration"
|
2
2
|
|
3
|
-
require "generators/typus/assets_generator"
|
4
3
|
require "generators/typus/config_generator"
|
5
4
|
require "generators/typus/controller_generator"
|
6
5
|
require "generators/typus/initializers_generator"
|
@@ -28,10 +27,6 @@ Description:
|
|
28
27
|
Typus::Generators::InitializersGenerator.new.invoke_all
|
29
28
|
end
|
30
29
|
|
31
|
-
def generate_assets
|
32
|
-
Typus::Generators::AssetsGenerator.new.invoke_all
|
33
|
-
end
|
34
|
-
|
35
30
|
def generate_controllers
|
36
31
|
Typus.application_models.each do |model|
|
37
32
|
Typus::Generators::ControllerGenerator.new([model.pluralize]).invoke_all
|
data/lib/typus.rb
CHANGED
@@ -24,6 +24,7 @@ module Typus
|
|
24
24
|
|
25
25
|
module Controller
|
26
26
|
autoload :Actions, "typus/controller/actions"
|
27
|
+
autoload :ActsAs, "typus/controller/acts_as"
|
27
28
|
autoload :Associations, "typus/controller/associations"
|
28
29
|
autoload :Autocomplete, "typus/controller/autocomplete"
|
29
30
|
autoload :Filters, "typus/controller/filters"
|
@@ -38,7 +39,7 @@ module Typus
|
|
38
39
|
end
|
39
40
|
|
40
41
|
mattr_accessor :autocomplete
|
41
|
-
@@autocomplete =
|
42
|
+
@@autocomplete = nil
|
42
43
|
|
43
44
|
mattr_accessor :admin_title
|
44
45
|
@@admin_title = "Typus"
|
@@ -20,6 +20,13 @@ module Typus
|
|
20
20
|
# super
|
21
21
|
# end
|
22
22
|
#
|
23
|
+
# Additionally you can set a condition to each action passing a Proc as 4th parameter. If the proc return true
|
24
|
+
# the item will be showed and if return false will be hidden.
|
25
|
+
#
|
26
|
+
# def index
|
27
|
+
# add_resource_action('Recover', {:action => 'untrash'}, {}, Proc.new {|item| item.is_trash? })
|
28
|
+
# super
|
29
|
+
# end
|
23
30
|
|
24
31
|
def add_resource_action(*args)
|
25
32
|
@resource_actions ||= []
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Typus
|
2
|
+
module Controller
|
3
|
+
module ActsAs
|
4
|
+
|
5
|
+
##
|
6
|
+
# Change item position:
|
7
|
+
#
|
8
|
+
# params[:go] = 'move_to_top'
|
9
|
+
#
|
10
|
+
# Available positions are move_to_top, move_higher, move_lower, move_to_bottom.
|
11
|
+
#
|
12
|
+
# NOTE: Only works if `acts_as_list` is installed.
|
13
|
+
#
|
14
|
+
def position
|
15
|
+
@item.send(params[:go])
|
16
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
|
17
|
+
redirect_to :back, :notice => notice
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -2,6 +2,72 @@ module Typus
|
|
2
2
|
module Controller
|
3
3
|
module Associations
|
4
4
|
|
5
|
+
##
|
6
|
+
# Action to relate models which respond to:
|
7
|
+
#
|
8
|
+
# - has_and_belongs_to_many
|
9
|
+
# - has_many
|
10
|
+
#
|
11
|
+
# For example:
|
12
|
+
#
|
13
|
+
# class Item < ActiveRecord::Base
|
14
|
+
# has_many :line_items
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# class LineItem < ActiveRecord::Base
|
18
|
+
# belongs_to :item
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# >> related_item = LineItem.find(params[:related][:id])
|
22
|
+
# => ...
|
23
|
+
# >> item = Item.find(params[:id])
|
24
|
+
# => ...
|
25
|
+
# >> item.line_items << related_item
|
26
|
+
# => ...
|
27
|
+
#
|
28
|
+
def relate
|
29
|
+
resource_class = params[:related][:model].typus_constantize
|
30
|
+
association_name = params[:related][:association_name].tableize
|
31
|
+
|
32
|
+
if params[:related][:id].present? && (item = resource_class.find(params[:related][:id]))
|
33
|
+
@item.send(association_name) << item
|
34
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
|
35
|
+
else
|
36
|
+
notice = Typus::I18n.t("Please, select an option.")
|
37
|
+
end
|
38
|
+
|
39
|
+
redirect_to :back, :notice => notice
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# Action to unrelate models which respond to:
|
44
|
+
#
|
45
|
+
# - has_and_belongs_to_many
|
46
|
+
# - has_many
|
47
|
+
# - has_one
|
48
|
+
#
|
49
|
+
def unrelate
|
50
|
+
item_class = params[:resource].typus_constantize
|
51
|
+
item = item_class.find(params[:resource_id])
|
52
|
+
|
53
|
+
case item_class.relationship_with(@resource)
|
54
|
+
when :has_one
|
55
|
+
association_name = @resource.model_name.underscore.to_sym
|
56
|
+
worked = item.send(association_name).delete
|
57
|
+
else
|
58
|
+
association_name = params[:association_name] ? params[:association_name].to_sym : @resource.model_name.tableize.split("/").last.to_sym
|
59
|
+
worked = item.send(association_name).delete(@item)
|
60
|
+
end
|
61
|
+
|
62
|
+
if worked
|
63
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => item_class.model_name.human)
|
64
|
+
else
|
65
|
+
alert = item.error.full_messages
|
66
|
+
end
|
67
|
+
|
68
|
+
redirect_to :back, :notice => notice, :alert => alert
|
69
|
+
end
|
70
|
+
|
5
71
|
protected
|
6
72
|
|
7
73
|
##
|
@@ -7,7 +7,7 @@ module Typus
|
|
7
7
|
params.merge!(:search => params[:term])
|
8
8
|
get_objects
|
9
9
|
@items = @resource.limit(20)
|
10
|
-
render :json => @items.map { |i| { "id" => i.id, "label" => i.to_label, "value" => i.to_label } }
|
10
|
+
render :json => @items.map { |i| { "id" => i.id, "label" => i.to_label, "value" => i.to_label, "name" => i.to_label } }
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
data/lib/typus/engine.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
module Typus
|
2
|
-
|
3
2
|
class Engine < Rails::Engine
|
4
|
-
end
|
5
3
|
|
4
|
+
initializer "static assets" do |app|
|
5
|
+
if app.config.serve_static_assets
|
6
|
+
app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/app/assets"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
6
11
|
end
|
@@ -58,7 +58,7 @@ module Typus
|
|
58
58
|
next
|
59
59
|
end
|
60
60
|
|
61
|
-
dragonfly = respond_to?(:
|
61
|
+
dragonfly = respond_to?(:dragonfly_attachment_classes) && dragonfly_attachment_classes.map { |i| i.attribute }.include?(field)
|
62
62
|
paperclip = respond_to?(:attachment_definitions) && attachment_definitions.try(:has_key?, field)
|
63
63
|
|
64
64
|
if dragonfly || paperclip
|
data/lib/typus/version.rb
CHANGED
@@ -85,11 +85,15 @@ class Admin::AssetsControllerTest < ActionController::TestCase
|
|
85
85
|
|
86
86
|
context "create" do
|
87
87
|
|
88
|
-
|
89
|
-
asset = {:caption => "My Caption",
|
88
|
+
setup do
|
89
|
+
@asset = { :caption => "My Caption",
|
90
|
+
:dragonfly_required => File.new("#{Rails.root}/public/images/rails.png"),
|
91
|
+
:paperclip_required => File.new("#{Rails.root}/public/images/rails.png") }
|
92
|
+
end
|
90
93
|
|
94
|
+
should "redirect to edit with custom layout" do
|
91
95
|
assert_difference('Asset.count') do
|
92
|
-
post :create, { :asset => asset, :layout => "admin/headless" }
|
96
|
+
post :create, { :asset => @asset, :layout => "admin/headless" }
|
93
97
|
end
|
94
98
|
|
95
99
|
assert_response :redirect
|
@@ -98,10 +102,9 @@ class Admin::AssetsControllerTest < ActionController::TestCase
|
|
98
102
|
|
99
103
|
should "redirect to index with custom layout" do
|
100
104
|
Typus::Resources.expects(:action_after_save).returns("index")
|
101
|
-
asset = {:caption => "My Caption", :dragonfly_required => File.new("#{Rails.root}/public/images/rails.png")}
|
102
105
|
|
103
106
|
assert_difference('Asset.count') do
|
104
|
-
post :create, { :asset => asset, :layout => "admin/headless" }
|
107
|
+
post :create, { :asset => @asset, :layout => "admin/headless" }
|
105
108
|
end
|
106
109
|
|
107
110
|
assert_response :redirect
|
@@ -27,10 +27,10 @@ class Admin::PagesControllerTest < ActionController::TestCase
|
|
27
27
|
Factory(:page, :status => false)
|
28
28
|
end
|
29
29
|
|
30
|
-
should "return
|
30
|
+
should "return scoped results" do
|
31
31
|
assert Page.count.eql?(1)
|
32
32
|
get :index
|
33
|
-
assert assigns(:items).size.eql?(
|
33
|
+
assert assigns(:items).size.eql?(1)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -152,8 +152,7 @@ class Admin::PostsControllerTest < ActionController::TestCase
|
|
152
152
|
|
153
153
|
should "be included in index" do
|
154
154
|
get :index
|
155
|
-
|
156
|
-
assert_equal expected, assigns(:predefined_filters)
|
155
|
+
assert assigns(:predefined_filters).nil?
|
157
156
|
end
|
158
157
|
|
159
158
|
end
|
@@ -486,6 +485,32 @@ title;status
|
|
486
485
|
assert_equal "Post successfully updated.", flash[:notice]
|
487
486
|
end
|
488
487
|
|
488
|
+
should "return a message instead a 404 error if related_id is empty" do
|
489
|
+
comment = Factory(:comment, :post => nil)
|
490
|
+
@request.env['HTTP_REFERER'] = "/admin/posts/edit/#{@post.id}#comments"
|
491
|
+
|
492
|
+
assert_no_difference('@post.comments.count') do
|
493
|
+
post :relate, { :id => @post.id, :related => { :model => 'Comment', :id => "", :association_name => 'comments' } }
|
494
|
+
end
|
495
|
+
|
496
|
+
assert_response :redirect
|
497
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
498
|
+
assert_equal "Please, select an option.", flash[:notice]
|
499
|
+
end
|
500
|
+
|
501
|
+
should "return a message instead a 404 error if related_id is nil" do
|
502
|
+
comment = Factory(:comment, :post => nil)
|
503
|
+
@request.env['HTTP_REFERER'] = "/admin/posts/edit/#{@post.id}#comments"
|
504
|
+
|
505
|
+
assert_no_difference('@post.comments.count') do
|
506
|
+
post :relate, { :id => @post.id, :related => { :model => 'Comment', :id => nil, :association_name => 'comments' } }
|
507
|
+
end
|
508
|
+
|
509
|
+
assert_response :redirect
|
510
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
511
|
+
assert_equal "Please, select an option.", flash[:notice]
|
512
|
+
end
|
513
|
+
|
489
514
|
should "relate category to post (has_and_belongs_to_many)" do
|
490
515
|
category = Factory(:category)
|
491
516
|
@request.env['HTTP_REFERER'] = "/admin/posts/edit/#{@post.id}#categories"
|