Exemplo n.º 1
0
def host_a_maker(record=None):
    """
    Give a host record, return a A object that will open a new window
    to that host record
    """

    from gluon.html import A, I, URL, SPAN

    if record is None:
        return A()

    if isinstance(record, type([str, int])):
        record = get_host_record(record)

    host_a = A(host_title_maker(record),
               _target="host_detail_%s" % (record.id),
               _href=URL('hosts', 'detail', extension='html', args=record.id))

    info_a = SPAN(A(I(_class='icon-info-sign'),
                    _href='#',
                    _class='withajaxpopover',
                    **{
                        '_data-load': URL('hosts',
                                          'popover.json',
                                          args=record.id),
                        '_data-trigger': 'hover',
                        '_data-delay': "{show: 500, hide: 100}",
                        '_data-placement': 'right',
                        '_data-html': 'true',
                        '_data-container': '#popoverwrap'
                    }),
                  _id="popoverwrap")

    return SPAN(host_a, info_a)
Exemplo n.º 2
0
def myfolderwidget(field, value, **attributes):
    _id = "%s_%s" % (field._tablename, field.name)
    attr = attributes
    attributes['_class'] = "%sfolders span10" % attributes.get('_class', ' ')
    _style = "display: inline-block;"
    attributes['_style'] = _style
    default_input = SQLFORM.widgets.string.widget(field, value, **attributes)
    return DIV(SPAN(I(_class="icon-folder-open"),_class="add-on"),default_input, _class="input-prepend span9", _style=_style)
Exemplo n.º 3
0
def myfolderwidgetmultiple(field, value, **attributes):
    _id = '%s_%s' % (field._tablename, field.name)
    _name = field.name
    _class = 'string folders span10'
    _style = "display: inline-block;"
    requires = field.requires if isinstance(field.requires,
                                            (IS_NOT_EMPTY,
                                             IS_LIST_OF)) else None
    items = [
        LI(
            DIV(SPAN(I(_class="icon-folder-open"), _class="add-on"),
                INPUT(_class=_class,
                      _name=_name,
                      value=v,
                      hideerror=True,
                      requires=requires,
                      _style=_style),
                _class="input-prepend span9",
                _style=_style)) for v in value or ['']
    ]
    script = SCRIPT("""
// from http://refactormycode.com/codes/694-expanding-input-list-using-jquery
(function(){
jQuery.fn.grow_input_fold = function() {
return this.each(function() {
var ul = this;
jQuery(ul).find(":text").after('<a href="javascript:void(0)">+</a>').keypress(function (e) { return (e.which == 13) ? pe(ul) : true; }).next().click(function(){ pe(ul) });
});
};
function pe(ul) {
var new_line = ml(ul);
rel(ul);
new_line.appendTo(ul);
new_line.find(":text").focus().after('<a href="javascript:void(0)">+</a>').keypress(function (e) { return (e.which == 13) ? pe(ul) : true; }).next().click(function(){ pe(ul) });
new_line.find(":text").scanfolders();
return false;
}
function ml(ul) {
var line = jQuery(ul).find("li:first").clone();
line.find(':text').val('');
line.find('a').remove();
return line;
}
function rel(ul) {
return;
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_fold();
    });
""" % _id)
    attributes['_id'] = _id + '_grow_input'
    return TAG[''](UL(*items, _class="unstyled", **attributes), script)
Exemplo n.º 4
0
 def btn_show(self):
     # Button to trigger modal .
    btn_show_modal = A(I(_class="icon-plus-sign"),
                         ' ', self.value,
                         **{"_role": "button",
                            #"_class": "btn btn-link",
                           "_data-toggle": "modal",
                            "_href": "#%s" % self.modal_id,
                            "_title": self.title_btn})
    return btn_show_modal
