From 11fefa100fd9df70d557e7312a28294254c4a0a1 Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Thu, 8 Nov 2012 01:24:37 +0800 Subject: [PATCH] all of user can get json of gprs from outside --- .../gprs/back_end/locations_controller.rb | 92 ++++++++++++++----- 1 file changed, 68 insertions(+), 24 deletions(-) diff --git a/vendor/built_in_modules/gprs/app/controllers/panel/gprs/back_end/locations_controller.rb b/vendor/built_in_modules/gprs/app/controllers/panel/gprs/back_end/locations_controller.rb index c09b1379..1aff6223 100644 --- a/vendor/built_in_modules/gprs/app/controllers/panel/gprs/back_end/locations_controller.rb +++ b/vendor/built_in_modules/gprs/app/controllers/panel/gprs/back_end/locations_controller.rb @@ -1,29 +1,73 @@ class Panel::Gprs::BackEnd::LocationsController < OrbitBackendController - - def index - @newlocation = Location.new - end - def create - debugger - @newlocation = Location.new(params[:location]) - @newlocation.save! - render :action => "index" - end + before_filter :clean_values, :only => [:create, :update] - def get_locations - locations = Location.all - @data = Array.new + before_filter :force_order_for_visitor,:only => [:index, :new, :edit, :delete] + before_filter :force_order_for_user,:except => :get_locations + before_filter :for_app_sub_manager,:except => [:index, :new, :edit, :delete, :get_locations] - locations.each do |location| - picurl = "http://"+request.host + location.file.url - thumburl = "http://"+request.host + location.file.thumb.url - @data << {"name"=>location.name,"pic_url"=>picurl,"thumb_url"=>thumburl,"description"=>location.description} - end - render :json => @data.to_json - end - + def index + @locations = Location.all + respond_to do |format| + format.html # new.html.erb + format.json { render json: @locations } + end + end + + def new + @location = Location.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @location } + end + end + + def edit + @location = Location.find(params[:id]) + end + + def show + @location = Location..find(params[:id]) + respond_to do |format| + format.html + format.json { render json: @location } + end + end + + def create + debugger + @location = Location.new(params[:location]) + if @location.save + format.html { redirect_to @location } + format.json { render json: @location, status: :created, location: @location } + end + #render :action => "new" + end + + def destroy + @location = Location..find(params[:id]) + @location.destroy + + respond_to do |format| + format.json { head :no_content } + end + end + + def get_locations + locations = Location.all + @data = Array.new + + locations.each do |location| + picurl = "http://"+request.host + location.file.url + thumburl = "http://"+request.host + location.file.thumb.url + @data << { name: location.name, + pic_url: picurl, + thumb_url: thumburl, + longitude: location.longitude, + latitude: location.latitude, + description: location.description } + end + render :json => @data.to_json + end end - - -