improved static/js/web2py-bootstrap3.js

This commit is contained in:
mdipierro
2015-03-10 22:18:42 -05:00
parent ac24ce446e
commit a2060eedce
6 changed files with 254 additions and 235 deletions
@@ -0,0 +1,8 @@
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])
return dict(
form = SQLFORM(db.mytable).process(),
grid = SQLFORM.grid(db.mytable),
)
+27
View File
@@ -53,3 +53,30 @@ CREATE TABLE auth_cas(
renew CHAR(1) renew CHAR(1)
); );
success! success!
timestamp: 2015-03-10T21:30:43.774215
CREATE TABLE mytable(
id INTEGER PRIMARY KEY AUTOINCREMENT,
f_string CHAR(512),
f_text TEXT,
f_date DATE,
f_time TIME,
f_datetime TIMESTAMP,
f_integer INTEGER,
f_double DOUBLE,
f_list:string TEXT,
f_list:integer TEXT
);
timestamp: 2015-03-10T21:31:46.944243
CREATE TABLE mytable(
id INTEGER PRIMARY KEY AUTOINCREMENT,
f_string CHAR(512),
f_text TEXT,
f_date DATE,
f_time TIME,
f_datetime TIMESTAMP,
f_integer INTEGER,
f_double DOUBLE,
f_list_string TEXT,
f_list_integer TEXT
);
success!
Binary file not shown.
+4 -10
View File
@@ -6,12 +6,14 @@
######################################################################### #########################################################################
response.logo = A(B('web',SPAN(2),'py'),XML('™ '), response.logo = A(B('web',SPAN(2),'py'),XML('™ '),
_class="brand",_href="http://www.web2py.com/") _class="navbar-brand",_href="http://www.web2py.com/",
_id="web2py-logo")
response.title = request.application.replace('_',' ').title() response.title = request.application.replace('_',' ').title()
response.subtitle = '' response.subtitle = ''
## read more at http://dev.w3.org/html5/markup/meta.name.html ## read more at http://dev.w3.org/html5/markup/meta.name.html
response.meta.author = 'Your Name <you@example.com>' response.meta.author = 'Your Name <you@example.com>'
response.meta.description = 'a cool new app'
response.meta.keywords = 'web2py, python, framework' response.meta.keywords = 'web2py, python, framework'
response.meta.generator = 'Web2py Web Framework' response.meta.generator = 'Web2py Web Framework'
@@ -124,15 +126,7 @@ def _():
(T('Live Chat'), False, (T('Live Chat'), False,
'http://webchat.freenode.net/?channels=web2py'), 'http://webchat.freenode.net/?channels=web2py'),
]), ]),
(T('Plugins'), False, None, [ (T('Plugins'), False, 'http://web2py.com/plugins')]
('plugin_wiki', False,
'http://web2py.com/examples/default/download'),
(T('Other Plugins'), False,
'http://web2py.com/plugins'),
(T('Layout Plugins'),
False, 'http://web2py.com/layouts'),
])
]
)] )]
if DEVELOPMENT_MENU: _() if DEVELOPMENT_MENU: _()
@@ -14,240 +14,230 @@
*/ */
(function ($) { 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 - data // bootstrap3 classes for elements of horizontal form - calculations
var FH_CL_PREFIX = 'col-md-', // class prefix var fh_label_class = FH_CL_PREFIX + FH_LABEL_COLW,
FH_LABEL_COLW = '4', // nr. of columns of 12 fh_offest_class = FH_CL_PREFIX+'offset-'+FH_LABEL_COLW,
FH_CONTROL_COLW = '8' // 12 - FH_LABEL_COLW; fh_control_class = FH_CL_PREFIX + FH_CONTROL_COLW;
// bootstrap3 classes for elements of horizontal form - calculations // functions
var fh_label_class = FH_CL_PREFIX + FH_LABEL_COLW, function menu_is_collapsed() {
fh_offest_class = FH_CL_PREFIX+'offset-'+FH_LABEL_COLW, return !jQuery('.navbar-toggle').is(':hidden');
fh_control_class = FH_CL_PREFIX + FH_CONTROL_COLW;
// functions
function menu_is_collapsed() {
return !$('.navbar-toggle').is(':hidden')
};
function closeSubmenu() {
$(".dropdown-submenu>a.active").each(function(){
var o = $(this);
o.parent().children("ul").toggleClass('open').data('phase', null);
o.toggleClass('active');
});
};
$.fn.center = function (options) {
var defaults = {'parent': false, 'mode': "both"};
var settings = $.extend(defaults, options);
var parent;
if (settings.parent) {
parent = this.parent();
} else {
parent = window;
}
if (settings.mode != "horizontally") {
this.css("top", Math.max(0, (($(parent).height() - $(this).outerHeight()) / 2) + $(parent).scrollTop()) + "px");}
if (settings.mode != "vertically") {
this.css("left", Math.max(0, (($(parent).width() - $(this).outerWidth()) / 2) + $(parent).scrollLeft()) + "px");}
return this;
};
function adjust_maxheight_of_collapsed_nav() {
var cn = $('div.navbar-collapse');
var sh = $(window).height();
if (cn.get(0)) {
if (sh<320) {
cn.addClass('short-screen');
}
else {
cn.removeClass('short-screen');
}
}
};
// alert centering
$('.flash.alert.centered').center({'mode': "horizontally"});
// navs
$(".nav ul.dropdown-menu").not("#w2p-auth-bar").each(function() {
var toggle = $(this).parent();
if (toggle.parent().hasClass("nav")) {
toggle.attr("data-w2pmenulevel", "l0");
toggle.children("a")
.addClass("dropdown-toggle")
.append('<span class="caret"> </span>')
.attr("data-toggle", "dropdown");
} else {
toggle.addClass("dropdown-submenu").removeClass("dropdown");
}; };
});
$('.navbar-nav a.dropdown-toggle').click(function(e) { function closeSubmenu() {
if (menu_is_collapsed()) { jQuery(".dropdown-submenu > a.active").each(function(){
e.preventDefault(); var o = jQuery(this);
}else{ o.parent().children("ul")
window.location=$(this).attr('href'); .toggleClass('open').data('phase', null);
o.toggleClass('active');
});
}; };
});
$(".dropdown-submenu>a").click(function(event) { jQuery.fn.center = function (options) {
if (menu_is_collapsed()) { var defaults = {'parent': false, 'mode': "both"};
event.preventDefault(); var settings = jQuery.extend(defaults, options);
event.stopPropagation(); var parent;
var submenu = $(this).parent().children("ul"); if (settings.parent)
submenu.data('phase','opening'); parent = this.parent();
var dropdownOfThis = $(this).parent().parent(); else
var actives = dropdownOfThis.find('ul.dropdown-menu.open'); parent = window;
if (actives && actives.length) { if (settings.mode != "horizontally") {
var hasData = actives.data('phase'); this.css("top", Math.max
if (hasData && hasData=='opened') { (0, ((jQuery(parent).height() - jQuery(this).outerHeight()) / 2) + jQuery(parent).scrollTop()) + "px");
actives.removeClass('open'); }
actives.siblings('a.active').removeClass('active'); if (settings.mode != "vertically") {
hasData || actives.data('phase', null); this.css("left", Math.max
(0, ((jQuery(parent).width() - jQuery(this).outerWidth()) / 2) + jQuery(parent).scrollLeft()) + "px");
}
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"});
// navs
jQuery(".nav ul.dropdown-menu").not("#w2p-auth-bar").each(function() {
var toggle = jQuery(this).parent();
if (toggle.parent().hasClass("nav")) {
toggle.attr("data-w2pmenulevel", "l0");
toggle.children("a")
.addClass("dropdown-toggle")
.append('<span class="caret"> </span>')
.attr("data-toggle", "dropdown");
} else {
toggle.addClass("dropdown-submenu").removeClass("dropdown");
}; };
}; });
submenu.toggleClass('open').data('phase','opened');
$(this).toggleClass('active');
}else{
window.location=$(this).attr('href');
};
});
$(".nav-tabs .web2py-menu-active").addClass('active'); jQuery('.navbar-nav a.dropdown-toggle').click(function(e) {
$(".nav-tabs a").not(".dropdown-toggle").attr("data-toggle", "tab"); if (menu_is_collapsed())
e.preventDefault();
else
window.location=jQuery(this).attr('href');
});
// form fixes jQuery(".dropdown-submenu>a").click(function(event) {
$(document).ready(function() { if (menu_is_collapsed()) {
$("form.bs3-form .w2p_list a").each(function() { event.preventDefault();
// the plus and minus buttons are generated by web2py.js event.stopPropagation();
$(this).addClass('btn btn-default'); var submenu = jQuery(this).parent().children("ul");
}); submenu.data('phase','opening');
$("form.bs3-form p.w2p-autocomplete-widget").each(function() { var dropdownOfThis = jQuery(this).parent().parent();
// not generated by formstyle var actives = dropdownOfThis.find('ul.dropdown-menu.open');
$(this).children('input').addClass('form-control'); if (actives && actives.length) {
}); var hasData = actives.data('phase');
$("form.bs3-form input[name='password_two']").each(function() { if (hasData && hasData=='opened') {
// auth addition after form creation actives.removeClass('open');
var $this = $(this).addClass('form-control'); actives.siblings('a.active').removeClass('active');
var groupClass = 'form-group' hasData || actives.data('phase', null);
var labelClass = 'control-label'; };
var commentClass = 'help-block'; };
var comment; submenu.toggleClass('open').data('phase','opened');
var mode; jQuery(this).toggleClass('active');
var hasError = false; }else{
if ($this.parent().hasClass('form-horizontal')) { window.location=jQuery(this).attr('href');
mode = 'horizontal'; };
labelClass = fh_label_class+' control-label'; });
};
if ($this.parent().hasClass('form-inline')) { jQuery(".nav-tabs .web2py-menu-active").addClass('active');
mode = 'inline'; jQuery(".nav-tabs a").not(".dropdown-toggle").attr("data-toggle", "tab");
labelClass = 'sr-only';
commentClass = 'sr-only'; // form fixes
var labelText = $this.prev('label').text(); jQuery("ul.w2p_list").css('margin-left',0);
$this.attr("placeholder", labelText.slice(0,-2)); jQuery("ul.w2p_list input").addClass('form-control');
}; jQuery("input.date,input.time,input.datetime,input.double,input.integer").css('width','33.33333333%');
var error = $this.next('div.error_wrapper'); // the plus and minus buttons are generated by web2py.js
if (error.length > 0) { jQuery("form.bs3-form .w2p_list a").addClass('btn btn-default');
var hasError = true; // not generated by formstyle
groupClass = 'form-group has-error' jQuery("form.bs3-form p.w2p-autocomplete-widget input").addClass('form-control');
var text = error[0].nextSibling.nodeValue; 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) { if (text) {
comment = "<span class='"+commentClass+"'>"+text+"</span>"; comment = "<span class='"+commentClass+"'>"+text+"</span>";
error[0].parentNode.removeChild(error[0].nextSibling); error[0].parentNode.removeChild(error[0].nextSibling);
}; };
} else { } else {
var text = $this[0].nextSibling.nodeValue; var text = self[0].nextSibling.nodeValue;
if (text) { if (text) {
comment = "<span class='"+commentClass+"'>"+text+"</span>"; comment = "<span class='"+commentClass+"'>"+text+"</span>";
$this[0].parentNode.removeChild($this[0].nextSibling); self[0].parentNode.removeChild(self[0].nextSibling);
};
}; };
}; self.prev('label').addClass(labelClass).andSelf().wrapAll("<div class='"+groupClass+"' id='auth_user_verify_password__row'></div>");
$this.prev('label').addClass(labelClass).andSelf().wrapAll("<div class='"+groupClass+"' id='auth_user_verify_password__row'></div>"); if (mode == 'horizontal') {
if (mode == 'horizontal') { self.wrap('<div class="'+fh_control_class+'"></div>');
$this.wrap('<div class="'+fh_control_class+'"></div>'); };
}; if (hasError) {
if (hasError) { self.parent().append(error);
$this.parent().append(error); };
}; self.parent().append(comment);
$this.parent().append(comment); });
}); jQuery('form.bs3-form #auth_user_remember').each(function() {
$('form.bs3-form #auth_user_remember').each(function() { // auth addition after form creation
// auth addition after form creation var $input = jQuery(this);
var $input = $(this); var $label = $input.next('label');
var $label = $input.next('label'); var $iParent = $input.parent();
var $iParent = $input.parent(); $input.removeClass('checkbox');
$input.removeClass('checkbox'); $iParent.prev('label').remove();
$iParent.prev('label').remove(); $input.prependTo($label);
$input.prependTo($label); var newGroup = $label;
var newGroup = $label; $iParent.replaceWith(newGroup);
$iParent.replaceWith(newGroup); if (newGroup.parent().hasClass('form-horizontal')) {
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>'));
newGroup.wrap($('<div class="form-group"><div class="'+fh_offest_class+' '+fh_control_class+'"><div class="checkbox"></div></div></div>')); } else {
} else { newGroup.wrap(jQuery('<div class="form-group"><div class="checkbox"></div></div>'));
newGroup.wrap($('<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');
// form errors // uploadwidget
$('form.bs3-form .error_wrapper').each(function() { jQuery('#file-reset-btn').click(function() {
var $this = $(this) var el = jQuery('div.w2p-uploaded-file')[0];
var rcContainer = $this.parents('.rc_container'); var whatReset = jQuery.data(el, "reset");
if (rcContainer.length > 0) { if (whatReset == "changed") {
$this.appendTo(rcContainer); 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();
$('form.bs3-form').find('div.error').addClass('text-danger').closest(".form-group").addClass('has-error'); } 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");
});
// uploadwidget // on page load
$('#file-reset-btn').click(function() {
var el = $('div.w2p-uploaded-file')[0];
var whatReset = jQuery.data(el, "reset");
if (whatReset == "changed") {
$('.w2p-uploaded-file input[type="file"]')
.replaceWith(
$('.w2p-uploaded-file input[type="file"]')
.clone());
$('.w2p-file-preview, .w2p-uploaded-file input[type="file"], #edit-btn-dd, #file-reset-btn').toggle();
}else{
$('.w2p-file-preview, #no-file, #edit-btn-dd, #file-reset-btn').toggle();
$('div.w2p-uploaded-file').children('input[type=checkbox]').trigger('click');
}
jQuery.removeData(el, "reset");
});
$('#change-file-option').click(function(e) {
e.preventDefault();
$('.w2p-file-preview, .w2p-uploaded-file input[type="file"], #edit-btn-dd, #file-reset-btn').toggle();
jQuery.data($('div.w2p-uploaded-file')[0], "reset", "changed");
});
$('#delete-file-option').click(function(e) {
e.preventDefault();
var wimg = $('#image-thumb').outerWidth(),
himg = $('#image-thumb').outerHeight();
$('#no-file')
.width(wimg)
.height(himg)
.css({'line-height':himg+'px'});
$('.w2p-file-preview, #no-file, #edit-btn-dd, #file-reset-btn').toggle();
$('div.w2p-uploaded-file').children('input[type=checkbox]').trigger('click');
jQuery.data($('div.w2p-uploaded-file')[0], "reset", "deleted");
});
// on page load
adjust_maxheight_of_collapsed_nav();
// resize and orientation change events
$(window).on('orientationchange resize', function(event) {
adjust_maxheight_of_collapsed_nav(); adjust_maxheight_of_collapsed_nav();
$('.flash.alert').center({'mode':"horizontally"});
if (menu_is_collapsed() === false) {
closeSubmenu();
$('.navbar-nav .dropdown.open a.dropdown-toggle').dropdown('toggle');
$('#main-menu.in, #login-menu.in').collapse('hide');
};
});
}(jQuery)); // resize and orientation change events
jQuery(window).on('orientationchange resize', function(event) {
adjust_maxheight_of_collapsed_nav();
jQuery('.flash.alert').center({'mode':"horizontally"});
if (menu_is_collapsed() === false) {
closeSubmenu();
jQuery('.navbar-nav .dropdown.open a.dropdown-toggle').dropdown('toggle');
jQuery('#main-menu.in, #login-menu.in').collapse('hide');
};
});
});