ruby update for form and edit tagging

This commit is contained in:
Harry Bomrah 2012-08-29 17:13:45 +08:00
parent a11d865dd1
commit 4e6703dae6
4 changed files with 47 additions and 28 deletions

View File

@ -127,7 +127,6 @@ var galleryAPI = function(){
var $img = $("<div class='rgalbum'><a title='"+album.description+"' href='"+album.show_path+"'><img src='../../../assets/gallery/default.jpg' width='120px' height='90px'/></a><span class='albumname'>"+album.name+"</span><span class='categoryname'>"+album.category_name+"</span><span class='tagnames'></span></div>"); var $img = $("<div class='rgalbum'><a title='"+album.description+"' href='"+album.show_path+"'><img src='../../../assets/gallery/default.jpg' width='120px' height='90px'/></a><span class='albumname'>"+album.name+"</span><span class='categoryname'>"+album.category_name+"</span><span class='tagnames'></span></div>");
else else
var $img = $("<div class='rgalbum'><a title='"+album.description+"' href='"+album.show_path+"'><img src='"+album.cover_path+"' width='120px' height='90px'/></a><span class='albumname'>"+album.name+"</span><span class='categoryname'>"+album.category_name+"</span><span class='tagnames'></span></div>"); var $img = $("<div class='rgalbum'><a title='"+album.description+"' href='"+album.show_path+"'><img src='"+album.cover_path+"' width='120px' height='90px'/></a><span class='albumname'>"+album.name+"</span><span class='categoryname'>"+album.category_name+"</span><span class='tagnames'></span></div>");
var tag_string = ""; var tag_string = "";
for(tag in album.tag_names){ for(tag in album.tag_names){
tag_string+= '<span class="label label-tags">' + album.tag_names[tag] + '</span>'; tag_string+= '<span class="label label-tags">' + album.tag_names[tag] + '</span>';
@ -294,12 +293,9 @@ var galleryAPI = function(){
} }
}) })
g.albumArea.find("#tag_panel .bt-save").click(function(){ g.albumArea.find("#tag_panel .bt-save").click(function(){
g.saveTags(imageArray[imagecount]._id,"pic") g.saveTags(imageArray[imagecount]._id,"pic",function(tagids){
var tagids = new Array(); imageArray[imagecount].tag_ids = tagids;
g.tagList.find("li input:checked").each(function(){
tagids.push($(this).parent().attr("data-content"));
}) })
imageArray[imagecount].tag_ids = tagids;
}) })
$(".slidectrl a.togglelist").click(function(){ $(".slidectrl a.togglelist").click(function(){
var rslide_h = $rslide.outerHeight(); var rslide_h = $rslide.outerHeight();
@ -493,6 +489,7 @@ var galleryAPI = function(){
}) })
var current_element_for_tags = null; var current_element_for_tags = null;
var current_element_no = null;
$('.bt-tag').click(function(){ $('.bt-tag').click(function(){
var has_class = false; var has_class = false;
if($(this).hasClass("active")) if($(this).hasClass("active"))
@ -527,11 +524,11 @@ var galleryAPI = function(){
current_element_for_tags = $(this).attr("href"); current_element_for_tags = $(this).attr("href");
if(count == 1){ if(count == 1){
var no = $(this).parent().attr("no"); current_element_no = $(this).parent().attr("no");
if(imageTagArray[no].id == current_element_for_tags){ if(imageTagArray[current_element_no].id == current_element_for_tags){
g.tagList.find("input").attr("checked",false); g.tagList.find("input").attr("checked",false);
for(tag in imageTagArray[no].tags){ for(tag in imageTagArray[current_element_no].tags){
g.tagList.find("li[data-content="+imageTagArray[no].tags[tag]+"] input").attr("checked",true); g.tagList.find("li[data-content="+imageTagArray[current_element_no].tags[tag]+"] input").attr("checked",true);
} }
} }
} }
@ -555,7 +552,9 @@ var galleryAPI = function(){
} }
}) })
g.albumArea.find("#tag_panel .bt-save").click(function(){ g.albumArea.find("#tag_panel .bt-save").click(function(){
g.saveTags(current_element_for_tags,"pic"); g.saveTags(current_element_for_tags,"pic",function(tagids){
imageTagArray[current_element_no].tags = tagids;
})
}) })
var tempval; var tempval;
$(".txtchange").focus(function(){ $(".txtchange").focus(function(){
@ -603,12 +602,15 @@ var galleryAPI = function(){
}) })
bindHandlers(); bindHandlers();
} }
this.saveTags = function(id,tagsfor){ this.saveTags = function(id,tagsfor,callbackFn){
var tagids = new Array(); var tagids = new Array();
g.tagList.find("li input:checked").each(function(){ g.tagList.find("li input:checked").each(function(){
tagids.push($(this).parent().attr("data-content")); tagids.push($(this).parent().attr("data-content"));
}) })
$.post("../save_tags",{"id":id,"tag":tagsfor,"tids":tagids}) $.post("../save_tags",{"id":id,"tag":tagsfor,"tids":tagids},function(){
if(typeof callbackFn == "function")
callbackFn.call(this,tagids);
})
} }
} }
galleryAPI.prototype.locale = "en"; galleryAPI.prototype.locale = "en";

