Commit 09b45db2 authored by Lisa Seeto's avatar Lisa Seeto Committed by Robert Lyon
Browse files

Bug 1846972: Skin text colour defaults should default to the theme colours



Set up skin colour fields to be able to use the theme default

behatnotneeded

Change-Id: I891f8fbe4907d962535f2e769ad912d073f03f3c
Signed-off-by: default avatarLisa Seeto <lisaseeto@catalyst.net.nz>
parent 4e60a70f
......@@ -73,7 +73,7 @@ $string['element.passwordpolicy.ulns'] = 'Upper and lowercase letters, numbers,
$string['element.select.other'] = 'Other';
$string['element.select.remove'] = 'Remove "%s"';
$string['element.color.transparent'] = 'Default or ';
$string['element.color.transparent1'] = 'Theme default';
$string['element.font.themedefault'] = 'Use Theme font';
$string['rule.before.before'] = 'This cannot be after the field "%s"';
......
......@@ -25,21 +25,22 @@ function pieform_element_color(Pieform $form, $element) {
$name = Pieform::hsc($element['name']);
$baseid = Pieform::hsc($form->get_name() . '_' . $element['name']);
$value = Pieform::hsc($form->get_value($element));
$transparent = (!empty($element['options']['transparent']) && $element['options']['transparent'] == true);
$themedefault = (!empty($element['options']['themedefault'])) ? $element['options']['themedefault'] : '';
// Transparency optional control
if ($transparent) {
if ($themedefault) {
$optional = <<<EOF
<script>
var {$baseid}_oldval = '';
var {$baseid}_oldval = '{$value}';
function {$baseid}_toggle(x) {
if ( x.checked ) {
{$baseid}_oldval = jQuery('#{$baseid}').val();
jQuery('#{$baseid}').val('');
document.getElementById('{$baseid}')._jscLinkedInstance.fromString('{$themedefault}');
jQuery('#{$baseid}').prop('disabled', true);
}
else {
jQuery('#{$baseid}').val({$baseid}_oldval);
document.getElementById('{$baseid}')._jscLinkedInstance.fromString({$baseid}_oldval);
jQuery('#{$baseid}').prop('disabled', false);
}
}
......@@ -52,30 +53,29 @@ EOF;
}
$optional .= ' <input type="checkbox" '
. (isset($element['defaultvalue']) && $element['defaultvalue'] == 'transparent' ? 'checked="checked" ' : '')
. ($themedefault && $element['defaultvalue'] == $themedefault ? 'checked="checked" ' : '')
. 'name="' . $name . '_optional" id="' . $baseid . '_optional" onchange="' . $baseid . '_toggle(this)" '
. 'tabindex="' . Pieform::hsc($element['tabindex']) . '">';
$optional .= ' <label for="' . $baseid . '_optional">'
. $title . $form->i18n('element', 'color', 'transparent', $element) . '</label> ';
. $title . $form->i18n('element', 'color', 'transparent1', $element) . '</label> ';
$result .= $optional;
}
// Color Picker (Chooser)
$result .= '<input type="text" name="' . $name . '_color" id="' . $baseid . '"'
. ($transparent && (!isset($element['defaultvalue']) || $element['defaultvalue'] == 'transparent') ? ' disabled="disabled"' : '')
. ($transparent ? ' class="jscolor {hash:true,required:false}"' : ' class="jscolor {hash:true}"')
. ' value="' . ($value == 'transparent' ? '' : $value) . '">';
. ($themedefault && $element['defaultvalue'] == $themedefault ? ' disabled="disabled"' : '')
. ' value="' . $value . '">';
return $result;
}
/**
* Returns the color value of the color selector element from the request or transparent
* Returns the color value of the color selector element from the request
*
* @param Pieform $form The form the element is attached to
* @param array $element The element to get the value for
* @return string A 6-digit hex color value, or the string "transparent"
* @return string A 6-digit hex color value
*/
function pieform_element_color_get_value(Pieform $form, $element) {
$name = $element['name'];
......@@ -97,17 +97,23 @@ function pieform_element_color_get_value(Pieform $form, $element) {
$color = '';
}
if ($color === '') {
return 'transparent';
return '#FFFFFF';
}
$color = "#{$color}";
return $color;
}
if (isset($global[$name . '_optional']) && isset($element['options']['themedefault'])) {
if (!empty($element['options']['themedefault'])) {
return $element['options']['themedefault'];
}
}
if (isset($element['defaultvalue'])) {
return $element['defaultvalue'];
}
return 'transparent';
return '#FFFFFF';
}
/**
......@@ -118,17 +124,13 @@ function pieform_element_color_get_value(Pieform $form, $element) {
*/
function pieform_element_color_get_headdata($element, Pieform $form) {
$libfile = get_config('wwwroot') . 'js/jscolor/jscolor.js';
$name = $form->get_property('name') . '_' . $element['name'];
$name = Pieform::hsc($form->get_name() . '_' . $element['name']);
$result = '<script>';
$result .= "var initjscolor = false; \n";
$result .= "var jsc" . $name . " = ''\n";
$result .= "PieformManager.connect('onload', null, function() {\n";
$result .= " jQuery(function($) { \n";
$result .= " if (initjscolor === true) { \n";
$result .= " // rewire up the picker to show up\n";
$result .= " var jsc = new jscolor('" . $name . "'); \n";
$result .= " } \n";
$result .= " // only after initial page load\n";
$result .= " initjscolor = true; \n";
$result .= " jsc" . $name . " = new jscolor('" . $name . "'); \n";
$result .= " }); \n";
$result .= "});</script>";
$results = array(
......
......@@ -579,10 +579,13 @@ class Skin {
public static function get_css_font_family_from_font_name($font, $type='text') {
if ($font === '') {
global $THEME;
$font = Skin::get_all_theme_fonts($type)[$THEME->basename];
$fonts = Skin::get_all_theme_fonts($type);
$fontname = isset($fonts[$THEME->basename]) ? $fonts[$THEME->basename] : '';
}
$fontdata = get_record('skin_fonts', 'name', $font);
if (!$fontdata) {
return '';
}
return $fontdata->fontstack . ', ' . $fontdata->genericfont;
}
......@@ -709,7 +712,9 @@ class Skin {
$theme = '';
if ($fontname === '') {
global $THEME;
$fontname = Skin::get_all_theme_fonts($type)[$THEME->basename];
$fonts = Skin::get_all_theme_fonts($type);
$fontname = isset($fonts[$THEME->basename]) ? $fonts[$THEME->basename] : '';
}
$fontdata = get_record('skin_fonts', 'name', $fontname);
if (!$fontdata) {
......@@ -942,15 +947,9 @@ class Skin {
imagealphablending($img, true);
imagesavealpha($img, true);
if ($skin['body_background_color'] != 'transparent') {
list($r, $g, $b) = self::get_rgb_from_hex($skin['body_background_color']);
$bodybackgroundcolor = imagecolorallocate($img, $r, $g, $b);
imagefill($img, 0, 0, $bodybackgroundcolor);
}
else {
$transparentcolor = imagecolorallocatealpha($img, 255, 255, 255, 127);
imagefill($img, 0, 0, $transparentcolor);
}
list($r, $g, $b) = self::get_rgb_from_hex($skin['body_background_color']);
$bodybackgroundcolor = imagecolorallocate($img, $r, $g, $b);
imagefill($img, 0, 0, $bodybackgroundcolor);
// ========== BODY BACKGROUND IMAGE ==========
if (!empty($skin['body_background_image'])) {
......
......@@ -135,6 +135,9 @@ $elements['viewskin'] = array(
),
);
// Use the theme default or default to theme 'Raw'
$themeheaderbgcolor = isset($THEME->themeheaderbgcolor) ? $THEME->themeheaderbgcolor : '#F7F7F7'; // $pageheader-bg
// Page
$elements['skinbg'] = array(
'type' => 'fieldset',
......@@ -145,10 +148,10 @@ $elements['skinbg'] = array(
'type' => 'color',
'title' => get_string('headerbackgroundcolor', 'skin'),
'description' => get_string('headerbackgroundcolordescription', 'skin'),
'defaultvalue' => (!empty($viewskin['header_background_color']) ? $viewskin['header_background_color'] : '#FFFFFF'),
'defaultvalue' => (!empty($viewskin['header_background_color']) ? $viewskin['header_background_color'] : $themeheaderbgcolor),
'size' => 7,
'options' => array(
'transparent' => true,
'themedefault' => $themeheaderbgcolor,
),
),
'header_background_image' => array(
......@@ -183,7 +186,7 @@ $elements['skinbg'] = array(
'defaultvalue' => (!empty($viewskin['body_background_color']) ? $viewskin['body_background_color'] : '#FFFFFF'),
'size' => 7,
'options' => array(
'transparent' => true,
'themedefault' => '#FFFFFF',
),
)
)
......@@ -258,6 +261,22 @@ $fontoptions = Skin::get_textonly_font_options();
$headerfontoptions = $themefontoption + $headerfontoptions;
$fontoptions = $themefontoption + $fontoptions;
// Set the 'Custom' theme default variables
if ($THEME->basename == 'custom') {
$themeheadingcolor = get_custom_theme_field('headings');
$themelinkcolor = get_custom_theme_field('link');
}
// Set the theme default variables, default to theme 'Raw'
if (!isset($themeheadingcolor)) {
$themeheadingcolor = isset($THEME->themeheadingcolor) ? $THEME->themeheadingcolor : '#333333'; // $view_text_heading_color
}
if (!isset($themelinkcolor)) {
$themelinkcolor = isset($THEME->themelinkcolor) ? $THEME->themelinkcolor : '#556d32'; // $view_link_normal_color
}
$themetextcolor = isset($THEME->themetextcolor) ? $THEME->themetextcolor : '#333333'; // $view_text_font_color
$themeemphasizedtextcolor = isset($THEME->themeemphasizedtextcolor) ? $THEME->themeemphasizedtextcolor : '#333333'; // $view_text_emphasized_color
$themefocusedlinkcolor = isset($THEME->themefocusedlinkcolor) ? $THEME->themefocusedlinkcolor : '#475c2a'; // $view_link_hover_color
// Text
$elements['viewcontent'] = array(
'type' => 'fieldset',
......@@ -275,10 +294,10 @@ $elements['viewcontent'] = array(
'type' => 'color',
'title' => get_string('headingcolor', 'skin'),
'description' => get_string('headingcolordescription', 'skin'),
'defaultvalue' => (!empty($viewskin['view_text_heading_color']) ? $viewskin['view_text_heading_color'] : '#000000'),
'defaultvalue' => (!empty($viewskin['view_text_heading_color']) ? $viewskin['view_text_heading_color'] : $themeheadingcolor),
'size' => 7,
'options' => array(
'transparent' => true,
'themedefault' => $themeheadingcolor,
),
),
'view_text_font_family' => array(
......@@ -307,29 +326,29 @@ $elements['viewcontent'] = array(
'type' => 'color',
'title' => get_string('textcolor', 'skin'),
'description' => get_string('textcolordescription', 'skin'),
'defaultvalue' => (!empty($viewskin['view_text_font_color']) ? $viewskin['view_text_font_color'] : '#000000'),
'defaultvalue' => (!empty($viewskin['view_text_font_color']) ? $viewskin['view_text_font_color'] : $themetextcolor),
'size' => 7,
'options' => array(
'transparent' => true,
'themedefault' => $themetextcolor,
),
),
'view_text_emphasized_color' => array(
'type' => 'color',
'title' => get_string('emphasizedcolor', 'skin'),
'description' => get_string('emphasizedcolordescription', 'skin'),
'defaultvalue' => (!empty($viewskin['view_text_emphasized_color']) ? $viewskin['view_text_emphasized_color'] : '#000000'),
'defaultvalue' => (!empty($viewskin['view_text_emphasized_color']) ? $viewskin['view_text_emphasized_color'] : $themeemphasizedtextcolor),
'size' => 7,
'options' => array(
'transparent' => true,
'themedefault' => $themeemphasizedtextcolor,
),
),
'view_link_normal_color' => array(
'type' => 'color',
'title' => get_string('normallinkcolor', 'skin'),
'defaultvalue' => (!empty($viewskin['view_link_normal_color']) ? $viewskin['view_link_normal_color'] : '#0000EE'),
'defaultvalue' => (!empty($viewskin['view_link_normal_color']) ? $viewskin['view_link_normal_color'] : $themelinkcolor),
'size' => 7,
'options' => array(
'transparent' => true,
'themedefault' => $themelinkcolor,
),
),
'view_link_normal_underline' => array(
......@@ -340,10 +359,10 @@ $elements['viewcontent'] = array(
'view_link_hover_color' => array(
'type' => 'color',
'title' => get_string('hoverlinkcolor', 'skin'),
'defaultvalue' => (!empty($viewskin['view_link_hover_color']) ? $viewskin['view_link_hover_color'] : '#EE0000'),
'defaultvalue' => (!empty($viewskin['view_link_hover_color']) ? $viewskin['view_link_hover_color'] : $themefocusedlinkcolor),
'size' => 7,
'options' => array(
'transparent' => true,
'themedefault' => $themefocusedlinkcolor,
),
),
'view_link_hover_underline' => array(
......@@ -425,6 +444,18 @@ $smarty->assign('designskinform', $designskinform);
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->display('skin/design.tpl');
function get_custom_theme_field($field) {
global $USER;
$institutions = $USER->get('institutions');
$theme_var = get_field_sql(
"SELECT sp.value FROM style_property sp JOIN institution i ON i.style = sp.style AND sp.field = ?
WHERE i.name IN ('" . join("','", array_keys($institutions)) . "')
ORDER BY i.name
LIMIT 1", array($field)
);
return $theme_var;
}
function designskinform_validate(Pieform $form, $values) {
global $USER;
......
......@@ -34,11 +34,6 @@ if (!$skinobj->can_view()) {
throw new AccessDeniedException();
}
$skin->viewskin = unserialize($skin->viewskin);
foreach ($skin->viewskin as $key => $option) {
if ($option === 'transparent') {
$skin->viewskin[$key] = '';
}
}
$smarty = smarty();
// Font Notice
......
......@@ -19,6 +19,12 @@ $theme->parent = 'raw';
/* If we are using normal CSS, this should be false. If we are using SASS, it should be true. */
$theme->overrideparentcss = true;
$theme->themeheadingcolor = '#545B5D'; // $view_text_heading_color
$theme->themetextcolor = '#545B5D'; // $view_text_font_color
$theme->themelinkcolor = '#1f6c88;'; // $view_link_normal_color
$theme->themeemphasizedtextcolor = '#545B5D'; // $view_text_emphasized_color
$theme->themefocusedlinkcolor = '#1d6781'; // $view_link_hover_color
/**
* The following themeconfig options are available. If you make new themeconfig
* options please add them here and explain what they do.
......
......@@ -17,6 +17,10 @@ $theme->formrenderer = 'div';
/* Currently Ocean cannot be a parent theme for subtheme */
$theme->parent = 'raw';
$theme->themelinkcolor = '#20738F'; // $view_link_normal_color
$theme->themefocusedlinkcolor = '#3FAFD4'; // $view_link_hover_color
/* This theme includes all css via sass, so we don't need raw's css. */
$theme->overrideparentcss = true;
......
......@@ -18,6 +18,10 @@ $theme->parent = 'raw';
/* This theme includes all css via sass, so we don't need raw's css. */
$theme->overrideparentcss = true;
$theme->themelinkcolor = '#0162a7'; // $view_link_normal_color
$theme->themefocusedlinkcolor = '#01528c'; // $view_link_hover_color
/**
* The following themeconfig options are available. If you make new themeconfig
* options please add them here and explain what they do.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment