Sha256: 27e38e486c7fc8e73f225f7bf0c1c9f44afcdce5695fefb7bc3fe3f0a13d6b14

Contents?: true

Size: 1.63 KB

Versions: 4

Compression:

Stored size: 1.63 KB

Contents

require_dependency "fastui/application_controller"

module Fastui
  class MOrgsController < ApplicationController
    respond_to :html, :xml, :json

    def index
      #@m_orgs = MOrg.scoped
      @m_orgs = params[:node] == '' ? MOrg.roots : MOrg.where({
                                                                    :parent_id => params[:node]
                                                                }.delete_if { |k, v| v.blank? })

      respond_with(@m_orgs.to_json(:include => [:parent], :methods => [:leaf, :expanded]))
    end

    def show
      @m_org = MOrg.find(params[:id])
      respond_with(@m_org)
    end

    def edit
      @m_org = MOrg.find(params[:id])
      respond_with(@m_org.to_json(:include => [:parent]))
    end

    def new
      @m_org = MOrg.new
      respond_with(@m_org)
    end

    def create
      @m_org = MOrg.new(params[:m_org])
      respond_with(@m_org) do |format|
        if @m_org.save
          format.json { render :json => {:success => true, :msg => 'ok'} }
        else
          format.json { render :json => {:success => false, :msg => 'failure'} }
        end
      end

    end

    def update
      @m_org = MOrg.find(params[:id])

      respond_with(@m_org) do |format|
        if @m_org.update_attributes(params[:m_org])
          format.json { render :json => {:success => true, :msg => 'ok'} }
        else
          format.json { render :json => {:success => false, :msg => 'false'} }
        end
      end
    end

    def destroy
      @m_org = MOrg.find(params[:id])
      @m_org.destroy
      respond_with(@m_org)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fastui-0.1.8 app/controllers/fastui/m_orgs_controller.rb
fastui-0.1.7 app/controllers/fastui/m_orgs_controller.rb
fastui-0.1.6 app/controllers/fastui/m_orgs_controller.rb
fastui-0.1.4 app/controllers/fastui/m_orgs_controller.rb