announcement-test/app/views/admin/announcements/settings.html.erb

424 lines
17 KiB
Plaintext
Raw Normal View History

2020-05-19 04:31:57 +00:00
<%= stylesheet_link_tag "select2/select2" %>
<%= javascript_include_tag 'validator' %>
<%= javascript_include_tag "select2/select2.min" %>
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<% end %>
<style type="text/css">
#notification{
background-color: #ececec;
font-size: 14px;
left: 40%;
padding: 10px;
position: absolute;
text-align: center;
top: 40px;
width: auto;
z-index: 1200;
display: none;
}
.badge-info{
margin-left: 10px;
}
#approver-list{
list-style: none;
margin-left: 5px;
}
#approver-list li {
border-bottom: 1px solid #efefef;
margin-bottom: 10px;
padding-bottom: 10px;
}
#approver-list .approver-avatar{
width: 60px;
height: 60px;
border-radius: 50px;
margin-right: 20px;
}
#approver-list .approver-check{
vertical-align: middle;
margin-top: 25px;
}
#approver-list .approver-check input{
margin-right: 5px;
vertical-align: middle;
}
#approver-list .approver-check label{
display: inline;
vertical-align: middle;
}
#approver-list .approver-title{
font-size: 14px;
}
.table{
display: flex;
flex-direction: column;
}
.table-row,.role_limit_tr,.role_limit_add {
width: 100%;
display: inline-flex;
align-items: center;
margin-bottom: 0.5em;
}
.td{
width: 30%;
display: inline-flex;
justify-content: center;
}
.table{
border: #2d4cd0 0.1em solid;
}
.td-3{
width: 100%;
display: inline-flex;
justify-content: center;
}
.td>*{
max-width: 95%;
}
.td-delete{
width: 10%;
}
</style>
2016-09-02 02:45:05 +00:00
<%
sub_managers = @module_app.sub_managers
sub_managers.delete(nil)
all_statuses = [[t('top'),'is_top'],[t('hot'),'is_hot']]
tp1 = select_tag("announcement_setting[anns_status_settings][-1][status]",options_for_select(all_statuses))
tp2 = select_tag("announcement_setting[anns_status_settings][-1][role_id]",options_for_select(Role.all.map{|r| [r.title,r.id]}))
tp3 = number_field_tag("announcement_setting[anns_status_settings][-1][top_limit]",nil, min: 0,required: true)
tp4 = "<button type='button' onclick='delete_limit_role(this)'' class='btn'>#{t('delete_')}</button>"
all_tp = "<div class='role_limit_tr'><div class='td'>#{tp1}</div><div class='td'>#{tp2}</div><div class='td'>#{tp3}</div><div class='td-delete'>#{tp4}</div></div>"
2016-09-02 02:45:05 +00:00
%>
<script type="text/javascript">
function add_limit_role(){
var role_limit_l = $('.role_limit_tr').length
var role_limit_tp = '<%= all_tp.inspect %>'
role_limit_tp = role_limit_tp.replace(/-1/g,role_limit_l)
$('.role_limit_add').before($('<div/>').html(role_limit_tp).text().slice(1,-2))
}
function delete_limit_role(ele){
var now_index = $(ele).parents('.role_limit_tr').index('.role_limit_tr')
console.log(now_index)
$(ele).parents('.role_limit_tr').remove()
$('.role_limit_tr').each(function(i,v){
if (i >= now_index){
$(v).find('[name^="announcement_setting[anns_status_settings]"]').each(function(i1,v1){
console.log($(v1).attr('name'))
$(v1).attr('name',$(v1).attr('name').replace(/\d+/g,i.toString()))
})
}
})
}
2020-08-03 08:35:08 +00:00
$(document).ready(function(){
var approverList = $(".hidden-approver-list");
$(".approver-check input").on("click",function(){
var el = $(this);
if(el.is(":checked")){
var t = $("<input type='hidden'>");
t.val(el.val());
t.attr("name", "announcement_setting[approvers][]");
t.attr("id", "check_" + el.val());
approverList.append(t);
}else{
approverList.find("#check_" + el.val()).remove();
}
})
})
</script>
2018-01-19 09:05:26 +00:00
<div id="notification"><%= t("announcement.click_on_submit") %></div>
<%= form_for @setting, url: (@setting.new_record? ? admin_announcement_createsettings_path : admin_announcement_updatesettings_path), html: {class: "form-horizontal main-forms"} do |f| %>
<div class="input-area">
<div class="control-group">
<%= f.label :sub_annc_title_trans, t("announcement.default_sub_annc_title_trans"), :class => "control-label muted" %>
<div class="controls">
<div class="input-append">
<div class="tab-content">
<% @site_in_use_locales.each_with_index do |locale, i| %>
<div class="tab-pane fade <%= ( i == 0 ) ? "active in" : '' %>" id="sub_annc_title_trans_<%= locale %>">
<%= f.fields_for :sub_annc_title_trans_translations,f.object do |f| %>
<%= f.text_field locale, :value => f.object.get_sub_annc_title_trans(locale), :placeholder=>t("announcement.default_sub_annc_title_trans") %>
<% end %>
</div>
<% end %>
</div>
<div class="btn-group" data-toggle="buttons-radio">
<% @site_in_use_locales.each_with_index do |locale, i| %>
<a class="btn <%= ( i == 0 ) ? "active" : '' %>" href="#sub_annc_title_trans_<%= locale %>" data-toggle="tab"><%= t(locale.to_s) %></a>
<% end %>
</div>
</div>
</div>
</div>
<div class="control-group">
<%= f.label :carousel_image_type, t("announcement.default_carousel_image_type"), :class => "control-label muted" %>
<div class="controls">
<% carousel_image_types = ["carousel","album"] %>
<%= f.select :carousel_image_type, options_for_select(carousel_image_types.map.with_index{|type,i| [t("announcement.carousel_image_types.#{type}"),i]}.to_h,:selected => f.object.carousel_image_type) %>
</div>
</div>
<div class="control-group">
<%= f.label :carousel_image_width, t("announcement.default_carousel_image_width"), :class => "control-label muted" %>
<div class="controls">
<%= f.text_field :carousel_image_width %>
</div>
</div>
<div class="control-group">
<%= f.label :only_manager_can_edit_status, t("announcement.only_manager_can_edit_status"), :class => "control-label muted" %>
<div class="controls">
<%= f.check_box :only_manager_can_edit_status %>
</div>
</div>
<div class="control-group">
<%= f.label :is_display_edit_only, t("announcement.is_display_edit_only"), :class => "control-label muted" %>
<div class="controls">
<%= f.check_box :is_display_edit_only %>
</div>
</div>
<div class="control-group">
2018-01-19 09:05:26 +00:00
<%= f.label :top_limit, t("announcement.top_limit"), :class => "control-label muted" %>
<div class="controls">
<%= f.number_field :top_limit, :min => "0" %>
2018-01-19 09:05:26 +00:00
<span class="help-block"><%= t("announcement.for_unlimited") %></span>
</div>
</div>
<div class="control-group">
<div class="table">
<div class="table-row">
<div class="td">
<%= t('status') %>
</div>
<div class="td">
<%= t('role') %>
</div>
<div class="td">
<%= t('announcement.top_limit') %>
</div>
</div>
<% (AnnouncementSetting.first.anns_status_settings rescue []).each_with_index do |v,i| %>
<div class="role_limit_tr">
<%= hidden_field_tag("announcement_setting[anns_status_settings][#{i}][_id]",v.id) %>
<div class="td">
<%= select_tag("announcement_setting[anns_status_settings][#{i}][status]",options_for_select(all_statuses,:selected => v['status'])) %>
</div>
<div class="td">
<%= select_tag("announcement_setting[anns_status_settings][#{i}][role_id]",options_for_select(Role.all.map{|r| [r.title,r.id]},:selected => v['role_id'])) %>
</div>
<div class="td">
<%= number_field_tag("announcement_setting[anns_status_settings][#{i}][top_limit]",v['top_limit'], min: 0,required: true) %>
</div>
<div class="td-delete">
<button type="button" onclick="delete_limit_role(this)" class="btn">
<%= t('delete_') %>
</button>
</div>
</div>
<% end %>
<div class="role_limit_add">
<div class="td-3">
<button type="button" onclick="add_limit_role()" class="btn">
<%= t('add') %>
</button>
</div>
</div>
</div>
</div>
<% if AnnouncementSetting.is_pro? %>
<% if !sub_managers.blank? %>
<div class="control-group">
<%= f.label "Approver Setting", :class => "control-label muted" %>
<div class="controls">
<a href="#approverModal" role="button" class="btn" data-toggle="modal"><%= t("announcement.approvers_list") %></a>
<span class="badge badge-info"><%= @setting.approvers.count %></span>
</div>
</div>
<% else %>
<div class="control-group">
<a href="/admin/authorizations/announcement"><%= t("announcement.click_set_sub_manager") %></a>
</div>
<% end %>
<div class="control-group">
<%= f.label "Send emails to", :class => "control-label muted" %>
<div class="controls">
<input type="checkbox" name="announcement_setting[email_to][]" value="admins" <%= @setting.email_to.include?("admins") ? "checked=checked" : "" %>> <%= t("admin") %>
<input type="checkbox" name="announcement_setting[email_to][]" value="managers" <%= @setting.email_to.include?("managers") ? "checked=checked" : "" %>> <%= t("manager") %>
<input type="checkbox" name="announcement_setting[email_to][]" value="approvers" <%= @setting.email_to.include?("approvers") ? "checked=checked" : "" %>> <%= t("announcement.approver") %>
</div>
</div>
</div>
<div class="hidden-approver-list">
<% sub_managers.each do |sm| %>
<% if @setting.approvers.include?(sm.id.to_s) %>
<input type="hidden" id="check_<%= sm.id.to_s %>" value="<%= sm.id.to_s %>" name="announcement_setting[approvers][]">
<% end %>
<% end %>
</div>
<% end %>
<div class="form-actions">
<%= f.submit t('submit'), class: 'btn btn-primary' %>
</div>
<% end %>
2020-05-19 04:31:57 +00:00
</div>
<% if AnnouncementSetting.is_pro? %>
<div id="approverModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="approverModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
2018-01-19 09:05:26 +00:00
<h3 id="approverModalLabel"><%= t("sub_manager") %></h3>
</div>
<div class="modal-body">
<ul id="approver-list">
<% sub_managers.each do |sm| %>
<li>
<%= image_tag sm.member_profile.avatar.thumb, :class => "approver-avatar" %>
<span class="approver-title"><%= sm.name %></span>
<span class="pull-right approver-check">
<input id="checkbox_<%= sm.id %>" type="checkbox" value="<%= sm.id %>" <%= @setting.approvers.include?(sm.id.to_s) ? "checked=checked" : "" %>>
<label for="checkbox_<%= sm.id %>"><%= t("announcement.approver") %></label>
</span>
</li>
<% end %>
</ul>
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Ok</button>
</div>
</div>
<script type="text/javascript">
$("#approverModal").on("hidden",function(){
$("#notification").slideDown();
$(".badge-info").text($(".hidden-approver-list input").length);
})
</script>
<% end %>
2020-05-19 04:31:57 +00:00
<%= fields_for :iframe do |f| %>
<div class="form-horizontal input-area">
<fieldset id="iframe_settings">
<legend><%=t('announcement.announcement_setting_for_iframe')%></legend>
<div class="control-group">
<%= f.label :layout_type, t("announcement.layout_type"), :class => "control-label muted" %>
<div class="controls">
<% @layout_types = get_layouts(@module_app.key) %>
<% if @layout_types.first.kind_of?(Hash) %>
<select name="iframe[layout_type]" id="page_layout" class="select2">
<% @layout_types.each do |lt| %>
<option value="<%= lt["filename"] %>" data-image="<%= lt["thumbnail"] %>"><%= (lt["name"].kind_of?(Hash) ? (lt["name"][I18n.locale.to_s] || lt["name"]['en']) : lt["name"]) %></option>
<% end %>
</select>
<script type="text/javascript">
$("select.select2").select2({
formatResult: function(el){
var $element = $(el.element),
image = $element.data("image");
return "<img class='thumbnail' src='" + image + "'/><span class='thumbnail-text'>" + el.text + "</span>";
},
minimumResultsForSearch: -1,
width : 250
});
</script>
<% else %>
<%= f.select(:layout, @layout_types) %>
<% end %>
</div>
</div>
<div class="control-group">
<%= f.label :tags, t(:tags), :class => "control-label muted" %>
<div class="controls">
<% @module_app.tags.each_with_index do |t,index| %>
<label class="checkbox inline btn" for="<%="tags_#{index}"%>">
<input id="<%="tags_#{index}"%>" name="iframe[tags][]" type="checkbox" value="<%=t.id%>" style="opacity: 0;">
<%=t.name%>
</label>
<% end %>
</div>
</div>
<div class="control-group">
<label class="control-label muted" ><%=t(:categories)%></label>
<div class="controls">
<% @module_app.categories.each_with_index do |c,index| %>
<label class="checkbox inline btn" for="<%="categories_#{index}"%>">
<input id="<%="categories_#{index}"%>" name="iframe[categories][]" type="checkbox" value="<%=c.id%>" style="opacity: 0;">
<%=c.title%>
</label>
<% end %>
</div>
</div>
<div class="control-group">
<%= f.label :authors, t('announcement.table.author'), :class => "control-label muted" %>
<div class="controls">
<%= render partial: 'admin/members/generate_modal_select' , locals: { :@sorted_members => @sorted_members ,:member_form_id => "card-list-members",:member_field_name=>"iframe[member_ids][]" } %>
</div>
</div>
<div class="control-group">
<%= f.label :show_page, t('announcement.show_page'), :class => "control-label muted" %>
<div class="controls">
<%=f.check_box :show_page ,{:checked=>'checked'},'true','false'%>
</div>
</div>
<div class="control-group">
<%= f.label :data_count, t(:data_count), :class => "control-label muted" %>
<div class="controls">
<%=f.number_field :data_count, {min: 0,:value=> 10} %>
</div>
</div>
<div class="control-group">
<div class="controls">
<a class="btn btn-primary" title="<%= t("announcement.url_generate") %>" id="url_generate"><%= t("announcement.url_generate") %></a>
</div>
</div>
</fieldset>
</div>
<% end %>
<script type="text/javascript">
function getparams(id){
var params_array = $("#"+id).serializeArray();
var params = {};
params_array.forEach(function(dict){
if(params[dict.name] == undefined)
if(dict.name.substr(dict.name.length-2,2) == "[]")
params[dict.name] = [dict.value]
else
params[dict.name] = dict.value
else
if(dict.name.substr(dict.name.length-2,2) == "[]")
params[dict.name].push(dict.value)
else
params[dict.name] = dict.value
})
return params;
}
$(document).ready(function(){
$('label.checkbox input').click(function(){
if($(this).parent().hasClass('active'))
$(this).parent().removeClass('active');
else
$(this).parent().addClass('active');
})
$('#url_generate').off('click').on('click',function(){
var params = getparams('iframe_settings');
$.post("<%=admin_announcement_generate_iframe_url_path%>",params).done(function(url){
2020-05-19 08:15:14 +00:00
var real_url = '/annc_url?url='+window.location.href.split('/')[0]+"//"+window.location.host+url;
2020-05-19 04:31:57 +00:00
if($("#dialog-confirm").length == 0){
$("#url_generate").before("<div id='dialog-confirm' title='<%="iframe "+t('announcement.URL')%>'>"+
"<div style='clear:both;'></div><div id='info_texts'>"+"<label style='float:left;margin-right: 0.2em; line-height: 2em;' for='iframe_url'><%="iframe "+t('announcement.URL') %>:</label><input id= 'iframe_url' style='float:left;cursor:text;' type='text' readyonly value='"+real_url+"'><a class='btn btn-primary copy_text' style='color: white;'><%=t('announcement.copy')%></a>"+"</div>"+
"</div>");
}
$( "#dialog-confirm" ).dialog({
resizable: true,
minHeight: 100,
maxHeight: 400,
width: '80%',
modal: true,
buttons: {
"<%= t(:close) %>": function(){$( this ).dialog( "close" );}
}
});
$('.copy_text').off('click').on('click',function(){
var copyText = document.getElementById("iframe_url");
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
})
});
});
})
</script>