nicer alignment, removed leftovers, new listwidget and passwordwidget

This commit is contained in:
niphlod
2013-06-27 00:25:44 +02:00
parent cdf8ee8d85
commit 81495f7cca
4 changed files with 282 additions and 258 deletions
+26 -3
View File
@@ -143,6 +143,7 @@
$('.hidden', target).hide(); $('.hidden', target).hide();
web2py.manage_errors(target); web2py.manage_errors(target);
web2py.ajax_fields(target); web2py.ajax_fields(target);
web2py.show_if_handler(target);
}, },
//manage errors in forms //manage errors in forms
manage_errors: function(target) { manage_errors: function(target) {
@@ -155,7 +156,6 @@
*/ */
var doc = $(document); var doc = $(document);
doc.on('click', '.flash', function (e) { doc.on('click', '.flash', function (e) {
console.log('das');
var t = $(this); var t = $(this);
if(t.css('top') == '0px') t.slideUp('slow'); if(t.css('top') == '0px') t.slideUp('slow');
else t.fadeOut(); else t.fadeOut();
@@ -275,10 +275,10 @@
var jelement = $("#" + target); var jelement = $("#" + target);
var element = jelement.get(0); var element = jelement.get(0);
var statement = "jQuery('#" + target + "').get(0).reload();"; var statement = "jQuery('#" + target + "').get(0).reload();";
element.reload = function () { jelement.reload = function () {
// Continue if times is Infinity or // Continue if times is Infinity or
// the times limit is not reached // the times limit is not reached
if(this.reload_check()) { if(element.reload_check()) {
web2py.ajax_page('get', action, null, target, el); web2py.ajax_page('get', action, null, target, el);
} }
}; // reload }; // reload
@@ -461,6 +461,29 @@
hide_flash: function() { hide_flash: function() {
$('.flash').hide().html(''); $('.flash').hide().html('');
}, },
show_if_handler: function(target) {
var triggers = {};
var show_if = function () {
var t = $(this);
var id = t.attr('id');
t.attr('value', t.val());
for(var k = 0; k < triggers[id].length; k++) {
var dep = $('#' + triggers[id][k], target);
var tr = $('#' + triggers[id][k] + '__row', target);
if(t.is(dep.attr('data-show-if'))) tr.slideDown();
else tr.hide();
}
};
$('[data-show-trigger]', target).each(function () {
var name = $(this).attr('data-show-trigger');
if(!triggers[name]) triggers[name] = [];
triggers[name].push($(this).attr('id'));
});
for(var name in triggers) {
$('#' + name, target).change(show_if).keyup(show_if);
show_if.call($('#' + name, target));
};
},
a_handler: function (el, e) { a_handler: function (el, e) {
e.preventDefault(); e.preventDefault();
var method = el.data('w2p_method'); var method = el.data('w2p_method');
+26 -3
View File
@@ -143,6 +143,7 @@
$('.hidden', target).hide(); $('.hidden', target).hide();
web2py.manage_errors(target); web2py.manage_errors(target);
web2py.ajax_fields(target); web2py.ajax_fields(target);
web2py.show_if_handler(target);
}, },
//manage errors in forms //manage errors in forms
manage_errors: function(target) { manage_errors: function(target) {
@@ -155,7 +156,6 @@
*/ */
var doc = $(document); var doc = $(document);
doc.on('click', '.flash', function (e) { doc.on('click', '.flash', function (e) {
console.log('das');
var t = $(this); var t = $(this);
if(t.css('top') == '0px') t.slideUp('slow'); if(t.css('top') == '0px') t.slideUp('slow');
else t.fadeOut(); else t.fadeOut();
@@ -275,10 +275,10 @@
var jelement = $("#" + target); var jelement = $("#" + target);
var element = jelement.get(0); var element = jelement.get(0);
var statement = "jQuery('#" + target + "').get(0).reload();"; var statement = "jQuery('#" + target + "').get(0).reload();";
element.reload = function () { jelement.reload = function () {
// Continue if times is Infinity or // Continue if times is Infinity or
// the times limit is not reached // the times limit is not reached
if(this.reload_check()) { if(element.reload_check()) {
web2py.ajax_page('get', action, null, target, el); web2py.ajax_page('get', action, null, target, el);
} }
}; // reload }; // reload
@@ -461,6 +461,29 @@
hide_flash: function() { hide_flash: function() {
$('.flash').hide().html(''); $('.flash').hide().html('');
}, },
show_if_handler: function(target) {
var triggers = {};
var show_if = function () {
var t = $(this);
var id = t.attr('id');
t.attr('value', t.val());
for(var k = 0; k < triggers[id].length; k++) {
var dep = $('#' + triggers[id][k], target);
var tr = $('#' + triggers[id][k] + '__row', target);
if(t.is(dep.attr('data-show-if'))) tr.slideDown();
else tr.hide();
}
};
$('[data-show-trigger]', target).each(function () {
var name = $(this).attr('data-show-trigger');
if(!triggers[name]) triggers[name] = [];
triggers[name].push($(this).attr('id'));
});
for(var name in triggers) {
$('#' + name, target).change(show_if).keyup(show_if);
show_if.call($('#' + name, target));
};
},
a_handler: function (el, e) { a_handler: function (el, e) {
e.preventDefault(); e.preventDefault();
var method = el.data('w2p_method'); var method = el.data('w2p_method');
+26 -3
View File
@@ -143,6 +143,7 @@
$('.hidden', target).hide(); $('.hidden', target).hide();
web2py.manage_errors(target); web2py.manage_errors(target);
web2py.ajax_fields(target); web2py.ajax_fields(target);
web2py.show_if_handler(target);
}, },
//manage errors in forms //manage errors in forms
manage_errors: function(target) { manage_errors: function(target) {
@@ -155,7 +156,6 @@
*/ */
var doc = $(document); var doc = $(document);
doc.on('click', '.flash', function (e) { doc.on('click', '.flash', function (e) {
console.log('das');
var t = $(this); var t = $(this);
if(t.css('top') == '0px') t.slideUp('slow'); if(t.css('top') == '0px') t.slideUp('slow');
else t.fadeOut(); else t.fadeOut();
@@ -275,10 +275,10 @@
var jelement = $("#" + target); var jelement = $("#" + target);
var element = jelement.get(0); var element = jelement.get(0);
var statement = "jQuery('#" + target + "').get(0).reload();"; var statement = "jQuery('#" + target + "').get(0).reload();";
element.reload = function () { jelement.reload = function () {
// Continue if times is Infinity or // Continue if times is Infinity or
// the times limit is not reached // the times limit is not reached
if(this.reload_check()) { if(element.reload_check()) {
web2py.ajax_page('get', action, null, target, el); web2py.ajax_page('get', action, null, target, el);
} }
}; // reload }; // reload
@@ -461,6 +461,29 @@
hide_flash: function() { hide_flash: function() {
$('.flash').hide().html(''); $('.flash').hide().html('');
}, },
show_if_handler: function(target) {
var triggers = {};
var show_if = function () {
var t = $(this);
var id = t.attr('id');
t.attr('value', t.val());
for(var k = 0; k < triggers[id].length; k++) {
var dep = $('#' + triggers[id][k], target);
var tr = $('#' + triggers[id][k] + '__row', target);
if(t.is(dep.attr('data-show-if'))) tr.slideDown();
else tr.hide();
}
};
$('[data-show-trigger]', target).each(function () {
var name = $(this).attr('data-show-trigger');
if(!triggers[name]) triggers[name] = [];
triggers[name].push($(this).attr('id'));
});
for(var name in triggers) {
$('#' + name, target).change(show_if).keyup(show_if);
show_if.call($('#' + name, target));
};
},
a_handler: function (el, e) { a_handler: function (el, e) {
e.preventDefault(); e.preventDefault();
var method = el.data('w2p_method'); var method = el.data('w2p_method');
+4 -49
View File
@@ -295,57 +295,15 @@ class ListWidget(StringWidget):
_class = 'string' _class = 'string'
requires = field.requires if isinstance( requires = field.requires if isinstance(
field.requires, (IS_NOT_EMPTY, IS_LIST_OF)) else None field.requires, (IS_NOT_EMPTY, IS_LIST_OF)) else None
attributes['_style'] = 'list-style:none'
nvalue = value or [''] nvalue = value or ['']
items = [LI(INPUT(_id=_id, _class=_class, _name=_name, items = [LI(INPUT(_id=_id, _class=_class, _name=_name,
value=v, hideerror=k < len(nvalue) - 1, value=v, hideerror=k < len(nvalue) - 1,
requires=requires), requires=requires),
**attributes) for (k, v) in enumerate(nvalue)] **attributes) for (k, v) in enumerate(nvalue)]
script = SCRIPT("""
// from http://refactormycode.com/codes/694-expanding-input-list-using-jquery
(function(){
jQuery.fn.grow_input = function() {
return this.each(function() {
var ul = this;
jQuery(ul).find(":text").after('<a href="javascript:void(0)">+</a>&nbsp;<a href="javascript:void(0)">-</a>').keypress(function (e) { return (e.which == 13) ? pe(ul, e) : true; }).next().click(function(e){ pe(ul, e) }).next().click(function(e){ rl(ul, e)});
});
};
function pe(ul, e) {
var new_line = ml(ul);
rel(ul);
if (jQuery(e.target).parent().is(':visible')) {
//make sure we didn't delete the element before we insert after
new_line.insertAfter(jQuery(e.target).parent());
} else {
//the line we clicked on was deleted, just add to end of list
new_line.appendTo(ul);
}
new_line.find(":text").focus();
return false;
}
function rl(ul, e) {
if (jQuery(ul).children().length > 1) {
//only remove if we have more than 1 item so the list is never empty
jQuery(e.target).parent().remove();
}
}
function ml(ul) {
var line = jQuery(ul).find("li:first").clone(true);
line.find(':text').val('');
return line;
}
function rel(ul) {
jQuery(ul).find("li").each(function() {
var trimmed = jQuery.trim(jQuery(this.firstChild).val());
if (trimmed=='') jQuery(this).remove(); else jQuery(this.firstChild).val(trimmed);
});
}
})();
jQuery(document).ready(function(){jQuery('#%s_grow_input').grow_input();});
""" % _id)
attributes['_id'] = _id + '_grow_input' attributes['_id'] = _id + '_grow_input'
attributes['_style'] = 'list-style:none' attributes['_style'] = 'list-style:none'
return TAG[''](UL(*items, **attributes), script) attributes['_class'] = 'w2p_list'
return TAG[''](UL(*items, **attributes))
class MultipleOptionsWidget(OptionsWidget): class MultipleOptionsWidget(OptionsWidget):
@@ -521,7 +479,6 @@ class PasswordWidget(FormWidget):
_value=(value and cls.DEFAULT_PASSWORD_DISPLAY) or '', _value=(value and cls.DEFAULT_PASSWORD_DISPLAY) or '',
) )
attr = cls._attributes(field, default, **attributes) attr = cls._attributes(field, default, **attributes)
output = CAT(INPUT(**attr))
# deal with entropy check! # deal with entropy check!
requires = field.requires requires = field.requires
@@ -529,10 +486,9 @@ class PasswordWidget(FormWidget):
requires = [requires] requires = [requires]
is_strong = [r for r in requires if isinstance(r, IS_STRONG)] is_strong = [r for r in requires if isinstance(r, IS_STRONG)]
if is_strong: if is_strong:
output.append(SCRIPT("web2py_validate_entropy(jQuery('#%s'),%s);" % ( attr['_data-w2p_entropy'] = is_strong[0].entropy if is_strong[0].entropy else "null"
attr['_id'], is_strong[0].entropy
if is_strong[0].entropy else "null")))
# end entropy check # end entropy check
output = INPUT(**attr)
return output return output
@@ -3136,4 +3092,3 @@ class ExporterJSON(ExportClass):
return self.rows.as_json() return self.rows.as_json()
else: else:
return 'null' return 'null'