]>
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. | |
b9546011 AD |
5 | private $host; |
6 | ||
d2a421e3 | 7 | function about() { |
7a866114 AD |
8 | return array(1.0, |
9 | "Example plugin #1", | |
de612e7a | 10 | "fox", |
bb5e1a32 AD |
11 | true, |
12 | "http://site.com"); | |
7a866114 AD |
13 | } |
14 | ||
d2a421e3 | 15 | function init($host) { |
b9546011 AD |
16 | $this->host = $host; |
17 | ||
18 | $host->add_hook($host::HOOK_PREFS_TAB, $this); | |
19 | } | |
20 | ||
21 | function save() { | |
6322ac79 | 22 | $example_value = db_escape_string( $_POST["example_value"]); |
b9546011 | 23 | |
d8a1d2a2 AD |
24 | $this->host->set($this, "example", $example_value); |
25 | ||
26 | echo "Value set to $example_value"; | |
b9546011 AD |
27 | } |
28 | ||
29 | function get_prefs_js() { | |
30 | return file_get_contents(dirname(__FILE__) . "/example.js"); | |
31 | } | |
32 | ||
33 | function hook_prefs_tab($args) { | |
34 | if ($args != "prefPrefs") return; | |
35 | ||
36 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("Example Pane")."\">"; | |
37 | ||
d8a1d2a2 AD |
38 | print "<br/>"; |
39 | ||
40 | // print_r($this->host->set($this, "example", rand(0,100))); | |
41 | // print_r($this->host->get_all($this)); | |
42 | ||
43 | $value = $this->host->get($this, "example"); | |
44 | ||
b9546011 AD |
45 | print "<form dojoType=\"dijit.form.Form\">"; |
46 | ||
47 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> | |
48 | evt.preventDefault(); | |
49 | if (this.validate()) { | |
50 | console.log(dojo.objectToQuery(this.getValues())); | |
51 | new Ajax.Request('backend.php', { | |
52 | parameters: dojo.objectToQuery(this.getValues()), | |
53 | onComplete: function(transport) { | |
54 | notify_info(transport.responseText); | |
55 | } | |
56 | }); | |
d8a1d2a2 | 57 | //this.reset(); |
b9546011 AD |
58 | } |
59 | </script>"; | |
60 | ||
61 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">"; | |
62 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">"; | |
63 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"example\">"; | |
64 | ||
65 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
66 | ||
67 | print "<tr><td width=\"40%\">".__("Sample value")."</td>"; | |
d8a1d2a2 | 68 | print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"example_value\" value=\"$value\"></td></tr>"; |
b9546011 AD |
69 | |
70 | print "</table>"; | |
71 | ||
72 | print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". | |
73 | __("Set value")."</button>"; | |
74 | ||
75 | print "</form>"; | |
76 | ||
77 | print "</div>"; #pane | |
78 | } | |
79 | } | |
80 | ?> |