示例#1
0
 /**
  * Render list
  *
  * @return string
  */
 public final function render()
 {
     $result = '';
     // css & js
     layout::add_css('/numbers/media_submodules/numbers_frontend_html_list_media_css_base.css', 9000);
     layout::add_js('/numbers/media_submodules/numbers_frontend_html_list_media_js_base.js', 9000);
     // load mask
     numbers_frontend_media_libraries_loadmask_base::add();
     // hidden fields
     $result .= html::hidden(['name' => 'offset', 'id' => 'offset', 'value' => $this->offset]);
     $result .= html::hidden(['name' => 'limit', 'id' => 'limit', 'value' => $this->limit]);
     // get total number of rows from count datasource
     if (!empty($this->datasources['count'])) {
         $temp = factory::model($this->datasources['count']['model'])->get($this->datasources['count']['options']);
         $this->total = $temp[0]['count'] ?? 0;
     }
     // get rows
     if (!empty($this->datasources['data'])) {
         $this->rows = factory::model($this->datasources['data']['model'])->get($this->datasources['data']['options']);
         $this->num_rows = count($this->rows);
     }
     // new record
     if (object_controller::can('record_new')) {
         $mvc = application::get('mvc');
         $url = $mvc['controller'] . '/_edit';
         $this->actions['list_new'] = ['value' => 'New', 'sort' => -32000, 'icon' => 'file-o', 'href' => $url];
     }
     // filter
     if (!empty($this->filter)) {
         $this->actions['list_filter'] = ['value' => 'Filter', 'sort' => 1, 'icon' => 'filter', 'onclick' => "numbers.modal.show('list_{$this->list_link}_filter');"];
         $result .= numbers_frontend_html_list_filter::render($this);
     }
     // order by
     $this->actions['list_sort'] = ['value' => 'Sort', 'sort' => 2, 'icon' => 'sort-alpha-asc', 'onclick' => "numbers.modal.show('list_{$this->list_link}_sort');"];
     $result .= numbers_frontend_html_list_sort::render($this);
     // export, before pagination
     if (object_controller::can('list_export')) {
         // add export link to the panel
         $result .= numbers_frontend_html_list_export::render($this);
         $this->actions['list_export'] = ['value' => 'Export/Print', 'sort' => 3, 'icon' => 'print', 'onclick' => "numbers.modal.show('list_{$this->list_link}_export');"];
         // if we are exporting
         if (!empty($this->options['input']['submit_export']) && !empty($this->options['input']['export']['format'])) {
             $result .= numbers_frontend_html_list_export::export($this, $this->options['input']['export']['format']);
             goto finish;
         }
     }
     // refresh
     $this->actions['form_refresh'] = ['value' => 'Refresh', 'sort' => 32000, 'icon' => 'refresh', 'href' => 'javascript:location.reload();', 'internal_action' => true];
     // pagination top
     if (!empty($this->pagination['top'])) {
         $result .= factory::model($this->pagination['top'])->render($this, 'top');
     }
     // data
     $result .= '<hr class="simple"/>';
     if (method_exists($this, 'render_data')) {
         $result .= $this->render_data();
     } else {
         $result .= $this->render_data_default();
     }
     $result .= '<hr class="simple"/>';
     // pagination bottom
     if (!empty($this->pagination['bottom'])) {
         $result .= factory::model($this->pagination['bottom'])->render($this, 'bottom');
     }
     finish:
     $value = '';
     if (!empty($this->actions)) {
         $value .= '<div style="text-align: right;">' . $this->render_actions() . '</div>';
         $value .= '<hr class="simple" />';
     }
     // we add hidden submit element
     $result .= html::submit(['name' => 'submit_hidden', 'value' => 1, 'style' => 'display: none;']);
     // build a form
     $value .= html::form(['name' => "list_{$this->list_link}_form", 'id' => "list_{$this->list_link}_form", 'value' => $result, 'onsubmit' => 'return numbers.frontend_list.on_form_submit(this);']);
     // if we came from ajax we return as json object
     if (!empty($this->options['input']['__ajax'])) {
         $result = ['success' => true, 'html' => $value, 'js' => layout::$onload];
         layout::render_as($result, 'application/json');
     }
     $value = "<div id=\"list_{$this->list_link}_form_mask\"><div id=\"list_{$this->list_link}_form_wrapper\">" . $value . '</div></div>';
     $temp = ['type' => 'primary', 'value' => $value];
     return html::segment($temp);
 }