editing for the assets are done with replacable files and description

This commit is contained in:
Harry Bomrah 2013-09-10 12:45:10 +08:00 committed by saurabhbhatia
parent f920a4f6ba
commit 9e10a3c944
8 changed files with 65 additions and 97 deletions

View File

@ -32,12 +32,8 @@ class Admin::AssetsController < OrbitBackendController
def edit def edit
@asset = Asset.find(params[:id]) @asset = Asset.find(params[:id])
@asset_categories = AssetCategory.all
@tags = get_tags @tags = get_tags
respond_to do |format| render layout: false
format.html {}
format.js { render 'js/show_pop_up', :locals => {:partial => 'admin/assets/edit'} }
end
end end
def create def create
@ -74,10 +70,7 @@ class Admin::AssetsController < OrbitBackendController
def update def update
@asset = Asset.find(params[:id]) @asset = Asset.find(params[:id])
if @asset.update_attributes(params[:asset]) if @asset.update_attributes(params[:asset])
respond_to do |format| render layout: false
format.html { redirect_to admin_assets_url }
format.js { render 'js/remove_pop_up_and_reload_content', :locals => {:function => 'replaceWith', :id => "asset_#{@asset.id}", :value => @asset, :values => nil, :partial => 'admin/assets/asset', :locals => nil} }
end
else else
flash[:error] = t('update.fail') flash[:error] = t('update.fail')
@asset_categories = AssetCategory.all @asset_categories = AssetCategory.all

View File

@ -30,6 +30,6 @@
</div> </div>
</td> </td>
<td> <td>
<a href="#" class="editform">Edit</a> <a href="<%= edit_admin_asset_path(asset) %>" class="editform">Edit</a>
</td> </td>
</tr> </tr>

View File

@ -1,18 +1,15 @@
<div id='pop_up_content' class="main2"> <%= flash_messages %>
<h1><%= t('editing.asset') %></h1> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<%= flash_messages %> <h3><%= t('editing.asset') %></h3>
</div>
<%= form_for @asset, :url => admin_asset_path(@asset), :html => {:id => (is_html ? nil : 'ajaxForm'), :multipart => true } do |f| %> <%= form_for @asset, :url => admin_asset_path(@asset), :remote => true do |f| %>
<div class="modal-body" id="modal_body">
<%= f.error_messages %> <%= f.error_messages %>
<%= render :partial => "form", :locals => { :f => f } %> <%= render :partial => "form", :locals => { :f => f } %>
<div class="button_bar"> </div>
<% if is_html %> <div class="modal-footer">
<%= link_back %> <a href="#" class="btn" data-dismiss="modal">Close</a>
<%= f.submit t(:edit) %> <%= f.submit t('submit'), class: 'btn btn-primary' %>
<% else %> </div>
<a id='ajax_form_submit' class="btn btn-primary"><%= t(:update_) %></a> <% end %>
<% end %>
</div>
<% end %>
</div>

View File

