How to use the lino.utils.jsgen.js_code 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
def js_render_GridPanel_class(self, rh):

        yield ""
        yield "// js_render_GridPanel_class %s" % rh.actor
        yield "Lino.%s.GridPanel = Ext.extend(Lino.GridPanel,{" % rh.actor

        kw = dict()
        #~ kw.update(empty_title=%s,rh.actor.get_button_label()
        if getattr(rh.actor,'use_detail_params_value',None):
            kw.update(use_detail_params_value=True)
        kw.update(ls_url=rh.actor.actor_url())
        if not hasattr(rh, 'store'):
            raise AttributeError("20200128 {} has no store".format(rh))
        kw.update(ls_store_fields=[js_code(f.as_js(f.name))
                  for f in rh.store.list_fields])
        if rh.store.pk is not None:
            kw.update(ls_id_property=rh.store.pk.name)
            kw.update(pk_index=rh.store.pk_index)
            if settings.SITE.is_installed('contenttypes'):
                m = getattr(rh.store.pk, 'model', None)
                # e.g. pk may be the VALUE_FIELD of a choicelist which
                # has no model
                if m is not None:
                    ct = ContentType.objects.get_for_model(m).pk
                    kw.update(content_type=ct)

        kw.update(cell_edit=rh.actor.cell_edit)
        kw.update(focus_on_quick_search=rh.actor.focus_on_quick_search)
        kw.update(ls_bbar_actions=self.toolbar(
            rh.actor.get_toolbar_actions(rh.actor.default_action.action)))
github lino-framework / lino / lino / modlib / extjs / ext_renderer.py View on Github external
def js_render_GridPanel_class(self, rh):

        yield ""
        yield "// js_render_GridPanel_class %s" % rh.actor
        yield "Lino.%s.GridPanel = Ext.extend(Lino.GridPanel,{" % rh.actor

        kw = dict()
        #~ kw.update(empty_title=%s,rh.actor.get_button_label()
        kw.update(ls_url=rh.actor.actor_url())
        kw.update(ls_store_fields=[js_code(f.as_js(f.name))
                  for f in rh.store.list_fields])
        if rh.store.pk is not None:
            kw.update(ls_id_property=rh.store.pk.name)
            kw.update(pk_index=rh.store.pk_index)
            if settings.SITE.is_installed('contenttypes'):
                m = getattr(rh.store.pk, 'model', None)
                # e.g. pk may be the VALUE_FIELD of a choicelist which
                # has no model
                if m is not None:
                    ct = ContentType.objects.get_for_model(m).pk
                    kw.update(content_type=ct)

        kw.update(cell_edit=rh.actor.cell_edit)
        kw.update(ls_bbar_actions=self.toolbar(
            rh.actor.get_toolbar_actions(rh.actor.default_action.action)))
        kw.update(ls_grid_configs=[gc.data for gc in rh.actor.grid_configs])
github lino-framework / lino / obsolete / ui_old / qx / qx_elems.py View on Github external
chooser = choosers.get_for_field(e.field)
            if chooser:
                #~ logger.debug("20100615 %s.%s has chooser", self.lh.layout, e.field.name)
                for f in chooser.context_fields:
                    for el in elems_by_field.get(f.name,[]):
                        #~ if main.has_field(f):
                        #~ varname = varname_field(f)
                        #~ on_render.append("%s.on('change',Lino.chooser_handler(%s,%r));" % (varname,e.ext_name,f.name))
                        on_render.append(
                            "%s.on('change',Lino.chooser_handler(%s,%r));" % (
                            el.ext_name,e.ext_name,f.name))
        
        if on_render:
            assert not kw.has_key('listeners')
            #~ kw.update(listeners=dict(render=js_code('function(){%s}' % '\n'.join(on_render))))
            self.listeners=dict(render=js_code('function(){%s}' % '\n'.join(on_render)))
        #~ kw.update(before_row_edit=before_row_edit(main))
        self.before_row_edit=before_row_edit(main)
        
        rpt = rh.report
        a = rpt.get_action('detail')
        if a:
            kw.update(ls_detail_handler=js_code("Lino.%s" % a))
        a = rpt.get_action('insert')
        if a:
            kw.update(ls_insert_handler=js_code("Lino.%s" % a))
        
        kw.update(ls_bbar_actions=[rh.ui.a2btn(a) for a in rpt.get_actions(action)])
        kw.update(ls_url=rh.ui.build_url(rpt.app_label,rpt._actor_name))
        jsgen.Component.__init__(self,'form_panel',**kw)
github lino-framework / lino / obsolete / ui_old / qx / qx_elems.py View on Github external
if isinstance(e,GridElement):
            l.append("%s.on_master_changed();" % e.as_ext())
        elif isinstance(e,PictureElement):
            l.append("this.load_picture_to(%s,record);" % e.as_ext())
        elif isinstance(e,HtmlBoxElement):
            l.append("%s.refresh();" % e.as_ext())
        elif isinstance(e,FieldElement):
            chooser = choosers.get_for_field(e.field)
            if chooser:
                #~ logger.debug("20100615 %s.%s has chooser", self.lh.layout, e.field.name)
                for f in chooser.context_fields:
                    #~ l.append("console.log('20110128 before_row_edit',record.data);")
                    l.append("%s.setContextValue(%r,record ? record.data[%r] : undefined);" % (
                        e.ext_name,f.name,ext_requests.form_field_name(f)))
    #~ return js_code('function(record){\n  %s\n}' % ('\n  '.join(l)))
    return js_code('function(record){ %s }' % (' '.join(l)))
