netzke-has-many 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 359206b0e8be43e03a9e5beaf7082718ef0cc5db
4
+ data.tar.gz: 1de1d95eebfe1529da9bae6f048be63a5271b7a0
5
+ SHA512:
6
+ metadata.gz: 805e4f013c3f34d4d7c030786d2115af2b07cbe58ce817a0729743773c01990048ff7f30c3ae913b1869a98ffbb64bad70556aa8ebf750252c49904b7d2aaf20
7
+ data.tar.gz: 04c755a03433ac77f43ffcdac66685edc9353a1cc4499cf3dd8e3338a777b5314a2357d8fa2773b87ae18f002623eee20f7730db01a2929240002b4d732af4da
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1 @@
1
+ require File.join('netzke','has_many')
@@ -0,0 +1,2 @@
1
+ require File.join("netzke","has_many","base")
2
+ require File.join("netzke","has_many","window")
@@ -0,0 +1,65 @@
1
+ require 'active_support/concern'
2
+
3
+ module Netzke
4
+ module HasMany
5
+ module Base
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+ def has_many many, options = {}
10
+ grid_klass = options[:grid_klass].to_s if options[:grid_klass]
11
+ endpoint_path = options[:endpoint] || :select_one
12
+ endpoint_fun = endpoint_path.to_s.camelize
13
+ endpoint_fun = endpoint_fun[0].downcase + endpoint_fun[1..-1]
14
+ class_eval do
15
+ action "edit_#{many}".to_sym
16
+
17
+ endpoint endpoint_path do | params, this |
18
+ component_session["selected_#{config["model"].underscore}_id"] = params["one_id"]
19
+ end
20
+
21
+ component "#{many}_window" do |c|
22
+ c.klass = Window
23
+ c.one_id = component_session["selected_#{config["model"].underscore}_id"]
24
+ c.one_name = "#{config["model"].underscore}_id".to_sym
25
+ c.grid_klass = grid_klass
26
+ c.grid_model = many.to_s.singularize.camelize
27
+ end
28
+
29
+ js_configure do |c|
30
+ c.send "on_edit_#{many}=", <<-JS
31
+ function(){
32
+ this.netzkeLoadComponent("#{many}_window", {callback: function(w){
33
+ w.show();
34
+ }});
35
+ }
36
+ JS
37
+
38
+ c.init_component = <<-JS
39
+ function(){
40
+ Netzke.classes.#{self.to_s.gsub("::",".")}.superclass.initComponent.call(this);
41
+
42
+ this.getSelectionModel().on('selectionchange', function(selModel){
43
+ this.actions.edit#{many.to_s.camelize}.setDisabled(selModel.getCount() != 1);
44
+ if(selModel.getCount() == 1) {
45
+ one_id = selModel.store.getAt(selModel.getSelection()[0].index).get('id');
46
+ this.#{endpoint_fun}({one_id: one_id})
47
+ }
48
+ }, this);
49
+ }
50
+ JS
51
+ end
52
+
53
+ define_method :default_bbar do |*params|
54
+ ["edit_#{many}".to_sym, "-", *super(*params)]
55
+ end
56
+
57
+ define_method :default_context_menu do |*params|
58
+ ["edit_#{many}".to_sym, "-", *super(*params)]
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,5 @@
1
+ module Netzke
2
+ module HasMany
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require 'netzke-basepack'
2
+
3
+ module Netzke
4
+ module HasMany
5
+ class Window < Netzke::Basepack::Window
6
+ def configure(c)
7
+ super
8
+ c.width = 400
9
+ c.items = [:many_grid]
10
+ end
11
+
12
+ component :many_grid do |c|
13
+ if config[:grid_klass]
14
+ c.klass = config[:grid_klass].constantize
15
+ else
16
+ c.klass = Netzke::Basepack::Grid
17
+ c.model = config[:grid_model]
18
+ c.force_fit = true
19
+ end
20
+ attrs = {config[:one_name] => config[:one_id]}
21
+ c.scope = attrs
22
+ c.strong_default_attrs = attrs
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.join('..', 'lib', 'netzke', 'has_many', 'version'), __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'netzke-has-many'
6
+ gem.version = Netzke::HasMany::VERSION
7
+ gem.homepage = 'https://github.com/bamorim/netzke-has-many'
8
+
9
+ gem.author = "Bernardo Amorim"
10
+ gem.email = 'contato@bamorim.com'
11
+ gem.description = 'Has Many Grid Editor for Netzke'
12
+ gem.summary = gem.description
13
+
14
+ gem.license = "MIT"
15
+
16
+ gem.add_dependency "netzke-core"
17
+ gem.add_dependency "netzke-basepack"
18
+ gem.add_dependency "activesupport"
19
+
20
+ gem.add_development_dependency 'rake'
21
+
22
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
23
+ gem.files = `git ls-files`.split("\n")
24
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+
26
+ gem.require_paths = ['lib']
27
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netzke-has-many
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bernardo Amorim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: netzke-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: netzke-basepack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Has Many Grid Editor for Netzke
70
+ email: contato@bamorim.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - Gemfile
76
+ - lib/netzke-has-many.rb
77
+ - lib/netzke/has_many.rb
78
+ - lib/netzke/has_many/base.rb
79
+ - lib/netzke/has_many/version.rb
80
+ - lib/netzke/has_many/window.rb
81
+ - netzke-has-many.gemspec
82
+ homepage: https://github.com/bamorim/netzke-has-many
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.0.3
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Has Many Grid Editor for Netzke
106
+ test_files: []