Modifications in ruby

This commit is contained in:
Harry Bomrah 2012-08-31 22:01:19 +08:00 committed by Christophe Vilayphiou
parent 7ae1dcd8e0
commit 2a66b89d33
16 changed files with 225 additions and 305 deletions

View File

@ -56,26 +56,26 @@ var galleryAPI = function(){
this.makeNewAlbum = function(path){
$.get(path,function(html){
rcom.modalWindow({loadHtml:html,width:400,height:320,"closeBtn":false},function(dom){
dom.find("#album_name_save_btn").click(function(){
var options ={
cid : dom.find("select#category_list").val(),
albumname : {
"en" : dom.find("#name_en").val(),
"zh_tw" : dom.find("#name_zh_tw").val()
},
albumdesc : {
"en" : dom.find("#desc_en").val(),
"zh_tw" : dom.find("#desc_zh_tw").val()
}
}
if(options.cid){
$.post("albums/create",options,function(response){
if(g.loadArea == "albums")
g.loadAlbums("all");
rcom.modalWindowClose();
})
}
})
// dom.find("#album_name_save_btn").click(function(){
// var options ={
// cid : dom.find("select#category_list").val(),
// albumname : {
// "en" : dom.find("#name_en").val(),
// "zh_tw" : dom.find("#name_zh_tw").val()
// },
// albumdesc : {
// "en" : dom.find("#desc_en").val(),
// "zh_tw" : dom.find("#desc_zh_tw").val()
// }
// }
// if(options.cid){
// $.post("albums/create",options,function(response){
// if(g.loadArea == "albums")
// g.loadAlbums("all");
// rcom.modalWindowClose();
// })
// }
// })
dom.find("#album_name_close_btn").click(function(){
rcom.modalWindowClose();
})
@ -87,9 +87,9 @@ var galleryAPI = function(){
if(confirm("<%= I18n.t('gallery.del_album?') %>")){
$.ajax({
type: "DELETE",
url : "albums/"+id,
url : id,
success : function(){
window.location = "albums";
window.location = "../albums";
}
})
}
@ -200,8 +200,6 @@ var galleryAPI = function(){
g.albumArea.addClass('o_album');
g.albumArea.find(".rghead .rgfn").append(uploadpanel);
g.albumArea.find("#imgholder").empty();
$("#filter").remove();
g.albumArea.css("margin-top","");
$.getJSON(id+"/imgs",function(album){
$.each(album.images,function(i,image){
var thumb = image.file.thumb.url;
@ -390,6 +388,7 @@ var galleryAPI = function(){
}
var changeImage = function(dom){
var pageurl = dom.attr('href');
$img.fadeOut(200,function(){
$img.attr({"src":dom.attr("data-content"),"height":picHeight+"px"});
$img.fadeIn(200);
@ -398,9 +397,13 @@ var galleryAPI = function(){
}
$slidelist.stop().animate({'height':'0px'}, 300);
$slidelist.find("ul").hide();
if(pageurl!=window.location){
window.history.pushState({path:pageurl},'',pageurl);
}
if(rcom.getInternetExplorerVersion() == -1){
if(pageurl!=window.location){
window.history.pushState({path:pageurl},'',pageurl);
}
}else{
window.location.hash = pageurl;
}
// $(".slideinfo b.info").text(imageArray[imagecount].title);
if($('.bt-tag').hasClass("active"))
updatePhotoTag();
@ -439,7 +442,19 @@ var galleryAPI = function(){
bindHandlers();
})
}
if(rcom.getInternetExplorerVersion()!=-1){
var url_constructor = window.location.href.split("/");
var url = "";
for(x=0;x<=url_constructor.length-1;x++){
if(x == url_constructor.length-1){
url+="#!/"+url_constructor[x];
}else{
url+=url_constructor[x]+"/";
}
}
window.location.href = url;
}
var albumid = $("#main_pic").attr("data-content");
g.albumArea.find(".bt-back").attr("href","../albums/"+albumid);
@ -466,28 +481,23 @@ var galleryAPI = function(){
$(this)
.toggleClass("setdelete btn-danger active")
.find('span').toggleClass('icon-white');
if($(".description_loader .edit_fn .setdelete").length > 0){
g.albumArea.find(".rghead .rgfn .bt-delete").show();
if($(".description_loader .edit_fn .setdelete").length > 0)
g.albumArea.find(".rghead .rgfn .bt-save").show();
if($(this).hasClass("active")){
$(this).parent().parent().find("input.del_field").val(true);
}else{
g.albumArea.find(".rghead .rgfn .bt-delete").hide();
$(this).parent().parent().find("input.del_field").val(false);
}
delete_cover();
})
g.albumArea.find(".rghead .rgfn .bt-save").click(function(){
// var dataArray = Array();
// $(".description_loader .en .txtchange").each(function(){
// var thisid = $(this).attr("for");
// dataArray.push({"id":thisid,"text":{"en":$(this).val(),"zh_tw":$(".description_loader .zh_tw .txtchange[for="+thisid+"]").val()}});
// })
// var albumnm = Array();
// $(".albumname_edit .txtchange").each(function(){
// albumnm.push($(this).val())
// })
// var dataArray = $("form#edit_album").serialize();
// $.post("update_album",{"data":dataArray},function(){
// })
})
var delete_cover = function(){
if($(".description_loader .setcover").parent().find(".bt-dels").hasClass("active")){
$("input.del_cover").val(true);
}else{
$("input.del_cover").val(false);
}
}
var current_element_for_tags = null;
var current_element_no = null;
$('.bt-tag').click(function(){

View File

@ -28,22 +28,27 @@ include AdminHelper
elsif is_sub_manager?
@categorylist = GalleryCategory.authed_for_user(current_user,"new_album")
end
@album = GalleryAlbum.new
render :layout => false
end
def create
category = GalleryCategory.find(params['cid'])
albumnames = params["albumname"]
albumdescs = params["albumdesc"]
album = category.gallery_albums.new
I18n.locale = :en
album.name = albumnames["en"]
album.description = albumdescs["en"]
I18n.locale = :zh_tw
album.name = albumnames["zh_tw"]
album.description = albumdescs["zh_tw"]
# category = GalleryCategory.find(params['cid'])
# albumnames = params["albumname"]
# albumdescs = params["albumdesc"]
# album = category.gallery_albums.new
# I18n.locale = :en
# album.name = albumnames["en"]
# album.description = albumdescs["en"]
# I18n.locale = :zh_tw
# album.name = albumnames["zh_tw"]
# album.description = albumdescs["zh_tw"]
album = GalleryAlbum.new(params[:gallery_album])
album.save!
render :json=>{"success"=>true,"id"=>album.id}.to_json
# render :json=>{"success"=>true,"id"=>album.id}.to_json
respond_to do |h|
h.js
end
end
def get_albums
@ -170,15 +175,16 @@ include AdminHelper
end
def update
debugger
@album = GalleryAlbum.find(params[:id])
#album.update_attributes(params[:gallery_album])
@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

View File

@ -2,24 +2,32 @@ class Panel::Gallery::BackEnd::GalleryCategoriesController < OrbitBackendControl
def index
@categorylist = GalleryCategory.all
#render :layout => false
@new_category = GalleryCategory.new
end
def edit
@category = GalleryCategory.find(params[:id])
render :layout => false
end
def create
@category = GalleryCategory.new(params[:gallery_category])
@category.save!
respond_to do |h|
h.js
end
end
def update
@category = GalleryCategory.find(params[:id])
@category.update_attributes(params[:gallery_category])
respond_to do |h|
h.js
end
end
def new
names = params['category']
category = GalleryCategory.new
I18n.locale = :en
category.name = names['en']
I18n.locale = :zh_tw
category.name = names['zh_tw']
category.save!
render :json=>{"success"=>true,"id"=>category.id}.to_json
end
def delete
def destroy
@category = GalleryCategory.find(params['id'])
@category.delete
render :json=>{"success"=>"true"}.to_json
end
end
end

View File

@ -11,5 +11,6 @@ class GalleryAlbum
belongs_to :gallery_category
has_and_belongs_to_many :tags, :class_name => "GalleryTag"
has_many :gallery_images, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :gallery_images, :allow_destroy => true
end

View File

@ -1,95 +0,0 @@
<%= stylesheet_link_tag "gallery" %>
<div id="orbit_gallery" class="rg">
<div class="rgbody">
<div id="imgholder">
</div>
</div>
<!-- tag part -->
<div id="tag_panel" class="my_scroll">
<div class="scrollbar">
<div class="track">
<div class="thumb">
<div class="end"></div>
</div>
</div>
</div>
<%
@locales = Array.new
@site_valid_locales.each do |locale|
@locales << locale
end
%>
<div class="viewport">
<div class="overview">
<ul class="tag_list" id="gallery_tag_list">
<% if @authenticated %>
<% @tags.each do |tag| %>
<li data-content="<%= tag.id %>"><input id="tag_<%= tag.id %>" type="checkbox"><label for="tag_<%= tag.id %>"><%= tag[I18n.locale] %></label><span style="display:none;"><%= tag[@locales[1]] %> <%= tag[@locales[0]] %></span></li>
<% end %>
<% end %>
</ul>
</div>
</div>
<% if @authenticated %>
<div class="tag_search"><div class="icon-search"></div><input type="text" value="<%= t('gallery.search_tags') %>" onblur="if(this.value=='')this.value='<%= t('gallery.search_tags') %>';" onfocus="if(this.value=='<%= t("gallery.search_tags") %>')this.value='';" id="tag_search_box"> <div class="tag_save"><a class="btn bt-save"><i class="icon-ok"></i><%= I18n.t("gallery.save") %></a></div></div>
<% end %>
</div>
<script type="text/javascript">
var $tag_panel = $('#tag_panel');
orbit_bar_height = $('#orbit-bar').outerHeight();
action_panel_height = $('.form-actions').outerHeight();
window_height = $(window).height();
$tag_panel.height( window_height - orbit_bar_height - 90 );
$tag_panel.tinyscrollbar();
$(window).resize(function(){
$tag_panel.tinyscrollbar_update('relative');
$tag_panel.height( $(window).height() - orbit_bar_height - 90 );
});
</script>
<!-- tag end -->
<div class="form-actions form-fixed pagination-right rghead">
<div class="rgfn">
<% if params[:theater] %>
<a href="" class="bt-back btn pull-left" title="<%= I18n.t("gallery.back_to_photos") %>"><i class="icon-arrow-left icon-black"></i><%= I18n.t("gallery.back_to_photos") %></a>
<a class="bt-edit btn btn-primary pull-right" title="<%= I18n.t("gallery.edit") %>" href="" ><i class="icon-pencil icon-white"></i><%= I18n.t("gallery.edit") %></a>
<a class="bt-tag btn btn-primary pull-right" title="<%= I18n.t("gallery.photo_tag") %>" href="" ><i class="icon-tag icon-white"></i><%= I18n.t("gallery.photo_tag") %></a>
<% else %>
<a class="bt-back btn btn-primary pull-left" title="<%= I18n.t("gallery.back_to_albums") %>" href="albums"><i class="icon-arrow-left icon-white"></i><%= I18n.t("gallery.back_to_albums") %></a>
<a class="bt-tag btn btn-primary pull-right" title="<%= I18n.t("gallery.album_tag") %>" href="" ><i class="icon-tag icon-white"></i><%= I18n.t("gallery.album_tag") %></ a>
<% if @authenticated %>
<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>
<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>
<a class="bt-edit btn btn-primary pull-right" title="<%= I18n.t("gallery.edit") %>" href="albums/<%= params[:album] %>/edit" ><i class="icon-pencil icon-white"></i><%= I18n.t("gallery.edit") %></a>
<% end %>
<% end %>
</div>
</div>
</div>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "galleryAPI" %>
<% end %>
<script type="text/javascript">
galleryAPI.prototype.locale = "<%= I18n.locale %>";
var gallery = new galleryAPI();
gallery.initialize();
//gallery.loadAlbums(gallery.urlVars['cat']);
gallery.loadArea = "images";
gallery.loadImages("<%= params[:id] %>");
</script>

View File

@ -1,34 +0,0 @@
<!-- <div class="rghead">
<div class="rgfn">
<a href="" class="rgui bt-back rgbt" title="Back" id='bakbtngallery'><span id='album_name_span'>Back to photos</span></a>
</div>
<div class="rgtitle">Gallery</div>
</div>
</div> -->
<div class="rslide" style="position:relative; width:100%;">
<div class="rslideinside"><div id="loading" style="display:none;"></div>
<div class="comp" id='main_pic' data-content='<%= @image.gallery_album_id %>'><a href="" id="nextpic" class="navN" title="下一張" onclick="return false;" ><img src="<%= @image.file.url %>" alt="" /></a></div>
<div class="rslidenav">
<a href="" class="navP" title="上一張" onclick="return false;">Prev</a>
<a href="" class="navN" title="下一張" onclick="return false;">Next</a>
</div>
</div>
<div class="slidelist">
<ul id='galleryimagelist' style="display:none;">
<% i=0 %>
<% @images.each do |image| %>
<li for="<%= i %>"><a href="orbit_gallery?theater=<%= image.id %>" class="list_element" data-content="<%= image.file.url %>" onclick="return false;"><img src="<%= image.file.thumb.url %>" alt="" /></a></li>
<% i=i+1 %>
<% end %>
</ul>
</div>
<div class="slidectrl">
<a href="" class="togglescreen" title="切換全螢幕" onclick="return false;">Screen</a>
<a href="" class="togglelist" title="顯示照片清單" onclick="return false;">List</a>
<a href="" class="browserfullscreen" title="顯示照片清單" onclick="return false;">F</a>
<div class="slideinfo">
<!-- <b class="info"><%= @image.title %></b> -->
<span class="info"><%= @image.description %></span>
</div>
</div>
</div>

View File

@ -0,0 +1,3 @@
var gal = new galleryAPI();
gal.loadAlbums("all");
rcom.modalWindowClose();

View File

@ -15,19 +15,20 @@
<!-- <form id="edit_album" action="update_album" method="post"> -->
<%= form_for @album, :url => panel_gallery_back_end_album_path(@album), :html => {:class => 'clear'} do |f| %>
<div class="tab_content">
<% @site_valid_locales.each_with_index do |locale, i| %>
<% if i == 0 %>
<div class="<%= locale %> fade tab-pane in active">
<% else %>
<div class="<%= locale %> fade tab-pane" >
<% end %>
<div class="albumname_edit">
<%= f.fields_for :name_translations do |name| %>
<%= f.label t("gallery.album_name") %>
<div class="inputui rginput rgih26 w380">
<% @site_valid_locales.each_with_index do |locale, i| %>
<% if i == 0 %>
<div class="<%= locale %> fade tab-pane in active">
<% else %>
<div class="<%= locale %> fade tab-pane" >
<% end %>
<%= name.text_field locale, :value => (@album_name[locale]), :class => "txtchange" %>
</div>
<% end %>
</div>
<% end %>
</div>
@ -38,10 +39,19 @@
<img src="<%= image.file.thumb.url %>" />
<% end %>
<div class="inputui rginput rgih98 w380">
<%= f.fields_for :gallery_images do |j| %>
<%= f.fields_for :gallery_images, image do |j| %>
<%= j.hidden_field :id, :value => (image.id) %>
<%= j.hidden_field :_destroy, :value => false, :class => "del_field" %>
<%= j.fields_for :description_translations do |desc| %>
<% @site_valid_locales.each_with_index do |locale, i| %>
<% if i == 0 %>
<div class="<%= locale %> fade tab-pane in active">
<% else %>
<div class="<%= locale %> fade tab-pane" >
<% end %>
<%= desc.text_area locale, :value => (image.description_translations[locale] rescue nil), :class => "txtchange" %>
</div>
<% end %>
<% end %>
<% end %>
</div>
@ -57,12 +67,11 @@
</div>
<% end %>
</div>
</div>
<% end %>
<input type="hidden" name="delete_cover" value="false" class="del_cover" />
<div class="form-actions form-fixed pagination-right rghead">
<div class="rgfn">
<a href="<%= panel_gallery_back_end_album_path(@album) %>" class="bt-back btn pull-left" title="<%= I18n.t("gallery.back_to_photos") %>"><i class="icon-arrow-left icon-black"></i><%= I18n.t("gallery.back_to_photos") %></a>
<a class="bt-del bt-delete btn btn-primary pull-right" onclick="return false;" style="display:none;" title="<%= I18n.t("gallery.delete_selected") %>" href="<%= panel_gallery_back_end_album_images_path %>"><i class="icon-trash icon-white"></i><%= I18n.t("gallery.delete_selected") %></a>
<%= f.submit t('gallery.save'), :class=>'bt-save icon-ok btn btn-primary pull-right', :style=>"display:none;" %>
</div>
</div>

View File

@ -2,33 +2,50 @@
<div class="modal-header">
<h3><%= t("gallery.add_album") %></h3>
</div>
<%= form_for @album, :url => {:action => "create"}, :remote => true do |f| %>
<div class="modal-body add-album">
<select id="category_list">
<option value=""><%= t("gallery.select_category") %></option>
<% @categorylist.each do |category| %>
<option value='<%= category.id %>' ><%= category.name %></option>
<% end %>
</select>
<%= f.select(:gallery_category_id, GalleryCategory.all.collect {|p| [ p.name, p.id ] },{:prompt => t("gallery.select_category")}) %>
<ul class="nav nav-tabs">
<% @site_valid_locales.each_with_index do |locale, i| %>
<li <%= ( i == 0 ) ? " class='active'" : '' %>><a data-toggle="tab" href=".<%= locale %>"><%= I18nVariable.from_locale(locale) %></a></li>
<% end %>
</ul>
<div class="tab_content form-horizontal">
<% @site_valid_locales.each_with_index do |locale, i| %>
<% if i == 0 %>
<div class="<%= locale %> fade tab-pane in active">
<% else %>
<div class="<%= locale %> fade tab-pane" >
<% end %>
<p class="control-group"><label class="control-label"><%= t("gallery.album_name") %></label><input type="text" id="name_<%= locale %>" /></p>
<p class="control-group"><label class="control-label"><%= t("gallery.album_desc") %></label><input type="text" id="desc_<%= locale %>" /></p>
</div>
<% end %>
<%= f.fields_for :name_translations do |name| %>
<% @site_valid_locales.each_with_index do |locale, i| %>
<% if i == 0 %>
<div class="<%= locale %> fade tab-pane in active">
<% else %>
<div class="<%= locale %> fade tab-pane" >
<% end %>
<p class="control-group">
<%= label_tag(locale, t("gallery.album_name")) %>
<%= name.text_field locale %>
</p>
</div>
<% end %>
<% end %>
<%= f.fields_for :description_translations do |desc| %>
<% @site_valid_locales.each_with_index do |locale, i| %>
<% if i == 0 %>
<div class="<%= locale %> fade tab-pane in active">
<% else %>
<div class="<%= locale %> fade tab-pane" >
<% end %>
<p class="control-group">
<%= label_tag(locale, t("gallery.album_desc")) %>
<%= desc.text_field locale %>
</p>
</div>
<% end %>
<% end %>
</div>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal" id="album_name_close_btn" onclick="return false;"><%= t("gallery.close") %></a>
<a href="#" class="btn btn-primary" id="album_name_save_btn" onclick="return false;"><%= t("gallery.save_changes") %></a>
<!-- <a href="#" class="btn btn-primary" id="album_name_save_btn" onclick="return false;"><%#= t("gallery.save_changes") %></a> -->
<%= f.submit t("gallery.save"), :class=> "btn btn-primary" %>
</div>
</div>
<% end %>
</div>

View File

@ -0,0 +1,13 @@
<div class="tag clear">
<div class="tagitem">
<i class="icon-folder-close"></i>
<% @site_valid_locales.each do |locale| %>
<span class="value" for="<%= locale %>"><%= category.name_translations[locale] rescue nil %> </span>
<% end %>
</div>
<div class="action">
<%= link_to(t("gallery.delete"), panel_gallery_back_end_gallery_category_path(category), :method => :delete, :confirm => t("gallery.sure?"), :remote => true, :class => "delete") %>
<%= link_to(t("gallery.edit"), edit_panel_gallery_back_end_gallery_category_path(category), :remote => true, :class => "edit") %>
<%= show_gallery_category_permission_link(category) %>
</div>
</div>

View File

@ -0,0 +1,2 @@
var dom = $("<%= j render :partial => 'category', :object => @category %>");
$("div#tags").append(dom);

View File

@ -0,0 +1,10 @@
<%= form_for @category, :url => panel_gallery_back_end_gallery_category_path(@category), :remote => true do |f| %>
<%= f.fields_for :name_translations do |name| %>
<% @site_valid_locales.each do |locale| %>
<%= label_tag(locale,t("gallery.new_category")+"["+I18nVariable.from_locale(locale)+"]") %>
<%= name.text_field locale, :value =>(@category.name_translations[locale]) %>
<% end %>
<% end %>
<%= f.submit t("gallery.save"), :class=> "btn btn-primary temp_save_btn" %>
<a href="#" class="btn btn-primary" id="temp_cancel_btn" onclick="return false;"><%= I18n.t("gallery.cancel") %></a>
<% end %>

View File

@ -1,89 +1,52 @@
<div id="tags" class="clear">
<% @categorylist.each do |category| %>
<div class="tag clear">
<div class="tagitem">
<i class="icon-folder-close"></i>
<% @site_valid_locales.each do |locale| %>
<span class="value" 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 %>
<%= render :partial => 'category', :collection => @categorylist %>
</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>
<%= form_for @new_category, :url => {:action => "create"}, :remote => true do |f| %>
<%= f.fields_for :name_translations do |name| %>
<% @site_valid_locales.each do |locale| %>
<%= label_tag(locale,t("gallery.new_category")+"["+I18nVariable.from_locale(locale)+"]") %>
<%= name.text_field locale %>
<% end %>
<% end %>
<%= f.submit t("gallery.save"), :class=> "btn btn-primary" %>
<% end %>
</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();})
})
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.value").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);
var parent;
var editCategory = function(a,data){
parent = a.parent().parent();
var parenthtml = parent.html();
var tempdom = $("<div class='tagitem'></div>");
tempdom.append(data);
parent.html(tempdom);
tempdom.find("a#temp_cancel_btn").click(function(){
parent.html(parenthtml);
})
}
$(document).ready(function(){
$("#tags div.action a.delete").click(function(){
$("#tags div.action a.delete").live('ajax:success', function(){
deleteCategory($(this));
})
$("#tags div.action a.edit").click(function(){
editCategory($(this));
$("#tags div.action a.edit").live('ajax:success',function(evt, data, status, xhr){
editCategory($(this),data);
})
$("#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("");
}
})
})
})
</script>
</script>

View File

@ -0,0 +1,2 @@
var dom = $("<%= j render :partial => 'category', :object => @category %>");
parent.html(dom.html());

View File

@ -30,3 +30,4 @@ en:
search_tags: Search Tags
cover: Album Cover
set_cover: Set as Album Cover
sure?: "Are you sure?"

View File

@ -14,7 +14,11 @@ Rails.application.routes.draw do
match "images_tags" => "albums#images_tags"
end
match "album_images/#!/:id" => "album_images#show"
resources :album_images
resources :gallery_categories
resources :tags