How to use the lino.utils.jsgen.py2js function in lino

To help you get started, we’ve selected a few lino examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lino-framework / lino / lino / modlib / extjs / ext_renderer.py View on Github external
#~ f.write(jscompress(unicode(tpl)+'\n'))
        f.write(jscompress(tpl.render(**context) + '\n'))

        env = settings.SITE.plugins.jinja.renderer.jinja_env
        for p in settings.SITE.installed_plugins:
            if isinstance(p, Plugin):
                for tplname in p.site_js_snippets:
                    tpl = env.get_template(tplname)
                    f.write(jscompress('\n// from %s:%s\n' % (p, tplname)))
                    f.write(jscompress('\n' + tpl.render(**context) + '\n'))

        menu = settings.SITE.get_site_menu(self, profile)
        menu.add_item(
            'home', _("Home"), javascript="Lino.handle_home_button()")
        f.write("Lino.main_menu = %s;\n" % py2js(menu))

        """Call Ext.namespace for *all* actors because
        e.g. outbox.Mails.FormPanel is defined in ns outbox.Mails
        which is not directly used by non-expert users.

        """
        for a in self.actors_list:
            f.write("Ext.namespace('Lino.%s')\n" % a)

        # actors with their own `get_handle_name` don't have a js
        # implementation
        actors_list = [
            a for a in self.actors_list if a.get_handle_name is None]

        # generate only actors whose default_action is visible
        actors_list = [
github lino-framework / lino / lino / modlib / extjs / ext_renderer.py View on Github external
def fn():
            yield "// lino.js --- generated %s by %s for %s." % (
                time.ctime(), escape(settings.SITE.site_version()),
                get_user_profile())
            # lino.__version__)
            #~ // $site.title ($lino.welcome_text())
            if self.extjs_version == 3:
                yield "Ext.BLANK_IMAGE_URL = '%s';" % extjs.build_lib_url(
                    'resources/images/default/s.gif')
            yield "LANGUAGE_CHOICES = %s;" % py2js(
                list(settings.SITE.LANGUAGE_CHOICES))
            yield "MEDIA_URL = %s;" % py2js(settings.SITE.build_media_url())
            yield "GEN_TIMESTAMP = %s;" % py2js(rt.settings.SITE.kernel.code_mtime)
github lino-framework / lino / lino / modlib / extjs / ext_renderer.py View on Github external
def fn():
            yield "// lino.js --- generated %s by %s for %s." % (
                time.ctime(), escape(settings.SITE.site_version()),
                get_user_profile())
            # lino.__version__)
            #~ // $site.title ($lino.welcome_text())
            if self.extjs_version == 3:
                yield "Ext.BLANK_IMAGE_URL = '%s';" % extjs.build_lib_url(
                    'resources/images/default/s.gif')
            yield "LANGUAGE_CHOICES = %s;" % py2js(
                list(settings.SITE.LANGUAGE_CHOICES))
            yield "MEDIA_URL = %s;" % py2js(settings.SITE.build_media_url())
            yield "GEN_TIMESTAMP = %s;" % py2js(rt.settings.SITE.kernel.code_mtime)
github lino-framework / lino / lino / ui / extjsu / ext_windows.py View on Github external
def unused_js_main(self):
        for ln in MasterWrapper.js_main(self):
            yield ln
        yield "this.refresh = function() { console.log('DetailMasterWrapper.refresh() is not implemented') };"
        yield "this.get_current_record = function() { return this.current_record;};"
        yield "this.get_selected = function() {"
        yield "  return this.current_record.id;"
        yield "}"
        yield "this.load_record = function(record) {"
        yield "  this.current_record = record;" 
        yield "  if (record) this.main_panel.form.loadRecord(record)"
        yield "  else this.main_panel.form.reset();"
        yield "};"
        #~ yield "this.load_record(%s);" % py2js(ext_store.Record(self.datalink.store,object))
        yield "var fn = Ext.data.Record.create(%s)" % \
            py2js([js_code(f.as_js()) for f in self.rh.store.fields])
        d = self.rh.store.row2dict(self.rh.row)
        yield "this.load_record(fn(%s));" % py2js(d)
github lino-framework / lino / obsolete / ui_old / qx / qx_ui.py View on Github external
def json_response(x):
    #s = simplejson.dumps(kw,default=unicode)
    #return HttpResponse(s, mimetype='text/html')
    s = py2js(x)
    #~ logger.debug("json_response() -> %r", s)
    # http://dev.sencha.com/deploy/dev/docs/source/BasicForm.html#cfg-Ext.form.BasicForm-fileUpload
    return HttpResponse(s, content_type='text/html')
    #~ return HttpResponse(s, content_type='text/json')
github lino-framework / lino / lino / modlib / extjs / ext_renderer.py View on Github external
a = bound_action.action
        if a.opens_a_window or (a.parameters and not a.no_params_window):
            if request and request.subst_user:
                status[
                    constants.URL_PARAM_SUBST_USER] = request.subst_user
            if isinstance(a, ShowEmptyTable):
                status.update(record_id=-99998)
            if request is None:
                rp = None
            else:
                rp = request.requesting_panel
            if status:
                return "Lino.%s.run(%s,%s)" % (
                    bound_action.full_name(),
                    py2js(rp),
                    py2js(status))
            return "Lino.%s.run(%s)" % (bound_action.full_name(), py2js(rp))
        return "%s()" % self.get_panel_btn_handler(bound_action)
github lino-framework / lino / lino / modlib / extjs / ext_renderer.py View on Github external
def js_render_custom_action(self, rh, action):
        """Defines the non-window action handler used by
        :meth:`row_action_button`
        """
        yield "Lino.%s = function(rp, pk, params) { " % action.full_name()
        yield "  var h = function() { "
        uri = rh.actor.actor_url()
        yield "    Lino.run_row_action(rp, %s, %s, pk, %s, params, %s);" % (
            py2js(uri), py2js(action.action.http_method),
            py2js(action.action.action_name),
            action.action.preprocessor)
        yield "  };"
        yield "  var panel = Ext.getCmp(rp);"
        yield "  if(panel) panel.do_when_clean(true, h); else h();"
        yield "};"
github lino-framework / lino / lino / modlib / extjs / elems.py View on Github external
def get_field_options(self, **kw):
        kw = ComboFieldElement.get_field_options(self, **kw)
        if self.editable:
            sto = self.store_options()
            # print repr(sto)
            if self.layout_handle.ui.renderer.extjs_version == 3:
                kw.update(
                    store=js_code(
                        "new Lino.ComplexRemoteComboStore(%s)" %
                        py2js(sto)))
            else:
                kw.update(
                    store=js_code(
                        "Ext.create('Lino.ComplexRemoteComboStore',%s)" %
                        py2js(sto)))
        return kw
github lino-framework / lino / lino / modlib / extjs / ext_renderer.py View on Github external
if a.key:
            kw.update(keycode=a.key.keycode)
        if a.help_text:
            # if a.__class__.__name__ in ('ChangePassword', 'SubmitDetail'):
            #     logger.info("20160829 a2btn() %r %r", a, str(a.help_text))
            
            # A tooltip becomes visible only on buttons with an
            # iconCls. On a button which has only text we must use
            # Lino.quicktip_renderer. But I didn't find out why this
            # doesn't seem to work.
            if a.icon_name:
                kw.update(tooltip=a.help_text)
            elif settings.SITE.use_quicktips:
                kw.update(listeners=dict(render=js_code(
                    "Lino.quicktip_renderer('a2btn',%s)" %
                    py2js(a.help_text))
                ))
        elif a.icon_name:
            kw.update(tooltip=a.label)
        return kw
github lino-framework / lino / lino / core / renderer.py View on Github external
# 20140429 `ar` is now None, see :ref:`welfare.tested.integ`
        if ba.action.select_rows:
            params = self.get_action_params(ar, ba, obj)
            return "Lino.%s(%s,%s,%s,%s)" % (
                ba.full_name(), py2js(rp),
                py2js(ar.is_on_main_actor), py2js(obj.pk), py2js(params))
        # assert obj is None
        # return "oops"
        # params = self.get_action_params(ar, ba, obj)
        # url = ar.get_request_url()

        url = self.front_end.build_plain_url(
            ar.actor.app_label, ar.actor.__name__)
        params = ar.get_status().get('base_params', None)
        pp = "function() {return %s;}" % py2js(params)
        return "Lino.list_action_handler(%s,%s,%s,%s)()" % (
            py2js(url), py2js(ba.action.action_name),
            py2js(ba.action.http_method),pp)