Class: Easypiechart::MainController

Inherits:
Volt::ModelController
  • Object
show all
Defined in:
app/easypiechart/controllers/main_controller.rb

Instance Method Summary collapse

Instance Method Details

#before_index_removeObject



28
29
30
31
32
# File 'app/easypiechart/controllers/main_controller.rb', line 28

def before_index_remove
  @watches.each do |watch|
    watch.stop
  end
end

#index_readyObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/easypiechart/controllers/main_controller.rb', line 4

def index_ready
  @watches = []
  @elem = `$("#" + #{first_element}.id)`
  if @elem
    if attrs.options
      begin
        JSON.parse(attrs.options).each do |option, value|
          `#{@elem}.data(#{option}, #{value})`
        end
      rescue Object => e
        Volt.logger.error "'options' attribute passed to EasyPieChart must be a string that is valid, parsable JSON. Error was #{e}"
      end
    end
    `#{@elem}.easyPieChart();`
    @watches << -> { update_value(attrs.percent) }.watch!
  end
end

#update_valueObject



22
23
24
25
26
# File 'app/easypiechart/controllers/main_controller.rb', line 22

def update_value
  if @elem
    `#{@elem}.data('easyPieChart').update(#{attrs.percent})`
  end
end