Orbit::Application.routes.draw do
  devise_for :users do
    match "/users_passwd" => "desktop/registrations#update", :as => :users_passwd, :via => :put
  end

  mount Resque::Server, :at => "/admin/resque"

  # routes for sinatra app
  match '/site/set_registered', :to => CentralServerExchangeApp  
  match '/site/public_key', :to => CentralServerExchangeApp 
  match '/site/update', :to => GithubApp
  match '/purchase/:type', :to => CentralServerExchangeApp

  match 'load_orbit_bar' => 'pages#load_orbit_bar'

  # routes for admin
  namespace :admin do
    mount Resque::Server.new, :at => "/resque"
    resources :assets do   
      collection do
        get 'file_upload'
        get 'delete'
      end
    end
    resources :asset_categories
    resources :asset_tags
    resources :app_auths 
    resources :object_auths  do
      match 'new_interface/:ob_type/:title/new' => "object_auths_new_interface#new" ,:as => :init_ob_auth,:via => :get
      match 'new_interface' => "object_auths_new_interface#setting" ,:as => :ob_auth,:via => :get
      match 'new_interface' => "object_auths_new_interface#update_setting" ,:as => :ob_auth,:via => :post
      match 'new_interface' => "object_auths_new_interface#user_list" ,:as => :ob_auth_show,:via => :put

      collection do
        match 'new/:type/:obj_id',:action => 'new',:via => "get",:as => :init
      end
      member do
        match ':id/create_role',:action => 'create_role',:via => "post",:as => :create_role
        match 'remove/:type/:target_id' ,:action=> 'remove_role',:via => "delete",:as =>:remove
      end
    end


    match 'ad_banners/:id/preview' => 'ad_banners#realtime_preview',:as => :realtime_preview_ad_banner,:via => :put
    match 'ad_banners/:id/rename' => 'ad_banners#rename',:as => :rename_ad_banner,:via => :post

    resources :ad_banners do 
      collection do
        match 'new_ad_image' => 'ad_images#new',:as => :new_ad_image,:via => :get
        match 'new_ad_image' => 'ad_images#create',:as => :create_ad_image,:via => :post
      end
      resources :ad_images ,:except => [:show,:index]
    end
    resources :dashboards
    resources :designs do
      collection do
        get 'upload_package'
        get 'delete'
        post 'upload_package'
      end
      member do
        post 'edit_file'  => 'designs#edit_file'
        post 'update_file' => 'designs#update_file'
        post 'upload_image' => 'designs#upload_image'
      end
    end
    resources :infos do
      get 'add_attribute_field'
    end
    resources :items
    match 'update_position' => 'items#update_position'
    resources :links do
      member do
        get 'delete'
      end
    end
    resources :pages do
      member do
        get 'delete'
        get 'reload_themes'
      end
    end
    resources :module_apps do
      match 'manager_auth_proc' => "module_apps_new_interface#setting" ,:as => :manager_auth_proc,:via => :get
      match 'manager_auth_proc' => "module_apps_new_interface#update_setting" ,:as => :manager_auth_proc,:via => :post
      match 'manager_auth_proc' => "module_apps_new_interface#user_list" ,:as => :manager_auth_show,:via => :put
      resources :app_auths do
        member do
          match 'remove/:type/:target_id' ,:action=> 'remove',:via => "delete",:as =>:remove
        end
      end

      member do
        match 'assign_manager' ,:action=> 'assign_manager',:via => "post",:as =>:assign_manager
        match 'assign_sub_manager' ,:action=> 'assign_sub_manager',:via => "post",:as =>:assign_sub_manager

        match 'remove_manager/:app_manager_id' ,:action=> 'remove_manager',:via => "delete",:as =>:remove_manager
        match 'remove_sub_manager/:app_sub_manager_id' ,:action=> 'remove_sub_manager',:via => "delete",:as =>:remove_sub_manager
        get 'reload_frontend_pages'
      end
    end
    resources :page_parts do
      member do
        get 'reload_widgets'
        get 'reload_widget_styles'
        get 'reload_r_tag_options'
      end
    end
    resources :plugins
    resources :purchases do
      collection do
        get 'install_app'
      end
      member do
        get 'buy_template'
        get 'download'
      end
    end
    resources :roles do
      get 'add_sub_role'
      get 'add_attribute_field'
    end
    resources :sites do
      get 'mail_setting'
      get 'site_info'
      get 'sitemap'
      get 'sitemap_frontend'
      get 'sitemap_toggle', :on => :member
      get 'system_info'
      get 'ui_theme'
      get 'change_design'
    end
    resources :tags
    resources :users
    resources :users_new_interface do
      member do
        get 'temp_edit'
      end
    end
	
    resources :member_selects do
  	  match 'member_select_search' => "member_selects#member_select_search" ,:as => :member_select_search,:via => "post"
  	  match 'member_select_add' => "member_selects#member_select_add" ,:as => :member_select_add,:via => "post"
  	end

    match 'module_store' => 'module_store#index'
    match 'module_store/show' => 'module_store#show'
    match 'template_store' => 'template_store#index'
    match 'template_store/template/:id' => 'template_store#show', :as => :template_store_template

  end
  # end admin

  namespace :panel do
    resources :users
  end

  resources :desktop_widgets do
    collection do
      get 'upload'
      get 'delete'
      post 'upload'
    end
  end

  match "desktop" =>  "desktop#index"
  namespace :desktop do
   match "desktop" => "desktop#desktop"
    match '/journal_pages/get_journals_json' => 'journal_pages#get_journals_json'
    match '/desktop'=>'desktop#desktop'
    match '/app_manager'=>'desktop#app_manager'
    match '/allsections'=>'desktop#allsections'
    match '/settings'=>'desktop#settings'
    match '/get_desktop_settings/'=>'desktop#get_desktop_settings'
    match '/save_desktop_settings/'=>'desktop#save_desktop_settings'
    match '/getgroups/'=>'desktop#getgroups'
    match '/getsectionlist/'=>'desktop#getsectionlist'
    match '/themes/'=>'desktop#themes'
    match '/sections/'=>'desktop#sections'
    match '/getapplist/'=>'desktop#getapplist'
    match '/newpositions/'=>'desktop#newpositions'
    match '/connections/'=>'desktop#connections'
    match '/widget_layout' => 'desktop#widget_layout'
    match '/temp_func/'=>'desktop#temp_func'

    resources :journal_pages, except: :show
    resources :journal_lists, only: :index
    resources :co_authors, except: :show
    resources :co_author_relations, except: :show
  end

  # namespace :desktop_publications do
  match 'desktop_publications/journal_p'=>'desktop_publications#journal_p'
  match 'desktop_publications/books' => 'desktop_publications#books'
  match 'desktop_publications/books_list'=>'desktop_publications#books_list'
  match 'desktop_publications/books_add'=>'desktop_publications#books_add'

  match 'desktop_publications/seminar_p' => 'desktop_publications#seminar_p'
  match 'desktop_publications/seminar_p_list/'=>'desktop_publications#seminar_p_list'
  match 'desktop_publications/seminar_p_add/'=>'desktop_publications#seminar_p_add'
  # end

  # namespace :desktop_research do
  match 'desktop_research/research_d' => 'desktop_research#research_d'
  match 'desktop_research/research_d_list/' => 'desktop_research#research_d_list'
  match 'desktop_research/research_d_add' => 'desktop_research#research_d_add'

  match 'desktop_research/research_p' => 'desktop_research#research_p'
  match 'desktop_research/research_p_list/' => 'desktop_research#research_p_list'
  match 'desktop_research/research_p_add' => 'desktop_research#research_p_add'
  # end

  match '/twitter/'=>'otheraccounts#twitter'
  match '/forgmail/'=>'otheraccounts#gmail'
  match '/otheraccounts/getaccounts'=>'otheraccounts#getaccounts'
  match '/save_account_info/'=>'otheraccounts#saveaccountinfo'

  match '/desktop_appstore/appstore'=>'desktop_appstore#appstore'
  match '/desktop_appstore/onlinestore'=>'desktop_appstore#onlinestore'
  match '/desktop_appstore/widgets'=>'desktop_appstore#widgets'
  match '/desktop_appstore/getuserwidgets'=>'desktop_appstore#getuserwidgets'
  match '/desktop_appstore/widgets_settings'=>'desktop_appstore#widgets_settings'

  match '/desktop_orbit/orbit' => 'desktop_orbit#orbit'

  match '/desktop_orbit/eventajaxload'=> 'desktop_orbit#eventajaxload'
  match '/desktop_orbit/gettimelinespan' => 'desktop_orbit#gettimelinespan'


  #match '/desktop_orbit/eventajaxload' => 'desktop_publications#create_journal'
  #match '/desktop_orbit/eventajaxload' => 'desktop_publications#delete_journal'
  # match '/desktop_orbit/eventajaxload' => 'desktop_publications#update_journal'


  scope '/front' do
    match 'show_banner/:id' => 'front#show_banner', :as => :front_show_banner
    match 'show_footer' => 'front#show_footer', :as => :front_show_footer
    match 'show_menu/:id' => 'front#show_menu', :as => :front_show_menu
    match 'show_page_sub_menu' => 'front#show_page_sub_menu', :as => :front_show_page_sub_menu
    match 'show_site_sub_menu' => 'front#show_site_sub_menu', :as => :front_show_site_sub_menu
    match 'show_sitemap' => 'front#show_sitemap', :as => :front_show_sitemap
  end


  match '/panel/:app_name/front_end/:app_action/:id(/:controller_action)' => 'pages#show_from_link', :constraints => lambda { |request|
    !request.query_string.include?("inner=true")
  }

  match '/panel/:app_name/front_end/:app_action' => 'pages#index_from_link', :constraints => lambda { |request|
    !request.query_string.include?("inner=true")
  }

  match '/share/:model/:id' => 'application#render_share'

  # routes for gridfs files
  match "/gridfs/*path" => "gridfs#serve" 

  # match "/images/*path" => "gridfs#serve_images"
  # match "/admin/pages/images/*path" => "gridfs#serve_images"

  # routes for pages to generate
  match '*page_name' => 'pages#show', :as => :page, :constraints => lambda{|request|
    !request.path.starts_with?("/panel")
  }

  root :to => 'pages#index'

end
