diff options
author | Andrew Dolgov <[email protected]> | 2012-12-23 16:15:44 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-12-23 16:15:44 +0400 |
commit | b9546011d61665c26842ed133bae46c355ce19d5 (patch) | |
tree | 875b9706d33a99fc7acd7e69101d358ba8629638 /plugins/example | |
parent | 6065f3ad6364943e4d6b160db8a2c78ff52e2373 (diff) |
add example plugin
Diffstat (limited to 'plugins/example')
-rw-r--r-- | plugins/example/example.js | 3 | ||||
-rw-r--r-- | plugins/example/example.php | 66 |
2 files changed, 69 insertions, 0 deletions
diff --git a/plugins/example/example.js b/plugins/example/example.js new file mode 100644 index 000000000..a31f2c2a2 --- /dev/null +++ b/plugins/example/example.js @@ -0,0 +1,3 @@ +function example(value) { + alert("Value saved: " + value); +} diff --git a/plugins/example/example.php b/plugins/example/example.php new file mode 100644 index 000000000..e49ee5f27 --- /dev/null +++ b/plugins/example/example.php @@ -0,0 +1,66 @@ +<?php +class Example extends Plugin { + + // Demonstrates how to add a separate panel to the preferences screen and inject Javascript/save data using Dojo forms. + + private $link; + private $host; + + function __construct($host) { + $this->link = $host->get_link(); + $this->host = $host; + + $host->add_hook($host::HOOK_PREFS_TAB, $this); + } + + function save() { + $example_value = db_escape_string($_POST["example_value"]); + + echo "Value set to $example_value (not really)"; + } + + function get_prefs_js() { + return file_get_contents(dirname(__FILE__) . "/example.js"); + } + + function hook_prefs_tab($args) { + if ($args != "prefPrefs") return; + + print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("Example Pane")."\">"; + + print "<form dojoType=\"dijit.form.Form\">"; + + print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> + evt.preventDefault(); + if (this.validate()) { + console.log(dojo.objectToQuery(this.getValues())); + new Ajax.Request('backend.php', { + parameters: dojo.objectToQuery(this.getValues()), + onComplete: function(transport) { + notify_info(transport.responseText); + } + }); + this.reset(); + } + </script>"; + + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"example\">"; + + print "<table width=\"100%\" class=\"prefPrefsList\">"; + + print "<tr><td width=\"40%\">".__("Sample value")."</td>"; + print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"example_value\"></td></tr>"; + + print "</table>"; + + print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". + __("Set value")."</button>"; + + print "</form>"; + + print "</div>"; #pane + } +} +?> |