abstracted 0.3.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -53,7 +53,7 @@ App.init = ->
53
53
  #
54
54
  # Prepare close-notice's for acting on clicks to remove div
55
55
  #
56
- $(document.body).unbind('click.close_notice')
56
+ $(document.body).off('click.close_notice')
57
57
  $(document.body).on 'click.close_notice', 'a.close-notice', App.closeNotice
58
58
 
59
59
 
@@ -4,13 +4,13 @@ class AbstractResourcesController < ApplicationController
4
4
  self.responder = ::AbstractedResponder
5
5
  respond_to :html, :xml, :js, :json
6
6
 
7
- before_action :set_resource #, except: :index
8
- before_action :set_fab_button_options
9
- before_filter :set_parents, only: [ :new, :edit, :show ]
10
- before_action :set_resources, only: [:index, :print]
11
- before_action :set_variant_template
7
+ include PrintControl
8
+ include ResourceControl
9
+ include ParentControl
12
10
 
13
11
  before_filter :authenticate_user!
12
+ before_action :set_fab_button_options
13
+ before_action :set_variant_template
14
14
  after_action :verify_authorized
15
15
  # after_action :manage_parenthood, only: [:create,:update,:destroy]
16
16
 
@@ -101,16 +101,6 @@ class AbstractResourcesController < ApplicationController
101
101
  scoop_from_error e
102
102
  end
103
103
 
104
- #
105
- # build an array of the resource - particular to <SELECT>
106
- def set_parents
107
- @parents = []
108
- return @parents unless resource_class.respond_to? :roots #( 'arraying') && resource? )
109
- @parents = resource_class.arraying({ order: 'name'}, resource.possible_parents)
110
- rescue Exception => e
111
- scoop_from_error e
112
- end
113
-
114
104
  def show
115
105
  authorize resource
116
106
  respond_with resource
@@ -133,42 +123,6 @@ class AbstractResourcesController < ApplicationController
133
123
  scoop_from_error e
134
124
  end
135
125
 
136
- PRINTSUCCESS = 1
137
- NOQUEUE = -1
138
- NOUSER = -2
139
- PRINTRECERROR = -3
140
- PRINTCMDERROR = -4
141
- PRINTLISTERROR = -5
142
- PRINTEXCEPTION = -99
143
-
144
- #
145
- # print this view - let the Class handle everything
146
- # returning either the ID to a print_job or false (in which case something went terribly wrong)
147
- #
148
- # always an Ajax call - hence will always update the print_jobs link with 'yellow'-blink
149
- # POST /printers/print.js
150
- # params[:id] holds records to be printed
151
- def print
152
- authorize resource, :print?
153
- if resources.any?
154
- if print_resources > 0
155
- flash[:info] = t(:resources_printed_correct)
156
- status = 200
157
- else
158
- flash[:error] = t(:resources_not_found_printjob_not_created)
159
- status = 301
160
- end
161
- else
162
- flash[:error] = I18n.oxt(:resources_not_found_printjob_not_created)
163
- status = 301
164
- end
165
- return if params[:download]
166
- render :print, layout: false, status: status and return
167
- rescue Exception => e
168
- scoop_from_error e
169
- end
170
-
171
-
172
126
  def index
173
127
  authorize resource_class, :index?
174
128
  respond_with resources
@@ -217,139 +171,6 @@ class AbstractResourcesController < ApplicationController
217
171
  scoop_from_error e
218
172
  end
219
173
 
