![](/s/cache/08/b9/08b9d40b6e56331fc40cd3895fed86ac.png)
0
Answered
Creating basic links and javascripts in layout?
hi
is it possible to create HREF links and javascript validation in the layout XML files? i have tried to include some and found that it didn't work. i would like to have some links in the layout XML. with some custom javascript controls. how can i get that?
thanks for your help and fast response as always
is it possible to create HREF links and javascript validation in the layout XML files? i have tried to include some and found that it didn't work. i would like to have some links in the layout XML. with some custom javascript controls. how can i get that?
thanks for your help and fast response as always
Answer
![](/s/cache/c3/94/c39402226f80f121f6a818b91880b7d6.png)
Answer
Answered
Take a look at Custom UI Controls article: http://docs.ajenti.org/dev/custom-controls.html
(you can use JS instead of CoffeeScript too)
(you can use JS instead of CoffeeScript too)
![](/s/cache/08/b9/08b9d40b6e56331fc40cd3895fed86ac.png)
hi
thanks for your reply.
i have looked at it and tried to play with the example given. However, i'm still not very sure where the pieces comes together. perhaps you can enlighten me.
it seems to me that the coffee script creates a DOM that would be inserted into the layout based on the XML tag provided as part of the typeid defined in the respective class.
The example made use of a input type to read a value from the DOM.
but what if i wanted to updated a section of the text? something like manipulating innerHTML from the custom DOM?
i created something like the below.
class window.Controls.textinfo extends window.Control
createDom: () ->
# createDom() must set this.dom and (optional) this.childContainer to jQuery DOM elements
# use this.properties hash to populate control with its current state
@dom = $("""
<div id="textinfo">
Something to see
</div>
""")
and tried to access/change it using the below in main.py
self.find("textinfo").value = "New stuff"
but it doesn't work. is there any advice you can give?
thanks for your reply.
i have looked at it and tried to play with the example given. However, i'm still not very sure where the pieces comes together. perhaps you can enlighten me.
it seems to me that the coffee script creates a DOM that would be inserted into the layout based on the XML tag provided as part of the typeid defined in the respective class.
The example made use of a input type to read a value from the DOM.
but what if i wanted to updated a section of the text? something like manipulating innerHTML from the custom DOM?
i created something like the below.
class window.Controls.textinfo extends window.Control
createDom: () ->
# createDom() must set this.dom and (optional) this.childContainer to jQuery DOM elements
# use this.properties hash to populate control with its current state
@dom = $("""
<div id="textinfo">
Something to see
</div>
""")
and tried to access/change it using the below in main.py
self.find("textinfo").value = "New stuff"
but it doesn't work. is there any advice you can give?
![](/s/cache/c3/94/c39402226f80f121f6a818b91880b7d6.png)
Instead of "Something to see", use #{@properties.value}
this.properties (@properties) contains all values for properties which were defined with @p in Python and later set with, for example, self.find("textinfo").value
this.properties (@properties) contains all values for properties which were defined with @p in Python and later set with, for example, self.find("textinfo").value
![](/s/cache/08/b9/08b9d40b6e56331fc40cd3895fed86ac.png)
thanks for the hint.
i think i got it.... i had to also "id" the tag in layout/main.xml to make sure that self.find() is able to locate the attribute in the XML.
thanks
i think i got it.... i had to also "id" the tag in layout/main.xml to make sure that self.find() is able to locate the attribute in the XML.
thanks
![](/s/cache/08/b9/08b9d40b6e56331fc40cd3895fed86ac.png)
hi
(apologies for all these seemingly newbie questions. i'm not too familiar with python and coffee script.. )
as an extension to this question. How do i call my own JS from the text included in in my own control?
i have a simple coffee script included as part of the DOM build
go_alert: () ->
alert "Test text"
but how do i call it in my own control? and reference my own DOM in the JS within Ajenti?
(apologies for all these seemingly newbie questions. i'm not too familiar with python and coffee script.. )
as an extension to this question. How do i call my own JS from the text included in in my own control?
i have a simple coffee script included as part of the DOM build
go_alert: () ->
alert "Test text"
but how do i call it in my own control? and reference my own DOM in the JS within Ajenti?
![](/s/cache/c3/94/c39402226f80f121f6a818b91880b7d6.png)
Actually, DOM is rebuilt on each UI update, so it's not generally possible to invoke JS methods from Python without actually refreshing the UI. One thing you can do is to create a boolean property (show_dialog), which is checked in JS createDom().
However we have a special API which you can use to show messages: http://docs.ajenti.org/dev/notifications.html
However we have a special API which you can use to show messages: http://docs.ajenti.org/dev/notifications.html
![](/s/cache/08/b9/08b9d40b6e56331fc40cd3895fed86ac.png)
How about a way to update the UI when the user clicks away from a plugin? i tried putting the item into init but it doesn't seem to get called beyond the first time the page loads.
or a way to extend the servicebar action such that it calls my python function after it performs a start/stop?
i have information that i would like to provide the user depending on if the service is started or stopped. i was hoping to be able to provide a link the the user initially (through JS), and the link changes depending the state of the service.
or a way to extend the servicebar action such that it calls my python function after it performs a start/stop?
i have information that i would like to provide the user depending on if the service is started or stopped. i was hoping to be able to provide a link the the user initially (through JS), and the link changes depending the state of the service.
![](/s/cache/c3/94/c39402226f80f121f6a818b91880b7d6.png)
Then it's a much better idea to simply create a link/label and update it depending on service status.
1. You should put that update inside on_page_load (see http://docs.ajenti.org/ref/ajenti.plugins.main.api... ) method, which is called each time when navigating to section.
2. from ajenti.plugins.services.api import ServiceMultiplexor
3. use ServiceMultiplexor.get().get_one('servicename').start/stop/restart/running (see http://docs.ajenti.org/ref/ajenti.plugins.services... ) to start/stop service with your custom buttons and get the service status.
If you need any help, you can write directly to e@ajenti.org or skype: john.pankov
1. You should put that update inside on_page_load (see http://docs.ajenti.org/ref/ajenti.plugins.main.api... ) method, which is called each time when navigating to section.
2. from ajenti.plugins.services.api import ServiceMultiplexor
3. use ServiceMultiplexor.get().get_one('servicename').start/stop/restart/running (see http://docs.ajenti.org/ref/ajenti.plugins.services... ) to start/stop service with your custom buttons and get the service status.
If you need any help, you can write directly to e@ajenti.org or skype: john.pankov
![](/s/cache/c3/94/c39402226f80f121f6a818b91880b7d6.png)
You can also see how servicebar works here: https://github.com/Eugeny/ajenti/blob/dev/ajenti/plugins/services/main.py#L55
Customer support service by UserEcho
(you can use JS instead of CoffeeScript too)