Esempio n. 1
0
    def widget(field, value):
        default = dict(value=[{
            'id': _id,
            'represent': field.represent([_id])
        } for _id in value],
                       _url=URL('default',
                                'api',
                                args=['tags', 'contains', '__query__.json'],
                                vars=dict(limit=25)),
                       _filterby='tag')
        default['_@selected'] = 'itemSelected($event)'
        attr = FormWidget._attributes(field, default)
        attr.update(default)
        wautocomplete = TAG['w-autocomplete'](**attr)
        attr2 = {
            '_:items': 'items',
            '_display_prop': 'tag',
            '_@deleted': "itemDeleted"
        }
        wchiplist = TAG['w-chip-list'](**attr2)
        options = [
            OPTION(field.represent([id_]), _value=id_, _selected=True)
            for id_ in value
        ]
        sattr = FormWidget._attributes(field, dict(_multiple=True, _hidden=""))
        #sattr.update(dict(_multiple=True))
        select = SELECT(*options, **sattr)

        return DIV(wautocomplete, wchiplist, select)
Esempio n. 2
0
    def widget(field, value, **attributes):
        default = {'value': value}

        attributes = FormWidget._attributes(field, default, **attributes)
        # attributes['_class'] = 'form-control input-append date form_datetime'
        attributes['_class'] = 'form-control form_datetime'

        dateinput = INPUT(**attributes)
        settings_str = ',\n'.join(
            item[0] + ':' + str(item[1])
            for item in settings.iteritems()) if settings else ''
        javascript = SCRIPT(
            """
            $('head').append($('<link  href="%(cssurl)s" type="text/css" rel="stylesheet" />'));
            $.getScript('%(scripturl)s').done(function(){
                $('#%(_id)s').datetimepicker({
                    format: w2p_ajax_datetime_format.replace('%%Y', 'yyyy').replace('%%m', 'mm').replace('%%d', 'dd').replace('%%H', 'hh').replace('%%M', 'ii').replace('%%S', '00'),
                    %(settings)s
                })
            });
            """ % {
                'cssurl':
                URL('static',
                    'plugin_bs_datepicker/bootstrap-datetimepicker.css'),
                'scripturl':
                URL('static',
                    'plugin_bs_datepicker/bootstrap-datetimepicker.js'),
                '_id':
                dateinput.attributes['_id'],
                'settings':
                settings_str
            })
        return CAT(dateinput, javascript)
    def widget(field, value, **attributes):
        _set_files(FILES)

        default = {'value': value}
        attributes = FormWidget._attributes(field, default, **attributes)

        if value and len(value) > 1:
            lat, lng = IS_GEOLOCATION.parse_geopoint(value)
            settings.marker_options['position'] = {'lat': lat, 'lng': lng}
            settings.map_options['center'] = {'lat': lat, 'lng': lng}
        else:
            if 'position' in settings.marker_options:
                lat, lng = (settings.marker_options['position']['lat'],
                            settings.marker_options['position']['lng'])
            else:
                lat, lng = 0.0, 0.0

        html = CAT(
            DIV(DIV(INPUT(_id=settings.latid,
                          _value=lat,
                          _class='latitude form-control'),
                    _class='col-lg-6 col-md-6'),
                DIV(INPUT(_id=settings.lngid,
                          _value=lng,
                          _class='longitude form-control'),
                    _class='col-lg-6 col-md-6'),
                INPUT(_type='hidden', **attributes),
                _class='row form-group'),
            DIV(DIV(DIV(_id=settings.mapid,
                        _class='map',
                        _style='width: %(width)spx; height: %(height)spx' %
                        settings),
                    _class='col-lg-12 col-md-12'),
                _class='row form-group'))
        hidden_id = attributes['_id']

        javascript = SCRIPT(
            """
            $('#%(mapid)s').geolocate({
                lat: '#%(latid)s',
                lng: '#%(lngid)s',
                markerOptions: %(marker_options)s,
                mapOptions: %(map_options)s
                });
            $('#%(latid)s').closest('form').submit(function() {
                    $('#%(hidden_id)s').val('POINT (' + $('#%(latid)s').val() + ' ' + $('#%(lngid)s').val() + ')');
                });        
            """ % {
                'mapid': settings.mapid,
                'latid': settings.latid,
                'lngid': settings.lngid,
                'marker_options': json_parser.dumps(settings.marker_options),
                'map_options': json_parser.dumps(settings.map_options),
                'hidden_id': hidden_id
            })
        return CAT(html, javascript)