220
- def resource_params
221
- raise 'You need to "def resource_params" on the %sController! (see: http://blog.trackets.com/2013/08/17/strong-parameters-by-example.html)' % params[:controller].capitalize
222
- end
223
-
224
- def set_resource
225
- parent
226
- resource
227
- end
228
-
229
- def set_resources
230
- resources
231
- end
232
-
233
- def resource?
234
- !(%w{NilClass TrueClass FalseClass}.include? @resource.class.to_s)
235
- rescue Exception => e
236
- scoop_from_error e
237
- end
238
-
239
- def resource
240
- @resource ||= (_id.nil? ? new_resource : resource_class.find(_id) )
241
- return @resource if @resource.nil?
242
- @resource.current_user = (current_user || nil) if @resource.respond_to? :current_user
243
- @resource
244
- rescue Exception => e
245
- scoop_from_error e
246
- end
247
-
248
- # def resource=val
249
- # @resource=val
250
- # end
251
-
252
- def new_resource
253
- return nil if resource_class.nil?
254
- return resource_class.new if resource_class.ancestors.include?( ActiveRecord::Base ) and !(params.include? resource_class.to_s.underscore) #[ 'create', 'update' ].include? params[:action]
255
- p = resource_params
256
- p=p.compact.first if p.class==Array
257
- return resource_class.new(p.merge(current_user: current_user)) if resource_class.ancestors.include? ActiveRecord::Base
258
- nil
259
- rescue Exception => e
260
- scoop_from_error e
261
- end
262
-
263
- def _id
264
- return nil if !params[:id] || params[:id]=="0"
265
- params[:id] || params["#{resource_class.to_s.downcase}_id".to_sym]
266
- rescue Exception => e
267
- scoop_from_error e
268
- end
269
-
270
- def resource_name options={}
271
- resource_class.table_name
272
- rescue Exception => e
273
- scoop_from_error e
274
- # resource_class.to_s.underscore.pluralize
275
- end
276
-
277
- def resource_class
278
- return @resource_class if resource?
279
- @resource_class ||= params[:controller].singularize.classify.constantize
280
- rescue Exception => e
281
- scoop_from_error e
282
- end
283
-
284
- def resource_class= val
285
- @resource_class = val
286
- end
287
-
288
- def parent
289
- @parent ||= find_parent
290
- end
291
-
292
-
293
- def parent_class
294
- @parent_class ||= @parent.class
295
- end
296
-
297
- def parent_class= val
298
- @parent_class = val
299
- end
300
-
301
- def parent?
302
- !(%w{NilClass TrueClass FalseClass}.include? parent.class.to_s)
303
- end
304
-
305
- #
306
- #
307
- # return the resources collection - preferably from the cache
308
- def resources options={}
309
- @resources ||= find_resources options
310
- end
311
-
312
-
313
- #
314
- # returns the url for the resource - like /users/1
315
- def resource_url options={}
316
- r=request.path
317
- id=params[:id]
318
- options = case params[:action]
319
- when 'create','update','delete','destroy'; ""
320
- else resource_options(options)
321
- end
322
- return "%s%s" % [r,options] if r.match "#{resource.class.to_s.tableize}\/#{id}$"
323
- "%s%s" % [ r.split("/#{params[:action]}")[0], options]
324
- rescue Exception => e
325
- scoop_from_error e
326
- end
327
-
328
-
329
- #
330
- # returns the url for the resources - /employees or /employees/1/events
331
- def resources_url options={}
332
- r=request.path
333
- options = case params[:action]
334
- when 'create','update','delete','destroy'; ""
335
- else resource_options(options)
336
- end
337
- return "%s%s" % [r,options] if r.match "#{resource.class.to_s.tableize}$"
338
- "%s%s%s" % [ r.split( resource.class.to_s.tableize)[0],resource.class.to_s.tableize, options]
339
- rescue Exception => e
340
- scoop_from_error e
341
- end
342
-
343
- #
344
- # parent_url returns the parent url - /employees/1
345
- def parent_url options={}
346
- parent? ? url_for(@parent) : ""
347
- # parent? ? ( "/%s/%s" % [ @parent.class.table_name, @parent.id ] ) : ""
348
- rescue Exception => e
349
- scoop_from_error e
350
- end
351
-
352
-
353
174
  private
354
175
 
355
176
  # you can override this on your controller
@@ -362,43 +183,6 @@ class AbstractResourcesController < ApplicationController
362
183
  resources_url {}
363
184
  end
364
185
 
