authorization

This commit is contained in:
Harry Bomrah 2012-08-11 17:28:49 +08:00 committed by chris
parent 489231166f
commit 2c0058e8c9
9 changed files with 217 additions and 74 deletions

View File

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

View File

@ -67,7 +67,7 @@
<% end -%>
<% end -%>
<%= content_tag :li, :class => active_for_controllers('orbit_galleries','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 %>
<%= 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') %>

View File

@ -4,6 +4,7 @@ var galleryAPI = function(){
this.urlVars = rcom.getUrlVars();
this.albumArea = $("#orbit_gallery");
this.loadArea = "";
// this.authenticated = false;
this.initialize = function(){
$(document).ready(function(){
bindHandlers();
@ -19,6 +20,9 @@ var galleryAPI = function(){
}else if(typeof g.urlVars['edit']!= "undefined"){
g.editAlbum(g.urlVars['edit']);
g.loadArea = "edit";
}else if(typeof g.urlVars['tag']!= "undefined"){
g.loadAlbums(g.urlVars['tag']);
g.loadArea = "albums";
}else{
g.loadAlbums("all");
g.loadArea = "albums";
@ -28,7 +32,7 @@ var galleryAPI = function(){
$("#filter .filter_btns a").click(function(){
if(!$(this).hasClass("active")){
$(this).addClass("active");
if(typeof g.urlVars['cat'] == "undefined")
if(g.urlVars.length == 0)
window.location = "orbit_gallery?" + $(this).attr("href");
else
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(){
$.get("add_album",function(html){
@ -91,19 +111,29 @@ var galleryAPI = function(){
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>');
$addsign.find("a").click(function(){g.makeNewAlbum();})
if(id!="all"){
var ids = [];
var cids = [];
var tids = [];
var href = null;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++){
hash = hashes[i].split('=');
ids.push(hash[1]);
var href = "cat="+hash[1];
if(hash[0]=="cat"){
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");
}
if(cids.length == 0)
cids = "all";
}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(category,function(i,album){
if(album.cover == "default")
@ -117,7 +147,6 @@ var galleryAPI = function(){
})
}
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 pull-left" title="<%= I18n.t("gallery.back_to_albums") %>" href="orbit_gallery"><i class="icon-arrow-left icon-black"></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> ';
@ -438,6 +467,5 @@ var galleryAPI = function(){
bindHandlers();
})
}
}
}

View File

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

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::Timestamps
include OrbitCoreLib::ObjectAuthable
ObjectAuthTitlesOptions = %W{new_album}
APP_NAME = "album"
field :name, localize: true
has_many :gallery_albums, :autosave => true, :dependent => :destroy
def pp_object
name
end
end

View File

@ -1,51 +1,89 @@
<div class="modal-window" id="categories">
<div class="modal-header">
<h3><%= t("gallery.categories") %></h3>
</div>
<div class="modal-body">
<ul id="category_list">
<% @categorylist.each do |category| %>
<li><%= category.name %> <a href="<%= category.id %>" class='btn delete' onclick='return false;'><%= t("gallery.delete") %></a> </li>
<% end %>
</ul>
</div>
<div class="modal-footer">
<%= t("gallery.new_category")+"["+ t("gallery.english")+"]" %> : <input type="text" id="category_name_en"></text><br />
<%= t("gallery.new_category") +"["+ t("gallery.chinese")+"]" %> : <input type="text" id="category_name_zh_tw"></text><br />
<a href="#" class="btn btn-primary" id="category_save_btn" onclick="return false;"><%= t("gallery.save_changes") %></a>
</div>
</div>
<div id="tags" class="clear">
<% @categorylist.each do |category| %>
<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 %>
</div>
<div class="action">
<a href="<%= category.id %>" class='delete' onclick='return false;'><%= t("gallery.delete") %></a>
<a href="<%= category.id %>" class='edit' onclick='return false;'><%= t("gallery.edit") %></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>
<script type="text/javascript">
var deleteCategory = function(a){
var cid = a.attr("href");
var parent = a.parent().parent();
$.post("gallery_category_delete",{id:cid},function(response){
if(response.success)
parent.hide("slide",function(){parent.remove();})
})
}
var editCategory = function(a){
var cid = a.attr("href");
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(){
var deleteCategory = function(a){
var cid = a.attr("href");
$.post("gallery_category_delete",{id:cid},function(response){
if(response.success)
a.parent().hide("slide",function(){a.parent().remove();})
$("#tags div.action a.delete").click(function(){
deleteCategory($(this));
})
}
$.get("categorylist",function(html){
$("ul#category_list a.delete").click(function(){
var a = $(this);
deleteCategory(a);
$("#tags div.action a.edit").click(function(){
editCategory($(this));
})
$("#category_save_btn").click(function(){
var lang = {
"en" : $("#category_name_en").val(),
"zh_tw" : $("#category_name_zh_tw").val()
};
$.post("gallery_category_save",{"category":lang},function(response){
if(response.success){
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>');
$("div#tags").append($dom);
$dom.show('slide');
$dom.find("a.delete").click(function(){
deleteCategory($(this));
})
$("input[type=text]").val("");
}
})
$("#category_save_btn").click(function(){
var lang = {
"en" : $("#category_name_en").val(),
"zh_tw" : $("#category_name_zh_tw").val()
};
$.post("gallery_category_save",{"category":lang},function(response){
if(response.success){
var $li = $("<li class='hide'>"+lang.en+" <a href='"+response.id+"' class='btn delete' onclick='return false;'>Delete</a></li>");
$("ul#category_list").append($li);
$li.show('slide');
$li.find("a.delete").click(function(){
deleteCategory($(this));
})
$("input[type=text]").val("");
}
})
})
})
})
})
</script>

View File

@ -1,8 +1,6 @@
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "galleryAPI" %>
<% end %>
<%= stylesheet_link_tag "gallery" %>
<div id="filter" class="subnav">
<ul class="nav nav-pills filter">
<li class="accordion-group">
@ -18,21 +16,23 @@
</ul>
<div class="filters">
<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| %>
<a href="cat=<%= category.id %>" class="btn" onclick="return false;"><%= category.name %></a>
<% end %>
</div>
<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 class="accordion-body collapse" id="collapse-tags">
<div class="accordion-inner" data-toggle="buttons-checkbox">
<a href="#" class="btn js_history">album tags</a>
<div class="accordion-inner filter_btns tags" data-toggle="buttons-checkbox">
<% @tags.each do |tag| %>
<a href="tag=<%= tag.id %>" class="btn" onclick="return false;"><%= tag[I18n.locale] %></a>
<% end %>
</div>
<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>
@ -129,8 +129,16 @@
</div>
</div>
</div>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "galleryAPI" %>
<% end %>
<script type="text/javascript">
var gallery = new galleryAPI();
gallery.initialize();
</script>
</script>

View File

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