Example #1
0
    def prepare(self):
        if not getattr(self, 'entity', None):
            raise ValueError("SQLAjqGridWidget must be supplied an 'entity'")

        if not getattr(self, 'options', None):
            raise ValueError("SQLAjqGridWidget must be supplied an 'options'")

        if 'url' not in self.options:
            raise ValueError("SQLAjqGridWidget options must contain 'url'")

        _options = self.options
        super(SQLAjqGridWidget, self).prepare()

        pkey = sa.orm.class_mapper(self.entity).primary_key[0].key

        # Derive caption from table name if not passed as argument
        if 'caption' not in _options:
            name2label = tw2.core.util.name2label
            _options['caption'] = name2label(self.entity.__name__)

        # if 'sortname' not specified in _options, use pkey
        ## TODO:: should warn (or raise err) if the colModel option for the
        ##        specified column is {'sortable': False}
        if 'sortname' not in _options:
            _options['sortname'] = pkey

        # set datatype
        _options.update({'datatype': 'json'})

        _options.update(type(self)._get_metadata())
        self.options = encoder.encode(_options)
Example #2
0
        def handlerFunction(*args, **kwargs):
            if not self._initialized:
                raise ValueError, "panel not initialized.  call .init() first"
            if kwargs:
                raise ValueError, "keyword arguments are disallowed"

            if name.endswith('add'):
                js_id = "%s_%s" % (
                    args[0].src.replace('.',''),
                    str(uuid.uuid4()).replace('-','')
                )
                m = PVMark(
                    pvcls=args[0],
                    js_id=js_id,
                    parent_js_id=self.js_id,
                    add_method=name,
                ).req().init()
                self._adds.append(m)
                return m

            src=".%s(%s)" % (name, encoder.encode(args)[1:-1])

            if name.endswith('anchor'):
                return NameExtensionWrapper(mrk=self, pre=src[1:]).req().init()
               
            f = twc.JSSymbol(src=src)
            if f not in self._pv_prop_funcs:
                self._pv_prop_funcs.append(f)
            
            return self
    def prepare(self):
        if not getattr(self, 'entity', None):
            raise ValueError("SQLAjqGridWidget must be supplied an 'entity'")

        if not getattr(self, 'options', None):
            raise ValueError("SQLAjqGridWidget must be supplied an 'options'")

        if 'url' not in self.options:
            raise ValueError("SQLAjqGridWidget options must contain 'url'")

        _options = self.options
        super(SQLAjqGridWidget, self).prepare()

        pkey = sa.orm.class_mapper(self.entity).primary_key[0].key

        # Derive caption from table name if not passed as argument
        if not _options['caption']:
            _options.update(
                {'caption': tw2.core.util.name2label(self.entity.__name__)})

        _options.update({
            'sortname': pkey,
            'datatype': 'json',
        })

        _options.update(type(self)._get_metadata())
        self.options = encoder.encode(_options)
    def prepare(self):
        if not getattr(self, 'entity', None):
            raise ValueError("SQLAjqGridWidget must be supplied an 'entity'")

        if not getattr(self, 'options', None):
            raise ValueError("SQLAjqGridWidget must be supplied an 'options'")

        if 'url' not in self.options:
            raise ValueError("SQLAjqGridWidget options must contain 'url'")

        _options = self.options
        super(SQLAjqGridWidget, self).prepare()

        pkey = sa.orm.class_mapper(self.entity).primary_key[0].key

        # Derive caption from table name if not passed as argument
        if not _options['caption']:
            _options.update({
                'caption': tw2.core.util.name2label(self.entity.__name__)
            })

        _options.update({
            'sortname': pkey,
            'datatype': 'json',
        })

        _options.update(type(self)._get_metadata())
        self.options = encoder.encode(_options)
Example #5
0
    def prepare(self):
        if self.events is not None and not isinstance(self.events, dict):
            raise ValueError, 'Events parameter must be a dict'

        self.resources.append(jquery_ui_css(name=get_ui_theme_name()))
        self.options = encoder.encode(self.options)
        super(JQueryUIWidget, self).prepare()
        if not hasattr(self, 'id') or 'id' not in self.attrs:
            raise ValueError, 'JQueryWidget must be supplied an id'
        self.selector = self.attrs['id'].replace(':', '\\\\:')
 def request(cls, req):
     import webob
     data = make_data()
     minx, maxx, miny, maxy = find_bounds(data)
     options = {
         'axes': {
             'xaxis': {'min': minx, 'max': maxx},
             'yaxis': {'min': miny, 'max': maxy},
         }
     }
     json = encoder.encode(dict(data=data, options=options))
     return webob.Response(json, content_type="application/json")
