Add setForm and resetForm to pageslide.js

Category, AdBanner and Tag are using js to load the values in the form
This commit is contained in:
chris 2013-10-21 06:34:55 +08:00
parent 8e168b0fe1
commit f9f2232259
21 changed files with 167 additions and 71 deletions

View File

@ -1,5 +1,3 @@
//= require lib/arrow-on-list-edit
$(function() { $(function() {
$.pageslide.closeCallback(function(pageslide, item) { $.pageslide.closeCallback(function(pageslide, item) {
$("tr").removeClass("active"); $("tr").removeClass("active");
@ -8,14 +6,16 @@ $(function() {
$.pageslide.loadComplete(function(pageslide, item) { $.pageslide.loadComplete(function(pageslide, item) {
$("tr").removeClass("active"); $("tr").removeClass("active");
item.closest('tr').addClass('active'); item.closest('tr').addClass('active');
setSlideshow(pageslide.find('.preview'), item.data());
if(item.data('id') == 'new') { if(item.data('id') == 'new') {
resetForm();
pageslide.find('form').attr('action', '/admin/ad_banners/'); pageslide.find('form').attr('action', '/admin/ad_banners/');
pageslide.find('form').attr('method', 'post'); pageslide.find('form').attr('method', 'post');
} }
else { else {
setForm(item.data('form'));
pageslide.find('form').attr('action', '/admin/ad_banners/' + item.data('id')); pageslide.find('form').attr('action', '/admin/ad_banners/' + item.data('id'));
pageslide.find('form').attr('method', 'put'); pageslide.find('form').attr('method', 'put');
} }
setSlideshow(pageslide.find('.preview'), item.data());
}); });
}) })

View File

@ -1 +1,19 @@
//= require lib/arrow-on-list-edit $(function() {
$.pageslide.closeCallback(function(pageslide, item) {
$("tr").removeClass("active");
});
$.pageslide.loadComplete(function(pageslide, item) {
$("tr").removeClass("active");
item.closest('tr').addClass('active');
if(item.data('id') == 'new') {
resetForm();
pageslide.find('form').attr('action', '/admin/module_apps/' + item.data('module') + '/categories/');
pageslide.find('form').attr('method', 'post');
}
else {
setForm(item.data('form'));
pageslide.find('form').attr('action', '/admin/module_apps/' + item.data('module') + '/categories/' + item.data('id'));
pageslide.find('form').attr('method', 'put');
}
});
})

View File

@ -1 +1,18 @@
//= require admin/tags //= require lib/tags
$(function() {
$.pageslide.closeCallback(function(pageslide, item) {
$('.filter-item').removeClass("active");
});
$.pageslide.loadComplete(function(pageslide, item) {
$('.filter-item').removeClass("active");
item.closest('li').addClass('active');
if(item.hasClass('btn')) {
addTagsTab();
$('#filter-default-tag').fastLiveFilter('.add-default-tags-list', '.filter-item', '.tag');
$('.tags-groups').cardCheck({
item: '.card',
});
};
});
})

View File

@ -1 +1,21 @@
//= require lib/tags //= require lib/tags
$(function() {
$.pageslide.closeCallback(function(pageslide, item) {
$('.filter-item').removeClass("active");
});
$.pageslide.loadComplete(function(pageslide, item) {
$('.filter-item').removeClass("active");
item.closest('li').addClass('active');
if(item.data('id') == 'new') {
resetForm();
pageslide.find('form').attr('action', '/admin/tags/');
pageslide.find('form').attr('method', 'post');
}
else {
setForm(item.data('form'));
pageslide.find('form').attr('action', '/admin/tags/' + item.data('id'));
pageslide.find('form').attr('method', 'put');
}
});
})

View File

@ -540,7 +540,7 @@ function changeStatusHidden() {
// Document Ready // Document Ready
$(function() { $(function() {
new ini(); new ini();
$('.delete').on('click', function() { $('#main-wrap').on('click', '.delete', function() {
api.modal($(this).attr('rel')); api.modal($(this).attr('rel'));
}) })
initialState(); initialState();

View File

@ -8,26 +8,11 @@ function slideshow (element, bannerEffect, bannerTime, bannerSpeed) {
}); });
}; };
function setSlideshow(element, data) { function setSlideshow(element, data) {
bannerName = data.name; $("#pageslide .ad_banner_ad_fx").children('option:selected').each(function(index, el) {
bannerEffect = data.fx; $(this).val() == 'flipHorz' || $(this).val() == 'flipVert' ? $('.suckIE').show() : $('.suckIE').hide();
bannerTime = data.time;
bannerSpeed = data.speed;
bannerW = data.w;
bannerH = data.h;
$("#pageslide #bannerName").attr("value", bannerName);
$("#pageslide #timeout").attr("value", bannerTime);
$("#pageslide #speed").attr("value", bannerSpeed);
$("#pageslide #banner_width").attr("value", bannerW);
$("#pageslide #banner_height").attr("value", bannerH);
$("#pageslide .ad_banner_ad_fx option").each(function(i) {
if($(this).attr("value") == bannerEffect) {
this.selected = true;
$(this).hasClass('notIE') ? $('.suckIE').show() : $('.suckIE').hide();
}
}); });
element.cycle('destroy'); element.cycle('destroy');
slideshow(element, bannerEffect, 2000, 1000); slideshow(element, data['fx'], 2000, 1000);
} }
function preview() { function preview() {

View File

@ -1,9 +0,0 @@
$(function() {
$.pageslide.closeCallback(function(pageslide, item) {
$("tr").removeClass("active");
});
$.pageslide.loadComplete(function(pageslide, item) {
$("tr").removeClass("active");
item.closest('tr').addClass('active');
});
})

View File

@ -324,3 +324,31 @@
} }
}); });
}(window.jQuery); }(window.jQuery);
function setForm(data) {
$.each(data, function(key, value) {
switch($("#pageslide form #" + key).prop("tagName"))
{
case "INPUT":
$("#pageslide form #" + key).val(value);
break;
case "SELECT":
$("#pageslide form #" + key).val(value);
break;
}
});
}
function resetForm() {
$("#pageslide form").find("input[type=text], input[type=number], textarea")
.val("")
.end()
.find("select")
.prop('selectedIndex', 0)
.end()
.find("input[type=checkbox]")
.prop('checked', false)
.end()
.find("input[type=radio]")
.prop('checked', false);
}

