2012-12-23 13:15:44 +01:00
|
|
|
<?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 $host;
|
|
|
|
|
2012-12-25 07:02:08 +01:00
|
|
|
function about() {
|
2012-12-24 12:39:42 +01:00
|
|
|
return array(1.0,
|
|
|
|
"Example plugin #1",
|
2012-12-24 21:45:10 +01:00
|
|
|
"fox",
|
2013-03-27 15:16:30 +01:00
|
|
|
true,
|
|
|
|
"http://site.com");
|
2012-12-24 12:39:42 +01:00
|
|
|
}
|
|
|
|
|
2012-12-25 07:02:08 +01:00
|
|
|
function init($host) {
|
2012-12-23 13:15:44 +01:00
|
|
|
$this->host = $host;
|
|
|
|
|
|
|
|
$host->add_hook($host::HOOK_PREFS_TAB, $this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function save() {
|
2013-04-17 16:34:18 +02:00
|
|
|
$example_value = db_escape_string($_POST["example_value"]);
|
2012-12-23 13:15:44 +01:00
|
|
|
|
2012-12-27 13:55:25 +01:00
|
|
|
$this->host->set($this, "example", $example_value);
|
|
|
|
|
|
|
|
echo "Value set to $example_value";
|
2012-12-23 13:15:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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")."\">";
|
|
|
|
|
2012-12-27 13:55:25 +01:00
|
|
|
print "<br/>";
|
|
|
|
|
|
|
|
// print_r($this->host->set($this, "example", rand(0,100)));
|
|
|
|
// print_r($this->host->get_all($this));
|
|
|
|
|
|
|
|
$value = $this->host->get($this, "example");
|
|
|
|
|
2012-12-23 13:15:44 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2012-12-27 13:55:25 +01:00
|
|
|
//this.reset();
|
2012-12-23 13:15:44 +01:00
|
|
|
}
|
|
|
|
</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>";
|
2012-12-27 13:55:25 +01:00
|
|
|
print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"example_value\" value=\"$value\"></td></tr>";
|
2012-12-23 13:15:44 +01:00
|
|
|
|
|
|
|
print "</table>";
|
|
|
|
|
|
|
|
print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
|
|
|
|
__("Set value")."</button>";
|
|
|
|
|
|
|
|
print "</form>";
|
|
|
|
|
|
|
|
print "</div>"; #pane
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|