From 394813281744a6178a3f01d0005f003b78ce5c5c Mon Sep 17 00:00:00 2001 From: mdipierro Date: Tue, 10 Mar 2015 23:07:00 -0500 Subject: [PATCH] better bootstrap3 --- applications/welcome3/controllers/test.py | 4 +- applications/welcome3/databases/sql.log | 3 + .../welcome3/databases/storage.sqlite | Bin 12288 -> 12288 bytes .../welcome3/static/css/web2py-bootstrap3.css | 5 + .../welcome3/static/js/web2py-bootstrap3.js | 143 +++--------------- gluon/sqlhtml.py | 28 ++-- 6 files changed, 45 insertions(+), 138 deletions(-) diff --git a/applications/welcome3/controllers/test.py b/applications/welcome3/controllers/test.py index 65b49b39..82a6bedb 100644 --- a/applications/welcome3/controllers/test.py +++ b/applications/welcome3/controllers/test.py @@ -1,7 +1,7 @@ def index(): types = ['string','text','date','time','datetime','integer','double', - 'list:string','list:integer'] - db.define_table('mytable',*[Field('f_'+t.replace(':','_'),t) for t in types]) + 'list:string','list:integer','upload'] + db.define_table('mytable',*[Field('f_'+t.replace(':','_'),t,requires=IS_NOT_EMPTY()) for t in types]) return dict( form = SQLFORM(db.mytable).process(), grid = SQLFORM.grid(db.mytable), diff --git a/applications/welcome3/databases/sql.log b/applications/welcome3/databases/sql.log index 0d964f10..c3235b01 100644 --- a/applications/welcome3/databases/sql.log +++ b/applications/welcome3/databases/sql.log @@ -80,3 +80,6 @@ CREATE TABLE mytable( f_list_integer TEXT ); success! +timestamp: 2015-03-10T23:02:09.466071 +ALTER TABLE mytable ADD f_upload CHAR(512); +success! diff --git a/applications/welcome3/databases/storage.sqlite b/applications/welcome3/databases/storage.sqlite index 96827200c529b4b9f7513455839a35e3e0aff7d6..1692c2c71c0b3c65d0a84e421aff168679e377f8 100644 GIT binary patch delta 164 zcmZojXh@hKEy&Hlz`z57wgR7W8#zO*1GKQTqY*~2kN!_?47QxgD07$rym delta 104 zcmZojXh@hKEy%&Zz`z5o7df%!F1@*(r&*V@u74;Yvp0D0G#xSC`+*u|x#8CwK5U(*w1WYh!z!|)kM diff --git a/applications/welcome3/static/css/web2py-bootstrap3.css b/applications/welcome3/static/css/web2py-bootstrap3.css index 2e18330c..93229240 100644 --- a/applications/welcome3/static/css/web2py-bootstrap3.css +++ b/applications/welcome3/static/css/web2py-bootstrap3.css @@ -289,3 +289,8 @@ body { .dropdown .highlighted { color: #428bca; } + +ul.w2p_list { margin-left: 0px; } +input.date,input.time,input.datetime,input.double,input.integer { width: 33.333%; } + + diff --git a/applications/welcome3/static/js/web2py-bootstrap3.js b/applications/welcome3/static/js/web2py-bootstrap3.js index 813fc375..31dc1617 100644 --- a/applications/welcome3/static/js/web2py-bootstrap3.js +++ b/applications/welcome3/static/js/web2py-bootstrap3.js @@ -15,15 +15,10 @@ */ jQuery(function(){ - // bootstrap3 classes for elements of horizontal form - data - var FH_CL_PREFIX = 'col-md-', // class prefix - FH_LABEL_COLW = '4', // nr. of columns of 12 - FH_CONTROL_COLW = '8'; // 12 - FH_LABEL_COLW; - // bootstrap3 classes for elements of horizontal form - calculations - var fh_label_class = FH_CL_PREFIX + FH_LABEL_COLW, - fh_offest_class = FH_CL_PREFIX+'offset-'+FH_LABEL_COLW, - fh_control_class = FH_CL_PREFIX + FH_CONTROL_COLW; + var fh_label_class = 'col-md-4', + fh_offest_class = 'col-md-offset-4', + fh_control_class = 'col-md-8'; // functions function menu_is_collapsed() { @@ -58,17 +53,6 @@ jQuery(function(){ return this; }; - function adjust_maxheight_of_collapsed_nav() { - var cn = jQuery('div.navbar-collapse'); - var sh = jQuery(window).height(); - if (cn.get(0)) { - if (sh<320) - cn.addClass('short-screen'); - else if(cn.hasClass('short-screen')) - cn.removeClass('short-screen'); - } - }; - // alert centering jQuery('.flash.alert.centered').center({'mode': "horizontally"}); @@ -118,116 +102,23 @@ jQuery(function(){ jQuery(".nav-tabs .web2py-menu-active").addClass('active'); jQuery(".nav-tabs a").not(".dropdown-toggle").attr("data-toggle", "tab"); - + // button fixes + jQuery("button:not(.btn),input[type=button]:not(.btn),.w2p_list a").addClass('btn btn-default'); // form fixes - jQuery("ul.w2p_list").css('margin-left',0); - jQuery("ul.w2p_list input").addClass('form-control'); - jQuery("input.date,input.time,input.datetime,input.double,input.integer").css('width','33.33333333%'); - // the plus and minus buttons are generated by web2py.js - jQuery("form.bs3-form .w2p_list a").addClass('btn btn-default'); - // not generated by formstyle jQuery("form.bs3-form p.w2p-autocomplete-widget input").addClass('form-control'); - jQuery("form.bs3-form input[name='password_two']").each(function() { - // auth addition after form creation - var self = jQuery(this).addClass('form-control'); - var groupClass = 'form-group'; - var labelClass = 'control-label'; - var commentClass = 'help-block'; - var comment; - var mode; - var hasError = false; - if (self.parent().hasClass('form-horizontal')) { - mode = 'horizontal'; - labelClass = fh_label_class+' control-label'; - }; - if (self.parent().hasClass('form-inline')) { - mode = 'inline'; - labelClass = 'sr-only'; - commentClass = 'sr-only'; - var labelText = self.prev('label').text(); - self.attr("placeholder", labelText.slice(0,-2)); - }; - var error = self.next('div.error_wrapper'); - if (error.length > 0) { - var hasError = true; - groupClass = 'form-group has-error' - var text = error[0].nextSibling.nodeValue; - if (text) { - comment = ""+text+""; - error[0].parentNode.removeChild(error[0].nextSibling); - }; - } else { - var text = self[0].nextSibling.nodeValue; - if (text) { - comment = ""+text+""; - self[0].parentNode.removeChild(self[0].nextSibling); - }; - }; - self.prev('label').addClass(labelClass).andSelf().wrapAll("
"); - if (mode == 'horizontal') { - self.wrap('
'); - }; - if (hasError) { - self.parent().append(error); - }; - self.parent().append(comment); - }); - jQuery('form.bs3-form #auth_user_remember').each(function() { - // auth addition after form creation - var $input = jQuery(this); - var $label = $input.next('label'); - var $iParent = $input.parent(); - $input.removeClass('checkbox'); - $iParent.prev('label').remove(); - $input.prependTo($label); - var newGroup = $label; - $iParent.replaceWith(newGroup); - if (newGroup.parent().hasClass('form-horizontal')) { - newGroup.wrap(jQuery('
')); - } else { - newGroup.wrap(jQuery('
')); - }; - }); - // form errors - jQuery('form.bs3-form .error_wrapper').each(function() { - var self = jQuery(this); - var rcContainer = self.parents('.rc_container'); - if (rcContainer.length > 0) { - self.appendTo(rcContainer); - } - }); - jQuery('form.bs3-form').find('div.error').addClass('text-danger').closest(".form-group").addClass('has-error'); - - // uploadwidget - jQuery('#file-reset-btn').click(function() { - var el = jQuery('div.w2p-uploaded-file')[0]; - var whatReset = jQuery.data(el, "reset"); - if (whatReset == "changed") { - jQuery('.w2p-uploaded-file input[type="file"]') - .replaceWith(jQuery('.w2p-uploaded-file input[type="file"]').clone()); - jQuery('.w2p-file-preview, .w2p-uploaded-file input[type="file"], #edit-btn-dd, #file-reset-btn').toggle(); - } else { - jQuery('.w2p-file-preview, #no-file, #edit-btn-dd, #file-reset-btn').toggle(); - jQuery('div.w2p-uploaded-file').children('input[type=checkbox]').trigger('click'); - } - jQuery.removeData(el, "reset"); - }); - jQuery('#change-file-option').click(function(e) { - e.preventDefault(); - jQuery('.w2p-file-preview, .w2p-uploaded-file input[type="file"], #edit-btn-dd, #file-reset-btn').toggle(); - jQuery.data(jQuery('div.w2p-uploaded-file')[0], "reset", "changed"); - }); - jQuery('#delete-file-option').click(function(e) { - e.preventDefault(); - var wimg = jQuery('#image-thumb').outerWidth(), - himg = jQuery('#image-thumb').outerHeight(); - jQuery('#no-file').width(wimg).height(himg).css({'line-height':himg+'px'}); - jQuery('.w2p-file-preview, #no-file, #edit-btn-dd, #file-reset-btn').toggle(); - jQuery('div.w2p-uploaded-file').children('input[type=checkbox]').trigger('click'); - jQuery.data(jQuery('div.w2p-uploaded-file')[0], "reset", "deleted"); - }); - + // on page load + function adjust_maxheight_of_collapsed_nav() { + var cn = jQuery('div.navbar-collapse'); + var sh = jQuery(window).height(); + if (cn.get(0)) { + if (sh<320) + cn.addClass('short-screen'); + else if(cn.hasClass('short-screen')) + cn.removeClass('short-screen'); + } + }; + adjust_maxheight_of_collapsed_nav(); // resize and orientation change events diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index a248a761..ba267556 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -318,7 +318,7 @@ class ListWidget(StringWidget): attributes['_id'] = _id + '_grow_input' attributes['_style'] = 'list-style:none' attributes['_class'] = 'w2p_list' - return TAG[''](UL(*items, **attributes)) + return UL(*items, **attributes) class MultipleOptionsWidget(OptionsWidget): @@ -712,9 +712,10 @@ class AutocompleteWidget(object): name=name, div_id=div_id, u='F' + self.keyword) if self.min_length == 0: attr['_onfocus'] = attr['_onkeyup'] - return TAG[''](INPUT(**attr), INPUT(_type='hidden', _id=key3, _value=value, - _name=name, requires=field.requires), - DIV(_id=div_id, _style='position:absolute;')) + return CAT(INPUT(**attr), + INPUT(_type='hidden', _id=key3, _value=value, + _name=name, requires=field.requires), + DIV(_id=div_id, _style='position:absolute;')) else: attr['_name'] = field.name attr['_onblur'] = "jQuery('#%(div_id)s').delay(1000).fadeOut('slow');" % \ @@ -724,7 +725,8 @@ class AutocompleteWidget(object): key=self.keyword, id=attr['_id'], div_id=div_id, u='F' + self.keyword) if self.min_length == 0: attr['_onfocus'] = attr['_onkeyup'] - return TAG[''](INPUT(**attr), DIV(_id=div_id, _style='position:absolute;')) + return CAT(INPUT(**attr), + DIV(_id=div_id, _style='position:absolute;')) def formstyle_table3cols(form, fields): @@ -859,10 +861,14 @@ def formstyle_bootstrap3_stacked(form, fields): controls.add_class('form-control') elif isinstance(controls, TEXTAREA): controls.add_class('form-control') - + elif isinstance(controls, SPAN): _controls = P(controls.components) + elif isinstance(controls, UL): + for e in controls.elements("input"): + e.add_class('form-control') + if isinstance(label, LABEL): label['_class'] = 'control-label' @@ -909,10 +915,12 @@ def formstyle_bootstrap3_inline_factory(col_label_size=3): controls.add_class('form-control') elif isinstance(controls, TEXTAREA): controls.add_class('form-control') - + elif isinstance(controls, SPAN): _controls = P(controls.components, _class="form-control-static %s" % col_class) - + elif isinstance(controls, UL): + for e in controls.elements("input"): + e.add_class('form-control') if isinstance(label, LABEL): label['_class'] = 'control-label %s' % label_col_class @@ -1233,7 +1241,7 @@ class SQLFORM(FORM): else: inp = self.widgets.multiple.widget(field, default) if fieldname in keepopts: - inpval = TAG[''](*inp.components) + inpval = CAT(*inp.components) elif field.type.startswith('list:'): inp = self.widgets.list.widget(field, default) elif field.type == 'text': @@ -1466,7 +1474,7 @@ class SQLFORM(FORM): self.deleted = \ request_vars.get(self.FIELDNAME_REQUEST_DELETE, False) - self.custom.end = TAG[''](self.hidden_fields(), self.custom.end) + self.custom.end = CAT(self.hidden_fields(), self.custom.end) auch = record_id and self.errors and self.deleted