Sha256: c38b09fea85e26d32072aa81713dcb4d81fc476a261777712edf5f1bfaae7dc4

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

module ExtJS::Helpers
  module Store
    def extjs_store(params)
      params[:format] = 'json' if params[:format].nil?
      params[:proxy] = 'http' if params[:proxy].nil?

      controller = "#{params[:controller].to_s.capitalize}Controller".constantize
      model = ((params[:model]) ? params[:model] : params[:controller].singularize).capitalize.constantize

      reader = controller.extjs_reader(model)
      proxy = controller.extjs_proxy(params)

      params[:config]["storeId"] = model.to_s.downcase
      params[:config].merge!(reader)
      params[:config].merge!(proxy)

      type = (params[:proxy] === 'direct' ? params[:proxy] : params[:format]).capitalize

      script = ''
      # ugly hack for DirectProxy API.  Have to add an Ext.onReady() after the Store constructor to set API
      if params[:proxy] === 'direct'
        auto_load = params[:config].delete("autoLoad")
        cname = params[:controller].capitalize
        script = "Ext.onReady(function() { var s = Ext.StoreMgr.get('#{model.to_s.downcase}');"
        if (params[:config]["directFn"])
          script += "s.proxy.directFn = #{cname}.#{params[:config]["directFn"]};"
        else
          script += "s.proxy.setApi({create:#{cname}.#{params[:config]["api"]["create"]},read:#{cname}.#{params[:config]["api"]["read"]},update:#{cname}.#{params[:config]["api"]["update"]},destroy:#{cname}.#{params[:config]["api"]["destroy"]}});"
        end
        if auto_load
          script += "s.load();"
        end
        script += "});"
      end
      "new Ext.data.#{type}Store(#{params[:config].to_json});#{script}"

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
extjs-mvc-0.1.2 lib/action_view/helpers/store.rb
extjs-mvc-0.1.5 lib/action_view/helpers/store.rb
extjs-mvc-0.1.6 lib/action_view/helpers/store.rb