(function (global, $, _, Backbone, Dropzone) { 'use strict'; var SettingsView, SettingView, NamePositionView, FieldFormView, FormPaddingsView, FontView, BackgroundColorView, BackgroundImageView, ThemesView, FormStyleView, FormStyleModel, themes = [ { settings: { background: { type: 'color', value: 'transparent' }, font: { family: "Arial", size: 15 }, names_position: 'before', form_paddings: 'no', borders_type: 'rounded', theme_id: 0 }, submit: { color: '#2184db' } }, { settings: { background: { type: 'color', value: '#f6f7fa' }, font: { family: "PT Sans", size: 15 }, names_position: 'before', form_paddings: 'yes', borders_type: 'rounded', theme: { id: 1 } }, submit: { color: '#49b65d' } }, { settings: { background: { type: 'color', value: '#323d45' }, font: { family: "Georgia", size: 15 }, names_position: 'above', form_paddings: 'yes', borders_type: 'rectangular', theme: { id: 2 } }, submit: { color: '#f78d46' } }, { settings: { background: { type: 'image', value: AMOFORMS.images.url + 'bg/bg1.jpg' }, font: { family: "PT Sans", size: 15 }, names_position: 'inside', form_paddings: 'yes', borders_type: 'rounded', theme: { id: 3 } }, submit: { color: '#ff5722' } }, { settings: { background: { type: 'image', value: AMOFORMS.images.url + 'bg/bg3.jpg' }, font: { family: "Times New Roman", size: 15 }, names_position: 'inside', form_paddings: 'yes', borders_type: 'rectangular', theme: { id: 4 } }, submit: { color: '#f78d46' } }, { settings: { background: { type: 'image', value: AMOFORMS.images.url + 'bg/bg2.jpg' }, font: { family: "Lucida Console", size: 15 }, names_position: 'inside', form_paddings: 'yes', borders_type: 'rounded', theme: { id: 5 } }, submit: { color: '#2e95d1' } } ]; SettingView = Backbone.View.extend({ ns: '.amoforms:setting:view', className: 'amoforms', events: { 'click': 'stopPropagation' }, initialize: function (options) { this.options = options || {}; $(document).on('click' + this.ns, _.bind(this.remove, this)); }, _remove: function () {}, remove: function () { if (this._removed) { return; } this._remove(); this._removed = true; $(document).off(this.ns); Backbone.View.prototype.remove.apply(this, arguments); }, render: function () { this._render_template(); this._render(); this.reposition(); }, _render_template: function() { this.$el.html(this.template()); }, _render: function () {}, stopPropagation: function (e) { e.stopPropagation(); }, reposition: function () { var offset = this.options.$button.offset(); this.$el.css({ position: 'absolute', top: offset.top + this.options.$button[0].offsetHeight + 10, left: offset.left - (this.el.offsetWidth/2) + (this.options.$button[0].offsetWidth/2), zIndex: 10 }); }, commit: function (new_settings) { if (this.ajax_sended) { return; } this.ajax_sended = true; $.ajax({ url: ajaxurl, data: { action: AMOFORMS.ajax_action_prefix + 'update_design_settings', form: { id: this.options.form_id, settings: _.extend({}, new_settings) } }, dataType: 'json', type: 'POST' }) .always(_.bind(function () { this.ajax_sended = false; }, this)) .done(_.bind(function (res) { }, this)); } }); /* Themes View */ ThemesView = SettingView.extend({ className: SettingView.prototype.className + ' amoforms__setting-modal-themes', template: _.template( '
 + '.png)
File
', init: _.bind(function () { }, this), success: _.bind(function (file, data) { // @TODO: handle !data.result if (!data.result) { return; } data = _.extend({ image_url: '', thumb_url: '', img_basename: '' }, data); var background = { url: data.image_url, thumb: {url: data.thumb_url}, img_basename: data.img_basename }; AMOFORMS.images.backgrounds.push(background); this._render_template(); this.initDropZone(); }, this) }); }, destroyDropZone: function () { this.drop_zone && this.drop_zone.destroy && this.drop_zone.destroy(); $(document).off('click' + this.ns, '.dz-input-hidden'); }, deleteImages: function (e) { var $this = $(e.currentTarget); e.stopPropagation(); new AMOFORMS.core.confirm({ template_params: { caption: 'Are you sure you want to delete?', accept_btn: 'Yes', decline_btn: 'No' }, accept: _.bind(function (confirm) { if (this.$el.find('.amoforms__captcha').length > 0) { $('[data-type="captcha"]').attr('data-active', 'true'); } $.ajax({ url: ajaxurl, data: { action: AMOFORMS.ajax_action_prefix + 'delete_form_background', img_basename: $this.parent().attr('data-item') }, dataType: 'json', type: 'POST' }).done(_.bind(function () { var nameImg = $this.parent().attr('data-item'); $this.closest('.js-background-choose').remove(); for (var p in AMOFORMS.images.backgrounds) { if (nameImg == AMOFORMS.images.backgrounds[p].img_basename) { AMOFORMS.images.backgrounds.splice(p, 1); } } }, this) ); this.changed = ['image', '']; confirm.done(); }, this), fail: _.bind(function () { confirm.failed(); }, this), }); }, removeImages: function(e) { var $this = $(e.currentTarget); e.remove(); this.commit({ background: { type: 'color', value: color } }); }, clearBackground: function (e) { var color = 'transparent'; e.stopPropagation(); this.options.changeSetting('background-color', color); this.changed = ['color', color]; }, changeBackgroundImage: function (e) { var $this = $(e.currentTarget), val = $this.attr('data-value'); e.stopPropagation(); $this.parent().find('.selected').removeClass('selected'); $this.addClass('selected'); this.options.$button.attr('data-value', val); if (this.is_style) { this.options.$button.trigger('change'); } this.options.changeSetting(this.css_rule, val); this.changed = ['image', this.options.$button.attr('data-value')]; }, _remove: function () { if (!this.changed || !this.changed[0] || !this.changed[1]) { return; } this.commit({ background: { type: this.changed[0], value: this.changed[1] } }); }, destroy: function () { this.destroyDropZone(); SettingView.prototype.destroy.call(this, arguments); } }); /* End of Background Image View */ /* Forms Styles View */ FormStyleView = SettingView.extend({ className: SettingView.prototype.className + ' amoforms__setting-modal-form-css', names: { form_container: 'Form Container', form_row: 'Form Row', background_color: 'Background Color', background_image: 'Background Image', border_color: 'Border Color', border_radius: 'Border Radius', border_style: 'Border Style', border_width: 'Border Width', font_family: 'Font Family', margin: 'Margin', padding: 'Padding', height: 'Height' }, selectors: { save: '.js-amoforms-form-style-save', form: '.amoforms__fields__editor', row: '.amoforms__fields__container', style_el: '#amoforms__custom_style', reset: '.js-amoforms-style-reset' }, events: { 'click .amoforms__fields__expander__item__head': 'expanderToggle', 'click .js-amoforms-form-style-cancel': 'closeModal', 'click .js-amoforms-form-style-save': 'saveForm', 'click [data-type="background-image"]' : 'renderBackgrounds', 'change .amoforms__style_background' : 'updateModel', 'click .js-amoforms-style-reset' : 'resetStyle' }, template: function () { var form = _.map(AMOFORMS.style.form.elements, function (style, name) { var params = { background_color: style['background-color'], border_width: style['border-width'], background_image: style['background-image'], border_radius: style['border-radius'], border_color: style['border-color'], border_style: style['border-style'], font_family: style['font-family'], margin: style.margin, padding: style.padding, height: style.height }, colorpickers = ['background_color', 'border_color', 'color'], lists = ['font_family', 'border_style'], selects = { font_family: [ 'PT Sans', 'Arial', 'Courier New', 'Georgia', 'Lucida Console', 'Tahoma', 'Times New Roman', 'Verdana' ], border_style: [ 'solid', 'dashed', 'dotted', 'double', 'groove', 'ridge', 'inset', 'outset' ] }; var types = _.map(params, function(value, key) { if(value != undefined) { var wrapper = '