Results 1 to 3 of 3

Thread: Dynamically binding events on custom objects

  1. #1
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,719
    Blog Entries
    17

    Dynamically binding events on custom objects

    In LianjaScript.

    Code:
    // event handlers
    proc clockin()
        ocamera.takePhoto()
        thisform.showSuccessMessage("You clocked in on " + dtoc(date()) + " at " + time())
    endproc
    
    proc clockout()
        ocamera.takePhoto()
        thisform.showSuccessMessage("You clocked out on " + dtoc(date()) + " at " + time())
    endproc
    
    // dynamically assign event handlers for the "Clock in" and "Clock out" commandbuttons
    obtn1.click = clockin
    obtn2.click = clockout
    In python.

    Code:
    # event handlers
    def clockin(self):
       ocamera.takePhoto()
       now = datetime.now()
       oform.showSuccessMessage("You clocked in at " + now.strftime("%m/%d/%Y %H:%M:%S"))
    
    def clockout(self):
       ocamera.takePhoto()
       now = datetime.now()
       oform.showSuccessMessage("You clocked out at " + now.strftime("%m/%d/%Y %H:%M:%S"))
    
    # dynamically assign event handlers using the bindEvent() built-in Lianja/Python function
    bindEvent(obtn1, clockin, "click")
    bindEvent(obtn2, clockout, "click")
    In JavaScript.

    Code:
    // event handlers
    function clockin()
    {
        ocamera.takePhoto()
        oform.showSuccessMessage("You clocked in on " + new Date().toLocaleString())
    };
    
    function clockout()
    {
        ocamera.takePhoto();
        oform.showSuccessMessage("You clocked out on " + new Date().toLocaleString())
    };
    
    // dynamically assign event handlers like this in JavaScript
    obtn1.click = clockin;
    obtn2.click = clockout;
    Last edited by barrymavin; 2022-01-18 at 05:18.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  2. #2
    Member
    Join Date
    Feb 2012
    Location
    Earth.Europe.Germany.Bavaria.Obing
    Posts
    45
    Totally unrelated to the main reason of that post, but I'm just wondering about:
    "You clocked in on " + dtoc(date()) + " at " + time()

    Wouldn't this be more comprehensive?
    "You clocked in on " + TtoC(DateTime())

    wOOdy (Currently in Refactoring Mode )
    Last edited by woody-soft; 2022-02-17 at 05:00.
    wOOdy

  3. #3
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,719
    Blog Entries
    17
    You are right woody. So many ways to do the same thing.

    Be my guest to complete the example_timeclock app to record the clicking in and out times in a database.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us