]> git.andy128k.dev Git - ipf.git/commitdiff
admin fields and widgets
authorAndrey Kutejko <andy128k@gmail.com>
Sun, 14 Dec 2014 12:43:53 +0000 (14:43 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Sun, 14 Dec 2014 12:55:34 +0000 (14:55 +0200)
ipf/admin/form/fields/html.php [new file with mode: 0644]
ipf/admin/form/fields/orderedset.php [new file with mode: 0644]
ipf/admin/form/layout.php [new file with mode: 0644]
ipf/admin/form/widgets/htmlinput.php [new file with mode: 0644]
ipf/admin/form/widgets/orderedsettable.php [new file with mode: 0644]
ipf/admin/formlayout.php [deleted file]
ipf/form/field/html.php [deleted file]
ipf/form/field/orderedset.php [deleted file]
ipf/form/field/varchar.php
ipf/form/widget/htmlinput.php [deleted file]
ipf/form/widget/orderedsettable.php [deleted file]

diff --git a/ipf/admin/form/fields/html.php b/ipf/admin/form/fields/html.php
new file mode 100644 (file)
index 0000000..52a5f01
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+
+class IPF_Admin_Form_Field_Html extends IPF_Form_Field_Varchar
+{
+    public $widget = 'IPF_Admin_Form_Widget_HTMLInput';
+}
+
diff --git a/ipf/admin/form/fields/orderedset.php b/ipf/admin/form/fields/orderedset.php
new file mode 100644 (file)
index 0000000..c46acb3
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+class IPF_Admin_Form_Field_OrderedSet extends IPF_Form_Field_Set
+{
+    public $widget = 'IPF_Admin_Form_Widget_OrderedSetTable';
+    public $orderBy;
+
+    public function clean($value)
+    {
+        if (!$value)
+            return $value;
+
+        $reorder = \PFF\Arr::pop($value, 'reorder');
+        $value = parent::clean($value);
+        $value['reorder'] = $reorder;
+
+        return $value;
+    }
+
+    protected function createWidget($args)
+    {
+        $args['orderBy'] = $this->orderBy;
+        return parent::createWidget($args);
+    }
+}
+
diff --git a/ipf/admin/form/layout.php b/ipf/admin/form/layout.php
new file mode 100644 (file)
index 0000000..97072db
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+
+use \PFF\HtmlBuilder\Tag as Tag;
+
+class IPF_Admin_Form_Layout extends IPF_Form_LayoutAdapter
+{
+    public function startForm($form)
+    {
+        $errors = $this->commonErrors($form);
+        return $this->errors($errors) .
+            $this->hiddenWidgets($form);
+    }
+
+    public function startGroup($label)
+    {
+        if ($label)
+            return Tag::div(array('class' => 'form-group-title'), $label)->html();
+        else
+            return '';
+    }
+
+    public function field($boundField, $errors)
+    {
+        if ($boundField->help_text) {
+            $help_text = Tag::p(array('class' => 'help'))
+                ->raw($boundField->help_text);
+        } else {
+            $help_text = '';
+        }
+
+        if ($boundField->field instanceof IPF_Form_Field_Set) {
+            return $this->errors($errors) .
+                Tag::div()
+                    ->raw($boundField->renderWidget())
+                    ->append($help_text);
+        } else {
+            return $this->errors($errors) .
+                Tag::div(array('class' => 'form-row'))
+                    ->raw($boundField->renderLabel())
+                    ->append(Tag::div()
+                        ->raw($boundField->renderWidget())
+                        ->append($help_text));
+        }
+    }
+
+    private function errors($errors)
+    {
+        if (!count($errors))
+            return '';
+
+        $ul = Tag::ul(array('class' => 'errorlist'));
+        foreach ($errors as $err)
+            $ul->append(Tag::li(null, $err->message));
+        return Tag::div(array('class' => 'form-row'), $ul);
+    }
+}
+
diff --git a/ipf/admin/form/widgets/htmlinput.php b/ipf/admin/form/widgets/htmlinput.php
new file mode 100644 (file)
index 0000000..30d17b8
--- /dev/null
@@ -0,0 +1,113 @@
+<?php
+
+use \PFF\HtmlBuilder\Tag as Tag;
+
+class IPF_Admin_Form_Widget_HTMLInput extends IPF_Form_Widget
+{
+    public $tinymce_url;
+    public $force_absolute_urls;
+    public $editor_config;
+
+    public function __construct($attrs=array())
+    {
+        $this->tinymce_url = \PFF\Arr::pop($attrs, 'tinymce_url',
+            IPF::get('tiny_mce_url',
+            IPF::get('static_url').'admin/tinymce/'));
+
+        $this->force_absolute_urls  = \PFF\Arr::pop($attrs, 'force_absolute_urls',  false);
+        $this->editor_config        = \PFF\Arr::pop($attrs, 'editor_config',        array());
+
+        parent::__construct($attrs);
+    }
+
+    public function render($name, $value, $extra_attrs=array())
+    {
+        if ($value === null) $value = '';
+
+        $extra_config = '';
+        foreach ($this->editor_config as $key => $val) {
+            $extra_config .= ",\n{$key} : ";
+            if (is_bool($val)) {
+                $extra_config .= $val ? 'true' : 'false';
+            } else {
+                $extra_config .= '"'.$val.'"';
+            }
+        }
+
+        return Tag::textarea()
+            ->attr('cols', 70)
+            ->attr('rows', 20)
+            ->attrs($this->attrs)
+            ->attrs($extra_attrs)
+            ->attr('name', $name)
+            ->addClass($this->force_absolute_urls ? 'htmlEditorAbs' : 'htmlEditor')
+            ->append($value)
+            ->html();
+    }
+
+    public function extra_js()
+    {
+        $filebrowser_url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_FileBrowser', array('/'));
+        return array(
+            '<script type="text/javascript" src="'.$this->tinymce_url.'tinymce.min.js"></script>',
+            '<script type="text/javascript">(function(){
+function ipf_filebrowser(field_name, url, type, win) {
+  tinyMCE.activeEditor.windowManager.open({
+    file: "'.$filebrowser_url.'/",
+    title: "IPF File Browser",
+    width: 800,
+    height: 600,
+    resizable: "yes",
+    inline: "yes",
+    close_previous: "no"
+  }, {
+    onSelect: function(value) {
+      var input = win.document.getElementById(field_name);
+
+      input.value = value;
+      if ("createEvent" in document) {
+        var evt = document.createEvent("HTMLEvents");
+        evt.initEvent("change", false, true);
+        input.dispatchEvent(evt);
+      } else {
+        input.fireEvent("onchange");
+      }
+    }
+  });
+  return false;
+}
+
+var defaults = {
+  plugins: "anchor, charmap, code, colorpicker, contextmenu, fullscreen, hr, image, insertdatetime, link, lists, media, nonbreaking, paste, preview, print, searchreplace, tabfocus, table, textcolor, visualchars, wordcount",
+  toolbar: [
+    "undo redo | styleselect | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | forecolor backcolor sub sup | preview fullscreen",
+    "code link unlink image charmap | table | pastetext removeformat | formatselect fontselect fontsizeselect"
+  ],
+  extended_valid_elements: "span[class|style],code[class],iframe[src|width|height|name|align|frameborder|scrolling]",
+  fix_list_elements: true,
+  browser_spellcheck: true,
+  width: "80%",
+  height: "300",
+  document_base_url: "/",
+  file_browser_callback: ipf_filebrowser
+};
+
+tinyMCE.init($.extend({}, defaults, {
+  selector: ".htmlEditor",
+  convert_urls: false,
+  relative_urls: false,
+  remove_script_host: true
+}));
+
+tinyMCE.init($.extend({}, defaults, {
+  selector: ".htmlEditorAbs",
+  convert_urls: true,
+  relative_urls: false,
+  remove_script_host: false
+}));
+
+})();</script>',
+        );
+    }
+}
+
diff --git a/ipf/admin/form/widgets/orderedsettable.php b/ipf/admin/form/widgets/orderedsettable.php
new file mode 100644 (file)
index 0000000..1bbd432
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+
+use \PFF\HtmlBuilder\Tag as Tag;
+
+class IPF_Admin_Form_Widget_OrderedSetTable extends IPF_Form_Widget_SetTable
+{
+    public $orderBy;
+
+    public function __construct($attrs=array())
+    {
+        $this->orderBy = \PFF\Arr::pop($attrs, 'orderBy');
+        parent::__construct($attrs);
+    }
+
+    public function render($name, $value, $extra_attrs=array())
+    {
+        if (array_key_exists('class', $extra_attrs))
+            $extra_attrs['class'] .= ' orderable-set-table';
+        else
+            $extra_attrs['class'] = 'orderable-set-table';
+
+        $extra_attrs['data-reorder'] = $name.'[reorder]';
+
+        return parent::render($name, $value, $extra_attrs);
+    }
+
+    protected function renderRow($prefix, $obj, $errors, $index)
+    {
+        $tr = parent::renderRow($prefix, $obj, $errors, $index);
+
+        if (array_key_exists('id', $obj))
+            $tr->attr('data-id', $obj['id']);
+        else
+            $tr->addClass('nodrag')->addClass('nodrop');
+
+        return $tr;
+    }
+
+    public function extra_js()
+    {
+        $js = parent::extra_js();
+
+        $js[] = '<script src="'.IPF::get('static_url').'admin/js/jquery.tablednd.js"></script>';
+        $js[] = '<script>
+$(function(){
+    $(\'.orderable-set-table\').each(function(){
+        var $table = $(this), $form = $table.closest("form"), reorder = $table.data("reorder");
+        $table.tableDnD({
+            onDragClass: "ItemsDragClass",
+            onDrop: function(table, row) {
+                var i;
+                $form.find("[name=\'"+reorder+"[]\']").remove();
+                $table.find(\'tr[data-id]\').each(function(){
+                    i = $("<input/>").attr("type", "hidden").attr("name", reorder+"[]").attr("value", $(this).data(\'id\'));
+                    $form.append(i);
+                });
+            }
+        });
+    });
+});
+</script>';
+        return $js;
+    }
+
+    public function valueFromFormData($name, $data)
+    {
+        if (!isset($data[$name]))
+            return null;
+
+        $value = $data[$name];
+        $reorder = \PFF\Arr::pop($value, 'reorder');
+        $data[$name] = $value;
+
+        $value = parent::valueFromFormData($name, $data);
+        $value['reorder'] = $reorder;
+
+        return $value;
+    }
+}
+
diff --git a/ipf/admin/formlayout.php b/ipf/admin/formlayout.php
deleted file mode 100644 (file)
index 97072db..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-
-use \PFF\HtmlBuilder\Tag as Tag;
-
-class IPF_Admin_Form_Layout extends IPF_Form_LayoutAdapter
-{
-    public function startForm($form)
-    {
-        $errors = $this->commonErrors($form);
-        return $this->errors($errors) .
-            $this->hiddenWidgets($form);
-    }
-
-    public function startGroup($label)
-    {
-        if ($label)
-            return Tag::div(array('class' => 'form-group-title'), $label)->html();
-        else
-            return '';
-    }
-
-    public function field($boundField, $errors)
-    {
-        if ($boundField->help_text) {
-            $help_text = Tag::p(array('class' => 'help'))
-                ->raw($boundField->help_text);
-        } else {
-            $help_text = '';
-        }
-
-        if ($boundField->field instanceof IPF_Form_Field_Set) {
-            return $this->errors($errors) .
-                Tag::div()
-                    ->raw($boundField->renderWidget())
-                    ->append($help_text);
-        } else {
-            return $this->errors($errors) .
-                Tag::div(array('class' => 'form-row'))
-                    ->raw($boundField->renderLabel())
-                    ->append(Tag::div()
-                        ->raw($boundField->renderWidget())
-                        ->append($help_text));
-        }
-    }
-
-    private function errors($errors)
-    {
-        if (!count($errors))
-            return '';
-
-        $ul = Tag::ul(array('class' => 'errorlist'));
-        foreach ($errors as $err)
-            $ul->append(Tag::li(null, $err->message));
-        return Tag::div(array('class' => 'form-row'), $ul);
-    }
-}
-
diff --git a/ipf/form/field/html.php b/ipf/form/field/html.php
deleted file mode 100644 (file)
index 6c44320..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php
-
-class IPF_Form_Field_Html extends IPF_Form_Field_Varchar
-{
-    public $widget = 'IPF_Form_Widget_HTMLInput';
-}
-
diff --git a/ipf/form/field/orderedset.php b/ipf/form/field/orderedset.php
deleted file mode 100644 (file)
index 773e372..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-
-class IPF_Form_Field_OrderedSet extends IPF_Form_Field_Set
-{
-    public $widget = 'IPF_Form_Widget_OrderedSetTable';
-    public $orderBy;
-
-    public function clean($value)
-    {
-        if (!$value)
-            return $value;
-
-        $reorder = \PFF\Arr::pop($value, 'reorder');
-        $value = parent::clean($value);
-        $value['reorder'] = $reorder;
-
-        return $value;
-    }
-
-    protected function createWidget($args)
-    {
-        $args['orderBy'] = $this->orderBy;
-        return parent::createWidget($args);
-    }
-}
-
index 57078d66aefae175c9a8a1254f72bbba8e505db0..4ff45b41cae94aaacf6b3ba0c0bf79cfaa349775 100644 (file)
@@ -24,7 +24,7 @@ class IPF_Form_Field_Varchar extends IPF_Form_Field
 
     protected function createWidget($args)
     {
-        if ($this->max_length > 255 && $this->widget !== 'IPF_Form_Widget_HTMLInput') {
+        if ($this->max_length > 255 && $this->widget === 'IPF_Form_Widget_TextInput') {
             $widgetClass = 'IPF_Form_Widget_TextareaInput';
         } else {
             $widgetClass = $this->widget;
diff --git a/ipf/form/widget/htmlinput.php b/ipf/form/widget/htmlinput.php
deleted file mode 100644 (file)
index e872198..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-
-use \PFF\HtmlBuilder\Tag as Tag;
-
-class IPF_Form_Widget_HTMLInput extends IPF_Form_Widget
-{
-    public $tinymce_url;
-    public $force_absolute_urls;
-    public $editor_config;
-
-    public function __construct($attrs=array())
-    {
-        $this->tinymce_url = \PFF\Arr::pop($attrs, 'tinymce_url',
-            IPF::get('tiny_mce_url',
-            IPF::get('static_url').'admin/tinymce/'));
-
-        $this->force_absolute_urls  = \PFF\Arr::pop($attrs, 'force_absolute_urls',  false);
-        $this->editor_config        = \PFF\Arr::pop($attrs, 'editor_config',        array());
-
-        parent::__construct($attrs);
-    }
-
-    public function render($name, $value, $extra_attrs=array())
-    {
-        if ($value === null) $value = '';
-
-        $extra_config = '';
-        foreach ($this->editor_config as $key => $val) {
-            $extra_config .= ",\n{$key} : ";
-            if (is_bool($val)) {
-                $extra_config .= $val ? 'true' : 'false';
-            } else {
-                $extra_config .= '"'.$val.'"';
-            }
-        }
-
-        return Tag::textarea()
-            ->attr('cols', 70)
-            ->attr('rows', 20)
-            ->attrs($this->attrs)
-            ->attrs($extra_attrs)
-            ->attr('name', $name)
-            ->addClass($this->force_absolute_urls ? 'htmlEditorAbs' : 'htmlEditor')
-            ->append($value)
-            ->html();
-    }
-
-    public function extra_js()
-    {
-        $filebrowser_url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_FileBrowser', array('/'));
-        return array(
-            '<script type="text/javascript" src="'.$this->tinymce_url.'tinymce.min.js"></script>',
-            '<script type="text/javascript">(function(){
-function ipf_filebrowser(field_name, url, type, win) {
-  tinyMCE.activeEditor.windowManager.open({
-    file: "'.$filebrowser_url.'/",
-    title: "IPF File Browser",
-    width: 800,
-    height: 600,
-    resizable: "yes",
-    inline: "yes",
-    close_previous: "no"
-  }, {
-    onSelect: function(value) {
-      var input = win.document.getElementById(field_name);
-
-      input.value = value;
-      if ("createEvent" in document) {
-        var evt = document.createEvent("HTMLEvents");
-        evt.initEvent("change", false, true);
-        input.dispatchEvent(evt);
-      } else {
-        input.fireEvent("onchange");
-      }
-    }
-  });
-  return false;
-}
-
-var defaults = {
-  plugins: "anchor, charmap, code, colorpicker, contextmenu, fullscreen, hr, image, insertdatetime, link, lists, media, nonbreaking, paste, preview, print, searchreplace, tabfocus, table, textcolor, visualchars, wordcount",
-  toolbar: [
-    "undo redo | styleselect | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | forecolor backcolor sub sup | preview fullscreen",
-    "code link unlink image charmap | table | pastetext removeformat | formatselect fontselect fontsizeselect"
-  ],
-  extended_valid_elements: "span[class|style],code[class],iframe[src|width|height|name|align|frameborder|scrolling]",
-  fix_list_elements: true,
-  browser_spellcheck: true,
-  width: "80%",
-  height: "300",
-  document_base_url: "/",
-  file_browser_callback: ipf_filebrowser
-};
-
-tinyMCE.init($.extend({}, defaults, {
-  selector: ".htmlEditor",
-  convert_urls: false,
-  relative_urls: false,
-  remove_script_host: true
-}));
-
-tinyMCE.init($.extend({}, defaults, {
-  selector: ".htmlEditorAbs",
-  convert_urls: true,
-  relative_urls: false,
-  remove_script_host: false
-}));
-
-})();</script>',
-        );
-    }
-}
-
diff --git a/ipf/form/widget/orderedsettable.php b/ipf/form/widget/orderedsettable.php
deleted file mode 100644 (file)
index 60ca43c..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-
-use \PFF\HtmlBuilder\Tag as Tag;
-
-class IPF_Form_Widget_OrderedSetTable extends IPF_Form_Widget_SetTable
-{
-    public $orderBy;
-
-    public function __construct($attrs=array())
-    {
-        $this->orderBy = \PFF\Arr::pop($attrs, 'orderBy');
-        parent::__construct($attrs);
-    }
-
-    public function render($name, $value, $extra_attrs=array())
-    {
-        if (array_key_exists('class', $extra_attrs))
-            $extra_attrs['class'] .= ' orderable-set-table';
-        else
-            $extra_attrs['class'] = 'orderable-set-table';
-
-        $extra_attrs['data-reorder'] = $name.'[reorder]';
-
-        return parent::render($name, $value, $extra_attrs);
-    }
-
-    protected function renderRow($prefix, $obj, $errors, $index)
-    {
-        $tr = parent::renderRow($prefix, $obj, $errors, $index);
-
-        if (array_key_exists('id', $obj))
-            $tr->attr('data-id', $obj['id']);
-        else
-            $tr->addClass('nodrag')->addClass('nodrop');
-
-        return $tr;
-    }
-
-    public function extra_js()
-    {
-        $js = parent::extra_js();
-
-        $js[] = '<script src="'.IPF::get('static_url').'admin/js/jquery.tablednd.js"></script>';
-        $js[] = '<script>
-$(function(){
-    $(\'.orderable-set-table\').each(function(){
-        var $table = $(this), $form = $table.closest("form"), reorder = $table.data("reorder");
-        $table.tableDnD({
-            onDragClass: "ItemsDragClass",
-            onDrop: function(table, row) {
-                var i;
-                $form.find("[name=\'"+reorder+"[]\']").remove();
-                $table.find(\'tr[data-id]\').each(function(){
-                    i = $("<input/>").attr("type", "hidden").attr("name", reorder+"[]").attr("value", $(this).data(\'id\'));
-                    $form.append(i);
-                });
-            }
-        });
-    });
-});
-</script>';
-        return $js;
-    }
-
-    public function valueFromFormData($name, $data)
-    {
-        if (!isset($data[$name]))
-            return null;
-
-        $value = $data[$name];
-        $reorder = \PFF\Arr::pop($value, 'reorder');
-        $data[$name] = $value;
-
-        $value = parent::valueFromFormData($name, $data);
-        $value['reorder'] = $reorder;
-
-        return $value;
-    }
-}
-