Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 6.67 KB | None | 0 0
  1. {% extends "base.html" %}
  2. {% load i18n %}
  3.  
  4.  
  5. {% block title %}{{ _("Voimaperheet") }}{% endblock %}
  6.  
  7. {% block content %}
  8.     <div class="row">
  9.         <div class="col-md-12">
  10.             <h1>{{ _("Voimaperheet-neuvolakysely") }}</h1>
  11.             <h3>{{ _("vanhemmille tai huoltajille 4-vuotiaan lapsen laajan terveystarkastuksen tueksi") }}</h3>
  12.         </div>
  13.     </div>
  14.  
  15.     <div class="row">
  16.         <div class="col-md-12">
  17.  
  18.             <form method="POST" action="." class="form-horizontal" id="productForm">
  19.                 <ul class="nav nav-pills">
  20.                     {% for c, qs in questions_by_category.iteritems  %}
  21.                     <li class="active">            
  22.                         <a href="#form-part-{{ forloop.counter }}" data-toggle="tab">{{forloop.counter }}</a></li>
  23.                     {% endfor %}
  24.                 </ul>
  25.                 {% csrf_token %}
  26.                 <div class="row">
  27.                     {{ form.non_field_errors }}
  28.                 </div>
  29.                
  30.                 {% for category, questions in questions_by_category.iteritems  %}
  31.                     {% include 'partials/question_category.html' %}
  32.                 {% endfor %}
  33.                 <div class="help-block with-errors"></div>
  34.                
  35.                 <button type="submit" class="form-submit-btn btn btn-success btn-lg btn-block" id="sendButton">{{ _('Lähetä') }}!</button>
  36.              <!-- Previous/Next buttons -->
  37.                 <ul class="pager wizard"><span class="custom-progress">
  38.                     <li class="custom-progress-prev"><a href="#form-part-prev" aria-label="Previous">&laquo; {{ _('Edellinen') }}</a></li>
  39.                     <li class="custom-progress-next"><a href="#form-part-next" aria-label="Next">{{ _('Seuraava') }} &raquo;</a></li>
  40.                 </ul></span>
  41.                  <ul class="pager wizard">
  42.                     <li class="previous"><a href="javascript: void(0);">Previous</a></li>
  43.                     <li class="next"><a href="javascript: void(0);">Next</a></li>
  44.                 </ul>
  45.             </form>
  46.         </div>
  47.     </div>
  48.  
  49.     <!--
  50.     <nav>
  51.         <div class="text-center">
  52.             <ul class="pagination">
  53.                 <li class="custom-progress-prev">
  54.                     <span class="custom-progress">
  55.                         <a href="#form-part-prev" aria-label="Previous">&laquo; {{ _('Edellinen') }}</a>
  56.                     </span>
  57.                 </li>
  58.  
  59.                 {% for c, qs in questions_by_category.iteritems  %}
  60.                     <li class="part-link-{{ forloop.counter }}">
  61.                         <span class="custom-progress">
  62.                             <a href="#form-part-{{ forloop.counter }}"> {{forloop.counter }} </a>
  63.                         </span>
  64.                     </li>
  65.                 {% endfor %}
  66.  
  67.                 <li class="custom-progress-next">
  68.                     <span class="custom-progress">
  69.                         <a href="#form-part-next" aria-label="Next">{{ _('Seuraava') }} &raquo;</a>
  70.                     </span>
  71.                 </li>
  72.             </ul>
  73.         </div>
  74.     </nav>-->
  75.    
  76.  
  77. {% endblock %}
  78.  
  79. {% block extra_js %}
  80.     {{ block.super }}
  81.  
  82.  
  83.     <script>
  84.    
  85.     $(document).ready(function() {
  86.         //$('body, input[type=text]').addClass('form-control');
  87.         $('body, input[type=text]').attr("required", "true");
  88.  
  89.         $("#productForm")
  90.             .formValidation({
  91.                 framework: 'bootstrap',
  92.                 icon: {
  93.                     valid: 'glyphicon glyphicon-ok',
  94.                     invalid: 'glyphicon glyphicon-remove',
  95.                     validating: 'glyphicon glyphicon-refresh'
  96.                 },
  97.                 excluded: ':disabled',
  98.             })
  99.  
  100.         .bootstrapWizard({
  101.             tabClass: 'nav nav-pills',
  102.             onTabClick: function(tab, navigation, index) {
  103.                 return validateTab(index);
  104.             },
  105.             onNext: function(tab, navigation, index) {
  106.                 var numTabs    = $('#productForm').find('.wrapper-div').length,
  107.                     isValidTab = validateTab(index - 1);
  108.                 if (!isValidTab) {
  109.                     return false;
  110.                 }
  111.  
  112.                 return true;
  113.             },
  114.             onPrevious: function(tab, navigation, index) {
  115.                 return validateTab(index + 1);
  116.             },
  117.             onTabShow: function(tab, navigation, index) {
  118.                 // Update the label of Next button when we are at the last tab
  119.                 var numTabs = $('#productForm').find('.wrapper-div').length;
  120.                 $('#productForm')
  121.                     .find('.next')
  122.                         .removeClass('disabled')    // Enable the Next button
  123.                         .find('a')
  124.                         .html(index === numTabs - 1 ? 'Install' : 'Next');
  125.             }
  126.         });
  127.  
  128.    
  129.         function validateTab(index) {
  130.             var fv   = $('#productForm').data('formValidation'), // FormValidation instance
  131.                 // The current tab
  132.                 $tab = $('#productForm').find('.wrapper-div').eq(index);
  133.  
  134.             // Validate the container
  135.             fv.validateContainer($tab);
  136.  
  137.             var isValidStep = fv.isValidContainer($tab);
  138.             if (isValidStep === false || isValidStep === null) {
  139.                 // Do not jump to the target tab
  140.                 return false;
  141.             }
  142.  
  143.             return true;
  144.  
  145.         }
  146.     });
  147.  
  148.         // Jaa formi osiin
  149.         $(function() {
  150.             var $parts = $('.form-part');
  151.  
  152.             if ($parts.length === 0) { return }
  153.  
  154.             // Initial part number is 1
  155.             var partNumber = 1;
  156.  
  157.             var updateParts = function (activePartNumber) {
  158.                 // Hide all form parts
  159.                 $('.form-part').css('display', 'none');
  160.  
  161.                 // Display the correct form part
  162.                 $('#form-part-' + activePartNumber).css('display', 'block');
  163.  
  164.                 // Remove active class from every part link
  165.                 $('.custom-progress a')
  166.                     .removeClass('custom-active');
  167.  
  168.                 // Add active class to the correct part link
  169.                 $('.part-link-' + activePartNumber + ' a')
  170.                     .addClass('custom-active');
  171.  
  172.                 // Set correct href to prev button
  173.                 $('.custom-progress-prev a')
  174.                     .attr('href', '#form-part-' + (activePartNumber-1));
  175.  
  176.                 // Set correct href to next button
  177.                 $('.custom-progress-next a')
  178.                     .attr('href', '#form-part-' + (activePartNumber+1));
  179.  
  180.                 // Display prev button if not on the first part
  181.                 if (activePartNumber > 1) {
  182.                     $('.custom-progress-prev').css('display', 'inline');
  183.                 } else {
  184.                     $('.custom-progress-prev').css('display', 'none');
  185.                 }
  186.  
  187.                 // Display next button if not on the last part
  188.                 if (activePartNumber < $parts.length) {
  189.                     $('.custom-progress-next').css('display', 'inline');
  190.                 } else {
  191.                     $('.custom-progress-next').css('display', 'none');
  192.                 }
  193.  
  194.                 // Display the submit button if on the last part
  195.                 if (activePartNumber === $parts.length) {
  196.                     $('.form-submit-btn').css('display', 'inline');
  197.                 } else {
  198.                     $('.form-submit-btn').css('display', 'none');
  199.                 }
  200.             }
  201.            
  202.             // Actions to the page numbers
  203.             $('.custom-progress a').click(function(event) {
  204.                 event.preventDefault();
  205.  
  206.                 // Get the new part number
  207.                 var partNumber = parseInt(event.target.hash.split('-').slice(-1));
  208.  
  209.                 // Scroll the page up
  210.                 scrollTo(0,0);
  211.  
  212.                 updateParts(partNumber);
  213.             });
  214.  
  215.             updateParts(partNumber);
  216.  
  217.         });
  218.  
  219.     </script>
  220. {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement