private function _init_structure($type, $content, $user_options) { $this->_structure = parent::array_to_object($this->_structure); $this->_structure->type = $type; $this->_structure->content = $content; $this->_structure->options = parent::set_array_prop_def($this->_options_map, $user_options); }
private function _init_structure($panels, $user_options = array()) { $this->_structure = parent::array_to_object($this->_structure); $this->_structure->options = parent::set_array_prop_def($this->_options_map, $user_options); $this->_structure->id = parent::create_id(true); $this->_structure->panel = $panels; }
private function _init_structure($data, $user_options, $widget_title) { $this->_structure = parent::array_to_object($this->_structure); $this->_structure->data = $data; $this->_structure->options = parent::set_array_prop_def($this->_options_map, $user_options); $uid = parent::create_id(true); $this->_structure->id = $uid; // set the id as default id $this->_uid = $uid; $ui = new parent(); $this->_structure->widget = $ui->create_widget(); $this->_structure->widget->header('icon', 'fa-table')->header('title', $widget_title)->body("class", "no-padding")->body("editbox", '<input class="form-control" type="text"> <span class="note"><i class="fa fa-check text-success"></i> Change title to update and save instantly!</span>'); if (!$this->_structure->data) { $col_list = array("No Data"); } else { $col_list = array_keys(is_object($data[0]) ? get_object_vars($data[0]) : $data[0]); } $cols = array_combine($col_list, $col_list); $cells = array_fill_keys($col_list, array()); $hide = array_fill_keys($col_list, false); $this->_cells_map = $cells; $this->_cols_map = $cols; $this->_hide_map = $hide; $this->_structure->col = $cols; $this->_structure->cell = $cells; $this->_structure->hide = $hide; $this->_structure->row = array_fill(1, count($data) + 1, array()); $this->_structure->js = array("properties" => array(), "oTable" => 'oTable_' . $this->_uid, "custom" => ""); }
private function _init_structure($items, $style = 'slide', $user_options = array()) { $this->_structure = parent::array_to_object($this->_structure); $this->_structure->options = parent::set_array_prop_def($this->_options_map, $user_options); $this->_structure->id = parent::create_id(true); $this->_structure->item = $items; $this->_structure->options['style'] = $style; }
private function _init_structure($steps, $user_options = array()) { $this->_structure = parent::array_to_object($this->_structure); $this->_structure->options = parent::set_array_prop_def($this->_options_map, $user_options); $this->_structure->step = $steps; $this->_structure->id = parent::create_id(true); $ui = new parent(); $widget = $ui->create_widget(); $widget->options('editbutton', false)->header('title', '<h2></h2>'); $this->_structure->widget = $widget; }
private function _init_structure($user_options, $user_contents) { $this->_structure = parent::array_to_object($this->_structure); $user_contents_map = array("header" => array(), "body" => "", "color" => ""); $new_user_contents = parent::set_array_prop_def($user_contents_map, $user_contents); $this->_structure->options = parent::set_array_prop_def($this->_options_map, $user_options); $body_structure = array("editbox" => "", "content" => "", "class" => "", "toolbar" => null, "footer" => null); $this->_structure->body = parent::set_array_prop_def($body_structure, $new_user_contents["body"], "content"); $header_structure = array("icon" => null, "class" => "", "title" => "", "toolbar" => array()); $this->_structure->header = parent::set_array_prop_def($header_structure, $new_user_contents["header"], "title"); $this->_structure->color = $new_user_contents["color"]; $this->_structure->id = parent::create_id(true); }
public function print_html($return = false) { $get_property_value = parent::_get_property_value_func(); $that = $this; $structure = $this->_structure; $structure->options = parent::set_array_prop_def($this->_options_map, $structure->options); $tabs = $get_property_value($structure->tab, array('if_closure' => function ($tabs) use($that) { return SmartUI::run_callback($tabs, array($that)); }, 'if_other' => function ($tabs) { SmartUI::err('SmartUI::Tab::tab requires array'); return null; })); if (!is_array($tabs)) { parent::err("SmartUI::Tab::tab requires array"); return null; } $li_list = array(); $tab_content_list = array(); $has_active = false; foreach ($tabs as $tab_id => $tab_prop) { $tab_structure = array('content' => isset($structure->content[$tab_id]) ? $structure->content[$tab_id] : '', 'title' => isset($structure->title[$tab_id]) ? $structure->title[$tab_id] : '', 'icon' => isset($structure->icon[$tab_id]) ? $structure->icon[$tab_id] : '', 'dropdown' => isset($structure->dropdown[$tab_id]) ? $structure->dropdown[$tab_id] : '', 'position' => isset($structure->position[$tab_id]) ? $structure->position[$tab_id] : '', 'active' => isset($structure->active[$tab_id]) && $structure->active[$tab_id] === true, 'fade' => false); $new_tab_prop = parent::get_clean_structure($tab_structure, $tab_prop, array($that, $tabs, $tab_id), 'title'); foreach ($new_tab_prop as $tab_prop_key => $tab_prop_vaue) { $new_tab_prop_value = $get_property_value($tab_prop_vaue, array('if_closure' => function ($prop_value) use($that, $tabs) { return SmartUI::run_callback($prop_value, array($that, $tabs)); })); $new_tab_prop[$tab_prop_key] = $new_tab_prop_value; } $tab_content_classes = array(); $tab_content_classes[] = 'tab-pane'; $li_classes = array(); $a_classes = array(); $a_attr = array(); if (!$structure->active && !$has_active || $new_tab_prop['active'] === true && !$has_active) { $li_classes[] = 'active'; $tab_content_classes[] = 'in active'; $has_active = true; } $title = $new_tab_prop['title']; $dropdown_html = ''; if ($new_tab_prop['dropdown']) { $dropdown = $new_tab_prop['dropdown']; $li_classes[] = 'dropdown'; $href = 'javascript:void(0);'; $dropdown_html = is_array($dropdown) ? parent::print_dropdown($dropdown, false, true) : $dropdown; $a_classes[] = 'dropdown-toggle'; $a_attr[] = 'data-toggle="dropdown"'; $title .= ' <b class="caret"></b>'; } else { $href = '#' . $tab_id; $a_attr[] = 'data-toggle="tab"'; } if ($new_tab_prop['position']) { $li_classes[] = 'pull-' . $new_tab_prop['position']; } $icon = $new_tab_prop['icon'] ? '<i class="fa ' . $new_tab_prop['icon'] . '"></i> ' : ''; $class = $li_classes ? ' class="' . implode(' ', $li_classes) . '"' : ''; $li_html = '<li' . $class . '>'; $li_html .= '<a href="' . $href . '" ' . ($a_classes ? 'class="' . implode(' ', $a_classes) . '"' : '') . ($a_attr ? ' ' . implode(' ', $a_attr) : '') . '>' . $icon . $title . '</a>'; $li_html .= $dropdown_html; $li_html .= '</li>'; $li_list[] = $li_html; if ($new_tab_prop['fade']) { $tab_content_classes[] = 'fade'; } $tab_content_html = '<div class="' . implode(' ', $tab_content_classes) . '" id="' . $tab_id . '">'; $tab_content_html .= $new_tab_prop['content']; $tab_content_html .= '</div>'; $tab_content_list[] = $tab_content_html; } $ul_classes = array(); $ul_attr = array(); $ul_classes[] = 'nav nav-tabs'; $ul_id = $structure->tabs_id ? 'id="' . $structure->tabs_id . '"' : ''; $ul_attr[] = $ul_id; $content_classes = array(); $content_classes[] = 'tab-content'; if ($structure->content_class) { $content_classes[] = is_array($structure->content_class) ? implode(' ', $structure->content_class) : $structure->content_class; } $content_id = $structure->content_id ? 'id="' . $structure->content_id . '"' : ''; if ($structure->options['padding']) { $content_classes[] = 'padding-' . $structure->options['padding']; } $content_html = '<div class="' . implode(' ', $content_classes) . '" ' . $content_id . '>'; $content_html .= implode('', $tab_content_list); $content_html .= '</div>'; $main_content_html = ''; if ($structure->options['widget']) { $ul_classes[] = $structure->options['pull'] ? 'pull-' . $structure->options['pull'] : 'pull-left'; $ul_html = '<ul class="' . implode(' ', $ul_classes) . '" ' . implode(' ', $ul_attr) . '>'; $ul_html .= implode('', $li_list); $ul_html .= '</ul>'; $widget = $structure->options['widget']; if (!$widget instanceof Widget) { $ui = new parent(); $widget = $ui->create_widget(); } $widget->body('content', $content_html); $widget->options('colorbutton', false)->options('editbutton', false); $widget->header('title', $ul_html); $result = $widget->print_html(true); } else { if ($structure->options['bordered']) { $ul_classes[] = 'bordered'; } if ($structure->options['pull']) { $ul_classes[] = 'tabs-pull-' . $structure->options['pull']; } $ul_html = '<ul class="' . implode(' ', $ul_classes) . '" ' . implode(' ', $ul_attr) . '>'; $ul_html .= implode('', $li_list); $ul_html .= '</ul>'; $container_classes = array(); $container_classes[] = 'tabbable'; switch ($structure->options['position']) { case 'right': case 'left': $container_classes[] = 'tabs-' . $structure->options['position']; $main_content_html = $ul_html . $content_html; break; case 'below': $container_classes[] = 'tabs-' . $structure->options['position']; $main_content_html = $content_html . $ul_html; break; default: $main_content_html = $ul_html . $content_html; break; } $result = '<div class="' . implode(' ', $container_classes) . '">'; $result .= $main_content_html; $result .= '</div>'; } if ($return) { return $result; } else { echo $result; } }
private function parse_nav($nav_item, $is_parent = false) { if (!$nav_item) { return ''; } $nav_items_list = array(); foreach ($nav_item as $name => $nav) { $nav_prop = array('url' => '#', 'url_target' => '', 'icon' => '', 'icon_badge' => '', 'label_htm' => '', 'title' => $name, 'title_append' => '', 'label' => '', 'active' => false, 'sub' => array(), 'attr' => array(), 'class' => array(), 'li_class' => array()); $new_nav_prop = parent::set_array_prop_def($nav_prop, $nav, 'title'); $icon_badge_prop = array('content' => '', 'class' => ''); $icon_badge_prop = parent::set_array_prop_def($icon_badge_prop, $new_nav_prop['icon_badge'], 'content'); $badge = ''; if ($icon_badge_prop['content']) { $badge_class = $icon_badge_prop['class'] ? 'class="' . $icon_badge_prop['class'] . '"' : ''; $badge = '<em ' . $badge_class . '>' . $icon_badge_prop['content'] . '</em>'; } $icon = $new_nav_prop['icon'] ? '<i class="' . SmartUI::$icon_source . ' ' . SmartUI::$icon_source . '-lg ' . SmartUI::$icon_source . '-fw ' . $new_nav_prop['icon'] . '">' . $badge . '</i>' : ''; $title = $new_nav_prop['title']; $title_append = $new_nav_prop['title_append']; $display_title = $title . ' ' . $title_append; $label_htm = $new_nav_prop['label_htm'] ? ' ' . $new_nav_prop['label_htm'] : ''; $display_text = $is_parent ? '<span class="menu-item-parent">' . $display_title . '</span>' : $display_title; $display_text .= $label_htm; $attrs = array_map(function ($attr, $value) { return $attr . '="' . $value . '"'; }, array_keys($new_nav_prop['attr']), $new_nav_prop['attr']); if ($new_nav_prop['class']) { $attrs[] = 'class="' . $new_nav_prop['class'] . '"'; } $nav_htm = '<a href="' . $new_nav_prop['url'] . '" target="' . $new_nav_prop['url_target'] . '" title="' . $title . '" ' . implode(' ', $attrs) . '> ' . $icon . ' ' . $display_text . ' ' . $new_nav_prop['label'] . ' </a>'; $li_classes = array(); if ($new_nav_prop["active"]) { $li_classes[] = 'active'; } if ($new_nav_prop['li_class']) { if (is_string($new_nav_prop['li_class'])) { $li_classes[] = $new_nav_prop['li_class']; } else { if (is_array($new_nav_prop['li_class'])) { $li_classes = array_merge($li_classes, $new_nav_prop['li_class']); } } } $nav_item_structure = array('content' => $nav_htm, 'class' => implode(' ', $li_classes)); if (isset($new_nav_prop['sub'])) { if (is_string($new_nav_prop['sub'])) { $nav_item_structure['subitems'] = array($new_nav_prop['sub']); } else { $nav_item_structure['subitems'] = $this->parse_nav($new_nav_prop['sub']); } } $nav_items_list[] = $nav_item_structure; } return $nav_items_list; }
private static function _get_field_html($name, $field_type = self::FORM_FIELD_INPUT, $properties = array(), $field_html_only = false) { $field_class_map = array(self::FORM_FIELD_INPUT => 'input', self::FORM_FIELD_FILEINPUT => 'input input-file', self::FORM_FIELD_SELECT => 'select', self::FORM_FIELD_SELECT2 => 'select', self::FORM_FIELD_MULTISELECT => 'select select-multiple', self::FORM_FIELD_TEXTAREA => 'textarea', self::FORM_FIELD_CHECKBOX => 'checkbox', self::FORM_FIELD_RADIO => 'radio', self::FORM_FIELD_RATING => 'rating', self::FORM_FIELD_RATINGS => 'rating', self::FORM_FIELD_HIDDEN => '', self::FORM_FIELD_BLANK => ''); $result = ''; $field_html = ''; $result_html = ''; $notes = ''; $label = ''; $attrs = array(); switch ($field_type) { case self::FORM_FIELD_LABEL: $default_prop = array('label' => ''); $new_prop = parent::get_clean_structure($default_prop, $properties, array(), 'label'); $result_html = $new_prop['label']; break; case self::FORM_FIELD_BLANK: $default_prop = array('content' => ''); $new_prop = parent::get_clean_structure($default_prop, $properties, array(), 'content'); $result_html = $new_prop['content']; break; case self::FORM_FIELD_RATINGS: $default_prop = array('items' => array(), 'icon' => SmartUI::$icon_source . '-star'); $new_prop = parent::get_clean_structure($default_prop, $properties, array(), 'max'); if (!is_array($new_prop['items'])) { $new_prop['items'] = array($new_prop['items']); } $items = $new_prop['items']; $rating_html_list = array(); foreach ($items as $item) { $item_prop = array('max' => 5, 'icon' => $new_prop['icon'], 'name' => $name . '-' . SmartUtil::create_id(), 'label' => ''); $new_item_prop = parent::set_array_prop_def($item_prop, $item, 'max'); $field_html = self::_get_field_html($new_item_prop['name'], self::FORM_FIELD_RATING, $new_item_prop, true); $field_html .= $new_item_prop['label'] ? $new_item_prop['label'] : ' '; $result_html = ' <div class="' . $field_class_map[$field_type] . '">'; $result_html .= $field_html; $result_html .= ' </div>'; $rating_html_list[] = $result_html; } $result_html = implode('', $rating_html_list); break; case self::FORM_FIELD_RATING: $default_prop = array('max' => 5, 'icon' => SmartUI::$icon_source . '-star'); $new_prop = parent::get_clean_structure($default_prop, $properties, array(), 'max'); $rating_html_list = array(); for ($i = $new_prop['max']; $i >= 1; $i--) { $rate_id = $name . '-' . $i; $rating_html = self::_get_field_html($name, self::FORM_FIELD_INPUT, array('type' => 'radio', 'id' => $rate_id), true); $rating_html .= '<label for="' . $rate_id . '"><i class="' . SmartUI::$icon_source . ' ' . $new_prop['icon'] . '"></i></label>'; $rating_html_list[] = $rating_html; } $field_html .= implode('', $rating_html_list); if ($field_html_only) { return $field_html; } $result_html .= ' <label class="' . $field_class_map[$field_type] . '">'; $result_html .= $field_html; $result_html .= ' </label>'; break; case self::FORM_FIELD_TEXTAREA: $default_prop = array('rows' => 3, 'attr' => array(), 'class' => array(), 'icon' => '', 'icon_append' => true, 'value' => '', 'id' => '', 'type' => '', 'placeholder' => '', 'disabled' => false, 'wrapper' => 'label'); $new_prop = parent::get_clean_structure($default_prop, $properties, array(), 'placeholder'); $classes = array(); $classes[] = 'custom-scroll'; if ($new_prop['class']) { array_push($classes, $new_prop['class']); } $attrs = array(); $attrs[] = 'class="' . implode(' ', $classes) . '"'; $attrs[] = 'rows="' . $new_prop['rows'] . '"'; $attrs[] = 'name="' . $name . '"'; if ($new_prop['disabled']) { $attrs[] = 'disabled="disabled"'; } if ($new_prop['id']) { $attrs[] = 'id="' . $new_prop['id'] . '"'; } if ($new_prop['placeholder']) { $attrs[] = 'placeholder="' . $new_prop['placeholder'] . '"'; } if ($new_prop['attr']) { $attrs[] = implode(' ', $new_prop['attr']); } if ($new_prop['icon']) { $field_html .= '<i class="icon-' . ($new_prop['icon_append'] ? 'append' : 'prepend') . ' ' . SmartUI::$icon_source . ' ' . $new_prop['icon'] . '"></i>'; } $field_html .= '<textarea ' . implode(' ', $attrs) . '>'; $field_html .= $new_prop['value']; $field_html .= '</textarea>'; $field_class_map[self::FORM_FIELD_TEXTAREA] = 'textarea' . ($new_prop['type'] ? ' textarea-' . $new_prop['type'] : ''); if ($field_html_only) { return $field_html; } $result_html .= ' <' . $new_prop['wrapper'] . ' class="' . $field_class_map[$field_type] . '">'; $result_html .= $field_html; $result_html .= ' </' . $new_prop['wrapper'] . '>'; break; case self::FORM_FIELD_MULTISELECT: if (isset($properties['attr'])) { array_push($properties['attr'], array('multiple="multiple"', 'class="custom-scroll"')); } else { $properties['attr'] = array('multiple="multiple"'); } if (isset($properties['class'])) { array_push($properties['class'], array('custom-scroll')); } else { $properties['class'] = array('custom-scroll'); } $properties['icon'] = ''; $field_html = self::_get_field_html($name, self::FORM_FIELD_SELECT, $properties, true); if ($field_html_only) { return $field_html; } $result_html .= ' <label class="' . $field_class_map[$field_type] . '">'; $result_html .= $field_html; $result_html .= ' </label>'; break; case self::FORM_FIELD_SELECT2: if (!is_array($properties['class'])) { $properties['class'] = array($properties['class']); } array_push($properties['class'], 'select2'); $properties['icon'] = ''; $field_html = self::_get_field_html($name, self::FORM_FIELD_SELECT, $properties, true); if ($field_html_only) { return $field_html; } $result_html .= ' <label class="' . $field_class_map[$field_type] . '">'; $result_html .= $field_html; $result_html .= ' </label>'; break; case self::FORM_FIELD_SELECT: $default_prop = array('data' => array(), 'display' => '', 'value' => '', 'container' => 'select', 'selected' => false, 'id' => '', 'attr' => array(), 'class' => array(), 'icon' => '<i></i>', 'item_attr' => null, 'disabled' => false); $get_property_value = parent::_get_property_value_func(); $new_prop = parent::get_clean_structure($default_prop, $properties, array(), 'data'); $data = $new_prop['data']; if (!is_array($data)) { parent::err('SmartUI::Form "data" is required for "select" field.'); return ''; } if (!$data) { $data = array(array('No Data')); } $data = SmartUtil::object_to_array($data); if (!$new_prop['display']) { $display_key = array_keys($data[0]); $new_prop['display'] = is_array($data[0]) && $display_key ? $display_key[0] : 0; } if (!$new_prop['value']) { $value_key = array_keys($data[0]); $new_prop['value'] = is_array($data[0]) && $value_key ? $value_key[0] : 0; } $option_list = array(); foreach ($data as $row) { $item_attr = ''; if (!is_array($row)) { $row = array($row); } $selected = $row[$new_prop['value']] == $new_prop['selected']; if (isset($new_prop['item_attr'])) { $item_attr = $get_property_value($new_prop['item_attr'], array('if_closure' => function ($item_attr) use($row) { return SmartUtil::run_callback($row); }, 'if_array' => function ($item_attr) use($row) { $attrs = array(); foreach ($item_attr as $attr) { $attrs[] = SmartUtil::replace_col_codes($attr, $row); } return implode(' ', $attrs); }, 'if_other' => function ($item_attr) use($row) { return SmartUtil::replace_col_codes($item_attr, $row); })); } $option_list[] = '<option value="' . $row[$new_prop['value']] . '"' . ($selected ? ' selected' : '') . ($item_attr ? ' ' . $item_attr : '') . '>' . $row[$new_prop['display']] . '</option>'; } $attrs = array(); $attrs[] = 'name="' . $name . '"'; if ($new_prop['disabled']) { $attrs[] = 'disabled="disabled"'; } if ($new_prop['id']) { $attrs[] = 'id="' . $new_prop['id'] . '"'; } if ($new_prop['attr']) { $attrs[] = implode(' ', $new_prop['attr']); } if ($new_prop['class']) { $attrs[] = 'class="' . implode(' ', $new_prop['class']) . '"'; } $field_html = '<' . $new_prop['container'] . ' ' . implode(' ', $attrs) . '>'; $field_html .= implode('', $option_list); $field_html .= '</' . $new_prop['container'] . '>' . $new_prop['icon']; if ($field_html_only) { return $field_html; } $result_html .= ' <label class="' . $field_class_map[$field_type] . '">'; $result_html .= $field_html; $result_html .= ' </label>'; break; case self::FORM_FIELD_FILEINPUT: $file_button = self::_get_field_html($name, self::FORM_FIELD_INPUT, array('type' => 'file', 'attr' => array_merge(array('onchange="this.parentNode.nextSibling.value = this.value"'), isset($properties['attr']) ? $properties['attr'] : array())), true); $field_html = '<span class="button">'; $field_html .= $file_button; $field_html .= 'Browse</span>'; $default_prop = array('icon' => false, 'tooltip' => false, 'attr' => array('readonly'), 'type' => 'text'); if ($properties) { foreach ($properties as $key => $value) { if (!isset($default_prop[$key])) { $default_prop[$key] = $value; } } } $field_html .= self::_get_field_html($name . '-display', self::FORM_FIELD_INPUT, $default_prop, true); if ($field_html_only) { return $field_html; } $result_html .= ' <label class="' . $field_class_map[$field_type] . '">'; $result_html .= $field_html; $result_html .= ' </label>'; break; case self::FORM_FIELD_HIDDEN: $default_prop = array('icon' => false, 'tooltip' => false, 'type' => 'hidden', 'value' => ''); $new_prop = parent::get_clean_structure($default_prop, $properties, array(), 'value'); $field_html .= self::_get_field_html($name, self::FORM_FIELD_INPUT, $new_prop, true); return $field_html; break; case self::FORM_FIELD_INPUT: $default_prop = array('type' => 'text', 'attr' => array(), 'id' => '', 'icon' => '', 'icon_append' => true, 'placeholder' => '', 'value' => '', 'tooltip' => array(), 'disabled' => false, 'autocomplete' => false, 'size' => '', 'class' => array()); $new_prop = parent::get_clean_structure($default_prop, $properties, array(), 'placeholder'); $classes = array(); if ($new_prop['class']) { array_push($classes, $new_prop['class']); } if ($new_prop['size']) { $classes[] = 'input-' . $new_prop['size']; } $attrs = array(); $attrs[] = $classes ? 'class="' . implode(' ', $classes) . '"' : ''; $attrs[] = 'type="' . $new_prop['type'] . '"'; $attrs[] = 'name="' . $name . '"'; if ($new_prop['attr']) { $attrs[] = implode(' ', $new_prop['attr']); } if ($new_prop['id']) { $attrs[] = 'id="' . $new_prop['id'] . '"'; } $attrs[] = 'value="' . $new_prop['value'] . '"'; if ($new_prop['placeholder']) { $attrs[] = 'placeholder="' . $new_prop['placeholder'] . '"'; } if ($new_prop['disabled']) { $attrs[] = 'disabled="disabled"'; } $ac_html = ''; if ($new_prop['autocomplete']) { $ac_prop = array('data' => array(), 'display' => '', 'value' => ''); if (!isset($new_prop['autocomplete']['data'])) { $ac_prop['data'] = $new_prop['autocomplete']; } else { $ac_prop['data'] = $new_prop['autocomplete']['data']; $ac_prop['display'] = isset($new_prop['autocomplete']['display']) ? $new_prop['autocomplete']['display'] : ''; $ac_prop['value'] = isset($new_prop['autocomplete']['value']) ? $new_prop['autocomplete']['value'] : ''; } $list_name = 'list-' . $name . '-' . SmartUtil::create_id(); $ac_html = self::_get_field_html('', self::FORM_FIELD_SELECT, array('container' => 'datalist', 'data' => $ac_prop['data'], 'display' => $ac_prop['display'], 'value' => $ac_prop['value'], 'id' => $list_name), true); $attrs[] = 'list="' . $list_name . '"'; } if ($new_prop['icon']) { $field_html .= '<i class="icon-' . ($new_prop['icon_append'] ? 'append' : 'prepend') . ' ' . SmartUI::$icon_source . ' ' . $new_prop['icon'] . '"></i>'; } $field_html .= '<input ' . implode(' ', $attrs) . ' />'; $field_html .= $ac_html; if ($new_prop['tooltip']) { $tooltip_prop = array('content' => '', 'position' => 'top-right'); $new_tooltip_prop = parent::set_array_prop_def($tooltip_prop, $new_prop['tooltip'], 'content'); $field_html .= '<b class="tooltip tooltip-' . $new_tooltip_prop['position'] . '">' . $new_tooltip_prop['content'] . '</b>'; } if ($field_html_only) { return $field_html; } $result_html .= ' <label class="' . $field_class_map[$field_type] . '">'; $result_html .= $field_html; $result_html .= ' </label>'; break; case self::FORM_FIELD_RADIO: $default_prop = array('items' => array(), 'cols' => 0, 'inline' => false, 'toggle' => false); $new_prop = parent::get_clean_structure($default_prop, $properties, array(), 'items'); if (!is_array($new_prop['items'])) { $new_prop['items'] = array($new_prop['items']); } $items = $new_prop['items']; $item_list_html = array(); foreach ($items as $item) { $items_prop = array('name' => $name, 'checked' => false, 'value' => '', 'label' => '', 'id' => '', 'disabled' => false); $new_item_prop = parent::set_array_prop_def($items_prop, $item, 'label'); $item_html = self::_get_field_html($new_item_prop['name'], self::FORM_FIELD_INPUT, array('type' => 'radio', 'attr' => $new_item_prop['checked'] ? array('checked') : null, 'value' => $new_item_prop['value'], 'id' => $new_item_prop['id']), true); if ($new_prop['toggle']) { $text_off = is_array($new_prop['toggle']) && isset($new_prop['toggle']['text-off']) ? $new_prop['toggle']['text-off'] : 'OFF'; $text_on = is_array($new_prop['toggle']) && isset($new_prop['toggle']['text-on']) ? $new_prop['toggle']['text-on'] : 'ON'; $item_html .= '<i data-swchon-text="' . $text_on . '" data-swchoff-text="' . $text_off . '"></i>'; } else { $item_html .= '<i></i>'; } $item_html .= $new_item_prop['label']; $field_html = ' <label class="' . ($new_prop['toggle'] ? 'toggle' : $field_class_map[$field_type]) . ' ' . ($new_item_prop['disabled'] ? 'state-disabled' : '') . '">'; $field_html .= $item_html; $field_html .= ' </label>'; $item_list_html[] = $field_html; } if ($new_prop['cols']) { $result_html .= '<div class="row">'; $result_html .= self::print_col_items($item_list_html, function ($item) { return $item; }, $new_prop['cols'], true); $result_html .= '</div>'; } else { $list_html = implode('', $item_list_html); if ($new_prop['inline']) { $result_html .= '<div class="inline-group">'; $result_html .= $list_html; $result_html .= '</div>'; } else { $result_html .= $list_html; } } if ($field_html_only) { return $result_html; } break; case self::FORM_FIELD_CHECKBOX: $default_prop = array('items' => array(), 'cols' => 0, 'inline' => false, 'toggle' => false); $new_prop = parent::get_clean_structure($default_prop, $properties, array(), 'items'); if (!is_array($new_prop['items'])) { $new_prop['items'] = array($new_prop['items']); } $items = $new_prop['items']; $item_list_html = array(); foreach ($items as $item) { $items_prop = array('name' => $name, 'checked' => false, 'value' => '', 'label' => '', 'id' => '', 'disabled' => false); $new_item_prop = parent::set_array_prop_def($items_prop, $item, 'label'); $item_html = self::_get_field_html($new_item_prop['name'], self::FORM_FIELD_INPUT, array('type' => 'checkbox', 'attr' => $new_item_prop['checked'] ? array('checked') : null, 'value' => $new_item_prop['value'], 'id' => $new_item_prop['id']), true); if ($new_prop['toggle']) { $text_off = is_array($new_prop['toggle']) && isset($new_prop['toggle']['text-off']) ? $new_prop['toggle']['text-off'] : 'OFF'; $text_on = is_array($new_prop['toggle']) && isset($new_prop['toggle']['text-on']) ? $new_prop['toggle']['text-on'] : 'ON'; $item_html .= '<i data-swchon-text="' . $text_on . '" data-swchoff-text="' . $text_off . '"></i>'; } else { $item_html .= '<i></i>'; } $item_html .= $new_item_prop['label']; $field_html = ' <label class="' . ($new_prop['toggle'] ? 'toggle' : $field_class_map[$field_type]) . ' ' . ($new_item_prop['disabled'] ? 'state-disabled' : '') . '">'; $field_html .= $item_html; $field_html .= ' </label>'; $item_list_html[] = $field_html; } if ($new_prop['cols']) { $result_html .= '<div class="row">'; $result_html .= self::print_col_items($item_list_html, function ($item) { return $item; }, $new_prop['cols'], true); $result_html .= '</div>'; } else { $list_html = implode('', $item_list_html); if ($new_prop['inline']) { $result_html .= '<div class="inline-group">'; $result_html .= $list_html; $result_html .= '</div>'; } else { $result_html .= $list_html; } } if ($field_html_only) { return $result_html; } break; } if (is_array($properties)) { $notes = isset($properties['note']) ? '<div class="note">' . $properties['note'] . '</div>' : ''; $label = isset($properties['label']) && $properties['label'] ? '<label class="label">' . $properties['label'] . '</label>' : ''; } $result .= $label; $result .= $result_html; $result .= $notes; return $result; }
private function _init_structure($rows, $user_options = array()) { $this->_structure = parent::array_to_object($this->_structure); $this->_structure->options = parent::set_array_prop_def($this->_options_map, $user_options); $this->_structure->row = $rows; }