summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2009-04-23 18:39:15 +0000
committerdeva <deva>2009-04-23 18:39:15 +0000
commit9854238d0d44ea269d97509d6d35f49d3b46e834 (patch)
treec0b71348b8b67e3bcec4e47649dd56b0707b04d4
parent9ecc7372ae70b397f5546adb60b0e4542a6bbb78 (diff)
Crafted very ugly but slightly usable menu editor.
-rw-r--r--utils/forms.php129
-rw-r--r--utils/modules/config.php24
-rw-r--r--utils/modules/pages.php2
3 files changed, 131 insertions, 24 deletions
diff --git a/utils/forms.php b/utils/forms.php
index dd0a768..8f2238e 100644
--- a/utils/forms.php
+++ b/utils/forms.php
@@ -1,6 +1,6 @@
<?php
class LineEdit {
- private $label, $name, $value;
+ public $label, $name, $value;
function LineEdit($label, $name, $value = "")
{
@@ -20,7 +20,7 @@ class LineEdit {
}
class FileUpload {
- private $label, $name, $accept;
+ public $label, $name, $accept;
public function FileUpload($label, $name, $accept = "*")
{
@@ -41,7 +41,7 @@ class FileUpload {
}
class Button {
- private $label;
+ public $label;
public function Button($label)
{
@@ -60,7 +60,7 @@ class Button {
}
class CheckBox {
- private $label, $name, $value;
+ public $label, $name, $value;
public function CheckBox($label, $name, $value = "")
{
@@ -80,7 +80,7 @@ class CheckBox {
}
class ComboBox {
- private $label, $name, $value, $values;
+ public $label, $name, $value, $values;
public function ComboBox($label, $name, $value, $values)
{
@@ -108,7 +108,7 @@ class ComboBox {
}
class Hidden {
- private $values;
+ public $values;
public function Hidden($values)
{
@@ -126,7 +126,7 @@ class Hidden {
}
class TextEdit {
- private $label, $name, $value;
+ public $label, $name, $value;
function TextEdit($label, $name, $value = "")
{
@@ -146,7 +146,7 @@ class TextEdit {
}
class DateTimeEdit {
- private $label, $name, $timestamp;
+ public $label, $name, $timestamp;
function DateTimeEdit($label, $name, $timestamp = 0)
{
@@ -197,7 +197,7 @@ class DateTimeEdit {
}
class ImageComboBox {
- private $label, $name, $value, $values;
+ public $label, $name, $value, $values;
public function ImageComboBox($label, $name, $value, $values)
{
@@ -229,14 +229,118 @@ class ImageComboBox {
}
}
+class ListEditor {
+ public $label, $name, $namewidget, $valuewidget, $values;
+
+ public function ListEditor($label, $name, $namewidget, $valuewidget, $values = array())
+ {
+ $this->label = $label;
+ $this->name = $name;
+ $this->namewidget = $namewidget;
+ $this->valuewidget = $valuewidget;
+ $this->values = $values;
+ }
+
+ public function render($indent = "")
+ {
+ $str = $indent . "<script type=\"text/javascript\">\n";
+ $str .= $indent . "//<!--\n";
+ $str .= $indent . "function deleteItem()\n";
+ $str .= $indent . "{\n";
+ $str .= $indent . " var items = document.getElementById('items');\n";
+ $str .= $indent . " var selIndex = items.selectedIndex;\n";
+ $str .= $indent . " if(selIndex < 0) return;\n";
+ $str .= $indent . " var item = items.options.item(selIndex);\n";
+ $str .= $indent . " items.removeChild(item);\n";
+ $str .= $indent . "}\n";
+ $str .= $indent . "\n";
+ $str .= $indent . "function addItem()\n";
+ $str .= $indent . "{\n";
+ $str .= $indent . " var items = document.getElementById('items');\n";
+ $str .= $indent . " var item_names = document.getElementsByName('vars[".$this->namewidget->name."]');\n";
+ $str .= $indent . " var item_values = document.getElementsByName('vars[".$this->valuewidget->name."]');\n";
+ $str .= $indent . " var item_name = item_names[0].value;\n";
+ $str .= $indent . " var item_value = item_values[0].value;\n";
+ $str .= $indent . " var item = document.createElement('option');\n";
+ $str .= $indent . " item.value = item_value + ':' + item_name;\n";
+ $str .= $indent . " item.innerHTML = item_value + ':' + item_name;\n";
+ $str .= $indent . " items.appendChild(item);\n";
+ $str .= $indent . "}\n";
+ $str .= $indent . "\n";
+ $str .= $indent . "function move(mod)\n";
+ $str .= $indent . "{\n";
+ $str .= $indent . " var items = document.getElementById('items');\n";
+ $str .= $indent . " var idx = items.selectedIndex;\n";
+ $str .= $indent . "\n";
+ $str .= $indent . " if(idx < 0 || idx + mod < 0 || idx + mod > items.length - 1) return;\n";
+ $str .= $indent . "\n";
+ $str .= $indent . " var tmp_value = items.options[idx].value;\n";
+ $str .= $indent . " var tmp_innerHTML = items.options[idx].innerHTML;\n";
+ $str .= $indent . "\n";
+ $str .= $indent . " items.options[idx].value = items.options[idx + mod].value;\n";
+ $str .= $indent . " items.options[idx].innerHTML = items.options[idx + mod].innerHTML;\n";
+ $str .= $indent . " items.options[idx + mod].value = tmp_value;\n";
+ $str .= $indent . " items.options[idx + mod].innerHTML = tmp_innerHTML;\n";
+ $str .= $indent . "\n";
+ $str .= $indent . " items.selectedIndex += mod;\n";
+ $str .= $indent . "}\n";
+ $str .= $indent . "\n";
+ $str .= $indent . "function moveUp()\n";
+ $str .= $indent . "{\n";
+ $str .= $indent . " move(-1)\n";
+ $str .= $indent . "}\n";
+ $str .= $indent . "\n";
+ $str .= $indent . "function moveDown()\n";
+ $str .= $indent . "{\n";
+ $str .= $indent . " move(1)\n";
+ $str .= $indent . "}\n";
+ $str .= $indent . "\n";
+ $str .= $indent . "function selectAll()\n";
+ $str .= $indent . "{\n";
+ $str .= $indent . " var items = document.getElementById('items');\n";
+ $str .= $indent . " var len = items.length;\n";
+ $str .= $indent . " var data = '';\n";
+ $str .= $indent . " for(i = 0; i < len; i++) {\n";
+ $str .= $indent . " items.options[i].selected = true;\n";
+ $str .= $indent . " }\n";
+ $str .= $indent . "}\n";
+ $str .= $indent . "//-->\n";
+ $str .= $indent . "</script>\n";
+ $str .= $indent . "<select multiple size=\"8\" id=\"items\" name=\"".$this->name."[]\">\n";
+ foreach($this->values as $key => $val) {
+ $str .= $indent . " <option value=\"".$key.":".$val."\">".$key.":".$val."</option>\n";
+ }
+ $str .= $indent . "</select><br/>\n";
+ $str .= $indent . "<img src=\"gfx/up.png\" button onclick=\"moveUp()\"/><br/>\n";
+ $str .= $indent . "<img src=\"gfx/down.png\" onclick=\"moveDown()\"/><br/>\n";
+ $str .= $this->namewidget->render($indent);
+ $str .= $this->valuewidget->render($indent);
+ $str .= "<img src=\"gfx/add.png\" onclick=\"addItem()\"/><br/>\n";
+ $str .= $indent . "<img src=\"gfx/del.png\" onclick=\"deleteItem()\"/><br/>\n";
+ return $str;
+ }
+
+ public function splitValues($values)
+ {
+ $out = array();
+ foreach($values as $value) {
+ $vals = explode(":", $value);
+ $out[$vals[0]]=$vals[1];
+ }
+ return $out;
+ }
+}
+
class Form {
- private $widgets = array();
- private $action;
- private $hasFileUpload = false;
+ public $widgets = array();
+ public $action;
+ public $hasFileUpload = false;
+ public $hasListEditor = false;
public function addWidget($widget)
{
if(get_class($widget) == "FileUpload") $this->hasFileUpload = true;
+ if(get_class($widget) == "ListEditor") $this->hasListEditor = true;
array_push($this->widgets, $widget);
}
@@ -245,6 +349,7 @@ class Form {
global $m, $s;
$str = $indent . "<form method=\"post\"\n";
if($this->hasFileUpload) $str .= $indent . " enctype=\"multipart/form-data\"\n";
+ if($this->hasListEditor) $str .= $indent . " onsubmit=\"selectAll();\"\n";
$str .= $indent . " action=\"?page=admin&amp;m=".$m."&amp;s=".$s."&amp;a=".$this->action."\">\n";
foreach($this->widgets as $widget) {
$str .= $widget->render($indent . " ");
diff --git a/utils/modules/config.php b/utils/modules/config.php
index a7068ef..4afb264 100644
--- a/utils/modules/config.php
+++ b/utils/modules/config.php
@@ -35,22 +35,24 @@ class Config {
{
switch($action) {
case "update":
- $this->setValue("menu", array("news" => "News",
- "shop" => "Shop",
- "downloads" => "Downloads",
- "biography" => "Biography",
- "live" => "Concerts",
- "discography" => "Discography",
- "guestbook" => "Guestbook",
- "members" => "Members",
- "gallery" => "Gallery",
- "contact" => "Contact"));
+ global $menulist;
+ $menu = ListEditor::splitValues($menulist);
+ $this->setValue("menu", $menu);
$this->write();
break;
default:
+ global $config;
+ global $pages;
+ $pagetitles = array();
+ foreach($pages->pages as $page) {
+ $pagetitles[$page->title] = $page->title;
+ }
$form = new Form("update");
- echo "Coming soon!";
+ $form->addWidget(new ListEditor("Menu items", "menulist",
+ new LineEdit("Title", "title"),
+ new ComboBox("Page", "page", "", $pagetitles),
+ $config->value("menu")));
$form->addWidget(new Button("Update"));
$form->render();
break;
diff --git a/utils/modules/pages.php b/utils/modules/pages.php
index a3979d3..d69b9e9 100644
--- a/utils/modules/pages.php
+++ b/utils/modules/pages.php
@@ -53,7 +53,7 @@ class Page {
class Pages {
private $file;
- private $pages = array();
+ public $pages = array();
// Admin config
public $admin_title = "Pages";