def __call__(self):

        # We want to check that the user was indeed allowed to access the
        # form for this widget. We can only this now, since security isn't
        # applied yet during traversal.
        self.validate_access()

        query = self.request.get('term', None)
        if not query:
            return ''

        # Update the widget before accessing the source.
        # The source was only bound without security applied
        # during traversal before.
        self.context.update()
        source = self.context.bound_source
        if query:
            terms = set(source.search(query))
        else:
            terms = set()
        self.request.response.setHeader(
            'Content-Type', 'application/javascript')
        return demjson.dumps(
            [(t.token, t.title or t.value or t.token)
             for t in sorted(
                 terms,
                 key=lambda t: t.value or t.title)])
    def __call__(self):

        # We want to check that the user was indeed allowed to access the
        # form for this widget. We can only this now, since security isn't
        # applied yet during traversal.
        self.validate_access()

        query = self.request.get('term', None)
        if not query:
            return ''

        # Update the widget before accessing the source.
        # The source was only bound without security applied
        # during traversal before.
        self.context.update()
        source = self.context.bound_source

        if query:
            terms = set(source.search(query))
        else:
            terms = set()

        self.request.response.setHeader(
            'Content-Type', 'application/javascript')
        return demjson.dumps(
            [(t.token, t.title or t.value or t.token)
             for t in sorted(
                 terms,
                 key=lambda t: t.value or t.title)])
    def getCK_plone_menu_styles(self):
        """
        return javascript for ckeditor
        plone menu styles
        """
        request = self.request
        response = request.RESPONSE
        cke_properties = self.cke_properties
        styles = demjson.loads(cke_properties.getProperty('menuStyles', '[]'))
        for style in styles:
            if 'name' in style:
                style['name'] = self.context.translate(_(style['name']))
        menu_styles_js_string = """
styles = jQuery.parseJSON('%s');
CKEDITOR.stylesSet.add('plone', styles);""" % demjson.dumps(styles)
        response.setHeader(
            'Cache-control', 'pre-check=0,post-check=0,must-revalidate,'
            's-maxage=0,max-age=0,no-cache')
        response.setHeader('Content-Type', 'application/x-javascript')

        return JavascriptPacker('safe').pack(menu_styles_js_string)
    def getCK_plone_menu_styles(self):
        """
        return javascript for ckeditor
        plone menu styles
        """
        request = self.request
        response = request.RESPONSE
        cke_properties = self.cke_properties
        styles = demjson.loads(cke_properties.getProperty("menuStyles", "[]"))
        for style in styles:
            if "name" in style:
                style["name"] = self.context.translate(_(style["name"]))
        menu_styles_js_string = """
styles = jQuery.parseJSON('%s');
CKEDITOR.stylesSet.add('plone', styles);""" % demjson.dumps(
            styles
        )
        response.setHeader("Cache-control", "pre-check=0,post-check=0,must-revalidate," "s-maxage=0,max-age=0,no-cache")
        response.setHeader("Content-Type", "application/x-javascript")

        return JavascriptPacker("safe").pack(menu_styles_js_string)
Exemple #5
0
 def getJs(self, **jsvars):
     jsvars['tableid'] = self.get_table_id()
     JS = HEADER = ''
     HEADER += "var options = JSON.parse('%s');\n" % demjson.dumps(jsvars)
     js = self.js().replace('%HEADER%', HEADER)
     return js
 def response(self, rpcid=None, version=None):
     global _version
     if not version:
         version = _version
     return dumps(self, rpcid=rpcid, version=version)
 def request(self, encoding=None, rpcid=None):
     return dumps(self.params, self.method, version=2.0,
                  encoding=encoding, rpcid=rpcid, notify=self.notify)
 def _request_notify(self, methodname, params, rpcid=None):
     request = dumps(params, methodname, encoding=self.__encoding,
                     rpcid=rpcid, version=self.__version, notify=True)
     response = self._run_request(request, notify=True)
     check_for_errors(response)
     return
 def _request(self, methodname, params, rpcid=None):
     request = dumps(params, methodname, encoding=self.__encoding,
                     rpcid=rpcid, version=self.__version)
     response = self._run_request(request)
     check_for_errors(response)
     return response['result']
Exemple #10
0
 def getJs(self, **jsvars):
     jsvars['tableid'] = self.get_table_id()
     JS = HEADER = ''
     HEADER += "var options = JSON.parse('%s');\n" % demjson.dumps(jsvars)
     js = self.js().replace('%HEADER%', HEADER)
     return js