Witgets.set('button',{
styles: {
'element': 'button'
},
inputIndex: null,
content: {
actions: {
'type': 'send', // url
'method': 'get',
'url': null,
'redirect': null,
'handler': 'subscribe', // email or buy
'section': null
},
product: {
'name': null,
'price': null
},
header: 'Название формы',
footer: 'Мы против спама',
button: {
'position': 'center',
'name': 'Отправить'
},
inputs: [{
'type': 'input',
'placeholder': 'Введите ваше имя',
'label': '',
'name': '',
'required': true,
'value': null
}, {
'type': 'email',
'placeholder': 'Введите вашу почту',
'label': '',
'name': '',
'required': true,
'value': null
}],
settings: {
'url': null,
'type': 'form',
'position': 'center',
'name': 'Отправить'
},
primary: ['inputs']
},
contentSettings: {
'settings/url': 'input',
'settings/name': 'input',
'settings/position': 'buttons',
'settings/type': 'buttons',
'button/position': 'buttons',
'button/name': 'input',
'actions/url': 'input',
'actions/redirect': 'input',
'actions/section': function(value) {
// alert(value)
},
'actions/type': 'buttons',
'actions/method': 'buttons',
'actions/handler': 'buttons',
'product/name': 'input',
'product/price': 'input',
'header': 'input',
'footer': 'input',
},
startEditing: function() {
c = this.getContent();
if(typeof c.actions.section == 'undefined') {
c.actions.section = null;
}
$('#button-setup-inputs').hide();
$('#button-inputs-control').hide();
var _this = this;
Witgets.setButtonsEvent('settings/type', this, function(data) {
if(data == 'form') {
$('#button-settings-form-block').show();
$('#button-settings-url-block').hide();
$('#button-settings-section-block').hide();
} else if(data == 'url') {
$('#button-settings-form-block').hide();
$('#button-settings-url-block').show();
$('#button-settings-section-block').hide();
} else if(data == 'section') {
$('#button-settings-form-block').hide();
$('#button-settings-url-block').hide();
$('#button-settings-section-block').show();
}
_this.set('settings/type', data);
});
Witgets.setButtonsEvent('actions/type', this, function(data) {
if(data == 'send') {
$('#button-actions-our').show();
$('#button-actions-other').hide();
} else {
$('#button-actions-our').hide();
$('#button-actions-other').show();
}
_this.set('actions/type', data);
});
Witgets.setButtonsEvent('actions/handler', this, function(data) {
if(data != 'order') {
$('#button-product-button').hide();
} else {
$('#button-product-button').show();
}
_this.set('actions/handler', data);
});
Witgets.setScrollFixed($('#button-inputs'));
Witgets.setButtonsEvent('settings/position', this, function(data) {
_this.set('settings/position', data);
});
Witgets.setButtonsEvent('actions/method', this, function(data) {
_this.set('actions/method', data);
});
Witgets.setButtonsEvent('button/position', this, function(data) {
_this.set('button/position', data);
});
this.updateEditing();
this.setContent();
// this.openSendEditor();
},
hideDropdown: function(e) {
dropdown = $(e).closest('.dropdown');
dropdown.fadeOut(200);
dropdown.parent().removeClass('active');
},
updateEditing: function() {
c = this.getContent();
html = '';
header = (c.header == null) ? '' : c.header;
if(header == '') {
header = 'Введите текст заголовка формы...';
} else {
header = '
';
}
html += '\
'+header+'\
';
for (var i = 0; i < c.inputs.length; i++) {
input = c.inputs[i];
label = (input.label != '') ? '' : '';
html += '';
inside = getFormInputHtml(input);
html += inside;
html += label;
html += '
';
html += '
';
html += '
';
html += '
';
};
if(c.button['position'] != 'wide') {
position = 'text-'+c.button['position'];
} else {
position = c.button['position'];
}
if(c.settings['position'] != 'wide') {
buttonPosition = 'text-'+c.settings['position'];
} else {
buttonPosition = c.settings['position'];
}
footer = (c.footer == null) ? '' : c.footer;
if(footer == '') {
footer = 'Введите текст подвала формы...';
}
html += '';
html += '\
'+footer+'\
';
boxHtml = '';
Setup.element.find('.box-button').html(boxHtml);
$('#button-inputs').html(html);
if(this.inputIndex != null) {
$('#button-inputs').find('.input-dragdrop').eq(this.inputIndex+1).addClass('active');
}
},
closeEditing: function() {
this.inputIndex = null;
},
closeEditing: function() {
},
chooseSection: function() {
var _this = this;
c = _this.getContent();
$('#modal').fadeOut();
$('#editor').addClass('choose-section');
toastr.info('Выберите секций нажав на нее');
$('.wrapper-outside').each(function() {
offset = $(this).offset();
height = $(this).outerHeight();
width = $(this).outerWidth();
html = $('Кликните на секцию, чтобы выбрать ее
');
$('#spg_editor').append(html);
});
$('.wrapper-button').click(function() {
id = $(this).attr('data-id');
$('#modal').fadeIn();
c.actions.section = id;
_this.setContent();
toastr.success('Секция выбрана');
$('.wrapper-button').remove();
});
},
openFormEditor: function(type) {
var _this = this;
if(type == 'hide') {
$('#button-editor').fadeOut(150, function() {
$('#modal .modal').animate({
width: 400
}, 150);
});
$('#button-settings').css('border-right', '0ox');
} else if(type == 'show') {
$('#modal .modal').animate({
width: 800
}, 150, function() {
$('#button-editor').fadeIn(150);
});
$('#button-settings').css('border-right', '1px solid #ccc');
} else if(type == 'toggle') {
this.openFormEditor('hide');
setTimeout(function() {
_this.openFormEditor('show');
}, 300);
}
},
openSendEditor: function(e) {
if($('#button-setup-inputs').is(':visible')) {
$(e).html('Настроить форму');
this.openFormEditor('hide');
$('#button-send').hide();
$('#button-inputs-control').hide();
$('#button-setup-inputs').hide();
$('#button-setup-info').show();
} else {
$('#button-inputs-control').show();
$('#button-setup-inputs').show();
$('#button-setup-info').hide();
}
},
addInput: function(e) {
type = $(e).attr('data-type');
$(e).closest('.dropdown').fadeOut(150);
value = null;
switch(type) {
case 'input':
case 'textarea': placeholder = 'Название поля'; break;
case 'phone': placeholder = 'Введите ваш телефон'; break;
case 'email': placeholder = 'Введите вашу почту'; break;
case 'checkbox':
placeholder = 'Дополнительные услуги';
value = "Добавить подарочную упаковку\r\nДобавить срочную доставку (+500 р.)";
break;
case 'radio':
placeholder = 'Подарочная упаковка';
value = "Нужна\r\nНе нужна";
break;
default:
value = null;
placeholder = 'Название поля';
}
inputs = this.getContent().inputs;
inputs.push({
'type': type,
'placeholder': placeholder,
'label': '',
'name': '',
'required': false,
'value': value
});
this.set('inputs', inputs);
},
deleteInput: function(e, evt) {
inputs = this.getContent().inputs;
index = $(e).parent().index() - 1;
if(inputs.length > 1) {
inputs.splice(index, 1);
} else {
alert('В форме должен быть хотя бы 1 одно поле');
return false;
}
$('#button-input-value').parent().hide();
$('#button-input-empty').show();
$('#button-input-panel').hide();
this.inputIndex = null;
this.set('inputs', inputs);
$(":input").blur();
evt.preventDefault();
evt.stopPropagation();
return false;
},
moveInput: function(type, e, evt) {
input = $(e).parent();
index = input.index() - 1;
inputs = this.getContent().inputs;
if(type == 'top') {
needleIndex = (index-1 < 0) ? 0 : index-1;
} else {
needleIndex = (index+1 >= inputs.length) ? inputs.length-1 : index+1;
}
if(index != needleIndex) {
inputs = move(inputs, index, needleIndex);
this.set('inputs', inputs);
}
},
chooseInput: function(e, evt) {
this.openFormEditor('toggle');
type = $(e).attr('data-type');
index = $(e).index() - 1;
input = this.getContent().inputs[index];
this.inputIndex = index;
$(e).parent().find('.active').removeClass('active');
$(e).addClass('active');
$(":input").blur();
$('#button-header').parent().hide();
$('#button-footer').parent().hide();
$('#button-button-name').parent().hide();
$('#button-button-position').parent().hide();
$('#button-input-placeholder').parent().hide();
$('#button-input-label').parent().hide();
$('#button-input-name').parent().hide();
$('#button-input-value').parent().hide();
$('#button-input-required').parent().hide();
$('#button-input-empty').hide();
$('#button-input-panel').show();
if(type == 'header' || type == 'footer') {
$('#button-'+type).parent().show();
} else if(type == 'button') {
$('#button-button-name').parent().show();
$('#button-button-position').parent().show();
} else {
if(type == 'radio' || type == 'checkbox') {
$('#button-input-value').parent().show();
}
$('#button-input-placeholder').parent().show();
$('#button-input-label').parent().show();
$('#button-input-name').parent().show();
$('#button-input-required').parent().show();
}
if(typeof input != 'undefined') {
$('#button-input-placeholder').val(input.placeholder);
$('#button-input-label').val(input.label);
$('#button-input-name').val(input.name);
$('#button-input-value').val(input.value);
$('#button-input-required').prop('checked', input.required);
}
},
editInput: function(type, value) {
if(type == 'value') {
value = value.replace(/\n/g, '\r\n');
}
inputs = this.getContent().inputs;
inputs[this.inputIndex][type] = value;
this.set('inputs', inputs);
},
editValues: function(type, value) {
this.set(type, value);
}
});