예제 #1
0
 def div_modal(self, content_modal):
     div_modal = DIV(
         DIV(
             # BUTTON("x", _type="button", _class="close", **{'data-dismiss':"modal", 'aria-hidden':"true"}),
             BUTTON(
                 "x", **{
                     "_type": "button",
                     "_class": "close",
                     "_data-dismiss": "modal",
                     "_aria-hidden": "true"
                 }),
             H3(self.title_modal, _id="myModalLabel"),
             _class="modal-header"),
         DIV(content_modal, _class="modal-body", _id="host-modal"),
         SCRIPT(
             "$('#%s').on('show', function () { $(this).find('.modal-body').css({'overflow-y':'scroll', 'width':'auto', 'height':'auto'});});"
             % self.modal_id),
         **{
             "_id": "%s" % self.modal_id,
             "_class": "modal hide face",
             "_tabindex": "-1",
             "_role": "dialog",
             "_data-keyboard": "false",
             "_aria-hidden": "true",
             "_aria-labelledby": "myModalLabel"
         })
     return div_modal
예제 #2
0
     def div_modal(self, content_modal):

         div_modal = DIV(
                         DIV(
                             H3(self.title_modal, _id="myModalLabel"),
                             _class="modal-header"),
                         DIV(content_modal, _class="modal-body"),
                         DIV(
                             BUTTON("Cerrar", **{"_class": "btn",
                                                 "_data-dismiss": "modal",
                                                 "_aria-hidden": "true"}),
                             _class="modal-footer",
                             ),
                         **{"_id": "%s" % self.modal_id,
                            "_class": "modal hide face",
                            "_tabindex": "-1",
                            "_role": "dialog",
                            "_aria-hidden": "true",
                            "_aria-labelledby": "myModalLabel"}
                     )
         return div_modal
예제 #3
0
 def test_BUTTON(self):
     self.assertEqual(
         BUTTON('test', _type='button').xml(),
         b'<button type="button">test</button>')
예제 #4
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