From 9e10a3c94476ceaa17d9de84b15f200a8b9589be Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 10 Sep 2013 12:45:10 +0800 Subject: [PATCH] editing for the assets are done with replacable files and description --- app/controllers/admin/assets_controller.rb | 11 +--- app/views/admin/assets/_asset.html.erb | 2 +- app/views/admin/assets/_edit.html.erb | 29 +++++------ app/views/admin/assets/_form.html.erb | 60 ++++++++++++---------- app/views/admin/assets/create.html.erb | 25 --------- app/views/admin/assets/edit.html.erb | 8 --- app/views/admin/assets/index.html.erb | 26 +++++----- app/views/admin/assets/update.html.erb | 1 + 8 files changed, 65 insertions(+), 97 deletions(-) delete mode 100644 app/views/admin/assets/create.html.erb create mode 100644 app/views/admin/assets/update.html.erb diff --git a/app/controllers/admin/assets_controller.rb b/app/controllers/admin/assets_controller.rb index 96f0e7b9..ef054a1d 100644 --- a/app/controllers/admin/assets_controller.rb +++ b/app/controllers/admin/assets_controller.rb @@ -32,12 +32,8 @@ class Admin::AssetsController < OrbitBackendController def edit @asset = Asset.find(params[:id]) - @asset_categories = AssetCategory.all @tags = get_tags - respond_to do |format| - format.html {} - format.js { render 'js/show_pop_up', :locals => {:partial => 'admin/assets/edit'} } - end + render layout: false end def create @@ -74,10 +70,7 @@ class Admin::AssetsController < OrbitBackendController def update @asset = Asset.find(params[:id]) if @asset.update_attributes(params[:asset]) - respond_to do |format| - 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 + render layout: false else flash[:error] = t('update.fail') @asset_categories = AssetCategory.all diff --git a/app/views/admin/assets/_asset.html.erb b/app/views/admin/assets/_asset.html.erb index 860d3993..b7c30fe9 100644 --- a/app/views/admin/assets/_asset.html.erb +++ b/app/views/admin/assets/_asset.html.erb @@ -30,6 +30,6 @@ - Edit + Edit \ No newline at end of file diff --git a/app/views/admin/assets/_edit.html.erb b/app/views/admin/assets/_edit.html.erb index 5e26e0f6..5924ea1f 100644 --- a/app/views/admin/assets/_edit.html.erb +++ b/app/views/admin/assets/_edit.html.erb @@ -1,18 +1,15 @@ -
-

<%= t('editing.asset') %>

- - <%= flash_messages %> - - <%= form_for @asset, :url => admin_asset_path(@asset), :html => {:id => (is_html ? nil : 'ajaxForm'), :multipart => true } do |f| %> +<%= flash_messages %> + +<%= form_for @asset, :url => admin_asset_path(@asset), :remote => true do |f| %> + \ No newline at end of file +
+ +<% end %> \ No newline at end of file diff --git a/app/views/admin/assets/_form.html.erb b/app/views/admin/assets/_form.html.erb index 32817f82..1e080678 100644 --- a/app/views/admin/assets/_form.html.erb +++ b/app/views/admin/assets/_form.html.erb @@ -1,38 +1,46 @@
- -
- <%= f.fields_for :title_translations do |f| %> - <% @site_valid_locales.each do |locale| %> - <%= content_tag :label do -%> -
- <%= I18nVariable.from_locale(locale) %> - <%= f.text_field locale, :class => "input-large", :value => (@asset.title_translations[locale] rescue nil) %> + + <% @site_valid_locales.each_with_index do |locale, i| %> +
"> +
+ <%= f.label :title , t('asset.title'), :class=>"control-label muted" %> +
+ <%= f.fields_for :title_translations do |f| %> + <%= f.text_field locale, :class=>'post-title', :value => (@asset.title_translations[locale] rescue nil) %> + <% end %>
- <% end %> - <% end %> - <% end %> -
+
+
+ <%= f.label :description ,t('asset.description'), :class => "control-label muted" %> + <%= f.fields_for :description_translations do |f| %> +
+
+ <%= f.text_area locale, :style=>"width:100%;height:100px", :class => '', :value => (@asset.description_translations[locale] rescue nil) %> +
+
+ <% end %> +
+
+ <% end %> +
- -
- <%= f.select :asset_category_id, @asset_categories.collect{|t| [ t.title, t.id ]}, {}, :class => "input-large" %> -
-
-
- -
+ +
<% @tags.each do |tag| %> - <%= content_tag :label, :class => "checkbox inline" do -%> - <%= check_box_tag 'asset[tag_ids][]', tag.id, @asset.tag_ids.include?(tag.id) %> + <% end %>
-
+
- +
<%= f.file_field :data, :class => 'upload' %>
diff --git a/app/views/admin/assets/create.html.erb b/app/views/admin/assets/create.html.erb deleted file mode 100644 index 81b112dc..00000000 --- a/app/views/admin/assets/create.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<% if !request.xhr? %> - -<% end %> \ No newline at end of file diff --git a/app/views/admin/assets/edit.html.erb b/app/views/admin/assets/edit.html.erb index b4b57fab..c4c33e4b 100644 --- a/app/views/admin/assets/edit.html.erb +++ b/app/views/admin/assets/edit.html.erb @@ -1,9 +1 @@ -<% content_for :secondary do %> -
-
    -
  • <%= link_to t('new.asset'), new_admin_asset_path, :remote => true, :class => 'button positive' %>
  • -
-
-<% end -%> - <%= render :partial => 'edit', :locals => {:is_html => true} %> \ No newline at end of file diff --git a/app/views/admin/assets/index.html.erb b/app/views/admin/assets/index.html.erb index 070c640d..fc373d2e 100644 --- a/app/views/admin/assets/index.html.erb +++ b/app/views/admin/assets/index.html.erb @@ -302,17 +302,9 @@
<% content_for :page_specific_javascript do %> @@ -402,8 +394,18 @@ $(document).ready(function(){ 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(){ - $("#editform").modal("show"); + currentEdit = $(this).parent().parent(); + $.get($(this).attr("href"),function(data){ + $("#editform").html(data).modal("show"); + }) + return false; }) function getUrlParam( paramName ) { diff --git a/app/views/admin/assets/update.html.erb b/app/views/admin/assets/update.html.erb new file mode 100644 index 00000000..9154b694 --- /dev/null +++ b/app/views/admin/assets/update.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'asset', :object => @asset %> \ No newline at end of file