newsletter validation fix

remotes/origin/HEAD
ya_dim4ik 9 years ago
parent a74841c18a
commit f5232a8376
  1. 2
      apps/accounts/urls.py
  2. 7
      apps/accounts/views.py
  3. 126
      static/custom_js/main.js
  4. 102
      static/custom_js/select_tag.js
  5. 59
      static/mailing_settings/css/main.css
  6. 16
      static/mailing_settings/js/main.js
  7. 192
      templates/c_admin/article/blog_form.html
  8. 30
      templates/client/newsletters/mailing_settings.html

@ -42,7 +42,7 @@ urlpatterns = patterns('',
url(r'^profile/change-password/', 'accounts.views.change_password'),
url(
r'^profile/subscribe-themes-tags/$',
login_required(UserSubscribeThemesTagsView.as_view()),
UserSubscribeThemesTagsView.as_view(),
name='user_subscribe_themes_tags'
),

@ -543,11 +543,14 @@ class UserSubscribeThemesTagsView(GetUserMixin, TemplateView):
ctx = super(UserSubscribeThemesTagsView, self).get_context_data(**kwargs)
data = []
instance = self.get_user()
user_themes = []
user_tags = []
themes = Theme.objects.language().values('pk', 'name')
user_themes = instance.themes.values_list('pk', flat=True)
user_tags = instance.tags.values_list('pk', flat=True)
if instance is not None:
user_themes = instance.themes.values_list('pk', flat=True)
user_tags = instance.tags.values_list('pk', flat=True)
for theme in themes:
tags = []

@ -325,13 +325,12 @@ $(document).ready(function(){
}
if( $("#id_tag" ).length && $("#id_tag").is('select')) {
try{
$('#id_tag').select2({
placeholder: "Теги",
width: '550px',
multiple: true,
ajax: {
placeholder: "Теги",
width: '550px',
multiple: true,
ajax: {
url: "/admin/theme/tag/search/",
dataType: "json",
quietMillis: 200,
@ -339,9 +338,11 @@ $(document).ready(function(){
data: function(term, page, theme){
var theme = $('#id_theme').serialize();
return {term: term,
page: page,
theme: theme};
return {
term: term,
page: page,
theme: theme
};
},
results: function (data) {
@ -365,10 +366,12 @@ $(document).ready(function(){
});
});
callback(data);
}
});
} catch (e) {
console.log('===== Error =====');
console.warn(e);
console.log('=================')
}
@ -377,52 +380,55 @@ $(document).ready(function(){
*/
// theme change
$('#id_theme').change(function(){
$.get(
"/admin/ajax_tag/", {'id': $(this).serialize()}, function(data){
var optionValues = [];
var getValues = [];
var selectedValues = []
//push values sended from server in array
$.each(data, function(i, elem){
getValues.push(elem[0].toString())
});
//delete options if they aren't in getvalues
//otherwise push it in array
//also push in array already selected values
$('#id_tag option').each(function() {
var check = $.inArray($(this), getValues);
if ($(this).is(':selected') ){
selectedValues.push($(this).val())
}
if (check == -1){
$(this).remove()
}
else{
optionValues.push($(this).val());
}
});
//generate new options
//old options unchanged
var html = ''
$.each(data, function(i, elem){
var check = $.inArray(elem[0].toString(), optionValues);
if (check == -1){
html += '<option value="';
html += elem[0];
html += '">';
html += elem[1];
html += '</option>';
}
});
$('#id_tag').append(html);
//select previous selected values
$('#id_tag option').each(function() {
var check = $.inArray($(this).val(), selectedValues)
if (check != -1){
$(this).attr('selected', 'selected');
}
});
$.get("/admin/ajax_tag/", {'id': $(this).serialize()}, function(data){
var optionValues = [];
var getValues = [];
var selectedValues = [];
//push values sended from server in array
$.each(data, function(i, elem){
getValues.push(elem[0].toString())
});
//delete options if they aren't in getvalues
//otherwise push it in array
//also push in array already selected values
$('#id_tag option').each(function() {
var check = $.inArray($(this), getValues);
if ($(this).is(':selected') ){
selectedValues.push($(this).val())
}
if (check == -1){
$(this).remove()
}
else{
optionValues.push($(this).val());
}
});
//generate new options
//old options unchanged
var html = ''
$.each(data, function(i, elem){
var check = $.inArray(elem[0].toString(), optionValues);
if (check == -1){
html += '<option value="';
html += elem[0];
html += '">';
html += elem[1];
html += '</option>';
}
});
$('#id_tag').append(html);
//select previous selected values
$('#id_tag option').each(function() {
var check = $.inArray($(this).val(), selectedValues)
if (check != -1){
$(this).attr('selected', 'selected');
}
});
});//end get
});//end change
@ -499,7 +505,11 @@ $(document).ready(function(){
allowClear: true
});
} catch (e){}
} catch (e){
console.log('===== Error =====');
console.warn(e);
console.log('=================');
}
}

@ -1,52 +1,56 @@
// replace
$(document).ready(function(){
$('#id_theme').change(function(){
$.get(
"/admin/ajax_tag/", {'id': $(this).serialize()}, function(data){
var optionValues = [];
var getValues = [];
var selectedValues = []
//push values sended from server in array
$.each(data, function(i, elem){
getValues.push(elem[0].toString())
});
//delete options if they aren't in getvalues
//otherwise push it in array
//also push in array already selected values
$('#id_tag option').each(function() {
var check = $.inArray($(this), getValues);
if ($(this).is(':selected') ){
selectedValues.push($(this).val())
}
if (check == -1){
$(this).remove()
}
else{
optionValues.push($(this).val());
}
});
//generate new options
//old options unchanged
var html = ''
$.each(data, function(i, elem){
var check = $.inArray(elem[0].toString(), optionValues);
$('#id_theme').change(function(){
$.get("/admin/ajax_tag/", {'id': $(this).serialize()}, function(data){
var optionValues = [];
var getValues = [];
var selectedValues = [];
if (check == -1){
html += '<option value="';
html += elem[0];
html += '">';
html += elem[1];
html += '</option>';
}
});
$('#id_tag').append(html);
//select previous selected values
$('#id_tag option').each(function() {
var check = $.inArray($(this).val(), selectedValues)
if (check != -1){
$(this).attr('selected', 'selected');
}
});
});//end get
});//end change
});//end ready
//push values sended from server in array
$.each(data, function(i, elem){
getValues.push(elem[0].toString())
});
//delete options if they aren't in getvalues
//otherwise push it in array
//also push in array already selected values
$('#id_tag option').each(function() {
var check = $.inArray($(this), getValues);
if ($(this).is(':selected') ){
selectedValues.push($(this).val())
}
if (check == -1){
$(this).remove()
}
else{
optionValues.push($(this).val());
}
});
//generate new options
//old options unchanged
var html = '';
$.each(data, function(i, elem){
var check = $.inArray(elem[0].toString(), optionValues);
if (check == -1){
html += '<option value="';
html += elem[0];
html += '">';
html += elem[1];
html += '</option>';
}
});
$('#id_tag').append(html);
//select previous selected values
$('#id_tag option').each(function() {
var check = $.inArray($(this).val(), selectedValues)
if (check != -1){
$(this).attr('selected', 'selected');
}
});
});//end get
});//end change
});//end ready

@ -842,44 +842,57 @@ a.themes_trigger{
}
.pr-form .pr-row{
overflow:hidden;
/*overflow:hidden;*/
margin:0 0 14px;
}
.pr-form .pr-row:after{
content: '';
display: block;
clear: both;
}
.pr-input{
float:left;
height:46px;
width:247px;
padding:0 44px 0 18px;
display: inline-block;
vertical-align: bottom;
margin:0 0 0 13px;
background:#fff;
border-radius:4px;
position:relative;
}
.errorlist{
list-style: none;
}
.text_error{
display: block;
text-align: center;
font-weight: 300;
font-size: 14px;
color: #bd2626;
padding-bottom: 3px;
}
.pr-input.field_error input{
box-shadow: 0 0 0 2px #f00;
}
.pr-input:first-child{
margin:0;
}
.pr-input:after{
content:'';
position:absolute;
top:13px;
right:14px;
width:20px;
height:20px;
}
.pr-input.pr-name:after{
background:url(../images/pr-icon02.png) no-repeat 50% 50%;
.pr-input.pr-name input{
background:#fff url(../images/pr-icon02.png) no-repeat 210px 50%;
}
.pr-input.pr-email:after{
background:url(../images/pr-icon03.png) no-repeat 50% 50%;
.pr-input.pr-email input{
background:#fff url(../images/pr-icon03.png) no-repeat 210px 50%;
}
.pr-form input{
.pr-form input {
padding:0;
border:none;
color:#000;
font:17px/21px 'pf_dindisplay_promedium', Arial, Helvetica, sans-serif;
height:24px;
margin:12px 0 0;
height:46px;
width:247px;
padding:0 44px 0 18px;
background:#fff;
border-radius:4px;
position:relative;
}
.pr-form input:focus::-webkit-input-placeholder {
color:transparent;

@ -2,12 +2,24 @@
function sendForm () {
var $form = $('#mailing_settings_form');
$form.find('.field_error').removeClass('field_error');
$form.find('.text_error').remove();
$.ajax({
url: $form.attr('action'),
type: $form.attr('method'),
data: $form.serializeArray(),
success: function(response){
console.log(response);
// success: function(response){
// console.log(response);
// },
error: function (error) {
var form_errors = error.responseJSON.form_errors;
$.each(form_errors, function (field, err) {
var $field = $form.find('#id_' + field);
$field.addClass('field_error');
$field.parent('.pr-input').prepend('<span class="text_error">' + err + '</span>');
})
}
});
}

@ -15,17 +15,17 @@
<link href="{% static 'js/datetimepicker/css/datetimepicker.css' %}" rel="stylesheet"/>
<script src="{% static 'js/datetimepicker/js/bootstrap-datetimepicker.js' %}"></script>
<script>
$(document).ready(function(){
$('#id_publish_date').datetimepicker({
<script>
$(document).ready(function(){
$('#id_publish_date').datetimepicker({
todayHighlight: true,
format : 'yyyy-mm-dd',
minView:2
});
});
});
</script>
</script>
<link rel="stylesheet" href="{% static 'jQuery-filer/css/jquery.filer.css' %}">
<link rel="stylesheet" href="{% static 'jQuery-filer/css/jquery.filer-dragdropbox-theme.css' %}">
<script src="{% static 'jQuery-filer/js/jquery.filer.js' %}"></script>
@ -43,6 +43,7 @@
<div class="box-header well">
<h2><i class="icon-pencil"></i> {% trans "Основная информация" %}</h2>
</div>
<div class="box-content">
{# main_title #}
@ -50,35 +51,38 @@
<div class="control-group {% if form.publish_date.errors %}error{% endif %}">
<label class="control-label"><b>{{ form.publish_date.label }}:</b></label>
<div class="controls">
{{ form.publish_date }}
<span class="help-inline">{{ form.publish_date.errors }}</span>
</div>
<div class="controls">
{{ form.publish_date }}
<span class="help-inline">{{ form.publish_date.errors }}</span>
</div>
</div>
{% if not article %}
<div class="control-group {% if form.slug.errors %}error{% endif %}">
<label class="control-label">{{ form.slug.label }}:</label>
<div class="control-group {% if form.slug.errors %}error{% endif %}">
<label class="control-label">{{ form.slug.label }}:</label>
<div class="controls">
{{ form.slug }}
<span class="help-inline">{{ form.slug.errors }}</span>
</div>
</div>
</div>
{% endif %}
{# theme #}
<div class="control-group {% if form.theme.errors %}error{% endif %}">
<label class="control-label"><b>{{ form.theme.label }}:</b></label>
<div class="controls">
{{ form.theme }}
<span class="help-inline">{{ form.theme.errors }}</span>
</div>
<div class="controls">
{{ form.theme }}
<span class="help-inline">{{ form.theme.errors }}</span>
</div>
</div>
{# tag #}
<div class="control-group {% if form.tag.errors %}error{% endif %}">
<label class="control-label">{{ form.tag.label }}:</label>
<div class="controls">
{{ form.tag }}
<span class="help-inline">{{ form.tag.errors }}</span>
</div>
<div class="controls">
{{ form.tag }}
<span class="help-inline">{{ form.tag.errors }}</span>
</div>
</div>
{# exposition #}
{% if form.exposition %}
@ -160,78 +164,78 @@
{% block bot_scripts %}
<script>
$(document).ready(function(){
$('#id_exposition').select2({
placeholder: "Выставка",
multiple: false,
width: 'element',
ajax: {
url: "/admin/exposition/search/",
width: '550px',
dataType: "json",
quietMillis: 200,
data: function(term, page, theme){
return {term: term,
page: page};
},
results: function (data) {
var results = [];
$.each(data, function(index, item){
results.push({
id: item.id,
text: item.label
});
});
return {results: results};
}
},
initSelection : function(element, callback) {
var id= $(element).val();
var text = $(element).attr('data-init-text');
callback({id: id, text:text});
}
});
$('#id_conference').select2({
placeholder: "Конференция",
multiple: false,
width: 'element',
ajax: {
url: "/admin/conference/search/",
width: '550px',
dataType: "json",
quietMillis: 200,
data: function(term, page, theme){
return {term: term,
page: page};
},
results: function (data) {
var results = [];
$.each(data, function(index, item){
results.push({
id: item.id,
text: item.label
});
});
return {results: results};
}
},
initSelection : function(element, callback) {
var id= $(element).val();
var text = $(element).attr('data-init-text');
callback({id: id, text:text});
}
});
});
</script>
<script>
$(document).ready(function(){
$('#id_exposition').select2({
placeholder: "Выставка",
multiple: false,
width: 'element',
ajax: {
url: "/admin/exposition/search/",
width: '550px',
dataType: "json",
quietMillis: 200,
data: function(term, page, theme){
return {term: term,
page: page};
},
results: function (data) {
var results = [];
$.each(data, function(index, item){
results.push({
id: item.id,
text: item.label
});
});
return {results: results};
}
},
initSelection : function(element, callback) {
var id= $(element).val();
var text = $(element).attr('data-init-text');
callback({id: id, text:text});
}
});
$('#id_conference').select2({
placeholder: "Конференция",
multiple: false,
width: 'element',
ajax: {
url: "/admin/conference/search/",
width: '550px',
dataType: "json",
quietMillis: 200,
data: function(term, page, theme){
return {term: term,
page: page};
},
results: function (data) {
var results = [];
$.each(data, function(index, item){
results.push({
id: item.id,
text: item.label
});
});
return {results: results};
}
},
initSelection : function(element, callback) {
var id= $(element).val();
var text = $(element).attr('data-init-text');
callback({id: id, text:text});
}
});
});
</script>
{% endblock %}

@ -60,8 +60,15 @@
<div class="pr-form">
<fieldset>
<div class="pr-row">
<span class="pr-input pr-name">{{ form.first_name }}</span>
<span class="pr-input pr-email" >{{ form.email }}</span>
<span class="pr-input pr-name {% if form.first_name.errors %}field_error{% endif %}">
{% if form.first_name.errors %}<span class="text_error">{{ form.first_name.errors }}</span>{% endif %}
{{ form.first_name }}
</span>
<span class="pr-input pr-email {% if form.email.errors %}field_error{% endif %}">
{% if form.email.errors %}<span class="text_error">{{ form.email.errors }}</span>{% endif %}
{{ form.email }}
</span>
</div>
<button>{% trans 'Подписаться' %}</button>
</fieldset>
@ -195,11 +202,20 @@
</div>
<div class="button_block">
<div class="container">
<div class="tos">
<strong>{% trans 'Нажимая «Подписаться», вы соглашаетесь получать' %} <br /> {% trans 'материалы компании Expomap на свой электронный адрес' %} </strong>
<a href="{% url 'termsofuse' %}" style="color:#a2a2a2;">{% trans "Пользовательское соглашение" %}</a>
</div>
<button type="submit">{% trans "Сохранить" %}</button>
{% if not user.is_authenticated %}
<div class="tos">
<strong>{% trans 'Нажимая «Подписаться», вы соглашаетесь получать' %} <br /> {% trans 'материалы компании Expomap на свой электронный адрес' %} </strong>
<a href="{% url 'termsofuse' %}" style="color:#a2a2a2;">{% trans "Пользовательское соглашение" %}</a>
</div>
{% endif %}
<button type="submit">
{% if user.is_authenticated %}
{% trans "Сохранить" %}
{% else %}
{% trans 'Подписаться' %}
{% endif %}
</button>
<a href="?unsibscribe=1">{% trans 'Не хочу быть в курсе событий (отписаться от всего)' %}</a>
</div>
</div>

Loading…
Cancel
Save