365
- #
366
- # print_resources will try to add a print_job
367
- # return error code
368
- def print_resources
369
- if resource_class == PrintJob
370
- resources.each do |res|
371
- return NOQUEUE unless Delayed::Job.enqueue res, :queue => 'printing'
372
- end
373
- return PRINTSUCCESS
374
- else
375
- return NOUSER unless current_user
376
- params[:user] = current_user
377
- if params[:print_list].nil?
378
- #
379
- # print something specific?
380
- if params[:print_cmd].nil?
381
- resources.each do |res|
382
- return PRINTRECERROR unless res.print_record params: params, context: self
383
- end
384
- else
385
- resources.each do |res|
386
- return PRINTCMDERROR unless res.send(params[:print_cmd],params)
387
- end
388
- end
389
- else
390
- params[:resources] = resources
391
- return PRINTLISTERROR unless resource_class.print_list( params )
392
- end
393
- end
394
-
395
- return PRINTSUCCESS
396
-
397
-
398
- rescue Exception => err
399
- return PRINTEXCEPTION
400
- end
401
-
402
186
  #
403
187
  # use views/../$action.html+mobile.erb if request originates from an iPad
404
188
  #
@@ -406,62 +190,6 @@ class AbstractResourcesController < ApplicationController
406
190
  request.variant = :mobile if request.user_agent =~ /iPad/
407
191
  end
408
192
 
409
- def resource_options options
410
- options.merge! params.except( "id", "controller", "action", "utf8", "_method", "authenticity_token" )
411
- options = (options.empty? ? "" : "?" + options.collect{ |k,v| "#{k}=#{v}" }.join("&"))
412
- end
413
-
414
- #
415
- # find the resources collection
416
- def find_resources options
417
-
418
- # return [] unless resource_class.ancestors.include? ActiveRecord::Base
419
- params[:ids] ||= []
420
- params[:ids] << params[:id] unless params[:id].nil?
421
-
422
- if params[:ids].compact.any?
423
- policy_scope(resource_class).where(id: params[:ids].compact.split(",").flatten)
424
- else
425
- if params[:q].blank? #or params[:q]=="undefined"
426
- r = parent? ? parent.send(resource_name) : (resource_class.nil? ? nil : find_all_resources(options))
427
- else
428
- r = find_resources_queried options
429
- end
430
- if (r.respond_to?( :page)) && (params[:format].nil? or params[:format]=='html' or params[:scrolling])
431
- params[:perpage] ||= 20
432
- params[:page] ||= 1
433
- return r.page(params[:page]).per(params[:perpage])
434
- else
435
- return r
436
- end
437
-
438
- # (params[:format].nil? or params[:format]=='html') ? r.page(params[:page]).per(params[:perpage]) : r
439
- end
440
- end
441
-
442
- #
443
- # find queried resources collection - implement on each controller to customize
444
- # raise an exception
445
- def find_all_resources options
446
- policy_scope(resource_class)
447
- end
448
-
449
- #
450
- # find queried resources collection - implement on each controller to customize
451
- # raise an exception
452
- def find_resources_queried options
453
- case params[:f]
454
- when nil
455
- if parent?
456
- policy_scope(resource_class).tags_included?( params[:q].split(" ") ).where( options )
457
- else
458
- policy_scope(resource_class).tags_included?( params[:q].split(" ") )
459
- end
460
- else
461
- policy_scope(resource_class)
462
- end
463
- end
464
-
465
193
 
466
194
  #
467
195
  # build options for fixed action button - implement on each controller to customize
@@ -480,84 +208,7 @@ class AbstractResourcesController < ApplicationController
480
208
  @fab_button_options = opt
481
209
  end
482
210
 