Example #7
0
    def prepare(self):
        if self.events is not None and not isinstance(self.events, dict):
            raise ValueError, 'Events parameter must be a dict'

        self.resources.append(jquery_ui_css(name=get_ui_theme_name()))

        if self.options is not None and not isinstance(self.options, dict):
            raise ValueError, 'Options parameter must be a dict'

        self.options = encoder.encode(self.options)
        super(JQueryUIWidget, self).prepare()
        if not hasattr(self, 'id') or 'id' not in self.attrs:
            raise ValueError, 'JQueryWidget must be supplied an id'
        self.selector = self.attrs['id'].replace(':', '\\\\:')
Example #8
0
    def prepare(self):
        super(MokshaContainer, self).prepare()
        if isinstance(self.content, twc.widgets.WidgetMeta):
            self.content = self.content.req()

        if isinstance(self.content, twc.Widget):
            self.widget_name = self.content.__class__.__name__
            content_args = getattr(self, 'content_args', {})

            if isinstance(self.content, LiveWidget):
                topics = self.content.get_topics()
                # FIXME: also unregister the moksha callback functions.  Handle
                # cases where multiple widgets are listening to the same topics
                self.onClose = twc.JSSymbol(
                    src="function(o){%s $(o).remove();}" %
                    unsubscribe_topics(topics))
                self.onIconize = self.onCollapse = twc.JSSymbol(
                    src="function(o){%s}" % unsubscribe_topics(topics))
                self.onRestore = twc.JSSymbol(src="function(o){%s}" %
                                              subscribe_topics(topics))

            self.content = self.content.display(**content_args)

        for option in self.options:
            # TODO -- inspect this.  It might have become wonky in tw1->tw2
            setattr(self, option, getattr(self, option, True) and option or '')

        self.buttons = ''
        for button in self.button_options:
            if getattr(self, button, True):
                self.buttons += '%s,' % button[:1]

        self.buttons = self.buttons[:-1]

        self.id = str(uuid.uuid4())

        self._container_options = encoder.encode({
            'elementsPath':
            '/resources/moksha.widgets.container.container/static/css/elements/',
            'onClose': self.onClose,
            'onResize': self.onResize,
            'onCollapse': self.onCollapse,
            'onIconize': self.onIconize,
            'onDrag': self.onDrag,
            'onRestore': self.onRestore,
        })
    def prepare(self):
        if not self.options:
            raise ValueError('jqGridWidget must be given a dict of options')

        if (not 'url' in self.options and not 'data' in self.options
                and not 'datastr' in self.options):
            raise ValueError("jqGridWidget must be supplied a " +
                             "'url', 'data', or 'datastr' in options")

        self.pager_id = self.options.get('pager', None)
        super(jqGridWidget, self).prepare()
        self._pager_options = encoder.encode(self.pager_options)
        self._prmFilter = encoder.encode(self.prmFilter)
        self._prmEdit = encoder.encode(self.prmEdit)
        self._prmAdd = encoder.encode(self.prmAdd)
        self._prmDel = encoder.encode(self.prmDel)
        self._prmSearch = encoder.encode(self.prmSearch)
        self._prmView = encoder.encode(self.prmView)
        self._custom_pager_buttons = map(encoder.encode,
                                         self.custom_pager_buttons)
Example #10
0
    def prepare(self):
        if not self.options:
            raise ValueError, 'jqGridWidget must be supplied a dict of options'

        if (
            not 'url' in self.options and
            not 'data' in self.options and
            not 'datastr' in self.options):
            raise ValueError, "jqGridWidget must be supplied a " + \
                              "'url', 'data', or 'datastr' in options"

        self.pager_id = self.options.get('pager', None)
        super(jqGridWidget, self).prepare()
        self._pager_options = encoder.encode(self.pager_options)
        self._prmFilter  = encoder.encode(self.prmFilter)
        self._prmEdit    = encoder.encode(self.prmEdit)
        self._prmAdd     = encoder.encode(self.prmAdd)
        self._prmDel     = encoder.encode(self.prmDel)
        self._prmSearch  = encoder.encode(self.prmSearch)
        self._prmView    = encoder.encode(self.prmView)
        self._custom_pager_buttons = map(encoder.encode,
                                         self.custom_pager_buttons)
