Merge branch dev/task-148404 of zentao/zentaopms (#10986)
This commit is contained in:
@@ -1273,14 +1273,22 @@ const commands =
|
||||
if (typeof doc !== 'object') {
|
||||
doc = docApp._treeMap.value.docs.get(doc)?.data;
|
||||
}
|
||||
/** 如果是附件类型并且没有内容的文档,则跳转到上传文档页面进行编辑。 */
|
||||
if(doc.type === 'attachment' && !doc.hasContent) {
|
||||
const type = docApp.lib ? docApp.lib.data.type : docApp.spaceType;
|
||||
const url = $.createLink('doc', 'uploadDocs', `docID=${doc.id}&objectType=${type}&objectID=${docApp.spaceID}&libID=${docApp.libID}&moduleID=${docApp.moduleID}&type=attachment`);
|
||||
zui.Modal.open({url: url});
|
||||
return false;
|
||||
}
|
||||
return docApp.startEditDoc(doc, options);
|
||||
},
|
||||
/** 上传文档。Upload Doc. */
|
||||
uploadDoc: function()
|
||||
uploadDoc: function(_, args)
|
||||
{
|
||||
const docApp = getDocApp();
|
||||
const docID = args[0] || docApp.docID
|
||||
const type = docApp.lib ? docApp.lib.data.type : docApp.spaceType;
|
||||
const url = $.createLink('doc', 'uploadDocs', `objectType=${type}&objectID=${docApp.spaceID}&libID=${docApp.libID}&moduleID=${docApp.moduleID}&type=attachment`);
|
||||
const url = $.createLink('doc', 'uploadDocs', `docID=${docID}&objectType=${type}&objectID=${docApp.spaceID}&libID=${docApp.libID}&moduleID=${docApp.moduleID}&type=attachment`);
|
||||
zui.Modal.open({url: url});
|
||||
},
|
||||
/** 创建 Office 文件。 Start create office file. */
|
||||
|
||||
@@ -89,8 +89,9 @@ $config->doc->form->edit['mailto'] = array('type' => 'array', 'require
|
||||
$config->doc->form->edit['editedBy'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
$config->doc->form->edit['editedDate'] = array('type' => 'datetime', 'required' => false, 'default' => $now);
|
||||
$config->doc->form->edit['isDeliverable'] = array('type' => 'string', 'required' => false, 'default' => '0');
|
||||
$config->doc->form->edit['fromVersion'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
$config->doc->form->edit['files'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
$config->doc->form->edit['fromVersion'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
$config->doc->form->edit['files'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
$config->doc->form->edit['deleteFiles'] = array('type' => 'array', 'required' => false, 'default' => '', 'filter' => 'join');
|
||||
|
||||
$config->doc->form->edittemplate = $config->doc->form->edit;
|
||||
$config->doc->form->edittemplate['templateDesc'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
|
||||
+18
-8
@@ -789,6 +789,7 @@ class doc extends control
|
||||
* 上传文档。
|
||||
* Upload docs.
|
||||
*
|
||||
* @param int $docID
|
||||
* @param string $objectType product|project|execution|custom
|
||||
* @param int $objectID
|
||||
* @param int|string $libID
|
||||
@@ -797,7 +798,7 @@ class doc extends control
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function uploadDocs(string $objectType, int $objectID, int $libID, int $moduleID = 0, string $docType = '')
|
||||
public function uploadDocs(int $docID, string $objectType, int $objectID, int $libID, int $moduleID = 0, string $docType = '')
|
||||
{
|
||||
if(!empty($_POST))
|
||||
{
|
||||
@@ -828,12 +829,16 @@ class doc extends control
|
||||
|
||||
$this->config->doc->create->requiredFields = trim(str_replace(array(',content,', ',keywords,'), ",", ",{$this->config->doc->create->requiredFields},"), ',');
|
||||
|
||||
$docData = form::data($this->config->doc->form->create)
|
||||
->setDefault('addedBy', $this->app->user->account)
|
||||
->get();
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
$docData = form::data(!empty($docID) ? $this->config->doc->form->edit : $this->config->doc->form->create)->remove('fromVersion')->get();
|
||||
if(empty($docID)) $docData->addedBy = $this->app->user->account;
|
||||
if(!empty($docID)) $docData->editedBy = $this->app->user->account;
|
||||
|
||||
if($this->post->uploadFormat == 'combinedDocs')
|
||||
if(!empty($docID))
|
||||
{
|
||||
$docResult = $this->doc->update($docID, $docData);
|
||||
$docData->id = $docID;
|
||||
}
|
||||
elseif($this->post->uploadFormat == 'combinedDocs')
|
||||
{
|
||||
$docResult = $this->doc->create($docData);
|
||||
}
|
||||
@@ -843,7 +848,7 @@ class doc extends control
|
||||
}
|
||||
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
return $this->docZen->responseAfterUploadDocs($docResult);
|
||||
return !empty($docID) ? $this->send($this->docZen->responseAfterEdit($docData, $docResult['changes'], $docResult['files'])) : $this->docZen->responseAfterUploadDocs($docResult);
|
||||
}
|
||||
|
||||
if($objectType == 'execution' && $libID) // 此时传入的objectID是projectID,用lib的信息更改回executionID
|
||||
@@ -852,7 +857,12 @@ class doc extends control
|
||||
$objectID = $this->doc->getObjectIDByLib($lib);
|
||||
}
|
||||
|
||||
$doc = !empty($docID) ? $this->doc->getByID($docID) : null;
|
||||
if(empty($moduleID) && $doc) $moduleID = (int)$doc->module;
|
||||
|
||||
$this->docZen->assignVarsForUploadDocs($objectType, $objectID, $libID, $moduleID, $docType);
|
||||
$this->view->docID = $docID;
|
||||
$this->view->doc = $doc;
|
||||
$this->display();
|
||||
}
|
||||
|
||||
@@ -998,7 +1008,7 @@ class doc extends control
|
||||
$files = $result['files'];
|
||||
}
|
||||
|
||||
return $this->docZen->responseAfterEdit($doc, $changes, $files);
|
||||
return $this->send($this->docZen->responseAfterEdit($doc, $changes, $files));
|
||||
}
|
||||
|
||||
/* Get doc and set menu. */
|
||||
|
||||
@@ -8,7 +8,7 @@ function addFileUploadMutationObserver()
|
||||
let title = $('.uploadFileBox .file-selector-list .file-selector-item:nth-child(1) .item-title').text();
|
||||
let dotIdx = title.lastIndexOf('.');
|
||||
if(dotIdx != '-1') title = title.substring(0, dotIdx);
|
||||
$('.titleBox [name=title]').val(title);
|
||||
if(!docID) $('.titleBox [name=title]').val(title);
|
||||
$('.uploadFormatBox').toggleClass('hidden', $('.uploadFileBox .file-selector-list .file-selector-item').length <= 1);
|
||||
});
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ $lang->doc->collectCount = '%s次收藏';
|
||||
$lang->doc->index = '仪表盘';
|
||||
$lang->doc->createAB = '创建';
|
||||
$lang->doc->create = '创建文档';
|
||||
$lang->doc->createOrUpload = '创建/导入文档';
|
||||
$lang->doc->createOrUpload = '创建文档';
|
||||
$lang->doc->edit = '编辑文档';
|
||||
$lang->doc->effort = '日志';
|
||||
$lang->doc->delete = '删除文档';
|
||||
|
||||
+18
-12
@@ -773,8 +773,9 @@ class docModel extends model
|
||||
*/
|
||||
public function getDocsOfLibs(array $libs, string $spaceType, int $excludeID = 0, $queryTemplate = false): array
|
||||
{
|
||||
$docs = $this->dao->select('t1.*')->from(TABLE_DOC)->alias('t1')
|
||||
$docs = $this->dao->select('t1.*,t3.content')->from(TABLE_DOC)->alias('t1')
|
||||
->leftJoin(TABLE_MODULE)->alias('t2')->on('t1.module=t2.id')
|
||||
->leftJoin(TABLE_DOCCONTENT)->alias('t3')->on('t1.id=t3.doc and t1.version=t3.version')
|
||||
->where('t1.lib')->in($libs)
|
||||
->andWhere('t1.vision')->eq($this->config->vision)
|
||||
->beginIF(!$queryTemplate)->andWhere('t1.templateType')->eq('')->andWhere('t2.type')->eq('doc')->fi()
|
||||
@@ -785,14 +786,15 @@ class docModel extends model
|
||||
->orderBy('t1.`order` asc, t1.id asc')
|
||||
->fetchAll('id', false);
|
||||
|
||||
$rootDocs = $this->dao->select('*')->from(TABLE_DOC)
|
||||
->where('lib')->in($libs)
|
||||
->andWhere('vision')->eq($this->config->vision)
|
||||
->beginIF(!$queryTemplate)->andWhere('templateType')->eq('')->fi()
|
||||
->beginIF($queryTemplate)->andWhere('templateType')->ne('')->andWhere('builtIn')->eq('0')->fi()
|
||||
->andWhere("(status = 'normal' or (status = 'draft' and addedBy='{$this->app->user->account}'))")
|
||||
->andWhere('module')->in(array('0', ''))
|
||||
->beginIF(!empty($excludeID))->andWhere("NOT FIND_IN_SET('{$excludeID}', `path`)")->andWhere('id')->ne($excludeID)->fi()
|
||||
$rootDocs = $this->dao->select('t1.*,t3.content')->from(TABLE_DOC)->alias('t1')
|
||||
->leftJoin(TABLE_DOCCONTENT)->alias('t3')->on('t1.id=t3.doc and t1.version=t3.version')
|
||||
->where('t1.lib')->in($libs)
|
||||
->andWhere('t1.vision')->eq($this->config->vision)
|
||||
->beginIF(!$queryTemplate)->andWhere('t1.templateType')->eq('')->fi()
|
||||
->beginIF($queryTemplate)->andWhere('t1.templateType')->ne('')->andWhere('builtIn')->eq('0')->fi()
|
||||
->andWhere("(t1.status = 'normal' or (t1.status = 'draft' and t1.addedBy='{$this->app->user->account}'))")
|
||||
->andWhere('t1.module')->in(array('0', ''))
|
||||
->beginIF(!empty($excludeID))->andWhere("NOT FIND_IN_SET('{$excludeID}', t1.`path`)")->andWhere('t1.id')->ne($excludeID)->fi()
|
||||
->orderBy('`order` asc, id_asc')
|
||||
->fetchAll('id', false);
|
||||
|
||||
@@ -809,6 +811,7 @@ class docModel extends model
|
||||
$doc->isCollector = strpos($doc->collector, ',' . $this->app->user->account . ',') !== false;
|
||||
$doc->title = htmlspecialchars_decode($doc->title);
|
||||
if(!empty($doc->keywords) && is_string($doc->keywords)) $doc->keywords = htmlspecialchars_decode($doc->keywords);
|
||||
$doc->hasContent = !empty($doc->content) ? true : false;
|
||||
unset($doc->content);
|
||||
unset($doc->draft);
|
||||
}
|
||||
@@ -1716,6 +1719,9 @@ class docModel extends model
|
||||
$files = $this->loadModel('file')->saveUpload('doc', $docID);
|
||||
if(dao::isError()) return false;
|
||||
|
||||
$deleteFiles = !empty($doc->deleteFiles) ? $doc->deleteFiles : '';
|
||||
unset($doc->deleteFiles);
|
||||
|
||||
$oldDoc = $this->getByID($docID);
|
||||
$changes = common::createChanges($oldDoc, $doc);
|
||||
$oldRawContent = isset($oldDoc->rawContent) ? $oldDoc->rawContent : '';
|
||||
@@ -1723,7 +1729,7 @@ class docModel extends model
|
||||
$onlyRawChanged = $oldRawContent != $newRawContent;
|
||||
$isDraft = $doc->status == 'draft';
|
||||
$version = $isDraft ? 0 : ($oldDoc->version + 1);
|
||||
$changed = $files || $onlyRawChanged || (!$isDraft && $oldDoc->version == 0);
|
||||
$changed = $deleteFiles || $files || $onlyRawChanged || (!$isDraft && $oldDoc->version == 0);
|
||||
$basicInfoChanged = false;
|
||||
foreach($changes as $change)
|
||||
{
|
||||
@@ -1732,7 +1738,7 @@ class docModel extends model
|
||||
if($change['field'] == 'content') $onlyRawChanged = false;
|
||||
}
|
||||
if($onlyRawChanged) $changes[] = array('field' => 'content', 'old' => $oldDoc->content, 'new' => $doc->content);
|
||||
if($changed) $this->saveDocContent($docID, $doc, $version, array_merge(array_keys($files), array_keys($oldDoc->files)));
|
||||
if($changed) $this->saveDocContent($docID, $doc, $version, array_diff(array_merge(array_keys($files), array_keys($oldDoc->files)), explode(',', $deleteFiles)));
|
||||
else $version = $oldDoc->version;
|
||||
if(dao::isError()) return false;
|
||||
|
||||
@@ -1754,7 +1760,7 @@ class docModel extends model
|
||||
}
|
||||
|
||||
unset($doc->files);
|
||||
$this->dao->update(TABLE_DOC)->data($doc, 'content,contentType,rawContent,fromVersion')
|
||||
$this->dao->update(TABLE_DOC)->data($doc, 'content,contentType,rawContent,fromVersion,deleteFiles')
|
||||
->autoCheck()
|
||||
->batchCheck($requiredFields, 'notempty')
|
||||
->where('id')->eq($docID)
|
||||
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 docModel->responseAfterEdit();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取修改后的返回信息属性result @success
|
||||
- 获取修改后的返回信息属性message @保存成功
|
||||
- 获取修改后的返回信息
|
||||
- 第doc条的id属性 @1
|
||||
- 第doc条的title属性 @文档标题1
|
||||
- 获取修改后的返回信息属性result @success
|
||||
- 获取修改后的返回信息属性message @保存成功
|
||||
- 获取修改后的返回信息
|
||||
- 第doc条的id属性 @2
|
||||
- 第doc条的title属性 @文档标题2
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
zenData('doclib')->gen(50);
|
||||
zenData('doc')->gen(50);
|
||||
zenData('doccontent')->gen(50);
|
||||
su('admin');
|
||||
|
||||
global $tester;
|
||||
$tester->app->setModuleName('doc');
|
||||
$docZen = initReference('doc');
|
||||
$method = $docZen->getMethod('responseAfterEdit');
|
||||
$method->setAccessible(true);
|
||||
$result = $method->invokeArgs($docZen->newInstance(), [$tester->loadModel('doc')->fetchByID(1)]);
|
||||
|
||||
r($result) && p('result') && e('success'); // 获取修改后的返回信息
|
||||
r($result) && p('message') && e('保存成功'); // 获取修改后的返回信息
|
||||
r($result) && p('doc:id,title') && e('1,文档标题1'); // 获取修改后的返回信息
|
||||
|
||||
$result = $method->invokeArgs($docZen->newInstance(), [$tester->loadModel('doc')->fetchByID(2)]);
|
||||
|
||||
r($result) && p('result') && e('success'); // 获取修改后的返回信息
|
||||
r($result) && p('message') && e('保存成功'); // 获取修改后的返回信息
|
||||
r($result) && p('doc:id,title') && e('2,文档标题2'); // 获取修改后的返回信息
|
||||
@@ -10,10 +10,11 @@ declare(strict_types=1);
|
||||
*/
|
||||
namespace zin;
|
||||
|
||||
jsVar('docID', $docID);
|
||||
jsVar('libType', $objectType);
|
||||
formPanel
|
||||
(
|
||||
set::title($lang->doc->uploadDoc),
|
||||
set::title(!empty($docID) ? $lang->doc->edit : $lang->doc->uploadDoc),
|
||||
set::submitBtnText($lang->doc->release),
|
||||
$objectType == 'project' ? formRow
|
||||
(
|
||||
@@ -34,6 +35,7 @@ formPanel
|
||||
set::label($lang->doc->execution),
|
||||
set::name('execution'),
|
||||
set::items(isset($executions) ? $executions : null),
|
||||
set::value(!empty($doc->execution) ? $doc->execution : 0),
|
||||
set::placeholder($lang->doc->placeholder->execution),
|
||||
on::change('loadObjectModules')
|
||||
) : null
|
||||
@@ -88,10 +90,20 @@ formPanel
|
||||
(
|
||||
setClass('uploadFileBox'),
|
||||
set::label($lang->doc->uploadFile),
|
||||
fileSelector(),
|
||||
fileSelector(set::defaultFiles(array_values($doc->files))),
|
||||
set::required(true)
|
||||
),
|
||||
formGroup
|
||||
(
|
||||
setClass('titleBox'),
|
||||
set::hidden(!empty($doc) ? false : true),
|
||||
set::label($lang->doc->title),
|
||||
set::name('title'),
|
||||
set::value(!empty($doc->title) ? $doc->title : ''),
|
||||
set::required(true),
|
||||
on::input('titleChanged')
|
||||
),
|
||||
formGroup
|
||||
(
|
||||
setClass('uploadFormatBox'),
|
||||
set::hidden(true),
|
||||
@@ -105,15 +117,6 @@ formPanel
|
||||
on::change('toggleDocTitle')
|
||||
)
|
||||
),
|
||||
formGroup
|
||||
(
|
||||
setClass('titleBox'),
|
||||
set::hidden(true),
|
||||
set::label($lang->doc->title),
|
||||
set::name('title'),
|
||||
set::required(true),
|
||||
on::input('titleChanged')
|
||||
),
|
||||
formRow
|
||||
(
|
||||
setID('aclBox'),
|
||||
@@ -124,7 +127,7 @@ formPanel
|
||||
(
|
||||
set::name('acl'),
|
||||
set::items($lang->doc->aclList),
|
||||
set::value($objectType == 'mine' ? 'private' : 'open'),
|
||||
set::value(!empty($doc->acl) ? $doc->acl : ($objectType == 'mine' ? 'private' : 'open')),
|
||||
on::change("toggleAcl('doc')")
|
||||
)
|
||||
)
|
||||
|
||||
+9
-6
@@ -652,9 +652,9 @@ class docZen extends doc
|
||||
* @param array $changes
|
||||
* @param array $files
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
protected function responseAfterEdit(object $doc, array $changes = array(), array $files = array())
|
||||
protected function responseAfterEdit(object $doc, array $changes = array(), array $files = array()): array
|
||||
{
|
||||
if($this->post->comment != '' || !empty($changes) || !empty($files))
|
||||
{
|
||||
@@ -668,8 +668,11 @@ class docZen extends doc
|
||||
|
||||
$fileAction = '';
|
||||
if(!empty($files)) $fileAction = $this->lang->addFiles . join(',', $files) . "\n";
|
||||
$actionID = $this->action->create('doc', $doc->id, $action, $fileAction . $this->post->comment, '', '', false);
|
||||
if(!empty($changes)) $this->action->logHistory($actionID, $changes);
|
||||
if(!empty($changes))
|
||||
{
|
||||
$actionID = $this->action->create('doc', $doc->id, $action, $fileAction . $this->post->comment, '', '', false);
|
||||
$this->action->logHistory($actionID, $changes);
|
||||
}
|
||||
}
|
||||
|
||||
$link = $this->createLink('doc', 'view', "docID={$doc->id}");
|
||||
@@ -692,10 +695,10 @@ class docZen extends doc
|
||||
$link = $this->createLink($moduleName, $methodName, $params);
|
||||
}
|
||||
|
||||
if(isInModal()) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true));
|
||||
if(isInModal()) return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true);
|
||||
|
||||
$doc->isCollector = strpos($doc->collector, ',' . $this->app->user->account . ',') !== false;
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $link, 'doc' => $doc));
|
||||
return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $link, 'doc' => $doc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user