erp_app 3.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/app/controllers/erp_app/desktop/scaffold/base_controller.rb +72 -72
  2. data/app/controllers/erp_app/desktop/security_management/capabilities_controller.rb +2 -1
  3. data/app/controllers/erp_app/desktop/security_management/groups_controller.rb +2 -0
  4. data/app/views/erp_app/desktop/base/index.erb +1 -0
  5. data/config/routes.rb +1 -1
  6. data/lib/active_ext/core.rb +88 -65
  7. data/lib/active_ext/data_structures/column.rb +17 -17
  8. data/lib/active_ext/data_structures/columns.rb +55 -52
  9. data/lib/active_ext/ext_helpers/table_builder.rb +58 -58
  10. data/lib/erp_app/engine.rb +1 -1
  11. data/lib/erp_app/extensions/railties/action_view/helpers/extjs_helper.rb +5 -2
  12. data/lib/erp_app/extensions/railties/action_view/helpers/include_helper.rb +4 -4
  13. data/lib/erp_app/version.rb +1 -1
  14. data/lib/erp_app/widgets/javascript_loader.rb +1 -1
  15. data/lib/erp_app/widgets/loader.rb +5 -6
  16. data/lib/generators/compass_ae_mobile/USAGE +9 -0
  17. data/lib/generators/compass_ae_mobile/compass_ae_mobile_generator.rb +35 -0
  18. data/lib/generators/compass_ae_mobile/templates/controllers/controller_template.erb +4 -0
  19. data/lib/generators/compass_ae_mobile/templates/javascripts/main_template.erb +29 -0
  20. data/lib/generators/compass_ae_mobile/templates/views/view_template.erb +25 -0
  21. data/public/javascripts/erp_app/desktop/applications/scaffold/models_tree_panel.js +11 -59
  22. data/public/javascripts/erp_app/desktop/applications/scaffold/module.js +37 -36
  23. data/public/javascripts/erp_app/shared/Ext.ux.CheckColumn.js +115 -0
  24. data/public/javascripts/erp_app/shared/compass_ckeditor.js +17 -0
  25. data/public/javascripts/erp_app/shared/compass_codemirror.js +171 -159
  26. data/public/javascripts/erp_app/shared/file_manager_tree.js +1 -1
  27. data/public/stylesheets/erp_app/shared/grid_cell.css +23 -0
  28. metadata +9 -9
  29. data/app/controllers/erp_app/desktop/scaffold/role_controller.rb +0 -23
  30. data/app/views/erp_app/desktop/scaffold/role/create.rhtml +0 -19
  31. data/app/views/erp_app/desktop/scaffold/role/edit.rhtml +0 -65
  32. data/app/views/erp_app/desktop/scaffold/role/new.rhtml +0 -41
  33. data/app/views/erp_app/desktop/scaffold/role/show.rhtml +0 -58
  34. data/app/views/erp_app/desktop/scaffold/role/update.rhtml +0 -1
  35. data/public/javascripts/erp_app/desktop/applications/scaffold/role_active_ext.js +0 -17
@@ -6,84 +6,84 @@ module ErpApp
6
6
  module Scaffold
7
7
  class BaseController < ErpApp::Desktop::BaseController
8
8
 
9
- def create_model
10
- name = params[:name].underscore
9
+ def get_models
10
+ names = ActiveRecord::Base.all_subclasses.collect{|klass| klass.name}.delete_if{|item| item =~ /::/}.uniq.sort{|a,b| a <=> b}
11
11
 
12
- result = create_scaffold_check(name)
13
- if result[:success]
14
- Rails::Generators.invoke('active_ext', [name, 'desktop','scaffold'])
15
- load_files(name)
12
+ respond_to do |format|
13
+ format.json do
14
+ render :json => {:success => true, :names => names.collect{|name| {:name => name}}}
15
+ end
16
+ format.tree do
17
+ if params[:node].blank? || params[:node] == "root"
18
+ render :json => {:success => true, :names => names.collect{|model| {:text => model, :id => model.underscore, :model => model, :iconCls => 'icon-grid', :leaf => false}}}
19
+ else
20
+ active_ext_core = ActiveExt::Core.new(params[:node].classify, :ignore_associations => true, :include_timestamps => false)
21
+ non_excluded_columns = active_ext_core.non_excluded_columns.collect{|column| column.name}
22
+
23
+ render :json => {:success => true, :names => non_excluded_columns.collect{|column| {:text => column, :iconCls => 'icon-gear', :leaf => true}}}
24
+ end
25
+ end
16
26
  end
