Class: Sinatra::XeditableAbstract
- Inherits:
 - 
      Object
      
        
- Object
 - Sinatra::XeditableAbstract
 
 
- Defined in:
 - lib/sinatra/xeditable_abstract.rb
 
Overview
Common methods for Xeditable related classes
Direct Known Subclasses
Sinatra::Xeditable_Checkbox::Checkbox, Sinatra::Xeditable_Select::Select
Instance Attribute Summary collapse
- 
  
    
      #active  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
By default, true.
 - 
  
    
      #html_class  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Class of the text that links to the editable select.
 - 
  
    
      #method  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Method to send the request.
 - 
  
    
      #title  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Title of dialog.
 - 
  
    
      #url_data  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Url to send information to.
 - 
  
    
      #values  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Hash of key, values to put on select.
 
Instance Method Summary collapse
- 
  
    
      #initialize(values, url, html_class)  ⇒ XeditableAbstract 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of XeditableAbstract.
 - #javascript ⇒ Object
 - #process_values(x) ⇒ Object
 - #xeditable_type ⇒ Object
 
Constructor Details
#initialize(values, url, html_class) ⇒ XeditableAbstract
Returns a new instance of XeditableAbstract.
      47 48 49 50 51 52 53 54  | 
    
      # File 'lib/sinatra/xeditable_abstract.rb', line 47 def initialize(values, url, html_class) process_values(values) @url_data = url @html_class = html_class @title = ::I18n.t(:Select_an_option) @method = "put" @active = true end  | 
  
Instance Attribute Details
#active ⇒ Object
By default, true. Could be set to false conditional on permission
      45 46 47  | 
    
      # File 'lib/sinatra/xeditable_abstract.rb', line 45 def active @active end  | 
  
#html_class ⇒ Object (readonly)
Class of the text that links to the editable select. Should be unique for every type of select.
      39 40 41  | 
    
      # File 'lib/sinatra/xeditable_abstract.rb', line 39 def html_class @html_class end  | 
  
#method ⇒ Object
Method to send the request. By default, is put
      43 44 45  | 
    
      # File 'lib/sinatra/xeditable_abstract.rb', line 43 def method @method end  | 
  
#title ⇒ Object
Title of dialog
      41 42 43  | 
    
      # File 'lib/sinatra/xeditable_abstract.rb', line 41 def title @title end  | 
  
#url_data ⇒ Object (readonly)
Url to send information to
      37 38 39  | 
    
      # File 'lib/sinatra/xeditable_abstract.rb', line 37 def url_data @url_data end  | 
  
#values ⇒ Object (readonly)
Hash of key, values to put on select
      35 36 37  | 
    
      # File 'lib/sinatra/xeditable_abstract.rb', line 35 def values @values end  | 
  
Instance Method Details
#javascript ⇒ Object
      65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84  | 
    
      # File 'lib/sinatra/xeditable_abstract.rb', line 65 def javascript source = values.map {|v| "{value:'#{v[0]}', text:'#{v[1].gsub("'", "")}'}" }.join(",\n") " $(document).ready(function () { $('.#{html_class}').editable({ type:'#{xeditable_type}', title:'#{title}', mode:'inline', ajaxOptions: { type: '#{method}' }, url:'#{url_data}', source: [#{source}] }); }); " end  | 
  
#process_values(x) ⇒ Object
      58 59 60 61 62 63  | 
    
      # File 'lib/sinatra/xeditable_abstract.rb', line 58 def process_values(x) @values = {} x.each_pair {|key, val| @values[key.to_s] = val } end  | 
  
#xeditable_type ⇒ Object
      55 56 57  | 
    
      # File 'lib/sinatra/xeditable_abstract.rb', line 55 def xeditable_type raise "Should be defined xeditable_type for javascript" end  |