Pastebin

Paste #2042: py2js-bridging

< previous paste - next paste>

Pasted by chrivers

Download View as text

class TestApplication(WebApplication):

#        Q("#button").click(lambda: [Q("#dialog-confirm").dialog('open'), Q(this).button("option", "disabled", true)])
    def ready(self):
        a = Accordion("#accordion")
        b = Button("#button")
        d = DatePicker("#date")
        b.event_click = lambda: [alert("you clicked me"), b.enabled(False)]
        rpc = Button("#rpc")
        rce = Button("#rce")

        jQuery.jsonRPC.setup(js({
           endPoint: '/test/json'
        }))

        rpc.event_click = lambda: jQuery.jsonRPC.request(js('test.sum'), js({
                    params: [1, 2, 3, 4],
                    success: lambda result: alert(sprintf(js("Result from server: %s"), result.result)),
                    error: lambda result: alert("fail")
                    }))

#        b.enabled(True)
#        console.log(b.enabled(True))
#        console.log(b.enabled(False))

    def other(self):
        Q( "#dialog-confirm" ).dialog(js({
                autoOpen: false,
                resizable: true,
                height: 300,
                modal: true,
                buttons: {
                        js("Delete all items"): lambda: Q(this).dialog(js("close")),
                        js("Cancel"): lambda: Q(this).dialog(js("close")),
                }
        }))
        Q("#button").click(lambda: Q("#dialog-confirm").dialog(js('open')))
#        Q("#accordion").accordion()

        Q("#button").button()
        Q("#a1").click(lambda: Q("#button").button(js("option"), js("disabled"), False) )
        Q("#a2").click(lambda: Q("#button").button(js("option"), js("disabled"), True) )
        Q("#date").datepicker(js({dateFormat: "yy-mm-dd"}))

        jQuery.jsonRPC.setup(js({
           endPoint: '/test/json'
        }))

        Q("#rpc").button().click()

        Q("#rce").button().click(lambda:
           Q.jsonRPC.request('test.json', js({
           params: js([]),
           success: lambda result: eval(result.result),
           error: lambda result: alert("fail"),
        }))
        )

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.