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>");
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 tag_string = "";
for(tag in album.tag_names){
tag_string+= '<span class="label label-tags">' + album.tag_names[tag] + '</span>';
@ -294,13 +293,10 @@ var galleryAPI = function(){
}
})
g.albumArea.find("#tag_panel .bt-save").click(function(){
g.saveTags(imageArray[imagecount]._id,"pic")
var tagids = new Array();
g.tagList.find("li input:checked").each(function(){
tagids.push($(this).parent().attr("data-content"));
})
g.saveTags(imageArray[imagecount]._id,"pic",function(tagids){
imageArray[imagecount].tag_ids = tagids;
})
})
$(".slidectrl a.togglelist").click(function(){
var rslide_h = $rslide.outerHeight();
if ( $slidelist.height() < 1 ){
@ -493,6 +489,7 @@ var galleryAPI = function(){
})
var current_element_for_tags = null;
var current_element_no = null;
$('.bt-tag').click(function(){
var has_class = false;
if($(this).hasClass("active"))
@ -527,11 +524,11 @@ var galleryAPI = function(){
current_element_for_tags = $(this).attr("href");
if(count == 1){
var no = $(this).parent().attr("no");
if(imageTagArray[no].id == current_element_for_tags){
current_element_no = $(this).parent().attr("no");
if(imageTagArray[current_element_no].id == current_element_for_tags){
g.tagList.find("input").attr("checked",false);
for(tag in imageTagArray[no].tags){
g.tagList.find("li[data-content="+imageTagArray[no].tags[tag]+"] input").attr("checked",true);
for(tag in imageTagArray[current_element_no].tags){
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.saveTags(current_element_for_tags,"pic");
g.saveTags(current_element_for_tags,"pic",function(tagids){
imageTagArray[current_element_no].tags = tagids;
})
})
var tempval;
$(".txtchange").focus(function(){
@ -603,12 +602,15 @@ var galleryAPI = function(){
})
bindHandlers();
}
this.saveTags = function(id,tagsfor){
this.saveTags = function(id,tagsfor,callbackFn){
var tagids = new Array();
g.tagList.find("li input:checked").each(function(){
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";

View File

@ -168,6 +168,21 @@ include AdminHelper
end
render :json=>tags.to_json
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

View File

@ -23,21 +23,25 @@
<% end %>
<div class="albumname_edit">
<label for=""><%= t("gallery.album_name") %></label>
<div class="inputui rginput rgih26 w380"><input type="text" name="gallery_album[name_translations][<%= locale %>]" value="<%= @album_name[locale] %>" class="txtchange" /></div>
<%= f.fields_for :name_translations do |name| %>
<%= 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 class='description_loader'>
<% @images.each_with_index do |image,x| %>
<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 %>
<img src="<%= image.file.thumb.url %>" />
<% end %>
<div class="inputui rginput rgih98 w380">
<%= f.fields_for :gallery_images do |j| %>
<%= j.hidden_field :id, :value => (image.id) %>
<%= 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 %>
</div>
@ -59,16 +63,12 @@
<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>
<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>
</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>
<!-- tag part -->
<div id="tag_panel" class="my_scroll">

View File

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