Beispiel #1
0
 /**
  * see html::calendar()
  */
 public static function calendar($options = [])
 {
     // include js & css files
     if (empty($options['readonly'])) {
         layout::add_js('/numbers/media_submodules/numbers_frontend_components_calendar_numbers_media_js_base.js');
         layout::add_css('/numbers/media_submodules/numbers_frontend_components_calendar_numbers_media_css_base.css');
     }
     // font awesome icons
     library::add('fontawesome');
     // widget parameters
     $type = $options['calendar_type'] ?? $options['type'] ?? 'date';
     $widget_options = ['id' => $options['id'], 'type' => $type, 'format' => $options['calendar_format'] ?? format::get_date_format($type), 'date_week_start_day' => $options['calendar_date_week_start_day'] ?? 1, 'date_disable_week_days' => $options['calendar_date_disable_week_days'] ?? null, 'master_id' => $options['calendar_master_id'] ?? null, 'slave_id' => $options['calendar_slave_id'] ?? null];
     $options['type'] = 'text';
     // determine input size
     $placeholder = format::get_date_placeholder($widget_options['format']);
     $options['size'] = strlen($placeholder);
     // set placeholder
     if (!empty($options['placeholder']) && $options['placeholder'] == 'format::get_date_placeholder') {
         $options['placeholder'] = $placeholder;
         $options['title'] = ($options['title'] ?? '') . ' (' . $placeholder . ')';
     }
     if (isset($options['calendar_icon']) && ($options['calendar_icon'] == 'left' || $options['calendar_icon'] == 'right')) {
         $position = $options['calendar_icon'];
         if (i18n::rtl()) {
             if ($position == 'left') {
                 $position = 'right';
             } else {
                 $position = 'left';
             }
         }
         $icon_type = $type == 'time' ? 'clock-o' : 'calendar';
         unset($options['calendar_icon']);
         if (empty($options['readonly'])) {
             $icon_onclick = 'numbers_calendar_var_' . $options['id'] . '.show();';
         } else {
             $icon_onclick = null;
         }
         $icon_value = html::span(['onclick' => $icon_onclick, 'class' => 'numbers_calendar_icon numbers_prevent_selection', 'value' => html::icon(['type' => $icon_type])]);
         $result = html::input_group(['value' => html::input($options), $position => $icon_value, 'dir' => 'ltr']);
         $div_id = $options['id'] . '_div_holder';
         $result .= html::div(['id' => $div_id, 'class' => 'numbers_calendar_div_holder']);
         $widget_options['holder_div_id'] = $div_id;
     } else {
         $result = html::input($options);
     }
     // we do not render a widget if readonly
     if (empty($options['readonly'])) {
         layout::onload('numbers_calendar(' . json_encode($widget_options) . ');');
     }
     return $result;
 }