Example #11
0
 def prepare(self):
     self._data = encoder.encode(self.data)
     self._options = encoder.encode(self.options)
     super(FlotWidget, self).prepare()
 def prepare(self):
     self.url_kwargs = encoder.encode(self.url_kwargs)
     super(PollingJQPlotWidget, self).prepare()
 def prepare(self):
     self._data = encoder.encode(self.data)
     self._options = encoder.encode(self.options)
     super(JQPlotWidget, self).prepare()
Example #14
0
    def prepare(self):
        super(JitWidget, self).prepare()

        # Some validation
        if not self.jitClassName:
            msg = "{0.__name__} requires a 'jitClassName'.".format(type(self))
            raise ValueError, msg

        if not self.data and not self.base_url:
            msg = "%s requires 'data' or 'base_url' param." % self.__class__.__name__
            raise ValueError, msg

        self.url = self.base_url
        if getattr(self, 'url_kw', {}):
            q_str = urllib.urlencode(self.url_kw)
            self.url += '?' + q_str

        for k, v in self.attrs.iteritems():
            if type(v) in [JSSymbol]:
                for var, fun in self.jsVariables.iteritems():
                    if not var in v.src:
                        continue
                    res = fun(self)
                    if not isinstance(res, basestring):
                        res = encoder.encode(res)

                    self.attrs[k] = JSSymbol(
                        src=self.attrs[k].src.replace(var, res))

        setupcall = JSFuncCall(
            function='var jitwidget = setupTW2JitWidget',
            args=[
                self.jitClassName,
                self.jitSecondaryClassName,
                self.compound_id,
                self.attrs
            ])
        if self.data:
            # For normal loading
            loadcall = JSFuncCall(
                function='jitwidget.loadJSON',
                args=[self.data],)
            postcall = JSSource(
                src=self.attrs['postInitJSCallback'].src+'(jitwidget)')
        else:
            # For asynchronous loading
            self.resources.append(tw2.jquery.jquery_js)
            loadcall = None
            postcall = JSSource(src="""
                                $.getJSON(
                                    '%s',
                                    function (data) {
                                        // load data when we get it
                                        jitwidget.loadJSON(data);
                                        // Do post-init stuff
                                        %s(jitwidget);
                                    }
                               );""" % (self.url,
                                        self.attrs['postInitJSCallback'].src))

        composite_js_call = CompoundJSSource(
            exec_delay=self.init_delay,
            setupcall=setupcall,
            loadcall=loadcall,
            postcall=postcall)

        self.resources.append(composite_js_call)
 def prepare(self):
     self._data = encoder.encode(self.data)
     self._options = encoder.encode(self.options)
     super(MickeyMouse, self).prepare()
    def prepare(self):

        if self.options is not None and not isinstance(self.options, dict):
            raise ValueError, 'Options parameter must be a dict'

        self.options = encoder.encode(self.options)
Example #17
0
 def prepare(self):
     self.options = encoder.encode(self.options)
     super(JQueryUIWidget, self).prepare()
     if not hasattr(self, 'id') or 'id' not in self.attrs:
         raise ValueError, 'JQueryWidget must be supplied an id'
     self.selector = self.attrs['id'].replace(':', '\\\\:')
Example #18
0
 def prepare(self):
     super(MenuWidget, self).prepare()
     self._options = encoder.encode(self.options)
Example #19
0
 def prepare(self):
     self._data = encoder.encode(self.data)
     self._options = encoder.encode(self.options)
     self.style = "width:%s;height:%s;" % (self.width, self.height)
     super(JQPlotWidget, self).prepare()
 def prepare(self):
     self._options = encoder.encode(self.options)
     super(DynaTreeWidget, self).prepare()
Example #21
0
 def prepare(self):
     self._tips = encoder.encode(self.tips)
     super(TipsterWidget, self).prepare()
 def prepare(self):
     self.options = encoder.encode(self.options)
     super(gmap3, self).prepare()
Example #23
0
 def prepare(self):
     super(MenuWidget, self).prepare()
     self._options = encoder.encode(self.options)