aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorjpl2016-10-07 15:29:05 +0200
committerjpl2016-10-07 15:29:19 +0200
commit15523ffde84e85595224c3b5ecd7e6fa28256ca4 (patch)
tree7b5d32bcafd2051239384f1844be6b50c1f61e35 /app
parent3c61225461922bbb482795854cea8aadc8d61742 (diff)
downloadchouette-core-15523ffde84e85595224c3b5ecd7e6fa28256ca4.tar.bz2
adding link builder to table builder
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/application.sass.erb2
-rw-r--r--app/controllers/companies_controller.rb1
-rw-r--r--app/helpers/refobjects_helper.rb32
-rw-r--r--app/views/companies/_companies.html.slim6
4 files changed, 36 insertions, 5 deletions
diff --git a/app/assets/stylesheets/application.sass.erb b/app/assets/stylesheets/application.sass.erb
index 7d4b48de9..53b767384 100644
--- a/app/assets/stylesheets/application.sass.erb
+++ b/app/assets/stylesheets/application.sass.erb
@@ -48,4 +48,4 @@ $body-bg: #eee
// Hack to make li simple
li
- list-style: none \ No newline at end of file
+ list-style: none
diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb
index 72b751c9d..cd0467a21 100644
--- a/app/controllers/companies_controller.rb
+++ b/app/controllers/companies_controller.rb
@@ -25,7 +25,6 @@ class CompaniesController < BreadcrumbController
protected
def collection
@q = line_referential.companies.search(params[:q])
- # @companies ||= CompanyDecorator.decorate_collection(@q.result(:distinct => true).order(:name).paginate(:page => params[:page]))
@companies ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page])
end
diff --git a/app/helpers/refobjects_helper.rb b/app/helpers/refobjects_helper.rb
index c4a93134b..8dbc2bc07 100644
--- a/app/helpers/refobjects_helper.rb
+++ b/app/helpers/refobjects_helper.rb
@@ -1,6 +1,6 @@
module RefobjectsHelper
- def table_builder collection, columns, cls = nil
+ def table_builder collection, columns, actions = [], cls = nil
return unless collection.present?
head = content_tag :thead do
@@ -8,6 +8,7 @@ module RefobjectsHelper
columns.each do |col|
concat content_tag(:th, collection.first.respond_to?(col) ? col.to_s.titleize : "Doesn't exist")
end
+ concat content_tag :th, "Actions" if actions.any?
end
end
@@ -17,6 +18,8 @@ module RefobjectsHelper
columns.collect { |col|
concat content_tag(:td, item.try(col))
}.to_s.html_safe
+ # Build links
+ concat content_tag :td, autolinks_builder(item, actions, :xs) if actions.any?
end
}.join().html_safe
end
@@ -24,4 +27,31 @@ module RefobjectsHelper
content_tag :table, head.concat(body), class: cls
end
+ def autolinks_builder(item, actions, cls)
+ link = []
+
+ actions.each do |action|
+ if action == "show"
+ showlink = link_to({controller: params[:controller], action: action, id: item.id}, class: 'btn btn-default') do
+ content_tag :span, "", class: 'fa fa-eye'
+ end
+ link << showlink
+ elsif action == "edit"
+ editlink = link_to({controller: params[:controller], action: action, id: item.id}, class: 'btn btn-default') do
+ content_tag :span, "", class: 'fa fa-pencil'
+ end
+ link << editlink
+ elsif action == "delete"
+ deletelink = link_to({controller: params[:controller], action: "show", id: item.id}, method: :delete, data: { confirm: 'Are you sure?'}, class: 'btn btn-default') do
+ content_tag :span, "", class: 'fa fa-trash-o'
+ end
+ link << deletelink
+ end
+ end
+
+ content_tag :div, class: "btn-group btn-group-#{cls}" do
+ link.join().html_safe
+ end
+ end
+
end
diff --git a/app/views/companies/_companies.html.slim b/app/views/companies/_companies.html.slim
index b9053c8cb..af7f6d48f 100644
--- a/app/views/companies/_companies.html.slim
+++ b/app/views/companies/_companies.html.slim
@@ -2,8 +2,10 @@
span.search = t('will_paginate.page_entries_info.search')
= page_entries_info @companies
-.companies.paginated_content
- = table_builder CompanyDecorator.decorate_collection(@companies), [:name, :edited_at, :published_at, :validity_period, :linecount, :transporter, :status], 'table table-bordered'
+.companies.paginated_content style="margin-top:20px;"
+ = table_builder CompanyDecorator.decorate_collection(@companies),
+ [:name, :edited_at, :published_at, :validity_period, :linecount, :transporter, :status] ["show", "delete"],
+ 'table table-bordered'
.pagination
= will_paginate @companies, container: false, renderer: RemoteBootstrapPaginationLinkRenderer