github lino-framework / lino / obsolete / ui_old / qx / qx_elems.py View on Github external
def ext_options(self,**kw):
        rh = self.report.get_handle(self.lh.rh.ui)
        kw = LayoutElement.ext_options(self,**kw)
        #~ d.update(ls_data_url=rh.ui.get_actor_url(self.report))
        kw.update(ls_url=rh.ui.build_url(self.report.app_label,self.report._actor_name))
        kw.update(ls_store_fields=[js_code(f.as_js()) for f in rh.store.list_fields])
        #~ kw.update(ls_columns=[GridColumn(i,e) for i,e in enumerate(self.columns)])
        #~ kw.update(ls_filters=[e.get_filter_options() for e in self.elements if e.filter_type])
        kw.update(ls_id_property=rh.store.pk.name)
        kw.update(pk_index=rh.store.pk_index)
        kw.update(ls_quick_edit=rh.report.cell_edit)
        kw.update(ls_bbar_actions=[rh.ui.a2btn(a) for a in rh.get_actions(rh.report.default_action)])
        kw.update(ls_grid_configs=[gc.data for gc in self.report.grid_configs])
        kw.update(gc_name=DEFAULT_GC_NAME)
        #~ gc = self.report.grid_configs.get('',None)
        #~ if gc is not None:
            #~ kw.update(ls_grid_config=gc)
        return kw
github lino-framework / lino / lino / ui / extjsu / ext_elems.py View on Github external
def __init__(self,lh,name,dv,**kw):
        #~ self.dv = dv
        kw.update(store=js_code('this.store'))
        kw.update(tpl=js_code('new Ext.XTemplate(%s)' % py2js(dv.xtemplate)))
        kw.update(emptyText='No images to display')
        kw.update(itemSelector='div.thumb-wrap')
        kw.update(loadingText='Loading...')
        LayoutElement.__init__(self,lh,name,**kw)
github lino-framework / lino / lino / modlib / extjs / ext_renderer.py View on Github external
if a.parameters and not a.no_params_window:
            kw.update(panel_btn_handler=js_code(
                "Lino.param_action_handler(Lino.%s)" % ba.full_name()))
        elif isinstance(a, SubmitInsert):
            js = 'function(panel){panel.save()}'
            kw.update(panel_btn_handler=js_code(js))
        elif isinstance(a, SubmitDetail):
            js = 'function(panel){panel.save()}'
            kw.update(panel_btn_handler=js_code(js))
        elif isinstance(a, ShowDetail):
            kw.update(panel_btn_handler=js_code('Lino.show_detail'))
        elif isinstance(a, ShowInsert):
            kw.update(panel_btn_handler=js_code('Lino.show_insert'))
        else:
            kw.update(
                panel_btn_handler=js_code(self.get_panel_btn_handler(ba)))

        if a.icon_name:
            kw.update(iconCls='x-tbar-' + a.icon_name)
        else:
            txt = a.button_text or a.get_label()
            if len(txt) == 1:
                txt = ONE_CHAR_LABEL.format(txt)

            kw.update(text=txt)
        kw.update(
            #~ name=a.name,
            menu_item_text=a.get_label(),
            overflowText=a.get_label(),
            auto_save=a.auto_save,
            itemId=a.action_name,
            #~ text=unicode(a.label),
github lino-framework / lino / lino / ui / extjsu / ext_elems.py View on Github external
def get_column_options(self,**kw):
        kw = FieldElement.get_column_options(self,**kw)
        if not choosers.uses_simple_values(self.field):
            kw.update(hiddenName=self.field.name+ext_requests.CHOICES_HIDDEN_SUFFIX)
            kw.update(dataIndex=self.field.name+ext_requests.CHOICES_HIDDEN_SUFFIX)
            kw.update(renderer=js_code('Lino.comboRenderer(%r)' % self.field.name))
        return kw
github lino-framework / lino / lino / modlib / extjs / ext_renderer.py View on Github external
def a2btn(self, ba, **kw):
        a = ba.action
        if a.parameters and not a.no_params_window:
            kw.update(panel_btn_handler=js_code(
                "Lino.param_action_handler(Lino.%s)" % ba.full_name()))
        elif isinstance(a, SubmitInsert):
            js = 'function(panel){panel.save()}'
            kw.update(panel_btn_handler=js_code(js))
        elif isinstance(a, SubmitDetail):
            js = 'function(panel){panel.save()}'
            kw.update(panel_btn_handler=js_code(js))
        elif isinstance(a, ShowDetail):
            kw.update(panel_btn_handler=js_code('Lino.show_detail'))
        elif isinstance(a, ShowInsert):
            kw.update(panel_btn_handler=js_code('Lino.show_insert'))
        else:
            kw.update(
                panel_btn_handler=js_code(self.get_panel_btn_handler(ba)))

        if a.icon_name:
            kw.update(iconCls='x-tbar-' + a.icon_name)
        else:
            txt = a.button_text or a.label
            if len(txt) == 1:
                txt = ONE_CHAR_LABEL.format(txt)
                
            kw.update(text=txt)