1 package SL::Layout::ActionBar::Action;
 
   4 use parent qw(Rose::Object);
 
   8 use Rose::Object::MakeMethods::Generic (
 
   9   'scalar --get_set_init' => [ qw(id params text) ],
 
  12 # subclassing interface
 
  15   die 'needs to be implemented';
 
  19   sprintf q|$('#%s').data('action', %s);|, $_[0]->id, JSON->new->allow_blessed->convert_blessed->encode($_[0]->params);
 
  22 # this is mostly so that outside consumer don't need to load subclasses themselves
 
  24   my ($class, $data) = @_;
 
  26   require SL::Layout::ActionBar::Submit;
 
  28   my ($text, %params) = @$data;
 
  29   return if exists($params{only_if}) && !$params{only_if};
 
  30   return if exists($params{not_if})  &&  $params{not_if};
 
  31   return SL::Layout::ActionBar::Submit->new(text => $text, params => \%params);
 
  36 # shortcut for presenter
 
  46 # unique id to tie div and javascript together
 
  48   $_[0]->params->{id} //
 
  49   $_[0]->p->name_to_id('action[]')
 
  59 planned options for clickables:
 
  61 - checks => [ ... ] (done)
 
  63 a list of functions that need to return true before submitting
 
  65 - submit => [ form-selector, { params } ] (done)
 
  67 on click submit the form specified by form-selector with the additional params
 
  69 - function => function-name (done)
 
  71 on click call the specified function (is this a special case of checks?)
 
  73 - disabled => true/false/tooltip explaning why disabled (done)
 
  77 - runtime disable/enable