483
- #
484
- #
485
- # /employees/1/teams
486
- # /employees/1/teams/5
487
- # /employees/1/teams/5/attach
488
- # /theatres/2/contacts/5/uris.js
489
- def find_parent path=nil, parms=nil
490
- path ||= request.path
491
- parms ||= params
492
- if parms[:parent].nil? #or params[:parent_id].nil?
493
- paths=path.split("/")
494
- paths.pop if %w{new edit show create update delete index}.include? paths[-1]
495
- return nil if (paths.size < 3) #or (paths.size==4 and %w{edit new}.include?( parms[:action]))
496
- recognise_path paths.join("/")
497
- else
498
- parms[:parent].classify.constantize.find(parms[:parent_id])
499
- end
500
- end
501
- #
502
- # ['theatres','5','contacts','2','uris.js']
503
- def recognise_path path
504
- path_elements = Rails.application.routes.recognize_path path.gsub /\..*$/,'' # "/admin/users/2/printers/3/attach" => {:controller=>"printers", :action=>"attach", :user_id=>"2", :id=>"3"}
505
- recognise_parent( recognise_resource( path_elements ) )
506
-
507
- rescue Exception => e
508
- nil
509
- # return [ nil, nil, false ] if e.class.to_s == "ActionController::RoutingError"
510
211
 
511
- end
512
-
513
- # {:controller=>"printers", :action=>"attach", :user_id=>"2", :id=>"3"}
514
- def recognise_resource elems
515
- resource_class = elems.delete(:controller).singularize.classify.constantize
516
- resource = resource_class.find( elems.delete(:id) )
517
- elems
518
- rescue Exception => e
519
- return elems if e.class.to_s == "ActiveRecord::RecordNotFound"
520
- resource_class = nil
521
- elems
522
- end
523
-
524
- # { :action=>"attach", :user_id=>"2" }
525
- def recognise_parent elems
526
- elems.delete :action
527
- arr = elems.keys.first.to_s.split("_")
528
- return nil unless arr.include? "id"
529
- arr.pop
530
- arr.join("_").singularize.classify.constantize.find(elems.values.first)
531
- rescue
532
- nil
533
- end
534
-
535
- #
536
- # # /employees/1/teams/new
537
- # # /employees/1/teams/1/edit
538
- # # /employees/1/teams/1/delete
539
- def update_parenthood
540
- if params[:parent] and params[:parent_id]
541
- # raise "Ups - is this ready for prime time yet?"
542
- parent = params[:parent].classify.constantize.find(params[:parent_id])
543
- unless parent.blank?
544
- case params[:action]
545
- when "create"
546
- children = eval("parent.#{resource_name}")
547
- children << resource unless children.include? resource
548
- # when "edit"
549
- when "delete"
550
- children = eval("parent.#{resource_name}")
551
- children >> resource
552
- end
553
- end
554
- end
555
- true
556
- rescue
557
- false
558
- end
559
- #
560
- #
561
212
 
562
213
  def scoop_from_error e
563
214
  raise e if %w{ test development }.include? Rails.env
@@ -589,6 +240,22 @@ class AbstractResourcesController < ApplicationController
589
240
  flash.now[:error] = flash[:error] = "A template error occured - please call ALCO with: <br/><small>%s</small>" % e.message
590
241
  result= false
591
242
  status = 301
243
+
244
+ # when "PrintJobNotCreatedError"
245
+ #
246
+ # when "NoPreferredPrintersFound"
247
+ # logit :error, 'No preferred printers found! Sending PDF by email to %s (%s) ' % [usr.name,usr.email]
248
+ #
249
+ # when "PrintJobResourceError"
250
+ # logit :error, 'PrintJob could not be created - no records!?'
251
+ # return false
252
+ #
253
+ # when "PrintJobPrinterNotAvailableError"
254
+ # logit :error, 'PrintJob could not be created - the user has no printers attached!!'
255
+ # return false
256
+
257
+
258
+
592
259
  else
593
260
  raise e
594
261
  # flash.now[:error] = flash[:error] = "An error occured - please refer to log for details!"
@@ -164,8 +164,6 @@ module AbstractResourcesHelper
164
164
  '%s/%s/%s/defer' % [url_for( parent), resource.class.to_s.downcase.pluralize, resource.id]
165
165
  end
166
166
 
167
-
168
-
169
167
  #
