2011-11-12, 17:43
gugahoi Wrote:Fair enough. It worked with no problems for me.
MrK, sorry but Im gonna have to trouble you again with some Q's...
Which files need to be modified to add a new module? I've been reading around the code and thought it seemed simple but I've had no luck getting my new module showing up properly.
Is there a chance you could explain the saving process for the settings?
Cheers!
Sure. It varies depending on what you want the module to do, but the basic process is the same. These instructions are for a generic module like SABnzbd+.
First, you need to add the default settings for the module to AVAILABLE_MODULES in modules.py, as described here.
If you want to add extra settings (in the case on SABnzbd we have the SABnzbd API url) then add them in extra_settings - plenty of examples in module.py.
Then you need to create a .py file which contains all of the module's functions, mostly XHR views which render templates. See sabnzbd.py for a good example which you can base your module on.
To access the value of any extra settings that you've specified in modules.py, use:
Code:
get_setting_value('setting_name')
There is already code in place to handle the creation of extra settings, so it is done automatically, as is the 'edit settings' for each module.
Next, you need to create a template with the same name as 'AVAILABLE_MODULES[yourmodule].name' - so if in AVAILABLE_MODULES you set the name of your module to be "loldongs", the template should be loldongs.html.
The HTML for the module goes in this template. Again, check out sabnzbd.html for an example. You'll see that the module only appears if SABnzbd is downloading something, otherwise a placeholder is rendered instead. The placeholder is important because it provides styling hooks when in settings mode so that you can still see the module; also because the placeholder gets replaced with the actual module when it is determined that it should be displayed (in that case, when SABnzbd is actually downloading something). Make sure that you add an HTML5 data attribute (data-module) with the module "name" as this is used for the aforementioned hook.
You'll notice that all modules use the same basic styling (class of module, h2 for the title, etc.) so you can whip up a new module with consistent styling pretty easily.
You don't need to worry about JavaScript unless you're doing something more complex - the JS to show/hide/load/poll modules is already in place, and if you implement the module as described above then it will automatically pick it up and handle everything.
I think that's everything, but shoot if you have any questions.