From bcc9e910c514b2c8d73d488cc1e3329796022436 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 23 Apr 2021 14:51:10 +0200 Subject: [PATCH] Replace custom HTML with functions to parse HTML elements Fix UI elements --- assets/css/app.scss | 8 +++ public/main/dropbox/index.php | 56 +++++++++---------- .../main/gradebook/lib/be/category.class.php | 2 +- public/main/group/group.php | 5 +- public/main/group/group_category.php | 8 ++- public/main/group/settings.php | 4 +- public/main/inc/lib/display.lib.php | 14 ++--- .../Element/DateTimeRangePicker.php | 50 ++++++++--------- public/main/inc/lib/groupmanager.lib.php | 35 +++++------- .../inc/lib/pear/HTML/QuickForm/checkbox.php | 4 +- .../inc/lib/pear/HTML/QuickForm/radio.php | 4 +- public/main/session/session_list.php | 4 +- public/main/survey/create_new_survey.php | 15 +++-- public/main/survey/survey.php | 29 +++++----- public/main/work/work.lib.php | 22 ++++++-- .../views/Admin/Settings/menu.html.twig | 4 +- .../views/Course/settings_menu.html.twig | 2 +- 17 files changed, 135 insertions(+), 131 deletions(-) diff --git a/assets/css/app.scss b/assets/css/app.scss index 58f6a63f7d..3d35acb5b8 100644 --- a/assets/css/app.scss +++ b/assets/css/app.scss @@ -134,6 +134,14 @@ border: 0; } + .list-group { + @apply flex flex-col mr-4; + } + + .list-group-item { + @apply flex flex-row justify-start gap-2 border rounded-sm px-3 py-3; + } + @import "scss/index.scss"; } diff --git a/public/main/dropbox/index.php b/public/main/dropbox/index.php index e087bdadf4..fb8a74efc8 100644 --- a/public/main/dropbox/index.php +++ b/public/main/dropbox/index.php @@ -231,47 +231,47 @@ if ('add' != $action) { } // ACTIONS - if ('received' == $view || !$showSentReceivedTabs) { + if ('received' === $view || !$showSentReceivedTabs) { // This is for the categories if (isset($viewReceivedCategory) && '' != $viewReceivedCategory) { $view_dropbox_category_received = $viewReceivedCategory; } else { $view_dropbox_category_received = 0; } - /* Menu Received */ + /* Menu Received */ + $actions = ''; if (0 == api_get_session_id()) { - echo '
'; if (0 != $view_dropbox_category_received && api_is_allowed_to_session_edit(false, true)) { - echo ''. + $actions .= ''. Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('root'), '', ICON_SIZE_MEDIUM). ""; - echo get_lang('Category').': '.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).' '; + $actions .= get_lang('Category').': '.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).' '; $movelist[0] = 'Root'; // move_received selectbox content } else { - echo ''. + $actions .= ''. Display::return_icon('new_folder.png', get_lang('Add a new folder'), '', ICON_SIZE_MEDIUM).''; } - echo '
'; + echo Display::toolbarAction('dropbox', [$actions]); } else { if (api_is_allowed_to_session_edit(false, true)) { - echo '
'; if (0 != $view_dropbox_category_received && api_is_allowed_to_session_edit(false, true)) { - echo ''. + $actions .= ''. Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('root'), '', ICON_SIZE_MEDIUM).""; - echo get_lang('Category').': '.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).' '; + $actions .= get_lang('Category').': '.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).' '; $movelist[0] = 'Root'; // move_received selectbox content } else { - echo ''. + $actions .= ''. Display::return_icon('new_folder.png', get_lang('Add a new folder'), '', ICON_SIZE_MEDIUM). ''; } - echo '
'; + echo Display::toolbarAction('dropbox', [$actions]); } } } - if (!$view || 'sent' == $view || !$showSentReceivedTabs) { + $actions = ''; + if (!$view || 'sent' === $view || !$showSentReceivedTabs) { // This is for the categories if (isset($viewSentCategory) && '' != $viewSentCategory) { $view_dropbox_category_sent = $viewSentCategory; @@ -281,40 +281,38 @@ if ('add' != $action) { /* Menu Sent */ if (0 == api_get_session_id()) { - echo '
'; if (empty($viewSentCategory)) { - echo "". + $actions .= "". Display::return_icon('upload_file.png', get_lang('Share a new file'), '', ICON_SIZE_MEDIUM). ""; } if (0 != $view_dropbox_category_sent) { - echo ''. + $actions .= ''. Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('root'), '', ICON_SIZE_MEDIUM). ""; - echo get_lang('Category').': '.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).' '; + $actions .= get_lang('Category').': '.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).' '; } else { - echo "". + $actions .= "". Display::return_icon('new_folder.png', get_lang('Add a new folder'), '', ICON_SIZE_MEDIUM)."\n"; } - echo '
'; + echo Display::toolbarAction('dropbox', [$actions]); } else { if (api_is_allowed_to_session_edit(false, true)) { - echo '
'; if (empty($viewSentCategory)) { - echo "". + $actions .= "". Display::return_icon('upload_file.png', get_lang('Share a new file'), '', ICON_SIZE_MEDIUM). ""; } if (0 != $view_dropbox_category_sent) { - echo get_lang('You are in folder').': '.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).' '; - echo ''. + $actions .= get_lang('You are in folder').': '.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).' '; + $actions .= ''. Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('root'), '', ICON_SIZE_MEDIUM). ""; } else { - echo "". + $actions .= "". Display::return_icon('new_folder.png', get_lang('Add a new folder'), '', ICON_SIZE_MEDIUM)."\n"; } - echo '
'; + echo Display::toolbarAction('dropbox', [$actions]); } } } @@ -339,7 +337,7 @@ if ('add' != $action) { id == $_GET['id']) { $action_icons .= ""; // Ending the normal row of the sortable table $url = api_get_path(WEB_CODE_PATH).'dropbox/index.php?"'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params; - $action_icons .= " + $action_icons .= " ". feedback($dropbox_file->feedback2, $url). @@ -628,10 +626,10 @@ if ('add' != $action) { $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').' '. Display::return_icon('discuss.png', get_lang('Comment'), '', ICON_SIZE_SMALL). - ' + ' '. Display::return_icon('upload_file.png', get_lang('Update'), '', ICON_SIZE_SMALL). - ' + ' '. Display::return_icon('move.png', get_lang('Move'), '', ICON_SIZE_SMALL).' diff --git a/public/main/gradebook/lib/be/category.class.php b/public/main/gradebook/lib/be/category.class.php index 2f7b7964d8..980a07d98c 100644 --- a/public/main/gradebook/lib/be/category.class.php +++ b/public/main/gradebook/lib/be/category.class.php @@ -559,7 +559,7 @@ class Category implements GradebookItem $category->setUser(api_get_user_entity($this->user_id)); $category->setCourse($course); $category->setParent($parent); - $category->setWeight($this->weight); + $category->setWeight(api_float_val($this->weight)); $category->setVisible($this->visible ? true : false); $category->setCertifMinScore($this->certificate_min_score); $category->setSession(api_get_session_entity($this->session_id)); diff --git a/public/main/group/group.php b/public/main/group/group.php index 109b8e9249..1da6e9fbd5 100644 --- a/public/main/group/group.php +++ b/public/main/group/group.php @@ -286,13 +286,14 @@ if ('true' === api_get_setting('allow_group_categories')) { } } - echo Display::page_header( - Security::remove_XSS($category['title'].' '.$label.' ').$actions, + $header = Display::page_header( + Security::remove_XSS($category['title'].' '.$label.' '), null, 'h4', false ); + echo Display::toolbarAction('category_'.$categoryId, [$header.$actions]); echo $category['description']; echo $groupToShow; } diff --git a/public/main/group/group_category.php b/public/main/group/group_category.php index 14e8c2228a..0a32178201 100644 --- a/public/main/group/group_category.php +++ b/public/main/group/group_category.php @@ -166,9 +166,13 @@ $group = [ 'self_reg_allowed', get_lang('Registration'), get_lang('Learners are allowed to self-register in groups'), - 1 ), - $form->createElement('checkbox', 'self_unreg_allowed', null, get_lang('Learners are allowed to unregister themselves from groups'), 1), + $form->createElement( + 'checkbox', + 'self_unreg_allowed', + null, + get_lang('Learners are allowed to unregister themselves from groups') + ), ]; $form->addGroup( $group, diff --git a/public/main/group/settings.php b/public/main/group/settings.php index 20a1e3ef81..1680b28cf8 100644 --- a/public/main/group/settings.php +++ b/public/main/group/settings.php @@ -111,15 +111,13 @@ $group = [ 'checkbox', 'self_registration_allowed', get_lang('Registration'), - get_lang('Learners are allowed to self-register in groups'), - 1 + get_lang('Learners are allowed to self-register in groups') ), $form->createElement( 'checkbox', 'self_unregistration_allowed', null, get_lang('Learners are allowed to unregister themselves from groups'), - 1 ), ]; $form->addGroup( diff --git a/public/main/inc/lib/display.lib.php b/public/main/inc/lib/display.lib.php index def75d9583..93fd7c9e98 100644 --- a/public/main/inc/lib/display.lib.php +++ b/public/main/inc/lib/display.lib.php @@ -1150,14 +1150,12 @@ class Display $attributes['id'] = $id; $attributes['class'] = 'tab_wrapper'; - $html = self::tag( + return self::tag( 'div', $ul. self::tag('div', $divs, ['class' => 'tab-content']), $attributes ); - - return $html; } /** @@ -1170,7 +1168,7 @@ class Display { $id = uniqid('tabs_'); $i = 1; - $lis = null; + $list = ''; foreach ($headers as $item) { $class = null; if ($i == $selected) { @@ -1185,15 +1183,11 @@ class Display 'class' => 'nav-link '.$class, ] ); - $lis .= self::tag('li', $item, ['class' => 'nav-item']); + $list .= $item; $i++; } - return self::tag( - 'ul', - $lis, - ['class' => 'nav nav-tabs'] - ); + return self::toolbarAction($id, [$list]); } /** diff --git a/public/main/inc/lib/formvalidator/Element/DateTimeRangePicker.php b/public/main/inc/lib/formvalidator/Element/DateTimeRangePicker.php index 3847478fa1..430df7ad8c 100644 --- a/public/main/inc/lib/formvalidator/Element/DateTimeRangePicker.php +++ b/public/main/inc/lib/formvalidator/Element/DateTimeRangePicker.php @@ -1,4 +1,5 @@ '.sprintf(get_lang('Reset %s'), $this->_label).' - - + + '.$this->getElementJS(); } - /** - * @param string $layout - * - * @return string - */ - public function getTemplate($layout) + public function getTemplate(string $layout): string { $size = $this->calculateSize(); $id = $this->getAttribute('id'); @@ -91,31 +87,31 @@ class DateTimeRangePicker extends DateRangePicker {label_3} - - + +
-
-
-

- +

+
+

+ '.get_lang('To').'

-
+
-
- +
+ '; break; case FormValidator::LAYOUT_BOX_NO_LABEL: return '
- + {icon} {element}
'; @@ -182,13 +178,13 @@ class DateTimeRangePicker extends DateRangePicker $endTime = $dates['end_time']; } - $js .= ""; diff --git a/public/main/inc/lib/groupmanager.lib.php b/public/main/inc/lib/groupmanager.lib.php index 80c6f3ebf3..fb461a98b3 100644 --- a/public/main/inc/lib/groupmanager.lib.php +++ b/public/main/inc/lib/groupmanager.lib.php @@ -2755,27 +2755,22 @@ class GroupManager } $url = api_get_path(WEB_CODE_PATH).'group/%s?'.api_get_cidreq(); - - echo ' - '; + ', + ]; + + echo Display::toolbarAction('group', $items); } public static function groupOverview($group, $url) diff --git a/public/main/inc/lib/pear/HTML/QuickForm/checkbox.php b/public/main/inc/lib/pear/HTML/QuickForm/checkbox.php index 4fcb7654b9..1f10ab1e9d 100644 --- a/public/main/inc/lib/pear/HTML/QuickForm/checkbox.php +++ b/public/main/inc/lib/pear/HTML/QuickForm/checkbox.php @@ -33,7 +33,7 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input /** * Class constructor. * - * @param string $elementName (optional)Input field name attribute + * @param string $elementName Input field name attribute * @param string $elementLabel (optional)Input field value * @param string $text (optional)Checkbox display text * @param mixed $attributes (optional)Either a typical HTML attribute string @@ -47,7 +47,7 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input $elementName = null, $elementLabel = null, $text = '', - $attributes = null + ?array $attributes = [] ) { $this->labelClass = isset($attributes['label-class']) ? $attributes['label-class'] : ''; $this->checkboxClass = isset($attributes['checkbox-class']) ? $attributes['checkbox-class'] : 'checkbox'; diff --git a/public/main/inc/lib/pear/HTML/QuickForm/radio.php b/public/main/inc/lib/pear/HTML/QuickForm/radio.php index 6d8cec44b6..fae908a986 100644 --- a/public/main/inc/lib/pear/HTML/QuickForm/radio.php +++ b/public/main/inc/lib/pear/HTML/QuickForm/radio.php @@ -38,8 +38,6 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input public $radioClass; /** - * Class constructor - * * @param string Input field name attribute * @param mixed Label(s) for a field * @param string Text to display near the radio @@ -54,7 +52,7 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input $elementLabel = null, $text = null, $value = null, - $attributes = [] + ?array $attributes = [] ) { $this->labelClass = $attributes['label-class'] ?? ''; $this->radioClass = $attributes['radio-class'] ?? 'form-check'; diff --git a/public/main/session/session_list.php b/public/main/session/session_list.php index a0cd96fdba..06f3750ce8 100644 --- a/public/main/session/session_list.php +++ b/public/main/session/session_list.php @@ -14,8 +14,8 @@ SessionManager::protectSession(null, false); // Add the JS needed to use the jqgrid $htmlHeadXtra[] = api_get_jqgrid_js(); -$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; -$idChecked = isset($_REQUEST['idChecked']) ? $_REQUEST['idChecked'] : null; +$action = $_REQUEST['action'] ?? null; +$idChecked = $_REQUEST['idChecked'] ?? null; $listType = isset($_REQUEST['list_type']) ? Security::remove_XSS($_REQUEST['list_type']) : SessionManager::getDefaultSessionTab(); switch ($action) { diff --git a/public/main/survey/create_new_survey.php b/public/main/survey/create_new_survey.php index 39ca4ba4df..46f94c23a8 100644 --- a/public/main/survey/create_new_survey.php +++ b/public/main/survey/create_new_survey.php @@ -213,19 +213,22 @@ $form->addElement('html', '
'javascript: if (this.checked) { document.getElementById(\'gradebook_options\').style.display = \'block\'; } else { document.getElementById(\'gradebook_options\').style.display = \'none\'; }'], ); $form->addHtml(''); - $form->addElement('checkbox', 'add_to_calendar', null, get_lang('Add to calendar')); - $form->addElement('select', 'allow_text_assignment', get_lang('Document type'), getUploadDocumentType()); + $form->addCheckBox('add_to_calendar', null, get_lang('Add to calendar')); + $form->addSelect('allow_text_assignment', get_lang('Document type'), getUploadDocumentType()); // Extra fields $extraField = new ExtraField('work'); diff --git a/src/CoreBundle/Resources/views/Admin/Settings/menu.html.twig b/src/CoreBundle/Resources/views/Admin/Settings/menu.html.twig index d6de47fabc..30e0c78c34 100644 --- a/src/CoreBundle/Resources/views/Admin/Settings/menu.html.twig +++ b/src/CoreBundle/Resources/views/Admin/Settings/menu.html.twig @@ -1,9 +1,9 @@ -