170
168
  # List Helpers
171
169
  def set_attached_class children, child
@@ -175,7 +173,8 @@ module AbstractResourcesHelper
175
173
  children.include?( child) ? "" : "detached"
176
174
  end
177
175
 
178
-
176
+ #
177
+ #
179
178
  def show_resource_active item, linkable=true
180
179
  unless linkable
181
180
  if item.active
@@ -196,51 +195,67 @@ module AbstractResourcesHelper
196
195
  end
197
196
  end
198
197
 
199
-
198
+ #
200
199
  # return a link to delete a row
201
200
  def show_resource_delete_icon item, url, lbl='name'
202
- link_to item, class: 'delete_link', data: { balloon: t("balloons.delete" ), balloon_pos: "left", url: url, name: "#{item.send lbl }", id: "#{item.id}", remove: "#tr-#{item.class.to_s}-#{item.id}" } do
201
+ link_to item, class: 'delete_link', data: { delete_title: t("delete_title"), delete_prompt: t("delete_prompt", item: t("delete_modal.#{item.class.to_s.underscore}")), delete_confirm: t("delete_confirm"), balloon: t("balloons.delete" ), balloon_pos: "left", url: url, name: "#{item.send lbl }", id: "#{item.id}", remove: "#tr-#{item.class.to_s}-#{item.id}" } do
203
202
  content_tag :i, 'delete', class: 'material-icons small'
204
203
  end
205
204
  # = link_to account, class: 'delete_link', data: { url: '/admin/accounts', name: "#{account.name}", id: "#{account.id}", remove: "#tr-#{account.id}" } do
206
205
  # %i.material-icons.small{ title: "#{t('.delete')}"} delete
207
206
 
208
207
  end
208
+
209
+ #
209
210
  def build_delete_link resource
210
211
  link_to(content_tag(:i,'delete',class:'material-icons icon-trash'), resource, class: 'btn btn-mini delete_item', :"data-no-turbolink"=>true)
211
212
  end
212
213
 
214
+ #
213
215
  # return a link to print a row
214
216
  # url: ''
215
- # list: true|false
216
- # template: 'what_list.html.haml',
217
- # button: true|false either a button or a link
218
- # text: 'what to write on the link if at all'
217
+ # print: {template: 'what_list.html.haml', layout: 'list'|'record', range: '1,2,4-5', medium: 'printer'|'display'|'email'|'download', format: 'html'|'pdf', printer: 'name_of_printer'}
218
+ # data: { action: '', method: '', selector: '', id: '', osv. }
219
+ # button: 'material-icons'|false either classes for a button or false => a link
220
+ # link_layout: { text: '', title: '', icon: '' } text for the link - or <a..>text<i title="">icon</i></a>
219
221
  # classes: 'btn btn-mini print_item print_items ...' jquery hooks print_item will print a specific record, print_items will print a list of records
220
222
  def build_print_link resource, options={}
