diff --git a/module/api/config.php b/module/api/config.php index 9349615aa8..9d92132f9f 100644 --- a/module/api/config.php +++ b/module/api/config.php @@ -2,10 +2,10 @@ $config->api = new stdClass(); $config->api->createlib = new stdclass(); -$config->api->createlib->requiredFields = 'name'; +$config->api->createlib->requiredFields = 'name,baseUrl'; $config->api->editlib = new stdclass(); -$config->api->editlib->requiredFields = 'name'; +$config->api->editlib->requiredFields = 'name,baseUrl'; $config->api->struct = new stdClass(); $config->api->struct->requiredFields = 'name,params'; diff --git a/module/api/control.php b/module/api/control.php index 8b0451eff5..ccfa2b7ee8 100755 --- a/module/api/control.php +++ b/module/api/control.php @@ -333,26 +333,27 @@ class api extends control * @access public * @return void */ - public function createLib($type = 'normal') + public function createLib($type = 'product') { if(!empty($_POST)) { - $libID = $type == 'demo' ? $this->api->createDemoData($this->post->name, $this->post->baseUrl) : $this->doc->createApiLib(); - if(dao::isError()) return $this->sendError(dao::getError()); - - /* If the created api library of imported zentao api library, return directly. */ - if($type == 'demo') return $this->sendSuccess(array('locate' => $this->createLink('api', 'index', "libID=$libID"))); + $libID = $this->doc->createApiLib(); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); /* Record action for create api library. */ - $this->action->create('docLib', $libID, 'Created'); + $this->action->create('doclib', $libID, 'created'); if(!helper::isAjaxRequest()) return print(js::locate($this->createLink('api', 'index', "libID=$libID"), 'parent.parent')); - return $this->sendSuccess(array('locate' => $this->createLink('api', 'index', "libID=$libID"))); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->createLink('api', 'index', "libID=$libID"))); } - $this->view->type = $type; - $this->view->groups = $this->loadModel('group')->getPairs(); - $this->view->users = $this->user->getPairs('nocode|noclosed'); + $this->lang->api->aclList['default'] = sprintf($this->lang->doclib->aclList['default'], $this->lang->{$type}->common); + + $this->view->type = $type; + $this->view->groups = $this->loadModel('group')->getPairs(); + $this->view->users = $this->user->getPairs('nocode|noclosed'); + $this->view->projects = $this->loadModel('project')->getPairsByModel(); + $this->view->products = $this->loadModel('product')->getPairs(); $this->display(); } @@ -366,28 +367,26 @@ class api extends control */ public function editLib($id) { - $doc = $this->doc->getLibById($id); + $lib = $this->doc->getLibById($id); if(!empty($_POST)) { - $lib = fixer::input('post')->join('groups', ',')->join('users', ',')->get(); - - if($lib->acl == 'private') $lib->users = $this->app->user->account; - $this->doc->updateApiLib($id, $doc, $lib); + $this->doc->updateApiLib($id); if(dao::isError()) return $this->sendError(dao::getError()); - $res = array( - 'message' => $this->lang->saveSuccess, - 'closeModal' => true, - 'callback' => "redirectParentWindow($id)", - ); - return $this->sendSuccess($res); + return $this->sendSuccess(array('message' => $this->lang->saveSuccess, 'closeModal' => true, 'callback' => "redirectParentWindow($id)")); } - $this->view->doc = $doc; - $this->view->groups = $this->loadModel('group')->getPairs(); - $this->view->users = $this->user->getPairs('nocode|noclosed'); + $type = !empty($lib->product) ? 'product' : 'project'; + $this->lang->api->aclList['default'] = sprintf($this->lang->doclib->aclList['default'], $this->lang->{$type}->common); + + $this->view->lib = $lib; + $this->view->type = $type; + $this->view->groups = $this->loadModel('group')->getPairs(); + $this->view->users = $this->user->getPairs('nocode|noclosed'); + $this->view->projects = $this->loadModel('project')->getPairsByModel(); + $this->view->products = $this->loadModel('product')->getPairs(); $this->display(); } diff --git a/module/api/css/common.css b/module/api/css/common.css index f2370d8fc4..2af509f4d2 100644 --- a/module/api/css/common.css +++ b/module/api/css/common.css @@ -100,3 +100,5 @@ ol, ul {margin-bottom: 0} form .table-data, #content .table-data {border: 1px solid #e2e2e3;} .table-data thead {background: #f9f9f9;} + +#aclBox .acl-tip {color: #838a9d;} diff --git a/module/api/js/common.js b/module/api/js/common.js index 9f4268d397..161b5765d7 100644 --- a/module/api/js/common.js +++ b/module/api/js/common.js @@ -19,23 +19,36 @@ function loadDocModule(libID) */ function toggleAcl(acl, type) { - if(acl == 'custom') - { - $('#whiteListBox').removeClass('hidden'); - } - else + if(acl == 'open') { $('#whiteListBox').addClass('hidden'); } - if(type == 'lib') + else { - var notice = typeof(noticeAcl[acl]) != 'undefined' ? noticeAcl[acl] : ''; - $('#noticeAcl').html(notice); + $('#whiteListBox').removeClass('hidden'); + } +} + +/** + * Toggle lib type. + * + * @param string $libType + * @access public + * @return void + */ +function toggleLibType(libType) +{ + if(libType == 'project') + { + $('#projectBox').removeClass('hidden'); + $('#productBox').addClass('hidden'); + $('#acldefault').next('.acl-tip').html($('#acldefault').next('.acl-tip').html().replace(productLang, projectLang)); } else { - var notice = typeof(noticeAcl[acl]) != 'undefined' ? noticeAcl[acl] : ''; - $('#noticeAcl').html(notice); + $('#projectBox').addClass('hidden'); + $('#productBox').removeClass('hidden'); + $('#acldefault').next('.acl-tip').html($('#acldefault').next('.acl-tip').html().replace(projectLang, productLang)); } } diff --git a/module/api/js/createlib.js b/module/api/js/createlib.js index 4215cd9cf4..02a964d4fa 100644 --- a/module/api/js/createlib.js +++ b/module/api/js/createlib.js @@ -10,4 +10,4 @@ $(document).ready(function() } } }) -}); \ No newline at end of file +}); diff --git a/module/api/lang/de.php b/module/api/lang/de.php index 94f35208ae..1bde5a3c22 100644 --- a/module/api/lang/de.php +++ b/module/api/lang/de.php @@ -64,9 +64,9 @@ $lang->api->allLibs = "AllLibs"; /* Common access control lang. */ $lang->api->whiteList = 'Whitelist'; -$lang->api->aclList['open'] = 'Open'; -$lang->api->aclList['private'] = 'Private'; -$lang->api->aclList['custom'] = 'Custom'; +$lang->api->aclList['open'] = "Public (Users who can access doccan access it)"; +$lang->api->aclList['default'] = "Default (Users who can access the selected %s or users in the whiltelist can access it)"; +$lang->api->aclList['private'] = "Private (Only the one who created it or users in the whiltelist can access it)"; $lang->api->group = 'Group'; $lang->api->user = 'User'; @@ -148,6 +148,10 @@ $lang->api->default = 'Default'; $lang->api->desc = 'Beschreibung'; $lang->api->customType = 'Custom Structure'; $lang->api->format = 'Format'; +$lang->api->libType = 'Api Library Type'; +$lang->api->product = $lang->productCommon; +$lang->api->project = $lang->projectCommon; + $lang->api->methodOptions = array( 'GET' => 'GET', 'POST' => 'POST', @@ -169,6 +173,10 @@ $lang->api->requestTypeOptions['application/json'] = 'applicati $lang->api->requestTypeOptions['application/x-www-form-urlencoded'] = 'application/x-www-form-urlencoded'; $lang->api->requestTypeOptions['multipart/form-data'] = 'multipart/form-data'; +$lang->api->libTypeList = array(); +$lang->api->libTypeList['product'] = $lang->productCommon . ' Api Library'; +$lang->api->libTypeList['project'] = $lang->projectCommon . ' Api Library'; + $lang->api->statusOptions = array( 'done' => 'Done', 'doing' => 'Doing', diff --git a/module/api/lang/en.php b/module/api/lang/en.php index 75daf52e85..7c03c6cedb 100644 --- a/module/api/lang/en.php +++ b/module/api/lang/en.php @@ -64,9 +64,9 @@ $lang->api->allLibs = "AllLibs"; /* Common access control lang. */ $lang->api->whiteList = 'Whitelist'; -$lang->api->aclList['open'] = 'Open'; -$lang->api->aclList['private'] = 'Private'; -$lang->api->aclList['custom'] = 'Custom'; +$lang->api->aclList['open'] = "Public (Users who can access doccan access it)"; +$lang->api->aclList['default'] = "Default (Users who can access the selected %s or users in the whiltelist can access it)"; +$lang->api->aclList['private'] = "Private (Only the one who created it or users in the whiltelist can access it)"; $lang->api->group = 'Group'; $lang->api->user = 'User'; @@ -148,6 +148,10 @@ $lang->api->default = 'Default'; $lang->api->desc = 'Description'; $lang->api->customType = 'Custom Structure'; $lang->api->format = 'Format'; +$lang->api->libType = 'Api Library Type'; +$lang->api->product = $lang->productCommon; +$lang->api->project = $lang->projectCommon; + $lang->api->methodOptions = array( 'GET' => 'GET', 'POST' => 'POST', @@ -169,6 +173,10 @@ $lang->api->requestTypeOptions['application/json'] = 'applicati $lang->api->requestTypeOptions['application/x-www-form-urlencoded'] = 'application/x-www-form-urlencoded'; $lang->api->requestTypeOptions['multipart/form-data'] = 'multipart/form-data'; +$lang->api->libTypeList = array(); +$lang->api->libTypeList['product'] = $lang->productCommon . ' Api Library'; +$lang->api->libTypeList['project'] = $lang->projectCommon . ' Api Library'; + $lang->api->statusOptions = array( 'done' => 'Done', 'doing' => 'Doing', diff --git a/module/api/lang/fr.php b/module/api/lang/fr.php index 52e2fdfa2f..742931b2b8 100644 --- a/module/api/lang/fr.php +++ b/module/api/lang/fr.php @@ -64,9 +64,9 @@ $lang->api->allLibs = "AllLibs"; /* Common access control lang. */ $lang->api->whiteList = 'Whitelist'; -$lang->api->aclList['open'] = 'Open'; -$lang->api->aclList['private'] = 'Private'; -$lang->api->aclList['custom'] = 'Custom'; +$lang->api->aclList['open'] = "Public (Users who can access doccan access it)"; +$lang->api->aclList['default'] = "Default (Users who can access the selected %s or users in the whiltelist can access it)"; +$lang->api->aclList['private'] = "Private (Only the one who created it or users in the whiltelist can access it)"; $lang->api->group = 'Group'; $lang->api->user = 'User'; @@ -148,6 +148,10 @@ $lang->api->default = 'Default'; $lang->api->desc = 'Description'; $lang->api->customType = 'Custom Structure'; $lang->api->format = 'Format'; +$lang->api->libType = 'Api Library Type'; +$lang->api->product = $lang->productCommon; +$lang->api->project = $lang->projectCommon; + $lang->api->methodOptions = array( 'GET' => 'GET', 'POST' => 'POST', @@ -169,6 +173,10 @@ $lang->api->requestTypeOptions['application/json'] = 'applicati $lang->api->requestTypeOptions['application/x-www-form-urlencoded'] = 'application/x-www-form-urlencoded'; $lang->api->requestTypeOptions['multipart/form-data'] = 'multipart/form-data'; +$lang->api->libTypeList = array(); +$lang->api->libTypeList['product'] = $lang->productCommon . ' Api Library'; +$lang->api->libTypeList['project'] = $lang->projectCommon . ' Api Library'; + $lang->api->statusOptions = array( 'done' => 'Done', 'doing' => 'Doing', diff --git a/module/api/lang/zh-cn.php b/module/api/lang/zh-cn.php index 08ae3a58e8..f8c54f79eb 100755 --- a/module/api/lang/zh-cn.php +++ b/module/api/lang/zh-cn.php @@ -64,9 +64,9 @@ $lang->api->allLibs = "全部接口库"; /* Common access control lang. */ $lang->api->whiteList = '白名单'; -$lang->api->aclList['open'] = '公开'; -$lang->api->aclList['private'] = '私有'; -$lang->api->aclList['custom'] = '自定义'; +$lang->api->aclList['open'] = "公开 (有文档视图权限即可访问)"; +$lang->api->aclList['default'] = "默认 (有所选%s访问权限用户和白名单用户可以访问)"; +$lang->api->aclList['private'] = "私有 (仅创建者和白名单用户可访问)"; $lang->api->group = '分组'; $lang->api->user = '用户'; @@ -102,7 +102,7 @@ $lang->api->structType = '类型'; $lang->api->structAttr = '属性'; $lang->api->structAddedBy = '创建人'; $lang->api->structAddedDate = '创建时间'; -$lang->api->name = '接口库名称'; +$lang->api->name = '库名称'; $lang->api->baseUrl = '请求基础路径'; $lang->api->baseUrlDesc = '网址或者路径,比如 test.zentao.net 或者 /v1'; $lang->api->desc = '描述'; @@ -148,6 +148,10 @@ $lang->api->default = '默认值'; $lang->api->desc = '描述'; $lang->api->customType = '自定义结构'; $lang->api->format = '格式化'; +$lang->api->libType = '接口库类型'; +$lang->api->product = '所属' . $lang->productCommon; +$lang->api->project = '所属' . $lang->projectCommon; + $lang->api->methodOptions = array( 'GET' => 'GET', 'POST' => 'POST', @@ -169,6 +173,10 @@ $lang->api->requestTypeOptions['application/json'] = 'applicati $lang->api->requestTypeOptions['application/x-www-form-urlencoded'] = 'application/x-www-form-urlencoded'; $lang->api->requestTypeOptions['multipart/form-data'] = 'multipart/form-data'; +$lang->api->libTypeList = array(); +$lang->api->libTypeList['product'] = $lang->productCommon . '接口库'; +$lang->api->libTypeList['project'] = $lang->projectCommon . '接口库'; + $lang->api->statusOptions = array( 'done' => '开发完成', 'doing' => '开发中', diff --git a/module/api/view/createlib.html.php b/module/api/view/createlib.html.php index 022dea2f63..41d2fb0409 100644 --- a/module/api/view/createlib.html.php +++ b/module/api/view/createlib.html.php @@ -18,29 +18,45 @@