diff --git a/framework/base/helper.class.php b/framework/base/helper.class.php index a9490316bf..c787cc08fe 100644 --- a/framework/base/helper.class.php +++ b/framework/base/helper.class.php @@ -164,7 +164,7 @@ class baseHelper $sign = strpos($link, '?') === false ? "?" : "&"; $appendString = ''; if($onlyBody or self::inOnlyBodyMode()) $appendString = $sign . "onlybody=yes"; - if(self::isWithTID()) $appendString .= empty($appendString) ? "{$sign}tid={$_GET['tid']}" : "&tid={$_GET['tid']}"; + if(self::isWithTID() and strpos($link, 'tid=') === false) $appendString .= empty($appendString) ? "{$sign}tid={$_GET['tid']}" : "&tid={$_GET['tid']}"; return $link . $appendString; } diff --git a/module/doc/config.php b/module/doc/config.php index 61c0bc9719..dd5ec6214c 100644 --- a/module/doc/config.php +++ b/module/doc/config.php @@ -15,6 +15,7 @@ $config->doc->edit->requiredFields = 'title'; $config->doc->customObjectLibs = 'files,customFiles'; $config->doc->notArticleType = ''; $config->doc->officeTypes = 'word,ppt,excel'; +$config->doc->textTypes = 'html,markdown,text'; $config->doc->custom = new stdclass(); $config->doc->custom->objectLibs = $config->doc->customObjectLibs; diff --git a/module/doc/control.php b/module/doc/control.php index 1f767ce221..43dfae32a8 100755 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -286,15 +286,16 @@ class doc extends control /** * Create a doc. * - * @param string $objectType - * @param int $objectID - * @param int|string $libID - * @param int $moduleID - * @param string $docType + * @param string $objectType + * @param int $objectID + * @param int|string $libID + * @param int $moduleID + * @param string $docType + * @param bool $fromGlobal * @access public * @return void */ - public function create($objectType, $objectID, $libID, $moduleID = 0, $docType = '') + public function create($objectType, $objectID, $libID, $moduleID = 0, $docType = '', $fromGlobal = false) { if(!empty($_POST)) { @@ -318,7 +319,20 @@ class doc extends control $objectID = zget($lib, $lib->type, ''); $params = "type={$lib->type}&objectID=$objectID&libID={$lib->id}&docID=" . $docResult['id']; $link = isonlybody() ? 'parent' : $this->createLink('doc', 'objectLibs', $params, 'html') . '#app=' . $this->app->tab; - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $link)); + $response = array('result' => 'success', 'message' => $this->lang->saveSuccess); + + if(isonlybody() and $docResult['docType'] == 'text') + { + $link = helper::createLink('doc', 'edit', "docID=$docID&comment=false&objectType=$objectType&objectID=$objectID&libID={$docResult['libID']}"); + + $response['callback'] = "redirect2Edit($docID, \"$objectType\", $objectID, {$docResult['libID']})"; + } + else + { + $response['locate'] = "$link"; + } + + return $this->send($response); } unset($_GET['onlybody']); @@ -347,7 +361,7 @@ class doc extends control if($this->config->systemMode == 'new') unset($this->lang->doc->menu->project['subMenu']); } - $this->config->showMainMenu = strpos(',html,markdown,text,', ",$docType,") === false; + $this->config->showMainMenu = strpos($this->config->doc->textTypes, $docType) === false; /* Get libs and the default lib id. */ $gobackLink = ($objectID == 0 and $libID == 0) ? $this->createLink('doc', 'tableContents', "type=$objectType") : ''; @@ -362,7 +376,7 @@ class doc extends control $this->view->title = $libName . $this->lang->doc->create; $this->view->objectType = $objectType; - $this->view->objectID = $objectID; + $this->view->objectID = zget($lib, $lib->type, ''); $this->view->libID = $libID; $this->view->lib = $lib; $this->view->libs = $libs; @@ -373,6 +387,7 @@ class doc extends control $this->view->docType = $docType; $this->view->groups = $this->loadModel('group')->getPairs(); $this->view->users = $this->user->getPairs('nocode|noclosed|nodeleted'); + $this->view->fromGlobal = $fromGlobal; $this->display(); } @@ -380,15 +395,16 @@ class doc extends control /** * Edit a doc. * - * @param int $docID - * @param bool $comment - * @param string $objectType - * @param int $objectID - * @param int $libID + * @param int $docID + * @param bool $comment + * @param string $objectType + * @param int $objectID + * @param int $libID + * @param string $from * @access public * @return void */ - public function edit($docID, $comment = false, $objectType = '', $objectID = 0, $libID = 0) + public function edit($docID, $comment = false, $objectType = '', $objectID = 0, $libID = 0, $from = 'edit') { if(!empty($_POST)) { @@ -490,6 +506,9 @@ class doc extends control $this->view->lib = $lib; $this->view->groups = $this->loadModel('group')->getPairs(); $this->view->users = $this->user->getPairs('noletter|noclosed|nodeleted', $doc->users); + $this->view->from = $from; + $this->view->files = $this->loadModel('file')->getByObject('doc', $docID); + $this->view->objectID = zget($lib, $type, ''); $this->display(); } diff --git a/module/doc/js/create.js b/module/doc/js/create.js index d3e25d9fd5..8547c1beeb 100644 --- a/module/doc/js/create.js +++ b/module/doc/js/create.js @@ -87,7 +87,7 @@ function initPage(type) { $('#contentBox .contentmarkdown').removeClass('hidden'); $('#contentBox .contenthtml').addClass('hidden'); - $('#contentBox #contentType').val(type); + $('#contentType').val(type); } } else if(type == 'url') @@ -150,3 +150,17 @@ function loadWhitelist(libID) } }); } + +/** + * Redirect to edit page when create the doc of text type. + * + * @param int docID + * @param string objectType + * @param int objectID + * @param int libID + * @return void + */ +function redirect2Edit(docID, objectType, objectID, libID) +{ + parent.location.href = createLink('doc', 'edit', 'docID=' + docID + '&comment=false&objectType=' + objectType + '&objectID=' + objectID + '&libID=' + libID + '&from=create'); +} diff --git a/module/doc/js/selectlibtype.js b/module/doc/js/selectlibtype.js index b3711fee8e..02393b4e56 100644 --- a/module/doc/js/selectlibtype.js +++ b/module/doc/js/selectlibtype.js @@ -16,7 +16,7 @@ function redirectParentWindow(objectType, libID, docType) } else { - var link = createLink('doc', 'create', 'objectType=' + objectType + '&objectID=0&libID=' + libID + '&moduleID=0&docType=' + docType) + '#app=doc'; + var link = createLink('doc', 'create', 'objectType=' + objectType + '&objectID=0&libID=' + libID + '&moduleID=0&docType=' + docType + '&fromGlobal=true') + '#app=doc'; } window.parent.$.apps.open(link); } diff --git a/module/doc/model.php b/module/doc/model.php index 142f262d78..07fed51fb8 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -782,7 +782,7 @@ class docModel extends model $docContent->files = join(',', array_keys($files)); $this->dao->insert(TABLE_DOCCONTENT)->data($docContent)->exec(); $this->loadModel('score')->create('doc', 'create', $docID); - return array('status' => 'new', 'id' => $docID, 'files' => $files); + return array('status' => 'new', 'id' => $docID, 'files' => $files, 'docType' => $doc->type, 'libID' => $doc->lib); } return false; } @@ -2126,11 +2126,11 @@ class docModel extends model { foreach($this->lang->doc->typeList as $typeKey => $typeName) { - $class = strpos($this->config->doc->officeTypes, $typeKey) !== false ? 'iframe' : ''; + $class = (strpos($this->config->doc->officeTypes, $typeKey) !== false or strpos($this->config->doc->textTypes, $typeKey) !== false) ? 'iframe' : ''; $icon = zget($this->config->doc->iconList, $typeKey); - $html .= "