Beispiel #2
0
 /**
  * @see html::grid()
  */
 public static function grid($options = [])
 {
     $rtl = i18n::rtl();
     $grid_columns = application::get('flag.numbers.framework.html.options.grid_columns') ?? 12;
     $rows = isset($options['options']) ? $options['options'] : [];
     unset($options['options']);
     $result = '';
     foreach ($rows as $k => $v) {
         // we need to determine field sizes
         $field_sizes = [];
         foreach ($v as $k2 => $v2) {
             foreach ($v2 as $k3 => $v3) {
                 $field_sizes[] = $v3['options']['percent'] ?? null;
             }
         }
         $field_new_sizes = html::percentage_to_grid_columns($field_sizes);
         // count number of fields
         $count_fields = count($v);
         //$count_class = html::number_to_word($count_fields);
         // find all row classes
         $row_class = '';
         foreach ($v as $k2 => $v2) {
             foreach ($v2 as $k3 => $v3) {
                 if (!empty($v3['row_class'])) {
                     $row_class .= ' ' . $v3['row_class'];
                 }
             }
         }
         $result .= '<div class="row' . $row_class . '">';
         // we need to determine if we have label in the row
         $flag_have_label = false;
         foreach ($v as $k2 => $v2) {
             foreach ($v2 as $k3 => $v3) {
                 if (($v3['label'] ?? '') . '' != '') {
                     $flag_have_label = true;
                 }
             }
         }
         // we need to fill up empty columns if rtl
         if ($rtl) {
             $index = 0;
             $current_grid_columns = 0;
             foreach ($v as $k2 => $v2) {
                 foreach ($v2 as $k3 => $v3) {
                     // if we are mannually set field sizes we skip
                     if (!empty($v3['options']['field_size'])) {
                         $current_grid_columns = 12;
                         break;
                     }
                     $current_grid_columns += $field_new_sizes['data'][$index];
                     $v[$k2][$k3]['options']['field_size'] = 'col-sm-' . $field_new_sizes['data'][$index];
                     // a must
                     $index++;
                 }
             }
             if ($current_grid_columns != $grid_columns) {
                 $v['__empty_column_fill__']['__empty_column_fill__'] = ['value' => ' '];
                 $field_new_sizes['data'][$index] = $grid_columns - $current_grid_columns;
             }
             $v = array_reverse($v, true);
         }
         // loop though each field and render it
         $index = 0;
         foreach ($v as $k2 => $v2) {
             $flag_first_field = true;
             if ($rtl) {
                 $v2 = array_reverse($v2, true);
             }
             foreach ($v2 as $k3 => $v3) {
                 $error_class = '';
                 if (!empty($v3['error']['type'])) {
                     if ($v3['error']['type'] == 'danger') {
                         $v3['error']['type'] = 'error';
                     }
                     $error_class = 'has-' . $v3['error']['type'];
                 }
                 // style
                 $style = '';
                 if (isset($v3['options']['style'])) {
                     $style = ' style="' . $v3['options']['style'] . '"';
                 }
                 $field_size = $v3['options']['field_size'] ?? 'col-sm-' . $field_new_sizes['data'][$index];
                 $class = $v3['class'] ?? '';
                 $result .= '<div class="' . $field_size . ' form-group ' . $error_class . ' ' . $class . '"' . $style . '>';
                 // label
                 if ($flag_first_field) {
                     if (($v3['label'] ?? '') . '' != '') {
                         $result .= $v3['label'];
                     } else {
                         if ($flag_have_label) {
                             $result .= '<label>&nbsp;</label>';
                         }
                     }
                     $flag_first_field = false;
                 } else {
                     if ($flag_have_label) {
                         $result .= '<label>&nbsp;</label>';
                     }
                 }
                 $result .= $v3['value'] ?? '';
                 // error messages
                 if (!empty($v3['error']['message'])) {
                     $result .= $v3['error']['message'];
                 }
                 // description after error message
                 if (!empty($v3['description'])) {
                     $result .= html::text(['type' => 'muted', 'value' => $v3['description']]);
                 }
                 $result .= '</div>';
                 $index++;
             }
         }
         $result .= '</div>';
     }
     return '<div class="container-fluid">' . $result . '</div>';
 }
Beispiel #3
0
 /**
  * @see html::input()
  */
 public static function input($options = [])
 {
     $options['type'] = $options['input_type'] ?? $options['type'] ?? 'text';
     if (!empty($options['checked'])) {
         $options['checked'] = 'checked';
     } else {
         unset($options['checked']);
     }
     if (!empty($options['multiple'])) {
         $options['multiple'] = 'multiple';
     } else {
         unset($options['multiple']);
     }
     if (!empty($options['readonly'])) {
         $options['readonly'] = 'readonly';
     } else {
         unset($options['readonly']);
     }
     if (!empty($options['disabled'])) {
         $options['disabled'] = 'disabled';
     } else {
         unset($options['disabled']);
     }
     if (!isset($options['autocomplete'])) {
         $options['autocomplete'] = 'off';
     }
     if (!empty($options['autofocus'])) {
         $options['autofocus'] = 'autofocus';
     } else {
         unset($options['autofocus']);
     }
     // rtl
     $rtl = i18n::rtl(false);
     if (i18n::rtl()) {
         if (isset($options['style'])) {
             $options['style'] = str_replace(['text-align:right;', 'text-align: right;'], 'text-align:left;', $options['style']);
         }
         // let browser decide the direction based on content
         $rtl = ' dir="auto" ';
     }
     // generate html
     $options['value'] = isset($options['value']) ? htmlspecialchars($options['value']) : '';
     return '<input ' . self::generate_attributes($options, 'input') . $rtl . ' />';
 }