Skip to content
Browse files

fixed many things

  • Loading branch information...
1 parent 7cbbc35 commit 3f79909bd205abc0e3eee6b4a1b9d843e5273b7f @Guest007 committed Feb 23, 2014
Showing with 601 additions and 451 deletions.
  1. +23 −27 templates/easy-form.html
  2. +1 −15 templates/fast-form.html
  3. +54 −54 templates/helpers.html
  4. +16 −3 theme/css/template.css
  5. +21 −3 theme/css/template.less
  6. +486 −349 theme/js/init.js
View
50 templates/easy-form.html
@@ -1,5 +1,5 @@
- <form id="easy_form" class="jClever filter calc" action="{% url 'ajax-save-order' step=12 %}" method="POST">
+ <form id="easy_form" class="jClever filter calc" action="{% url 'ajax-save-order' step=12 %}" method="POST" novalidate>
{% csrf_token %}
<input type="hidden" id="id" name="id" class="common" value="{{ object.id }}">
<ul class="visual_first">
@@ -14,7 +14,7 @@
<span></span>
<i class="fa fa-times"></i>
</span>
- <small>
+ <small class="question">
<i class="fa fa-question"></i>
<span class="first_flag"><i class="fa fa-circle"></i></span>
</small>
@@ -31,7 +31,7 @@
<span></span>
<i class="fa fa-times"></i>
</span>
- <small>
+ <small class="question">
<i class="fa fa-question"></i>
<span class="second_flag"><i class="fa fa-circle"></i></span>
</small>
@@ -48,7 +48,7 @@
<span></span>
<i class="fa fa-times"></i>
</span>
- <small>
+ <small class="question">
<i class="fa fa-question"></i>
<span class="third_flag"><span></span><i class="fa fa-circle"></i></span>
</small>
@@ -65,7 +65,7 @@
<span></span>
<i class="fa fa-times"></i>
</span>
- <small>
+ <small class="question">
<i class="fa fa-question"></i>
<span class="fourth_flag"><span></span><i class="fa fa-circle"></i></span>
</small>
@@ -84,7 +84,7 @@
<span></span>
<i class="fa fa-times"></i>
</span>
- <small>
+ <small class="question">
<i class="fa fa-question"></i>
<span class="fifth_flag"><i class="fa fa-circle"></i></span>
</small>
@@ -101,7 +101,7 @@
<span></span>
<i class="fa fa-times"></i>
</span>
- <small>
+ <small class="question">
<i class="fa fa-question"></i>
<span class="sixth_flag"><i class="fa fa-circle"></i></span>
</small>
@@ -118,7 +118,7 @@
<span></span>
<i class="fa fa-times"></i>
</span>
- <small>
+ <small class="question">
<i class="fa fa-question"></i>
<span class="seventh_flag"><i class="fa fa-circle"></i></span>
</small>
@@ -135,36 +135,37 @@
<span></span>
<i class="fa fa-times"></i>
</span>
- <small>
+ <small class="question">
<i class="fa fa-question"></i>
<span class="eighth_flag"><i class="fa fa-circle"></i></span>
</small>
<p>Скрейтч панель</p>
</li>
</ul>
<ul class="order">
+ <li class="prompt">Поля отмеченные звёздочкой - обязательны для заполнения.</li>
<li class="info"></li>
<li class="printing"></li>
<li class="time"></li>
<li>
- <i class="error">Минимальное количество - 500 экземпляров</i>
- <label for="count">Тираж:</label>
- <input type="text" class="edition" id="count" name="count" placeholder="500" value="{{ object.draw }}">
+
+ <label for="i_01"><i class="fa fa-asterisk"></i> Тираж: </label>
+ <input type="text" class="edition for_valid" id="i_01" name="count" placeholder="500" value="{{ object.draw }}">
</li>
<li>
- <label for="color">Цвет:</label>
+ <label for="s_01">Цвет:</label>
<div class="select color">
- <select name="colors" class="calc">
+ <select name="colors" id="s_01">
{% for item in color %}
<option value="{{ item.id }}"{% if templ.color_front and templ.color_front.id == item.id %}selected="selected"{% endif %} data-price="{{ item.cost }}">{{ item.name }}</option>
{% endfor %}
</select>
</div>
</li>
<li>
- <label>Материал:</label>
+ <label for="s_02">Материал:</label>
<div class="select materials">
- <select name="materials" class="calc">
+ <select name="materials" id="s_02">
{% for item in materials %}
<option value="{{ item.id }}" {% if templ.material and templ.material.id == item.id %}selected="selected"{% endif %} data-price="{{ item.cost }}">{{ item.name }}</option>
{% endfor %}
@@ -176,24 +177,19 @@
<p class="sum">0 руб.</p>
</li>
<li>
- <label>ФИО:</label>
- <input type="text" name="user" value="{{ object.fio }}">
+ <label for="i_02"><i class="fa fa-asterisk"></i> ФИО:</label>
+ <input type="text" name="user" id="i_02" value="{{ object.fio }}" class="for_valid">
</li>
<li>
- <label>Телефон:</label>
- <input type="text" name="phone" value="{{ object.phone }}">
+ <label for="i_03"><i class="fa fa-asterisk"></i> Телефон:</label>
+ <input type="text" name="phone_" id="i_03" value="{{ object.phone }}" class="for_valid">
</li>
<li>
- <label>Email:</label>
- <input type="email" name="email" value="{{ object.email }}">
+ <label for="i_04"><i class="fa fa-asterisk"></i> Email:</label>
+ <input type="email" name="email" id="i_04" value="{{ object.email }}" class="for_valid">
</li>
<li>
-<!--
- <a href="#" class="next_step">Заказать</a>
--->
-
<input type="submit" name="order" value="Заказать" class="next_step">
-
</li>
</ul>
<input type="hidden" name="foil" class="flag" value="">
View
16 templates/fast-form.html
@@ -1,5 +1,5 @@
- <form id='fast_form' class="jClever calc" action="{% url 'ajax-save-order' step=2 %}" method="POST" enctype="multipart/form-data">
+ <form id='fast_form' class="jClever calc" action="{% url 'ajax-save-order' step=2 %}" method="POST" enctype="multipart/form-data" novalidate>
{% csrf_token %}
<input type="hidden" id="id" name="id" class="common" value="{{ object.id }}">
@@ -203,19 +203,5 @@
</form>
-<script type="application/javascript">
- $("#file_data").change(function() {
- var options = {
- url: '/uploadfile/',
- replaceTarget: true,
- target: $('#fd'),
- success: function(data) {
- /*alert(data);*/
- }
- };
-
- $('#fast_form').ajaxSubmit(options);
- });
-</script>
View
108 templates/helpers.html
@@ -1,54 +1,54 @@
-
-<div class="order">
- <span>Ваш заказ<small class="close_order"><i class="fa fa-times"></i></small></span>
- <ul class="info">
- <li>
- <span class="foil"><i class="fa {% if templ.foil %}fa-check{% else %}fa-times{% endif %}"></i>Тиснение фольгой</span>
- <span class="emboss"><i class="fa {% if templ.emboss %}fa-check{% else %}fa-times{% endif %}"></i>Эмбоссирование</span>
- <span class="sign"><i class="fa {% if templ.sign %}fa-check{% else %}fa-times{% endif %}"></i>Полоса для подписи</span>
- <span class="indent"><i class="fa {% if templ.indent %}fa-check{% else %}fa-times{% endif %}"></i>Индент печать</span>
- <span class="print_num"><i class="fa {% if templ.print_num %}fa-check{% else %}fa-times{% endif %}"></i>Печатный номер</span>
- <span class="magnet"><i class="fa {% if templ.magnet %}fa-check{% else %}fa-times{% endif %}"></i>Магнитная полоса</span>
- <span class="barcode"><i class="fa {% if templ.barcode %}fa-check{% else %}fa-times{% endif %}"></i>Штрих код</span>
- <span class="scratch"><i class="fa {% if templ.scratch %}fa-check{% else %}fa-times{% endif %}"></i>Скрейтч панель</span>
- <span class="chip"><i class="fa {% if templ.chip %}fa-check{% else %}fa-times{% endif %}"></i>Карта с чипом</span>
- <span class="uv"><i class="fa {% if templ.uv %}fa-check{% else %}fa-times{% endif %}"></i>Печать УФ краской</span>
- </li>
- <li>
- <span><span>Тираж</span>{{ object.draw }}</span>
- <span><span>Цвета</span>{{ color_front }}{% if color_back %}+{{ color_back }}{% else %}{% endif %}</span>
- <span><span>Материал</span>{{ material }}</span>
- <span><span>Ламинция</span>{% if lamination %}{{ lamination }}{% else %}Нет{% endif %}</span>
- <span><span>ФИО</span>{{ object.FIO }}</span>
- <span><span>Телефон</span>{{ object.phone }}</span>
- <span><span>Email</span>{{ object.email }}</span>
- <span class="full_price"><span>Сумма заказа</span>{{ object.cost }} руб.</span>
- </li>
- </ul>
- <ul>
- <li>
- <span>Способ оплаты</span>
- <div class="radio">
- <input type="radio">
- <label>Физическое лицо</label>
- </div>
- <div class="radio">
- <input type="radio">
- <label>Юридическое лицо</label>
- </div>
- </li>
- <li>
- <div class="select">
- <select>
- <option value="1">Безналичный расчёт</option>
- <option value="2">Наличный расчёт</option>
- </select>
- </div>
- <input type="submit" value="Отправить заказ">
- <!--
- <a href="#" class="next_step">Получить документы</a>
- -->
- </li>
- </ul>
-</div>
-
+<form class="jClever">
+ <div class="order">
+ <span>Ваш заказ<small class="close_order"><i class="fa fa-times"></i></small></span>
+ <ul class="info">
+ <li>
+ <span class="foil"><i class="fa {% if templ.foil %}fa-check{% else %}fa-times{% endif %}"></i>Тиснение фольгой</span>
+ <span class="emboss"><i class="fa {% if templ.emboss %}fa-check{% else %}fa-times{% endif %}"></i>Эмбоссирование</span>
+ <span class="sign"><i class="fa {% if templ.sign %}fa-check{% else %}fa-times{% endif %}"></i>Полоса для подписи</span>
+ <span class="indent"><i class="fa {% if templ.indent %}fa-check{% else %}fa-times{% endif %}"></i>Индент печать</span>
+ <span class="print_num"><i class="fa {% if templ.print_num %}fa-check{% else %}fa-times{% endif %}"></i>Печатный номер</span>
+ <span class="magnet"><i class="fa {% if templ.magnet %}fa-check{% else %}fa-times{% endif %}"></i>Магнитная полоса</span>
+ <span class="barcode"><i class="fa {% if templ.barcode %}fa-check{% else %}fa-times{% endif %}"></i>Штрих код</span>
+ <span class="scratch"><i class="fa {% if templ.scratch %}fa-check{% else %}fa-times{% endif %}"></i>Скрейтч панель</span>
+ <span class="chip"><i class="fa {% if templ.chip %}fa-check{% else %}fa-times{% endif %}"></i>Карта с чипом</span>
+ <span class="uv"><i class="fa {% if templ.uv %}fa-check{% else %}fa-times{% endif %}"></i>Печать УФ краской</span>
+ </li>
+ <li>
+ <span><span>Тираж</span>{{ object.draw }}</span>
+ <span><span>Цвета</span>{{ color_front }}{% if color_back %}+{{ color_back }}{% else %}{% endif %}</span>
+ <span><span>Материал</span>{{ material }}</span>
+ <span><span>Ламинция</span>{% if lamination %}{{ lamination }}{% else %}Нет{% endif %}</span>
+ <span><span>ФИО</span>{{ object.FIO }}</span>
+ <span><span>Телефон</span>{{ object.phone }}</span>
+ <span><span>Email</span>{{ object.email }}</span>
+ <span class="full_price"><span>Сумма заказа</span>{{ object.cost }} руб.</span>
+ </li>
+ </ul>
+ <ul>
+ <li>
+ <span>Способ оплаты</span>
+ <div class="radio">
+ <input type="radio">
+ <label>Физическое лицо</label>
+ </div>
+ <div class="radio">
+ <input type="radio">
+ <label>Юридическое лицо</label>
+ </div>
+ </li>
+ <li>
+ <div class="select">
+ <select>
+ <option value="1">Безналичный расчёт</option>
+ <option value="2">Наличный расчёт</option>
+ </select>
+ </div>
+ <input type="submit" value="Отправить заказ">
+ <!--
+ <a href="#" class="next_step">Получить документы</a>
+ -->
+ </li>
+ </ul>
+ </div>
+</form>
View
19 theme/css/template.css
@@ -924,6 +924,16 @@ body.under_overlay > div.data_wrap > div > .data_container > .data_checking.file
top: -39px !important;
background: url('../images/order_printing.png') no-repeat center center;
}
+.wrap_all > article > section.order > div > div > form > ul.order > li.prompt {
+ position: absolute !important;
+ bottom: 0;
+ left: 30px;
+ color: #fff;
+ font: 10px/30px 'Open Sans', sans-serif;
+ margin: 0 !important;
+ width: auto;
+ height: auto !important;
+}
.wrap_all > article > section.order > div > div.easy_form {
width: 944px;
padding: 0 29px;
@@ -1163,13 +1173,18 @@ body.under_overlay > div.data_wrap > div > .data_container > .data_checking.file
float: left;
margin: -25px 18px 75px 0;
height: 80px;
- position: relative;
}
.wrap_all > article > section.order > div > div.easy_form > form > ul.order > li > label {
display: block;
font: 600 14px/48px 'Open Sans', sans-serif;
color: #fff;
}
+.wrap_all > article > section.order > div > div.easy_form > form > ul.order > li > label > i {
+ font-size: 10px;
+}
+.wrap_all > article > section.order > div > div.easy_form > form > ul.order > li > label.error {
+ background: #22B77E;
+}
.wrap_all > article > section.order > div > div.easy_form > form > ul.order > li > input {
height: 36px;
display: block;
@@ -1818,10 +1833,8 @@ i.error {
border-radius: 6px 6px 6px 0;
background: #22B77E;
opacity: 0.8;
- width: 200px;
color: #fff;
font: 600 14px/14px 'Open Sans', sans-serif;
- top: -10px;
z-index: 99;
}
i.error.show {
View
24 theme/css/template.less
@@ -1009,6 +1009,16 @@ body {
top: -39px !important;
background: url('../images/order_printing.png') no-repeat center center;
}
+ &.prompt {
+ position: absolute !important;
+ bottom: 0;
+ left: 30px;
+ color: #fff;
+ font: 10px/30px @main_font;
+ margin: 0 !important;
+ width: auto;
+ height: auto !important;
+ }
}
}
}
@@ -1260,11 +1270,19 @@ body {
float: left;
margin: -25px 18px 75px 0;
height: 80px;
- position: relative;
+ //position: relative;
& > label {
display: block;
font: 600 14px/48px @main_font;
color: #fff;
+ & > i {
+ font-size: 10px;
+
+ }
+ &.error {
+ background: #22B77E;
+
+ }
}
& > input {
height: 36px;
@@ -1988,10 +2006,10 @@ i.error {
border-radius: 6px 6px 6px 0;
background: #22B77E;
opacity: 0.8;
- width: 200px;
+ //width: 200px;
color: #fff;
font: 600 14px/14px @main_font;
- top: -10px;
+ //top: -10px;
z-index: 99;
&.show {
display: inline-block;
View
835 theme/js/init.js
@@ -1,271 +1,406 @@
//Калькулятор
-function calc(){
- $('form.calc').each(function(){
- //сбрасываем значения hidden
- $('input[type="hidden"]').not('.ratio').val(0);
- //присваиваем значение по умолчанию селектам
- $('select.calc').each(function(){
- var this_name = $(this).attr('name')
- default_val = $(this).find('option:selected').data('price').replace(',','.');
- //console.log(default_val);
- $('input[name="'+this_name+'"]').val(default_val);
- })
- $('p.sum').html('0.00 руб.');
- //min тираж - 500
- $('input[name="count"]').val('')
- $('input[name="count_hidden"]').val(0);
- //переключаем состояние атрибута, передаем значение в hidden, следим за измененнием
- $('span.flag').click(function(){
- var this_flag = $(this),
- flag_id = $(this).attr('id');
- this_flag.toggleClass('active');
- if($(this).hasClass('active')){
- $(this).children('i').removeClass('fa-times').addClass('fa-check');
- //console.log("qwertyui", parseFloat($(this).data('price')));
- $('input[name="'+flag_id+'"]').val(parseFloat($(this).data('price').replace(',','.'))).trigger('change');
+(function(){
+ $.fn.calc = function(){
+
+ return this.each(function(){
+ var $this = $(this),
+ valid = null,
+ hidden = $(this).find('input[type="hidden"]'),
+ select = $(this).find('select'),
+ checkbox = $(this).find('input[type="checkbox"]');
+
+
+ //console.log(select);
+ hidden.not('.ratio').val(0);
+ $this.find('input[name="count"]').val('');
+ $this.find('input[name="count_hidden"]').val(0);
+
+ select.each(function(){
+ var self = $(this),
+ self_name = $(this).attr('name'),
+ self_val = $(this).find('option:selected').data('price').replace(',','.');
+ $this.find('input[name="'+self_name+'"]').val(self_val);
+ });
+
+ select.change(function(){
+ var self_name = $(this).attr('name'),
+ self_val = $(this).find('option:selected').data('price').replace(',','.');
+ $this.find('input[name="'+self_name+'"]').val(parseFloat(self_val)).trigger('change');
+ });
+
+ if($this.find('span.flag').length > 0) {
+ $('span.flag').click(function(){
+ var self = $(this),
+ self_id = $(this).attr('id');
+ self.toggleClass('active');
+ if(self.hasClass('active')){
+ self.children('i').removeClass('fa-times').addClass('fa-check');
+ $this.find('input[name="'+self_id+'"]').val(parseFloat(self.data('price').replace(',','.')));
+ }
+ else{
+ if(self.children('i').hasClass('fa-check')){
+ self.children('i').removeClass('fa-check').addClass('fa-times');
+ }
+ $this.find('input[name="'+self_id+'"]').val('0');
+ };
+ $this.find('input[name="'+self_id+'"]').trigger('change');
+ });
+ $this.find('small.question').click(function(){
+ $(this).toggleClass('active');
+ });
}
- else{
- if($(this).children('i').hasClass('fa-check')){
- $(this).children('i').removeClass('fa-check').addClass('fa-times');
- }
- $('input[name="'+flag_id+'"]').val('0').trigger('change');
+ else {
+ checkbox.change(function(){
+ var self = $(this),
+ self_name = $(this).attr('name'),
+ //this_checked = $(this).prop('checked'),
+ self_val = $(this).data('price').replace(',','.');
+ if(self.is(':checked')){
+ $this.find('input[name="'+self_name+'"]').val(parseFloat(self_val));
+ }
+ else{
+ $this.find('input[name="'+self_name+'"]').val(0);
+ }
+
+ });
}
- });
- //вводим тираж, следим за его значением (min - 500)
- $('input[name="count"]').keyup(function(){
- var count_val = parseFloat($(this).val())||0,
- this_name = $(this).attr('name');
- //error mes.
- if(count_val < 500){
- $(this).addClass('error').siblings('i').addClass('show');
- $('input[name="count_hidden"]').val(0);
+
+ $this.find('input[name="count"]').keyup(function(){
+ var self = $(this),
+ self_val = parseFloat($(this).val())||0;
+ if(self_val < 500){
+ /*
+ if(self.siblings('i.error').length == 0){
+ self.addClass('error')
+ self.parent().append('<i class="error show">Минимальное значение 500 экземпляров</i>');
+ self.siblings('i.error').css({
+ 'left': self.parent().position().left,
+ 'top': self.parent().position().top - 36
+ });
+ }
+ */
+ $this.find('input[name="count_hidden"]').val(0).trigger('change');
+ }
+ else{
+ //self.removeClass('error').siblings('i.error').remove();
+ $this.find('input[name="count_hidden"]').val(parseFloat(self_val)).trigger('change');
+ };
+ });
+
+ if($this.find('input[type="file"]').length > 0){
+ $("#file_data").change(function() {
+ var options = {
+ url: '/uploadfile/',
+ replaceTarget: true,
+ target: $('#fd'),
+ success: function(data) {
+ }
+ };
+ $this.ajaxSubmit(options);
+ });
}
- else{
- $(this).removeClass('error').siblings('i').removeClass('show');
- $('input[name="'+this_name+'_hidden"]').val(parseFloat(count_val)).trigger('change');
- };
- });
- //следим за изменением значений селектов
- $('select').change(function(){
- var this_name = $(this).attr('name'),
- this_val = $(this).find("option:selected").data('price').replace(',','.');
- $('input[name="'+this_name+'"]').val(parseFloat(this_val)).trigger('change');
- });
+ hidden.change(function(){
+ var flag_val = 0,
+ count_val = parseFloat($this.find('input[name="count_hidden"]').val()),
+ color_val = parseFloat($this.find('input[name="colors"]').val()),
+ material_val = parseFloat($this.find('input[name="materials"]').val()),
+ lamination_val = parseFloat($this.find('input[name="lamination"]').val()),
+ face_color = parseFloat($this.find('input[name="color_front"]').val()),
+ back_color = parseFloat($this.find('input[name="color_back"]').val()),
+ total_colors = color_val + face_color + back_color;
- $('input[type="checkbox"]').change(function(){
- var this_name = $(this).attr('name'),
- this_checked = $(this).prop('checked'),
- this_val = $(this).data('price').replace(',','.');
- if($(this).is(':checked')){
- $('input[name="'+this_name+'"]').val(parseFloat(this_val));
- }
- else{
- $('input[name="'+this_name+'"]').val(0);
- }
- $('input[type="hidden"]').trigger('change');
- });
- //счетаем
- $('input[type="hidden"]').change(function(){
- var flag_val = 0,
- count_val = parseFloat($('input[name="count_hidden"]').val()),
- color_val = parseFloat($('input[name="colors"]').val()),
- material_val = parseFloat($('input[name="materials"]').val()),
- lamination_val = parseFloat($('input[name="lamination"]').val()),
- face_color = parseFloat($('input[name="color_front"]').val()),
- back_color = parseFloat($('input[name="color_back"]').val()),
- total_colors = color_val + face_color + back_color;
- $('input.flag').each(function() {
- flag_val += parseFloat($(this).val())||0;
- });
- var values = {},
- range_array =[];
- $('input.ratio').each(function() {
- var this_val = parseFloat($(this).val().replace(',','.'));
- this_name = parseFloat($(this).attr('name')),
- q = count_val-this_name;
- if(q > 0){
- values[this_val] = q;
- range_array.push(q);
- }
+ $this.find('input.flag').each(function() {
+ flag_val += parseFloat($(this).val())||0;
+ });
+ var values = {},
+ range_array =[];
+ $this.find('input.ratio').each(function() {
+ var self_val = parseFloat($(this).val().replace(',','.'));
+ self_name = parseFloat($(this).attr('name')),
+ q = count_val-self_name;
+ if(q > 0){
+ values[self_val] = q;
+ range_array.push(q);
+ }
+ });
+ var min = Math.min.apply(null, range_array);
+ var z = 1;
+ $.each(values, function(key, value){
+ if(value == min){
+ z = parseFloat(key);
+ }
+ });
+ var sum = parseFloat(z*count_val*(flag_val+total_colors+material_val+lamination_val)).toFixed(2);
+ $this.find('input[name="sum"]').val(sum);
+ $this.find('p.sum').html(sum+' руб.');
});
- var min = Math.min.apply(null, range_array);
- var z = 1;
- $.each(values, function(key, value){
- if(value == min){
- z = parseFloat(key);
- }
- });
- var sum = parseFloat(z*count_val*(flag_val+total_colors+material_val+lamination_val)).toFixed(2);
- $('input[name="sum"]').val(sum);
- $('p.sum').html(sum+' руб.');
- });
- function get_cookie(name){
- var cookie_value = null;
- if(document.cookie && document.cookie != ''){
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = jQuery.trim(cookies[i]);
- // Does this cookie string begin with the name we want?
- if (cookie.substring(0, name.length + 1) == (name + '=')) {
- cookie_value = decodeURIComponent(cookie.substring(name.length + 1));
- break;
+
+ function get_cookie(name){
+ var cookie_value = null;
+ if(document.cookie && document.cookie != ''){
+ var cookies = document.cookie.split(';');
+ for (var i = 0; i < cookies.length; i++) {
+ var cookie = $.trim(cookies[i]);
+ // Does this cookie string begin with the name we want?
+ if (cookie.substring(0, name.length + 1) == (name + '=')) {
+ cookie_value = decodeURIComponent(cookie.substring(name.length + 1));
+ break;
+ }
}
}
+ return cookie_value;
}
- return cookie_value;
- };
- var csrftoken = get_cookie('csrftoken');
- function csrf_safe_method(method) {
- return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
- };
- function same_origin(url) {
- var host = document.location.host; // host + port
- var protocol = document.location.protocol;
- var sr_origin = '//' + host;
- var origin = protocol + sr_origin;
- // Allow absolute or scheme relative URLs to same origin
- return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
- (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
- // or any other URL that isn't scheme relative or absolute i.e relative.
- !(/^(\/\/|http:|https:).*/.test(url));
- };
- /*
- $.ajaxSetup({
- before_send: function(xhr, settings) {
- console.log("Before SENT")
- if (!csrf_safe_method(settings.type) && sameOrigin(settings.url)) {
- xhr.setRequestHeader("X-CSRFToken", csrftoken);
- }
+
+ var csrftoken = get_cookie('csrftoken');
+
+ function csrf_safe_method(method) {
+ return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
- });
- */
- $(this).submit(function(){
- console.log("Call AJAX", csrftoken);
- $('input[name="csrfmiddlewaretoken"]').val(csrftoken);
- console.log($('#file_data'));
- var action = $(this).attr('action'),
- self = $(this),
- selection = $(this).find('input, select').not(' .ratio, input[name="colors"], input[name="materials"], input[name="count_hidden"], input[name="lamination"], input[name="color_front"], input[name="color_back"]').serialize();
- console.log(selection);
- console.log(action);
- $.ajax({
- url: action,
- type: 'POST',
- data: selection,
- before_send: function(xhr, settings) {
- console.log("Before SENT")
- if (!csrf_safe_method(settings.type) && same_origin(settings.url)) {
- xhr.setRequestHeader("X-CSRFToken", csrftoken);
+
+ function same_origin(url) {
+ var host = document.location.host, // host + port
+ protocol = document.location.protocol,
+ sr_origin = '//' + host,
+ origin = protocol + sr_origin;
+ // Allow absolute or scheme relative URLs to same origin
+ return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
+ (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
+ // or any other URL that isn't scheme relative or absolute i.e relative.
+ !(/^(\/\/|http:|https:).*/.test(url));
+ }
+
+ function confirm_order(result) {
+ $this.find('input#id').val(result.id);
+ $('html').addClass('hidden');
+ $('body').addClass('under_overlay')
+ .append('<div class="overlay"></div><div class="data_wrap"><div><div class="data_container"><div class="data_checking"></div></div></div></div>');
+ $('.data_checking').load('/second/'+result.id+'/');
+ }
+
+ function validate() {
+ var validate_values = {},
+ a = [],
+ b = [];
+ $this.find('input.for_valid').each(function(){
+ var self = $(this),
+ self_name = $(this).attr('name'),
+ self_val = $(this).val();
+ console.log(self, self_name);
+ validate_values[self_name] = self_val;
+ a.push(self_val);
+ });
+ if ($.inArray('', a) > -1 ) {
+ $.each(validate_values, function(key, value){
+ if(value == ''){
+ if($this.find('input[name="'+key+'"]').siblings('i').length == 0){
+ $this.find('input[name="'+key+'"]').parent().append('<i class="error show">Поле не заполнено</i>');
+ $this.find('input[name="'+key+'"]').siblings('i.error').css({
+ 'left': $this.find('input[name="'+key+'"]').parent().position().left,
+ 'top': $this.find('input[name="'+key+'"]').parent().position().top - 36
+ });
+ console.log($this.find('input[name="'+key+'"]').position().left, $this.find('input[name="'+key+'"]').parent().position().top);
+ }
+ }
+ else {
+ $this.find('input[name="'+key+'"]').siblings('i.error').remove();
+ var pattern,
+ error_text;
+ function check_function() {
+ if(value.match(pattern)){
+ b.push(1);
+ $this.find('input[name="'+key+'"]').siblings('i.error').remove();
+
+
+ }
+ else{
+ b.push(0);
+
+ if($this.find('input[name="'+key+'"]').siblings('i').length == 0){
+ $this.find('input[name="'+key+'"]').parent().append('<i class="error show">'+error_text+'</i>');
+ $this.find('input[name="'+key+'"]').siblings('i.error').css({
+ 'left': $this.find('input[name="'+key+'"]').parent().position().left,
+ 'top': $this.find('input[name="'+key+'"]').parent().position().top - 36
+ });
+ console.log($this.find('input[name="'+key+'"]').position().left, $this.find('input[name="'+key+'"]').parent().position().top);
+ }
+
+ //$this.find('i.error').addClass('show')
+ }
+ }
+ if(key == 'user') {
+ pattern = /^[a-zA-ZА-Яа-я]+$/;
+ error_text = 'name_is_not_valid';
+ check_function();
+
+ }
+ if(key == 'phone_'){
+ pattern = /^\d+$/;
+ error_text = 'phone_is_not_valid';
+ check_function();
+ }
+ if(key == 'email'){
+ pattern = /^([a-z0-9_-]+\.)*[a-z0-9_-]+@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.[a-z]{2,4}$/;
+ error_text = 'email_is_not_valid';
+ check_function();
+ }
+ }
+ });
+ }
+ else {
+ $.each(validate_values, function(key, value){
+ $this.find('input[name="'+key+'"]').siblings('label').removeClass('error');
+ var pattern,
+ error_text;
+ function check_function() {
+ if(value.match(pattern)){
+ b.push(1);
+ $this.find('input[name="'+key+'"]').siblings('i.error').remove();
+
+
+ }
+ else{
+ b.push(0);
+
+ if($this.find('input[name="'+key+'"]').siblings('i').length == 0){
+ $this.find('input[name="'+key+'"]').parent().append('<i class="error show">'+error_text+'</i>');
+ $this.find('input[name="'+key+'"]').siblings('i.error').css({
+ 'left': $this.find('input[name="'+key+'"]').parent().position().left,
+ 'top': $this.find('input[name="'+key+'"]').parent().position().top - 36
+ });
+ console.log($this.find('input[name="'+key+'"]').position().left, $this.find('input[name="'+key+'"]').parent().position().top);
+ }
+
+ //$this.find('i.error').addClass('show')
+ }
+ }
+ if(key == 'user') {
+ pattern = /^[a-zA-ZА-Яа-я]+$/;
+ error_text = 'name_is_not_valid';
+ check_function();
+
+ }
+ if(key == 'phone_'){
+ pattern = /^\d+$/;
+ error_text = 'phone_is_not_valid';
+ check_function();
+ }
+ if(key == 'email'){
+ pattern = /^([a-z0-9_-]+\.)*[a-z0-9_-]+@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.[a-z]{2,4}$/;
+ error_text = 'email_is_not_valid';
+ check_function();
+ }
+ });
+ if ($.inArray(0, b) > -1 ) {
+ valid = false;
}
- },
- success: function(result){
- confirm_order(result);
- }
+ else{
+ valid = true;
+ }
+ //console.log(valid);
+ }
+ }
+
+ $this.submit(function(){
+
+
+ //console.log("Call AJAX", csrftoken);
+ $this.find('input[name="csrfmiddlewaretoken"]').val(csrftoken);
+ //console.log($('#file_data'));
+ var action = $(this).attr('action'),
+ self = $(this),
+ selection = $this.find('input, select').not(' .ratio, input[name="colors"], input[name="materials"], input[name="count_hidden"], input[name="lamination"], input[name="color_front"], input[name="color_back"]').serialize();
+ //console.log(selection);
+ //console.log(action);
+ $.ajax({
+ url: action,
+ type: 'POST',
+ data: selection,
+ before_send: function(xhr, settings) {
+ //console.log("Before SENT")
+ if (!csrf_safe_method(settings.type) && same_origin(settings.url)) {
+ xhr.setRequestHeader("X-CSRFToken", csrftoken);
+ }
+ },
+ success: function(result){
+ validate();
+ //console.log(valid);
+ if(valid == true){
+ confirm_order(result);
+ }
+ }
+ });
+ return false;
});
- return false;
});
-
- //Заказ (открываем модальное окно)
- function confirm_order(result) {
- $('input#id').val(result.id);
- $('html').addClass('hidden');
- $('body').addClass('under_overlay')
- .append('<div class="overlay"></div><div class="data_wrap"><div><div class="data_container"><div class="data_checking"><form class="jClever"></form></div></div></div></div>');
- $('.data_checking > form').load('/second/'+result.id+'/'
- , function(){
- form_style()
- }
-
- );
- }
- });
-}
+ }
+}());
+
+
+
+
-function validate() {
- var method = {
- numeric: function(data) {
- var pattern = /^\d+$/;
- return pattern.test(data);
- },
- string: function(data) {
- var pattern = /^[a-zA-ZА-Яа-я]+$/;
- return pattern.test(data);
- },
- text: function(data) {
- var pattern = /^[a-zA-ZА-Яа-я0-9]+$/;
- return pattern.test(data);
- },
- email: function(data) {
- var pattern = /^([a-z0-9_-]+\.)*[a-z0-9_-]+@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.[a-z]{2,4}$/;
- return pattern.test(data);
- },
- url: function(data) {
- var pattern = /^((https?|ftp)\:\/\/)?([a-z0-9]{1,})([a-z0-9-.]*)\.([a-z]{2,4})$/;
- return pattern.test(data);
- }
- };
-}
//Формы
function form_style() {
- $('.jClever').jClever({
- selfClass: "alice",
- applyTo: {
- input: false,
- select: true,
- checkbox: true,
- radio: true,
- button: false,
- file: true,
- textarea: false
- },
- });
+ $('.jClever').jClever({
+ selfClass: "alice",
+ applyTo: {
+ input: false,
+ select: true,
+ checkbox: true,
+ radio: true,
+ button: false,
+ file: true,
+ textarea: false
+ },
+ });
}
$(document).ready(function(){
- //Формы
- form_style();
-
- //Выбор адреса
- var x=0,
- y=0,
- z=0,
- f=0;
- tabs_count = $('section.location > div > ul > li').length;
- $('section.location > div > ul > li').each(function(){
- x++;
- $(this).attr('id', x);
- });
- $('section.location > div > span').each(function(){
- y++;
- $(this).attr('rel', y);
- });
- $('section.location > span > span').each(function(){
- z++;
- $(this).attr('rel', z);
- });
- $('footer > div > span > span').each(function(){
- f++;
- $(this).attr('rel', f);
- });
- $('section.location > div > ul > li').not('current').click(function(){
- var this_id = $(this).attr('id');
- $(this).addClass('current').siblings('li').removeClass('current');
- $('section.location > div > span[rel="'+this_id+'"], section.location > span > span[rel="'+this_id+'"], footer > div > span > span[rel="'+this_id+'"]')
- .addClass('current')
- .siblings('span')
- .removeClass('current');
- });
- $('section.location > div > ul > li').click(function(){
- $('section.location > div:first-child').toggleClass('drop');
- $(this).prependTo($(this).parent()[0])
- });
-
- //Табы
+ //$('form.calc').calc();
+ //Формы
+ //form_style();
+
+ //Выбор адреса
+ var x=0,
+ y=0,
+ z=0,
+ f=0;
+ tabs_count = $('section.location > div > ul > li').length;
+ $('section.location > div > ul > li').each(function(){
+ x++;
+ $(this).attr('id', x);
+ });
+ $('section.location > div > span').each(function(){
+ y++;
+ $(this).attr('rel', y);
+ });
+ $('section.location > span > span').each(function(){
+ z++;
+ $(this).attr('rel', z);
+ });
+ $('footer > div > span > span').each(function(){
+ f++;
+ $(this).attr('rel', f);
+ });
+ $('section.location > div > ul > li').not('current').click(function(){
+ var this_id = $(this).attr('id');
+ $(this).addClass('current').siblings('li').removeClass('current');
+ $('section.location > div > span[rel="'+this_id+'"], section.location > span > span[rel="'+this_id+'"], footer > div > span > span[rel="'+this_id+'"]')
+ .addClass('current')
+ .siblings('span')
+ .removeClass('current');
+ });
+ $('section.location > div > ul > li').click(function(){
+ $('section.location > div:first-child').toggleClass('drop');
+ $(this).prependTo($(this).parent()[0])
+ });
+
+ //Табы
var i=0,
h=0;
tabs_count = $('section.order > div > ul > li').length;
@@ -279,8 +414,9 @@ $(document).ready(function(){
if($(this).hasClass('current')){
$(this).load('/form_'+h+'/', function(){
- calc();
- form_style()
+ console.log($(this));
+ $(this).children('form').addClass('blue').calc();
+ //form_style();
});
}
@@ -296,110 +432,112 @@ $(document).ready(function(){
if(form_container.children('form').length == 0){
form_container.load('/form_'+this_id+'/', function(){
- calc();
- form_style()
+ //calc();
+ //form_style()
+ console.log($(this));
+ $(this).children('form').addClass('red').calc();
});
}
});
- //Расчёт стоимости
- $('.ready > ul > li').each(function(){
- $(this).find('input[type="text"]').val('').keyup(function(){
- var one_price = parseFloat($(this).siblings('span').children('small').html()),
- count = parseFloat($(this).val())||0,
- total = one_price*count,
- total_fix = total.toFixed(2);
- //console.log(count, total, one_price);
- if(count <= 0){
- $(this).addClass('error').siblings('span').children('span').html('');
- }
- else{
- $(this).removeClass('error').siblings('span').children('span').html(total_fix+'руб.');
- }
- });
- });
-
- //Заказ (открываем модальное окно)
- /*
- $('form.filter').each(function(){
- var self=$(this);
- $('a.next_step').click(function(){
- $('body').addClass('under_overlay')
- .append('<div class="overlay"></div><div class="data_checking"><form class="jClever"></form></div>');
- $('.data_checking > form').load('/static/include/helpers.html', function(){
- $('.jClever').jClever({
- selfClass: "alice",
- applyTo: {
- input: false,
- select: true,
- checkbox: true,
- radio: true,
- button: false,
- file: true,
- textarea: false
- }
- });
- });
- return false;
- });
- });
- */
- //Заказ (закрываем модальное окно)
- $(document).on('click', '.close_order', function(){
- $('div.data_checking, div.overlay').remove();
- $('body, html').removeClass();
- });
-
- $(document).on('click', '.data_checking a.next_step', function(){
- $('.data_checking').find('.order').addClass('hide');
- $('.data_checking').addClass('files').find('.files').removeClass('hide');
- return false;
- });
- $(document).on('click', '.data_checking a.back', function(){
- $('.data_checking').find('.files').removeClass('hide');
- $('.data_checking').removeClass('files').find('.order').removeClass('hide');
- //$('.data_checking > form').load('/include/helpers.html .files');
- return false;
- });
-
- //Обратный звонок
- $('.location > a').click(function(){
- $(this).siblings('form').removeClass('hide');
- return false;
- });
- $('form.call > span > small').click(function(){
- $(this).parents('form').addClass('hide');
- });
-
- //Убираем слэш
- $('div.ready > ul > li').each(function(){
- $(this).children().children('li').last().addClass('last');
- });
-
- //Клиенты(карусель)
- $('.carousel > div').carouFredSel({
- circular: false,
- infinite: false,
- auto: false,
- direction: 'left',
- align: 'left',
- prev: {
- button: '.clients > div > a.prev',
- key: 'left'
- },
- next: {
- button: '.clients > div > a.next',
- key: 'right'
- },
- });
-
- //Подсказки в первой форме
- $('div.easy_form > form > ul > li > small').click(function(){
- $(this).toggleClass('active');
- });
-
- //calc();
+ //Расчёт стоимости
+ $('.ready > ul > li').each(function(){
+ $(this).find('input[type="text"]').val('').keyup(function(){
+ var one_price = parseFloat($(this).siblings('span').children('small').html()),
+ count = parseFloat($(this).val())||0,
+ total = one_price*count,
+ total_fix = total.toFixed(2);
+ //console.log(count, total, one_price);
+ if(count <= 0){
+ $(this).addClass('error').siblings('span').children('span').html('');
+ }
+ else{
+ $(this).removeClass('error').siblings('span').children('span').html(total_fix+'руб.');
+ }
+ });
+ });
+
+ //Заказ (открываем модальное окно)
+ /*
+ $('form.filter').each(function(){
+ var self=$(this);
+ $('a.next_step').click(function(){
+ $('body').addClass('under_overlay')
+ .append('<div class="overlay"></div><div class="data_checking"><form class="jClever"></form></div>');
+ $('.data_checking > form').load('/static/include/helpers.html', function(){
+ $('.jClever').jClever({
+ selfClass: "alice",
+ applyTo: {
+ input: false,
+ select: true,
+ checkbox: true,
+ radio: true,
+ button: false,
+ file: true,
+ textarea: false
+ }
+ });
+ });
+ return false;
+ });
+ });
+ */
+ //Заказ (закрываем модальное окно)
+ $(document).on('click', '.close_order', function(){
+ $('div.data_checking, div.overlay').remove();
+ $('body, html').removeClass();
+ });
+
+ $(document).on('click', '.data_checking a.next_step', function(){
+ $('.data_checking').find('.order').addClass('hide');
+ $('.data_checking').addClass('files').find('.files').removeClass('hide');
+ return false;
+ });
+ $(document).on('click', '.data_checking a.back', function(){
+ $('.data_checking').find('.files').removeClass('hide');
+ $('.data_checking').removeClass('files').find('.order').removeClass('hide');
+ //$('.data_checking > form').load('/include/helpers.html .files');
+ return false;
+ });
+
+ //Обратный звонок
+ $('.location > a').click(function(){
+ $(this).siblings('form').removeClass('hide');
+ return false;
+ });
+ $('form.call > span > small').click(function(){
+ $(this).parents('form').addClass('hide');
+ });
+
+ //Убираем слэш
+ $('div.ready > ul > li').each(function(){
+ $(this).children().children('li').last().addClass('last');
+ });
+
+ //Клиенты(карусель)
+ $('.carousel > div').carouFredSel({
+ circular: false,
+ infinite: false,
+ auto: false,
+ direction: 'left',
+ align: 'left',
+ prev: {
+ button: '.clients > div > a.prev',
+ key: 'left'
+ },
+ next: {
+ button: '.clients > div > a.next',
+ key: 'right'
+ },
+ });
+
+ //Подсказки в первой форме
+ $('div.easy_form > form > ul > li > small').click(function(){
+ $(this).toggleClass('active');
+ });
+
+ //calc();
@@ -411,10 +549,9 @@ $(document).ready(function(){
//Глобальная загрузка Jclever для ajax контента
-//$(document).ajaxComplete(function(event, xhr, settings){
- //calc();
- //form_style();
-//});
+$(document).ajaxComplete(function(event, xhr, settings){
+ form_style();
+});

0 comments on commit 3f79909

Please sign in to comment.
Something went wrong with that request. Please try again.