Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # encoding: utf-8
- require 'datatables/depts_datatable.rb'
- class DeptsController < ApplicationController
- load_and_authorize_resource
- # GET /depts
- # GET /depts.json
- def index
- @depts = Dept.order(:name)
- if params[:json_request]
- respond_to do |format|
- format.html # index.html.erb
- format.json { render :json => @depts}
- end
- else
- respond_to do |format|
- format.html # index.html.erb
- #format.csv {send_data @depts.all_to_csv}
- format.json { render :json => DeptsDatatable.new(view_context, current_user)}
- end
- end
- end
- # GET /depts/1
- # GET /depts/1.json
- def show
- @dept = Dept.find(params[:id])
- @dept_address = DeptAddress.where(:dept_id => params[:id])
- @dept_telephones = DeptTelephone.where("dept_id = ?", params[:id])
- @dept_equipaments = @dept.teaching_equipaments
- respond_to do |format|
- format.html # show.html.erb
- if params[:type_document] == 'estudante_por_campus'
- authorize! :read, :dept_students
- format.csv {send_data @dept.students_to_csv}
- end
- if params[:type_document] == 'relatorio_mensal'
- authorize! :read, :dept_mensal_report
- format.csv { send_data @dept.to_csv_mensal(@dept) }
- end
- format.xls
- format.json { render :json => @dept }
- if params[:type_document] == "campus"
- format.pdf do
- pdf = AllStudentsPDF.new(:dept => @dept)
- send_data pdf.render, :filename => "alunos_por_campus", :type => "application/pdf", :disposition => "inline"
- end
- end
- end
- end
- # GET /depts/new
- # GET /depts/new.json
- def new
- @dept = Dept.new
- @dept.build_dept_address
- respond_to do |format|
- format.html # new.html.erb
- format.json { render :json => @dept }
- end
- end
- # GET /depts/1/edit
- def edit
- @dept = Dept.find(params[:id])
- end
- # POST /depts
- # POST /depts.json
- def create
- @dept = Dept.new(params[:dept])
- #comando para transformar as "/" para "." pois o sistema nao le datas com "/"
- params[:dept][:started_at].gsub!("/",".")
- params[:dept][:finished_at].gsub!("/",".")
- respond_to do |format|
- if @dept.save
- format.html { redirect_to @dept, :notice => 'Departamento criado com sucesso.' }
- format.json { render :json => @dept, :status => :created, :location => @dept }
- else
- format.html { render :action => "new" }
- format.json { render :json => @dept.errors, :status => :unprocessable_entity }
- end
- end
- end
- # PUT /depts/1
- # PUT /depts/1.json
- def update
- @dept = Dept.find(params[:id])
- #comando para transformar as "/" para "." pois o sistema nao le datas com "/"
- params[:dept][:started_at].gsub!("/",".")
- params[:dept][:finished_at].gsub!("/",".")
- respond_to do |format|
- if @dept.update_attributes(params[:dept])
- format.html { redirect_to @dept, :notice => 'Departamento atualizado com sucesso.' }
- format.json { head :no_content }
- else
- format.html { render :action => "edit" }
- format.json { render :json => @dept.errors, :status => :unprocessable_entity }
- end
- end
- end
- # DELETE /depts/1
- # DELETE /depts/1.json
- def destroy
- @dept = Dept.find(params[:id])
- @dept.destroy
- respond_to do |format|
- format.html { redirect_to depts_url, :notice => 'Departamento excluído com sucesso.' }
- format.json { head :no_content }
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement