diff --git a/apps/accounts/urls.py b/apps/accounts/urls.py index db75cd2d..e47e2dda 100644 --- a/apps/accounts/urls.py +++ b/apps/accounts/urls.py @@ -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' ), diff --git a/apps/accounts/views.py b/apps/accounts/views.py index 4ad205b1..7cedd3cd 100644 --- a/apps/accounts/views.py +++ b/apps/accounts/views.py @@ -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 = [] diff --git a/static/custom_js/main.js b/static/custom_js/main.js index a5e4ab1b..4dfa6759 100644 --- a/static/custom_js/main.js +++ b/static/custom_js/main.js @@ -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 += ''; - } - }); - $('#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 += ''; + } + }); + + $('#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('================='); + } } diff --git a/static/custom_js/select_tag.js b/static/custom_js/select_tag.js index aab5af84..b7f2fdd9 100644 --- a/static/custom_js/select_tag.js +++ b/static/custom_js/select_tag.js @@ -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 += ''; - } - }); - $('#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 += ''; + } + }); + + $('#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 diff --git a/static/mailing_settings/css/main.css b/static/mailing_settings/css/main.css index d5596784..e20e4706 100644 --- a/static/mailing_settings/css/main.css +++ b/static/mailing_settings/css/main.css @@ -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; diff --git a/static/mailing_settings/js/main.js b/static/mailing_settings/js/main.js index f36d1d54..98ea408d 100644 --- a/static/mailing_settings/js/main.js +++ b/static/mailing_settings/js/main.js @@ -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('' + err + ''); + }) } }); } diff --git a/templates/c_admin/article/blog_form.html b/templates/c_admin/article/blog_form.html index 127b7c17..9a840ed9 100644 --- a/templates/c_admin/article/blog_form.html +++ b/templates/c_admin/article/blog_form.html @@ -15,17 +15,17 @@ - - @@ -43,6 +43,7 @@