kirgudu_base 0.0.3 → 0.0.4
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 +4 -4
- data/app/assets/javascripts/kirgudu_base/dynamicEvents.js +2 -1
- data/app/assets/javascripts/kirgudu_base/jquery.container-management.js +241 -0
- data/app/assets/javascripts/kirgudu_base/jquery.fancybox copia.js +2020 -0
- data/app/assets/javascripts/kirgudu_base/scripts_nrg.js +300 -383
- data/app/controllers/kirgudu_base/admin_controller.rb +1 -44
- data/app/controllers/kirgudu_base/application_controller.rb +135 -92
- data/app/controllers/kirgudu_base/cabinet_controller.rb +35 -35
- data/app/controllers/kirgudu_base/security/authentications_controller.rb +452 -0
- data/app/controllers/kirgudu_base/security/email_confirmations_controller.rb +46 -0
- data/app/helpers/kirgudu_base/application_helper.rb +25 -0
- data/app/helpers/kirgudu_base/authentication_form_builder.rb +76 -0
- data/app/helpers/kirgudu_base/controllers/{basic_actions_with_parent.rb → OLD_basic_actions.rb} +39 -54
- data/app/helpers/kirgudu_base/controllers/basic_actions.rb +967 -161
- data/app/helpers/kirgudu_base/controllers/container_items_management_actions.rb +118 -40
- data/app/helpers/kirgudu_base/controllers/container_items_sorting_actions.rb +2 -2
- data/app/helpers/kirgudu_base/controllers/dynamic_pages.rb +147 -11
- data/app/helpers/kirgudu_base/form_builder.rb +3 -1
- data/app/helpers/kirgudu_base/gui_helper.rb +10 -5
- data/app/helpers/kirgudu_base/models/exports.rb +122 -122
- data/app/helpers/kirgudu_base/models/scopes.rb +5 -0
- data/app/mailers/authentications_mailer.rb +53 -0
- data/app/models/kirgudu_base/base_model.rb +47 -14
- data/app/models/kirgudu_base/dynamic_pages/builder.rb +0 -8
- data/app/models/kirgudu_base/dynamic_pages/controller_link.rb +4 -1
- data/app/models/kirgudu_base/dynamic_pages/controller_link_builder.rb +2 -1
- data/app/models/kirgudu_base/dynamic_pages/controller_link_id.rb +6 -6
- data/app/models/kirgudu_base/dynamic_pages/controller_link_id_builder.rb +6 -6
- data/app/models/kirgudu_base/dynamic_pages/element.rb +4 -5
- data/app/models/kirgudu_base/dynamic_pages/entry_builder.rb +2 -2
- data/app/models/kirgudu_base/dynamic_pages/event_if_block_builder.rb +1 -1
- data/app/models/kirgudu_base/dynamic_pages/form_builder.rb +2 -2
- data/app/models/kirgudu_base/dynamic_pages/list.rb +2 -0
- data/app/models/kirgudu_base/dynamic_pages/list_builder.rb +7 -3
- data/app/models/kirgudu_base/dynamic_pages/management_settings.rb +30 -0
- data/app/models/kirgudu_base/dynamic_pages/management_settings_builder.rb +47 -0
- data/app/models/kirgudu_base/dynamic_pages/menu.rb +9 -5
- data/app/models/kirgudu_base/dynamic_pages/menu_builder.rb +8 -5
- data/app/models/kirgudu_base/dynamic_pages/menu_item.rb +22 -6
- data/app/models/kirgudu_base/dynamic_pages/menu_items_block_builder.rb +9 -4
- data/app/models/kirgudu_base/dynamic_pages/menu_section.rb +38 -0
- data/app/models/kirgudu_base/dynamic_pages/menu_section_builder.rb +36 -0
- data/app/models/kirgudu_base/dynamic_pages/page.rb +6 -2
- data/app/models/kirgudu_base/dynamic_pages/page_builder.rb +18 -0
- data/app/models/kirgudu_base/dynamic_pages/relation.rb +23 -0
- data/app/models/kirgudu_base/dynamic_pages/relation_builder.rb +35 -0
- data/app/models/kirgudu_base/dynamic_pages/sorting_settings.rb +31 -0
- data/app/models/kirgudu_base/dynamic_pages/sorting_settings_builder.rb +48 -0
- data/app/models/kirgudu_base/security/autheintication.rb +4 -0
- data/app/models/kirgudu_base/security/authentication.rb +6 -7
- data/app/models/kirgudu_base/security/email_confirmation.rb +7 -0
- data/app/models/kirgudu_base/security/restore_password_code.rb +5 -0
- data/app/models/kirgudu_base/security/user.rb +2 -0
- data/app/models/kirgudu_base/security.rb +6 -7
- data/app/models/kirgudu_base/settings/group.rb +22 -0
- data/app/models/kirgudu_base/settings/option.rb +44 -0
- data/app/models/kirgudu_base/settings/settings_manager.rb +69 -0
- data/app/models/kirgudu_base/settings/value.rb +36 -0
- data/app/views/admin_templates/default/admin/layouts/application.html.erb +6 -4
- data/app/views/admin_templates/default/admin/system/settings/groups/edit.html.erb +9 -9
- data/app/views/admin_templates/default/admin/system/settings/groups/new.html.erb +1 -1
- data/app/views/admin_templates/default/admin/system/settings/options/edit.html.erb +1 -1
- data/app/views/admin_templates/default/admin/system/settings/options/new.html.erb +1 -1
- data/app/views/admin_templates/default/admin/system/settings/values/edit.html.erb +1 -1
- data/app/views/admin_templates/default/admin/system/settings/values/new.html.erb +1 -1
- data/app/views/admin_templates/erp/admin/shared/_top_nav_bar.html.erb +1 -3
- data/app/views/admin_templates/erp/admin/shared/entry_edit_form_renderer.html.erb +1 -1
- data/app/views/admin_templates/erp/admin/shared/entry_new_form_renderer.html.erb +1 -1
- data/app/views/admin_templates/good/admin/layouts/OLD_application.html.erb +14 -14
- data/app/views/admin_templates/good/admin/layouts/application.html.erb +11 -113
- data/app/views/admin_templates/good/admin/shared/_left_menu.html.erb +74 -63
- data/app/views/admin_templates/good/{zapanel/files/New Adobe Photoshop Image 12.psd → admin/shared/_left_menu_item.html.erb} +0 -0
- data/app/views/admin_templates/good/admin/shared/_left_menu_section.html.erb +21 -0
- data/app/views/admin_templates/good/admin/shared/render_new_OLD.html.erb +90 -0
- data/app/views/admin_templates/good/admin/shared/renderer_edit.html.erb +44 -13
- data/app/views/admin_templates/good/admin/shared/renderer_edit_OLD.html.erb +106 -0
- data/app/views/admin_templates/good/admin/shared/renderer_entries_list.html.erb +39 -18
- data/app/views/admin_templates/good/admin/shared/renderer_entries_list_with_parent.html.erb +4 -4
- data/app/views/admin_templates/good/admin/shared/renderer_management.html.erb +164 -0
- data/app/views/admin_templates/good/admin/shared/renderer_new.html.erb +40 -10
- data/app/views/admin_templates/good/admin/shared/renderer_show.html.erb +170 -58
- data/app/views/admin_templates/good/admin/shared/renderer_show_OLD.html.erb +159 -0
- data/app/views/admin_templates/good/admin/shared/renderer_sorting.html.erb +30 -0
- data/app/views/admin_templates/good/kirgudu_base/authentications/login.html.erb +13 -13
- data/app/views/admin_templates/good/kirgudu_base/authentications/register.html.erb +1 -1
- data/app/views/admin_templates/good/kirgudu_base/old/login_page.html.erb +7 -7
- data/app/views/admin_templates/good_flexy/admin/layouts/application.html.erb +17 -16
- data/app/views/admin_templates/good_flexy/admin/shared/_left_menu.html.erb +7 -0
- data/app/views/admin_templates/good_flexy/admin/shared/renderer_entries_list.html.erb +25 -17
- data/app/views/admin_templates/good_flexy/admin/shared/renderer_form_edit.html.erb +34 -13
- data/app/views/admin_templates/good_flexy/admin/shared/renderer_form_new.html.erb +31 -10
- data/app/views/admin_templates/good_flexy/admin/shared/renderer_show.html.erb +67 -52
- data/config/locales/kirgudu_base.ru.yml +92 -0
- data/config/routes.rb +16 -16
- data/db/migrate/20140413134252_create_kirgudu_base_security_authentications.rb +15 -0
- data/db/migrate/20140413152144_create_kirgudu_base_security_email_confirmations.rb +17 -0
- data/db/migrate/20140413201121_add_confirmations_kirgudu_base_security_users.rb +14 -0
- data/db/migrate/20140415093106_create_kirgudu_base_security_restore_password_codes.rb +20 -0
- data/lib/kirgudu_base.rb +2 -2
- data/test/fixtures/kirgudu_base/kirgudu_base/security/autheintications.yml +11 -0
- data/test/fixtures/kirgudu_base/security/applications.yml +21 -0
- data/test/fixtures/kirgudu_base/security/autheintications.yml +11 -0
- data/test/fixtures/kirgudu_base/security/authentications.yml +11 -0
- data/test/fixtures/kirgudu_base/security/email_confirmations.yml +13 -0
- data/test/fixtures/kirgudu_base/security/restore_password_codes.yml +13 -0
- data/test/models/kirgudu_base/kirgudu_base/security/autheintication_test.rb +9 -0
- data/test/models/kirgudu_base/security/application_test.rb +9 -0
- data/test/models/kirgudu_base/security/autheintication_test.rb +9 -0
- data/test/models/kirgudu_base/security/authentication_test.rb +9 -0
- data/test/models/kirgudu_base/security/email_confirmation_test.rb +9 -0
- data/test/models/kirgudu_base/security/restore_password_code_test.rb +9 -0
- metadata +102 -79
- data/app/assets/javascripts/kirgudu_base/jquery.fancybox.pack.js +0 -45
- data/app/controllers/kirgudu_base/authentications_controller.rb +0 -157
- data/app/views/admin_templates/good/zapanel/404.html +0 -386
- data/app/views/admin_templates/good/zapanel/billing.html +0 -550
- data/app/views/admin_templates/good/zapanel/blank-page.html +0 -343
- data/app/views/admin_templates/good/zapanel/buttons.html +0 -1018
- data/app/views/admin_templates/good/zapanel/calendars.html +0 -451
- data/app/views/admin_templates/good/zapanel/cart.html +0 -522
- data/app/views/admin_templates/good/zapanel/charts.html +0 -611
- data/app/views/admin_templates/good/zapanel/collapse.html +0 -555
- data/app/views/admin_templates/good/zapanel/contact.php +0 -102
- data/app/views/admin_templates/good/zapanel/dashboard.html +0 -985
- data/app/views/admin_templates/good/zapanel/dashboard2.html +0 -1091
- data/app/views/admin_templates/good/zapanel/dashboard3.html +0 -1079
- data/app/views/admin_templates/good/zapanel/data/movies.json +0 -1
- data/app/views/admin_templates/good/zapanel/faq.html +0 -435
- data/app/views/admin_templates/good/zapanel/file-manager.html +0 -358
- data/app/views/admin_templates/good/zapanel/files/index.php +0 -0
- data/app/views/admin_templates/good/zapanel/font-awesome/less/bootstrap.less +0 -84
- data/app/views/admin_templates/good/zapanel/font-awesome/less/core.less +0 -129
- data/app/views/admin_templates/good/zapanel/font-awesome/less/extras.less +0 -93
- data/app/views/admin_templates/good/zapanel/font-awesome/less/font-awesome-ie7.less +0 -1953
- data/app/views/admin_templates/good/zapanel/font-awesome/less/font-awesome.less +0 -33
- data/app/views/admin_templates/good/zapanel/font-awesome/less/icons.less +0 -381
- data/app/views/admin_templates/good/zapanel/font-awesome/less/mixins.less +0 -48
- data/app/views/admin_templates/good/zapanel/font-awesome/less/path.less +0 -14
- data/app/views/admin_templates/good/zapanel/font-awesome/less/variables.less +0 -735
- data/app/views/admin_templates/good/zapanel/font-awesome/scss/_bootstrap.scss +0 -84
- data/app/views/admin_templates/good/zapanel/font-awesome/scss/_core.scss +0 -129
- data/app/views/admin_templates/good/zapanel/font-awesome/scss/_extras.scss +0 -93
- data/app/views/admin_templates/good/zapanel/font-awesome/scss/_icons.scss +0 -381
- data/app/views/admin_templates/good/zapanel/font-awesome/scss/_mixins.scss +0 -48
- data/app/views/admin_templates/good/zapanel/font-awesome/scss/_path.scss +0 -14
- data/app/views/admin_templates/good/zapanel/font-awesome/scss/_variables.scss +0 -734
- data/app/views/admin_templates/good/zapanel/font-awesome/scss/font-awesome-ie7.scss +0 -1953
- data/app/views/admin_templates/good/zapanel/font-awesome/scss/font-awesome.scss +0 -33
- data/app/views/admin_templates/good/zapanel/form.html +0 -790
- data/app/views/admin_templates/good/zapanel/gallery.html +0 -392
- data/app/views/admin_templates/good/zapanel/grids.html +0 -574
- data/app/views/admin_templates/good/zapanel/hosting-dashboard.html +0 -448
- data/app/views/admin_templates/good/zapanel/icon.html +0 -722
- data/app/views/admin_templates/good/zapanel/inbox.html +0 -375
- data/app/views/admin_templates/good/zapanel/index.html +0 -48
- data/app/views/admin_templates/good/zapanel/invoice.html +0 -423
- data/app/views/admin_templates/good/zapanel/js/proxy/elFinderSupportVer1.js +0 -338
- data/app/views/admin_templates/good/zapanel/js/skins/default/lightbox-close.png +0 -0
- data/app/views/admin_templates/good/zapanel/js/skins/default/lightbox-next.png +0 -0
- data/app/views/admin_templates/good/zapanel/js/skins/default/lightbox-prev.png +0 -0
- data/app/views/admin_templates/good/zapanel/notification.html +0 -400
- data/app/views/admin_templates/good/zapanel/order-recieved.html +0 -348
- data/app/views/admin_templates/good/zapanel/php/MySQLStorage.sql +0 -23
- data/app/views/admin_templates/good/zapanel/php/connector.php +0 -44
- data/app/views/admin_templates/good/zapanel/php/elFinder.class.php +0 -1103
- data/app/views/admin_templates/good/zapanel/php/elFinderConnector.class.php +0 -133
- data/app/views/admin_templates/good/zapanel/php/elFinderVolumeDriver.class.php +0 -3370
- data/app/views/admin_templates/good/zapanel/php/elFinderVolumeLocalFileSystem.class.php +0 -835
- data/app/views/admin_templates/good/zapanel/php/elFinderVolumeMySQL.class.php +0 -896
- data/app/views/admin_templates/good/zapanel/php/mime.types +0 -512
- data/app/views/admin_templates/good/zapanel/price-table.html +0 -400
- data/app/views/admin_templates/good/zapanel/profile.html +0 -387
- data/app/views/admin_templates/good/zapanel/progressbar.html +0 -555
- data/app/views/admin_templates/good/zapanel/range-slider.html +0 -440
- data/app/views/admin_templates/good/zapanel/ribbon-grids.html +0 -491
- data/app/views/admin_templates/good/zapanel/sale-purchase-dashboard.html +0 -803
- data/app/views/admin_templates/good/zapanel/search.html +0 -370
- data/app/views/admin_templates/good/zapanel/skins/default/lightbox-close.png +0 -0
- data/app/views/admin_templates/good/zapanel/skins/default/lightbox-loading.gif +0 -0
- data/app/views/admin_templates/good/zapanel/skins/default/lightbox-next.png +0 -0
- data/app/views/admin_templates/good/zapanel/skins/default/lightbox-pause.png +0 -0
- data/app/views/admin_templates/good/zapanel/skins/default/lightbox-play.png +0 -0
- data/app/views/admin_templates/good/zapanel/skins/default/lightbox-playvideo.png +0 -0
- data/app/views/admin_templates/good/zapanel/skins/default/lightbox-prev.png +0 -0
- data/app/views/admin_templates/good/zapanel/slider.html +0 -453
- data/app/views/admin_templates/good/zapanel/tables.html +0 -470
- data/app/views/admin_templates/good/zapanel/typography.html +0 -746
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
module KirguduBase
|
|
4
4
|
module Controllers
|
|
5
5
|
module BasicActions
|
|
6
|
-
|
|
7
6
|
################################################################################################################
|
|
8
7
|
######################################### Base and Ajax Modules ######################################
|
|
9
8
|
################################################################################################################
|
|
@@ -20,89 +19,196 @@ module KirguduBase
|
|
|
20
19
|
raise "Method :get_kb_page must be implemented for controller '#{self.class}'"
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
options = {
|
|
23
|
+
logger: string_logger
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
local_data = {
|
|
27
|
+
errors: [],
|
|
28
|
+
messages: [],
|
|
29
|
+
page: self.class.get_kb_page(:index)
|
|
30
|
+
}
|
|
24
31
|
|
|
25
|
-
unless
|
|
32
|
+
unless local_data[:page]
|
|
26
33
|
respond_to do |format|
|
|
27
|
-
format.html { render_html1 self.
|
|
34
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
28
35
|
format.json { render_json_page_404 }
|
|
29
36
|
end
|
|
30
37
|
return
|
|
31
38
|
end
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
self.fill_obligatory_filters(
|
|
36
|
-
|
|
37
|
-
logger: string_logger
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
local_filters_data = self.load_data_for_filters_controls(local_page.lists[:entries_list], params)
|
|
41
|
-
|
|
42
|
-
local_entries_list = self.entry_class.get_entries(nil, filters, options)
|
|
40
|
+
# fill parent for data
|
|
41
|
+
filters_for_parents = {}
|
|
42
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
43
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
43
44
|
|
|
44
45
|
|
|
46
|
+
filters = self.get_filters_for_list(local_data[:page].lists[:entries_list], params)
|
|
47
|
+
self.fill_obligatory_filters(filters)
|
|
48
|
+
filters.merge!(local_data[:parent_ids])
|
|
49
|
+
|
|
50
|
+
filters[:per_page] = 30 unless filters[:per_page]
|
|
51
|
+
filters[:per_page] ||= 30
|
|
52
|
+
|
|
53
|
+
# retrieving filters data from database
|
|
54
|
+
local_data[:filters_data] = self.load_data_for_filters_controls(local_data[:page].lists[:entries_list], params)
|
|
55
|
+
# retrieving entries from database
|
|
56
|
+
local_data[:entries] = self.entry_class.get_entries(nil, filters, options)
|
|
57
|
+
|
|
58
|
+
# filling filters for current url
|
|
59
|
+
filters_for_current_url = self.get_filters_for_list(local_data[:page].lists[:entries_list], params)
|
|
60
|
+
filters_for_current_url.merge!(local_data[:parent_ids])
|
|
61
|
+
local_data[:current_url] = self.to_url_for(:index, filters_for_current_url)
|
|
62
|
+
|
|
63
|
+
# building breadcrumbs
|
|
64
|
+
home_controller = self.class.get_method_latest_result(:get_kb_home_controller)
|
|
65
|
+
home_controller = eval(home_controller) if home_controller and home_controller.is_a?(String)
|
|
66
|
+
if home_controller
|
|
67
|
+
if self.class == home_controller
|
|
68
|
+
add_new_breadcrumb(I18n.t("#{home_controller.to_i18n}.index.title"))
|
|
69
|
+
else
|
|
70
|
+
add_new_breadcrumb(I18n.t("#{home_controller.to_i18n}.index.title"), home_controller.to_url_for(:index))
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
parent_ids = {}
|
|
74
|
+
local_data[:parents].each do |parent|
|
|
75
|
+
# breadcrumbs: adding parent index
|
|
76
|
+
add_new_breadcrumb(I18n.t("#{parent[:controller].to_i18n}.index.title"), parent[:controller].to_url_for(:index, parent_ids))
|
|
77
|
+
# breadcrumbs: getting parent entry name
|
|
78
|
+
parent_entry_name = nil
|
|
79
|
+
parent_entry_name = parent[:entry].name_for_breadcrumbs if parent[:entry].respond_to?(:name_for_breadcrumbs)
|
|
80
|
+
parent_entry_name = parent[:entry].id unless parent_entry_name
|
|
81
|
+
# breadcrumbs: adding parent entry
|
|
82
|
+
add_new_breadcrumb(parent_entry_name, parent[:controller].to_url_for(:show, parent_ids.merge(id: parent[:entry].id)))
|
|
83
|
+
parent_ids[parent[:id_param]] = parent[:id_value]
|
|
84
|
+
end if local_data[:parents]
|
|
85
|
+
# breadcrumbs: adding current index
|
|
86
|
+
add_new_breadcrumb(I18n.t("#{self.to_i18n}.index.title"), self.to_url_for(:index, local_data[:parent_ids]))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# logger.info "TEMPLATE PATH: #{self.class.get_method_latest_result(:get_kb_template)}"
|
|
91
|
+
# logger.info "VIEW PATH: #{self.class.get_method_latest_result(:get_kb_view_path, :index)}"
|
|
92
|
+
|
|
93
|
+
# rendering page
|
|
45
94
|
respond_to do |format|
|
|
46
|
-
format.html { render_html1 self.
|
|
47
|
-
format.json { render_json_ok(
|
|
95
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :index)}", locals: {data: local_data} }
|
|
96
|
+
format.json { render_json_ok(local_data[:entries]) }
|
|
48
97
|
end
|
|
49
98
|
end
|
|
50
|
-
|
|
51
99
|
end
|
|
52
100
|
|
|
53
|
-
module ShowActions
|
|
54
101
|
|
|
55
|
-
def show
|
|
56
102
|
|
|
103
|
+
module ShowActions
|
|
104
|
+
def show
|
|
57
105
|
unless self.class.respond_to?(:get_kb_page)
|
|
58
106
|
raise "Method :get_kb_page must be implemented for controller '#{self.class}'"
|
|
59
107
|
end
|
|
60
108
|
|
|
61
|
-
|
|
109
|
+
options = {
|
|
110
|
+
logger: self.string_logger
|
|
111
|
+
}
|
|
112
|
+
|
|
62
113
|
|
|
63
|
-
|
|
114
|
+
local_data = {
|
|
115
|
+
errors: [],
|
|
116
|
+
messages: [],
|
|
117
|
+
page: self.class.get_kb_page(:show)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if local_data[:page].nil?
|
|
64
121
|
respond_to do |format|
|
|
65
|
-
format.html { render_html1 self.
|
|
122
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
66
123
|
format.json { render_json_page_404 }
|
|
67
124
|
end
|
|
68
125
|
return
|
|
69
126
|
end
|
|
70
127
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
#
|
|
76
|
-
# if menu
|
|
77
|
-
# parent_menu.items.each do |menu_item|
|
|
78
|
-
# menu.items << menu_item
|
|
79
|
-
# end
|
|
80
|
-
# end
|
|
81
|
-
# end if parent_page
|
|
82
|
-
#end
|
|
83
|
-
|
|
84
|
-
|
|
128
|
+
# fill parent for data
|
|
129
|
+
filters_for_parents = {}
|
|
130
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
131
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
132
|
+
# fill filters for search
|
|
85
133
|
filters = {}
|
|
86
134
|
self.fill_obligatory_filters(filters)
|
|
135
|
+
filters.merge!(local_data[:parent_ids])
|
|
136
|
+
# getting local entry
|
|
137
|
+
local_data[:entry] = self.entry_class.get_entry_by_id(params[:id], filters, options)
|
|
138
|
+
# entry not found, showing not found page
|
|
139
|
+
unless local_data[:entry]
|
|
140
|
+
local_data[:errors] << I18n.t("#{self.to_i18n}.messages.not_found", entry_id: params[:id])
|
|
141
|
+
respond_to do |format|
|
|
142
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :entry_not_found)}", locals: {data: local_data} }
|
|
143
|
+
format.json { render_json_not_found message: local_data[:errors] }
|
|
144
|
+
end
|
|
145
|
+
return
|
|
146
|
+
end
|
|
147
|
+
# getting lists
|
|
148
|
+
local_data[:page].lists.each_pair do |key, list|
|
|
149
|
+
if list.relation
|
|
150
|
+
filters_for_list = {}
|
|
151
|
+
self.fill_obligatory_filters(filters_for_list)
|
|
152
|
+
reflection = self.entry_class.reflections[list.relation.name]
|
|
153
|
+
list_per_page = list.relation.per_page_param
|
|
154
|
+
list_page = list.relation.page_param
|
|
87
155
|
|
|
88
|
-
|
|
156
|
+
begin
|
|
157
|
+
filters_for_list[:per_page] = params[list_per_page].to_i
|
|
158
|
+
rescue
|
|
159
|
+
end
|
|
160
|
+
filters_for_list[:per_page] ||= 30
|
|
161
|
+
filters_for_list[:per_page] = 30 if filters_for_list[:per_page] == 0
|
|
89
162
|
|
|
163
|
+
begin
|
|
164
|
+
filters_for_list[:page] = params[list_page].to_i if params[list_page]
|
|
165
|
+
rescue
|
|
166
|
+
end
|
|
90
167
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
entry: local_entry
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
format.json { render json: local_entry.errors, status: :unprocessable_entity }
|
|
168
|
+
filters_for_list[reflection.foreign_key] = local_data[:entry].id
|
|
169
|
+
|
|
170
|
+
#logger.info "FILTERS for LIST: #{filters_for_list.to_json}"
|
|
171
|
+
|
|
172
|
+
local_data[:"list_entries_#{list.name}"] = eval(reflection.class_name).get_entries(nil, filters_for_list, options)
|
|
100
173
|
end
|
|
101
|
-
|
|
174
|
+
end if local_data[:page].lists
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
# fill parent for data
|
|
178
|
+
filters_for_parents = {}
|
|
179
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
180
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
181
|
+
# building breadcrumbs
|
|
182
|
+
home_controller = self.class.get_method_latest_result(:get_kb_home_controller)
|
|
183
|
+
home_controller = eval(home_controller) if home_controller and home_controller.is_a?(String)
|
|
184
|
+
add_new_breadcrumb(I18n.t("#{home_controller.to_i18n}.index.title"), home_controller.to_url_for(:index)) if home_controller
|
|
185
|
+
parent_ids = {}
|
|
186
|
+
local_data[:parents].each do |parent|
|
|
187
|
+
# breadcrumbs: adding parent index
|
|
188
|
+
add_new_breadcrumb(I18n.t("#{parent[:controller].to_i18n}.index.title"), parent[:controller].to_url_for(:index, parent_ids))
|
|
189
|
+
# breadcrumbs: getting parent entry name
|
|
190
|
+
parent_entry_name = nil
|
|
191
|
+
parent_entry_name = parent[:entry].name_for_breadcrumbs if parent[:entry].respond_to?(:name_for_breadcrumbs)
|
|
192
|
+
parent_entry_name = parent[:entry].id unless parent_entry_name
|
|
193
|
+
# breadcrumbs: adding parent entry
|
|
194
|
+
add_new_breadcrumb(parent_entry_name, parent[:controller].to_url_for(:show, parent_ids.merge(id: parent[:entry].id)))
|
|
195
|
+
parent_ids[parent[:id_param]] = parent[:id_value]
|
|
196
|
+
end if local_data[:parents]
|
|
197
|
+
# breadcrumbs: adding current index
|
|
198
|
+
add_new_breadcrumb(I18n.t("#{self.to_i18n}.index.title"), self.to_url_for(:index, local_data[:parent_ids]))
|
|
199
|
+
# breadcrumbs: getting current entry name
|
|
200
|
+
current_entry_name = nil
|
|
201
|
+
if local_data[:entry].respond_to?(:name_for_breadcrumbs)
|
|
202
|
+
current_entry_name = local_data[:entry].name_for_breadcrumbs
|
|
203
|
+
#current_entry_name.trim(20) if current_entry_name
|
|
102
204
|
end
|
|
205
|
+
current_entry_name = local_data[:entry].id unless current_entry_name
|
|
206
|
+
# breadcrumbs: adding current entry
|
|
207
|
+
add_new_breadcrumb(current_entry_name)
|
|
208
|
+
# rendering page
|
|
103
209
|
respond_to do |format|
|
|
104
|
-
format.html { render_html1 self.
|
|
105
|
-
format.json {
|
|
210
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :show)}", locals: {data: local_data} }
|
|
211
|
+
format.json { render_json_ok local_data[:entry] }
|
|
106
212
|
end
|
|
107
213
|
end
|
|
108
214
|
|
|
@@ -114,29 +220,58 @@ module KirguduBase
|
|
|
114
220
|
unless self.class.respond_to?(:get_kb_page)
|
|
115
221
|
raise "Method :get_kb_page must be implemented for controller '#{self.class}'"
|
|
116
222
|
end
|
|
117
|
-
|
|
118
|
-
|
|
223
|
+
|
|
224
|
+
local_data = {
|
|
225
|
+
messages: [],
|
|
226
|
+
errors: [],
|
|
227
|
+
page: self.class.get_kb_page(:new)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
unless local_data[:page]
|
|
119
231
|
respond_to do |format|
|
|
120
|
-
format.html { render_html1 self.
|
|
232
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
121
233
|
format.json { render_json_page_404 }
|
|
122
234
|
end
|
|
123
235
|
return
|
|
124
236
|
end
|
|
125
|
-
local_entry = entry_class.new
|
|
126
237
|
|
|
127
|
-
|
|
128
|
-
|
|
238
|
+
filters = {}
|
|
239
|
+
self.fill_obligatory_filters(filters)
|
|
129
240
|
|
|
241
|
+
# getting entry
|
|
242
|
+
local_data[:entry] = entry_class.new
|
|
243
|
+
# getting controls data
|
|
244
|
+
local_data[:controls_data] = self.load_data_for_entry_controls(local_data[:page].forms[:changes], local_data[:entry])
|
|
245
|
+
|
|
246
|
+
# fill parent for data
|
|
247
|
+
filters_for_parents = {}
|
|
248
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
249
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
250
|
+
|
|
251
|
+
# building breadcrumbs
|
|
252
|
+
home_controller = self.class.get_method_latest_result(:get_kb_home_controller)
|
|
253
|
+
home_controller = eval(home_controller) if home_controller and home_controller.is_a?(String)
|
|
254
|
+
add_new_breadcrumb(I18n.t("#{home_controller.to_i18n}.index.title"), home_controller.to_url_for(:index)) if home_controller
|
|
255
|
+
parent_ids = {}
|
|
256
|
+
local_data[:parents].each do |parent|
|
|
257
|
+
# breadcrumbs: adding parent index
|
|
258
|
+
add_new_breadcrumb(I18n.t("#{parent[:controller].to_i18n}.index.title"), parent[:controller].to_url_for(:index, parent_ids))
|
|
259
|
+
# breadcrumbs: getting parent entry name
|
|
260
|
+
parent_entry_name = nil
|
|
261
|
+
parent_entry_name = parent[:entry].name_for_breadcrumbs if parent[:entry].respond_to?(:name_for_breadcrumbs)
|
|
262
|
+
parent_entry_name = parent[:entry].id unless parent_entry_name
|
|
263
|
+
# breadcrumbs: adding parent entry
|
|
264
|
+
add_new_breadcrumb(parent_entry_name, parent[:controller].to_url_for(:show, parent_ids.merge(id: parent[:entry].id)))
|
|
265
|
+
parent_ids[parent[:id_param]] = parent[:id_value]
|
|
266
|
+
end if local_data[:parents]
|
|
267
|
+
# breadcrumbs: adding current index
|
|
268
|
+
add_new_breadcrumb(I18n.t("#{self.to_i18n}.index.title"), self.to_url_for(:index, local_data[:parent_ids]))
|
|
269
|
+
add_new_breadcrumb(I18n.t("#{self.to_i18n}.new.title"))
|
|
270
|
+
|
|
271
|
+
# rendering page
|
|
130
272
|
respond_to do |format|
|
|
131
|
-
format.html { render_html1 self.
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
entry: local_entry,
|
|
135
|
-
page: local_page,
|
|
136
|
-
controls_data: local_controls_data
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
format.json { render json: local_entry }
|
|
273
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :new)}", locals: {data: local_data} }
|
|
274
|
+
format.json { render_json_ok local_data[:entry] }
|
|
140
275
|
end
|
|
141
276
|
end
|
|
142
277
|
|
|
@@ -145,33 +280,48 @@ module KirguduBase
|
|
|
145
280
|
unless self.class.respond_to?(:get_kb_page)
|
|
146
281
|
raise "Method :get_kb_page must be implemented for controller '#{self.class}'"
|
|
147
282
|
end
|
|
148
|
-
|
|
149
|
-
|
|
283
|
+
|
|
284
|
+
local_data = {
|
|
285
|
+
messages: [],
|
|
286
|
+
errors: [],
|
|
287
|
+
page: self.class.get_kb_page(:new)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
unless local_data[:page]
|
|
150
291
|
respond_to do |format|
|
|
151
|
-
format.html { render_html1 self.
|
|
292
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
152
293
|
format.json { render_json_page_404 }
|
|
153
294
|
end
|
|
154
295
|
return
|
|
155
296
|
end
|
|
156
297
|
|
|
157
|
-
strong_params = {}.merge(self.class_strong_params(local_page.forms[:changes]))
|
|
158
|
-
self.fill_obligatory_filters(strong_params)
|
|
159
298
|
|
|
160
|
-
|
|
299
|
+
# fill parent for data
|
|
300
|
+
filters_for_parents = {}
|
|
301
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
302
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
161
303
|
|
|
162
|
-
self.process_transaction_injections(local_entry, :create, :before_transaction, strong_params)
|
|
163
304
|
|
|
305
|
+
strong_params = {}.merge(self.class_strong_params(local_data[:page].forms[:changes]))
|
|
306
|
+
self.fill_obligatory_filters(strong_params)
|
|
307
|
+
strong_params.merge!(local_data[:parent_ids])
|
|
308
|
+
|
|
309
|
+
# getting entry
|
|
310
|
+
local_data[:entry] = self.entry_class.new(strong_params)
|
|
311
|
+
|
|
312
|
+
# pre create
|
|
313
|
+
self.process_transaction_injections(local_data[:entry], :create, :before_transaction, strong_params)
|
|
164
314
|
transaction_is_ok = true
|
|
165
315
|
|
|
166
316
|
ActiveRecord::Base.transaction do
|
|
167
317
|
#raise "In Transaction Before Create"
|
|
168
|
-
unless self.process_transaction_injections(
|
|
318
|
+
unless self.process_transaction_injections(local_data[:entry], :create, :before_save, strong_params)
|
|
169
319
|
transaction_is_ok = false
|
|
170
320
|
raise ActiveRecord::Rollback
|
|
171
321
|
end
|
|
172
322
|
|
|
173
|
-
if
|
|
174
|
-
unless process_transaction_injections(
|
|
323
|
+
if local_data[:entry].save
|
|
324
|
+
unless process_transaction_injections(local_data[:entry], :create, :after_save, strong_params)
|
|
175
325
|
transaction_is_ok = false
|
|
176
326
|
raise ActiveRecord::Rollback
|
|
177
327
|
end
|
|
@@ -181,26 +331,42 @@ module KirguduBase
|
|
|
181
331
|
end
|
|
182
332
|
end
|
|
183
333
|
|
|
184
|
-
self.process_transaction_injections(
|
|
334
|
+
self.process_transaction_injections(local_data[:entry], :create, :after_transaction, strong_params)
|
|
185
335
|
|
|
186
336
|
respond_to do |format|
|
|
187
337
|
if transaction_is_ok
|
|
188
|
-
|
|
189
|
-
format.html { render_redirect
|
|
190
|
-
format.json {
|
|
338
|
+
local_data[:messages] << I18n.t("#{self.to_i18n}.messages.entry_created", entry_name: local_data[:entry].to_s)
|
|
339
|
+
format.html { render_redirect self.to_url_for(:show, local_data[:parent_ids].merge(id: local_data[:entry].id)) }
|
|
340
|
+
format.json { render_json_ok local_data[:entry], message: local_data[:messages] }
|
|
191
341
|
else
|
|
192
342
|
# loading data for select-like controls
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
343
|
+
local_data[:controls_data] = self.load_data_for_entry_controls(local_data[:page].forms[:changes], local_data[:entry])
|
|
344
|
+
local_data[:errors] << I18n.t("#{self.to_i18n}.messages.create_error")
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
# building breadcrumbs
|
|
348
|
+
home_controller = self.class.get_method_latest_result(:get_kb_home_controller)
|
|
349
|
+
home_controller = eval(home_controller) if home_controller and home_controller.is_a?(String)
|
|
350
|
+
add_new_breadcrumb(I18n.t("#{home_controller.to_i18n}.index.title"), home_controller.to_url_for(:index)) if home_controller
|
|
351
|
+
parent_ids = {}
|
|
352
|
+
local_data[:parents].each do |parent|
|
|
353
|
+
# breadcrumbs: adding parent index
|
|
354
|
+
add_new_breadcrumb(I18n.t("#{parent[:controller].to_i18n}.index.title"), parent[:controller].to_url_for(:index, parent_ids))
|
|
355
|
+
# breadcrumbs: getting parent entry name
|
|
356
|
+
parent_entry_name = nil
|
|
357
|
+
parent_entry_name = parent[:entry].name_for_breadcrumbs if parent[:entry].respond_to?(:name_for_breadcrumbs)
|
|
358
|
+
parent_entry_name = parent[:entry].id unless parent_entry_name
|
|
359
|
+
# breadcrumbs: adding parent entry
|
|
360
|
+
add_new_breadcrumb(parent_entry_name, parent[:controller].to_url_for(:show, parent_ids.merge(id: parent[:entry].id)))
|
|
361
|
+
parent_ids[parent[:id_param]] = parent[:id_value]
|
|
362
|
+
end if local_data[:parents]
|
|
363
|
+
# breadcrumbs: adding current index
|
|
364
|
+
add_new_breadcrumb(I18n.t("#{self.to_i18n}.index.title"), self.to_url_for(:index, local_data[:parent_ids]))
|
|
365
|
+
add_new_breadcrumb(I18n.t("#{self.to_i18n}.new.title"))
|
|
366
|
+
|
|
367
|
+
# rendering page
|
|
368
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :new)}", locals: {data: local_data} }
|
|
369
|
+
format.json { render_json_error local_data[:entry], message: local_data[:errors] }
|
|
204
370
|
end
|
|
205
371
|
end
|
|
206
372
|
end
|
|
@@ -215,42 +381,71 @@ module KirguduBase
|
|
|
215
381
|
raise "Method :get_kb_page must be implemented for controller '#{self.class}'"
|
|
216
382
|
end
|
|
217
383
|
|
|
218
|
-
|
|
384
|
+
local_data = {
|
|
385
|
+
errors: [],
|
|
386
|
+
messages: [],
|
|
387
|
+
page: self.class.get_kb_page(:edit)
|
|
388
|
+
}
|
|
219
389
|
|
|
220
|
-
unless
|
|
390
|
+
unless local_data[:page]
|
|
221
391
|
respond_to do |format|
|
|
222
|
-
format.html { render_html1
|
|
392
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
223
393
|
format.json { render_json_page_404 }
|
|
224
394
|
end
|
|
225
395
|
return
|
|
226
396
|
end
|
|
227
397
|
|
|
398
|
+
# fill parent for data
|
|
399
|
+
filters_for_parents = {}
|
|
400
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
401
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
402
|
+
# filling filters for search
|
|
228
403
|
filters = {}
|
|
229
404
|
self.fill_obligatory_filters(filters)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
405
|
+
filters.merge!(local_data[:parent_ids])
|
|
406
|
+
# retrieving entry from database
|
|
407
|
+
local_data[:entry] = self.entry_class.get_entry_by_id(params[:id], filters, {logger: string_logger})
|
|
408
|
+
# entry not found, showing not found page
|
|
409
|
+
unless local_data[:entry]
|
|
410
|
+
local_data[:errors] << I18n.t("#{self.to_i18n}.messages.not_found", entry_id: params[:id])
|
|
234
411
|
respond_to do |format|
|
|
235
|
-
|
|
236
|
-
format.
|
|
237
|
-
format.json { render json: local_entry.errors, status: :unprocessable_entity }
|
|
412
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :entry_not_found)}", locals: {data: local_data} }
|
|
413
|
+
format.json { render_json_not_found message: local_data[:errors] }
|
|
238
414
|
end
|
|
239
415
|
return
|
|
240
416
|
end
|
|
241
|
-
# loading data for
|
|
242
|
-
|
|
243
|
-
|
|
417
|
+
# loading data for controls
|
|
418
|
+
local_data[:controls_data] = self.load_data_for_entry_controls(local_data[:page].forms[:changes], local_data[:entry])
|
|
419
|
+
|
|
420
|
+
# fill parent for data
|
|
421
|
+
filters_for_parents = {}
|
|
422
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
423
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
424
|
+
# building breadcrumbs
|
|
425
|
+
home_controller = self.class.get_method_latest_result(:get_kb_home_controller)
|
|
426
|
+
home_controller = eval(home_controller) if home_controller and home_controller.is_a?(String)
|
|
427
|
+
add_new_breadcrumb(I18n.t("#{home_controller.to_i18n}.index.title"), home_controller.to_url_for(:index)) if home_controller
|
|
428
|
+
parent_ids = {}
|
|
429
|
+
local_data[:parents].each do |parent|
|
|
430
|
+
# breadcrumbs: adding parent index
|
|
431
|
+
add_new_breadcrumb(I18n.t("#{parent[:controller].to_i18n}.index.title"), parent[:controller].to_url_for(:index, parent_ids))
|
|
432
|
+
# breadcrumbs: getting parent entry name
|
|
433
|
+
parent_entry_name = nil
|
|
434
|
+
parent_entry_name = parent[:entry].name_for_breadcrumbs if parent[:entry].respond_to?(:name_for_breadcrumbs)
|
|
435
|
+
parent_entry_name = parent[:entry].id unless parent_entry_name
|
|
436
|
+
# breadcrumbs: adding parent entry
|
|
437
|
+
add_new_breadcrumb(parent_entry_name, parent[:controller].to_url_for(:show, parent_ids.merge(id: parent[:entry].id)))
|
|
438
|
+
parent_ids[parent[:id_param]] = parent[:id_value]
|
|
439
|
+
end if local_data[:parents]
|
|
440
|
+
# breadcrumbs: adding current index
|
|
441
|
+
add_new_breadcrumb(I18n.t("#{self.to_i18n}.index.title"), self.to_url_for(:index, local_data[:parent_ids]))
|
|
442
|
+
# breadcrumbs: adding current entry
|
|
443
|
+
add_new_breadcrumb(local_data[:entry].id)
|
|
444
|
+
|
|
445
|
+
# rendering page
|
|
244
446
|
respond_to do |format|
|
|
245
|
-
format.html { render_html1 self.
|
|
246
|
-
|
|
247
|
-
{
|
|
248
|
-
entry: local_entry,
|
|
249
|
-
page: local_page,
|
|
250
|
-
controls_data: local_controls_data
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
format.json { render json: local_entry }
|
|
447
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :edit)}", locals: {data: local_data} }
|
|
448
|
+
format.json { render_json_ok local_data[:entry] }
|
|
254
449
|
end
|
|
255
450
|
end
|
|
256
451
|
|
|
@@ -261,45 +456,55 @@ module KirguduBase
|
|
|
261
456
|
raise "Method :get_kb_page must be implemented for controller '#{self.class}'"
|
|
262
457
|
end
|
|
263
458
|
|
|
264
|
-
|
|
459
|
+
local_data = {
|
|
460
|
+
errors: [],
|
|
461
|
+
messages: [],
|
|
462
|
+
page: self.class.get_kb_page(:edit)
|
|
463
|
+
}
|
|
265
464
|
|
|
266
|
-
unless
|
|
465
|
+
unless local_data[:page]
|
|
267
466
|
respond_to do |format|
|
|
268
|
-
format.html { render_html1 self.
|
|
467
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
269
468
|
format.json { render_json_page_404 }
|
|
270
469
|
end
|
|
271
470
|
return
|
|
272
471
|
end
|
|
273
472
|
|
|
274
473
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
474
|
+
# fill parent for data
|
|
475
|
+
filters_for_parents = {}
|
|
476
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
477
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
478
|
+
# filling filters for search
|
|
479
|
+
filters = {}
|
|
480
|
+
self.fill_obligatory_filters(filters)
|
|
481
|
+
filters.merge!(local_data[:parent_ids]) # merging search filters with parent ids
|
|
482
|
+
# retrieving data from database
|
|
483
|
+
local_data[:entry] = self.entry_class.get_entry_by_id(params[:id], filters, {logger: string_logger})
|
|
484
|
+
# entry not found, showing not found page
|
|
485
|
+
unless local_data[:entry]
|
|
486
|
+
local_data[:errors] << I18n.t("#{self.to_i18n}.messages.not_found", entry_id: params[:id])
|
|
279
487
|
respond_to do |format|
|
|
280
|
-
|
|
281
|
-
format.
|
|
282
|
-
format.json { render json: nil, status: :unprocessable_entity }
|
|
488
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :entry_not_found)}", locals: {data: local_data} }
|
|
489
|
+
format.json { render_json_not_found message: local_data[:errors] }
|
|
283
490
|
end
|
|
284
491
|
return
|
|
285
492
|
end
|
|
286
|
-
|
|
287
|
-
strong_params = {}.merge(self.class_strong_params(
|
|
493
|
+
# getting string params from params
|
|
494
|
+
strong_params = {}.merge(self.class_strong_params(local_data[:page].forms[:changes]))
|
|
288
495
|
self.fill_obligatory_filters(strong_params)
|
|
289
496
|
|
|
290
|
-
self.process_transaction_injections(
|
|
291
|
-
|
|
497
|
+
self.process_transaction_injections(local_data[:entry], :update, :before_transaction, strong_params)
|
|
292
498
|
transaction_is_ok = true
|
|
293
|
-
|
|
294
499
|
ActiveRecord::Base.transaction do
|
|
295
500
|
#raise "In Transaction Before Create"
|
|
296
|
-
unless self.process_transaction_injections(
|
|
501
|
+
unless self.process_transaction_injections(local_data[:entry], :update, :before_save, strong_params)
|
|
297
502
|
transaction_is_ok = false
|
|
298
503
|
raise ActiveRecord::Rollback
|
|
299
504
|
end
|
|
300
505
|
|
|
301
|
-
if
|
|
302
|
-
unless process_transaction_injections(
|
|
506
|
+
if local_data[:entry].update(strong_params)
|
|
507
|
+
unless process_transaction_injections(local_data[:entry], :update, :after_save, strong_params)
|
|
303
508
|
transaction_is_ok = false
|
|
304
509
|
raise ActiveRecord::Rollback
|
|
305
510
|
end
|
|
@@ -308,36 +513,104 @@ module KirguduBase
|
|
|
308
513
|
raise ActiveRecord::Rollback
|
|
309
514
|
end
|
|
310
515
|
end
|
|
311
|
-
|
|
312
|
-
self.process_transaction_injections(local_entry, :update, :after_transaction, strong_params)
|
|
516
|
+
self.process_transaction_injections(local_data[:entry], :update, :after_transaction, strong_params)
|
|
313
517
|
|
|
314
518
|
|
|
315
519
|
respond_to do |format|
|
|
316
|
-
flash[:success] = I18n.t("#{self.to_i18n}.messages.manufacturer_updated", entry_name:
|
|
520
|
+
flash[:success] = I18n.t("#{self.to_i18n}.messages.manufacturer_updated", entry_name: local_data[:entry].to_s)
|
|
317
521
|
if transaction_is_ok
|
|
318
|
-
format.html { render_redirect url_for(action: :show, id:
|
|
522
|
+
format.html { render_redirect url_for(action: :show, id: local_data[:entry]) }
|
|
319
523
|
format.json { head :no_content }
|
|
320
524
|
else
|
|
321
525
|
# loading data for select-like controls
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
526
|
+
local_data[:controls_data] = self.load_data_for_entry_controls(local_data[:page].forms[:changes], local_data[:entry])
|
|
527
|
+
local_data[:entry].errors[:form] << I18n.t("#{self.to_i18n}.messages.update_error")
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
# building breadcrumbs
|
|
531
|
+
home_controller = self.class.get_method_latest_result(:get_kb_home_controller)
|
|
532
|
+
home_controller = eval(home_controller) if home_controller and home_controller.is_a?(String)
|
|
533
|
+
add_new_breadcrumb(I18n.t("#{home_controller.to_i18n}.index.title"), home_controller.to_url_for(:index)) if home_controller
|
|
534
|
+
parent_ids = {}
|
|
535
|
+
local_data[:parents].each do |parent|
|
|
536
|
+
# breadcrumbs: adding parent index
|
|
537
|
+
add_new_breadcrumb(I18n.t("#{parent[:controller].to_i18n}.index.title"), parent[:controller].to_url_for(:index, parent_ids))
|
|
538
|
+
# breadcrumbs: getting parent entry name
|
|
539
|
+
parent_entry_name = nil
|
|
540
|
+
parent_entry_name = parent[:entry].name_for_breadcrumbs if parent[:entry].respond_to?(:name_for_breadcrumbs)
|
|
541
|
+
parent_entry_name = parent[:entry].id unless parent_entry_name
|
|
542
|
+
# breadcrumbs: adding parent entry
|
|
543
|
+
add_new_breadcrumb(parent_entry_name, parent[:controller].to_url_for(:show, parent_ids.merge(id: parent[:entry].id)))
|
|
544
|
+
parent_ids[parent[:id_param]] = parent[:id_value]
|
|
545
|
+
end if local_data[:parents]
|
|
546
|
+
# breadcrumbs: adding current index
|
|
547
|
+
add_new_breadcrumb(I18n.t("#{self.to_i18n}.index.title"), self.to_url_for(:index, local_data[:parent_ids]))
|
|
548
|
+
# breadcrumbs: adding current entry
|
|
549
|
+
add_new_breadcrumb(local_data[:entry].id)
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :edit)}", locals: {data: local_data} }
|
|
553
|
+
format.json { render json: local_data[:entry].errors, status: :unprocessable_entity }
|
|
333
554
|
end
|
|
334
555
|
end
|
|
335
556
|
end
|
|
336
557
|
end
|
|
337
558
|
|
|
338
559
|
module DeleteActions
|
|
339
|
-
def
|
|
560
|
+
def destroy
|
|
561
|
+
unless self.class.respond_to?(:get_kb_page)
|
|
562
|
+
raise "Method :get_kb_page must be implemented for controller '#{self.class}'"
|
|
563
|
+
end
|
|
564
|
+
|
|
565
|
+
local_data = {
|
|
566
|
+
errors: [],
|
|
567
|
+
messages: [],
|
|
568
|
+
page: self.class.get_kb_page(:delete)
|
|
569
|
+
}
|
|
340
570
|
|
|
571
|
+
#unless local_data[:page]
|
|
572
|
+
# respond_to do |format|
|
|
573
|
+
# format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
574
|
+
# format.json { render_json_page_404 }
|
|
575
|
+
# end
|
|
576
|
+
# return
|
|
577
|
+
#end
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
# fill parent for data
|
|
581
|
+
filters_for_parents = {}
|
|
582
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
583
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
584
|
+
# filling filters for search
|
|
585
|
+
filters = {}
|
|
586
|
+
self.fill_obligatory_filters(filters)
|
|
587
|
+
filters.merge!(local_data[:parent_ids])
|
|
588
|
+
# retrieving entry from database
|
|
589
|
+
local_data[:entry] = self.entry_class.get_entry_by_id(params[:id], filters, {logger: string_logger})
|
|
590
|
+
# entry not found, showing not found page
|
|
591
|
+
unless local_data[:entry]
|
|
592
|
+
local_data[:errors] << I18n.t("#{self.to_i18n}.messages.not_found", entry_id: params[:id])
|
|
593
|
+
respond_to do |format|
|
|
594
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :entry_not_found)}", locals: {data: local_data} }
|
|
595
|
+
format.json { render_json_not_found message: local_data[:errors] }
|
|
596
|
+
end
|
|
597
|
+
return
|
|
598
|
+
end
|
|
599
|
+
# destroying entry
|
|
600
|
+
if local_data[:entry].destroy
|
|
601
|
+
# entry destroyed
|
|
602
|
+
respond_to do |format|
|
|
603
|
+
format.html { render_redirect(self.to_url_for(:index, local_data[:parent_ids])) }
|
|
604
|
+
format.json { render_json_ok(local_data[:entry], message: "Record Deleted") }
|
|
605
|
+
end
|
|
606
|
+
else
|
|
607
|
+
# failed to destroy entry
|
|
608
|
+
local_data[:errors] << I18n.t("#{self.to_i18n}.messages.delete_error")
|
|
609
|
+
respond_to do |format|
|
|
610
|
+
format.html { render_html1 self.get_view_path_for_page_edit, locals: {data: local_data} }
|
|
611
|
+
format.json { render_json_error(local_data[:entry], message: local_data[:errors]) }
|
|
612
|
+
end
|
|
613
|
+
end
|
|
341
614
|
end
|
|
342
615
|
end
|
|
343
616
|
|
|
@@ -347,14 +620,25 @@ module KirguduBase
|
|
|
347
620
|
raise "No defined \"entry_class\" method for controller #{self.class}" if !self.respond_to?(:entry_class) || self.entry_class.nil?
|
|
348
621
|
raise "Current User NULL" if @current_user.nil?
|
|
349
622
|
|
|
350
|
-
filters = {}.merge(params)
|
|
351
623
|
options = {
|
|
352
624
|
logger: string_logger
|
|
353
625
|
}
|
|
354
626
|
|
|
355
|
-
|
|
627
|
+
local_data = {
|
|
628
|
+
errors: [],
|
|
629
|
+
messages: []
|
|
630
|
+
}
|
|
356
631
|
|
|
357
|
-
|
|
632
|
+
# fill parent for data
|
|
633
|
+
filters_for_parents = {}
|
|
634
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
635
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
636
|
+
# filling filters for search
|
|
637
|
+
filters = {}
|
|
638
|
+
self.fill_obligatory_filters(filters)
|
|
639
|
+
filters.merge!(local_data[:parent_ids])
|
|
640
|
+
# retrieving entries from database
|
|
641
|
+
local_data[:entries] = self.entry_class.get_entries(nil, filters, options)
|
|
358
642
|
|
|
359
643
|
export_type = params[:type]
|
|
360
644
|
|
|
@@ -376,12 +660,12 @@ module KirguduBase
|
|
|
376
660
|
when "json"
|
|
377
661
|
|
|
378
662
|
when "xml"
|
|
379
|
-
render text:
|
|
663
|
+
render text: local_data[:entries_list].to_xml
|
|
380
664
|
end
|
|
381
665
|
else
|
|
382
666
|
respond_to do |format|
|
|
383
|
-
format.json { render json:
|
|
384
|
-
format.json { render xml:
|
|
667
|
+
format.json { render json: local_data[:entries] }
|
|
668
|
+
format.json { render xml: local_data[:entries] }
|
|
385
669
|
end
|
|
386
670
|
end
|
|
387
671
|
end
|
|
@@ -395,8 +679,528 @@ module KirguduBase
|
|
|
395
679
|
end
|
|
396
680
|
end
|
|
397
681
|
|
|
682
|
+
|
|
683
|
+
module ItemsManagementActions
|
|
684
|
+
|
|
685
|
+
def manage_items
|
|
686
|
+
|
|
687
|
+
unless self.class.respond_to?(:get_kb_page)
|
|
688
|
+
raise "Method :get_kb_page must be implemented for controller '#{self.class}'"
|
|
689
|
+
end
|
|
690
|
+
|
|
691
|
+
local_data = {
|
|
692
|
+
errors: [],
|
|
693
|
+
messages: [],
|
|
694
|
+
page: self.class.get_kb_page(:management)
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
options = {
|
|
698
|
+
logger: string_logger
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
unless local_data[:page]
|
|
702
|
+
respond_to do |format|
|
|
703
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
704
|
+
format.json { render_json_page_404 }
|
|
705
|
+
end
|
|
706
|
+
return
|
|
707
|
+
end
|
|
708
|
+
|
|
709
|
+
# getting management settings
|
|
710
|
+
local_data[:management_settings] = local_data[:page].managements[:manage] if local_data[:page].managements
|
|
711
|
+
|
|
712
|
+
unless local_data[:management_settings]
|
|
713
|
+
respond_to do |format|
|
|
714
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
715
|
+
format.json { render_json_page_404 }
|
|
716
|
+
end
|
|
717
|
+
return
|
|
718
|
+
end
|
|
719
|
+
|
|
720
|
+
#raise "MANAGEMENT: management settings error" unless local_data[:management_settings]
|
|
721
|
+
|
|
722
|
+
local_container_class = local_data[:management_settings].container_class
|
|
723
|
+
local_container_id_property = local_data[:management_settings].container_id_property
|
|
724
|
+
local_item_class = local_data[:management_settings].item_class
|
|
725
|
+
local_entry_id_property = local_data[:management_settings].entry_id_property
|
|
726
|
+
local_entry_class = local_data[:management_settings].entry_class
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
# fill parent for data
|
|
730
|
+
filters_for_parents = {}
|
|
731
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
732
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
#loading container data
|
|
736
|
+
filters_4_container = {}
|
|
737
|
+
self.fill_obligatory_filters(filters_4_container)
|
|
738
|
+
filters_4_container.merge!(local_data[:parent_ids])
|
|
739
|
+
# retrieving container from database
|
|
740
|
+
local_data[:container] = local_container_class.get_entry_by_id(params[local_container_id_property], filters_4_container, options)
|
|
741
|
+
# filling filters for items
|
|
742
|
+
filters_4_items = {}
|
|
743
|
+
self.fill_obligatory_filters(filters_4_items)
|
|
744
|
+
filters_4_items.merge!(local_data[:parent_ids])
|
|
745
|
+
filters_4_items[local_container_id_property] = params[local_container_id_property]
|
|
746
|
+
# retrieving items from database
|
|
747
|
+
local_data[:items] = local_item_class.get_entries(nil, filters_4_items, options)
|
|
748
|
+
|
|
749
|
+
#entries_order_by = get_managing_entries_order_by if self.respond_to?(:get_managing_entries_order_by)
|
|
750
|
+
#entries_order_by = "name asc" unless entries_order_by
|
|
751
|
+
|
|
752
|
+
# filling filters for entries
|
|
753
|
+
filters_4_entries = {}
|
|
754
|
+
self.fill_obligatory_filters(filters_4_entries)
|
|
755
|
+
filters_4_entries[local_entry_id_property] = params[local_entry_id_property]
|
|
756
|
+
# retrieving entries from database
|
|
757
|
+
local_entries_initial_query = local_entry_class.where { -(id.in local_item_class.get_entries(nil, filters_4_items, options).select(local_entry_id_property)) }
|
|
758
|
+
|
|
759
|
+
#fill parent elements
|
|
760
|
+
filters_for_parents = {}
|
|
761
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
762
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
763
|
+
|
|
764
|
+
local_entries = local_entry_class.get_entries(local_entries_initial_query, filters_4_entries, options)
|
|
765
|
+
local_data[:entries] = local_entries
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
# building breadcrumbs
|
|
769
|
+
home_controller = self.class.get_method_latest_result(:get_kb_home_controller)
|
|
770
|
+
home_controller = eval(home_controller) if home_controller and home_controller.is_a?(String)
|
|
771
|
+
add_new_breadcrumb(I18n.t("#{home_controller.to_i18n}.index.title"), home_controller.to_url_for(:index)) if home_controller
|
|
772
|
+
parent_ids = {}
|
|
773
|
+
local_data[:parents].each do |parent|
|
|
774
|
+
# breadcrumbs: adding parent index
|
|
775
|
+
add_new_breadcrumb(I18n.t("#{parent[:controller].to_i18n}.index.title"), parent[:controller].to_url_for(:index, parent_ids))
|
|
776
|
+
# breadcrumbs: getting parent entry name
|
|
777
|
+
parent_entry_name = nil
|
|
778
|
+
parent_entry_name = parent[:entry].name_for_breadcrumbs if parent[:entry].respond_to?(:name_for_breadcrumbs)
|
|
779
|
+
parent_entry_name = parent[:entry].id unless parent_entry_name
|
|
780
|
+
# breadcrumbs: adding parent entry
|
|
781
|
+
add_new_breadcrumb(parent_entry_name, parent[:controller].to_url_for(:show, parent_ids.merge(id: parent[:entry].id)))
|
|
782
|
+
parent_ids[parent[:id_param]] = parent[:id_value]
|
|
783
|
+
end if local_data[:parents]
|
|
784
|
+
# breadcrumbs: adding current index
|
|
785
|
+
add_new_breadcrumb(I18n.t("#{self.to_i18n}.index.title"), self.to_url_for(:index, local_data[:parent_ids]))
|
|
786
|
+
add_new_breadcrumb(I18n.t("#{self.to_i18n}.management.title"))
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
respond_to do |format|
|
|
790
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :management)}", locals: {data: local_data} }
|
|
791
|
+
format.json { render json: local_data }
|
|
792
|
+
end
|
|
793
|
+
end
|
|
794
|
+
|
|
795
|
+
def manage_items_add
|
|
796
|
+
|
|
797
|
+
unless self.class.respond_to?(:get_kb_page)
|
|
798
|
+
raise "Method :get_kb_page must be implemented for controller '#{self.class}'"
|
|
799
|
+
end
|
|
800
|
+
|
|
801
|
+
local_data = {
|
|
802
|
+
errors: [],
|
|
803
|
+
messages: [],
|
|
804
|
+
page: self.class.get_kb_page(:management)
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
options = {
|
|
808
|
+
logger: string_logger
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
unless local_data[:page]
|
|
812
|
+
respond_to do |format|
|
|
813
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
814
|
+
format.json { render_json_page_404 }
|
|
815
|
+
end
|
|
816
|
+
return
|
|
817
|
+
end
|
|
818
|
+
|
|
819
|
+
# getting management settings
|
|
820
|
+
local_data[:management_settings] = local_data[:page].managements[:manage] if local_data[:page].managements
|
|
821
|
+
|
|
822
|
+
unless local_data[:management_settings]
|
|
823
|
+
respond_to do |format|
|
|
824
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
825
|
+
format.json { render_json_page_404 }
|
|
826
|
+
end
|
|
827
|
+
return
|
|
828
|
+
end
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
local_container_class = local_data[:management_settings].container_class
|
|
832
|
+
local_container_id_property = local_data[:management_settings].container_id_property
|
|
833
|
+
local_item_class = local_data[:management_settings].item_class
|
|
834
|
+
local_entry_id_property = local_data[:management_settings].entry_id_property
|
|
835
|
+
local_entry_class = local_data[:management_settings].entry_class
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
# fill parent for data
|
|
839
|
+
filters_for_parents = {}
|
|
840
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
841
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
#loading container from database
|
|
845
|
+
filters_4_container = {}
|
|
846
|
+
self.fill_obligatory_filters(filters_4_container)
|
|
847
|
+
local_data[:container] = local_container_class.get_entry_by_id(params[local_container_id_property], filters_4_container, options)
|
|
848
|
+
#checking if container not found
|
|
849
|
+
unless local_data[:container]
|
|
850
|
+
render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('set_not_found'), message: I18n.t("#{self.to_i18n}.management.messages.set_not_found", id: params[local_container_id_property])}
|
|
851
|
+
return
|
|
852
|
+
end
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
#loading entry from database
|
|
856
|
+
filters_4_entries = {}
|
|
857
|
+
self.fill_obligatory_filters(filters_4_entries)
|
|
858
|
+
#local_data[:entry] = local_entry_class.get_entry_by_id(params[local_entry_id_property], filters_4_entries, options )
|
|
859
|
+
local_data[:entry] = local_entry_class.get_entry_by_id(params[:entry_id], filters_4_entries, options)
|
|
860
|
+
|
|
861
|
+
#checking if entry not found
|
|
862
|
+
unless local_data[:entry]
|
|
863
|
+
render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('entry_not_found'), message: I18n.t("#{self.to_i18n}.management.messages.entry_not_found", entry_id: params[:entry_id])}
|
|
864
|
+
return
|
|
865
|
+
end
|
|
866
|
+
|
|
867
|
+
#raise "MANAGEMENT: entry is ok"
|
|
868
|
+
|
|
869
|
+
# loading item from database
|
|
870
|
+
filters_4_item = {}
|
|
871
|
+
self.fill_obligatory_filters(filters_4_item)
|
|
872
|
+
filters_4_item[local_container_id_property] = params[local_container_id_property]
|
|
873
|
+
#filters_4_item[local_entry_id_property] = params[local_entry_id_property]
|
|
874
|
+
filters_4_item[local_entry_id_property] = params[:entry_id]
|
|
875
|
+
|
|
876
|
+
logger.info("MANAGEMENT ADD: Retrieve Item from database filters - #{filters_4_item.to_json}")
|
|
877
|
+
|
|
878
|
+
local_data[:item] = local_item_class.get_entries(nil, filters_4_item, options).first
|
|
879
|
+
|
|
880
|
+
unless local_data[:item]
|
|
881
|
+
local_data[:item] = local_item_class.new
|
|
882
|
+
local_data[:item][local_container_id_property] = local_data[:container].id
|
|
883
|
+
local_data[:item][local_entry_id_property] = local_data[:entry].id
|
|
884
|
+
|
|
885
|
+
if local_data[:item].respond_to?(:sort_position)
|
|
886
|
+
filters_4_items_max = {}
|
|
887
|
+
self.fill_obligatory_filters(filters_4_items_max)
|
|
888
|
+
filters_4_items_max[local_container_id_property] = params[local_container_id_property]
|
|
889
|
+
|
|
890
|
+
max_sort_position = local_item_class.get_entries(nil, filters_4_items_max, options).maximum(:sort_position)
|
|
891
|
+
local_data[:item].sort_position = max_sort_position ? max_sort_position + 1 : 1
|
|
892
|
+
end
|
|
893
|
+
|
|
894
|
+
# saving entry using transactions
|
|
895
|
+
self.process_transaction_injections(local_data[:item], :create, :before_transaction, nil)
|
|
896
|
+
transaction_is_ok = true
|
|
897
|
+
ActiveRecord::Base.transaction do
|
|
898
|
+
#raise "In Transaction Before Create"
|
|
899
|
+
unless self.process_transaction_injections(local_data[:item], :create, :before_save, nil)
|
|
900
|
+
transaction_is_ok = false
|
|
901
|
+
raise ActiveRecord::Rollback
|
|
902
|
+
end
|
|
903
|
+
|
|
904
|
+
if local_data[:item].save
|
|
905
|
+
unless self.process_transaction_injections(local_data[:item], :create, :after_save, nil)
|
|
906
|
+
transaction_is_ok = false
|
|
907
|
+
raise ActiveRecord::Rollback
|
|
908
|
+
end
|
|
909
|
+
else
|
|
910
|
+
transaction_is_ok = false
|
|
911
|
+
raise ActiveRecord::Rollback
|
|
912
|
+
end
|
|
913
|
+
end
|
|
914
|
+
self.process_transaction_injections(local_data[:item], :create, :after_transaction, nil)
|
|
915
|
+
|
|
916
|
+
# rendering page
|
|
917
|
+
if transaction_is_ok
|
|
918
|
+
render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('management_ok'), message: I18n.t("#{self.to_i18n}.management.messages.add_management_ok")}
|
|
919
|
+
else
|
|
920
|
+
render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('management_error'), message: I18n.t("#{self.to_i18n}.management.messages.add_management_error")}
|
|
921
|
+
end
|
|
922
|
+
else
|
|
923
|
+
render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('entry_already_in_set'), message: I18n.t("#{self.to_i18n}.management.messages.entry_already_in_set")}
|
|
924
|
+
end
|
|
925
|
+
end
|
|
926
|
+
|
|
927
|
+
def manage_items_remove
|
|
928
|
+
|
|
929
|
+
unless self.class.respond_to?(:get_kb_page)
|
|
930
|
+
raise "Method :get_kb_page must be implemented for controller '#{self.class}'"
|
|
931
|
+
end
|
|
932
|
+
|
|
933
|
+
local_data = {
|
|
934
|
+
errors: [],
|
|
935
|
+
messages: [],
|
|
936
|
+
page: self.class.get_kb_page(:management)
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
options = {
|
|
940
|
+
logger: string_logger
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
unless local_data[:page]
|
|
944
|
+
respond_to do |format|
|
|
945
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
946
|
+
format.json { render_json_page_404 }
|
|
947
|
+
end
|
|
948
|
+
return
|
|
949
|
+
end
|
|
950
|
+
|
|
951
|
+
# getting management settings
|
|
952
|
+
local_data[:management_settings] = local_data[:page].managements[:manage] if local_data[:page].managements
|
|
953
|
+
|
|
954
|
+
unless local_data[:management_settings]
|
|
955
|
+
respond_to do |format|
|
|
956
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
957
|
+
format.json { render_json_page_404 }
|
|
958
|
+
end
|
|
959
|
+
return
|
|
960
|
+
end
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
local_container_class = local_data[:management_settings].container_class
|
|
964
|
+
local_container_id_property = local_data[:management_settings].container_id_property
|
|
965
|
+
local_item_class = local_data[:management_settings].item_class
|
|
966
|
+
local_entry_id_property = local_data[:management_settings].entry_id_property
|
|
967
|
+
local_entry_class = local_data[:management_settings].entry_class
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
# fill parent for data
|
|
971
|
+
filters_for_parents = {}
|
|
972
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
973
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
974
|
+
|
|
975
|
+
#loading container from database
|
|
976
|
+
filters_4_container = {}
|
|
977
|
+
self.fill_obligatory_filters(filters_4_container)
|
|
978
|
+
local_data[:container] = local_container_class.get_entry_by_id(params[local_container_id_property], filters_4_container, options)
|
|
979
|
+
#checking if container not found
|
|
980
|
+
unless local_data[:container]
|
|
981
|
+
render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('set_not_found'), message: I18n.t("#{self.to_i18n}.management.messages.set_not_found", id: params[local_container_id_property])}
|
|
982
|
+
return
|
|
983
|
+
end
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
# loading item from database
|
|
987
|
+
filters_4_item = {}
|
|
988
|
+
self.fill_obligatory_filters(filters_4_item)
|
|
989
|
+
filters_4_item[local_container_id_property] = params[local_container_id_property]
|
|
990
|
+
filters_4_item[local_entry_id_property] = params[:entry_id]
|
|
991
|
+
|
|
992
|
+
local_data[:item] = local_item_class.get_entries(nil, filters_4_item, options).first
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
unless local_data[:item]
|
|
996
|
+
render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('item_not_found'), message: I18n.t("#{self.to_i18n}.management.messages.item_not_found", entry_id: params[:entry_id])}
|
|
997
|
+
return
|
|
998
|
+
end
|
|
999
|
+
|
|
1000
|
+
if local_data[:item].destroy
|
|
1001
|
+
render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('management_ok'), message: I18n.t("#{self.to_i18n}.management.messages.remove_management_ok")}
|
|
1002
|
+
else
|
|
1003
|
+
render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('management_error'), message: I18n.t("#{self.to_i18n}.management.messages.remove_management_error")}
|
|
1004
|
+
end
|
|
1005
|
+
end
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
def sort_items
|
|
1009
|
+
|
|
1010
|
+
unless self.class.respond_to?(:get_kb_page)
|
|
1011
|
+
raise "Method :get_kb_page must be implemented for controller '#{self.class}'"
|
|
1012
|
+
end
|
|
1013
|
+
|
|
1014
|
+
local_data = {
|
|
1015
|
+
errors: [],
|
|
1016
|
+
messages: [],
|
|
1017
|
+
page: self.class.get_kb_page(:sorting)
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
options = {
|
|
1021
|
+
logger: string_logger
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
unless local_data[:page]
|
|
1025
|
+
respond_to do |format|
|
|
1026
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
1027
|
+
format.json { render_json_page_404 }
|
|
1028
|
+
end
|
|
1029
|
+
return
|
|
1030
|
+
end
|
|
1031
|
+
|
|
1032
|
+
# getting sorting settings
|
|
1033
|
+
local_data[:sorting_settings] = local_data[:page].sortings[:sort] if local_data[:page].sortings
|
|
1034
|
+
|
|
1035
|
+
unless local_data[:sorting_settings]
|
|
1036
|
+
respond_to do |format|
|
|
1037
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
1038
|
+
format.json { render_json_page_404 }
|
|
1039
|
+
end
|
|
1040
|
+
return
|
|
1041
|
+
end
|
|
1042
|
+
|
|
1043
|
+
#raise "SORTING: sorting settings error" unless local_data[:sorting_settings]
|
|
1044
|
+
|
|
1045
|
+
local_container_class = local_data[:sorting_settings].container_class
|
|
1046
|
+
local_container_id_property = local_data[:sorting_settings].container_id_property
|
|
1047
|
+
local_item_class = local_data[:sorting_settings].item_class
|
|
1048
|
+
local_entry_id_property = local_data[:sorting_settings].entry_id_property
|
|
1049
|
+
local_entry_class = local_data[:sorting_settings].entry_class
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
# fill parent for data
|
|
1053
|
+
filters_for_parents = {}
|
|
1054
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
1055
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
#loading container data
|
|
1059
|
+
filters_4_container = {}
|
|
1060
|
+
self.fill_obligatory_filters(filters_4_container)
|
|
1061
|
+
filters_4_container.merge!(local_data[:parent_ids])
|
|
1062
|
+
# retrieving container from database
|
|
1063
|
+
local_data[:container] = local_container_class.get_entry_by_id(params[local_container_id_property], filters_4_container, options)
|
|
1064
|
+
# filling filters for items
|
|
1065
|
+
filters_4_items = {}
|
|
1066
|
+
self.fill_obligatory_filters(filters_4_items)
|
|
1067
|
+
filters_4_items.merge!(local_data[:parent_ids])
|
|
1068
|
+
filters_4_items[local_container_id_property] = params[local_container_id_property]
|
|
1069
|
+
filters_4_items[:order] = ::Core::Store::CollectionProduct.for_sql_order_by(:sort_position, :asc)
|
|
1070
|
+
# retrieving items from database
|
|
1071
|
+
local_data[:items] = local_item_class.get_entries(nil, filters_4_items, options)
|
|
1072
|
+
|
|
1073
|
+
|
|
1074
|
+
# building breadcrumbs
|
|
1075
|
+
home_controller = self.class.get_method_latest_result(:get_kb_home_controller)
|
|
1076
|
+
home_controller = eval(home_controller) if home_controller and home_controller.is_a?(String)
|
|
1077
|
+
add_new_breadcrumb(I18n.t("#{home_controller.to_i18n}.index.title"), home_controller.to_url_for(:index)) if home_controller
|
|
1078
|
+
parent_ids = {}
|
|
1079
|
+
local_data[:parents].each do |parent|
|
|
1080
|
+
# breadcrumbs: adding parent index
|
|
1081
|
+
add_new_breadcrumb(I18n.t("#{parent[:controller].to_i18n}.index.title"), parent[:controller].to_url_for(:index, parent_ids))
|
|
1082
|
+
# breadcrumbs: getting parent entry name
|
|
1083
|
+
parent_entry_name = nil
|
|
1084
|
+
parent_entry_name = parent[:entry].name_for_breadcrumbs if parent[:entry].respond_to?(:name_for_breadcrumbs)
|
|
1085
|
+
parent_entry_name = parent[:entry].id unless parent_entry_name
|
|
1086
|
+
# breadcrumbs: adding parent entry
|
|
1087
|
+
add_new_breadcrumb(parent_entry_name, parent[:controller].to_url_for(:show, parent_ids.merge(id: parent[:entry].id)))
|
|
1088
|
+
parent_ids[parent[:id_param]] = parent[:id_value]
|
|
1089
|
+
end if local_data[:parents]
|
|
1090
|
+
# breadcrumbs: adding current index
|
|
1091
|
+
add_new_breadcrumb(I18n.t("#{self.to_i18n}.index.title"), self.to_url_for(:index, local_data[:parent_ids]))
|
|
1092
|
+
add_new_breadcrumb(I18n.t("#{self.to_i18n}.sorting.title"))
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
respond_to do |format|
|
|
1096
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :sorting)}", locals: {data: local_data} }
|
|
1097
|
+
format.json { render_json_ok local_data }
|
|
1098
|
+
end
|
|
1099
|
+
|
|
1100
|
+
end
|
|
1101
|
+
|
|
1102
|
+
def sort_items_process
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
unless self.class.respond_to?(:get_kb_page)
|
|
1106
|
+
raise "Method :get_kb_page must be implemented for controller '#{self.class}'"
|
|
1107
|
+
end
|
|
1108
|
+
|
|
1109
|
+
local_data = {
|
|
1110
|
+
errors: [],
|
|
1111
|
+
messages: [],
|
|
1112
|
+
page: self.class.get_kb_page(:sorting)
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
options = {
|
|
1116
|
+
logger: string_logger
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
unless local_data[:page]
|
|
1120
|
+
respond_to do |format|
|
|
1121
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
1122
|
+
format.json { render_json_page_404 }
|
|
1123
|
+
end
|
|
1124
|
+
return
|
|
1125
|
+
end
|
|
1126
|
+
|
|
1127
|
+
# getting sorting settings
|
|
1128
|
+
local_data[:sorting_settings] = local_data[:page].sortings[:sort] if local_data[:page].sortings
|
|
1129
|
+
|
|
1130
|
+
unless local_data[:sorting_settings]
|
|
1131
|
+
respond_to do |format|
|
|
1132
|
+
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}#{self.class.get_method_latest_result(:get_kb_view_path, :page_404)}" }
|
|
1133
|
+
format.json { render_json_page_404 }
|
|
1134
|
+
end
|
|
1135
|
+
return
|
|
1136
|
+
end
|
|
1137
|
+
|
|
1138
|
+
#raise "SORTING: sorting settings error" unless local_data[:sorting_settings]
|
|
1139
|
+
|
|
1140
|
+
local_container_class = local_data[:sorting_settings].container_class
|
|
1141
|
+
local_container_id_property = local_data[:sorting_settings].container_id_property
|
|
1142
|
+
local_item_class = local_data[:sorting_settings].item_class
|
|
1143
|
+
local_entry_id_property = local_data[:sorting_settings].entry_id_property
|
|
1144
|
+
local_entry_class = local_data[:sorting_settings].entry_class
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
# fill parent for data
|
|
1148
|
+
filters_for_parents = {}
|
|
1149
|
+
self.fill_obligatory_filters(filters_for_parents)
|
|
1150
|
+
self.fill_parents_for_local_data(local_data, filters_for_parents)
|
|
1151
|
+
|
|
1152
|
+
#loading container from database
|
|
1153
|
+
filters_4_container = {}
|
|
1154
|
+
self.fill_obligatory_filters(filters_4_container)
|
|
1155
|
+
local_data[:container] = local_container_class.get_entry_by_id(params[local_container_id_property], filters_4_container, options)
|
|
1156
|
+
#checking if container not found
|
|
1157
|
+
unless local_data[:container]
|
|
1158
|
+
render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('set_not_found'), message: I18n.t("#{self.to_i18n}.management.messages.set_not_found", id: params[local_container_id_property])}
|
|
1159
|
+
return
|
|
1160
|
+
end
|
|
1161
|
+
|
|
1162
|
+
|
|
1163
|
+
# loading items from database one by one and processing them
|
|
1164
|
+
# filters_4_item = {}
|
|
1165
|
+
# self.fill_obligatory_filters(filters_4_item)
|
|
1166
|
+
# filters_4_item[local_container_id_property] = params[local_container_id_property]
|
|
1167
|
+
|
|
1168
|
+
|
|
1169
|
+
filters_4_item = {}
|
|
1170
|
+
self.fill_obligatory_filters(filters_4_item)
|
|
1171
|
+
filters_4_item[local_container_id_property] = params[local_container_id_property]
|
|
1172
|
+
#filters_4_item[local_entry_id_property] = id
|
|
1173
|
+
|
|
1174
|
+
|
|
1175
|
+
result_is_ok = false
|
|
1176
|
+
if params[:items]
|
|
1177
|
+
begin
|
|
1178
|
+
ActiveRecord::Base.transaction do
|
|
1179
|
+
params[:items].each_with_index do |id, index|
|
|
1180
|
+
logger.info("ITEMID: #{id}")
|
|
1181
|
+
|
|
1182
|
+
logger.info "ITEM FILTERS: #{filters_4_item.to_json}"
|
|
1183
|
+
item = local_item_class.get_entry_by_id(id, filters_4_item, options)
|
|
1184
|
+
if item
|
|
1185
|
+
item.sort_position = index + 1
|
|
1186
|
+
item.save
|
|
1187
|
+
end
|
|
1188
|
+
end
|
|
1189
|
+
result_is_ok = true
|
|
1190
|
+
end
|
|
1191
|
+
end
|
|
1192
|
+
end
|
|
1193
|
+
if result_is_ok == true
|
|
1194
|
+
render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('management_ok'), message: I18n.t("#{self.to_i18n}.sorting.messages.management_ok")}
|
|
1195
|
+
else
|
|
1196
|
+
render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('management_error'), message: I18n.t("#{self.to_i18n}.sorting.messages.management_error")}
|
|
1197
|
+
end
|
|
1198
|
+
end
|
|
1199
|
+
|
|
1200
|
+
end
|
|
398
1201
|
end
|
|
399
1202
|
|
|
1203
|
+
|
|
400
1204
|
################################################################################################################
|
|
401
1205
|
######################################### Ajax Modules ###############################################
|
|
402
1206
|
################################################################################################################
|
|
@@ -410,23 +1214,25 @@ module KirguduBase
|
|
|
410
1214
|
return
|
|
411
1215
|
end
|
|
412
1216
|
|
|
413
|
-
|
|
1217
|
+
local_data = {}
|
|
1218
|
+
local_data[:page] = self.class.get_kb_page(:update)
|
|
1219
|
+
|
|
414
1220
|
|
|
415
|
-
unless
|
|
1221
|
+
unless local_data[:page]
|
|
416
1222
|
render text: '<span style = "color: red;"><b>ERROR OCCURRED!!!</b></span>'
|
|
417
1223
|
return
|
|
418
1224
|
end
|
|
419
1225
|
|
|
420
1226
|
|
|
421
|
-
|
|
422
|
-
if
|
|
1227
|
+
local_data[:entry] = self.entry_class.get_entry_by_id(params[:id], nil, {logger: string_logger})
|
|
1228
|
+
if local_data[:entry]
|
|
423
1229
|
result_string = ''
|
|
424
1230
|
begin
|
|
425
|
-
unless
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
unless
|
|
1231
|
+
unless local_data[:entry][params[:field_name]] == params[:value]
|
|
1232
|
+
local_data[:entry][params[:field_name]] = params[:value]
|
|
1233
|
+
local_data[:entry].updated_at = Time.now
|
|
1234
|
+
local_data[:entry].updater = @current_user
|
|
1235
|
+
unless local_data[:entry].save
|
|
430
1236
|
result_string = '<span style = "color: red;"><b>FAILED TO SAVE!!!</b></span>'
|
|
431
1237
|
end
|
|
432
1238
|
end
|
|
@@ -435,7 +1241,7 @@ module KirguduBase
|
|
|
435
1241
|
end
|
|
436
1242
|
if result_string.blank?
|
|
437
1243
|
begin
|
|
438
|
-
result_string =
|
|
1244
|
+
result_string = local_data[:entry].send(params[:field_name])
|
|
439
1245
|
rescue
|
|
440
1246
|
result_string = '<span style = "color: red;"><b>ERROR OCCURRED!!!</b></span>'
|
|
441
1247
|
end
|