Page 1 of 1

how to customize an event in a page and trigger it

Posted: Mon Jul 21, 2014 7:07 pm
by geliz zhang

If I have a chat program which in the background keep listening to the network, when new data is coming, how do I notify the page to update? I don't want to reload the whole page.

For a normal html page, I can define an event in the js file like this
function update()
{
//do some update
}
then call this function. But in appery, I can only define the event code within one control object, or if I modify the .js file it's no longer sync to the IDE.


how to customize an event in a page and trigger it

Posted: Mon Jul 21, 2014 7:59 pm
by Evgene Karachevtsev

Hello Geliz,

Please look here. It is the documentation about how you can add the JS to your project:
http://devcenter.appery.io/documentat...


how to customize an event in a page and trigger it

Posted: Mon Jul 21, 2014 9:07 pm
by geliz zhang

No. Add js in the project result in that js file is attached onto all of the pages, but I only need a certain page to have it loaded.
Other methods can only apply js to a control, not an independent level.


how to customize an event in a page and trigger it

Posted: Tue Jul 22, 2014 1:55 am
by Yurii Orishchuk

Hi Geliz,

You can use "page load" and "page show" events in accordance to your needs.

See details on screen shot how to do it:

http://prntscr.com/451uxs/direct

Regards.


how to customize an event in a page and trigger it

Posted: Tue Jul 22, 2014 2:54 pm
by geliz zhang

Thanks but if I add the code to page load, after its execution the code is no longer in the memory. What I need is a standby code that run in the background, and jump out to so something (for example when receiving a command from the network) do some updating in the page.

For example a weather forecast app, when there is a weather alert, a popup window comes out. This requires the background code to notify the page to update, but there is no such a way to send a notification into a page to trigger an event.

I now use an invisible button to trigger its click event, but if there is a way to define a function in page scope and call that function directly it will be more straight.


how to customize an event in a page and trigger it

Posted: Thu Jul 24, 2014 1:30 am
by Yurii Orishchuk

Hi Geliz,

Do you want have some function invoked by timer?

If so please use following jS code in "page load" JS event handler:

pre

var onInterval = function(){
//Here is you can place code you need

console.log("Interval work.");

};

//Set inverval for 5s.
setInterval(onInterval, 5000);

/pre

Regards.


how to customize an event in a page and trigger it

Posted: Thu Jul 24, 2014 3:01 am
by geliz zhang

No it should not be triggered by timer but network message event.
For example
var onIncomingMessage = function ()
{
//do some work
};
and in a global .js file, in the initialize part of the network module set the trigger
SomeObj.onIncomingMessage = Appery("MainScreen").onIncomingMessage;
Is that possible?


how to customize an event in a page and trigger it

Posted: Thu Jul 24, 2014 4:25 am
by Yurii Orishchuk

Geliz,

yes it could be implemented with Appery.io platform in the same way as other web application.

This event should be invoked by some logic(your own or external 3rd party).

Regards.