From c890f41b4977bc386f8f98ca815f6e4d7785c074 Mon Sep 17 00:00:00 2001 From: tanghucheng Date: Wed, 27 Jul 2022 17:23:17 +0800 Subject: [PATCH] * Code for port. --- module/port/control.php | 20 +++++ module/port/model.php | 72 ++++++++++++++++- module/port/view/showimport.html.php | 116 ++++++++++++++------------- 3 files changed, 153 insertions(+), 55 deletions(-) diff --git a/module/port/control.php b/module/port/control.php index c0e28ee02e..00d927ffb1 100644 --- a/module/port/control.php +++ b/module/port/control.php @@ -123,5 +123,25 @@ class port extends control } } + /** + * ajaxGetOptions + * + * @param string $model + * @param string $field + * @param string $value + * @param string $index + * @access public + * @return void + */ + public function ajaxGetOptions($model = '', $field = '', $value = '', $index = '') + { + $this->app->loadConfig($model); + $fields = $this->config->$model->templateFields; + $fieldList = $this->port->initFieldList($model, $fields, false); + if(!isset($fieldList[$field]['values'][''])) $fieldList[$field]['values'][''] = ''; + $multiple = $fieldList[$field]['control'] == 'multiple' ? 'multiple' : ''; + + return print(html::select($field. "[$index]", $fieldList[$field]['values'], $value, "class='form-control picker-select' $multiple")); + } } diff --git a/module/port/model.php b/module/port/model.php index 9bb367ab05..60074ba786 100644 --- a/module/port/model.php +++ b/module/port/model.php @@ -907,6 +907,37 @@ class portModel extends model return $fields; } + /** + * Get view datas. + * + * @param string $model + * @param string $datas + * @param string $title + * @param int $pagerID + * @param int $maxImport + * @access public + * @return void + */ + public function getViewDatas($model = '', $datas = '', $title = '', $pagerID = 1, $maxImport = 0, $insert) + { + $suhosinInfo = $this->checkSuhosinInfo($datas->datas); + + $fields = $this->config->$model->templateFields; + + $datas->title = $title ? $title : $this->lang->port->showImport; + $datas->requiredFields = $this->config->$model->create->requiredFields; + $datas->allPager = isset($datas->allPager) ? $datas->allPager : 1; + $datas->pagerID = $pagerID; + $datas->isEndPage = $pagerID >= $datas->allPager; + $datas->maxImport = $maxImport; + $datas->dataInsert = $insert; + $datas->fields = $this->initFieldList($model, $fields, false); + $datas->suhosinInfo = $suhosinInfo; + $datas->model = $model; + + return $datas; + } + /** * Update children datas. * @@ -1053,8 +1084,10 @@ class portModel extends model * @access public * @return void */ - public function saveImportDatas($model, $datas) + public function saveImportDatas($model, $datas = '') { + if(empty($datas)) $datas = $this->initPostFields($model); + foreach($datas as $key => $data) { $subDatas = array(); @@ -1135,4 +1168,41 @@ class portModel extends model $modelConfig->listFields = isset($modelConfig->listFields) ? $modelConfig->listFields : $portConfig->listFields; } + /** + * Read excel and format data . + * + * @param string $model + * @param int $pagerID + * @param int $maxImport + * @access public + * @return void + */ + public function readExcel($model = '', $pagerID = 1, $maxImport = 0) + { + /* Bulid import paris (field => name) .*/ + $fields = $this->getImportFields('bug'); + + /* Check tmpfile. */ + $tmpFile = $this->checkTmpFile(); + + /* If tmpfile not isset create tmpfile .*/ + if(!$tmpFile) + { + $rows = $this->checkRowsFromExcel(); + + $bugData = $this->processRows4Fields($rows, $fields); + + $bugData = $this->getNatureDatas('bug', $bugData); + + $this->createTmpFile($bugData); + } + else + { + $bugData = $this->getDatasByFile($tmpFile); + } + + /* Get page by datas.*/ + return $this->getPageDatas($bugData, $pagerID, $maxImport); + } + } diff --git a/module/port/view/showimport.html.php b/module/port/view/showimport.html.php index 3d1a174883..cef9feeda1 100644 --- a/module/port/view/showimport.html.php +++ b/module/port/view/showimport.html.php @@ -1,18 +1,30 @@ +title; + $requiredFields = $datas->requiredFields; + $allCount = $datas->allCount; + $allPager = $datas->allPager; + $pagerID = $datas->pagerID; + $isEndPage = $datas->isEndPage; + $maxImport = $datas->maxImport; + $dataInsert = $datas->dataInsert; + $fields = $datas->fields; + $suhosinInfo = $datas->suhosinInfo; + $model = $datas->model; + $datas = $datas->datas; +?> getModuleRoot() . 'common/view/header.html.php';?> - +
$this->config->file->maxImport):?>
-