27
+ end
17
28
 
18
- render :json => result
19
- end
29
+ def get_columns
30
+ active_ext_core = ActiveExt::Core.new(params[:model], :ignore_associations => true, :include_timestamps => false)
20
31
 
21
- def get_active_ext_models
22
- render :json => find_active_ext_models.map{|model| {:text => model, :model => model.underscore, :iconCls => 'icon-grid', :leaf => true}}
23
- end
32
+ non_excluded_columns = active_ext_core.non_excluded_columns.collect{|column| {:name => column.name}}
24
33
 
25
- private
34
+ render :json => {:success => true, :columns => non_excluded_columns.sort{|a,b| a[:name] <=> b[:name]}}
35
+ end
26
36
 
27
- def create_scaffold_check(name)
28
- result = {:success => true}
37
+ def setup
38
+ active_ext_core = setup_active_ext_core
29
39
 
30
- klass_name = name.classify
31
- model_names = find_active_ext_models
32
- unless model_names.include?(klass_name)
33
- unless class_exists?(klass_name)
34
- result[:success] = false
35
- result[:msg] = "Model does not exists"
36
- end
37
- else
38
- result[:success] = false
39
- result[:msg] = "Scaffold already exists"
40
- end
40
+ columns, fields, validations = ActiveExt::ExtHelpers::TableBuilder.generate_columns_and_fields(active_ext_core)
41
+ result = {
42
+ :success => true,
43
+ :use_ext_forms => active_ext_core.options[:use_ext_forms].nil? ? false : active_ext_core.options[:use_ext_forms],
44
+ :inline_edit => active_ext_core.options[:inline_edit].nil? ? false : active_ext_core.options[:inline_edit],
45
+ :columns => columns,
46
+ :fields => fields,
47
+ :validations => validations
48
+ }
49
+ render :inline => result.to_json
50
+ end
41
51
 
42
- return result
43
- end
44
-
45
- #get all file in root app/controllers and first level plugins app/controllers
46
- def find_active_ext_models
47
- model_names = []
48
-
49
- dirs = [Rails.root]
50
- dirs = dirs | Rails::Application::Railties.engines.map{|p| p.config.root.to_s}
51
-
52
- dirs.each do |dir|
53
- if File.exists? File.join(dir,"/app/controllers/erp_app/desktop/scaffold/")
54
- Dir.glob("#{dir}/app/controllers/erp_app/desktop/scaffold/*.rb") do |filename|
55
- next if filename =~ /#{['svn','git'].join("|")}/
56
- open(filename) do |file|
57
- if file.grep(/active_ext/).any?
58
- model = File.basename(filename).gsub("_controller.rb", "").classify
59
- if class_exists?(model)
60
- model_names << model
61
- end
62
- end
63
- end
64
- end
65
- end
52
+ def data
53
+ active_ext_core = setup_active_ext_core
54
+
55
+ json_text = nil
56
+
57
+ if request.get?
58
+ json_text = ActiveExt::ExtHelpers::DataHelper.build_json_data(active_ext_core, :limit => params[:limit], :offset => params[:start])
59
+ elsif request.post?
60
+ json_text = ActiveExt::ExtHelpers::DataHelper.create_record(active_ext_core, :data => params[:data])
61
+ elsif request.put?
62
+ json_text = ActiveExt::ExtHelpers::DataHelper.update_record(active_ext_core, :data => params[:data], :id => params[:data][:id])
63
+ elsif request.delete?
64
+ json_text = ActiveExt::ExtHelpers::DataHelper.delete_record(active_ext_core, :data => params[:data], :id => params[:data][:id])
66
65
  end
