nicer alignment, removed leftovers, new listwidget and passwordwidget
This commit is contained in:
+12
-57
@@ -86,8 +86,8 @@ def show_if(cond):
|
||||
if not cond:
|
||||
return None
|
||||
base = "%s_%s" % (cond.first.tablename, cond.first.name)
|
||||
if ((cond.op.__name__ == 'EQ' and cond.second == True) or
|
||||
(cond.op.__name__ == 'NE' and cond.second == False)):
|
||||
if ((cond.op.__name__ == 'EQ' and cond.second == True) or
|
||||
(cond.op.__name__ == 'NE' and cond.second == False)):
|
||||
return base,":checked"
|
||||
if ((cond.op.__name__ == 'EQ' and cond.second == False) or
|
||||
(cond.op.__name__ == 'NE' and cond.second == True)):
|
||||
@@ -97,7 +97,7 @@ def show_if(cond):
|
||||
if cond.op.__name__ == 'NE':
|
||||
return base,"[value!='%s']" % cond.second
|
||||
if cond.op.__name__ == 'CONTAINS':
|
||||
return base,"[value~='%s']" % cond.second
|
||||
return base,"[value~='%s']" % cond.second
|
||||
if cond.op.__name__ == 'BELONGS' and isinstance(cond.second,(list,tuple)):
|
||||
return base,','.join("[value='%s']" % (v) for v in cond.second)
|
||||
raise RuntimeError("Not Implemented Error")
|
||||
@@ -126,7 +126,7 @@ class FormWidget(object):
|
||||
_id='%s_%s' % (field.tablename, field.name),
|
||||
_class=cls._class or
|
||||
widget_class.match(str(field.type)).group(),
|
||||
_name=field.name,
|
||||
_name=field.name,
|
||||
requires=field.requires,
|
||||
)
|
||||
if getattr(field,'show_if',None):
|
||||
@@ -295,57 +295,15 @@ class ListWidget(StringWidget):
|
||||
_class = 'string'
|
||||
requires = field.requires if isinstance(
|
||||
field.requires, (IS_NOT_EMPTY, IS_LIST_OF)) else None
|
||||
attributes['_style'] = 'list-style:none'
|
||||
nvalue = value or ['']
|
||||
items = [LI(INPUT(_id=_id, _class=_class, _name=_name,
|
||||
value=v, hideerror=k < len(nvalue) - 1,
|
||||
requires=requires),
|
||||
**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> <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['_style'] = 'list-style:none'
|
||||
return TAG[''](UL(*items, **attributes), script)
|
||||
attributes['_class'] = 'w2p_list'
|
||||
return TAG[''](UL(*items, **attributes))
|
||||
|
||||
|
||||
class MultipleOptionsWidget(OptionsWidget):
|
||||
@@ -521,7 +479,6 @@ class PasswordWidget(FormWidget):
|
||||
_value=(value and cls.DEFAULT_PASSWORD_DISPLAY) or '',
|
||||
)
|
||||
attr = cls._attributes(field, default, **attributes)
|
||||
output = CAT(INPUT(**attr))
|
||||
|
||||
# deal with entropy check!
|
||||
requires = field.requires
|
||||
@@ -529,10 +486,9 @@ class PasswordWidget(FormWidget):
|
||||
requires = [requires]
|
||||
is_strong = [r for r in requires if isinstance(r, IS_STRONG)]
|
||||
if is_strong:
|
||||
output.append(SCRIPT("web2py_validate_entropy(jQuery('#%s'),%s);" % (
|
||||
attr['_id'], is_strong[0].entropy
|
||||
if is_strong[0].entropy else "null")))
|
||||
attr['_data-w2p_entropy'] = is_strong[0].entropy if is_strong[0].entropy else "null"
|
||||
# end entropy check
|
||||
output = INPUT(**attr)
|
||||
return output
|
||||
|
||||
|
||||
@@ -651,7 +607,7 @@ class AutocompleteWidget(object):
|
||||
self.help_fields = help_fields or []
|
||||
self.help_string = help_string
|
||||
if self.help_fields and not self.help_string:
|
||||
self.help_string = ' '.join('%%(%s)s'%f.name
|
||||
self.help_string = ' '.join('%%(%s)s'%f.name
|
||||
for f in self.help_fields)
|
||||
|
||||
self.request = request
|
||||
@@ -1484,7 +1440,7 @@ class SQLFORM(FORM):
|
||||
continue
|
||||
else:
|
||||
f = os.path.join(
|
||||
current.request.folder,
|
||||
current.request.folder,
|
||||
os.path.normpath(f))
|
||||
source_file = open(f, 'rb')
|
||||
original_filename = os.path.split(f)[1]
|
||||
@@ -2141,7 +2097,7 @@ class SQLFORM(FORM):
|
||||
else:
|
||||
rows = dbset.select(left=left, orderby=orderby,
|
||||
cacheable=True, *expcolumns)
|
||||
|
||||
|
||||
value = exportManager[export_type]
|
||||
clazz = value[0] if hasattr(value, '__getitem__') else value
|
||||
oExp = clazz(rows)
|
||||
@@ -2694,7 +2650,7 @@ class SQLFORM(FORM):
|
||||
elif grid.view_form:
|
||||
header = T('View %(entity)s') % dict(
|
||||
entity=format(grid.view_form.table,
|
||||
grid.view_form.record))
|
||||
grid.view_form.record))
|
||||
if next:
|
||||
breadcrumbs.append(LI(
|
||||
A(T(header), _class=trap_class(),_href=url()),
|
||||
@@ -3136,4 +3092,3 @@ class ExporterJSON(ExportClass):
|
||||
return self.rows.as_json()
|
||||
else:
|
||||
return 'null'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user