221
-
222
- list = options.include?(:list) ? options.delete(:list) : true
223
- button = options.include?(:button) ? options[:button] : false
224
- print_options = options.include?(:print_options) ? "?" + options.delete(:print_options) : ""
225
- url = options.include?(:url) ? options.delete(:url) : ( !list ? url_for( resource) + "/print" + print_options : url_for(resource_class.to_s.underscore.pluralize) + "/print?print_list=true&#{add_print_params}" )
226
- classes = options.include?(:classes) ? options.delete(:classes) : ( button ? 'btn btn-mini' : '')
227
- classes += ( list ? ' print_items' : ' print_item')
228
- return link_to( build_button_tag(options), url, class: classes) if options.include?(:button)
229
- link_to t(resource_class.to_s.underscore.pluralize.to_sym), url, options.merge( classes: classes)
230
-
231
- end
232
-
233
-
234
- def build_button_tag options={}
235
- text = options.include?(:text) ? options.delete(:text) : nil
236
- button = options.include?(:button) ? options.delete(:button) : false
237
- if text
238
- content_tag( :span) do
239
- text
240
- end << content_tag(:i,nil, class: button )
241
- else
242
- content_tag(:i,nil, class: button )
243
- end
223
+ url, list, options = build_resource_url(resource,options)
224
+ button = options.delete(:button) || false
225
+ options[:class] = options.delete(:classes) || ( button ? 'btn btn-mini' : '')
226
+ options[:class] += ( list ? ' print_items' : ' print_item')
227
+ return link_to( build_button_tag(button, options), url, options) if button
228
+ text = options.delete(:text) || t(resource_class.to_s.underscore.pluralize.to_sym)
229
+ link_to text, url, options
230
+ end
231
+
232
+ # return an array url, list, options
233
+ # options{ url: '', button: '', classes: '', text: ''}
234
+ def build_resource_url resource, options={}
235
+ print_options = options.delete(:print) || {}
236
+ args = add_print_params params.merge( print: print_options)
237
+ data_attribs = options.delete(:data) || {}
238
+ list = print_options[:format]=='list' || false
239
+ url = "%s/print?%s" % [ options.delete(:url) || ( !list ? url_for( resource) : url_for(resource_class.to_s.underscore.pluralize) ), args ]
240
+ [ url, list, options.merge( data: data_attribs) ]
241
+ end
242
+
243
+ # return button_tag
244
+ # text: 'what to write on the link if at all'
245
+ # classes: 'btn btn-mini print_item print_items ...' jquery hooks print_item will print a specific record, print_items will print a list of records
246
+ def build_button_tag button, options={}
247
+ layout = options.delete(:link_layout) || {}
248
+ text = layout.delete(:text) || ''
249
+ title = layout.delete(:title) || ''
250
+ icon = layout.delete(:icon) || ''
251
+ (text << content_tag(:i,icon, class: button, title: title )).html_safe
252
+ # if text
253
+ # content_tag( :span) do
254
+ # text[1]
255
+ # end << content_tag(:i,text[0], class: button )
256
+ # else
257
+ # content_tag(:i,text[0], class: button )
258
+ # end
244
259
  end
245
260
 
246
261
 
@@ -425,52 +440,19 @@ module AbstractResourcesHelper
425
440
  preferred ? r_url + "/defer" : r_url + "/prefer"
426
441
  end
427
442
 
428
-
429
- # return a link to print a row
430
- # url: ''
431
- # list: true|false
432
- # template: 'what_list.html.haml',
433
- # button: true|false either a button or a link
434
- # text: 'what to write on the link if at all'
435
- # classes: 'btn btn-mini print_item print_items ...' jquery hooks print_item will print a specific record, print_items will print a list of records
436
- # def build_print_link resource, options={}
437
- #
438
- # list = options.include?(:list) ? options.delete(:list) : true
439
- # button = options.include?(:button) ? options[:button] : false
440
- # print_options = options.include?(:print_options) ? "?" + options.delete(:print_options) : ""
441
- # url = options.include?(:url) ? options.delete(:url) : ( !list ? url_for( resource) + "/print" + print_options : url_for(resource_class.to_s.underscore.pluralize) + "/print?print_list=true&#{add_print_params}" )
442
- # classes = options.include?(:classes) ? options.delete(:classes) : ( button ? 'btn btn-mini' : '')
443
- # classes += ( list ? ' print_items' : ' print_item')
444
- # return link_to( build_button_tag(options), url, class: classes) if options.include?(:button)
445
- # link_to oxt(resource_class.to_s.underscore.pluralize.to_sym), url, options.merge( classes: classes)
446
- #
447
- # end
448
-
449
- # def build_button_tag options={}
450
- # text = options.include?(:text) ? options.delete(:text) : nil
451
- # button = options.include?(:button) ? options.delete(:button) : false
452
- # if text
453
- # content_tag( :span) do
454
- # text
455
- # end << content_tag(:i,nil, class: button )
456
- # else
457
- # content_tag(:i,nil, class: button )
458
- # end
459
- # end
460
-
461
- def add_print_params
443
+ def add_print_params p, prefix=""
462
444
  args = []