67
-
68
- model_names
69
- end
70
-
71
- def class_exists?(class_name)
72
- klass = Module.const_get(class_name)
73
- return klass.is_a?(Class) ? klass.superclass == ActiveRecord::Base : false
74
- rescue NameError
75
- return false
76
- end
77
-
78
- def load_files(name)
79
- #reload routes file
80
- load "#{Rails.root}/config/routes.rb"
81
-
82
- #load controller
83
- controller = "ErpApp::Desktop::Scaffold::#{name.classify}Controller"
84
- controller.constantize unless class_exists?(controller)
85
- end
86
- end
87
- end
88
- end
89
- end
66
+
67
+ render :inline => json_text
68
+ end
69
+
70
+ private
71
+
72
+ def setup_active_ext_core
73
+ model_id = params[:model_name]
74
+ default_options = {
75
+ :inline_edit => true,
76
+ :use_ext_forms => false,
77
+ :ignore_associations => true,
78
+ :show_id => true,
79
+ :show_timestamps => true,
80
+ :only => nil
81
+ }
82
+
83
+ ActiveExt::Core.new(model_id, default_options)
84
+ end
85
+
86
+ end #BaseController
87
+ end #Scaffold
88
+ end #Desktop
89
+ end #ErpApp
@@ -35,9 +35,9 @@ module ErpApp
35
35
  assign_to = params[:assign_to]
36
36
  assign_to_id = params[:id]
37
37
  sort = (params[:sort] || 'description').downcase
38
+ sort = 'capabilities.description' if sort == 'description'
38
39
  dir = (params[:dir] || 'asc').downcase
39
40
  query_filter = params[:query_filter].strip rescue nil
40
-
41
41
  scope_type_ids = [ScopeType.find_by_internal_identifier('class').id, ScopeType.find_by_internal_identifier('query').id]
42
42
 
43
43
  ar = assign_to_id.blank? ? Capability.joins(:capability_type) : assign_to.constantize.find(assign_to_id).capabilities_not.where("scope_type_id IN (#{scope_type_ids.join(',')})")
@@ -51,6 +51,7 @@ module ErpApp
51
51
  assign_to = params[:assign_to]
52
52
  assign_to_id = params[:id]
53
53
  sort = (params[:sort] || 'description').downcase
54
+ sort = 'capabilities.description' if sort == 'description'
54
55
  dir = (params[:dir] || 'asc').downcase
55
56
  query_filter = params[:query_filter].strip rescue nil
56
57
 
@@ -35,6 +35,7 @@ module ErpApp
35
35
  assign_to = params[:assign_to]
36
36
  assign_to_id = params[:id]
37
37
  sort = (params[:sort] || 'description').downcase
38
+ sort = 'groups.description' if sort == 'description'
38
39
  dir = (params[:dir] || 'asc').downcase
39
40
  query_filter = params[:query_filter].strip rescue nil
40
41
 
@@ -49,6 +50,7 @@ module ErpApp
49
50
  assign_to = params[:assign_to]
50
51
  assign_to_id = params[:id]
51
52
  sort = (params[:sort] || 'description').downcase
53
+ sort = 'groups.description' if sort == 'description'
52
54
  dir = (params[:dir] || 'asc').downcase
53
55
  query_filter = params[:query_filter].strip rescue nil
54
56
 
@@ -2,6 +2,7 @@
2
2
  <html xmlns="http://www.w3.org/1999/xhtml">
3
3
  <head>
4
4
  <style type="text/css">
5
+
5
6
  <%@desktop.applications.each do |application|%>
