]>
Commit | Line | Data |
---|---|---|
b9546011 AD |
1 | <?php |
2 | class Example extends Plugin { | |
3 | ||
4 | // Demonstrates how to add a separate panel to the preferences screen and inject Javascript/save data using Dojo forms. | |
5 | ||
6 | private $link; | |
7 | private $host; | |
8 | ||
7a866114 AD |
9 | function _about() { |
10 | return array(1.0, | |
11 | "Example plugin #1", | |
12 | "fox"); | |
13 | } | |
14 | ||
b9546011 AD |
15 | function __construct($host) { |
16 | $this->link = $host->get_link(); | |
17 | $this->host = $host; | |
18 | ||
19 | $host->add_hook($host::HOOK_PREFS_TAB, $this); | |
20 | } | |
21 | ||
22 | function save() { | |
23 | $example_value = db_escape_string($_POST["example_value"]); | |
24 | ||
25 | echo "Value set to $example_value (not really)"; | |
26 | } | |
27 | ||
28 | function get_prefs_js() { | |
29 | return file_get_contents(dirname(__FILE__) . "/example.js"); | |
30 | } | |
31 | ||
32 | function hook_prefs_tab($args) { | |
33 | if ($args != "prefPrefs") return; | |
34 | ||
35 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("Example Pane")."\">"; | |
36 | ||
37 | print "<form dojoType=\"dijit.form.Form\">"; | |
38 | ||
39 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
40 | evt.preventDefault(); | |
41 | if (this.validate()) { | |
42 | console.log(dojo.objectToQuery(this.getValues())); | |
43 | new Ajax.Request('backend.php', { | |
44 | parameters: dojo.objectToQuery(this.getValues()), | |
45 | onComplete: function(transport) { | |
46 | notify_info(transport.responseText); | |
47 | } | |
48 | }); | |
49 | this.reset(); | |
50 | } | |
51 | </script>"; | |
52 | ||
53 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">"; | |
54 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">"; | |
55 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"example\">"; | |
56 | ||
57 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
58 | ||
59 | print "<tr><td width=\"40%\">".__("Sample value")."</td>"; | |
60 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"example_value\"></td></tr>"; | |
61 | ||
62 | print "</table>"; | |
63 | ||
64 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
65 | __("Set value")."</button>"; | |
66 | ||
67 | print "</form>"; | |
68 | ||
69 | print "</div>"; #pane | |
70 | } | |
71 | } | |
72 | ?> |