lolita-menu 0.3.6 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +47 -0
- data/Gemfile +8 -11
- data/Rakefile +4 -43
- data/app/assets/javascripts/lolita/menu/autocomplete-rails.js +1 -1
- data/app/assets/javascripts/lolita/menu/menu-items.js +5 -5
- data/app/assets/stylesheets/lolita/menu/application.css +21 -0
- data/app/controllers/menu_items_controller.rb +4 -0
- data/app/controllers/nested_trees_controller.rb +46 -46
- data/app/models/menu.rb +1 -7
- data/app/models/menu_item.rb +13 -17
- data/app/views/components/lolita/menu/nested_tree/_display.html.haml +0 -1
- data/lib/generators/lolita/menu/templates/migrations/create_menu_items.rb +1 -1
- data/lib/lolita-menu/nested_tree.rb +253 -253
- data/lib/lolita-menu/nested_tree/branch_builder.rb +58 -58
- data/lib/lolita-menu/nested_tree/configuration.rb +72 -72
- data/lib/lolita-menu/nested_tree/scope.rb +52 -52
- data/lib/lolita-menu/nested_tree/tree_builder.rb +29 -29
- data/lolita-menu.gemspec +6 -110
- data/spec/models/menu_item_spec.rb +6 -6
- data/spec/models/menu_spec.rb +0 -1
- data/test_orm/active_record.rb +4 -6
- data/test_orm/log/.gitkeep +0 -0
- data/test_orm/rails/config/application.rb +2 -3
- data/test_orm/rails/log/.gitkeep +0 -0
- metadata +34 -129
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c32003725ace089823b958a151e48af409e4f6ee
|
4
|
+
data.tar.gz: 8e070736fa01c1271542089f3a3ca291246d0161
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 233a2a06346cf39630c4c5a5a50d8821a8ab470773c6f80f2b31b593473c1e023615a96f6f82f1d5f9887ab70f1f9efc16495c868f6599c388d06262d041c5bd
|
7
|
+
data.tar.gz: cdeae6f3a7fcf2efe92b7d54a0337b49a69494e6445d6aa9ad6ddfbd6768253618d0aa9baf7709809cf579f48ec16f9f002de4d38ae6b4bb4fdf04020053962e
|
data/.gitignore
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# rcov generated
|
2
|
+
test_orm/log/*.log
|
3
|
+
test_orm/rails/log/*.log
|
4
|
+
Gemfile.lock
|
5
|
+
coverage
|
6
|
+
.project
|
7
|
+
.rvmrc
|
8
|
+
|
9
|
+
# rdoc generated
|
10
|
+
rdoc
|
11
|
+
|
12
|
+
# yard generated
|
13
|
+
doc
|
14
|
+
.yardoc
|
15
|
+
|
16
|
+
# bundler
|
17
|
+
.bundle
|
18
|
+
|
19
|
+
# jeweler generated
|
20
|
+
pkg
|
21
|
+
|
22
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
23
|
+
#
|
24
|
+
# * Create a file at ~/.gitignore
|
25
|
+
# * Include files you want ignored
|
26
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
27
|
+
#
|
28
|
+
# After doing this, these files will be ignored in all your git projects,
|
29
|
+
# saving you from having to 'pollute' every project you touch with them
|
30
|
+
#
|
31
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
32
|
+
#
|
33
|
+
# For MacOS:
|
34
|
+
#
|
35
|
+
#.DS_Store
|
36
|
+
#
|
37
|
+
# For TextMate
|
38
|
+
#*.tmproj
|
39
|
+
#tmtags
|
40
|
+
#
|
41
|
+
# For emacs:
|
42
|
+
#*~
|
43
|
+
#\#*
|
44
|
+
#.\#*
|
45
|
+
#
|
46
|
+
# For vim:
|
47
|
+
*.swp
|
data/Gemfile
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
source
|
1
|
+
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
|
3
|
+
gemspec
|
4
4
|
|
5
|
-
group :
|
6
|
-
gem
|
7
|
-
gem '
|
8
|
-
gem
|
9
|
-
|
10
|
-
|
11
|
-
gem "jeweler", "~> 1.6.0"
|
12
|
-
gem "database_cleaner", "~>0.6.7"
|
13
|
-
end
|
5
|
+
group :test do
|
6
|
+
gem 'rails', '~> 3.2.12'
|
7
|
+
gem 'sqlite3', '~> 1.3.7'
|
8
|
+
gem 'rspec-rails', '~> 2.14'
|
9
|
+
gem 'database_cleaner', '~> 1.0.1'
|
10
|
+
end
|
data/Rakefile
CHANGED
@@ -1,46 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler'
|
3
|
-
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'rake'
|
3
|
+
require 'rspec/core/rake_task'
|
11
4
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
gem.name = "lolita-menu"
|
16
|
-
gem.homepage = "http://github.com/ithouse/lolita-menu"
|
17
|
-
gem.license = "MIT"
|
18
|
-
gem.summary = %Q{Menu managing plugin for Lolita.}
|
19
|
-
gem.description = %Q{Manage public menus for each project inside Lolita.}
|
20
|
-
gem.email = "support@ithouse.lv"
|
21
|
-
gem.authors = ["ITHouse","Arturs Meisters"]
|
22
|
-
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
-
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
-
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
-
end
|
27
|
-
Jeweler::RubygemsDotOrgTasks.new
|
28
|
-
|
29
|
-
require 'rake/testtask'
|
30
|
-
Rake::TestTask.new(:test) do |test|
|
31
|
-
test.libs << 'lib' << 'test'
|
32
|
-
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.verbose = true
|
34
|
-
end
|
35
|
-
|
36
|
-
task :default => :test
|
37
|
-
|
38
|
-
require 'rake/rdoctask'
|
39
|
-
Rake::RDocTask.new do |rdoc|
|
40
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
-
|
42
|
-
rdoc.rdoc_dir = 'rdoc'
|
43
|
-
rdoc.title = "lolita-menu #{version}"
|
44
|
-
rdoc.rdoc_files.include('README*')
|
45
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
-
end
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
task :default => :spec
|
@@ -22,7 +22,7 @@ $(document).ready(function(){
|
|
22
22
|
{
|
23
23
|
var self = null;
|
24
24
|
jQuery.fn.railsAutocomplete = function() {
|
25
|
-
return this.
|
25
|
+
return this.on('focus',this,function() {
|
26
26
|
if (!this.railsAutoCompleter) {
|
27
27
|
this.railsAutoCompleter = new jQuery.railsAutocomplete(this);
|
28
28
|
}
|
@@ -11,7 +11,7 @@ $(document).ready(function(){
|
|
11
11
|
success:function(){
|
12
12
|
tree.data("old_positions",tree.nestedSortable('serialize'))
|
13
13
|
}
|
14
|
-
})
|
14
|
+
})
|
15
15
|
}
|
16
16
|
}
|
17
17
|
|
@@ -41,7 +41,7 @@ $(document).ready(function(){
|
|
41
41
|
var that=this
|
42
42
|
$(".subrow").hide(0)
|
43
43
|
$("#branch_"+$(this).attr("data-id")).show(0);
|
44
|
-
|
44
|
+
|
45
45
|
//event.preventDefault();
|
46
46
|
})
|
47
47
|
|
@@ -57,7 +57,7 @@ $(document).ready(function(){
|
|
57
57
|
})
|
58
58
|
})
|
59
59
|
|
60
|
-
$(".delete-nested-tree-item"
|
60
|
+
$(document).on("click",".delete-nested-tree-item",function(){
|
61
61
|
var self = this;
|
62
62
|
$.ajax({
|
63
63
|
url:$(this).attr("data-url"),
|
@@ -70,11 +70,11 @@ $(document).ready(function(){
|
|
70
70
|
})
|
71
71
|
})
|
72
72
|
|
73
|
-
$(".nested-tree-content input"
|
73
|
+
$(document).on("focus",".nested-tree-content input",function(){
|
74
74
|
$(this).data("value",$(this).val())
|
75
75
|
})
|
76
76
|
|
77
|
-
$(".nested-tree-content input"
|
77
|
+
$(document).on("blur",".nested-tree-content input",function(){
|
78
78
|
var input=$(this);
|
79
79
|
if(input.data("value")!=input.val()){
|
80
80
|
var match = input.attr("name").match(/\[(\w+)\]$/);
|
@@ -1,7 +1,13 @@
|
|
1
|
+
button.add_new_nested_tree_item {
|
2
|
+
margin-top: 10px;
|
3
|
+
}
|
1
4
|
ol.nested-tree-items-tree li{
|
2
5
|
list-style:none;
|
3
6
|
width:390px;
|
4
7
|
}
|
8
|
+
ol.nested-tree-items-tree{
|
9
|
+
margin-bottom: 10px;
|
10
|
+
}
|
5
11
|
div.nested-tree-content{
|
6
12
|
width:500px;
|
7
13
|
}
|
@@ -11,6 +17,21 @@ div.nested-tree-content{
|
|
11
17
|
padding: 0;
|
12
18
|
margin-right: 10px;
|
13
19
|
}
|
20
|
+
#main div.nested-tree-content form input {
|
21
|
+
border: 1px solid #cdcdcd;
|
22
|
+
-moz-border-radius: 3px;
|
23
|
+
-webkit-border-radius: 3px;
|
24
|
+
border-radius: 3px;
|
25
|
+
-moz-box-sizing: border-box;
|
26
|
+
-webkit-box-sizing: border-box;
|
27
|
+
box-sizing: border-box;
|
28
|
+
padding: 3px 10px;
|
29
|
+
color: #494949;
|
30
|
+
}
|
31
|
+
#main div.nested-tree-content span img {
|
32
|
+
position: relative;
|
33
|
+
top: 4px;
|
34
|
+
}
|
14
35
|
li.placeholder{
|
15
36
|
background-color:white;
|
16
37
|
}
|
@@ -3,6 +3,10 @@ class MenuItemsController < NestedTreesController
|
|
3
3
|
|
4
4
|
before_filter :authenticate_lolita_user!
|
5
5
|
|
6
|
+
def index
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
6
10
|
def autocomplete_menu_item_url
|
7
11
|
authorization_proxy.authorize!(:read, Menu)
|
8
12
|
urls = Lolita::Menu::Autocomplete::Collector.new(params[:term])
|
@@ -1,86 +1,86 @@
|
|
1
1
|
class NestedTreesController < Lolita::RestController
|
2
|
-
|
2
|
+
include Lolita::ControllerAdditions
|
3
3
|
|
4
4
|
before_filter :authenticate_lolita_user!
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def index
|
7
|
+
super
|
8
|
+
end
|
9
9
|
|
10
|
-
|
10
|
+
def create
|
11
11
|
authorization_proxy.authorize!(:create, tree_class)
|
12
|
-
|
12
|
+
item = tree_class.build_empty_branch(attributes.merge(scopes))
|
13
13
|
item.save!
|
14
|
-
|
14
|
+
item.reload
|
15
15
|
notice(I18n.t("lolita.nested_tree.branch created", :name => tree_class.model_name.human))
|
16
|
-
|
17
|
-
|
16
|
+
render_component "lolita/menu/nested_tree/branch_builder", :row, :item => item, :scope => scope
|
17
|
+
end
|
18
18
|
|
19
|
-
|
19
|
+
def update
|
20
20
|
authorization_proxy.authorize!(:update,tree_class)
|
21
|
-
|
21
|
+
if params[:attribute].present? && item = tree_class.find_by_id(params[:id])
|
22
22
|
item.send(:"#{params[:attribute]}=",params[:value])
|
23
23
|
item.save
|
24
24
|
render :json=>{:status=>item.errors.any? ? "error" : "saved"}
|
25
|
-
|
25
|
+
else
|
26
26
|
render :json=>{:status=>"error"}
|
27
|
-
|
28
|
-
|
27
|
+
end
|
28
|
+
end
|
29
29
|
|
30
|
-
|
30
|
+
def update_tree
|
31
31
|
authorization_proxy.authorize!(:update,tree_class)
|
32
|
-
|
32
|
+
if tree_class.update_whole_tree(params[:items], scopes)
|
33
33
|
notice I18n.t("lolita.nested_tree.notice", :name => tree_class.model_name.human)
|
34
34
|
else
|
35
35
|
error I18n.t("lolita.nested_tree.error", :name => tree_class.model_name.human)
|
36
36
|
end
|
37
37
|
|
38
38
|
render :nothing=>true
|
39
|
-
|
39
|
+
end
|
40
40
|
|
41
|
-
|
41
|
+
def destroy
|
42
42
|
authorization_proxy.authorize!(:destroy,tree_class)
|
43
|
-
|
44
|
-
|
43
|
+
item = tree_class.find_by_id(params[:id])
|
44
|
+
item.destroy
|
45
45
|
notice I18n.t("lolita.nested_tree.branch deleted", :name => tree_class.model_name.human)
|
46
46
|
render :json=>{:id=>item.id}
|
47
|
-
|
47
|
+
end
|
48
48
|
|
49
49
|
def lolita_mapping
|
50
50
|
@lolita_mapping ||= Lolita.mappings[resource_class.to_s.underscore.to_sym]
|
51
51
|
end
|
52
52
|
|
53
53
|
def resource_name
|
54
|
-
|
54
|
+
"nested_tree"
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
def resource_class
|
58
|
+
tree_class
|
59
|
+
end
|
60
60
|
|
61
|
-
|
61
|
+
private
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
# URL:
|
64
|
+
# /nested_trees?tree_class=MenuItem
|
65
|
+
def tree_class
|
66
|
+
@tree_class ||= params[:tree_class].constantize
|
67
|
+
end
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
def scopes
|
70
|
+
@scopes ||= tree_class.lolita_nested_tree.scope_keys.inject({}) do |result, key|
|
71
|
+
result[key] = params[key]
|
72
|
+
result
|
73
|
+
end
|
74
|
+
end
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
def scope
|
77
|
+
tree_class.lolita_nested_tree.scope_classes.first && tree_class.lolita_nested_tree.scope_classes.first.find_by_id(scopes.values.first)
|
78
|
+
end
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
80
|
+
def attributes
|
81
|
+
@attributes ||= tree_class.lolita.tabs.first.fields.inject({}) do |result, field|
|
82
|
+
result[field.name.to_sym] = params[field.name.to_sym] if params[field.name.to_sym]
|
83
|
+
result
|
84
|
+
end
|
85
|
+
end
|
86
86
|
end
|
data/app/models/menu.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
class Menu < ActiveRecord::Base
|
2
|
-
|
2
|
+
self.table_name = 'lolita_menus'
|
3
3
|
has_many :items, :class_name => "MenuItem", :dependent => :destroy
|
4
|
-
|
5
4
|
validates :name, :presence => true
|
6
5
|
|
7
6
|
include Lolita::Configuration
|
@@ -27,9 +26,4 @@ class Menu < ActiveRecord::Base
|
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
|
-
class << self
|
31
|
-
def table_name
|
32
|
-
"lolita_menus"
|
33
|
-
end
|
34
|
-
end
|
35
29
|
end
|
data/app/models/menu_item.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class MenuItem < ActiveRecord::Base
|
2
|
-
|
3
|
-
|
2
|
+
include Lolita::Configuration
|
3
|
+
include Lolita::Menu::NestedTree
|
4
|
+
self.table_name = 'lolita_menu_items'
|
4
5
|
|
5
6
|
belongs_to :menu, :class_name => "Menu"
|
6
7
|
attr_accessible :lft, :rgt, :depth, :parent_id, :menu_id, :url, :name
|
@@ -10,9 +11,9 @@ class MenuItem < ActiveRecord::Base
|
|
10
11
|
|
11
12
|
before_save :normalize_url
|
12
13
|
|
13
|
-
|
14
|
+
lolita_nested_tree :scope => :menu, :build_method => :build_new_item
|
14
15
|
|
15
|
-
|
16
|
+
lolita do
|
16
17
|
list do
|
17
18
|
action :edit do
|
18
19
|
title ::I18n.t("lolita.shared.edit")
|
@@ -25,20 +26,15 @@ class MenuItem < ActiveRecord::Base
|
|
25
26
|
html :method => :delete, :confirm => ::I18n.t("lolita.list.confirm")
|
26
27
|
end
|
27
28
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
tab(:default) do
|
30
|
+
field :name
|
31
|
+
field :url do
|
31
32
|
builder :name => "/lolita/menu_item", :state => :display, :if => {:state => :display}
|
32
33
|
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class << self
|
37
|
-
|
38
|
-
def table_name
|
39
|
-
"lolita_menu_items"
|
40
34
|
end
|
35
|
+
end
|
41
36
|
|
37
|
+
class << self
|
42
38
|
def build_new_item(attributes)
|
43
39
|
self.new(attributes.merge(:url => "/", :name => ::I18n.t("lolita.menu_item.new")))
|
44
40
|
end
|
@@ -51,9 +47,9 @@ class MenuItem < ActiveRecord::Base
|
|
51
47
|
!!active_item
|
52
48
|
end
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
def visible?
|
51
|
+
self.is_visible
|
52
|
+
end
|
57
53
|
|
58
54
|
def url_match?(request,fullpath=false)
|
59
55
|
if self.url.strip.match(/^http/)
|