@ -1,38 +1,46 @@
<div class="control-group"> <div class="control-group">
<label for="title" class="control-label"><%= t :title %></label> <ul class="nav nav-pills language-nav">
<div class="controls"> <% @site_valid_locales.each_with_index do |locale, i| %>
<%= f.fields_for :title_translations do |f| %> <li <%= ( i == 0 ) ? "class=active" : '' %>><a data-toggle="tab" href=".<%= locale %>"><%= I18nVariable.from_locale(locale) %></a></li>
<% @site_valid_locales.each do |locale| %> <% end %>
<%= content_tag :label do -%> </ul>
<div> <% @site_valid_locales.each_with_index do |locale, i| %>
<%= I18nVariable.from_locale(locale) %> <div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">
<%= f.text_field locale, :class => "input-large", :value => (@asset.title_translations[locale] rescue nil) %> <div class="control-group input-title">
<%= f.label :title , t('asset.title'), :class=>"control-label muted" %>
<div class="controls">
<%= f.fields_for :title_translations do |f| %>
<%= f.text_field locale, :class=>'post-title', :value => (@asset.title_translations[locale] rescue nil) %>
<% end %>
</div> </div>
<% end %> </div>
<% end %> <div class="control-group input-content">
<% end %> <%= f.label :description ,t('asset.description'), :class => "control-label muted" %>
</div> <%= f.fields_for :description_translations do |f| %>
<div class="controls">
<div class="textarea">
<%= f.text_area locale, :style=>"width:100%;height:100px", :class => '', :value => (@asset.description_translations[locale] rescue nil) %>
</div>
</div>
<% end %>
</div>
</div>
<% end %>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label"><%= f.label :category, t(:category) %></label> <label class="control-label muted">Tag</label>
<div class="controls"> <div class="controls" data-toggle="buttons-checkbox">
<%= f.select :asset_category_id, @asset_categories.collect{|t| [ t.title, t.id ]}, {}, :class => "input-large" %>
</div>
</div>
<div class="control-group">
<label class="control-label"><%= t :tags %></label>
<div class="controls">
<% @tags.each do |tag| %> <% @tags.each do |tag| %>
<%= content_tag :label, :class => "checkbox inline" do -%> <label class="checkbox inline btn <%= 'active' if @asset.tag_ids.include?(tag.id) %>">
<%= check_box_tag 'asset[tag_ids][]', tag.id, @asset.tag_ids.include?(tag.id) %> <%= check_box_tag 'asset[tag_ids][]', tag.id, @asset.tag_ids.include?(tag.id)%>
<%= tag.name %> <%= tag.name %>
<%= hidden_field_tag 'asset[tag_ids][]', '' %> </label>
<% end %>
<% end %> <% end %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label"><%= f.label :data, t(:data) %></label> <label class="control-label muted"><%= f.label :data, t(:data) %></label>
<div class="controls"> <div class="controls">
<%= f.file_field :data, :class => 'upload' %> <%= f.file_field :data, :class => 'upload' %>
</div> </div>

View File

@ -1,25 +0,0 @@
<% if !request.xhr? %>
<textarea>
<% end %>
var returnurl = "<%= @asset.data.url %>";
var returntitle = "<%= show_all_fields(@asset, 'title') %>";
var returndescription = "<%= show_all_fields(@asset, 'description') %>";
var win = tinyMCEPopup.getWindowArg("window");
win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = returnurl;
if(win.document.getElementById(tinyMCEPopup.getWindowArg("alt")))
win.document.getElementById(tinyMCEPopup.getWindowArg("alt")).value = returndescription;
win.document.getElementById(tinyMCEPopup.getWindowArg("title")).value = returntitle;
if (typeof(win.ImageDialog) != "undefined") {
// we are, so update image dimensions...
if (win.ImageDialog.getImageData)
win.ImageDialog.getImageData();
// ... and preview if necessary
if (win.ImageDialog.showPreviewImage)
win.ImageDialog.showPreviewImage(returnurl);
}
tinyMCEPopup.close();
<% if !request.xhr? %>
</textarea>
<% end %>

View File

@ -1,9 +1 @@
<% content_for :secondary do %>
<div class="assets_setup">
<ul class="list">
<li><%= link_to t('new.asset'), new_admin_asset_path, :remote => true, :class => 'button positive' %></li>
</ul>
</div>
<% end -%>
<%= render :partial => 'edit', :locals => {:is_html => true} %> <%= render :partial => 'edit', :locals => {:is_html => true} %>

View File

@ -302,17 +302,9 @@
</form> </form>
</div> </div>
<div id="editform" class="modal hide fade"> <div id="editform" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
<a href="#" class="btn btn-primary">Save changes</a>
</div>
</div> </div>
<% content_for :page_specific_javascript do %> <% content_for :page_specific_javascript do %>
@ -402,8 +394,18 @@ $(document).ready(function(){
deleteBtn.hide(); deleteBtn.hide();
}) })
}) })
var currentEdit = null;
$(document).on("ajax:success","form[data-remote=true]",function(evt, data, xhr){
currentEdit.replaceWith($(data));
$("#editform").modal("hide");
})
$("#asset_sort_list").on(clickEvent,".editform",function(){ $("#asset_sort_list").on(clickEvent,".editform",function(){
$("#editform").modal("show"); currentEdit = $(this).parent().parent();
$.get($(this).attr("href"),function(data){
$("#editform").html(data).modal("show");
})
return false;
}) })
function getUrlParam( paramName ) { function getUrlParam( paramName ) {

View File

@ -0,0 +1 @@
<%= render :partial => 'asset', :object => @asset %>