Exemplo n.º 5
0
def nice_species_name(scientific=None,
                      common=None,
                      the=False,
                      html=False,
                      leaf=False,
                      first_upper=False,
                      break_line=None):
    """
    Constructs a nice species name, with common name in there too.
    If leaf=True, add a 'species' tag to the scientific name
    If break_line == 1, put a line break after common (if it exists)
    If break_line == 2, put a line break after sciname (even if common exists)
    
    TODO - needs internationalization
    """
    from gluon.html import CAT, I, SPAN, BR
    db = current.db
    species_nicename = (scientific or '').replace('_', ' ').strip()
    common = (common or '').strip()
    if the:
        common = add_the(common, leaf)
    if first_upper:
        common = common.capitalize()
    if html:
        if species_nicename:
            if leaf:  #species in italics
                species_nicename = I(species_nicename,
                                     _class=" ".join(["taxonomy", "species"]))
            else:
                species_nicename = SPAN(species_nicename, _class="taxonomy")
            if common:
                if break_line:
                    return CAT(common, BR(), '(', species_nicename, ')')
                else:
                    return CAT(common, ' (', species_nicename, ')')
            else:
                if break_line == 2:
                    return CAT(BR(), species_nicename)
                else:
                    return species_nicename
        else:
            return common
    else:
        if common and species_nicename:
            if break_line:
                return common + '\n(' + species_nicename + ')'
            else:
                return common + ' (' + species_nicename + ')'
        else:
            if break_line == 2:
                return common + "\n" + species_nicename
            else:
                return common + species_nicename
Exemplo n.º 6
0
 def btn_show(self,
              icon="icon-plus",
              btn_role="button",
              btn_class="btn btn-small"):
     """
     Generates an A() button object. By default a btn class and icon object are created
     but sending obj.btn_show(btn_role="", btn_class="", icon="") will clear all that.
     """
     btn_show_modal = A(
         I(_class=icon), ' ', self.value, **{
             "_role": btn_role,
             "_class": btn_class,
             "_data-toggle": "modal",
             "_href": "#%s" % self.modal_id,
             "_title": self.title_btn
         })
     return btn_show_modal
Exemplo n.º 7
0
 def test_I(self):
     self.assertEqual(
         I('<>', _a='1', _b='2').xml(), b'<i a="1" b="2">&lt;&gt;</i>')
Exemplo n.º 8
0
def formstyle_bootstrap_modal(form, fields, **kwargs):
    """"
    Bootstrap format modal form layout
    """
    span = kwargs.get('span') or 'span8'
    select_attributes = kwargs.get('select_attributes', '')
    form.add_class('form-horizontal')
    parent = FIELDSET()
    for id, label, controls, help in fields:
        _controls = DIV(controls, _class='controls')
        # submit unflag by default
        _submit = False

        if isinstance(controls, INPUT):
            controls.add_class(span)
            if controls['_type'] == 'submit':
                # flag submit button
                _submit = True
                controls['_class'] = 'btn btn-primary'
            if controls['_type'] == 'file':
                controls['_class'] = 'input-file'

        # For password fields, which are wrapped in a CAT object.
        if isinstance(controls, CAT) and isinstance(controls[0], INPUT):
            controls[0].add_class(span)

        if isinstance(controls, SELECT):
            controls.add_class(span)

        if isinstance(controls, TEXTAREA):
            controls.add_class(span)

        if isinstance(label, LABEL):
            label['_class'] = 'control-label'
            if help:
                label.append(
                    I(_class="icon-question-sign",
                      _rel="tooltip",
                      **{'_data-content': help}))

        if _submit:
            # submit button has unwrapped label and controls, different class
            parent.append(
                DIV(label,
                    BUTTON("Close",
                           _class="btn",
                           **{
                               '_data-dismiss': 'modal',
                               '_aria-hidden': True
                           }),
                    controls,
                    _class='modal-footer',
                    _id=id))
            # unflag submit (possible side effect)
            _submit = False
        else:
            # unwrapped label
            _class = 'control-group'
            parent.append(DIV(label, _controls, _class=_class, _id=id))

    # append tooltip and chosen field attributes
    if 'id' not in form.attributes:
        form.attributes['_id'] = "%s-id" % (str(form.table))
    script_data = """$(document).ready(function() {{
    $("[rel=tooltip]").popover({{
        placement: 'right',
        trigger: 'hover',
    }});
    $('#{0:s} select').select2({{{1:s}}});
    {2:s}
}});""".format(form.attributes['_id'], select_attributes,
               kwargs.get('script', ''))
    parent.append(SCRIPT(script_data))
    return parent