Esempio n. 4
0
    def widget(field, value, **attributes):

        default = {'_value': value}
        attributes = FormWidget._attributes(field, default, **attributes)
        attributes['_class'] = 'form-control time'

        data_attributes = {}
        for item in settings.items():
            data_attributes[item[0].replace('_', '-')] = item[1]

        return INPUT(data=data_attributes,
                     _placeholder=placeholder,
                     **attributes)
Esempio n. 5
0
    def widget(field, value, **attributes):

        default = {'value': value}

        attributes = FormWidget._attributes(field, default, **attributes)
        attributes['_class'] = 'form-control date'

        # default format “mm/dd/yyyy”

        data_attributes = {}
        data_attributes['date-format'] = 'yyyy-mm-dd'
        for item in settings.iteritems():
            data_attributes['date-' + item[0].replace('_', '-')] = item[1]

        return INPUT(data=data_attributes, **attributes)
Esempio n. 6
0
    def widget(self, field, value, **attributes):
        """
        To be used with db.table.field.widget to set CKEditor as the desired widget for the field.
        Simply set db.table.field.widget = ckeditor.widget to use the CKEditor widget.
        """
        default = dict(value=value, _cols=80, _rows=10)

        attributes = FormWidget._attributes(field, default, **attributes)
        attributes['_class'] = 'text plugin_ckeditor'

        textarea = TEXTAREA(**attributes)
        javascript = self.load('#' + textarea.attributes['_id'],
                               use_caching=False)
        result = CAT(textarea, javascript)

        return result
Esempio n. 7
0
    def widget(field, value, **attributes):

        default = {'_value': value}

        attributes = FormWidget._attributes(field, default, **attributes)
        attributes['_class'] = 'form-control date'

        data_attributes = {}
        data_attributes['date-format'] = 'dd.mm.yyyy'
        data_attributes['date-week-start'] = 1
        data_attributes['date-calendar-weeks'] = True
        for item in settings.items():
            data_attributes['date-' + item[0].replace('_', '-')] = item[1]

        return INPUT(data=data_attributes,
                     _placeholder=placeholder,
                     **attributes)
Esempio n. 8
0
    def widget(field, value, **attributes):

        default = {'value': value}

        attributes = FormWidget._attributes(field, default, **attributes)
        attributes['_class'] = 'form-control date'

        # default format “mm/dd/yyyy”

        data_attributes = {}
        data_attributes['date-format'] = 'yyyy-mm-dd'
        for item in settings.iteritems():
            data_attributes['date-'+item[0].replace('_', '-')] = item[1]

        return INPUT(
            data=data_attributes,
            **attributes
        )
Esempio n. 9
0
    def widget(self, field, value, **attributes):
        """
        To be used with db.table.field.widget to set CKEditor as the desired widget for the field.
        Simply set db.table.field.widget = ckeditor.widget to use the CKEditor widget.
        """
        default = dict(
            value = value,
            _cols = 80,
            _rows = 10
        )
        
        attributes = FormWidget._attributes(field, default, **attributes)
        attributes['_class'] = 'text plugin_ckeditor'
                    
        textarea = TEXTAREA(**attributes)
        javascript = self.load('#' + textarea.attributes['_id'], use_caching=False)
        result = CAT(textarea, javascript)

        return result