Merge branch 'gallery_orbit' of https://github.com/Rulingcom/orbit into gallery_orbit

Conflicts:
	vendor/built_in_modules/gallery/config/routes.rb
This commit is contained in:
Harry Bomrah committed 2012-11-14 16:25:02 +08:00
commit 46f80ade6a
22 files changed
+1042 -880

No files matched your search

@@ -4,11 +4,11 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
before_filter :clean_values, :only => [:create, :update]
# before_filter :for_admin_only,:only => [:]
# before_filter :for_app_manager,:only => [:index,:show,]
# before_filter :for_admin_only,:only => [:]
# before_filter :for_app_manager,:only => [:index,:show,]
before_filter :force_order_for_visitor,:only=>[:index,:show,:get_sorted_and_filtered_bulletins]
before_filter :force_order_for_user,:except => [:index,:show,:get_sorted_and_filtered_bulletins]
before_filter :for_app_sub_manager,:except => [:index,:show,:get_sorted_and_filtered_bulletins]
before_filter :force_order_for_user,:except => [:index,:show,:get_sorted_and_filtered_bulletins,:get_bulletins_json]
before_filter :for_app_sub_manager,:except => [:index,:show,:get_sorted_and_filtered_bulletins,:get_bulletins_json]
before_filter :only => [ :new,:create,:edit,:update,:create] do |controller|
controller.get_categorys('BulletinCategory')
@@ -22,6 +22,39 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
render '/shared/preview/preview.html.erb',:layout=>false
end
def get_bulletins_json
@bulletins = Bulletin.all
@data = Hash.new
@data[I18n.t("category")] = Hash.new
@bulletins.each do |b|
deadline = b.deadline
if not deadline.nil?
deadline = display_date_time(deadline)
else
deadline = I18n.t("no_deadline")
end
if @data[I18n.t("category")][b.bulletin_category.title].nil?
@data[I18n.t("category")][b.bulletin_category.title] = Array.new
@data[I18n.t("category")][b.bulletin_category.title] << { title: b.title,
postdate: display_date_time(b.postdate),
deadline: deadline,
tag: b.sorted_tags.to_a,
}
else
@data[I18n.t("category")][b.bulletin_category.title] << { title: b.title,
postdate: display_date_time(b.postdate),
deadline: deadline,
tag: b.sorted_tags.to_a,
}
end
end
#render :json => @data.to_json
#to print readable json
render :json => JSON.pretty_generate(@data)
end
def index
# @bulletins = Bulletin.all
# @bulletins = Bulletin.desc("postdate desc")
@@ -52,10 +85,10 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
@bulletin_link = BulletinLink.new
@link_url = panel_announcement_back_end_bulletins_path
@bulletin_file = BulletinFile.new
@file_url = panel_announcement_back_end_bulletins_path
respond_to do |format|
format.html # index.html.erb
format.js { }
@@ -84,13 +117,13 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
@bulletin = session[:in_validate_object]
session[:in_validate_object] = {}
end
@link_url = panel_announcement_back_end_bulletins_path
get_tags
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @bulletin }
end
format.html # new.html.erb
format.xml { render :xml => @bulletin }
end
end
# GET /bulletins/1/edit
@@ -100,85 +133,82 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
redirect_to :action => :index
else
# @summary_variable = @bulletin.summary_variable
@link_url = panel_announcement_back_end_bulletin_path(@bulletin)
get_tags
@link_url = panel_announcement_back_end_bulletin_path(@bulletin)
get_tags
end
end
# POST /bulletins
# POST /bulletins.xml
def create
get_tags
if params[:bulletin_link]
@bulletin_link = BulletinLink.new(params[:bulletin_link])
get_tags
if params[:bulletin_link]
respond_to do |format|
if @bulletin_link.save
format.js { render 'create_bulletin_link' }
end
end
elsif params[:bulletin_file]
@bulletin_file = BulletinFile.new(params[:bulletin_file])
@bulletin_link = BulletinLink.new(params[:bulletin_link])
respond_to do |format|
if @bulletin_file.save
format.js { render 'create_bulletin_file' }
end
end
else
@bulletin = Bulletin.new(params[:bulletin])
@bulletin.deadline = nil if (@bulletin.deadline < @bulletin.postdate rescue nil)
@bulletin.create_user_id = current_user.id
@bulletin.update_user_id = current_user.id
if(is_manager? || is_admin?)
@bulletin.is_checked = true
@bulletin.is_rejected = false
@bulletin.de_pending
end
respond_to do |format|
if @bulletin_link.save
format.js { render 'create_bulletin_link' }
end
end
respond_to do |format|
if @bulletin.save
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('announcement.create_bulletin_success')) }
format.xml { render :xml => @bulletin, :status => :created, :location => @bulletin }
# format.js
format.js {
@info = {"success"=>"true","redirect_url"=>panel_announcement_back_end_bulletins_url}
flash[:notice] = t('bulletin.create_bulletin_success')
render "/shared/preview/after_create.js.erb"
}
else
format.html { render :action => "new" }
format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity }
format.js {
@info = {"success"=>"false","redirect_url"=>new_panel_announcement_back_end_bulletin_url(:bulletin => @bulletin)}
session[:in_validate_object] = @bulletin
render "/shared/preview/after_create.js.erb"
}
end
end
end
elsif params[:bulletin_file]
@bulletin_file = BulletinFile.new(params[:bulletin_file])
respond_to do |format|
if @bulletin_file.save
format.js { render 'create_bulletin_file' }
end
end
else
@bulletin = Bulletin.new(params[:bulletin])
@bulletin.deadline = nil if (@bulletin.deadline < @bulletin.postdate rescue nil)
@bulletin.create_user_id = current_user.id
@bulletin.update_user_id = current_user.id
if(is_manager? || is_admin?)
@bulletin.is_checked = true
@bulletin.is_rejected = false
@bulletin.de_pending
end
respond_to do |format|
if @bulletin.save
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('announcement.create_bulletin_success')) }
format.xml { render :xml => @bulletin, :status => :created, :location => @bulletin }
# format.js
format.js {
@info = {"success"=>"true","redirect_url"=>panel_announcement_back_end_bulletins_url}
flash[:notice] = t('bulletin.create_bulletin_success')
render "/shared/preview/after_create.js.erb"
}
else
format.html { render :action => "new" }
format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity }
format.js {
@info = {"success"=>"false","redirect_url"=>new_panel_announcement_back_end_bulletin_url(:bulletin => @bulletin)}
session[:in_validate_object] = @bulletin
render "/shared/preview/after_create.js.erb"
}
end
end
end
end
def link_quick_add
def link_quick_add
@bulletin_link = BulletinLink.new
@link_url = panel_announcement_back_end_bulletins_path
@bulletin_link.bulletin_id = params[:bulletin_id]
respond_to do |format|
format.js
end
end
def link_quick_edit
@@ -189,14 +219,13 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
end
end
def file_quick_add
def file_quick_add
@bulletin_file = BulletinFile.new
@file_url = panel_announcement_back_end_bulletins_path
@bulletin_file.bulletin_id = params[:bulletin_id]
respond_to do |format|
format.js
end
end
def file_quick_edit
@@ -211,75 +240,71 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
# PUT /bulletins/1.xml
def update
if params[:bulletin_link]
@bulletin_link = BulletinLink.find(params[:id])
if params[:bulletin_link]
@link_url = panel_announcement_back_end_bulletin_path(@bulletin_link)
@bulletin_link = BulletinLink.find(params[:id])
@link_url = panel_announcement_back_end_bulletin_path(@bulletin_link)
respond_to do |format|
if @bulletin_link.update_attributes(params[:bulletin_link])
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
format.js { render 'update_bulletin_link' }
end
end
elsif params[:bulletin_file]
@bulletin_file = BulletinFile.find(params[:id])
@file_url = panel_announcement_back_end_bulletin_path(@bulletin_file)
respond_to do |format|
if @bulletin_link.update_attributes(params[:bulletin_link])
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
format.js { render 'update_bulletin_link' }
end
end
respond_to do |format|
if @bulletin_file.update_attributes(params[:bulletin_file])
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
format.js { render 'update_bulletin_file' }
end
end
else
@bulletin = Bulletin.find(params[:id])
# @bulletin.image.clear if params[:bulletin][:image_del] == '1'
# if params[:bulletin][:image_del] == '1'
# @bulletin.remove_image!
# @bulletin.image_del = nil
# params[:bulletin][:image_del] = nil
# end
elsif params[:bulletin_file]
@bulletin_file = BulletinFile.find(params[:id])
@file_url = panel_announcement_back_end_bulletin_path(@bulletin_file)
respond_to do |format|
if @bulletin_file.update_attributes(params[:bulletin_file])
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
format.js { render 'update_bulletin_file' }
end
end
else
@bulletin = Bulletin.find(params[:id])
# @bulletin.image.clear if params[:bulletin][:image_del] == '1'
# if params[:bulletin][:image_del] == '1'
# @bulletin.remove_image!
# @bulletin.image_del = nil
# params[:bulletin][:image_del] = nil
# end
delete_out_invalid_date_from_params
respond_to do |format|
if @bulletin.update_attributes(params[:bulletin])
if(is_manager? || is_admin?)
@bulletin.is_checked = true
@bulletin.is_rejected = false
@bulletin.de_pending!
end
# if (params[:bulletin][:is_checked] == "false")
# @bulletin.is_rejected = true
# @bulletin.save!
# end
# if (@bulletin.deadline < @bulletin.postdate rescue nil)
# @bulletin.deadline = nil
# @bulletin.update_user_id = current_user.id
# @bulletin.save!
# end
# format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) }
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) }
format.js { render 'toggle_enable' }
format.xml { head :ok }
else
get_tags
format.html { render :action => "edit" }
format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity }
end
end
delete_out_invalid_date_from_params
respond_to do |format|
if @bulletin.update_attributes(params[:bulletin])
if(is_manager? || is_admin?)
@bulletin.is_checked = true
@bulletin.is_rejected = false
@bulletin.de_pending!
end
# if (params[:bulletin][:is_checked] == "false")
# @bulletin.is_rejected = true
# @bulletin.save!
# end
# if (@bulletin.deadline < @bulletin.postdate rescue nil)
# @bulletin.deadline = nil
# @bulletin.update_user_id = current_user.id
# @bulletin.save!
# end
# format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) }
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) }
format.js { render 'toggle_enable' }
format.xml { head :ok }
else
get_tags
format.html { render :action => "edit" }
format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity }
end
end
end
end
@@ -291,7 +316,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
@bulletin.destroy
respond_to do |format|
format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
# format.xml { head :ok }
format.js
@@ -299,21 +324,21 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
end
# def top_edit
# Bulletin.where(id: params[:id]).update_all( is_top: true )
# respond_to do |format|
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
# format.xml { head :ok }
# end
# Bulletin.where(id: params[:id]).update_all( is_top: true )
# respond_to do |format|
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
# format.xml { head :ok }
# end
# end
def load_quick_edit
@bulletin = Bulletin.find(params[:id])
@type = params[:type]
@bulletin_categories = BulletinCategory.all
#TODO 需要做 manager ,admin 才可以 all. 其他 available就好
#TODO 需要做 manager ,admin 才可以 all. 其他 available就好
get_tags
end
@@ -325,9 +350,9 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
redirect_to panel_announcement_back_end_bulletins_url(:filter => params[:filter], :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
end
protected
def delete_out_invalid_date_from_params
if((params[:bulletin]["deadline(1i)"] && params[:bulletin]["deadline(1i)"].blank?) or (params[:bulletin]["deadline(2i)"] && params[:bulletin]["deadline(2i)"].blank?) or (params[:bulletin]["deadline(3i)"] && params[:bulletin]["deadline(3i)"].blank?))
params[:bulletin].delete("deadline(1i)")
@@ -361,10 +386,10 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
# redirect_to :action => :index
# end
# end
def get_tags
module_app = ModuleApp.first(:conditions => {:key => 'announcement'})
@tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) rescue []
module_app = ModuleApp.first(:conditions => {:key => 'announcement'})
@tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) rescue []
end
def clean_values
@@ -377,5 +402,4 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
end rescue nil
end
end
end
@@ -10,13 +10,13 @@
<table class="table main-list">
<thead>
<tr>
<th class="span1"><%= t('bulletin.category') %></th>
<th class="span3"><%= t('bulletin.title') %></th>
<th class="span1"><%= t('bulletin.start_date') %></th>
<th class="span1"><%= t('bulletin.end_date') %></th>
<th class="span1"><%= t('bulletin.tags') %></th>
<th class="span1"><%= t('category') %></th>
<th class="span3"><%= t('title') %></th>
<th class="span1"><%= t('start_date') %></th>
<th class="span1"><%= t('end_date') %></th>
<th class="span1"><%= t('tags') %></th>
<% if not @user%>
<th class="span1"><%= t('bulletin.last_modified') %></th>
<th class="span1"><%= t('last_modified') %></th>
<% end %>
</tr>
</thead>
@@ -35,7 +35,7 @@
<% if not bulletin.deadline.nil?%>
<td><%= display_date_time(bulletin.deadline) %></td>
<%else%>
<td><%= t('bulletin.no_deadline') %></td>
<td><%= t('no_deadline') %></td>
<% end %>
<td>
<div class="label-group">
+8 -6
View File
@@ -6,6 +6,7 @@ Rails.application.routes.draw do
match 'approval_setting' => "approvals#setting" ,:as => :approval_setting,:via => :get
match 'approval_setting' => "approvals#update_setting" ,:as => :approval_setting,:via => :post
match 'approval_setting' => "approvals#user_list" ,:as => :approval_user_list,:via => :put
#match 'get_bulletins_json' => "bulletins#get_bulletins_json" ,:as => :bulletins_json_list,:via => :get
resources :bulletins do
match "approve/:bulletin_id" => "approvals#preview_and_approve",:as => :approval_preview,:via => :put
match "approve/:bulletin_id" => "approvals#approve",:as => :approve,:via => :post
@@ -18,21 +19,22 @@ Rails.application.routes.draw do
post "preview"
put "preview"
get 'delete'
get 'get_bulletins_json'
end
match "file_quick_add/:bulletin_id" => "bulletins#file_quick_add" ,:as => :file_quick_add
match "file_quick_edit/:bulletin_id" => "bulletins#file_quick_edit" ,:as => :file_quick_edit
end
resources :bulletin_categorys
resources :bulletin_links, :controller => 'bulletin_links' do
resources :bulletin_links, :controller => 'bulletin_links' do
match "link_quick_edit/:bulletin_link_id" => "bulletin_links#link_quick_edit" ,:as => :link_quick_edit
end
resources :bulletin_files, :controller => 'bulletin_files' do
resources :bulletin_files, :controller => 'bulletin_files' do
match "file_quick_edit/:bulletin_file_id" => "bulletin_files#file_quick_edit" ,:as => :file_quick_edit
end
resources :tags
end
namespace :front_end do
@@ -1,190 +1,232 @@
class Panel::Gallery::BackEnd::AlbumsController < OrbitBackendController
include AdminHelper
# before_filter :force_order_for_visitor,:only=>[:index]
before_filter :force_order_for_user#,:except => [:index]
include AdminHelper
def index
if is_manager? || is_admin? || is_sub_manager?
@authenticated = true #turn this value to false for view only
else
@authenticated = false
end
@categorylist = GalleryCategory.all
@cid = params['cat']
@tags = GalleryTag.all
end
before_filter :force_order_for_user, :except => [:index,:get_album_json]
def show
if is_manager? || is_admin? || is_sub_manager?
@authenticated = true #turn this value to false for view only
else
@authenticated = false
end
@album = GalleryAlbum.find(params[:id])
@tags = GalleryTag.all
end
def index
if is_manager? || is_admin? || is_sub_manager?
@authenticated = true #turn this value to false for view only
else
@authenticated = false
end
@categorylist = GalleryCategory.all
@cid = params['cat']
@tags = GalleryTag.all
end
def new
if is_manager? || is_admin?
@categorylist = GalleryCategory.all
elsif is_sub_manager?
@categorylist = GalleryCategory.authed_for_user(current_user,"new_album")
end
@album = GalleryAlbum.new
render :layout => false
end
def show
if is_manager? || is_admin? || is_sub_manager?
@authenticated = true #turn this value to false for view only
else
@authenticated = false
end
@album = GalleryAlbum.find(params[:id])
@tags = GalleryTag.all
end
def create
album = GalleryAlbum.new(params[:gallery_album])
album.save!
respond_to do |h|
h.js
end
end
def new
if is_manager? || is_admin?
@categorylist = GalleryCategory.all
elsif is_sub_manager?
@categorylist = GalleryCategory.authed_for_user(current_user,"new_album")
end
@album = GalleryAlbum.new
render :layout => false
end
def get_albums
@categoryids = params["cid"]
@tags = params["tid"]
@albums = Array.new
if @categoryids == "all"
if @tags
if @tags.kind_of?(Array)
@tags.each do |tag|
@albums << GalleryAlbum.where(tag_ids: tag)
end
else
@albums << GalleryAlbum.where(tag_ids: @tags)
end
else
@albums << GalleryAlbum.all
end
else
@categoryids.each do |id|
category = GalleryCategory.find(id)
if @tags
if @tags.kind_of?(Array)
@tags.each do |tag|
@albums << category.gallery_albums.where(tag_ids: tag)
end
else
@albums << category.gallery_albums.where(tag_ids: @tags)
end
else
@albums << category.gallery_albums.all
end
end
end
@output = Array.new
@albums.each do |album|
@albs = Array.new
album.each do |values|
tags = Array.new
values.tag_ids.each do |tag|
tags << GalleryTag.find(tag)[I18n.locale]
end
category = GalleryCategory.find(values.gallery_category_id).name
@albs << {"_id"=>values.id,"show_path"=>panel_gallery_back_end_album_path(values),"cover"=>values.cover,"cover_path"=>values.cover_path,"description"=>values.description,"category_name"=>category,"gallery_category_id" => values.gallery_category_id,"name"=>values.name,"tag_ids"=>values.tag_ids,"tag_names"=>tags}
end
@output << @albs
end
render :json=>@output.to_json
end
def create
album = GalleryAlbum.new(params[:gallery_album])
album.save!
respond_to do |h|
h.js
end
end
def destroy
album = GalleryAlbum.find(params[:id])
album.delete
render :json =>{"success"=>true}.to_json
end
def get_albums
@categoryids = params["cid"]
@tags = params["tid"]
@albums = Array.new
if @categoryids == "all"
if @tags
if @tags.kind_of?(Array)
@tags.each do |tag|
@albums << GalleryAlbum.where(tag_ids: tag)
end
else
@albums << GalleryAlbum.where(tag_ids: @tags)
end
else
@albums << GalleryAlbum.all
end
else
@categoryids.each do |id|
category = GalleryCategory.find(id)
if @tags
if @tags.kind_of?(Array)
@tags.each do |tag|
@albums << category.gallery_albums.where(tag_ids: tag)
end
else
@albums << category.gallery_albums.where(tag_ids: @tags)
end
else
@albums << category.gallery_albums.all
end
end
end
@output = Array.new
@albums.each do |album|
@albs = Array.new
album.each do |values|
tags = Array.new
values.tag_ids.each do |tag|
tags << GalleryTag.find(tag)[I18n.locale]
end
category = GalleryCategory.find(values.gallery_category_id).name
@albs << {"_id"=>values.id,"show_path"=>panel_gallery_back_end_album_path(values),"cover"=>values.cover,"cover_path"=>values.cover_path,"description"=>values.description,"category_name"=>category,"gallery_category_id" => values.gallery_category_id,"name"=>values.name,"tag_ids"=>values.tag_ids,"tag_names"=>tags}
end
@output << @albs
end
render :json=>@output.to_json
end
def edit
if is_manager? || is_admin? || is_sub_manager?
@album = GalleryAlbum.find(params[:id])
@images = @album.gallery_images.all
@album_name = @album.name_translations
@cover = @album.cover
@tags = GalleryTag.all
end
end
def destroy
album = GalleryAlbum.find(params[:id])
album.delete
render :json =>{"success"=>true}.to_json
end
def set_cover
album = GalleryAlbum.find(params[:album_id])
image = GalleryImage.find(params[:imageid])
album.update_attributes({:cover_path => image.file.thumb.url, :cover=>params[:imageid]})
render :json =>{"success"=>true}.to_json
end
def edit
if is_manager? || is_admin? || is_sub_manager?
@album = GalleryAlbum.find(params[:id])
@images = @album.gallery_images.all
@album_name = @album.name_translations
@cover = @album.cover
@tags = GalleryTag.all
end
end
def imgs
@album = GalleryAlbum.find(params[:album_id])
@tag_names = Array.new
@images = @album.gallery_images.all
@output = Array.new
@images.each do |values|
tags = Array.new
values.tag_ids.each do |tag|
tags << GalleryTag.find(tag)[I18n.locale]
end
@output << {"_id"=>values.id,"theater_link"=>panel_gallery_back_end_album_image_path(values),"description"=>values.description,"title"=>values.title,"file"=>values.file,"gallery_album_id"=>values.gallery_album_id,"tag_ids"=>values.tag_ids,"tag_names"=>tags}
end
if is_manager? || is_admin? || is_sub_manager?
@authenticated = true #turn this value to false for view only
else
@authenticated = false
end
if @authenticated
render :json=>{"images" => @output, "tags" => @album.tag_ids}.to_json
else
@album.tag_ids.each do |tag|
@tag_names << GalleryTag.find(tag)[I18n.locale]
end
render :json=>{"images" => @output, "tags" => @album.tag_ids, "tag_names" => @tag_names}.to_json
end
end
def upload_panel
@album = GalleryAlbum.find(params[:album_id])
render :layout => false
end
def upload_image
@album = GalleryAlbum.find(params[:album_id])
@files = params['files']
a = Array.new
@files.each do |file|
@image = @album.gallery_images.new
@image.file = file
@image.save!
a << {"thumbnail_url"=>@image.file.thumb.url}
end
render :json=>a.to_json
end
def images_tags
album = GalleryAlbum.find(params[:album_id])
tags = Array.new
images = album.gallery_images.all
images.each do |image|
tags << {"id"=>image.id, "tags" => image.tag_ids}
end
render :json=>tags.to_json
end
def set_cover
album = GalleryAlbum.find(params[:album_id])
image = GalleryImage.find(params[:imageid])
album.update_attributes({:cover_path => image.file.thumb.url, :cover=>params[:imageid]})
render :json =>{"success"=>true}.to_json
end
def update
@album = GalleryAlbum.find(params[:id])
@album.update_attributes(params[:gallery_album])
if is_manager? || is_admin? || is_sub_manager?
@authenticated = true #turn this value to false for view only
else
@authenticated = false
end
if params['delete_cover'] == "true"
@album.update_attributes(:cover=>"default")
end
@tags = GalleryTag.all
render :action => :show
end
def get_album_json
albums = GalleryAlbum.all
output = Array.new
albums.each do |album|
tag_names = Array.new
all_image = Array.new
images = album.gallery_images.all
images.each do |image|
tags = Array.new
image.tag_ids.each do |tag|
tags << GalleryTag.find(tag)[I18n.locale]
end
all_image << {
image_title: image.title,
image_description: image.description,
image_file: { url: "http://#{request.host_with_port+image.file.url}",
thumb: "http://#{request.host_with_port+image.file.thumb.to_s}"},
image_tag_names: tags}
end
album.tag_ids.each do |tag|
tag_names << GalleryTag.find(tag)[I18n.locale]
end
output << {
album_cover_file: "http://#{request.host_with_port+album.cover_path}",
album_name: album.name,
album_tag_names: tag_names,
images: all_image
}
end
#render :json=>{:images => @output,
# :tag_names => @tag_names}.to_json
render :json=>JSON.pretty_generate(output)
end
def imgs
@album = GalleryAlbum.find(params[:album_id])
@tag_names = Array.new
@images = @album.gallery_images.all
@output = Array.new
@images.each do |values|
tags = Array.new
values.tag_ids.each do |tag|
tags << GalleryTag.find(tag)[I18n.locale]
end
@output << { _id: values.id,
theater_link: panel_gallery_back_end_album_image_path(values),
description: values.description,
title: values.title,
file: values.file,
gallery_album_id: values.gallery_album_id,
tag_ids: values.tag_ids,
tag_names: tags}
end
if is_manager? || is_admin? || is_sub_manager?
@authenticated = true #turn this value to false for view only
else
@authenticated = false
end
if @authenticated
render :json=>{"images" => @output, "tags" => @album.tag_ids}.to_json
else
@album.tag_ids.each do |tag|
@tag_names << GalleryTag.find(tag)[I18n.locale]
end
render :json=>{"images" => @output, "tags" => @album.tag_ids, "tag_names" => @tag_names}.to_json
end
end
def upload_panel
@album = GalleryAlbum.find(params[:album_id])
render :layout => false
end
def upload_image
@album = GalleryAlbum.find(params[:album_id])
@files = params['files']
a = Array.new
@files.each do |file|
@image = @album.gallery_images.new
@image.file = file
@image.save!
a << {"thumbnail_url"=>@image.file.thumb.url}
end
render :json=>a.to_json
end
def images_tags
album = GalleryAlbum.find(params[:album_id])
tags = Array.new
images = album.gallery_images.all
images.each do |image|
tags << {"id"=>image.id, "tags" => image.tag_ids}
end
render :json=>tags.to_json
end
def update
@album = GalleryAlbum.find(params[:id])
@album.update_attributes(params[:gallery_album])
if is_manager? || is_admin? || is_sub_manager?
@authenticated = true #turn this value to false for view only
else
@authenticated = false
end
if params['delete_cover'] == "true"
@album.update_attributes(:cover=>"default")
end
@tags = GalleryTag.all
render :action => :show
end
end
+7 -7
View File
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
namespace :panel do
namespace :gallery do
namespace :back_end do
@@ -16,12 +17,11 @@ Rails.application.routes.draw do
match "album_images/#!/:id" => "album_images#show"
resources :album_images
resources :gallery_categories
resources :tags
end
namespace :front_end do
resources :gallery_categories
resources :tags
end
namespace :front_end do
match "get_albums" => "albums#get_albums"
# match "orbit_galleries" => "orbit_galleries#index"
# match "gallery_category_save" => "orbit_galleries#new_category"
@@ -51,6 +51,6 @@ Rails.application.routes.draw do
namespace :widget do
match "widget1" => "albums#widget1"
end
end
end
end
end
@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/
@@ -1,29 +1,77 @@
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
@location = Location.new(params[:location])
@location.save!
redirect_to panel_gprs_back_end_locations_url
end
def update
@location = Location.find(params[:id])
@location.update_attributes(params[:location])
redirect_to panel_gprs_back_end_locations_url
end
def destroy
@location = Location.find(params[:id])
@location.destroy
redirect_to panel_gprs_back_end_locations_url
end
def get_locations
locations = Location.all
@data = Array.new
locations.each do |location|
picurl = "http://#{request.host_with_port + location.file.url}",
thumburl = "http://#{request.host_with_port + location.file.thumb.url}"
@data << { name: location.name,
pic_url: picurl,
thumb_url: thumburl,
longitude: location.longitude,
latitude: location.latitude,
description: location.description }
end
#print readable json
render :json => JSON.pretty_generate({location: @data})
#render :json => {location: @data}.to_json
end
end
@@ -0,0 +1,2 @@
module Panel::Gprs::BackEnd::LocationsHelper
end
+8 -9
View File
@@ -1,12 +1,11 @@
class Location
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Document
include Mongoid::Timestamps
mount_uploader :file, GprsUploader
mount_uploader :file, GprsUploader
field :name
field :description
field :longitude, type: Float
field :latitude, type: Float
end
field :name
field :description
field :longitude, type: Float
field :latitude, type: Float
end
@@ -0,0 +1,30 @@
<div class="control-group">
<label class="control-label" for="">Name</label>
<div class="controls">
<%= f.text_field :name, :class=>"span4", :placeholder => "Area" %>
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Picture</label>
<div class="controls">
<%= f.file_field :file %>
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Coordinates</label>
<div class="controls">
<%= f.text_field :longitude, :class=>"span2", :placeholder => "Longitude" %>
<%= f.text_field :latitude, :class=>"span2", :placeholder => "Langitude" %>
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Description</label>
<div class="controls">
<%= f.text_area :description, :class=>"span4", :cols=>"30", :row=>"5" %>
</div>
</div>
<div class="control-group">
<div class="controls">
<%= f.submit "Save", :class=>"btn" %>
</div>
</div>
@@ -0,0 +1,4 @@
<%= form_for @location, :url=> panel_gprs_back_end_location_path(@location), :html => { :class=>"form-horizontal"} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>
@@ -1,42 +1,28 @@
<table class="table main-list">
<thead>
<tr>
<th class="span1"><%= t('location.picture') %></th>
<th class="span1"><%= t('location.name') %></th>
<th class="span1"><%= t('location.longitude') %></th>
<th class="span1"><%= t('location.latitude') %></th>
<th class="span3"><%= t('location.description') %></th>
<th class="span1"><%= t('location.edit') %></th>
<th class="span1"><%= t('location.delete') %></th>
</tr>
</thead>
<tbody id="tbody_locations" class="sort-holder">
<% @locations.each do |location| %>
<tr class="with_action">
<td><%= image_tag(location.file, alt: location.file, size: "50x50" )%></td>
<td><%= location.name%></td>
<td><%= location.longitude%></td>
<td><%= location.latitude%></td>
<td><%= location.description%></td>
<td><%= link_to 'Edit', edit_panel_gprs_back_end_location_path(location) %></td>
<td><%= link_to 'Destroy', panel_gprs_back_end_location_path(location), method: :delete , :confirm => t(:sure?) %></td>
</tr>
<% end %>
</tbody>
</table>
<!-- <form class="form-horizontal"> -->
<%= form_for @newlocation, :url=>{:action => "create"}, :remote => true, :class=>"form-horizontal" do |f| %>
<div class="control-group">
<label class="control-label" for="">Name</label>
<div class="controls">
<!-- <input type="text" id="" class="span4" placeholder="Taipei 101"> -->
<%= f.text_field :name, :class=>"span4", :placeholder => "Area" %>
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Picture</label>
<div class="controls">
<!-- <input type="file" id=""> -->
<%= f.file_field :file %>
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Coordinates</label>
<div class="controls">
<!-- <input type="text" id="" class="span2" placeholder="long"> -->
<%= f.text_field :longitude, :class=>"span2", :placeholder => "Longitude" %>
<%= f.text_field :latitude, :class=>"span2", :placeholder => "Langitude" %>
<!-- <input type="text" id="" class="span2" placeholder="lat"> -->
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Description</label>
<div class="controls">
<!-- <textarea name="" id="" class="span4" cols="30" rows="5"></textarea> -->
<%= f.text_area :description, :class=>"span4", :cols=>"30", :row=>"5" %>
</div>
</div>
<div class="control-group">
<div class="controls">
<!-- <textarea name="" id="" class="span4" cols="30" rows="5"></textarea> -->
<%= f.submit "Save", :class=>"btn" %>
</div>
</div>
<% end %>
<!-- </form> -->
<td><%= link_to 'New', new_panel_gprs_back_end_location_path %></td>
@@ -0,0 +1,3 @@
<%= form_for @location, :url=> panel_gprs_back_end_locations_path, :html => { :class=>"form-horizontal"} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>
Whitespace-only changes.
+8 -10
View File
@@ -1,14 +1,12 @@
Rails.application.routes.draw do
namespace :panel do
namespace :gprs do
namespace :back_end do
namespace :panel do
namespace :gprs do
namespace :back_end do
match "locations/get_locations" => "locations#get_locations"
resources :locations
end
end
end
match "locations/get_locations" => "locations#get_locations"
resources :locations
end
end
end
end
@@ -0,0 +1,14 @@
require 'test_helper'
class Panel::Gprs::BackEnd::LocationsControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
end
test "should get edit" do
get :edit
assert_response :success
end
end
@@ -0,0 +1,4 @@
require 'test_helper'
class Panel::Gprs::BackEnd::LocationsHelperTest < ActionView::TestCase
end