From 6ed06eff82c8fde0103185e9e718634b56f678ee Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Thu, 28 Sep 2017 12:45:54 +0200 Subject: [PATCH] added deform widgets for deactivated fields this removes the need of setting deactivated attribute with javascript --- ordr2/schemas/account.py | 6 ++- ordr2/static/js/functions.js | 2 +- ordr2/templates/deform/select_disabled.pt | 42 ++++++++++++++++++++ ordr2/templates/deform/textinput_disabled.pt | 22 ++++++++++ ordr2/templates/layout.jinja2 | 1 - 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 ordr2/templates/deform/select_disabled.pt create mode 100644 ordr2/templates/deform/textinput_disabled.pt diff --git a/ordr2/schemas/account.py b/ordr2/schemas/account.py index d03c80a..04f66d7 100644 --- a/ordr2/schemas/account.py +++ b/ordr2/schemas/account.py @@ -15,9 +15,11 @@ class RegistrationSchema(CSRFSchema): user_name = colander.SchemaNode( colander.String(), - widget=deform.widget.TextInputWidget(), + widget=deform.widget.TextInputWidget( + template='textinput_disabled.pt' + ), description='automagically generated for you', - validator = deferred_unique_username_validator + validator = deferred_unique_username_validator, ) first_name = colander.SchemaNode( colander.String() diff --git a/ordr2/static/js/functions.js b/ordr2/static/js/functions.js index fd4effb..9814d83 100755 --- a/ordr2/static/js/functions.js +++ b/ordr2/static/js/functions.js @@ -1 +1 @@ -$(document).ready(function() { function capitalize(s){ return s.replace( /\b./g, function(a){ return a.toUpperCase(); } ); }; function generate_user_name() { var first_name = $('.registration .item-first_name input').val(); var last_name = $('.registration .item-last_name input').val(); var user_name = capitalize(first_name) + capitalize(last_name); return user_name.replace( /\s/g, '') }; // autocomplete of the username (registration form) $('.registration .item-user_name input').attr('disabled', 'disabled'); $('.registration .item-user_name input').val( generate_user_name() ); $('.registration .item-first_name input').keyup(function() { $('.registration .item-user_name input').val( generate_user_name() ); }); $('.registration .item-last_name input').keyup(function() { $('.registration .item-user_name input').val( generate_user_name() ); }); $('.registration #deformCreate_Account').click(function() { $('.registration .item-user_name input').removeAttr('disabled'); return true; }); // "dispatch" clicking a th to the corresponding anchor $('th.sortable').click( function() { window.location = $(this).children('a').attr('href'); }); // "dispatch" clicking list item in collapse to the corresponding anchor $('.accordion li').click( function() { window.location = $(this).children('a').attr('href'); }); // the mark all $('input[name="mark_all"]').click(function() { var checked_status = this.checked; $('input[name*="marked"]').each(function() { this.checked = checked_status; }); if( $('input[name="mark_all"]').is(':checked') && $('.marking-needed').is(':hidden') ) { $('.marking-needed').fadeIn("fast"); } else if( $('input[name="mark_all"]').is(':checked') && $('.marking-needed').is(':visible') ) { // do nothing } else { $('.marking-needed').fadeOut("fast"); } }); // show actions only if some data is marked $('input[name*="marked"]').change(function() { if( $('input[name*="marked"]').is(':checked') ) { if( $('.marking-needed').is(':hidden') ) $('.marking-needed').fadeIn("slow"); } else { $('.marking-needed').fadeOut("slow"); } }); // quick-actions $('.quick-action a[data-value]').click(function(event) { event.preventDefault(); var value = $(this).attr('data-value'); var action = $(this).closest('div').attr('data-action'); $('select[name*='+action+']').each(function() { $(this).val(value); }); }); // submit search $('.search-form input[type="search"]').keypress(function(event) { if( event.keyCode == 13 && $('.typeahead.dropdown-menu').is(':hidden') ) $('.search-form').submit(); }); // aside filter $('.filter input[type="checkbox"]').click( function() { if( $(this).is(':checked') ) { $(this).parents('li').addClass('active'); } else { $(this).parents('li').removeClass('active'); } }); // tooltips $('.page-controls').tooltip({ selector: "[rel=tooltip]" }); // calculator if ( $('input[name="price_unit"]').length ) { if( $('input[name="price_unit"]').val() != '' && $('input[name="quantity"]').val() != '' ){ var total = $('input[name="price_unit"]').val().replace(",", ".") * $('input[name="quantity"]').val(); total = Math.round(total*100)/100; $('input[name="price_total_disabled"]').attr( 'placeholder', total ); } $('input[name="price_unit"], input[name="quantity"]').keyup(function() { var total = $('input[name="price_unit"]').val().replace(",", ".") * $('input[name="quantity"]').val(); total = Math.round(total*100)/100; $('input[name="price_total_disabled"]').attr( 'placeholder', total ); }); } if ( $('input[name="currency"]').length ) { // added currency to total price if( $('input[name="currency"]').val() != '' ){ $('input[name="currency_disabled"]').attr( 'placeholder', $('input[name="currency"]').val() ); } $('input[name="currency"]').keyup(function() { $('input[name="currency_disabled"]').attr( 'placeholder', $('input[name="currency"]').val() ); }); $('input[name="currency"]').change(function() { $('input[name="currency_disabled"]').attr( 'placeholder', $('input[name="currency"]').val() ); }); } }); \ No newline at end of file +$(document).ready(function() { function capitalize(s){ return s.replace( /\b./g, function(a){ return a.toUpperCase(); } ); }; function generate_user_name() { var first_name = $('.registration .item-first_name input').val(); var last_name = $('.registration .item-last_name input').val(); var user_name = capitalize(first_name) + capitalize(last_name); return user_name.replace( /\s/g, '') }; // autocomplete of the username (registration form) $('.registration .item-user_name input').val( generate_user_name() ); $('.registration .item-first_name input').keyup(function() { $('.registration .item-user_name input').val( generate_user_name() ); }); $('.registration .item-last_name input').keyup(function() { $('.registration .item-user_name input').val( generate_user_name() ); }); $('.registration #deformCreate_Account').click(function() { $('.registration .item-user_name input').removeAttr('disabled'); return true; }); // "dispatch" clicking a th to the corresponding anchor $('th.sortable').click( function() { window.location = $(this).children('a').attr('href'); }); // "dispatch" clicking list item in collapse to the corresponding anchor $('.accordion li').click( function() { window.location = $(this).children('a').attr('href'); }); // the mark all $('input[name="mark_all"]').click(function() { var checked_status = this.checked; $('input[name*="marked"]').each(function() { this.checked = checked_status; }); if( $('input[name="mark_all"]').is(':checked') && $('.marking-needed').is(':hidden') ) { $('.marking-needed').fadeIn("fast"); } else if( $('input[name="mark_all"]').is(':checked') && $('.marking-needed').is(':visible') ) { // do nothing } else { $('.marking-needed').fadeOut("fast"); } }); // show actions only if some data is marked $('input[name*="marked"]').change(function() { if( $('input[name*="marked"]').is(':checked') ) { if( $('.marking-needed').is(':hidden') ) $('.marking-needed').fadeIn("slow"); } else { $('.marking-needed').fadeOut("slow"); } }); // quick-actions $('.quick-action a[data-value]').click(function(event) { event.preventDefault(); var value = $(this).attr('data-value'); var action = $(this).closest('div').attr('data-action'); $('select[name*='+action+']').each(function() { $(this).val(value); }); }); // submit search $('.search-form input[type="search"]').keypress(function(event) { if( event.keyCode == 13 && $('.typeahead.dropdown-menu').is(':hidden') ) $('.search-form').submit(); }); // aside filter $('.filter input[type="checkbox"]').click( function() { if( $(this).is(':checked') ) { $(this).parents('li').addClass('active'); } else { $(this).parents('li').removeClass('active'); } }); // tooltips $('.page-controls').tooltip({ selector: "[rel=tooltip]" }); // calculator if ( $('input[name="price_unit"]').length ) { if( $('input[name="price_unit"]').val() != '' && $('input[name="quantity"]').val() != '' ){ var total = $('input[name="price_unit"]').val().replace(",", ".") * $('input[name="quantity"]').val(); total = Math.round(total*100)/100; $('input[name="price_total_disabled"]').attr( 'placeholder', total ); } $('input[name="price_unit"], input[name="quantity"]').keyup(function() { var total = $('input[name="price_unit"]').val().replace(",", ".") * $('input[name="quantity"]').val(); total = Math.round(total*100)/100; $('input[name="price_total_disabled"]').attr( 'placeholder', total ); }); } if ( $('input[name="currency"]').length ) { // added currency to total price if( $('input[name="currency"]').val() != '' ){ $('input[name="currency_disabled"]').attr( 'placeholder', $('input[name="currency"]').val() ); } $('input[name="currency"]').keyup(function() { $('input[name="currency_disabled"]').attr( 'placeholder', $('input[name="currency"]').val() ); }); $('input[name="currency"]').change(function() { $('input[name="currency_disabled"]').attr( 'placeholder', $('input[name="currency"]').val() ); }); } }); \ No newline at end of file diff --git a/ordr2/templates/deform/select_disabled.pt b/ordr2/templates/deform/select_disabled.pt new file mode 100644 index 0000000..83304e5 --- /dev/null +++ b/ordr2/templates/deform/select_disabled.pt @@ -0,0 +1,42 @@ +
+ + + + +
diff --git a/ordr2/templates/deform/textinput_disabled.pt b/ordr2/templates/deform/textinput_disabled.pt new file mode 100644 index 0000000..ae5b3ba --- /dev/null +++ b/ordr2/templates/deform/textinput_disabled.pt @@ -0,0 +1,22 @@ + + + + diff --git a/ordr2/templates/layout.jinja2 b/ordr2/templates/layout.jinja2 index 3a59f72..37145c8 100644 --- a/ordr2/templates/layout.jinja2 +++ b/ordr2/templates/layout.jinja2 @@ -38,7 +38,6 @@ Logged in as {{request.user.user_name}}