public $onTaskSelected; public $onTaskOpened; public $onTaskClosed; public $onTaskDragStart; public $onTaskDrag; public $onBeforeTaskDrag; public $onBeforeTaskChanged; public $onAfterTaskDrag; public $itemsTag = 'div'; public $dataProcessorUrl; public $itemsStyle='height:500px;'; public $taskAttributes = array(); public $scales; public $tree = false;
public $taskAttributes = array( 'text'=>'description', 'start_date'=>'plan_start_date', 'end_date'=>'plan_end_date' );
Public $scales = array( array('unit'=>'year', 'step'=>1, 'date'=>'%Y') array('unit'=>'month', 'step'=>1, 'date'=>'%F, %Y') );
protected function initColumns() { if($this->columns===array()) { if($this->dataProvider instanceof CActiveDataProvider) $this->columns=$this->dataProvider->model->attributeNames(); elseif($this->dataProvider instanceof IDataProvider) { // use the keys of the first row of data as the default columns $data=$this->dataProvider->getData(); if(isset($data[0]) && is_array($data[0])) $this->columns=array_keys($data[0]); } } $id=$this->getId(); foreach($this->columns as $i=>$column) { if(is_string($column)) $column=$this->createDataColumn($column); else { if(!isset($column['class'])) { $column['class'] = 'CDataColumn'; } $column=Yii::createComponent($column, $this); } if(!$column->visible) { unset($this->columns[$i]); continue; } if($column->id===null) $column->id=$id.'_c'.$i; $this->columns[$i]=$column; } $tree_initiated = false; foreach($this->columns as $column) { $column->init(); if ($column instanceof CDataColumn && $this->tree && !$tree_initiated) { $this->tree_column_name = $column->name; $tree_initiated = true; } } }
public function renderItems() { if($this->dataProvider->getItemCount()>0 || $this->showTableOnEmpty) { echo CHtml::openTag($this->itemsTag, array('class'=>$this->itemsCssClass, 'style'=>$this->itemsStyle)); //render container only //content render in javascript echo CHtml::closeTag($this->itemsTag); } else $this->renderEmptyText(); }
public function getData() { $ret = array('data'=>array()); $data = $this->dataProvider->getData(); $n = count($data); if($n > 0) { for($row=0; $row < $n; ++$row) $ret['data'][] = $this->getDataRow($row); } return $ret; }
$r = new ReflectionMethod($column, 'getDataCellContent'); $r->setAccessible(true); $value = $r->invoke($column, $row, $data); $ret[$column->name] = $value;
public function registerClientScript() { $id = $this->getId(); if($this->ajaxUpdate===false) $ajaxUpdate=false; else $ajaxUpdate=array_unique(preg_split('/\s*,\s*/',$this->ajaxUpdate.','.$id,-1,PREG_SPLIT_NO_EMPTY)); $itemsSelector = $this->itemsTag; $itemsCssClass = explode(' ',$this->itemsCssClass,2); if (is_array($itemsCssClass)) { $itemsSelector .= '.'.$itemsCssClass[0]; } $options=array( 'ajaxUpdate'=>$ajaxUpdate, 'ajaxVar'=>$this->ajaxVar, 'pagerClass'=>$this->pagerCssClass, 'loadingClass'=>$this->loadingCssClass, 'filterClass'=>$this->filterCssClass, // 'tableClass'=>$this->itemsCssClass, // 'selectableRows'=>$this->selectableRows, 'enableHistory'=>$this->enableHistory, 'updateSelector'=>$this->updateSelector, 'filterSelector'=>$this->filterSelector, 'itemsSelector'=>$itemsSelector, ); if($this->ajaxUrl!==null) $options['url']=CHtml::normalizeUrl($this->ajaxUrl); if($this->ajaxType!==null) $options['ajaxType']=strtoupper($this->ajaxType); if($this->enablePagination) $options['pageVar']=$this->dataProvider->getPagination()->pageVar; foreach(array('beforeAjaxUpdate', 'afterAjaxUpdate', 'ajaxUpdateError', 'onTaskSelected', 'onTaskOpened', 'onTaskClosed', 'onTaskDragStart', 'onTaskDrag', 'onBeforeTaskDrag', 'onBeforeTaskChanged', 'onAfterTaskDrag', /*, 'selectionChanged'*/) as $event) { if($this->$event!==null) { if($this->$event instanceof CJavaScriptExpression) $options[$event]=$this->$event; else $options[$event]=new CJavaScriptExpression($this->$event); } } $options['config'] = array( //The default date format for JSON and XML data is "%d-%m-%Y" http://docs.dhtmlx.com/gantt/desktop__loading.html#loadingfromadatabase 'xml_date'=>'%Y-%m-%d', 'columns'=>array_map(function($column){ if ($column instanceof CCheckBoxColumn) { $ret = array('name'=>$column->name); } elseif ($column instanceof AlxdStatusrefColumn) { $ret = array('name'=>$column->name.($column->format ? '.'.$column->format : '')); } elseif ($column instanceof AlxdAttributerefColumn) { $ret = array('name'=>$column->name.($column->attribute ? '.'.$column->attribute : '')); } else { $ret = array('name'=>$column->name); } $r = new ReflectionMethod($column, 'renderHeaderCellContent'); $r->setAccessible(true); ob_start(); $r->invoke($column); $ret['label'] = ob_get_contents(); ob_end_clean(); if ($column instanceof CCheckBoxColumn) { $ret['width'] = 36; } else { $headerHtmlOptions = $column->headerHtmlOptions; if (isset($headerHtmlOptions['style'])) { $styles = explode(';', rtrim($headerHtmlOptions['style'], ';')); foreach ($styles as $style) { $pair = explode(':', $style, 2); if (count($pair) == 2 && strtolower(trim($pair[0])) == 'width') { $l = strlen($pair[1]); if (strtolower(substr($pair[1], $l-2, 2)) == 'px') { $ret['width'] = substr($pair[1], 0, $l - 2); } } } } if ($this->tree && $column->name == $this->tree_column_name) { $ret['tree'] = $this->tree; } } return $ret; }, $this->columns), 'filters'=>array_map(function($column){ $r = new ReflectionMethod($column, 'renderFilterCellContent'); $r->setAccessible(true); ob_start(); $r->invoke($column); $filter = ob_get_contents(); ob_end_clean(); return array( 'name'=>$column->name, 'control'=>$filter ); }, $this->columns), 'data'=>$this->getData(), ); $options['config']['scale_unit'] = $this->scales[0]['unit']; $options['config']['date_scale'] = $this->scales[0]['date']; if (count($this->scales) > 1) { $options['config']['subscales'] = array_slice($this->scales, 1); } if ($this->filter !== null) { $options['config']['scale_height_auto'] = true; $options['config']['filter'] = true; } if (isset($this->dataProcessorUrl)) { $options['dataProcessorUrl'] = $this->dataProcessorUrl; } $options=CJavaScript::encode($options); $cs=Yii::app()->getClientScript(); if ($this->_assets == null) { $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets'; $this->_assets = Yii::app()->assetManager->publish($path); } $cs->registerCoreScript('jquery'); $cs->registerCoreScript('bbq'); if($this->enableHistory) $cs->registerCoreScript('history'); $cs->registerCssFile($this->_assets . DIRECTORY_SEPARATOR . 'dhtmlxgantt.css'); $cs->registerScriptFile($this->_assets . DIRECTORY_SEPARATOR . 'dhtmlxgantt.js', CClientScript::POS_BEGIN); $cs->registerScriptFile($this->_assets . DIRECTORY_SEPARATOR . 'locale/locale_'.Yii::app()->language.'.js', CClientScript::POS_BEGIN); $cs->registerScriptFile($this->_assets . DIRECTORY_SEPARATOR . 'alxd.dhtmlxgantt.js', CClientScript::POS_BEGIN); $cs->registerScript(__CLASS__.'#'.$id,"jQuery('#$id').alxdDhtmlxGantt($options);", CClientScript::POS_READY); }
gantt._render_grid_header = function () { var columns = this.getGridColumns(); var filters = this.config.filters; var title_cells = []; var filter_cells = []; var width = 0, labels = this.locale.labels; var lineHeigth = this.config.scale_height - 2; for (var i = 0; i < columns.length; i++) { var last = i == columns.length - 1; var col = columns[i]; var colWidth = col.width*1; if (last && this._get_grid_width() > width + colWidth) col.width = colWidth = this._get_grid_width() - width; width += colWidth; var sort = (this._sort && col.name == this._sort.name) ? ("<div class='gantt_sort gantt_" + this._sort.direction + "'></div>") : ""; var cssClass = ["gantt_grid_head_cell", ("gantt_grid_head_" + col.name), (last ? "gantt_last_cell" : ""), this.templates.grid_header_class(col.name, col)].join(" "); var style = "width:" + (colWidth - (last ? 1 : 0)) + "px;"; var label = (col.label || labels["column_" + col.name]); label = label || ""; var title_cell = "<div class='" + cssClass + "' style='" + style + "' column_id='" + col.name + "'>" + label + sort + "</div>"; title_cells.push(title_cell); if (filters.length >= i) { var filter = filters[i]; var filter_cell = "<div class='" + cssClass + "' style='" + style + "'>" + filter.control + "</div>"; filter_cells.push(filter_cell); } } this.$grid_scale.innerHTML = "<div class='gantt_grid_scale_row'>" + title_cells.join("") + "</div>" + (this.config.filter ? "<div class='gantt_grid_scale_row'>" + filter_cells.join("") + "</div>" : ""); this.$grid_scale.style.width = (width - 1) + "px"; if (this.config.scale_height_auto == true) { var $grid_scale = $(this.$grid_scale); $grid_scale.removeAttr("style"); this.config.scale_height = $grid_scale.height(); this.$grid_scale.style.height = (this.config.scale_height - 1) + "px"; this.$grid_scale.style.lineHeight = "1.42857143"; } else { this.$grid_scale.style.height = (this.config.scale_height - 1) + "px"; this.$grid_scale.style.lineHeight = lineHeigth + "px"; } }; gantt._render_grid_item = function (item) { var btn_cell_width = 20; if (!gantt._is_grid_visible()) return null; var columns = this.getGridColumns(); var cells = []; var width = 0; for (var i = 0; i < columns.length; i++) { var last = i == columns.length - 1; var col = columns[i]; var cell; var value; var actions = null; if (col.template) value = col.template(item); else value = item[col.name]; if (value.actions) { actions = value.actions; value = value.content; } if (value instanceof Date) value = this.templates.date_grid(value, item); value = "<div class='gantt_tree_content'>" + value + "</div>"; var css = "gantt_cell" + (last ? " gantt_last_cell" : ""); var tree = ""; if (col.tree) { for (var j = 0; j < item.$level; j++) tree += this.templates.grid_indent(item); var has_child = this._has_children(item.id); if (has_child) { tree += this.templates.grid_open(item); tree += this.templates.grid_folder(item); } else { tree += this.templates.grid_blank(item); tree += this.templates.grid_file(item); } } var style = "width:" + (col.width - (actions ? btn_cell_width : 0) - (last ? 1 : 0)) + "px;"; if (this.defined(col.align)) style += "text-align:" + col.align + ";"; cell = "<div class='" + css + "' style='" + style + "'>" + tree + value + "</div>"; cells.push(cell); if (actions) { cells.push(actions); } } var css = item.$index % 2 === 0 ? "" : " odd"; css += (item.$transparent) ? " gantt_transparent" : ""; css += (item.$dataprocessor_class ? " " + item.$dataprocessor_class : ""); if (this.templates.grid_row_class) { var css_template = this.templates.grid_row_class.call(this, item.start_date, item.end_date, item); if (css_template) css += " " + css_template; } if (this.getState().selected_task == item.id) { css += " gantt_selected"; } var el = document.createElement("div"); el.className = "gantt_row" + css; el.style.height = this.config.row_height + "px"; el.style.lineHeight = (gantt.config.row_height) + "px"; el.setAttribute(this.config.task_attribute, item.id); el.innerHTML = cells.join(""); return el; };
@btn-cell-width: 20px; .gantt-loading { .gantt_container { background: url('../images/loading.gif') no-repeat center center !important; > .gantt_grid, > .gantt_task { opacity: 0.5; } } } .gantt_grid_scale, .gantt_task_scale { font-size: inherit; background-color: @primary-color; } .gantt_grid_head_cell { padding: 8px; text-align: inherit; overflow: inherit; white-space: normal; } .gantt_row { .btn-group { vertical-align: inherit; } .btn-cell { width: @btn-cell-width; height: 100%; .btn { height: inherit; line-height: inherit; padding: 0px; border-radius: 0px; border: none; width: 100%; span.caret { display: none; } } i { font-size: 14px; } } } .alxdgrid { .gantt.table-footer { margin-top: -1px; } }
$cnt = $viewpub->provider->totalItemCount; $template = array(); $template[] = '{items}'; if ($cnt > 0) { if ($viewpub->getShowAll()) { $isShowAll = isset($_GET['showall']) && $_GET['showall'] == 1; $params = array_merge((array)'', $_GET); if ($isShowAll) { unset($params['showall']); } else { $params['showall'] = 1; } $templateShowAll = CHtml::link( $isShowAll ? '<i class="fa fa-files-o"></i>' : '<i class="fa fa-file-o"></i>', $params, array( 'id'=>'Viewpub_page_to_all', 'class'=>'btn btn-primary btn-outline pull-right show-all', 'title'=>$isShowAll ? Yii::t('Viewpub','Page-by-page') : Yii::t('Viewpub','All at once') ) ); $template[] = '<div class="gantt table-footer clearfix">' . $templateShowAll . '{pager}{summary}</div>'; } else { $template[] = '<div class="gantt table-footer clearfix">{pager}{summary}</div>'; } } $options = array( 'id' => 'viewpub_grid_' . $suffix, 'type' => BsHtml::GRID_TYPE_STRIPED, 'dataProcessorUrl'=>Yii::app()->createUrl('viewpub/ganttDataProcessor', array('viewpub_id'=>$viewpub->id, 'user_id'=>$user->id)), 'dataProvider' => $viewpub->provider, 'filter' => $viewpub->objectref, 'columns' => array_merge( $cntCommands ? array($checkBoxColumn) : array(), $viewpub->columns ), 'taskAttributes'=> $viewpub->getTaskAttributes(), 'itemsCssClass' => 'gantt-mono-primary', 'summaryCssClass'=>'hidden-xs table-summary', 'pagerCssClass'=>'table-pagination', 'loadingCssClass'=>'gantt-loading', 'enableSorting' => $viewpub->getSorting(), 'tree' => $viewpub->getTree(), 'scales' =>$viewpub->getScales(), 'template' => implode('', $template), 'pager' => array( 'class' => 'CLinkPager', 'maxButtonCount' => $isMobileClient ? 3 : 10, 'firstPageLabel' => ' <i class="fa fa-angle-double-left"></i> ', 'header' => '', 'hiddenPageCssClass' => 'disabled', 'lastPageLabel' => ' <i class="fa fa-angle-double-right"></i> ', 'nextPageLabel' => ' <i class="fa fa-angle-right"></i> ',//'>', 'selectedPageCssClass' => 'active', 'prevPageLabel' => ' <i class="fa fa-angle-left"></i> ',//'<', 'htmlOptions' => array('class' => 'pagination') ), 'updateSelector' => ($viewpub->getShowAll() ? '{page}, {sort}, a.show-all' : '{page},{sort}'), 'ajaxUpdateError'=>'function(request, textStatus, errorThrow, errorMessage){ EaslaAlert.add(request.status == 501 ? request.responseText : request.statusText+": "+extractExceptionText(request.responseText), {type: "danger"});}' ); if ($cntCommands) { $options['afterAjaxUpdate'] = 'function() { $(":checkbox").uniform();}'; $options['onTaskSelected'] = $options['onTaskOpened'] = $options['onTaskClosed'] = $options['onTaskDrag'] = 'function(id) { $(":checkbox").uniform();}'; } $renderViewpub = $this->widget('ext.AlxdDhtmlxGantt.AlxdDhtmlxGantt', $options, true);
Source: https://habr.com/ru/post/302786/