View File

@ -197,7 +197,6 @@ function mergerTags() {
} }
$(function() { $(function() {
if($('.default-tags').length) { if($('.default-tags').length) {
// checkTagsQuantity();
checkedLength(); checkedLength();
$('#tags-merger').on('hidden', function () { $('#tags-merger').on('hidden', function () {
$(this).find('.filter-item').remove(); $(this).find('.filter-item').remove();
@ -205,18 +204,4 @@ $(function() {
} else { } else {
checkedLength(); checkedLength();
}; };
$.pageslide.closeCallback(function(pageslide, item) {
$('.filter-item').removeClass("active");
});
$.pageslide.loadComplete(function(pageslide, item) {
$('.filter-item').removeClass("active");
item.closest('li').addClass('active');
if(item.hasClass('btn')) {
addTagsTab();
$('#filter-default-tag').fastLiveFilter('.add-default-tags-list', '.filter-item', '.tag');
$('.tags-groups').cardCheck({
item: '.card',
});
};
});
}); });

View File

@ -31,7 +31,7 @@ class Admin::CategoriesController < OrbitBackendController
def update def update
@category = Category.find(params[:id]) @category = Category.find(params[:id])
if @category.update_attributes(params[:category]) if @category.update_attributes(params[:category])
redirect_to admin_module_app_categories_url(@module_app_id) redirect_to admin_module_app_categories_url(@module_app_id), :status => 303
else else
flash.now[:error] = t('update.error.category') flash.now[:error] = t('update.error.category')
render action: :edit render action: :edit

View File

@ -33,7 +33,7 @@ class Admin::TagsController < OrbitBackendController
def update def update
@tag = ModuleTag.find(params[:id]) @tag = ModuleTag.find(params[:id])
if @tag.update_attributes(params[:module_tag]) if @tag.update_attributes(params[:module_tag])
redirect_to action: :index redirect_to action: :index, :status => 303
else else
flash.now[:error] = t('update.error.tag') flash.now[:error] = t('update.error.tag')
render :action => "edit" render :action => "edit"

View File

@ -2,7 +2,7 @@
<%= f.error_messages %> <%= f.error_messages %>
<%= f.label :title, t('ad_banner.banner_name') %> <%= f.label :title, t('ad_banner.banner_name') %>
<%= f.text_field :title, class: 'input-large', placeholder: t('ad_banner.banner_name'), id: 'bannerName' %> <%= f.text_field :title, class: 'input-large', placeholder: t('ad_banner.banner_name'), id: 'name' %>
<span class="help-block"><%= t('ad_banner.name_only_english') %></span> <span class="help-block"><%= t('ad_banner.name_only_english') %></span>
<%= f.label :timeout, t('ad_banner.transition_interval') %> <%= f.label :timeout, t('ad_banner.transition_interval') %>
@ -15,12 +15,12 @@
<%= f.label :size, t('ad_banner.size') %> <%= f.label :size, t('ad_banner.size') %>
<span class="banner_set">W</span> <span class="banner_set">W</span>
<%= f.number_field :width, in: 10..1000, step: 10, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;", id: 'banner_width' %> <%= f.number_field :width, in: 10..1000, step: 10, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;", id: 'width' %>
<span class="banner_set">H</span> <span class="banner_set">H</span>
<%= f.number_field :height, in: 10..1000, step: 10, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;", id: 'banner_height' %> <%= f.number_field :height, in: 10..1000, step: 10, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;", id: 'height' %>
<%= f.label :ad_fx, t('ad_banner.effect') %> <%= f.label :ad_fx, t('ad_banner.effect') %>
<%= f.select :ad_fx, AdBanner::FX_TYPES, {}, {class: 'ad_banner_ad_fx'} %> <%= f.select :ad_fx, AdBanner::FX_TYPES, {}, {class: 'ad_banner_ad_fx', id: 'ad_fx'} %>
<p class="suckIE hide"><i class="icons-warning"></i> <%= t('ad_banner.no_ie_10_effect_support') %></p> <p class="suckIE hide"><i class="icons-warning"></i> <%= t('ad_banner.no_ie_10_effect_support') %></p>
<div class="preview"> <div class="preview">
<%= image_tag "slideshow_preview_A.png", width: 200, height: 80 %> <%= image_tag "slideshow_preview_A.png", width: 200, height: 80 %>

View File

@ -2,16 +2,20 @@
objects @ad_banners objects @ad_banners
quick_edit_link type: 'edit', quick_edit_link type: 'edit',
class: 'open-slide', class: 'open-slide',
data: "{" data: "{form: {"
.concat("title: t('ad_banner.edit_banner')") .concat("width: object.width")
.concat(", w: object.width") .concat(", height: object.height")
.concat(", h: object.height") .concat(", ad_fx: object.ad_fx")
.concat(", fx: object.ad_fx")
.concat(", id: object.id.to_s")
.concat(", name: object.title") .concat(", name: object.title")
.concat(", time: object.timeout") .concat(", timeout: object.timeout")
.concat(", speed: object.speed") .concat(", speed: object.speed")
.concat("}.to_json")
.concat(", title: t('ad_banner.edit_banner')")
.concat(", id: object.id.to_s")
.concat(", fx: object.ad_fx")
.concat("}") .concat("}")
# '{"#first":{"equal":"Yes"}}'
quick_edit_link type: 'detail' quick_edit_link type: 'detail'
quick_edit_link type: 'delete', quick_edit_link type: 'delete',
link: 'admin_ad_banner_path' link: 'admin_ad_banner_path'

View File

@ -6,8 +6,8 @@
<div class="quick-edit"> <div class="quick-edit">
<ul class="nav nav-pills"> <ul class="nav nav-pills">
<% if is_admin?%> <% if is_admin?%>
<li><%= link_to t(:edit), edit_admin_module_app_category_path(@module_app_id, category), class: "open-slide", data: {title: t(:edit_category)} %></li> <li><%= link_to t(:edit), '#', class: "open-slide", data: {title: t(:edit_category), id: category.id.to_s, module: @module_app_id.to_s, form: category.title_translations} %></li>
<li><%= link_to show_toggle_archive_btn(category) , toggle_admin_module_app_category_path(@module_app_id, category), method: :post, remote: true, class: "archive_toggle" %></li> <li><%= link_to show_toggle_archive_btn(category), toggle_admin_module_app_category_path(@module_app_id, category), method: :post, remote: true, class: "archive_toggle" %></li>
<% end %> <% end %>
<% if is_manager? || is_admin? %> <% if is_manager? || is_admin? %>
<li><%= link_to t(:category_auth), admin_authorizations_path(@module_app.key, 'category_authorization', category.id) %></li> <li><%= link_to t(:category_auth), admin_authorizations_path(@module_app.key, 'category_authorization', category.id) %></li>

View File

@ -4,6 +4,6 @@
<%= f.fields_for :title_translations do |f| %> <%= f.fields_for :title_translations do |f| %>
<% @site_valid_locales.each do |locale| %> <% @site_valid_locales.each do |locale| %>
<%= label_tag "name-#{locale}", "#{t(:name)} (#{I18nVariable.from_locale(locale)})" %> <%= label_tag "name-#{locale}", "#{t(:name)} (#{I18nVariable.from_locale(locale)})" %>
<%= f.text_field locale, :class => 'input-large', :value => (@category.title_translations[locale] rescue ''), placeholder: t(:name) %> <%= f.text_field locale, :class => 'input-large', :value => (@category.title_translations[locale] rescue ''), placeholder: t(:name), id: locale %>
<% end %> <% end %>
<% end %> <% end %>

View File

@ -13,7 +13,7 @@
<div class="bottomnav clearfix"> <div class="bottomnav clearfix">
<div class="action pull-right"> <div class="action pull-right">
<%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_module_app_category_path(@module_app_id), class: "btn btn-primary open-slide", data: {title: t(:add_category)} %> <%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), '#', class: "btn btn-primary open-slide", data: {title: t(:add_category), id: 'new', module: @module_app_id.to_s } %>
</div> </div>
<div class="pagination pagination-centered"> <div class="pagination pagination-centered">
<%= paginate @categories unless @categories.blank? %> <%= paginate @categories unless @categories.blank? %>

View File

@ -1,3 +1,27 @@
<div id="categories_index"> <div id="categories_index">
<%= render 'index' %> <%= render 'index' %>
</div> </div>
<div id="pageslide">
<div class="page-title clearfix">
<a class="pull-right" href="javascript:$.pageslide.close()">
<i class="icons-arrow-left-2"></i>
</a>
<span></span>
</div>
<div class="view-page">
<div class="nano">
<div class="content">
<%= form_for :category, url: nil, remote: true do |f| %>
<fieldset>
<%= render :partial => "form", :locals => { :f => f } %>
<div class="form-actions">
<a href="javascript:$.pageslide.close()" class="btn btn-small"><%= t(:cancel) %></a>
<%= f.submit t(:submit), class: 'btn btn-primary btn-small' %>
</div>
</fieldset>
<% end %>
</div>
</div>
</div>
</div>

View File

@ -4,6 +4,6 @@
<%= f.fields_for :name_translations do |f| %> <%= f.fields_for :name_translations do |f| %>
<% @site_valid_locales.each do |locale| %> <% @site_valid_locales.each do |locale| %>
<%= f.label :locale, "#{t(:name)} #{I18nVariable.from_locale(locale)}" %> <%= f.label :locale, "#{t(:name)} #{I18nVariable.from_locale(locale)}" %>
<%= f.text_field locale, class: 'input-large', placeholder: "#{t(:name)} #{I18nVariable.from_locale(locale)}", value: (@tag.name_translations[locale] rescue nil) %> <%= f.text_field locale, class: 'input-large', placeholder: "#{t(:name)} #{I18nVariable.from_locale(locale)}", value: (@tag.name_translations[locale] rescue nil), id: locale %>
<% end %> <% end %>
<% end %> <% end %>

View File

@ -6,7 +6,7 @@
<%= link_to t(:delete), '#', id: "deleteTags", class: "btn btn-danger toggable hide", rel: '' %> <%= link_to t(:delete), '#', id: "deleteTags", class: "btn btn-danger toggable hide", rel: '' %>
<%= link_to t(:merge), '#', id: "mergerTags", class: "btn btn-success toggable hide", rel: merge_admin_tags_path %> <%= link_to t(:merge), '#', id: "mergerTags", class: "btn btn-success toggable hide", rel: merge_admin_tags_path %>
<%= link_to t(:add_to_default), add_to_default_admin_tags_path, id: "addDefault", class: "btn btn-info toggable hide", method: :post, remote: true %> <%= link_to t(:add_to_default), add_to_default_admin_tags_path, id: "addDefault", class: "btn btn-info toggable hide", method: :post, remote: true %>
<%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_tag_path, class: "btn btn-primary open-slide", data: {title: t('new.tag')} %> <%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), '#', class: "btn btn-primary open-slide", data: {title: t('new.tag'), id: 'new'} %>
</div> </div>
</div> </div>
<!-- footer:end --> <!-- footer:end -->

View File

@ -11,7 +11,7 @@
<%= show_names_slash(tag) %> <%= show_names_slash(tag) %>
</a> </a>
<% else %> <% else %>
<%= link_to edit_admin_tag_path(tag), class: "open-slide", data: {title: t('editing.tag')} do %> <%= link_to '#', class: "open-slide", data: {title: t('editing.tag'), id: tag.id.to_s, form: tag.name_translations} do %>
<span class="amount"><%= get_tagging_count(tag) %></span> <span class="amount"><%= get_tagging_count(tag) %></span>
<%= show_names_slash(tag) %> <%= show_names_slash(tag) %>
<% end %> <% end %>

View File

@ -7,3 +7,27 @@
<div id="tags_index"> <div id="tags_index">
<%= render 'index' %> <%= render 'index' %>
</div> </div>
<div id="pageslide">
<div class="page-title clearfix">
<a class="pull-right" href="javascript:$.pageslide.close()">
<i class="icons-arrow-left-2"></i>
</a>
<span></span>
</div>
<div class="view-page">
<div class="nano">
<div class="content">
<%= form_for :module_tag, url: nil, remote: true do |f| %>
<fieldset>
<%= render :partial => "form", :locals => { :f => f } %>
<div class="form-actions">
<a href="javascript:$.pageslide.close()" class="btn btn-small"><%= t(:cancel) %></a>
<%= f.submit t(:submit), class: 'btn btn-primary btn-small' %>
</div>
</fieldset>
<% end %>
</div>
</div>
</div>
</div>