authorization

This commit is contained in:
Harry Bomrah 2012-08-11 17:28:49 +08:00
parent 2f4b93db59
commit 34e4928ee1
9 changed files with 222 additions and 77 deletions

View File

@ -346,6 +346,9 @@ getUrlVars : function(){
vars.push(hash[0]); vars.push(hash[0]);
vars[hash[0]] = hash[1]; vars[hash[0]] = hash[1];
} }
if(vars[0] == window.location.href){
vars =[];
}
return vars; return vars;
}, },
/*function to open a modalwindow on a page.. self reliant no images, no css needed. /*function to open a modalwindow on a page.. self reliant no images, no css needed.

View File

@ -68,7 +68,7 @@
<% end -%> <% end -%>
<%= content_tag :li, :class => active_for_controllers('orbit_galleries','/panel/gallery/back_end/tags') do -%> <%= content_tag :li, :class => active_for_controllers('orbit_galleries','/panel/gallery/back_end/tags') || active_for_app_auth("orbit_gallery") do -%>
<%= link_to content_tag(:i, nil, :class => 'icons-picture') + t('admin.orbit_gallery'), panel_gallery_back_end_orbit_gallery_path %> <%= link_to content_tag(:i, nil, :class => 'icons-picture') + t('admin.orbit_gallery'), panel_gallery_back_end_orbit_gallery_path %>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('orbit_galleries') ) do -%> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('orbit_galleries') ) do -%>
<%#= content_tag :li, link_to(t('admin.ad.all_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %> <%#= content_tag :li, link_to(t('admin.ad.all_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %>

View File

@ -4,6 +4,7 @@ var galleryAPI = function(){
this.urlVars = rcom.getUrlVars(); this.urlVars = rcom.getUrlVars();
this.albumArea = $("#orbit_gallery"); this.albumArea = $("#orbit_gallery");
this.loadArea = ""; this.loadArea = "";
// this.authenticated = false;
this.initialize = function(){ this.initialize = function(){
$(document).ready(function(){ $(document).ready(function(){
bindHandlers(); bindHandlers();
@ -19,6 +20,9 @@ var galleryAPI = function(){
}else if(typeof g.urlVars['edit']!= "undefined"){ }else if(typeof g.urlVars['edit']!= "undefined"){
g.editAlbum(g.urlVars['edit']); g.editAlbum(g.urlVars['edit']);
g.loadArea = "edit"; g.loadArea = "edit";
}else if(typeof g.urlVars['tag']!= "undefined"){
g.loadAlbums(g.urlVars['tag']);
g.loadArea = "albums";
}else{ }else{
g.loadAlbums("all"); g.loadAlbums("all");
g.loadArea = "albums"; g.loadArea = "albums";
@ -28,7 +32,7 @@ var galleryAPI = function(){
$("#filter .filter_btns a").click(function(){ $("#filter .filter_btns a").click(function(){
if(!$(this).hasClass("active")){ if(!$(this).hasClass("active")){
$(this).addClass("active"); $(this).addClass("active");
if(typeof g.urlVars['cat'] == "undefined") if(g.urlVars.length == 0)
window.location = "orbit_gallery?" + $(this).attr("href"); window.location = "orbit_gallery?" + $(this).attr("href");
else else
window.location = window.location.href +"&"+ $(this).attr("href"); window.location = window.location.href +"&"+ $(this).attr("href");
@ -45,6 +49,22 @@ var galleryAPI = function(){
} }
}) })
} }
$("#filter .filter-clear a").click(function(){
var loc = window.location.href;
var url = null;
var forwhat = $(this).attr("for");
$("#filter ."+forwhat+" a.active").each(function(){
$(this).removeClass("active");
url = loc.replace($(this).attr("href")+"&","");
if(url == loc)
url = loc.replace($(this).attr("href"),"");
if(url.charAt(url.length-1)=="&" || url.charAt(url.length-1)=="?")
url = url.substr(0,url.length-1);
loc = url;
})
window.location = url;
})
} }
this.makeNewAlbum = function(){ this.makeNewAlbum = function(){
$.get("add_album",function(html){ $.get("add_album",function(html){
@ -91,19 +111,29 @@ var galleryAPI = function(){
g.albumArea.find("#imgholder").empty(); g.albumArea.find("#imgholder").empty();
var $addsign = $('<div class="rgalbum"><a id="global_add" class="rgui bt-addnew" href="add" onclick="return false;">Add Album</a></div>'); var $addsign = $('<div class="rgalbum"><a id="global_add" class="rgui bt-addnew" href="add" onclick="return false;">Add Album</a></div>');
$addsign.find("a").click(function(){g.makeNewAlbum();}) $addsign.find("a").click(function(){g.makeNewAlbum();})
if(id!="all"){ if(id!="all"){
var ids = []; var cids = [];
var tids = [];
var href = null;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++){ for(var i = 0; i < hashes.length; i++){
hash = hashes[i].split('='); hash = hashes[i].split('=');
ids.push(hash[1]); if(hash[0]=="cat"){
var href = "cat="+hash[1]; cids.push(hash[1]);
href = "cat="+hash[1];
}else if(hash[0]=="tag"){
tids.push(hash[1]);
href = "tag="+hash[1];
}
$("#filter .filter_btns a[href='"+href+"']").addClass("active"); $("#filter .filter_btns a[href='"+href+"']").addClass("active");
} }
if(cids.length == 0)
cids = "all";
}else{ }else{
var ids = "all"; var cids = "all";
} }
$.getJSON("get_albums",{cid:ids},function(categories){ $.getJSON("get_albums",{cid:cids,tid:tids},function(categories){
$.each(categories,function(x,category){ $.each(categories,function(x,category){
$.each(category,function(i,album){ $.each(category,function(i,album){
if(album.cover == "default") if(album.cover == "default")
@ -117,12 +147,13 @@ var galleryAPI = function(){
}) })
} }
this.loadImages = function(id){ this.loadImages = function(id){
//<iframe id="upload_panel" width="100%" scrolling="no" height="300" frameborder="0" src="upload_panel.html?id=16">
var headarea = '<a class="bt-back btn btn-primary pull-right" title="<%= I18n.t("gallery.back_to_albums") %>" href="orbit_gallery"><i class="icon-arrow-left icon-white"></i><%= I18n.t("gallery.back_to_albums") %></a> '; var headarea = '<a class="bt-back btn btn-primary pull-right" title="<%= I18n.t("gallery.back_to_albums") %>" href="orbit_gallery"><i class="icon-arrow-left icon-white"></i><%= I18n.t("gallery.back_to_albums") %></a> ';
headarea+='<a class="bt-add btn btn-primary pull-right" title="<%= I18n.t("gallery.add_images") %>" href="images" onclick="return false;"><i class="icon-plus icon-white"></i><%= I18n.t("gallery.add_images") %></a> '; headarea+='<a class="bt-add btn btn-primary pull-right" title="<%= I18n.t("gallery.add_images") %>" href="images" onclick="return false;"><i class="icon-plus icon-white"></i><%= I18n.t("gallery.add_images") %></a> ';
headarea+='<a class="bt-del btn btn-primary pull-right" title="<%= I18n.t("gallery.del_album") %>" href="delete" onclick="return false;"><i class="icon-trash icon-white"></i><%= I18n.t("gallery.del_album") %></a> '; headarea+='<a class="bt-del btn btn-primary pull-right" title="<%= I18n.t("gallery.del_album") %>" href="delete" onclick="return false;"><i class="icon-trash icon-white"></i><%= I18n.t("gallery.del_album") %></a> ';
headarea+='<a class="bt-edit btn btn-primary pull-right" title="<%= I18n.t("gallery.edit") %>" href="orbit_gallery?edit='+id+'" ><i class="icon-pencil icon-white"></i><%= I18n.t("gallery.edit") %></a>'; headarea+='<a class="bt-edit btn btn-primary pull-right" title="<%= I18n.t("gallery.edit") %>" href="orbit_gallery?edit='+id+'" ><i class="icon-pencil icon-white"></i><%= I18n.t("gallery.edit") %></a>';
headarea = $(headarea); headarea = $(headarea);
var uploadpanel = $('<div id="upload_panel_holder"><div class="rgfn"><a class="bt-cls btn btn-primary pull-right" title="Close" href="" onclick="return false;"><i class="icon-remove icon-white"></i>Close Panel</a></div></div>'); var uploadpanel = $('<div id="upload_panel_holder"><div class="rgfn"><a class="bt-cls btn btn-primary pull-right" title="Close" href="" onclick="return false;"><i class="icon-remove icon-white"></i>Close Panel</a></div></div>');
var frame = $('<iframe id="upload_panel" width="100%" scrolling="no" height="200" frameborder="0" src="upload_panel"></iframe>'); var frame = $('<iframe id="upload_panel" width="100%" scrolling="no" height="200" frameborder="0" src="upload_panel"></iframe>');
@ -401,6 +432,5 @@ var galleryAPI = function(){
bindHandlers(); bindHandlers();
}) })
} }
} }

View File

@ -1,8 +1,14 @@
class Panel::Gallery::BackEnd::OrbitGalleriesController < OrbitBackendController class Panel::Gallery::BackEnd::OrbitGalleriesController < OrbitBackendController
include AdminHelper
def index def index
if is_manager? || is_admin? || is_sub_manager?
@authenticated = true
else
@authenticated = false
end
@categorylist = GalleryCategory.all @categorylist = GalleryCategory.all
@cid = params['cat'] @cid = params['cat']
@tags = GalleryTag.all
end end
def new_category def new_category
@ -28,7 +34,11 @@ class Panel::Gallery::BackEnd::OrbitGalleriesController < OrbitBackendController
end end
def add_album def add_album
if is_manager? || is_admin?
@categorylist = GalleryCategory.all @categorylist = GalleryCategory.all
elsif is_sub_manager?
@categorylist = GalleryCategory.authed_for_user(current_user,"new_album")
end
render :layout => false render :layout => false
end end
@ -50,15 +60,41 @@ class Panel::Gallery::BackEnd::OrbitGalleriesController < OrbitBackendController
def get_albums def get_albums
@categoryids = params["cid"] @categoryids = params["cid"]
@tags = params["tid"]
@albums = Array.new @albums = Array.new
if @categoryids == "all" 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 @albums << GalleryAlbum.all
end
else else
@categoryids.each do |id| @categoryids.each do |id|
category = GalleryCategory.find(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 @albums << category.gallery_albums.all
end end
end end
end
# @albums = GalleryAlbum.find("5017a7babd98eb049900000a")
# @albums.update_attributes({:tag_ids =>["501ba786bd98eb0232000126"]})
render :json=>@albums.to_json render :json=>@albums.to_json
end end
@ -103,6 +139,7 @@ class Panel::Gallery::BackEnd::OrbitGalleriesController < OrbitBackendController
end end
def edit_album def edit_album
if is_manager? || is_admin? || is_sub_manager?
aid = params['aid'] aid = params['aid']
album = GalleryAlbum.find(aid) album = GalleryAlbum.find(aid)
@images = album.gallery_images.all @images = album.gallery_images.all
@ -110,6 +147,7 @@ class Panel::Gallery::BackEnd::OrbitGalleriesController < OrbitBackendController
@cover = album.cover @cover = album.cover
render :layout => false render :layout => false
end end
end
def set_cover def set_cover
aid = params['aid'] aid = params['aid']

View File

@ -0,0 +1,16 @@
module Panel::Gallery::BackEnd::GalleryCategoriesHelper
include ActionView::Helpers::UrlHelper
def show_gallery_category_permission_link(gallery_category)
type = 'new_album'
oa = gallery_category.get_object_auth_by_title(type)
if oa.nil?
gallery_category.object_auths.new(title: type ).save
oa = gallery_category.get_object_auth_by_title(type)
end
# link_to t('announcement.bulletin.cate_auth'), edit_admin_object_auth_path(oa)
link_to t('gallery.cate_auth'),admin_object_auth_ob_auth_path(oa)
end
end

View File

@ -2,7 +2,16 @@ class GalleryCategory
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
include OrbitCoreLib::ObjectAuthable
ObjectAuthTitlesOptions = %W{new_album}
APP_NAME = "album"
field :name, localize: true field :name, localize: true
has_many :gallery_albums, :autosave => true, :dependent => :destroy has_many :gallery_albums, :autosave => true, :dependent => :destroy
def pp_object
name
end
end end

View File

@ -1,51 +1,89 @@
<div class="modal-window" id="categories"> <div id="tags" class="clear">
<div class="modal-header">
<h3><%= t("gallery.categories") %></h3>
</div>
<div class="modal-body">
<ul id="category_list">
<% @categorylist.each do |category| %> <% @categorylist.each do |category| %>
<li><%= category.name %> <a href="<%= category.id %>" class='btn delete' onclick='return false;'><%= t("gallery.delete") %></a> </li> <div class="tag clear">
<div class="tagitem">
<i class="icons-star"></i>
<% @site_valid_locales.each do |locale| %>
<span for="<%= locale %>"><%= category.name_translations[locale] %> </span>
<% end %> <% end %>
</ul>
</div> </div>
<div class="modal-footer"> <div class="action">
<%= t("gallery.new_category")+"["+ t("gallery.english")+"]" %> : <input type="text" id="category_name_en"></text><br /> <a href="<%= category.id %>" class='delete' onclick='return false;'><%= t("gallery.delete") %></a>
<%= t("gallery.new_category") +"["+ t("gallery.chinese")+"]" %> : <input type="text" id="category_name_zh_tw"></text><br /> <a href="<%= category.id %>" class='edit' onclick='return false;'><%= t("gallery.edit") %></a>
<a href="#" class="btn btn-primary" id="category_save_btn" onclick="return false;"><%= t("gallery.save_changes") %></a> <%= show_gallery_category_permission_link(category) %>
</div>
</div>
<% end %>
</div>
<div class="form-actions form-fixed pagination-right">
<div style="margin:0;padding:0;display:inline">
<%= t("gallery.new_category")+"["+ t("gallery.english")+"]" %> : <input type="text" id="category_name_en" />
<%= t("gallery.new_category") +"["+ t("gallery.chinese")+"]" %> : <input type="text" id="category_name_zh_tw" />
<a href="#" class="btn btn-primary" id="category_save_btn" onclick="return false;"><%= t("gallery.save") %></a>
</div>
</div> </div>
</div>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function(){
var deleteCategory = function(a){ var deleteCategory = function(a){
var cid = a.attr("href"); var cid = a.attr("href");
var parent = a.parent().parent();
$.post("gallery_category_delete",{id:cid},function(response){ $.post("gallery_category_delete",{id:cid},function(response){
if(response.success) if(response.success)
a.parent().hide("slide",function(){a.parent().remove();}) parent.hide("slide",function(){parent.remove();})
}) })
} }
$.get("categorylist",function(html){
$("ul#category_list a.delete").click(function(){ var editCategory = function(a){
var a = $(this); var cid = a.attr("href");
deleteCategory(a); var parent = a.parent().parent();
var parenthtml = parent.html();
var tempdom = $("<div class='tagitem'></div>");
parent.find("span").each(function(){
var locale = $(this).attr("for");
var lang = {
"en" : "English",
"zh_tw" : "Chinese"
}
tempdom.append("<label>"+lang[locale] + " :</label><input type='text' id='temp_name_"+locale+"' value='"+$(this).text()+"' />");
})
tempdom.append('<br /><a href="#" class="btn btn-primary" id="temp_save_btn" onclick="return false;"><%= I18n.t("gallery.save") %></a> <a href="#" class="btn btn-primary" id="temp_cancel_btn" onclick="return false;"><%= I18n.t("gallery.cancel") %></a>');
tempdom.find("a#temp_cancel_btn").click(function(){
parent.html(parenthtml);
parent.find("div.action a.delete").click(function(){
deleteCategory($(this));
})
parent.find(" div.action a.edit").click(function(){
editCategory($(this));
})
})
parent.html(tempdom);
}
$(document).ready(function(){
$("#tags div.action a.delete").click(function(){
deleteCategory($(this));
})
$("#tags div.action a.edit").click(function(){
editCategory($(this));
}) })
$("#category_save_btn").click(function(){ $("#category_save_btn").click(function(){
var lang = { var lang = {
"en" : $("#category_name_en").val(), "en" : $("#category_name_en").val(),
"zh_tw" : $("#category_name_zh_tw").val() "zh_tw" : $("#category_name_zh_tw").val()
}; };
$.post("gallery_category_save",{"category":lang},function(response){ $.post("gallery_category_save",{"category":lang},function(response){
if(response.success){ if(response.success){
var $li = $("<li class='hide'>"+lang.en+" <a href='"+response.id+"' class='btn delete' onclick='return false;'>Delete</a></li>"); var $dom = $('<div class="tag clear hide"><div class="tagitem"><i class="icons-star"></i>'+lang.en+' '+lang.zh_tw+'</div> <div class="action"><a href="'+response.id+'" class="delete" onclick="return false;"><%= I18n.t("gallery.delete") %></a></div></div>');
$("ul#category_list").append($li); $("div#tags").append($dom);
$li.show('slide'); $dom.show('slide');
$li.find("a.delete").click(function(){ $dom.find("a.delete").click(function(){
deleteCategory($(this)); deleteCategory($(this));
}) })
$("input[type=text]").val(""); $("input[type=text]").val("");
} }
}) })
}) })
})
}) })
</script> </script>

View File

@ -1,8 +1,6 @@
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "galleryAPI" %>
<% end %>
<%= stylesheet_link_tag "gallery" %> <%= stylesheet_link_tag "gallery" %>
<div id="filter" class="subnav"> <div id="filter" class="subnav">
<ul class="nav nav-pills filter"> <ul class="nav nav-pills filter">
<li class="accordion-group"> <li class="accordion-group">
@ -18,21 +16,23 @@
</ul> </ul>
<div class="filters"> <div class="filters">
<div class="accordion-body collapse" id="collapse-categories"> <div class="accordion-body collapse" id="collapse-categories">
<div class="accordion-inner filter_btns" data-toggle="buttons-checkbox"> <div class="accordion-inner filter_btns cats" data-toggle="buttons-checkbox">
<% @categorylist.each do |category| %> <% @categorylist.each do |category| %>
<a href="cat=<%= category.id %>" class="btn" onclick="return false;"><%= category.name %></a> <a href="cat=<%= category.id %>" class="btn" onclick="return false;"><%= category.name %></a>
<% end %> <% end %>
</div> </div>
<div class="filter-clear"> <div class="filter-clear">
<a href="panel/gallery/back_end/orbit_gallery" class="btn js_history"><i class="icons-brush-large"></i>清除</a> <a href="" class="btn" onclick="return false;" for="cats"><i class="icons-brush-large"></i>清除</a>
</div> </div>
</div> </div>
<div class="accordion-body collapse" id="collapse-tags"> <div class="accordion-body collapse" id="collapse-tags">
<div class="accordion-inner" data-toggle="buttons-checkbox"> <div class="accordion-inner filter_btns tags" data-toggle="buttons-checkbox">
<a href="#" class="btn js_history">album tags</a> <% @tags.each do |tag| %>
<a href="tag=<%= tag.id %>" class="btn" onclick="return false;"><%= tag[I18n.locale] %></a>
<% end %>
</div> </div>
<div class="filter-clear"> <div class="filter-clear">
<a href="panel/gallery/back_end/orbit_gallery" class="btn js_history"><i class="icons-brush-large"></i>清除</a> <a href="" class="btn" onclick="return false;" for="tags"><i class="icons-brush-large" ></i>清除</a>
</div> </div>
</div> </div>
</div> </div>
@ -72,8 +72,16 @@
</div> </div>
</div> </div>
</div> </div>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "galleryAPI" %>
<% end %>
<script type="text/javascript"> <script type="text/javascript">
var gallery = new galleryAPI(); var gallery = new galleryAPI();
gallery.initialize(); gallery.initialize();
</script> </script>

View File

@ -22,4 +22,7 @@ en:
del_album?: "Delete this album?" del_album?: "Delete this album?"
album_not_found: "Album not found" album_not_found: "Album not found"
pic_not_found: "Picture not found" pic_not_found: "Picture not found"
save: Save
cate_auth: Category Authorization
cancel: Cancel