View File

@ -168,6 +168,21 @@ include AdminHelper
end end
render :json=>tags.to_json render :json=>tags.to_json
end end
def update
debugger
@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
@tags = GalleryTag.all
render :action => :show
end
end end

View File

@ -23,21 +23,25 @@
<% end %> <% end %>
<div class="albumname_edit"> <div class="albumname_edit">
<label for=""><%= t("gallery.album_name") %></label> <%= f.fields_for :name_translations do |name| %>
<div class="inputui rginput rgih26 w380"><input type="text" name="gallery_album[name_translations][<%= locale %>]" value="<%= @album_name[locale] %>" class="txtchange" /></div> <%= f.label t("gallery.album_name") %>
<div class="inputui rginput rgih26 w380">
<%= name.text_field locale, :value => (@album_name[locale]), :class => "txtchange" %>
</div>
<% end %>
</div> </div>
<div class='description_loader'> <div class='description_loader'>
<% @images.each_with_index do |image,x| %> <% @images.each_with_index do |image,x| %>
<div class="rgphoto_edit <%= locale %>" data-content="<%= image.id %>"> <div class="rgphoto_edit <%= locale %>" data-content="<%= image.id %>">
<!-- <a href="<%= panel_gallery_back_end_album_images_path(image) %>"> -->
<%= link_to panel_gallery_back_end_album_image_path(image) do %> <%= link_to panel_gallery_back_end_album_image_path(image) do %>
<img src="<%= image.file.thumb.url %>" /> <img src="<%= image.file.thumb.url %>" />
<% end %> <% end %>
<div class="inputui rginput rgih98 w380"> <div class="inputui rginput rgih98 w380">
<%= f.fields_for :gallery_images do |j| %> <%= f.fields_for :gallery_images do |j| %>
<%= j.hidden_field :id, :value => (image.id) %>
<%= j.fields_for :description_translations do |desc| %> <%= j.fields_for :description_translations do |desc| %>
<%= desc.text_area locale, :value => (image.description_translations[locale] rescue nil ), :class => "txtchange" %> <%= desc.text_area locale, :value => (image.description_translations[locale] rescue nil), :class => "txtchange" %>
<% end %> <% end %>
<% end %> <% end %>
</div> </div>
@ -57,19 +61,15 @@
<% end %> <% end %>
<div class="form-actions form-fixed pagination-right rghead"> <div class="form-actions form-fixed pagination-right rghead">
<div class="rgfn"> <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 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> <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>
<input type="submit" class="bt-save icon-ok btn btn-primary pull-right" style="display:none;" value="Save" /><i class="icon-ok icon-white"></i> <%= f.submit t('gallery.save'), :class=>'bt-save icon-ok btn btn-primary pull-right', :style=>"display:none;" %>
</div> </div>
</div>
</div>
<!-- </form> -->
<% end %>
<script type="text/javascript">
$("form#edit_album input[name=authenticity_token]").val($('meta[name="csrf-token"]').attr("content"));
</script>
</div> </div>
</div> </div>
<% end %>
</div>
</div>
<!-- tag part --> <!-- tag part -->
<div id="tag_panel" class="my_scroll"> <div id="tag_panel" class="my_scroll">
<div class="scrollbar"> <div class="scrollbar">

View File

@ -5,6 +5,7 @@ Rails.application.routes.draw do
match "get_albums" => "albums#get_albums" match "get_albums" => "albums#get_albums"
match "upload_image" => "albums#upload_image" match "upload_image" => "albums#upload_image"
match "save_tags" => "tags#save_tags" match "save_tags" => "tags#save_tags"
match "albums/save_tags" => "tags#save_tags"
resources :albums do resources :albums do
match "set_cover" => "albums#set_cover" match "set_cover" => "albums#set_cover"
@ -16,6 +17,7 @@ Rails.application.routes.draw do
resources :album_images resources :album_images
resources :gallery_categories resources :gallery_categories
resources :tags resources :tags
end end
namespace :front_end do namespace :front_end do
match "orbit_galleries" => "orbit_galleries#index" match "orbit_galleries" => "orbit_galleries#index"