From 2dd67098cd608a24bc1300cb484059d48c2f826d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kiss=20=C3=81d=C3=A1m?= Date: Fri, 23 Jan 2015 19:20:35 +0100 Subject: [PATCH 1/2] color picker --- .../dashboard/blocks/designer_content.php | 2 + libraries/block_generator.php | 45 +++++++++++++++++++ .../dashboard/blocks/designer_content.php | 3 ++ 3 files changed, 50 insertions(+) diff --git a/controllers/dashboard/blocks/designer_content.php b/controllers/dashboard/blocks/designer_content.php index 5b7c36a..796b311 100644 --- a/controllers/dashboard/blocks/designer_content.php +++ b/controllers/dashboard/blocks/designer_content.php @@ -93,6 +93,8 @@ public function generate_block() { //In single_pages, do not prepend "action_" ( $block->add_url_field($field_labels[$id], $field_prefixes[$id], $field_suffixes[$id], !empty($fields_required[$id]), $field_url_targets[$id]); } else if ($type == 'date') { $block->add_date_field($field_labels[$id], $field_prefixes[$id], $field_suffixes[$id], !empty($fields_required[$id]), $field_date_formats[$id]); + } else if ($type == 'color') { + $block->add_color_field($field_labels[$id], $field_prefixes[$id], $field_suffixes[$id], !empty($fields_required[$id])); } else if ($type == 'select') { $block->add_select_field($field_labels[$id], $field_select_options[$id], !empty($fields_required[$id]), $field_select_show_headers[$id], $field_select_header_texts[$id]); } else if ($type == 'wysiwyg') { diff --git a/libraries/block_generator.php b/libraries/block_generator.php index 51b20a3..1014ccf 100644 --- a/libraries/block_generator.php +++ b/libraries/block_generator.php @@ -117,6 +117,17 @@ public function add_date_field($label, $prefix = '', $suffix = '', $required = f ); } + public function add_color_field($label, $prefix = '', $suffix = '', $required = false) { + $this->fields[] = array( + 'num' => count($this->fields) + 1, + 'type' => 'color', + 'label' => $label, + 'prefix' => $prefix, + 'suffix' => $suffix, + 'required' => $required + ); + } + public function add_select_field($label, $options, $required, $show_header = false, $header_text = '') { $this->fields[] = array( 'num' => count($this->fields) + 1, @@ -237,6 +248,14 @@ private function generate_auto_js() { $code .= "\t}\n\n"; } + if ($field['type'] == 'color' && $field['required']) { + $code .= "\tif (\$('input[name=field_{$field['num']}_color_value]').val() == '' || \$('input[name=field_{$field['num']}_color_value]').val() == 0) {\n"; + $translated_error = $this->addslashes_single( t('Missing required color') ); + $label = $this->addslashes_single($field['label']); + $code .= "\t\tccm_addError('{$translated_error}: {$field_label}');\n"; + $code .= "\t}\n\n"; + } + if ($field['type'] == 'select' && $field['required']) { $code .= "\tif (\$('select[name=field_{$field['num']}_select_value]').val() == '' || \$('select[name=field_{$field['num']}_select_value]').val() == 0) {\n"; $translated_error = $this->addslashes_single( t('Missing required selection') ); @@ -323,6 +342,10 @@ private function generate_controller_php() { $code .= "\t\t\$content[] = date('{$field['format']}', \$this->field_{$field['num']}_date_value);\n"; $fieldcount++; } + if ($field['type'] == 'color') { + $code .= "\t\t\$content[] = \$this->field_{$field['num']}_color_value;\n"; + $fieldcount++; + } if ($field['type'] == 'wysiwyg') { $code .= "\t\t\$content[] = \$this->field_{$field['num']}_wysiwyg_content;\n"; $fieldcount++; @@ -470,6 +493,9 @@ private function generate_db_xml() { if ($field['type'] == 'date') { $code .= "\t\t\n\n"; } + if ($field['type'] == 'color') { + $code .= "\t\t\n\n"; + } if ($field['type'] == 'select') { $code .= "\t\t\n\n"; } @@ -605,6 +631,14 @@ private function generate_edit_php() { $include_date_time = true; } + if ($field['type'] == 'color') { + $code .= "
\n"; + $code .= "\t

{$field['label']}

\n"; + $code .= "\toutput('field_{$field['num']}_color_value', '', \$field_{$field['num']}_color_value); ?>\n"; + $code .= "
\n\n"; + $include_color = true; + } + if ($field['type'] == 'select') { $code .= "
\n"; $code .= "\t

{$field['label']}

\n"; @@ -642,6 +676,7 @@ private function generate_edit_php() { $code .= $include_asset_library ? "\$al = Loader::helper('concrete/asset_library');\n" : ''; $code .= $include_page_selector ? "\$ps = Loader::helper('form/page_selector');\n" : ''; $code .= $include_date_time ? "\$dt = Loader::helper('form/date_time');\n" : ''; + $code .= $include_color ? "\$fh = Loader::helper('form/color');\n" : ''; $code .= $include_editor_config ? "Loader::element('editor_config');\n" : ''; $token = '[[[GENERATOR_REPLACE_HELPERLOADERS]]]'; $template = str_replace($token, $code, $template); @@ -764,6 +799,16 @@ private function generate_view_php() { $code .= "\n\n"; } + if ($field['type'] == 'color') { + $code .= "\n"; + $code .= "\t"; + $code .= empty($field['prefix']) ? '' : $field['prefix']; + $code .= ""; + $code .= empty($field['suffix']) ? '' : $field['suffix']; + $code .= "\n"; + $code .= "\n\n"; + } + if ($field['type'] == 'select') { $i = 1; foreach ($field['options'] as $option) { diff --git a/single_pages/dashboard/blocks/designer_content.php b/single_pages/dashboard/blocks/designer_content.php index b333d7a..8a3f44a 100644 --- a/single_pages/dashboard/blocks/designer_content.php +++ b/single_pages/dashboard/blocks/designer_content.php @@ -245,6 +245,8 @@ function s2nb($text) {    []    + [] +    []    [] @@ -288,6 +290,7 @@ function s2nb($text) { 'link': '', 'url': '', 'date': '', + 'color': '', 'select': '', 'wysiwyg': '' }; From aa516af1198aee9f832c5fdce6991971b8e6327c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kiss=20=C3=81d=C3=A1m?= Date: Sun, 25 Jan 2015 19:55:13 +0100 Subject: [PATCH 2/2] spectrum color picker support --- libraries/block_generator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/block_generator.php b/libraries/block_generator.php index 1014ccf..8feb9a4 100644 --- a/libraries/block_generator.php +++ b/libraries/block_generator.php @@ -675,8 +675,8 @@ private function generate_edit_php() { $code = ''; $code .= $include_asset_library ? "\$al = Loader::helper('concrete/asset_library');\n" : ''; $code .= $include_page_selector ? "\$ps = Loader::helper('form/page_selector');\n" : ''; - $code .= $include_date_time ? "\$dt = Loader::helper('form/date_time');\n" : ''; - $code .= $include_color ? "\$fh = Loader::helper('form/color');\n" : ''; + $code .= $include_date_time ? "\$dt = Loader::helper('form/date_time');\n" : '';; + $code .= $include_color ? "\$fh = Package::getByHandle('jl_spectrum_color_picker') ? Loader::helper('spectrum_color', 'jl_spectrum_color_picker') : Loader::helper('form/color');\n" : ''; $code .= $include_editor_config ? "Loader::element('editor_config');\n" : ''; $token = '[[[GENERATOR_REPLACE_HELPERLOADERS]]]'; $template = str_replace($token, $code, $template);