diff --git a/db/update15.3.sql b/db/update15.3.sql index 743ccea4e4..0a42b47c5a 100644 --- a/db/update15.3.sql +++ b/db/update15.3.sql @@ -1 +1,2 @@ ALTER TABLE `zt_testtask` ADD `realFinishedDate` datetime NOT NULL AFTER `end`; +ALTER TABLE `zt_doc` ADD `tempContent` longtext NOT NULL AFTER `views`; diff --git a/db/zentao.sql b/db/zentao.sql index ab4f9f3beb..454543e96c 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -310,6 +310,7 @@ CREATE TABLE IF NOT EXISTS `zt_doc` ( `keywords` varchar(255) NOT NULL, `type` varchar(30) NOT NULL, `views` smallint(5) unsigned NOT NULL, + `tempContent` longtext NOT NULL, `collector` text NOT NULL, `addedBy` varchar(30) NOT NULL, `addedDate` datetime NOT NULL, diff --git a/module/doc/control.php b/module/doc/control.php index 35f930da6f..6556eec2c2 100644 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -752,6 +752,18 @@ class doc extends control die($select); } + /** + * Ajax save temporary content of doc. + * + * @param int $docID + * @access public + * @return void + */ + public function ajaxSaveContent($docID) + { + $this->doc->saveTempContent($docID); + } + /** * Show files. * diff --git a/module/doc/js/edit.js b/module/doc/js/edit.js index 15d946b179..2a1069e2b5 100644 --- a/module/doc/js/edit.js +++ b/module/doc/js/edit.js @@ -1,5 +1,15 @@ $(function() { + if(needUpdateContent) + { + if(confirm(confirmUpdateContent)) + { + $('#content').html(tempContent); + editor = KindEditor.instances[0]; + editor.html(tempContent); + } + } + $('#top-submit').click(function() { $(this).addClass('disabled'); @@ -23,42 +33,64 @@ $(function() $('#subNavbar li[data-id="doc"]').addClass('active'); + /* Automatically save document contents. */ + setInterval("saveTempContent()", 60 * 1000); + $(document).on("mousedown", 'span[data-name="fullscreen"]', function() { - if($(this).hasClass('ke-selected')) + if(config.onlybody == 'no') { - $('#submit').removeClass('fullscreen-save') - $('#submit').addClass('btn-wide') - } - else - { - $('#submit').addClass('fullscreen-save') - $('#submit').removeClass('btn-wide') + if($(this).hasClass('ke-selected')) + { + $('#submit').removeClass('fullscreen-save') + $('#submit').addClass('btn-wide') + } + else + { + $('#submit').addClass('fullscreen-save') + $('#submit').removeClass('btn-wide') + } } }); $(document).on("mousedown", 'a[title="Fullscreen"],.icon-columns', function() { - setTimeout(function() + if(config.onlybody == 'no') { - if($('a[title="Fullscreen"]').hasClass('active')) + setTimeout(function() { - $('#submit').addClass('markdown-fullscreen-save') - $('#submit').removeClass('btn-wide') - $('.fullscreen').css('height', '50px'); - $('.fullscreen').css('padding-top', '15px'); - $('.CodeMirror-fullscreen').css('top', '50px'); - $('.editor-preview-side').css('top', '50px'); - } - else - { - $('#submit').removeClass('markdown-fullscreen-save') - $('#submit').addClass('btn-wide') - $('.editor-toolbar').css('height', '30px'); - $('.editor-toolbar').css('padding-top', '1px'); - $('.CodeMirror').css('top', '0'); - $('.editor-preview-side').css('top', '30px'); - } - }, 200); + if($('a[title="Fullscreen"]').hasClass('active')) + { + $('#submit').addClass('markdown-fullscreen-save') + $('#submit').removeClass('btn-wide') + $('.fullscreen').css('height', '50px'); + $('.fullscreen').css('padding-top', '15px'); + $('.CodeMirror-fullscreen').css('top', '50px'); + $('.editor-preview-side').css('top', '50px'); + } + else + { + $('#submit').removeClass('markdown-fullscreen-save') + $('#submit').addClass('btn-wide') + $('.editor-toolbar').css('height', '30px'); + $('.editor-toolbar').css('padding-top', '1px'); + $('.CodeMirror').css('top', '0'); + $('.editor-preview-side').css('top', '30px'); + } + }, 200); + } }); }) + +/** + * Save temporary doc content. + * + * @access public + * @return void + */ +function saveTempContent() +{ + var content = $('#content').val(); + var link = createLink('doc', 'ajaxSaveContent', 'docID=' + docID); + $.post(link, {content: content}); +} diff --git a/module/doc/lang/de.php b/module/doc/lang/de.php index 25cd16baa5..3cfb95756c 100644 --- a/module/doc/lang/de.php +++ b/module/doc/lang/de.php @@ -189,6 +189,7 @@ $lang->doc->noEditedDoc = 'Sie haben kein Dokument bearbeitet.'; $lang->doc->noOpenedDoc = 'Sie haben kein Dokument erstellt.'; $lang->doc->noCollectedDoc = 'Sie haben kein Dokument gesammelt.'; $lang->doc->errorEmptyLib = 'No data in document library.'; +$lang->doc->confirmUpdateContent = 'You have a document that is not saved from last time. Do you want to continue editing it?'; $lang->doc->noticeAcl['lib']['product']['default'] = 'Users who can access the selected product can access it.'; $lang->doc->noticeAcl['lib']['product']['custom'] = 'Users who can access the selected product or users in the whiltelist can access it.'; diff --git a/module/doc/lang/en.php b/module/doc/lang/en.php index 95b90e6c8e..f3bc4adaf6 100644 --- a/module/doc/lang/en.php +++ b/module/doc/lang/en.php @@ -194,6 +194,7 @@ $lang->doc->noEditedDoc = 'You have not edited any documents.'; $lang->doc->noOpenedDoc = 'You have not created any documents.'; $lang->doc->noCollectedDoc = 'You have not favorited any documents.'; $lang->doc->errorEmptyLib = 'No data in document library.'; +$lang->doc->confirmUpdateContent = 'You have a document that is not saved from last time. Do you want to continue editing it?'; $lang->doc->noticeAcl['lib']['product']['default'] = 'Users who can access the selected product can access it.'; $lang->doc->noticeAcl['lib']['product']['custom'] = 'Users who can access the selected product or users in the whiltelist can access it.'; diff --git a/module/doc/lang/fr.php b/module/doc/lang/fr.php index b13b96b2c3..90a77b2b57 100644 --- a/module/doc/lang/fr.php +++ b/module/doc/lang/fr.php @@ -189,6 +189,7 @@ $lang->doc->noEditedDoc = "Vous n'avez pas mis à jour de documents."; $lang->doc->noOpenedDoc = "Vous n'avez pas ajouté de documents."; $lang->doc->noCollectedDoc = "Vous avez aucun document dans vos favoris."; $lang->doc->errorEmptyLib = 'No data in document library.'; +$lang->doc->confirmUpdateContent = 'You have a document that is not saved from last time. Do you want to continue editing it?'; $lang->doc->noticeAcl['lib']['product']['default'] = 'Les utilisateurs qui ont accès au Product peuvent y accéder.'; $lang->doc->noticeAcl['lib']['product']['custom'] = 'Les utilisateurs qui ont accès au Product ou les utilisateurs de la Liste Blanche peuvent y accéder.'; diff --git a/module/doc/lang/vi.php b/module/doc/lang/vi.php index d232acb35f..b14754bdda 100644 --- a/module/doc/lang/vi.php +++ b/module/doc/lang/vi.php @@ -189,6 +189,7 @@ $lang->doc->noEditedDoc = 'Bạn có not edited any documents.'; $lang->doc->noOpenedDoc = 'Bạn chưa tạo any documents.'; $lang->doc->noCollectedDoc = 'Bạn có not favorited any documents.'; $lang->doc->errorEmptyLib = 'No data in document library.'; +$lang->doc->confirmUpdateContent = 'You have a document that is not saved from last time. Do you want to continue editing it?'; $lang->doc->noticeAcl['lib']['product']['default'] = 'Users who can access the selected product có thể truy cập nó.'; $lang->doc->noticeAcl['lib']['product']['custom'] = 'Users who can access the selected product or users in the whiltelist có thể truy cập nó.'; diff --git a/module/doc/lang/zh-cn.php b/module/doc/lang/zh-cn.php index 821eeb15ad..dc928e2572 100644 --- a/module/doc/lang/zh-cn.php +++ b/module/doc/lang/zh-cn.php @@ -194,6 +194,7 @@ $lang->doc->noEditedDoc = '您还没有编辑任何文档。'; $lang->doc->noOpenedDoc = '您还没有创建任何文档。'; $lang->doc->noCollectedDoc = '您还没有收藏任何文档。'; $lang->doc->errorEmptyLib = '文档库暂无数据。'; +$lang->doc->confirmUpdateContent = '检查到您有未保存的文档内容,是否继续编辑?'; $lang->doc->noticeAcl['lib']['product']['default'] = '有所选产品访问权限的用户可以访问。'; $lang->doc->noticeAcl['lib']['product']['custom'] = '有所选产品访问权限或白名单里的用户可以访问。'; diff --git a/module/doc/model.php b/module/doc/model.php index 56dd28616c..eb83a89c8a 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -421,7 +421,7 @@ class docModel extends model $doc->content = isset($docContent->content) ? $docContent->content : ''; $doc->contentType = isset($docContent->type) ? $docContent->type : ''; - if($doc->type != 'url' and $doc->contentType != 'markdown') $doc = $this->loadModel('file')->replaceImgURL($doc, 'content'); + if($doc->type != 'url' and $doc->contentType != 'markdown') $doc = $this->loadModel('file')->replaceImgURL($doc, 'content,tempContent'); if($setImgSize) $doc->content = $this->file->setImgSize($doc->content); $doc->files = $docFiles; @@ -622,6 +622,7 @@ class docModel extends model } unset($doc->contentType); + $doc->tempContent = $doc->content; $this->dao->update(TABLE_DOC)->data($doc, 'content') ->autoCheck() ->batchCheck($requiredFields, 'notempty') @@ -629,11 +630,33 @@ class docModel extends model ->exec(); if(!dao::isError()) { + unset($doc->tempContent); $this->file->updateObjectID($this->post->uid, $docID, 'doc'); return array('changes' => $changes, 'files' => $files); } } + /** + * Save temporary doc content. + * + * @param int $docID + * @access public + * @return void + */ + public function saveTempContent($docID) + { + $data = fixer::input('post') + ->stripTags($this->config->doc->editor->edit['id'], $this->config->allowedTags) + ->get(); + $doc = new stdclass(); + $doc->tempContent = $data->content; + + $docType = $this->dao->select('type')->from(TABLE_DOCCONTENT)->where('doc')->eq((int)$docID)->orderBy('version_desc')->fetch(); + if($docType == 'markdown') $doc->tempContent = $this->post->content; + + $this->dao->update(TABLE_DOC)->data($doc)->where('id')->eq($docID)->exec(); + } + /** * Build search form. * diff --git a/module/doc/view/edit.html.php b/module/doc/view/edit.html.php index 1b346fb5ea..c07f21e464 100644 --- a/module/doc/view/edit.html.php +++ b/module/doc/view/edit.html.php @@ -13,6 +13,10 @@ contentType == 'html') include '../../common/view/kindeditor.html.php';?> contentType == 'markdown') include '../../common/view/markdown.html.php';?> +content != $doc->tempContent);?> +doc->confirmUpdateContent);?> +id);?> +tempContent);?>