463
- params.each do |k,v|
464
- args << "#{k}=#{v}" unless %w{ ids action controller}.include? k
445
+ p.each do |k,v|
446
+ k = "#{prefix}[#{k}]" unless prefix.blank?
447
+ if v.is_a? Hash
448
+ args << add_print_params( v, 'print')
449
+ else
450
+ args << "#{k}=#{v}" unless %w{ ids action controller}.include? k
451
+ end
465
452
  end
466
453
  args.join("&")
467
454
  end
468
455
 
469
- # def add_from_to_params
470
- # return "" if params[:from].blank?
471
- # "&from=#{params[:from]}&until=#{params[:until]}"
472
- # end
473
-
474
456
  def build_toggle_white_collar_url
475
457
  if params[:blue_collar].nil?
476
458
  link_to oxt(:kun_timelønnede), collection_url(blue_collar: true), class: "btn btn-info"
@@ -534,4 +516,72 @@ module AbstractResourcesHelper
534
516
  end
535
517
  end
536
518
 
519
+ #
520
+ # when sorting rows
521
+ # set_direction will flip ASC and DESC
522
+ def set_direction dir
523
+ return 'ASC' unless dir
524
+ dir == 'ASC' ? 'DESC' : 'ASC'
525
+ end
526
+
527
+ #
528
+ # column_header sets a table header (TH) optionally with necessary data for balloon text and sorting
529
+ # options: balloon: "", balloon_pos: "", role: "", direction: "", field: ""
530
+ #
531
+ # bare minimum is
532
+ # column_header :some_field - which will be translated, using the tables.headers.some_field.label
533
+ # (if you need a different "label", identify the sorting field by an field: table_field)
534
+ #
535
+ # adding class's to managing styling
536
+ # column_header :some_field, class: ""
537
+ #
538
+ # adding sorting
539
+ # column_header :some_field, role: "sort",
540
+
541
+ # adding balloon helptext
542
+ # column_header :some_field, balloon: true
543
+ # ( set the text to fixed with balloon: "FIXED TEXT - NOT TRANSLATED")
544
+ # ( set position with balloon_pos: "left")
545
+ #
546
+ def column_header field, options={}
547
+ options[:data] ||= {}
548
+ # role = (options.delete :role) || ''
549
+ # classes = (options.delete :class) || ''
550
+ # id = (options.delete :id) || nil
551
+ balloon = (options.delete :balloon) || false
552
+ if balloon
553
+ options[:data][:balloon] = (balloon.class==String) ? balloon : I18n.translate("tables.headers.#{field}.balloon")
554
+ options[:data][:balloon_pos] = (options.delete :balloon_pos) || "up"
555
+ options[:data][:balloon_length] = (options.delete :balloon_length) || "fit"
556
+ end
557
+ options[:data][:field] = (options.delete :field) || field
558
+ options[:data][:direction] = (options.delete :direction) || @sorting_direction
559
+ txt = []
560
+ content_tag :th, options do
561
+ if options[:role] && options[:role]=="sort"
562
+ mark_sorted options[:data][:field], I18n.translate( "tables.headers.#{field}.label")
563
+ else
564
+ I18n.translate( "tables.headers.#{field}.label")
565
+ end
566
+ end
567
+ end
568
+
569
+ #
570
+ # mark_sorted will set a class depending on whether this column is sorted on
571
+ def mark_sorted col, label
572
+ if request.params[:s] == col
573
+ (
574
+ content_tag( :span, label, class: "th-label-sort-by") +
575
+ (content_tag :i, class: "material-icons" do
576
+ (request.params[:d]=='DESC' ? "arrow_drop_down" : "arrow_drop_up") rescue "arrow_drop_up"
577
+ end)
578
+ ).html_safe
579
+ else
580
+ content_tag :span, label, class: "th-label"
581
+ end
582
+ rescue
583
+ content_tag :span, label, class: "th-label"
584
+ end
585
+
586
+
537
587
  end