better bootstrap3

This commit is contained in:
mdipierro
2015-03-10 23:07:00 -05:00
parent a2060eedce
commit 3948132817
6 changed files with 45 additions and 138 deletions

View File

@@ -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),

View File

@@ -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!

View File

@@ -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%; }

View File

@@ -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 = "<span class='"+commentClass+"'>"+text+"</span>";
error[0].parentNode.removeChild(error[0].nextSibling);
};
} else {
var text = self[0].nextSibling.nodeValue;
if (text) {
comment = "<span class='"+commentClass+"'>"+text+"</span>";
self[0].parentNode.removeChild(self[0].nextSibling);
};
};
self.prev('label').addClass(labelClass).andSelf().wrapAll("<div class='"+groupClass+"' id='auth_user_verify_password__row'></div>");
if (mode == 'horizontal') {
self.wrap('<div class="'+fh_control_class+'"></div>');
};
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('<div class="form-group"><div class="'+fh_offest_class+' '+fh_control_class+'"><div class="checkbox"></div></div></div>'));
} else {
newGroup.wrap(jQuery('<div class="form-group"><div class="checkbox"></div></div>'));
};
});
// 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

View File

@@ -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