class Panel::PersonalDiploma::Desktop::PersonalDiplomasController < ApplicationController

	def index
   @diplomas = Diploma.where(create_user_id: current_user.id)
		respond_to do |format|
    	format.html { render :layout => false}
    end
	end

  def new
   @diploma = Diploma.new
    render :layout => false
  end

  def create
    params[:diploma][:create_user_id] = current_user.id
    @diploma = Diploma.new(params[:diploma])
    if @diploma.save
      render json: {success: true, msg: t('create_success')}.to_json
    else
      error_msg = @diploma.errors.full_messages.join("<br />")
      render json: {success: false, msg: error_msg}.to_json
    end
  end

  def edit
    @diploma = Diploma.find(params[:id])
    render :layout => false
  end

  def update
    params[:diploma][:create_user_id] = current_user.id
    @diploma = Diploma.find(params[:id])
    if @diploma.update_attributes(params[:diploma])
      render json: {success: true, msg: t('create_success')}.to_json
    else
      error_msg = @diploma.errors.full_messages.join("<br />")
      render json: {success: false, msg: error_msg}.to_json
    end
  end

  def destroy 
    @diploma = Diploma.find(params[:id])
    @diploma.destroy
    render :json => {success: true, msg: t('delete_success')}
  end

  def diploma_window
    render :layout => false
  end
end