add custom field feature and fix some error
This commit is contained in:
parent
262a78f602
commit
f3bd5f4941
|
@ -0,0 +1,400 @@
|
|||
/*
|
||||
Month and Year picker for jQuery UI Datepicker 1.8.21
|
||||
|
||||
Written by Anton Ludescher (silverskater{at}gmail.com).
|
||||
Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and
|
||||
MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. */
|
||||
|
||||
if (datepicker == undefined){
|
||||
var datepicker_fn = $.fn.datepicker
|
||||
var datepicker = $.datepicker
|
||||
}
|
||||
(function($, undefined ) {
|
||||
|
||||
//overriding functions meant to be private (starting with an underscore)
|
||||
$.ui_datepicker = datepicker
|
||||
$.fn.ui_datepicker = datepicker_fn
|
||||
$.ui_datepicker._updateDatepicker_MonthYearPicker = $.ui_datepicker._updateDatepicker;
|
||||
$.ui_datepicker._showDatepicker_MonthYearPicker = $.ui_datepicker._showDatepicker;
|
||||
$.ui_datepicker._doKeyDown_MonthYearPicker = $.ui_datepicker._doKeyDown;
|
||||
|
||||
$.extend($.ui_datepicker, {
|
||||
_doKeyDown: function(event) {
|
||||
var inst = $.ui_datepicker._getInst(event.target);
|
||||
var handled = true;
|
||||
//var isRTL = inst.dpDiv.is('.ui-datepicker-rtl');
|
||||
inst._keyEvent = true;
|
||||
if ($.ui_datepicker._datepickerShowing) {
|
||||
switch (event.keyCode) {
|
||||
case 27:
|
||||
if($('.ui-datepicker-select-month').is(':visible')) {
|
||||
$.ui_datepicker._updateDatepicker(inst);
|
||||
}
|
||||
else if($('.ui-datepicker-select-year').is(':visible')) {
|
||||
$.ui_datepicker._toggleDisplay_MonthYearPicker(inst, 2, this);
|
||||
}
|
||||
else {
|
||||
$.ui_datepicker._hideDatepicker();
|
||||
}
|
||||
break; // hide on escape
|
||||
//TODO prev/next month/year on month/year picker screens
|
||||
default:
|
||||
//call the original function
|
||||
$.ui_datepicker._doKeyDown_MonthYearPicker(event);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//call the original function
|
||||
$.ui_datepicker._doKeyDown_MonthYearPicker(event);
|
||||
}
|
||||
},
|
||||
|
||||
_updateDatepicker: function(inst) {
|
||||
//call the original function
|
||||
if (this._get(inst, 'show_view') == 'year' && !$('.ui-datepicker-select-year').is(':visible')){
|
||||
var current_format = this._get(inst, 'dateFormat')
|
||||
var regex = /\W/, indice = 0;
|
||||
var result = current_format.split(/\W/)
|
||||
for (var i=0;i<result.length;i++)
|
||||
{
|
||||
if (result[i] != '' && result[i].toLowerCase().replace(/y/g,'')==''){
|
||||
indice = i
|
||||
break
|
||||
}
|
||||
}
|
||||
var current_year = inst.input.val().split(/\W/)[indice];
|
||||
if (current_year != '' && current_year != undefined){
|
||||
inst.selectedYear = parseInt(current_year)
|
||||
inst.drawYear = parseInt(current_year)
|
||||
}
|
||||
}
|
||||
else if (this._get(inst, 'show_view') == 'month' && !$('.ui-datepicker-select-month').is(':visible')){
|
||||
var current_format = this._get(inst, 'dateFormat')
|
||||
var regex = /\W/, indice_y = 0,indice_m = 0;
|
||||
var result = current_format.split(/\W/)
|
||||
for (var i=0;i<result.length;i++)
|
||||
{
|
||||
if (result[i] !== '' && result[i].toLowerCase().replace(/y/g,'')===''){
|
||||
indice_y = i
|
||||
}
|
||||
else if (result[i] !== '' && result[i].toLowerCase().replace(/m/g,'')===''){
|
||||
indice_m = i
|
||||
}
|
||||
}
|
||||
var current_array = inst.input.val().split(/\W/)
|
||||
var current_year = current_array[indice_y];
|
||||
var current_month = current_array[indice_m];
|
||||
if (current_year != '' && current_year !== undefined){
|
||||
inst.selectedYear = parseInt(current_year)
|
||||
inst.drawYear = parseInt(current_year)
|
||||
}
|
||||
if (current_month != '' && current_month !== undefined){
|
||||
inst.selectedMonth = parseInt(current_month) - 1
|
||||
inst.drawMonth = parseInt(current_month) - 1
|
||||
}
|
||||
}
|
||||
this._updateDatepicker_MonthYearPicker(inst);
|
||||
//TODO: multiMonth
|
||||
var numMonths = this._getNumberOfMonths(inst);
|
||||
var isMultiMonth = (numMonths[0] != 1 || numMonths[1] != 1);
|
||||
var changeMonth = this._get(inst, 'changeMonth');
|
||||
var changeYear = this._get(inst, 'changeYear');
|
||||
if(isMultiMonth || changeMonth || changeYear ) {
|
||||
return ;
|
||||
}
|
||||
|
||||
//console.log($('<div>').append(this.dpDiv.clone()).html());
|
||||
|
||||
var uidptitle = inst.dpDiv.find('.ui-datepicker-title');
|
||||
var uidptitle_link = uidptitle.wrapInner('<a href="#"/>');
|
||||
uidptitle_link.click(function(){$.ui_datepicker.select_month = false;$.ui_datepicker._toggleDisplay_MonthYearPicker('#' + inst.id, 2); return false;});
|
||||
inst.dpDiv.children('table.ui-datepicker-calendar').after(this._generateExtraHTML_MonthYearPicker(inst));
|
||||
if (!$('.ui-datepicker-select-year').is(':visible') && !$('.ui-datepicker-select-month').is(':visible')){
|
||||
if (this._get(inst, 'show_view') == 'month')
|
||||
{
|
||||
this._toggleDisplay_MonthYearPicker('#' + inst.id,2)
|
||||
}else if (this._get(inst, 'show_view') == 'year'){
|
||||
this._toggleDisplay_MonthYearPicker('#' + inst.id,3)
|
||||
}
|
||||
}
|
||||
this._reposition_MonthYearPicker(inst);
|
||||
},
|
||||
|
||||
//focus the date input field
|
||||
_instInputFocus_MYP: function(inst) {
|
||||
//code copied from datePicker's _updateDatepicker()
|
||||
if (inst == $.ui_datepicker._curInst && $.ui_datepicker._datepickerShowing && inst.input &&
|
||||
// #6694 - don't focus the input if it's already focused
|
||||
// this breaks the change event in IE
|
||||
inst.input.is(':visible') && !inst.input.is(':disabled') && inst.input[0] != document.activeElement)
|
||||
inst.input.focus();
|
||||
|
||||
},
|
||||
|
||||
_generateMonthPickerHTML_MonthYearPicker: function(inst, minDate, maxDate, drawMonth, inMinYear, inMaxYear) {
|
||||
//TODO RTL?
|
||||
var monthNamesShort = this._get(inst, 'monthNamesShort');
|
||||
|
||||
var monthPicker = '<table><tbody><tr>';
|
||||
|
||||
var unselectable = false;
|
||||
for (var month = 0; month < 12; ) {
|
||||
unselectable = (inMinYear && month < minDate.getMonth()) ||
|
||||
(inMaxYear && month > maxDate.getMonth());
|
||||
monthPicker += '<td class="' +
|
||||
(unselectable ? ' ' + this._unselectableClass + ' ui-state-disabled': '') + // highlight unselectable months
|
||||
(month == drawMonth ? ' ui-datepicker-today' : '') + '"' +
|
||||
(unselectable ? '' : ' onclick="$.ui_datepicker.select_month = true;jQuery.ui_datepicker._pickMonthYear_MonthYearPicker(\'#' + inst.id + '\', ' + month + ', \'M\');return false;"') + '>' + // actions
|
||||
((unselectable ? '<span class="ui-state-default">' + monthNamesShort[month] + '</span>' : '<a class="ui-state-default ' +
|
||||
//(month == drawMonth ? ' ui-state-highlight' : '') +
|
||||
(month == drawMonth ? ' ui-state-active' : '') + // highlight selected day
|
||||
//(otherMonth ? ' ui-priority-secondary' : '') + // distinguish dates from other months
|
||||
'" href="#">' + monthNamesShort[month] + '</a>')) + '</td>'; // display selectable date
|
||||
|
||||
if(++month % 4 === 0) {
|
||||
monthPicker += '</tr>';
|
||||
if(month != 12) {
|
||||
monthPicker += '<tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
monthPicker += '</tbody></table>';
|
||||
|
||||
return monthPicker;
|
||||
},
|
||||
|
||||
_generateExtraHTML_MonthYearPicker: function(inst,show_view) {
|
||||
if (show_view != 'year'){
|
||||
var minDate = this._getMinMaxDate(inst, 'min');
|
||||
var maxDate = this._getMinMaxDate(inst, 'max');
|
||||
var drawYear = inst.drawYear;
|
||||
var drawMonth = inst.drawMonth;
|
||||
var inMinYear = (minDate && minDate.getFullYear() == drawYear);
|
||||
var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
|
||||
var monthPicker = this._generateMonthPickerHTML_MonthYearPicker(inst, minDate, maxDate, drawMonth, inMinYear, inMaxYear);
|
||||
if (show_view != 'month'){
|
||||
return '<div class="ui-datepicker-select-month" style="display: none">' + monthPicker + '</div>' +
|
||||
'<div class="ui-datepicker-select-year" style="display: none"></div>'; //yearPicker gets filled dinamically
|
||||
}
|
||||
else{
|
||||
return '<div class="ui-datepicker-select-month" style="display: block">' + monthPicker + '</div>' +
|
||||
'<div class="ui-datepicker-select-year" style="display: none"></div>';
|
||||
}
|
||||
}
|
||||
else{
|
||||
return '<div class="ui-datepicker-select-month" style="display: none">' + monthPicker + '</div>' +
|
||||
'<div class="ui-datepicker-select-year" style="display: block"></div>';
|
||||
}
|
||||
},
|
||||
|
||||
_pickMonthYear_MonthYearPicker: function(id, valueMY, period) {
|
||||
var dummySelect = $('<select/>').append( new Option(valueMY, valueMY, true, true) );
|
||||
//select month and show datepicker or select year ...
|
||||
this._selectMonthYear(id, dummySelect[0], period);
|
||||
//... and show month picker
|
||||
if(period == 'Y' && valueMY != undefined) {
|
||||
var target = $(id);
|
||||
var inst = this._getInst(target[0]);
|
||||
inst.selectedYear = valueMY
|
||||
inst.drawYear = valueMY
|
||||
this._toggleDisplay_MonthYearPicker(id, 2);
|
||||
}
|
||||
},
|
||||
|
||||
_reposition_MonthYearPicker: function (inst) {
|
||||
if (inst.inline) {
|
||||
return;
|
||||
}
|
||||
inst.dpDiv.position({
|
||||
my: "left top",
|
||||
at: "left bottom",
|
||||
of: $(inst.input)
|
||||
});
|
||||
},
|
||||
|
||||
_addHoverEvents_MonthYearPicker: function (parent) {
|
||||
var dpMonths = parent.find('.ui-state-default');
|
||||
dpMonths.hover(
|
||||
function () {
|
||||
$(this).addClass('ui-state-hover');
|
||||
},
|
||||
function () {
|
||||
$(this).removeClass("ui-state-hover");
|
||||
});
|
||||
},
|
||||
|
||||
_toggleDisplay_MonthYearPicker: function(inst, screen, input) {
|
||||
if(typeof inst == 'string') {
|
||||
//var inst = this._curInst;
|
||||
var target = $(inst);
|
||||
inst = this._getInst(target[0]);
|
||||
}
|
||||
else {
|
||||
//get the input element and put it in the target array
|
||||
var target = [ input !== undefined
|
||||
? input
|
||||
: instActive.inline ? dpDiv.parent()[0] : instActive.input[0]];
|
||||
}
|
||||
if (this._isDisabledDatepicker(target[0])) {
|
||||
return;
|
||||
}
|
||||
//keep the focus for _doKeyDown to work
|
||||
this._instInputFocus_MYP(inst);
|
||||
|
||||
var minDate = this._getMinMaxDate(inst, 'min');
|
||||
var maxDate = this._getMinMaxDate(inst, 'max');
|
||||
var drawYear = inst.drawYear; //inst.drawYear = inst.selectedYear = inst.currentYear
|
||||
var drawMonth = inst.drawMonth;
|
||||
var minYear = minDate ? minDate.getFullYear() : 0; //TODO
|
||||
var maxYear = maxDate ? maxDate.getFullYear() : undefined;
|
||||
var dpHeader = inst.dpDiv.children('.ui-datepicker-header');
|
||||
var dpPrev = dpHeader.children('a.ui-datepicker-prev');
|
||||
var dpNext = dpHeader.children('a.ui-datepicker-next');
|
||||
var dpTitle = dpHeader.children('.ui-datepicker-title');
|
||||
|
||||
var self = this;
|
||||
|
||||
switch (screen) {
|
||||
case 2:
|
||||
if (self._get(inst, 'show_view') != 'year'){
|
||||
//month picker
|
||||
var inMinYear = (minYear !== undefined && minYear == drawYear);
|
||||
var inMaxYear = (maxYear !== undefined && maxYear == drawYear);
|
||||
var _advanceYear_MYP = function(diff) {
|
||||
inst.drawYear = (drawYear += diff);
|
||||
inst.selectedYear = drawYear;
|
||||
dpTitle.children(':first').text(drawYear);
|
||||
//update screen
|
||||
if(minDate || maxDate) {
|
||||
inMinYear = minYear == drawYear;
|
||||
inMaxYear = maxYear == drawYear;
|
||||
//update month selection
|
||||
var monthPicker = self._generateMonthPickerHTML_MonthYearPicker(inst, minDate, maxDate, drawMonth, inMinYear, inMaxYear);
|
||||
inst.dpDiv.children('.ui-datepicker-select-month').html(monthPicker);
|
||||
}
|
||||
_updatePrevNextYear_MYP();
|
||||
};
|
||||
var _updatePrevNextYear_MYP = function() {
|
||||
dpPrev.unbind('click');
|
||||
if(!inMinYear) {
|
||||
dpPrev.removeClass('ui-state-disabled').click(function() {_advanceYear_MYP(-1); self._instInputFocus_MYP(inst);});
|
||||
}
|
||||
else {
|
||||
dpPrev.addClass('ui-state-disabled');
|
||||
}
|
||||
dpNext.unbind('click');
|
||||
if(!inMaxYear) {
|
||||
dpNext.removeClass('ui-state-disabled').click(function() {_advanceYear_MYP(1); self._instInputFocus_MYP(inst);});
|
||||
}
|
||||
else {
|
||||
dpNext.addClass('ui-state-disabled');
|
||||
}
|
||||
};
|
||||
//change title link behaviour
|
||||
dpTitle.html('<a href="#" class="ui-datepicker-yearpicker" onclick="jQuery.ui_datepicker._toggleDisplay_MonthYearPicker(\''+'#' + inst.id +'\', 3);return false;">' + drawYear +'</a>');
|
||||
//change prev next behaviour
|
||||
dpPrev.removeAttr('onclick'); //remove DatePicker's onclick event
|
||||
dpNext.removeAttr('onclick'); //remove DatePicker's onclick event
|
||||
_updatePrevNextYear_MYP();
|
||||
|
||||
var dpMonthSelector = inst.dpDiv.find('.ui-datepicker-select-month table');
|
||||
this._addHoverEvents_MonthYearPicker(dpMonthSelector);
|
||||
if ($.ui_datepicker.select_month != false && self._get(inst, 'show_view') == 'month' && inst.selectedDay != undefined && inst.selectedMonth != undefined && inst.selectedYear != undefined){
|
||||
var dateStr = self._formatDate( inst,inst.selectedDay, inst.selectedMonth, inst.selectedYear )
|
||||
inst.input.val( dateStr );
|
||||
self._hideDatepicker()
|
||||
}
|
||||
inst.dpDiv.find('table.ui-datepicker-calendar').hide();
|
||||
inst.dpDiv.find('.ui-datepicker-select-month').show();
|
||||
inst.dpDiv.find('.ui-datepicker-select-year').hide();
|
||||
this._reposition_MonthYearPicker(inst);
|
||||
}
|
||||
else{
|
||||
var dateStr = self._formatDate( inst,inst.selectedDay, inst.selectedMonth, inst.selectedYear )
|
||||
inst.input.val( dateStr );
|
||||
self._hideDatepicker()
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
//year picker
|
||||
var year = parseInt(drawYear/10, 10) * 10; //first year in this decade
|
||||
//change title link behaviour
|
||||
dpTitle.unbind('click');
|
||||
//change prev next behaviour
|
||||
$.backToActualMonth = function() {
|
||||
//var d = new Date();
|
||||
//var month = d.getMonth()+1;
|
||||
$.ui_datepicker._pickMonthYear_MonthYearPicker('#'+inst.id,drawMonth,'M');
|
||||
return false;
|
||||
};
|
||||
var _updateYearPicker_MYP = function(year) {
|
||||
//TODO RTL
|
||||
//change title html
|
||||
dpTitle.html('<a class="ui-datepicker-title" '+
|
||||
'onclick="$.ui_datepicker.select_month = false;return $.backToActualMonth();" '+
|
||||
'href="#">'+ year + '-' + (year + 9) + '</a>');
|
||||
//change prev next behaviour
|
||||
dpPrev.unbind('click');
|
||||
dpNext.unbind('click');
|
||||
if(year > minYear) {
|
||||
dpPrev.removeClass('ui-state-disabled').click(function() {_updateYearPicker_MYP(year-21); self._instInputFocus_MYP(inst);}); //year is 2021 at this point
|
||||
}
|
||||
else {
|
||||
dpPrev.addClass('ui-state-disabled');
|
||||
}
|
||||
if(maxYear === undefined || year+9 < maxYear) {
|
||||
dpNext.removeClass('ui-state-disabled').click(function() {_updateYearPicker_MYP(year-1); self._instInputFocus_MYP(inst);});
|
||||
}
|
||||
else {
|
||||
dpNext.addClass('ui-state-disabled');
|
||||
}
|
||||
|
||||
//generate year picker HTML
|
||||
var yearPicker = '<table><tbody><tr>';
|
||||
//show years in 4x3 matrix (2009-2020)
|
||||
year--; //last year of the previous decade (2009)
|
||||
for (var i = 1; i <= 12; i++) {
|
||||
unselectable = (minYear !== 'undefined' && year < minYear) ||
|
||||
(maxYear !== 'undefined' && year > maxYear);
|
||||
//html += '<span class="year'+(i == -1 || i == 10 ? ' old' : '')+(currentYear == year ? ' active' : '')+'">'+year+'</span>';
|
||||
yearPicker += '<td class="' +
|
||||
(unselectable ? ' ' + this._unselectableClass + ' ui-state-disabled': '') + // highlight unselectable months
|
||||
((!unselectable && (i==1 || i==12)) ? ' outoffocus' : '') +
|
||||
(year == drawYear ? ' ui-datepicker-today' : '') + '"' +
|
||||
(unselectable ? '' : ' onclick="$.ui_datepicker.select_month = false;jQuery.ui_datepicker._pickMonthYear_MonthYearPicker(\'#' + inst.id + '\', ' + year + ', \'Y\');return false;"') + '>' + // actions
|
||||
((unselectable ? '<span class="ui-state-default">' + year + '</span>' : '<a class="ui-state-default ' +
|
||||
//(month == drawMonth ? ' ui-state-highlight' : '') +
|
||||
(year == drawYear ? ' ui-state-active' : '') + // highlight selected day
|
||||
//(otherMonth ? ' ui-priority-secondary' : '') + // distinguish dates from other months
|
||||
'" href="#">' + year + '</a>')) + '</td>'; // display selectable date
|
||||
if(i % 4 == 0) {
|
||||
yearPicker += '</tr>';
|
||||
if(i != 12) {
|
||||
yearPicker += '<tr>';
|
||||
}
|
||||
}
|
||||
year++;
|
||||
}
|
||||
yearPicker += '</tbody></table>';
|
||||
$('.ui-datepicker-select-year').html(yearPicker);
|
||||
};
|
||||
|
||||
_updateYearPicker_MYP(year);
|
||||
|
||||
var dpYearSelector = inst.dpDiv.find('.ui-datepicker-select-year table');
|
||||
this._addHoverEvents_MonthYearPicker(dpYearSelector);
|
||||
|
||||
inst.dpDiv.find('table.ui-datepicker-calendar').hide();
|
||||
inst.dpDiv.find('.ui-datepicker-select-month').hide();
|
||||
inst.dpDiv.find('.ui-datepicker-select-year').show();
|
||||
|
||||
this._reposition_MonthYearPicker(inst);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})(jQuery);
|
|
@ -0,0 +1,74 @@
|
|||
:root {
|
||||
--background-color: #fff;
|
||||
--border-color: #ccc;
|
||||
--text-color: #555;
|
||||
--selected-text-color: rgb(56, 241, 164);
|
||||
--hover-background-color: #eee;
|
||||
}
|
||||
|
||||
.yearpicker-container {
|
||||
z-index: 2000000000;
|
||||
position: absolute;
|
||||
color: var(--text-color);
|
||||
width: 280px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 3px;
|
||||
font-size: 1rem;
|
||||
box-shadow: 1px 1px 8px 0px rgba(0, 0, 0, 0.2);
|
||||
background-color: var(--background-color);
|
||||
}
|
||||
|
||||
.yearpicker-header {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 2.5rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.yearpicker-prev,
|
||||
.yearpicker-next {
|
||||
cursor: pointer;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.yearpicker-prev:hover,
|
||||
.yearpicker-next:hover {
|
||||
color: var(--selected-text-color);
|
||||
}
|
||||
|
||||
.yearpicker-year {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.yearpicker-items {
|
||||
list-style: none;
|
||||
padding: 1rem 0.5rem;
|
||||
flex: 0 0 33.3%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.yearpicker-items:hover {
|
||||
background-color: var(--hover-background-color);
|
||||
color: var(--selected-text-color);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.yearpicker-items.selected {
|
||||
color: var(--selected-text-color);
|
||||
}
|
||||
|
||||
.hide {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.yearpicker-items.disabled {
|
||||
pointer-events: none;
|
||||
color: #bbb;
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
# encoding: utf-8
|
||||
class Admin::AsksController < OrbitAdminController
|
||||
include Admin::AsksHelper
|
||||
helper Admin::AsksHelper
|
||||
before_action ->(module_app = @app_title) { set_variables module_app }
|
||||
before_action :set_askquestion, only: [:edit, :destroy, :update]
|
||||
|
||||
layout :compute_layout
|
||||
def compute_layout
|
||||
'back_end_with_jquery_first'
|
||||
end
|
||||
def initialize
|
||||
super
|
||||
@app_title = "ask"
|
||||
|
@ -26,7 +29,24 @@ class Admin::AsksController < OrbitAdminController
|
|||
params[:filters][:identity].blank? ? [] : params[:filters][:identity] rescue []
|
||||
end
|
||||
end
|
||||
|
||||
def setting_save
|
||||
ask_setting = AskSetting.first
|
||||
p1 = ask_setting_params
|
||||
ask_setting.update_attributes(p1)
|
||||
redirect_to '/admin/asks'
|
||||
end
|
||||
def setting
|
||||
@ask_setting = AskSetting.first
|
||||
@ask_setting = AskSetting.create() if @ask_setting.nil?
|
||||
@url = setting_save_admin_asks_path
|
||||
end
|
||||
def get_new_setting_index
|
||||
ask_setting_index = AskSettingIndex.first
|
||||
ask_setting_index = AskSettingIndex.create() if ask_setting_index.nil?
|
||||
ask_setting_index.key = ask_setting_index.key + 1
|
||||
ask_setting_index.save
|
||||
render :json => {key: ask_setting_index.key.to_i}
|
||||
end
|
||||
def index
|
||||
@tags = @module_app.tags
|
||||
@categories = @module_app.categories
|
||||
|
@ -74,7 +94,8 @@ class Admin::AsksController < OrbitAdminController
|
|||
end
|
||||
|
||||
def update
|
||||
@ask_question.update_attributes(params.require(:ask_question).permit!)
|
||||
ask_question_param = params.require(:ask_question).permit!
|
||||
@ask_question.update_attributes(ask_question_param)
|
||||
if @ask_question.send_email?
|
||||
build_email(@ask_question)
|
||||
end
|
||||
|
@ -149,4 +170,24 @@ class Admin::AsksController < OrbitAdminController
|
|||
def set_askquestion
|
||||
@ask_question = AskQuestion.find(params[:id])
|
||||
end
|
||||
private
|
||||
def ask_setting_params
|
||||
param = params.require('ask_setting').permit!
|
||||
param_clone = param.clone
|
||||
param_clone['default_setting'].each { |k, v| param_clone['default_setting'][k] = (v == 'true'? true : false) }
|
||||
param_clone.delete('custom_fields')
|
||||
ask_setting = AskSetting.first
|
||||
custom_fields = ask_setting['custom_fields'].clone
|
||||
params_custom_fields = (params.require('ask_setting').require('custom_fields') rescue {})
|
||||
params_custom_fields.each do |k,v|
|
||||
custom_fields[k] = v
|
||||
end
|
||||
field_to_delete = params['delete_field'].to_s.split(',').select{|v| !v.empty?}
|
||||
field_to_delete.each do |k|
|
||||
if custom_fields.keys.include? k
|
||||
custom_fields[k]['delete'] = true
|
||||
end
|
||||
end
|
||||
param_clone.merge({custom_fields: custom_fields})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class AsksController < ApplicationController
|
||||
helper Admin::AsksHelper
|
||||
def initialize
|
||||
super
|
||||
@app_title = 'ask'
|
||||
|
@ -6,7 +7,8 @@ class AsksController < ApplicationController
|
|||
|
||||
def index
|
||||
module_app = ModuleApp.where(:key => "ask").first
|
||||
categories = module_app.categories
|
||||
categories = Array(Category.find(OrbitHelper.page_categories)) rescue ['all']
|
||||
categories = module_app.categories if categories.include? 'all'
|
||||
tags = module_app.tags
|
||||
ask_question = AskQuestion.new
|
||||
{
|
||||
|
@ -19,7 +21,7 @@ class AsksController < ApplicationController
|
|||
|
||||
def create
|
||||
@ask_question = AskQuestion.new(create_params)
|
||||
if gotcha_valid? && @ask_question.save
|
||||
if (gotcha_valid? || !AskSetting.first.default_setting['recaptcha'])&& @ask_question.save
|
||||
build_email(@ask_question)
|
||||
redirect_to "#{params[:referer_url]}/?method=thank"
|
||||
else
|
||||
|
|
|
@ -1,4 +1,176 @@
|
|||
module Admin::AsksHelper
|
||||
def set_input_name(input_name)
|
||||
@input_name = input_name
|
||||
end
|
||||
def get_input_name
|
||||
@input_name
|
||||
end
|
||||
def create_lang_panel(field)
|
||||
tmp2 = content_tag(:div,:class => 'btn-group', :data=>{:toggle=>"buttons-radio"}) do
|
||||
I18n.available_locales.collect do |key|
|
||||
link_entry_ary = ["##{field}","_#{key}"]
|
||||
link_entry = link_entry_ary.join
|
||||
link_to(I18n.t(key),link_entry,:data=>{:toggle=>"tab"},:class=>"btn #{(key == I18n.locale ? "active" : nil)}",:for=>key)
|
||||
end.join.html_safe
|
||||
end
|
||||
end
|
||||
def multiple_lang_tag(index1,type_of_tag,field,value=nil,custom_options={},combine_element='',exteral_options={})
|
||||
content_tag(:div,{:class => "tab-panel"}.merge(exteral_options)) do
|
||||
all_field = (get_input_name + "[#{index1}][#{field}][parant]").gsub(/\[/,'_').gsub(/\]/,'')
|
||||
(I18n.available_locales.collect do |locale|
|
||||
active_flag = ((locale == I18n.locale) ? ' active' : '')
|
||||
content_tag(:div,:class => "tab-content#{active_flag}",:id=>"#{all_field}_#{locale}") do
|
||||
value_locale = value[locale.to_s] rescue nil
|
||||
self.__send__("#{type_of_tag}_tag","#{get_input_name}[#{index1}][#{field}][#{locale}]",value_locale,custom_options)
|
||||
end
|
||||
end.join + create_lang_panel(all_field)).html_safe + combine_element
|
||||
end
|
||||
end
|
||||
def time_setting_block(key,value={})
|
||||
class_block = (value['type'] != 'date') ? "time_setting_block" : "time_setting_block active"
|
||||
format_selected = (value['type'] != 'date') ? nil : value['format']
|
||||
range_selected = (value['type'] != 'date') ? nil : value['range_flag']
|
||||
options1 = [['YYYY / MM / DD HH:mm','format1'],['YYYY / MM / DD','format2'],['YYYY / MM','format3'],['YYYY','format4']]
|
||||
options2 = [[t('yes'),'true'],[t('no'),'false']]
|
||||
format_setting_tag = field_select_tag(key,'format',options1,format_selected)
|
||||
range_setting_tag = field_select_tag(key,'range_flag',options2,range_selected)
|
||||
"<div class=\"#{class_block}\">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>#{t('ask.format')}:</td><td>#{format_setting_tag}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>#{t('ask.enable_range_setting')}:</td><td>#{range_setting_tag}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>"
|
||||
end
|
||||
def field_select_tag(index1,field,options,selected=nil,custom_options={})
|
||||
select_tag("#{get_input_name}[#{index1}][#{field}]",options_for_select(options,selected: selected),custom_options)
|
||||
end
|
||||
def field_radio_button_tag(index1,field,show_value,value,custom_options={})
|
||||
radio_button_tag("#{get_input_name}[#{index1}][#{field}]",show_value,value)
|
||||
end
|
||||
def render_date_block(field_name,v,i,value)
|
||||
case v['format']
|
||||
when 'format1'
|
||||
t1 = text_field_tag("#{field_name}[datetime][date][#{i}]",(value['datetime']['date']["#{i}"] rescue nil),{:required => v['required']=='true',autocomplete: 'off',placeholder: t('ask.datepicker'),style:'width:100%;'})
|
||||
t2_value = value['datetime']['h']["#{i}"] rescue nil
|
||||
t3_value = value['datetime']['m']["#{i}"] rescue nil
|
||||
t2 = select_tag("#{field_name}[datetime][h][#{i}]",options_for_select((1..24).collect{|v1| v1.to_s.rjust(2, "0")},selected: t2_value))
|
||||
t3 = select_tag("#{field_name}[datetime][m][#{i}]",options_for_select((0..59).collect{|v1| v1.to_s.rjust(2, "0")},selected: t3_value))
|
||||
t4 = "#{t2}<b style=\"padding: 0 0.1em;\">:</b>#{t3}"
|
||||
"<div class=\"datetime_selector\" style=\"display: inline-flex;\">#{t1}<div class=\"time_selector\" style=\"width:100%;\">#{t4}</div></div>
|
||||
<script>
|
||||
jQuery(document).ready(function( $ ) {
|
||||
$(\"input[name='#{field_name}[datetime][date][#{i}]']\").ui_datepicker();
|
||||
})
|
||||
</script>".html_safe
|
||||
when 'format2'
|
||||
t1 = text_field_tag("#{field_name}[datetime][date][#{i}]",(value['datetime']['date']["#{i}"] rescue nil),{:required => v['required']=='true',autocomplete: 'off',placeholder: t('ask.datepicker')})
|
||||
"<div class=\"datetime_selector\" style=\"display: inline-flex;\">#{t1}</div>
|
||||
<script>
|
||||
jQuery(document).ready(function( $ ) {
|
||||
$(\"input[name='#{field_name}[datetime][date][#{i}]']\").ui_datepicker();
|
||||
})
|
||||
</script>".html_safe
|
||||
when 'format3'
|
||||
t1 = text_field_tag("#{field_name}[datetime][date][#{i}]",(value['datetime']['date']["#{i}"] rescue nil),{:required => v['required']=='true',autocomplete: 'off',placeholder: t('ask.datepicker'),:class => 'yearpicker'})
|
||||
"#{t1}
|
||||
<script>
|
||||
jQuery(document).ready(function( $ ) {
|
||||
$(\"input[name='#{field_name}[datetime][date][#{i}]']\").ui_datepicker({dateFormat: 'yy-mm',show_view: 'month'});
|
||||
})
|
||||
</script>
|
||||
"
|
||||
when 'format4'
|
||||
t1 = text_field_tag("#{field_name}[datetime][date][#{i}]",(value['datetime']['date']["#{i}"] rescue nil),{:required => v['required']=='true',autocomplete: 'off',placeholder: t('ask.datepicker'),:class => 'yearpicker'})
|
||||
"#{t1}
|
||||
<script>
|
||||
jQuery(document).ready(function( $ ) {
|
||||
$(\"input[name='#{field_name}[datetime][date][#{i}]']\").ui_datepicker({dateFormat: 'yy',show_view: 'year'});
|
||||
})
|
||||
</script>
|
||||
"
|
||||
end
|
||||
end
|
||||
def show_on_front(k,v,value=nil)
|
||||
field_name = "#{get_input_name}[custom_values][#{k}]"
|
||||
begin
|
||||
case v['type']
|
||||
when 'text_field'
|
||||
text_field_tag(field_name,value,{:required => v['required']=='true',placeholder: v['prompt_word'][I18n.locale]})
|
||||
when 'select'
|
||||
prompt_hash = v['prompt_word'][I18n.locale].blank? ? {} : {prompt: v['prompt_word'][I18n.locale]}
|
||||
prompt_hash.merge(:required => v['required']=='true')
|
||||
select_tag(field_name,options_for_select(Array(v['options']).select{|index1,option| option['disabled'] != 'true'}.collect{|index1,option| [option[I18n.locale],index1]},selected: value),prompt_hash)
|
||||
when 'date'
|
||||
if v['range_flag']=='true'
|
||||
"<div style=\"display:inline-flex;flex-direction:column;\">
|
||||
#{render_date_block(field_name,v,0,value)}
|
||||
<div style=\"display: inline-flex;align-items: center;writing-mode: tb-rl;padding: 0.3em;\">~</div>
|
||||
#{render_date_block(field_name,v,1,value)}
|
||||
</div>".html_safe
|
||||
else
|
||||
render_date_block(field_name,v,0,value)
|
||||
end
|
||||
when 'text_area'
|
||||
text_area_tag(field_name,value,{:required => v['required']=='true',:placeholder=> v['prompt_word'][I18n.locale],:class=>'ckeditor'})
|
||||
when 'radio_button'
|
||||
if value.nil?
|
||||
value = {}
|
||||
end
|
||||
Array(v['options']).select{|index1,option| option['disabled'] != 'true'}.collect do |index1,option|
|
||||
"#{radio_button_tag(field_name,index1,value==index1,{:required => v['required']=='true'})}#{option[I18n.locale]}"
|
||||
end.join
|
||||
when 'checkbox'
|
||||
if value.nil?
|
||||
value = {}
|
||||
end
|
||||
Array(v['options']).select{|index1,option| option['disabled'] != 'true'}.collect do |index1,option|
|
||||
"#{check_box_tag("#{field_name}[#{index1}]",index1,value[index1]==index1)}#{option[I18n.locale]}"
|
||||
end.join
|
||||
end
|
||||
rescue => e
|
||||
debug e.inspect
|
||||
end
|
||||
end
|
||||
def custom_field_block(k,v={})
|
||||
set_input_name('ask_setting[custom_fields]')
|
||||
markups = LIST[:markups].select{|k,v| k != 'member_relationship' && k != 'address'}.collect{|key,val| [t("lists.markups."+key),key]}
|
||||
multi_lang_tag = multiple_lang_tag(k,'text_field','field',v['field'],{placeholder: t('ask.field_name')})
|
||||
field_select_tag = field_select_tag(k,'type',markups,v['type'],{:onchange=>'check_available_setting_block(this)'})
|
||||
key = hidden_field_tag "ask_setting[custom_fields][#{k}][key]",k,{'class' => 'key'}
|
||||
all_new_options = Array(v['options']).collect do |key,value|
|
||||
tmp = create_delete_button('delete_added_select_option').html_safe+hidden_field_tag("ask_setting[custom_fields][#{k}][options][#{key}][disabled]",value['disabled'],{'class' => 'disabled_field'})
|
||||
hidden_style = value['disabled'] == 'true' ? {style: 'display:none;'} : {}
|
||||
"#{multiple_lang_tag(k,'text_field',"options][#{key}",value,{placeholder: t('ask.option_name')},tmp,hidden_style)}"
|
||||
end.join
|
||||
active_class = Array(v['options']).count !=0 ? ' active' : ''
|
||||
active_prompt_class = ['date','radio_button','checkbox'].exclude?(v['type']) ? ' active' : ''
|
||||
multi_lang_prompt_tag = "<div class=\"prompt_word#{active_prompt_class}\">#{multiple_lang_tag(k,'text_field','prompt_word',v['prompt_word'],{placeholder: t('ask.prompt_word')})}</div>"
|
||||
require_ask_tag = "<div>#{t('ask.required')}: #{field_radio_button_tag(k,'required','true',v['required']=='true')}#{t('ask.yes')}#{field_radio_button_tag(k,'required','false',v['required']!='true')}#{t('ask.no')}</div>"
|
||||
tmp = "<div class=\"add_new_options#{active_class}\">#{all_new_options}<input type=\"button\" value=\"#{t('ask.add_new_options')}\" onclick=\"add_new_options_for_field(this,#{k})\"></div>"
|
||||
field_html = "<tr class=\"custom_field\">
|
||||
<td>
|
||||
#{multi_lang_tag}
|
||||
#{require_ask_tag}
|
||||
#{field_select_tag}<br>
|
||||
#{multi_lang_prompt_tag}
|
||||
#{time_setting_block(k,v)}
|
||||
#{tmp}
|
||||
#{key}
|
||||
</td>
|
||||
<td>
|
||||
#{create_delete_button('delete_field_func')}
|
||||
</td>
|
||||
</tr>"
|
||||
end
|
||||
def create_delete_button(func_name)
|
||||
"<input class=\"btn btn-danger\" type=\"button\" value=\"#{t('delete_')}\" onclick=\"#{func_name}(this)\">"
|
||||
end
|
||||
def page_for_askquestion(askquestion)
|
||||
ann_page = nil
|
||||
pages = Page.where(:module=>'ask')
|
||||
|
|
|
@ -21,7 +21,7 @@ class AskQuestion
|
|||
field :situation, type: String, default: "is_waiting" #預設待處理
|
||||
field :send_email, type: Boolean, default: false
|
||||
field :email_id
|
||||
|
||||
field :custom_values, type: Hash,default: {}
|
||||
# validates_presence_of :name, :identity, :mail, :title, :content
|
||||
|
||||
def email
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
class AskSetting
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
after_initialize do
|
||||
if default_setting.class != Hash
|
||||
default_setting = {}
|
||||
end
|
||||
if custom_fields.class != Hash
|
||||
custom_fields = {}
|
||||
end
|
||||
self.save
|
||||
end
|
||||
def custom_fields
|
||||
tmp = super
|
||||
tmp.select{|k,v| v['delete'] != true}
|
||||
end
|
||||
field :default_setting, type: Hash,default: {ask_category_id: true,name: true,sex: false,mail: true,phone: false,appointment: false,recaptcha: false}
|
||||
field :custom_fields, type: Hash,default: {}
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AskSettingIndex
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
field :key,type: Integer,default: 0
|
||||
end
|
|
@ -1,11 +1,36 @@
|
|||
<%
|
||||
ask_setting = AskSetting.first
|
||||
set_input_name('ask_question')
|
||||
%>
|
||||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||
<%= stylesheet_link_tag "lib/main-list" %>
|
||||
<% end %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "lib/module-area" %>
|
||||
<% end %>
|
||||
|
||||
<%# javascript_include_tag "lib/bootstrap-datetimepicker.js" %>
|
||||
<%# javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"%>
|
||||
<%= javascript_include_tag "/assets/lib/jquery-ui-1.12.1/jquery-ui.min" %>
|
||||
<%# javascript_include_tag "lib/module-area" %>
|
||||
<%= javascript_include_tag "jquery.ui.datepicker.monthyearpicker" %>
|
||||
<%# javascript_include_tag "lib/bootstrap-datetimepicker" %>
|
||||
<style type="text/css">
|
||||
.time_selector{
|
||||
display: inline-flex;
|
||||
}
|
||||
.input-area tr td {
|
||||
text-align: center;
|
||||
}
|
||||
@media (max-width: 768px){
|
||||
.ask-question .control-group{
|
||||
justify-content: center;
|
||||
}
|
||||
.time_selector{
|
||||
display: inline-flex;
|
||||
}
|
||||
.datetime_selector{
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<div class="input-area">
|
||||
<div id="ask-asks">
|
||||
<table class="table">
|
||||
|
@ -21,7 +46,7 @@
|
|||
<!-- <td><%= AskQuestion.human_attribute_name(:fax) %>:<%= @ask_question.fax %></td> -->
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5"><%= AskQuestion.human_attribute_name(:appointment) %>:<%= @ask_question.appointment.strftime("%Y-%m-%d %H:%M") %></td>
|
||||
<td colspan="5"><%= AskQuestion.human_attribute_name(:appointment) %>:<%= @ask_question.appointment.strftime("%Y-%m-%d %H:%M") rescue nil %></td>
|
||||
<!-- <td colspan="5"><%= AskQuestion.human_attribute_name(:name) %>:<%= @ask_question.name %></td> -->
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -55,6 +80,15 @@
|
|||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<%= ask_setting.custom_fields.collect do |k,v|
|
||||
required_pattern = v['required']=='true' ? '*' : ''
|
||||
"<div class=\"control-group\">
|
||||
<label class=\"control-label\" for=\"ask_question_mail\">#{required_pattern}#{v['field'][I18n.locale]}</label>
|
||||
<div class=\"controls\">
|
||||
#{show_on_front(k,v,@ask_question.custom_values[k])}
|
||||
</div>
|
||||
</div>"
|
||||
end.join.html_safe %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
</div>
|
||||
</td>
|
||||
<td><%= b.phone %></td>
|
||||
<td><%= b.appointment.strftime("%Y-%m-%d %H:%M") %></td>
|
||||
<td><%= b.appointment.strftime("%Y-%m-%d %H:%M") rescue nil %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
<%
|
||||
set_input_name('ask_setting[custom_fields]')
|
||||
%>
|
||||
<style type="text/css">
|
||||
thead td {
|
||||
text-align: center;
|
||||
color: blueviolet;
|
||||
}
|
||||
.add_new_options,.prompt_word,.time_setting_block{
|
||||
display: none;
|
||||
}
|
||||
.add_new_options.active,.prompt_word.active,.time_setting_block.active{
|
||||
display: inline-block;
|
||||
}
|
||||
tr td {
|
||||
text-align: center;
|
||||
}
|
||||
tr.custom_field td:nth-child(1){
|
||||
text-align: left;
|
||||
}
|
||||
td{
|
||||
padding: 0.5em;
|
||||
}
|
||||
.tab-content{
|
||||
display: none;
|
||||
}
|
||||
.tab-content.active{
|
||||
display: block;
|
||||
}
|
||||
.tab-panel{
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
tr.custom_field {
|
||||
border: 0.1em solid #8e00ff;
|
||||
}
|
||||
tr.custom_field > td >div {
|
||||
padding: 0.5em 0;
|
||||
}
|
||||
input[type=text] {
|
||||
height: 30px;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
<%
|
||||
option_multi_lang_tag = multiple_lang_tag(-1,'text_field','options][-2',nil,{placeholder: t('ask.option_name')},create_delete_button('delete_added_select_option').html_safe+hidden_field_tag("ask_setting[custom_fields][-1][options][-2][disabled]",nil,{'class' => 'disabled_field'}))
|
||||
%>
|
||||
function check_available_setting_block(ele){
|
||||
var tmp = $(ele).val()
|
||||
var parent_div = $(ele).parents('.custom_field').eq(0)
|
||||
if (tmp != 'date' && tmp != 'radio_button' && tmp!='checkbox'){
|
||||
parent_div.find('.prompt_word').addClass('active')
|
||||
}else{
|
||||
parent_div.find('.prompt_word').removeClass('active')
|
||||
}
|
||||
if (tmp == 'select' || tmp == 'radio_button' || tmp=='checkbox'){
|
||||
parent_div.find('.add_new_options').addClass('active')
|
||||
}else{
|
||||
parent_div.find('.add_new_options').removeClass('active')
|
||||
}
|
||||
if (tmp == 'date'){
|
||||
parent_div.find('.time_setting_block').addClass('active')
|
||||
}else{
|
||||
parent_div.find('.time_setting_block').removeClass('active')
|
||||
}
|
||||
}
|
||||
function delete_field_func(ele){
|
||||
$(ele).parents('tr').remove()
|
||||
var all_delete_field = $('.delete_field').val()
|
||||
all_delete_field = all_delete_field + ',' + $(ele).parents('tr').find('.key').val()
|
||||
$('.delete_field').val(all_delete_field)
|
||||
}
|
||||
function add_new_options_for_field(ele,key){
|
||||
var add_html = "<%= option_multi_lang_tag.inspect %>"
|
||||
add_html = add_html.replace(/-1/g,key)
|
||||
var parent_div = $(ele).parents('.add_new_options')
|
||||
var tab_panel = parent_div.eq(0).find('.tab-panel')
|
||||
var tab_panel_length = tab_panel.length
|
||||
add_html = add_html.replace(/-2/g,tab_panel_length)
|
||||
parent_div.find('input[type="button"]').eq(-1).before($('<div/>').html(add_html).text().slice(1,-2))
|
||||
}
|
||||
function delete_added_select_option(ele){
|
||||
var parent_div = $(ele).parents('.tab-panel')
|
||||
parent_div.find('.disabled_field').val('true')
|
||||
parent_div.hide()
|
||||
}
|
||||
function add_new_field(){
|
||||
$.ajax({
|
||||
url : "<%= get_new_setting_index_admin_asks_path %>",
|
||||
dataType : "json",
|
||||
type : "post",
|
||||
error: function(){
|
||||
alert('init process failed, please try again later.')
|
||||
},
|
||||
success: function(data){
|
||||
var add_field_html = "<%= custom_field_block(-1).inspect %>"
|
||||
add_field_html = add_field_html.replace(/-1/g,data['key'])
|
||||
$('.add_field').before($('<div/>').html(add_field_html).text().slice(1,-2))
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<%= form_for @ask_setting,method: 'post',url: @url,html: { class: 'form-horizontal main-forms previewable' } do |f| %>
|
||||
<fieldset>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>
|
||||
<%= t('ask.field') %>
|
||||
</td>
|
||||
<td>
|
||||
<%= t('ask.whether_open') %>
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @ask_setting.default_setting.each do |k,v| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= t("mongoid.attributes.ask_question.#{k}") %>
|
||||
</td>
|
||||
<td>
|
||||
<%= f.select "default_setting[#{k}]",[[t('yes'),'true'],[t('no'),false]] ,selected: v %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% @ask_setting.custom_fields.each do |k,v| %>
|
||||
<%= custom_field_block(k,v).html_safe %>
|
||||
<% end %>
|
||||
<tr class="add_field">
|
||||
<td colspan="2" style="text-align: center;">
|
||||
<input class="btn btn-info" type="button" value="<%= t('add')%>" onclick="add_new_field()">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" style="text-align: center;">
|
||||
<%= hidden_field_tag :delete_field, nil,{'class'=> 'delete_field' } %>
|
||||
<%= f.hidden_field :id, value: @ask_setting.id %>
|
||||
<input class="btn btn-primary" type="submit" value="<%= t('submit')%>">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
<% end %>
|
|
@ -3,6 +3,9 @@
|
|||
@categories = data["categories"]
|
||||
@tags = data["tags"]
|
||||
@module_app = data["module_app"]
|
||||
ask_setting = AskSetting.first
|
||||
ask_setting = AskSetting.create() if ask_setting.nil?
|
||||
set_input_name('ask_question')
|
||||
%>
|
||||
|
||||
<%= stylesheet_link_tag "basic/bootstrap-datetimepicker" %>
|
||||
|
@ -10,48 +13,122 @@
|
|||
.default_picker label{
|
||||
display: none;
|
||||
}
|
||||
.ask-question .control-group{
|
||||
flex-wrap: wrap;
|
||||
display: inline-flex;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
}
|
||||
.ask-question .controls > *{
|
||||
display: block;
|
||||
}
|
||||
.ask-question .controls > script{
|
||||
display: none;
|
||||
}
|
||||
.ask-question .form-horizontal .control-label{
|
||||
width: 24%;
|
||||
max-width: 15em;
|
||||
min-width: 14em;
|
||||
padding: 0;
|
||||
text-align: center;
|
||||
}
|
||||
.ask-question .form-horizontal .control-group .controls{
|
||||
margin: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
min-width: 10em;
|
||||
max-width: 20em;
|
||||
padding-left: 0;
|
||||
width: 70%;
|
||||
padding: 0.5em;
|
||||
justify-content: center;
|
||||
}
|
||||
.ask-question .form-horizontal input[type="text"],.ask-question .form-horizontal select{
|
||||
width: 97%;
|
||||
max-width: 13.75em;
|
||||
}
|
||||
.ask-question .form-horizontal .form-actions{
|
||||
position: relative;
|
||||
padding: 1em 0 0 0;
|
||||
text-align: center;
|
||||
}
|
||||
.time_selector{
|
||||
display: inline-flex;
|
||||
}
|
||||
@media (max-width: 768px){
|
||||
.ask-question .control-group{
|
||||
justify-content: center;
|
||||
}
|
||||
.time_selector{
|
||||
display: inline-flex;
|
||||
}
|
||||
.datetime_selector{
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<%= javascript_include_tag "/assets/lib/jquery-ui-1.12.1/jquery-ui.min" %>
|
||||
<%= stylesheet_link_tag "/assets/lib/jquery-ui-1.12.1/jquery-ui.min" %>
|
||||
<script type="text/javascript">
|
||||
var datepicker_fn = $.fn.datepicker
|
||||
var datepicker = $.datepicker
|
||||
var a = 1
|
||||
</script>
|
||||
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
|
||||
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
|
||||
|
||||
|
||||
<%= javascript_include_tag "jquery.ui.datepicker.monthyearpicker" %>
|
||||
|
||||
<%= javascript_include_tag 'validator' %>
|
||||
<link href="/assets/ask/ask.css" media="screen" rel="stylesheet">
|
||||
<div id="new-ask-question" class="ask-question">
|
||||
<%= form_for @ask_question, url: asks_path, html: {class: 'form-horizontal'} do |f| %>
|
||||
<!-- Category -->
|
||||
<div class="control-group">
|
||||
<%= f.label :ask_category_id, class: 'control-label required' %>
|
||||
<div class="controls">
|
||||
<%= f.select :category_id, @categories.collect{|t| [ t.title, t.id ]} %>
|
||||
<% if ask_setting.default_setting['ask_category_id'] %>
|
||||
<div class="control-group">
|
||||
<%= f.label :ask_category_id, class: 'control-label required' %>
|
||||
<div class="controls">
|
||||
<% if @categories.count > 1 %>
|
||||
<%= f.select :category_id, @categories.collect{|t| [ t.title, t.id ]} %>
|
||||
<% else %>
|
||||
<span>
|
||||
<%= @categories[0].title rescue '' %>
|
||||
</span>
|
||||
<%= f.hidden_field :category_id, :value => (@categories[0].id.to_s rescue nil) %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% elsif @categories.count == 1 %>
|
||||
<%= f.hidden_field :category_id, :value => (@categories[0].id.to_s rescue nil) %>
|
||||
<% end %>
|
||||
<!-- 姓名 -->
|
||||
<div class="control-group">
|
||||
<%= f.label :name, class: 'control-label required' %>
|
||||
<div class="controls">
|
||||
<%= f.text_field :name, data: {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} %>
|
||||
<% if ask_setting.default_setting['name'] %>
|
||||
<div class="control-group">
|
||||
<%= f.label :name, class: 'control-label required' %>
|
||||
<div class="controls">
|
||||
<%= f.text_field :name, data: {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<!-- 性別 -->
|
||||
<div class="control-group">
|
||||
<%= f.label :sex, class: 'control-label required' %>
|
||||
<div class="controls">
|
||||
<label class="radio-inline">
|
||||
<%= f.radio_button :sex, "male" %><%= t('users.male')%>
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<%= f.radio_button :sex, "female" %><%= t('users.female')%>
|
||||
</label>
|
||||
<% if ask_setting.default_setting['sex'] %>
|
||||
<div class="control-group">
|
||||
<%= f.label :sex, class: 'control-label required' %>
|
||||
<div class="controls">
|
||||
<label class="radio-inline">
|
||||
<%= f.radio_button :sex, "male" %><%= t('users.male')%>
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<%= f.radio_button :sex, "female" %><%= t('users.female')%>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<!-- 身分 -->
|
||||
<!-- <div class="control-group">
|
||||
<%= f.label :identity, class: 'control-label required' %>
|
||||
<%# f.label :identity, class: 'control-label required' %>
|
||||
<div class="controls">
|
||||
<%= select_tag "ask_question[identity]", options_for_select(@tags.collect{|t| [ t.name, t.id ]}) if !@tags.nil? %>
|
||||
<%# select_tag "ask_question[identity]", options_for_select(@tags.collect{|t| [ t.name, t.id ]}) if !@tags.nil? %>
|
||||
</div>
|
||||
</div> -->
|
||||
<!-- Email -->
|
||||
|
@ -62,49 +139,63 @@
|
|||
</div>
|
||||
</div>
|
||||
<!-- 聯絡電話 -->
|
||||
<div class="control-group">
|
||||
<%= f.label :phone, class: 'control-label' %>
|
||||
<div class="controls">
|
||||
<%= f.text_field :phone %>
|
||||
<% if ask_setting.default_setting['phone'] %>
|
||||
<div class="control-group">
|
||||
<%= f.label :phone, class: 'control-label' %>
|
||||
<div class="controls">
|
||||
<%= f.text_field :phone %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<!-- 預約日期 -->
|
||||
<div class="control-group">
|
||||
<%= f.label :appointment, class: 'control-label' %>
|
||||
<div class="controls">
|
||||
<%= f.datetime_picker :appointment %>
|
||||
<% if ask_setting.default_setting['appointment'] %>
|
||||
<div class="control-group">
|
||||
<%= f.label :appointment, class: 'control-label' %>
|
||||
<div class="controls">
|
||||
<%= f.datetime_picker :appointment %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<!-- 傳真 -->
|
||||
<!-- <div class="control-group">
|
||||
<%= f.label :fax, class: 'control-label' %>
|
||||
<%# f.label :fax, class: 'control-label' %>
|
||||
<div class="controls">
|
||||
<%= f.text_field :fax %>
|
||||
<%# f.text_field :fax %>
|
||||
</div>
|
||||
</div> -->
|
||||
<!-- 主旨 -->
|
||||
<!-- <div class="control-group">
|
||||
<%= f.label :title, class: 'control-label required' %>
|
||||
<%# f.label :title, class: 'control-label required' %>
|
||||
<div class="controls">
|
||||
<%= f.text_field :title, data: {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} %>
|
||||
<%# f.text_field :title, data: {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} %>
|
||||
</div>
|
||||
</div> -->
|
||||
<!-- 內容 -->
|
||||
<!-- <div class="control-group">
|
||||
<%= f.label :content, class: 'control-label required' %>
|
||||
<%# f.label :content, class: 'control-label required' %>
|
||||
<div class="controls">
|
||||
<%= f.text_area :content, rows: 8, class: 'input-xlarge' %>
|
||||
<%# f.text_area :content, rows: 8, class: 'input-xlarge' %>
|
||||
</div>
|
||||
</div> -->
|
||||
<!-- 驗證碼 -->
|
||||
<div class="control-group">
|
||||
<%= f.label :recaptcha, class: 'control-label' %>
|
||||
<div class="controls">
|
||||
<%= gotcha_error %>
|
||||
<%= gotcha %>
|
||||
<%= ask_setting.custom_fields.collect do |k,v|
|
||||
required_pattern = v['required']=='true' ? '*' : ''
|
||||
"<div class=\"control-group\">
|
||||
<label class=\"control-label\" for=\"ask_question_mail\">#{required_pattern}#{v['field'][I18n.locale]}</label>
|
||||
<div class=\"controls\">
|
||||
#{show_on_front(k,v)}
|
||||
</div>
|
||||
</div>"
|
||||
end.join.html_safe %>
|
||||
<% if ask_setting.default_setting['recaptcha'] %>
|
||||
<div class="control-group">
|
||||
<%= f.label :recaptcha, class: 'control-label' %>
|
||||
<div class="controls">
|
||||
<%= gotcha_error %>
|
||||
<%= gotcha %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
<div class="form-actions">
|
||||
<input type="hidden" name="referer_url" value="<%= request.original_url.split(request.env["HTTP_HOST"]).last %>">
|
||||
<%= f.submit t('submit'), class: 'btn btn-primary', :id => 'button-mail' %>
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"%>
|
||||
<%= javascript_include_tag "/assets/lib/jquery-ui-1.12.1/jquery-ui.min" %>
|
||||
<script type="text/javascript">
|
||||
var jq = $.noConflict()
|
||||
var datepicker_fn = jq.fn.datepicker
|
||||
var datepicker = jq.datepicker
|
||||
</script>
|
||||
<%= render :template => 'layouts/back_end' %>
|
|
@ -5,6 +5,19 @@ en:
|
|||
is_referral: Rreferral
|
||||
sex: Sex
|
||||
ask:
|
||||
'yes': 'Yes'
|
||||
'no': 'No'
|
||||
required: Required
|
||||
datepicker: Select a Date
|
||||
enable_range_setting: Enable Time Range Setting
|
||||
format: Format
|
||||
add_new_options: Add new options
|
||||
field: Field
|
||||
prompt_word: Prompt Word
|
||||
option_name: Option Name
|
||||
field_name: Field Name
|
||||
whether_open: Whether to open it
|
||||
setting: Setting
|
||||
ask: Ask
|
||||
all_articles: All
|
||||
exports: Export
|
||||
|
@ -26,7 +39,21 @@ en:
|
|||
mongoid:
|
||||
attributes:
|
||||
ask_question:
|
||||
ask_category_id: Ask Category
|
||||
recaptcha: Recaptcha
|
||||
sex: Sex
|
||||
name: Name
|
||||
identity: Identity
|
||||
mail: Email
|
||||
phone: Phone
|
||||
male: Man
|
||||
female: Woman
|
||||
ask_category_id: Ask Category
|
||||
identity: Identity
|
||||
appointment: Appointment time
|
||||
fax: Fax
|
||||
title: Title
|
||||
reply: Reply
|
||||
created_at: Time
|
||||
content: Content
|
||||
comment: Comment
|
||||
status: Status
|
||||
send_email: Whether to reply email
|
|
@ -11,6 +11,19 @@ zh_tw:
|
|||
errors:
|
||||
verification_failed: 驗證碼錯誤
|
||||
ask:
|
||||
'yes': 是
|
||||
'no': 否
|
||||
required: 必填
|
||||
datepicker: 選擇日期
|
||||
enable_range_setting: 啟用時間區段設定
|
||||
format: 格式
|
||||
add_new_options: 新增選項
|
||||
field: 欄位
|
||||
prompt_word: 提示文字
|
||||
option_name: 選項名稱
|
||||
field_name: 欄位名稱
|
||||
whether_open: 是否開啟
|
||||
setting: 設定
|
||||
name: 預約客戶
|
||||
appointment: 預約時間
|
||||
created_at: 發問時間
|
||||
|
@ -44,7 +57,7 @@ zh_tw:
|
|||
sex: 性別
|
||||
name: 姓名
|
||||
identity: 身份
|
||||
mail: Email
|
||||
mail: 電子信箱
|
||||
phone: 聯絡電話
|
||||
male: 男
|
||||
female: 女
|
||||
|
|
|
@ -6,6 +6,9 @@ Rails.application.routes.draw do
|
|||
resources :asks do
|
||||
collection do
|
||||
get 'export'
|
||||
get 'setting'
|
||||
post 'setting_save'
|
||||
post 'get_new_setting_index'
|
||||
post 'export', to: 'asks#do_export'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
module Ask
|
||||
class Engine < ::Rails::Engine
|
||||
initializer "ask" do
|
||||
begin
|
||||
require File.expand_path('../../../app/models/ask_setting', __FILE__)
|
||||
require File.expand_path('../../../app/models/ask_setting_index', __FILE__)
|
||||
if defined? AskSetting && AskSetting.first.nil?
|
||||
AskSetting.create()
|
||||
end
|
||||
if defined? AskSettingIndex && AskSettingIndex.first.nil?
|
||||
AskSettingIndex.create()
|
||||
end
|
||||
rescue => e
|
||||
puts ['AskSetting not found',e]
|
||||
end
|
||||
OrbitApp.registration "Ask", :type => "ModuleApp" do
|
||||
module_label "ask.ask"
|
||||
base_url File.expand_path File.dirname(__FILE__)
|
||||
|
@ -23,6 +35,11 @@ module Ask
|
|||
:priority=>1,
|
||||
:active_for_action=>{'admin/asks'=>'index'},
|
||||
:available_for => 'users'
|
||||
context_link 'ask.setting',
|
||||
:link_path=>"setting_admin_asks_path" ,
|
||||
:priority=>5,
|
||||
:active_for_action=>{'admin/asks'=>'setting'},
|
||||
:available_for => 'managers'
|
||||
context_link 'categories',
|
||||
:link_path=>"admin_module_app_categories_path" ,
|
||||
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'ask').id}",
|
||||
|
|
Loading…
Reference in New Issue