Sha256: 804b18dbfa6ddba2eade6b97143994495f782c63a239f8f34d545cf1bb353514

Contents?: true

Size: 873 Bytes

Versions: 2

Compression:

Stored size: 873 Bytes

Contents

module Easypiechart
  class MainController < Volt::ModelController

    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

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

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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
volt-easypiechart-0.2.0 app/easypiechart/controllers/main_controller.rb
volt-easypiechart-0.1.0 app/easypiechart/controllers/main_controller.rb