edit.html.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. <?php
  2. namespace zin;
  3. $apiHeader = $apiQuery = $apiParams = $apiResponse = array();
  4. $defaultTR = function()
  5. {
  6. return h::tr
  7. (
  8. setClass('input-row'),
  9. h::td
  10. (
  11. input
  12. (
  13. set::name('')
  14. )
  15. ),
  16. h::td
  17. (
  18. html("<input type='checkbox' />")
  19. ),
  20. h::td
  21. (
  22. textarea
  23. (
  24. set::rows(1)
  25. )
  26. ),
  27. h::td
  28. (
  29. div(setClass('pl-2 flex self-center line-btn'), btn
  30. (
  31. setClass('btn ghost btn-add'),
  32. icon('plus')
  33. ), btn
  34. (
  35. setClass('btn ghost btn-delete'),
  36. icon('trash')
  37. ))
  38. )
  39. );
  40. };
  41. if(!empty($api->params['header']))
  42. {
  43. foreach($api->params['header'] as $param)
  44. {
  45. $apiHeader[] = h::tr
  46. (
  47. setClass('input-row'),
  48. h::td
  49. (
  50. input
  51. (
  52. set::name(''),
  53. set::value($param['field'])
  54. )
  55. ),
  56. h::td
  57. (
  58. $param['required'] ? html("<input type='checkbox' checked/>") : html("<input type='checkbox'/>")
  59. ),
  60. h::td
  61. (
  62. textarea
  63. (
  64. set::rows(1),
  65. set::value($param['desc'])
  66. )
  67. ),
  68. h::td
  69. (
  70. div
  71. (
  72. setClass('pl-2 flex self-center line-btn'),
  73. btn
  74. (
  75. setClass('btn ghost btn-add'),
  76. icon('plus')
  77. ),
  78. btn
  79. (
  80. setClass('btn ghost btn-delete'),
  81. icon('trash')
  82. )
  83. )
  84. )
  85. );
  86. }
  87. }
  88. else
  89. {
  90. $apiHeader[] = $defaultTR();
  91. }
  92. if(!empty($api->params['query']))
  93. {
  94. foreach($api->params['query'] as $query)
  95. {
  96. $apiQuery[] = h::tr
  97. (
  98. setClass('input-row'),
  99. h::td
  100. (
  101. input
  102. (
  103. set::name(''),
  104. set::value($query['field'])
  105. )
  106. ),
  107. h::td
  108. (
  109. $query['required'] ? html("<input type='checkbox' checked/>") : html("<input type='checkbox'/>")
  110. ),
  111. h::td
  112. (
  113. textarea
  114. (
  115. set::rows(1),
  116. set::value($query['desc'])
  117. )
  118. ),
  119. h::td
  120. (
  121. div
  122. (
  123. setClass('pl-2 flex self-center line-btn'),
  124. btn
  125. (
  126. setClass('btn ghost btn-add'),
  127. icon('plus')
  128. ),
  129. btn
  130. (
  131. setClass('btn ghost btn-delete'),
  132. icon('trash')
  133. )
  134. )
  135. )
  136. );
  137. }
  138. }
  139. else
  140. {
  141. $apiQuery[] = $defaultTR();
  142. }
  143. $parseTree = function($data, $typeList, $level = 0) use (&$parseTree)
  144. {
  145. global $lang;
  146. $hidden = $data['paramsType'] == 'formData' ? 'hidden' : '';
  147. $tbody[] = h::tr
  148. (
  149. setClass('input-row'),
  150. setData(array('level' => $level + 1, 'key' => $data['key'], 'parent' => isset($data['parentKey']) ? $data['parentKey'] : 0)),
  151. h::td
  152. (
  153. $level ? setStyle('padding-left', ($level + 1) * 10 . 'px') : null,
  154. input
  155. (
  156. set::name(''),
  157. set::value($data['field'])
  158. )
  159. ),
  160. h::td
  161. (
  162. select
  163. (
  164. setClass('objectType'),
  165. set::name(''),
  166. set::value($data['paramsType']),
  167. set::items($typeList)
  168. )
  169. ),
  170. h::td
  171. (
  172. $data['required'] ? html("<input type='checkbox' checked/>") : html("<input type='checkbox'/>")
  173. ),
  174. h::td
  175. (
  176. textarea
  177. (
  178. set::rows(1),
  179. set::value($data['desc'])
  180. )
  181. ),
  182. h::td
  183. (
  184. div
  185. (
  186. setClass('pl-2 flex self-center line-btn'),
  187. btn
  188. (
  189. setClass("btn ghost btn-split $hidden"),
  190. icon('split')
  191. ),
  192. btn
  193. (
  194. setClass('btn ghost btn-add'),
  195. icon('plus')
  196. ),
  197. btn
  198. (
  199. setClass('btn ghost btn-delete'),
  200. icon('trash')
  201. )
  202. )
  203. )
  204. );
  205. if(isset($data['children']) && count($data['children']) > 0)
  206. {
  207. $level++;
  208. foreach($data['children'] as $item) $tbody[] = $parseTree($item, $typeList, $level);
  209. }
  210. return $tbody;
  211. };
  212. if(!empty($api->params['params']))
  213. {
  214. foreach($api->params['params'] as $param) $apiParams = array_merge($apiParams, $parseTree($param, $typeOptions));
  215. }
  216. else
  217. {
  218. $apiParams[] = h::tr
  219. (
  220. setClass('input-row'),
  221. setData(array('level' => 1, 'key' => 'origin', 'parent' => '0')),
  222. h::td
  223. (
  224. input
  225. (
  226. set::name('')
  227. )
  228. ),
  229. h::td
  230. (
  231. select
  232. (
  233. setClass('objectType'),
  234. set::name(''),
  235. set::value('object'),
  236. set::items($lang->api->paramsTypeOptions)
  237. )
  238. ),
  239. h::td
  240. (
  241. html("<input type='checkbox' />")
  242. ),
  243. h::td
  244. (
  245. textarea
  246. (
  247. set::rows(1)
  248. )
  249. ),
  250. h::td
  251. (
  252. div
  253. (
  254. setClass('pl-2 flex self-center line-btn'),
  255. btn
  256. (
  257. setClass('btn ghost btn-split hidden'),
  258. icon('split')
  259. ),
  260. btn
  261. (
  262. setClass('btn ghost btn-add'),
  263. icon('plus')
  264. ),
  265. btn
  266. (
  267. setClass('btn ghost btn-delete'),
  268. icon('trash')
  269. )
  270. )
  271. )
  272. );
  273. }
  274. if(!empty($api->response))
  275. {
  276. foreach($api->response as $param) $apiResponse = array_merge($apiResponse, $parseTree($param, $typeOptions));
  277. }
  278. else
  279. {
  280. $apiResponse[] = h::tr
  281. (
  282. setClass('input-row'),
  283. setData(array('level' => 1, 'key' => 'origin', 'parent' => '0')),
  284. h::td
  285. (
  286. input
  287. (
  288. set::name('')
  289. )
  290. ),
  291. h::td
  292. (
  293. select
  294. (
  295. setClass('objectType'),
  296. set::name(''),
  297. set::value('object'),
  298. set::items($lang->api->paramsTypeOptions)
  299. )
  300. ),
  301. h::td
  302. (
  303. html("<input type='checkbox' />")
  304. ),
  305. h::td
  306. (
  307. textarea
  308. (
  309. set::rows(1)
  310. )
  311. ),
  312. h::td
  313. (
  314. div
  315. (
  316. setClass('pl-2 flex self-center line-btn'),
  317. btn
  318. (
  319. setClass('btn ghost btn-split'),
  320. icon('split')
  321. ),
  322. btn
  323. (
  324. setClass('btn ghost btn-add'),
  325. icon('plus')
  326. ),
  327. btn
  328. (
  329. setClass('btn ghost btn-delete'),
  330. icon('trash')
  331. )
  332. )
  333. )
  334. );
  335. }
  336. formPanel
  337. (
  338. to::heading
  339. (
  340. div
  341. (
  342. setClass('panel-title text-lg'),
  343. $title
  344. )
  345. ),
  346. formGroup
  347. (
  348. set::width('1/2'),
  349. set::label($lang->api->module),
  350. picker
  351. (
  352. set::items($moduleOptionMenu),
  353. set::name('module'),
  354. set::value($api->module),
  355. set::required(true)
  356. )
  357. ),
  358. formGroup
  359. (
  360. set::width('1/2'),
  361. set::required(true),
  362. set::label($lang->api->title),
  363. input
  364. (
  365. set::name('title'),
  366. set::value($api->title)
  367. )
  368. ),
  369. formRow
  370. (
  371. formGroup
  372. (
  373. set::width('330px'),
  374. set::required(true),
  375. set::label($lang->api->path),
  376. inputGroup
  377. (
  378. picker
  379. (
  380. set::required(true),
  381. set::items($lang->api->protocalOptions),
  382. set::name('protocol'),
  383. set::value($api->protocol)
  384. ),
  385. picker
  386. (
  387. set::required(true),
  388. set::width('1/5'),
  389. set::items($lang->api->methodOptions),
  390. set::name('method'),
  391. set::value($api->method)
  392. )
  393. )
  394. ),
  395. formGroup
  396. (
  397. input
  398. (
  399. set::name('path'),
  400. set::value($api->path)
  401. )
  402. )
  403. ),
  404. formGroup
  405. (
  406. set::width('2/5'),
  407. set::label($lang->api->requestType),
  408. picker
  409. (
  410. set::name('requestType'),
  411. set::value($api->requestType),
  412. set::items($lang->api->requestTypeOptions)
  413. )
  414. ),
  415. formGroup
  416. (
  417. set::label($lang->api->status),
  418. radioList
  419. (
  420. set::name('status'),
  421. set::inline(true),
  422. set::value($api->status),
  423. set::items($lang->api->statusOptions)
  424. )
  425. ),
  426. formGroup
  427. (
  428. set::width('2/5'),
  429. set::label($lang->api->owner),
  430. picker
  431. (
  432. set::name('owner'),
  433. set::items($allUsers),
  434. set::value($api->owner)
  435. )
  436. ),
  437. formGroup
  438. (
  439. setID('form-header'),
  440. setClass('params-group'),
  441. set::label($lang->api->header),
  442. h::table
  443. (
  444. setClass('table condensed bordered'),
  445. h::tr
  446. (
  447. h::th
  448. (
  449. width('300px'),
  450. $lang->struct->field
  451. ),
  452. h::th
  453. (
  454. width('70px'),
  455. $lang->struct->required
  456. ),
  457. h::th
  458. (
  459. $lang->struct->desc
  460. ),
  461. h::th
  462. (
  463. width('100px')
  464. )
  465. ),
  466. $apiHeader
  467. )
  468. ),
  469. formGroup
  470. (
  471. setID('form-query'),
  472. setClass('params-group'),
  473. set::label($lang->api->query),
  474. h::table
  475. (
  476. setClass('table condensed bordered'),
  477. h::tr
  478. (
  479. h::th
  480. (
  481. width('300px'),
  482. $lang->struct->field
  483. ),
  484. h::th
  485. (
  486. width('70px'),
  487. $lang->struct->required
  488. ),
  489. h::th
  490. (
  491. $lang->struct->desc
  492. ),
  493. h::th
  494. (
  495. width('100px')
  496. )
  497. ),
  498. $apiQuery
  499. )
  500. ),
  501. formGroup
  502. (
  503. setID('form-paramsType'),
  504. setClass('params-group'),
  505. set::label($lang->struct->type),
  506. radioList
  507. (
  508. set::name('type'),
  509. set::inline(true),
  510. set::value(!empty($api->params['paramsType']) ? $api->params['paramsType'] : ''),
  511. set::items($lang->struct->typeOptions)
  512. )
  513. ),
  514. formGroup
  515. (
  516. setID('form-params'),
  517. setClass('params-group'),
  518. set::label($lang->api->params),
  519. h::table
  520. (
  521. setClass('table condensed bordered'),
  522. h::tr
  523. (
  524. h::th
  525. (
  526. width('300px'),
  527. $lang->struct->field
  528. ),
  529. h::th
  530. (
  531. width('100px'),
  532. $lang->struct->paramsType
  533. ),
  534. h::th
  535. (
  536. width('70px'),
  537. $lang->struct->required
  538. ),
  539. h::th
  540. (
  541. $lang->struct->desc
  542. ),
  543. h::th
  544. (
  545. width('100px')
  546. )
  547. ),
  548. $apiParams
  549. )
  550. ),
  551. formHidden('params', json_encode($api->params)),
  552. formGroup
  553. (
  554. set::width('1/2'),
  555. set::label($lang->api->paramsExample),
  556. textarea
  557. (
  558. set::name('paramsExample'),
  559. set::value($api->paramsExample)
  560. )
  561. ),
  562. formGroup
  563. (
  564. setID('form-response'),
  565. setClass('response'),
  566. set::label($lang->api->response),
  567. h::table
  568. (
  569. setClass('table condensed bordered'),
  570. h::tr
  571. (
  572. h::th
  573. (
  574. width('300px'),
  575. $lang->struct->field
  576. ),
  577. h::th
  578. (
  579. width('100px'),
  580. $lang->struct->paramsType
  581. ),
  582. h::th
  583. (
  584. width('70px'),
  585. $lang->struct->required
  586. ),
  587. h::th
  588. (
  589. $lang->struct->desc
  590. ),
  591. h::th
  592. (
  593. width('100px')
  594. )
  595. ),
  596. $apiResponse
  597. )
  598. ),
  599. formHidden('response', json_encode($api->response)),
  600. formGroup
  601. (
  602. set::width('1/2'),
  603. set::label($lang->api->responseExample),
  604. textarea
  605. (
  606. set::name('responseExample'),
  607. set::value($api->responseExample)
  608. )
  609. ),
  610. formGroup
  611. (
  612. set::label($lang->api->desc),
  613. editor
  614. (
  615. set::name('desc'),
  616. html($api->desc)
  617. )
  618. ),
  619. formHidden('editedDate', $api->editedDate)
  620. );