task->import;?>

+

port->import;?>

file->importSummary, $allCount, html::input('maxImport', $config->file->maxImport, "style='width:50px'"), ceil($allCount / $config->file->maxImport));?>

import, "id='import'", 'btn btn-primary');?>

@@ -24,49 +36,37 @@ $(function() { if(parseInt($('#maxImport').val())) $('#times').html(Math.ceil(parseInt($('#allCount').html()) / parseInt($('#maxImport').val()))); }); - - $('#import').click(function(){ - $.cookie('maxImport', $('#maxImport').val()); - location.href = ""; + $('#import').click(function() + { + $.cookie('maxImport', $('#maxImport').val()) + window.location.reload(); }) }); +
-

task->import;?>

+

port->import;?>

- + $value):?> - show) continue; - - $width = ($field->width && $field->width != 'auto' ? $field->width . 'px' : 'auto'); - $required = strpos(",$field->rules,", ",$notEmptyRule->id,") !== false ? 'required' : ''; - echo ""; - } - } - ?> $object):?> @@ -79,19 +79,24 @@ $(function() } else { - $sub = (strpos($object->name, '>') === 0) ? " {$lang->port->children}" : " {$lang->task->new}"; - echo $addID++ . $sub; + echo $addID++ . " {$lang->port->new}"; } ?> + $value):?> + + + - + $field) ? $object->$field : '';$list = array();?> + $value['values'][$selected]);?> + + - - + config->port->dateMatch;?> @@ -112,27 +117,15 @@ $(function() - loadModel('flow'); - foreach($appendFields as $field) - { - if(!$field->show) continue; - $value = $field->defaultValue ? $field->defaultValue : zget($task, $field->field, ''); - echo ''; - } - } - ?> + - @@ -156,12 +149,27 @@ $(function()
task->id?> port->id?> $field->name
$field) ? $object->$field : '', "class='form-control chosen'")?> $field) ? $object->$field : '', "multiple class='form-control chosen'")?>$field) ? $object->$field : '', "class='form-control picker-select' data-field='{$field}' data-key='$key' multiple")?> ' . $this->flow->buildControl($field, $value, "$field->field[$key]", true) . '
+ lang->save : $this->lang->file->saveAndNext; - $isStartPage = $pagerID == 1 ? true : false; + $submitText = $isEndPage ? $this->lang->save : $this->lang->file->saveAndNext; if(!$insert and $dataInsert === '') { echo ""; @@ -144,7 +137,7 @@ $(function() } echo html::hidden('isEndPage', $isEndPage ? 1 : 0); echo html::hidden('pagerID', $pagerID); - echo '   ' . html::a("javascript:history.back(-1)", $lang->goback, '', "class='btn btn-back btn-wide'"); + echo html::a("javascript:history.back(-1)", $lang->goback, '', "class='btn btn-back btn-wide'"); echo '   ' . sprintf($lang->file->importPager, $allCount, $pagerID, $allPager); ?>