6
7
  .<%=application.shortcut_id%>-shortcut{
7
8
  background-image:url("/images/icons/<%=application.icon.split('-')[1]%>/<%=application.icon.split('-')[1]%>_48x48.png");
data/config/routes.rb CHANGED
@@ -42,7 +42,7 @@ ErpApp::Engine.routes.draw do
42
42
 
43
43
  #Desktop Applications
44
44
  #scaffold
45
- match '/desktop/scaffold/:action' => "desktop/scaffold/base"
45
+ match '/desktop/scaffold/:action((/:model_name)(.:format))' => "desktop/scaffold/base"
46
46
  match '/desktop/scaffold/role/:action(/:id)' => "desktop/scaffold/role#index"
47
47
 
48
48
  #user_management
@@ -1,82 +1,105 @@
1
1
  module ActiveExt
2
- class Core
3
- attr :model_id
4
- attr_accessor :columns
5
- attr_accessor :association_names
6
-
7
- #rails generated columns. Do not remove these
8
- RAILS_COLUMNS = [:id, :created_at, :updated_at]
9
- BETTER_NESTED_SET_COLUMNS = [:parent_id, :lft, :rgt]
10
-
11
- def initialize(model_id, options)
12
- @model_id = model_id.to_s.pluralize.singularize
13
- @options = options
14
-
15
- #get all attribute columns
16
- attribute_names = self.model.columns.collect{ |c| c.name.to_sym }.sort_by { |c| c.to_s }
17
-
18
- #only include attribute columns we care about, do not remove rails generated columns
19
- if options[:only]
20
- valid_columns = []
21
- options[:only].each do |option|
22
- if option.is_a?(Hash)
23
- valid_columns << option.keys.first
24
- else
25
- valid_columns << option
2
+ class Core
3
+ attr :model_id
4
+ attr_accessor :columns
5
+ attr_accessor :association_names
6
+
7
+ #rails generated columns. Do not remove these
8
+ RAILS_COLUMNS = [:id, :created_at, :updated_at]
9
+ BETTER_NESTED_SET_COLUMNS = [:parent_id, :lft, :rgt]
10
+
11
+ def initialize(model_id, options)
12
+ @model_id = model_id.to_s.pluralize.singularize
13
+ @options = options
14
+
15
+ #get all attribute columns
16
+ attribute_names = self.model.columns.collect { |c| c.name.to_sym }.sort_by { |c| c.to_s }
17
+
18
+ #only include attribute columns we care about, do not remove rails generated columns
19
+ if options[:only]
20
+ valid_columns = []
21
+ options[:only].each do |option|
22
+ if option.is_a?(Hash)
23
+ valid_columns << option.keys.first
24
+ else
25
+ valid_columns << option
26
+ end
26
27
  end
28
+ valid_columns = valid_columns | RAILS_COLUMNS
29
+ attribute_names.delete_if { |item| !valid_columns.include?(item.to_sym) }
30
+ end
31
+
32
+ #if we are including associations get them
33
+ unless options[:ignore_associations]
34
+ @association_names = self.model.reflect_on_all_associations.collect { |a| a.name.to_sym }
35
+ association_column_names = @association_names.sort_by { |c| c.to_s }
36
+ attribute_names += association_column_names
27
37
  end
28
- valid_columns = valid_columns | RAILS_COLUMNS
29
- attribute_names.delete_if{|item| !valid_columns.include?(item.to_sym)}
38
+
39
+ @columns = ActiveExt::DataStructures::Columns.new(self.model, attribute_names)
40
+
41
+ #exclude id columns and count columns and better nested set columns
42
+ @columns.exclude(*@columns.find_all { |c| c.column and (c.column.primary or c.column.name =~ /(_id|_count)$/) }.collect { |c| c.name })
43
+ #exclude nested set columns
44
+ @columns.exclude(*@columns.find_all { |c| c.column and (BETTER_NESTED_SET_COLUMNS.include?(c.column.name.to_sym)) }.collect { |c| c.name })
45
+ #exclude associations columns
46
+ @columns.exclude(*self.model.reflect_on_all_associations.collect { |a| :"#{a.name}_type" if a.options[:polymorphic] }.compact)
47
+
48
+ set_column_options
30
49
  end
31
50
 
32
- #if we are including associations get them
33
- unless options[:ignore_associations]
34
- @association_names = self.model.reflect_on_all_associations.collect{ |a| a.name.to_sym }
35
- association_column_names = @association_names.sort_by { |c| c.to_s }
36
- attribute_names += association_column_names
51
+ def model_id
52
+ @model_id
37
53
  end
38
54
 
39
- @columns = ActiveExt::DataStructures::Columns.new(self.model, attribute_names)
40
-
41
- #exclude id columns and count columns and better nested set columns
42
- @columns.exclude(*@columns.find_all { |c| c.column and (c.column.primary or c.column.name =~ /(_id|_count)$/) }.collect {|c| c.name})
43
- #exclude nested set columns
44
- @columns.exclude(*@columns.find_all { |c| c.column and (BETTER_NESTED_SET_COLUMNS.include?(c.column.name.to_sym)) }.collect {|c| c.name})
45
- #exclude associations columns
46
- @columns.exclude(*self.model.reflect_on_all_associations.collect{|a| :"#{a.name}_type" if a.options[:polymorphic]}.compact)
55
+ def model
56
+ @model ||= @model_id.to_s.camelize.constantize
57
+ end
47
58
 
48
- set_column_options
49
- end
59
+ def options
60
+ @options
61
+ end
50
62
 
51
- def model_id
52
- @model_id
53
- end
54
-
55
- def model
56
- @model ||= @model_id.to_s.camelize.constantize
57
- end
63
+ def non_excluded_columns
64
+ columns = []
58
65
 
59
- def options
60
- @options
61
- end
66
+ #add id column if showing it
67
+ if self.options[:show_id]
68
+ columns << core.columns[:id]
69
+ end
70
+
71
+ #build ext columns
72
+ self.columns.each do |column|
73
+ next if column.name.to_s =~ /(^id|created_at|updated_at)$/ || self.columns.exclude_column?(column.name)
74
+ columns << column
75
+ end
76
+
77
+ #add timestamp columns if showing them
78
+ if self.options[:show_timestamps]
79
+ columns << self.columns[:created_at]
80
+ columns << self.columns[:updated_at]
81
+ end
82
+
83
+ columns
84
+ end
85
+
86
+ private
62
87
 
63
- private
64
-
65
- def set_column_options
66
- all_column_options = self.options[:only]
67
- self.columns.each do |column|
68
- if RAILS_COLUMNS.include?(column.name)
69
- column.options = {:readonly => true, :required => false}
70
- else
71
- unless all_column_options.nil?
72
- column_options = all_column_options.find{|item| item.is_a?(Hash) && item.has_key?(column.name)}
73
- unless column_options.nil?
74
- column.options = column_options[column.name]
88
+ def set_column_options
89
+ all_column_options = self.options[:only]
90
+ self.columns.each do |column|
91
+ if RAILS_COLUMNS.include?(column.name)
92
+ column.options = {:readonly => true, :required => false}
93
+ else
94
+ unless all_column_options.nil?
95
+ column_options = all_column_options.find { |item| item.is_a?(Hash) && item.has_key?(column.name) }
96
+ unless column_options.nil?
97
+ column.options = column_options[column.name]
98
+ end
75
99
  end
76
100
  end
77
101
  end
78
102
  end
79
- end
80
103
 
81
- end
104
+ end
82
105
  end
@@ -1,21 +1,21 @@
1
1
  module ActiveExt
2
- module DataStructures
3
- class Column
4
- attr_accessor :name, :association, :column, :options
5
-
6
- def initialize(name, active_record_class)
7
- @name = name.to_sym
8
- @column = active_record_class.columns_hash[self.name.to_s]
9
- @association = active_record_class.reflect_on_association(self.name)
10
- @active_record_class = active_record_class
11
- @table = active_record_class.table_name
12
- #set default options
13
- @options = {:required => false, :readonly => false}
14
- end
2
+ module DataStructures
3
+ class Column
4
+ attr_accessor :name, :association, :column, :options
5
+
6
+ def initialize(name, active_record_class)
7
+ @name = name.to_sym
8
+ @column = active_record_class.columns_hash[self.name.to_s]
9
+ @association = active_record_class.reflect_on_association(self.name)
10
+ @active_record_class = active_record_class
11
+ @table = active_record_class.table_name
12
+ #set default options
13
+ @options = {:required => false, :readonly => false}
14
+ end
15
15
 
16
- def sql_type
17
- @column.type
16
+ def sql_type
17
+ @column.type
18
+ end
19
+ end
18
20
  end
19
- end
20
- end
21
21
  end
@@ -1,66 +1,69 @@
1
1
  module ActiveExt
2
- module DataStructures
3
- class Columns
4
- include Enumerable
2
+ module DataStructures
3
+ class Columns
4
+ include Enumerable
5
5
 
6
- # This collection is referenced by other parts of ActiveExt and by methods within this DataStructure.
7
- # IT IS NOT MEANT FOR PUBLIC USE (but if you know what you're doing, go ahead)
8
- def _inheritable=(value)
9
- @sorted = true
10
- @_inheritable = value
11
- end
6
+ # This collection is referenced by other parts of ActiveExt and by methods within this DataStructure.
7
+ # IT IS NOT MEANT FOR PUBLIC USE (but if you know what you're doing, go ahead)
8
+ def _inheritable=(value)
9
+ @sorted = true
10
+ @_inheritable = value
11
+ end
12
12
 
13
- # This accessor is used by ActionColumns to create new Column objects without adding them to this set
14
- attr_reader :active_record_class
13
+ # This accessor is used by ActionColumns to create new Column objects without adding them to this set
14
+ attr_reader :active_record_class
15
15
 
16
- def initialize(active_record_class, *args)
17
- @active_record_class = active_record_class
18
- @_inheritable = []
19
- @excluded_columns = []
20
- @set = []
16
+ def initialize(active_record_class, *args)
17
+ @active_record_class = active_record_class
18
+ @_inheritable = []
19
+ @excluded_columns = []
20
+ @set = []
21
21
 
22
- self.add *args
23
- end
22
+ self.add *args
23
+ end
24
24
 
25
- # the way to add columns to the set. this is primarily useful for virtual columns.
26
- # note that this also makes columns inheritable
27
- def add(*args)
28
- args.flatten! # allow [] as a param
29
- args = args.collect{ |a| a.to_sym }
25
+ # the way to add columns to the set. this is primarily useful for virtual columns.
26
+ # note that this also makes columns inheritable
27
+ def add(*args)
28
+ args.flatten! # allow [] as a param
29
+ args = args.collect { |a| a.to_sym }
30
30
 
31
- # make the columns inheritable
32
- @_inheritable.concat(args)
33
- # then add columns to @set (unless they already exist)
34
- args.each { |a| @set << ActiveExt::DataStructures::Column.new(a.to_sym, @active_record_class) unless find_by_name(a) }
35
- end
36
- alias_method :<<, :add
31
+ # make the columns inheritable
32
+ @_inheritable.concat(args)
33
+ # then add columns to @set (unless they already exist)
34
+ args.each { |a| @set << ActiveExt::DataStructures::Column.new(a.to_sym, @active_record_class) unless find_by_name(a) }
35
+ end
37
36
 
38
- def exclude(*args)
39
- # only remove columns from _inheritable. we never want to completely forget about a column.
40
- args.each { |a| @_inheritable.delete a }
41
- @excluded_columns.concat(args)
42
- end
37
+ alias_method :<<, :add
43
38
 
44
- # returns an array of columns with the provided names
45
- def find_by_names(*names)
46
- @set.find_all { |column| names.include? column.name }
47
- end
39
+ def exclude(*args)
40
+ # only remove columns from _inheritable. we never want to completely forget about a column.
41
+ args.each { |a| @_inheritable.delete a }
42
+ @excluded_columns.concat(args)
43
+ end
48
44
 
49
- # returns the column of the given name.
50
- def find_by_name(name)
51
- # this works because of `def column.=='
52
- column = @set.find { |c| c.name == name }
53
- column
54
- end
55
- alias_method :[], :find_by_name
45
+ # returns an array of columns with the provided names
46
+ def find_by_names(*names)
47
+ @set.find_all { |column| names.include? column.name }
48
+ end
56
49
 
57
- def each
58
- @set.each {|i| yield i }
59
- end
50
+ # returns the column of the given name.
51
+ def find_by_name(name)
52
+ # this works because of `def column.=='
53
+ column = @set.find { |c| c.name == name }
54
+ column
55
+ end
56
+
57
+ alias_method :[], :find_by_name
58
+
59
+ def each
60
+ @set.each { |i| yield i }
61
+ end
62
+
63
+ def exclude_column?(name)
64
+ @excluded_columns.include?(name)
65
+ end
60
66
 
61
- def exclude_column?(name)
62
- @excluded_columns.include?(name)
67
+ end
63
68
  end
64
- end
65
- end
66
69
  end