browse.ui.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. /**
  2. * 重写文档应用的配置选项方法。
  3. * Override the method to set the doc app options.
  4. */
  5. window._setDocAppOptions = window.setDocAppOptions; // Save the original method.
  6. window.setDocAppOptions = function(_, options) // Override the method.
  7. {
  8. options = window._setDocAppOptions(_, options);
  9. currentUser = options.currentUser;
  10. return $.extend(options,
  11. {
  12. getTableOptions : getTableOptions,
  13. onSaveDoc : handleSaveDoc,
  14. customRenders : $.extend(docAppCustomRenders, customRenders),
  15. getDocViewSidebarTabs: getDocViewSidebarTabs,
  16. viewModeUrl : getViewModeUrl,
  17. isMatchFilter : isMatchFilter,
  18. diffEnabled : false
  19. });
  20. };
  21. const customRenders =
  22. {
  23. 'app-nav': function(items)
  24. {
  25. const docApp = getDocApp();
  26. if(docApp.mode == 'view')
  27. {
  28. const doc = docApp.doc;
  29. if(doc.data.status == 'pause')
  30. {
  31. const docIndex = items.findIndex(item => item[0] === 'current');
  32. const versionView = items[docIndex][1];
  33. const statusLabel = zui.renderCustomContent({className: 'label gray-pale rounded-full ml-1', content: getDocAppLang('pauseText')});
  34. items[docIndex] = ['current', [versionView, statusLabel]];
  35. }
  36. }
  37. return items;
  38. },
  39. toolbar: function()
  40. {
  41. if(this.mode == 'list')
  42. {
  43. const items = [];
  44. if(docAppHasPriv('create')) items.push({text: getDocAppLang('create'), icon: 'plus', btnType: 'primary', command: 'createTemplate'});
  45. return {component: 'toolbar', props: {items: items}};
  46. }
  47. },
  48. 'sidebar-footer-hint': function()
  49. {
  50. return '';
  51. }
  52. }
  53. /**
  54. * 获取查看视图的 URL,用于更新浏览器地址栏。
  55. * Get the view mode URL for updating the browser address bar.
  56. */
  57. function getViewModeUrl(options)
  58. {
  59. if(options.mode == 'view') return $.createLink('reporttemplate', 'view', `templateID=${options.docID}`);
  60. if(options.mode == 'edit') return $.createLink('reporttemplate', 'edit', `templateID=${options.docID}`);
  61. return $.createLink('reporttemplate', 'browse', `libID=${options.libID}&moduleID=${options.moduleID}`);
  62. }
  63. /**
  64. * 获取模板界面上的表格初始化选项。
  65. * Get the table initialization options on the doc UI.
  66. *
  67. * @param {object} options
  68. * @param {object} info
  69. * @returns {object}
  70. */
  71. function getTableOptions(options, info)
  72. {
  73. const lang = getDocAppLang('tableCols');
  74. options.data.sort((a, b) => a.id > b.id ? -1 : 1); // Sort by id desc.
  75. const templateCols = [];
  76. templateCols.push({...options.cols.find(col => col.name === 'rawID'), type: 'id'});
  77. /* Set table column. */
  78. let titleCol = options.cols.find(col => col.name == 'title');
  79. let cycleCol = {name: 'cycle', title: lang.cycle, type: 'category', sort: true};
  80. let moduleCol = {name: 'moduleName', title: lang.module, type: 'string', sort: true};
  81. let objectsCol = {name: 'objectsName', title: lang.objects, type: 'desc', sort: true};
  82. let addedByCol = options.cols.find(col => col.name == 'addedBy');
  83. let addedDateCol = options.cols.find(col => col.name == 'addedDate');
  84. let descCol = {name: 'templateDesc', title: lang.desc, type: 'desc', sort: true}
  85. let actionsCol = options.cols.find(col => col.name == 'actions');
  86. titleCol.title = lang.title;
  87. actionsCol.width = '125';
  88. templateCols.push(titleCol);
  89. templateCols.push(cycleCol);
  90. templateCols.push(moduleCol);
  91. templateCols.push(objectsCol);
  92. templateCols.push(addedByCol);
  93. templateCols.push(addedDateCol);
  94. templateCols.push(descCol);
  95. templateCols.push(actionsCol);
  96. options.cols = templateCols;
  97. /* Set table actions. */
  98. options.cols.forEach(col =>
  99. {
  100. if(col.name === 'actions' && col.actionsMap)
  101. {
  102. col.actions = col.actions.filter(action => (action !== 'move' && docAppHasPriv(action)));
  103. delete col.actionsMap.move;
  104. const actionsLang = getDocAppLang('actions');
  105. const privMap = {edit: docAppHasPriv('edit'), pause: docAppHasPriv('pause'), cron: docAppHasPriv('cron'), delete: docAppHasPriv('delete')};
  106. $.each(col.actionsMap, (key, value) =>
  107. {
  108. value.disabled = !privMap[key];
  109. });
  110. }
  111. });
  112. options.onRenderCell = function(result, info)
  113. {
  114. if(info.col.name == 'title' && result)
  115. {
  116. const template = info.row.data;
  117. if(template.status == 'pause') result[result.length] = {html: '<span class="label gray-pale rounded-full ml-1 flex-none nowrap">' + getDocAppLang('pauseText') + '</span>'};
  118. }
  119. return result;
  120. }
  121. options.actionsCreator = function(item, info)
  122. {
  123. const template = item.row.data;
  124. const actionsLang = getDocAppLang('actions');
  125. const actions = [
  126. docAppHasPriv('edit') ? {icon: 'edit', 'hint': actionsLang.editTemplate, command: `startEditDoc/${template.id}`} : null,
  127. docAppHasPriv('pause') ? {icon: 'pause', 'hint': actionsLang.pauseTemplate, command: `pauseDoc/${template.id}`, disabled: template.status != 'normal', 'hint': template.status == 'draft' ? getDocAppLang('disabledPauseHint') : getDocAppLang('pauseText')} : null,
  128. docAppHasPriv('cron') ? {icon: 'clock', 'hint': actionsLang.cron, command: `cronConfig/${template.id}`} : null,
  129. docAppHasPriv('delete') ? {icon: 'trash', 'hint': actionsLang.deleteTemplate, command: `deleteDoc/${template.id}`, disabled: template.builtIn != 0, 'hint': template.builtIn != 0 ? getDocAppLang('disabledDeleteHint') : actionsLang.deleteTemplate} : null,
  130. ];
  131. return actions;
  132. }
  133. options.checkable = false;
  134. options.footer = options.footer.filter(f => f !== 'checkbox');
  135. options.footer = options.footer.filter(f => f !== 'checkedInfo');
  136. return options;
  137. }
  138. /**
  139. * 定义报告模板各个视图和 UI 元素的上的操作方法。
  140. * Define the operation methods on the views and UI elements of the report template.
  141. */
  142. $.extend(window.docAppActions,
  143. {
  144. /**
  145. * 定义目录的操作按钮。
  146. * Define the actions on the module page.
  147. */
  148. module: function(info)
  149. {
  150. const lang = getLang('actions');
  151. const items = [];
  152. const module = info.data;
  153. if(docAppHasPriv('editCategory')) items.push({text: lang.editCategory, command: `editModule/${module.id}`});
  154. if(docAppHasPriv('deleteCategory')) items.push({text: lang.deleteCategory, command: `deleteModule/${module.id}`});
  155. if(info.ui === 'sidebar')
  156. {
  157. return [
  158. items.length ? {icon: 'ellipsis-v', caret: false, placement: 'bottom-end', size: 'xs', items: items} : null,
  159. ];
  160. }
  161. return items;
  162. },
  163. /**
  164. * 定义文档库的操作按钮。
  165. * Define the actions of modules.
  166. */
  167. lib: function(info)
  168. {
  169. const items = [];
  170. const lib = info.data;
  171. const libID = lib?.data == undefined ? lib?.id : lib?.data.id;
  172. /* 获取侧边栏没有模块时的操作按钮。 Get actions when sidebar no module. */
  173. if(info.ui === 'sidebar-no-module')
  174. {
  175. if(!docAppHasPriv('addCategory')) return;
  176. return [{text: getLang('addCategory'), command: `addModule/${libID}`, icon: 'plus', type: 'primary-pale'}];
  177. }
  178. if(docAppHasPriv('addCategory')) items.push({text: getLang('addCategory'), command: `addModule/${libID}`});
  179. if(!items.length) return;
  180. return [{type: 'dropdown', icon: 'cog-outline', square: true, caret: false, placement: 'top-end', items: items}];
  181. },
  182. /**
  183. * 定义模板列表的操作按钮。
  184. * Define the actions on the template list.
  185. */
  186. 'doc-list': function(info)
  187. {
  188. /* 文档列表没有文档时的按钮。Actions for empty doc list. */
  189. if(info.ui === 'doc-list-empty')
  190. {
  191. const createLang = getLang('create');
  192. return docAppHasPriv('create') ? [{icon: 'plus', text: createLang, btnType: 'primary', command: 'createTemplate'}] : null;
  193. }
  194. },
  195. /**
  196. * 定义文档编辑时的操作按钮。
  197. * Define the actions on toolbar of the doc editing page.
  198. */
  199. 'doc-edit': function(info)
  200. {
  201. const doc = info.data;
  202. if(!doc) return;
  203. const lang = getLang();
  204. const isToolbar = info.ui === 'toolbar';
  205. const docApp = this;
  206. return [
  207. isToolbar ? {hint: docApp.fullscreen ? lang.exitFullscreen : lang.enterFullscreen, icon: docApp.fullscreen ? 'fullscreen-exit' : 'fullscreen', command: 'toggleFullscreen'} : null,
  208. (isToolbar && docApp.props.showDocHistory !== false) ? {hint: lang.history, icon: 'file-log', command: 'toggleViewSideTab/history'} : null,
  209. (isToolbar && docApp.props.quickEditMenu) ? {hint: lang.insertSystemData, icon: 'controls', command: 'toggleViewSideTab/quick-edit-menu'} : null,
  210. {text: lang.basic, size: 'md', type: 'ghost', command: `showSettingModal/${doc.id}`, icon: 'cog-outline'},
  211. doc.status === 'draft' ? {text: lang.saveDraft, size: 'md', className: 'btn-wide', type: 'secondary', command: `saveDoc/draft`} : null,
  212. {text: lang.release, size: 'md', className: 'btn-wide', type: 'primary', command: `saveDoc`},
  213. {text: lang.cancel, size: 'md', className: 'btn-wide', type: 'primary-outline', command: 'cancelEditDoc'},
  214. ];
  215. },
  216. /**
  217. * 定义模板的操作按钮。
  218. * Define the actions of template.
  219. */
  220. doc: function(info)
  221. {
  222. const lang = getLang();
  223. const doc = info.data;
  224. const isTemplate = doc.templateType !== '';
  225. const canEditDoc = hasPriv('edit');
  226. const isChapter = doc.type === 'chapter';
  227. /* 侧边栏上的文档操作按钮。Doc actions in sidebar. */
  228. if(info.ui === 'sidebar')
  229. {
  230. const moreItems =
  231. [
  232. hasPriv('addChapter') ? {icon: 'plus', text: lang.addSubChapter, command: `addChapter/${doc.id}`} : null,
  233. hasPriv('addChapter') && doc.parent != 0 ? {icon: 'plus', text: lang.addSameChapter, command: `addChapter/${doc.parent}`} : null,
  234. !isTemplate && hasPriv('create') ? {icon: 'plus', text: lang.addSubDoc, command: `startCreateDoc/${doc.id}`} : null,
  235. !isChapter && hasPriv('delete') ? {icon: 'trash', text: lang.delete, command: `deleteDoc/${doc.id}`, disabled: doc.builtIn != 0, 'hint': doc.builtIn != 0 ? getDocAppLang('disabledDeleteHint') : lang.delete} : null,
  236. isChapter && hasPriv('editChapter') ? {icon: 'pencil', text: lang.editChapter, command: `editChapter/${doc.id}`} : null,
  237. isChapter && hasPriv('deleteChapter') ? {icon: 'trash', text: lang.deleteChapter, command: `deleteDoc/${doc.id}`} : null,
  238. ];
  239. return [
  240. moreItems.every(item => item === null) ? null : {icon: 'ellipsis-v', caret: false, placement: 'bottom-end', size: 'xs', items: moreItems}
  241. ];
  242. }
  243. const moreItems = [];
  244. if(hasPriv('delete')) moreItems.push({icon: 'trash', text: lang.delete, command: `deleteDoc/${doc.id}`, disabled: doc.builtIn != 0, 'hint': doc.builtIn != 0 ? getDocAppLang('disabledDeleteHint') : lang.delete});
  245. const docApp = this;
  246. const isOpen = isOpenVersion(config.version);
  247. if(!isOpen && docApp && docApp.mode === 'view' && doc.status != 'draft' && !doc.api && !isTemplate)
  248. {
  249. moreItems.push({icon: 'link', text: getLang('relateObject'), className: 'relateObject-btn', command: 'toggleViewSideTab/relateObject'})
  250. }
  251. const isToolbar = info.ui === 'toolbar';
  252. const isInModal = $(this.element).closest('.modal').length;
  253. const actions = isInModal ? [] : [
  254. isToolbar ? {hint: docApp.fullscreen ? lang.exitFullscreen : lang.enterFullscreen, icon: docApp.fullscreen ? 'fullscreen-exit' : 'fullscreen', command: 'toggleFullscreen'} : null,
  255. docAppHasPriv('cron') ? {hint: lang.cron, icon: 'clock', command: `cronConfig/${doc.id}`} : null,
  256. canEditDoc ? {icon: 'edit', class: doc.editable ? null : 'disabled', type: doc.editable ? 'ghost text-primary' : 'ghost text-gray', hint: doc.editable ? lang.edit : lang.needEditable, rounded: 'lg', command: doc.editable ? 'startEditDoc' : null} : null,
  257. (isToolbar && docApp.props.showDocOutline !== false) ? {hint: lang.docOutline, icon: 'list-box', command: 'toggleViewSideTab/outline'} : null,
  258. (isToolbar && docApp.props.showDocHistory !== false) ? {hint: lang.history, icon: 'file-log', command: 'toggleViewSideTab/history'} : null,
  259. moreItems.length ? {icon: 'icon-ellipsis-v', type: 'dropdown', rounded: 'lg', placement: 'bottom-end', caret: false, items: moreItems} : null,
  260. ];
  261. return actions;
  262. }
  263. });
  264. /* 扩展报告模板命令定义。 Extend the doc app command definition. */
  265. $.extend(window.docAppCommands,
  266. {
  267. createTemplate: function(_, args)
  268. {
  269. const docApp = getDocApp();
  270. const lib = docApp.lib;
  271. const {libID, moduleID} = docApp;
  272. const url = $.createLink('reporttemplate', 'create', `libID=${libID}&moduleID=${moduleID}`);
  273. zui.Modal.open({url: url});
  274. },
  275. showSettingModal: function(_, args)
  276. {
  277. const docApp = getDocApp();
  278. const libID = docApp.libID;
  279. const moduleID = docApp.moduleID;
  280. const docID = args[0] || docApp.docID;
  281. const url = $.createLink('reporttemplate', 'ajaxSetBasic', `libID=${libID}&moduleID=${moduleID}&docID=${docID || 0}`);
  282. zui.Modal.open({url: url});
  283. },
  284. pauseDoc: function(_, args)
  285. {
  286. const docApp = getDocApp();
  287. const docID = args[0] || docApp.docID;
  288. $.ajaxSubmit(
  289. {
  290. confirm: getLang('confirmPause'),
  291. url: $.createLink('reporttemplate', 'pause', `docID=${docID}`),
  292. load: false,
  293. onSuccess: function()
  294. {
  295. loadPage($.createLink('reporttemplate', 'browse', `libID=${docApp.libID}&moduleID=${docApp.moduleID}`));
  296. }
  297. });
  298. },
  299. cronConfig: function(_, args)
  300. {
  301. const docApp = getDocApp();
  302. const docID = args[0] || docApp.docID;
  303. const url = $.createLink('reporttemplate', 'cron', `docID=${docID}`);
  304. zui.Modal.open({url: url});
  305. },
  306. deleteDoc: function(_, args)
  307. {
  308. const docApp = getDocApp();
  309. const docID = args[0] || docApp.docID;
  310. $.ajaxSubmit(
  311. {
  312. confirm: getLang('confirmDelete'),
  313. url: $.createLink('reporttemplate', 'delete', `docID=${docID}`),
  314. load: false,
  315. onSuccess: function()
  316. {
  317. getDocApp().delete('doc', docID);
  318. loadPage($.createLink('reporttemplate', 'browse', `libID=${docApp.libID}&moduleID=${docApp.moduleID}`));
  319. }
  320. });
  321. },
  322. addModule: function(_, args)
  323. {
  324. const docApp = getDocApp();
  325. const scope = args[0];
  326. const url = $.createLink('reporttemplate', 'addCategory', `scopeID=${scope}`);
  327. zui.Modal.open({size: 'sm', url: url});
  328. },
  329. editModule: function(_, args)
  330. {
  331. const docApp = getDocApp();
  332. const moduleID = args[0] || docApp.moduleID;
  333. const url = $.createLink('reporttemplate', 'editCategory', `moduleID=${moduleID}`);
  334. zui.Modal.open({size: 'sm', url: url});
  335. },
  336. deleteModule: function(_, args)
  337. {
  338. const docApp = getDocApp();
  339. const moduleID = args[0] || docApp.moduleID;
  340. $.get($.createLink('reporttemplate', 'ajaxCheckDeleteCategory', `moduleID=${moduleID}`), function(result)
  341. {
  342. if(!result) return zui.Modal.alert(getLang('errorDeleteCategory'));
  343. $.ajaxSubmit(
  344. {
  345. confirm: getLang('confirmDeleteCategory'),
  346. url: $.createLink('reporttemplate', 'deleteCategory', `moduleID=${moduleID}`),
  347. load: false,
  348. onSuccess: function()
  349. {
  350. getDocApp().delete('module', moduleID);
  351. }
  352. })
  353. })
  354. }
  355. });
  356. function handleSaveDoc(doc)
  357. {
  358. const docApp = getDocApp();
  359. if(docApp.isSavingDoc) return;
  360. docApp.isSavingDoc = true;
  361. const url = $.createLink('reporttemplate', 'edit', `templateID=${doc.id}`);
  362. const docData = {
  363. rawContent : doc.content,
  364. status : doc.status || 'normal',
  365. contentType: doc.contentType,
  366. type : 'text',
  367. title : doc.title,
  368. keywords : doc.keywords,
  369. content : doc.html,
  370. uid : (doc.uid || `doc${doc.id}`),
  371. };
  372. if(doc.fromVersion) docData.fromVersion = doc.fromVersion;
  373. return new Promise((resolve, reject) => {
  374. $.ajaxSubmit({'url': url, 'data': docData, 'load': false, 'onComplete': function(result)
  375. {
  376. docApp.isSavingDoc = false;
  377. resolve(result.newDoc);
  378. docApp.cancelEditDoc();
  379. }});
  380. });
  381. }
  382. /**
  383. * 获取快捷编辑菜单项。
  384. * Get the quick edit menu item.
  385. *
  386. * @param {object} item
  387. * @returns {object}
  388. */
  389. window.getQuickEditMenuItem = function(item)
  390. {
  391. const holder = item.holder;
  392. if(holder && !item.command && !item.url)
  393. {
  394. const commandParts = [holder.block ? 'editor$.insertHolderBlock' : 'editor$.insertHolderText', encodeURIComponent(holder.name)];
  395. if(holder.text) commandParts.push(encodeURIComponent(JSON.stringify({text: holder.text, hint: item.text})));
  396. if(holder.data) commandParts.push(encodeURIComponent(JSON.stringify(holder.data)));
  397. return $.extend({url: `#!${commandParts.join('/')}`}, item);
  398. }
  399. return item;
  400. };
  401. window.getDocViewSidebarTabs = function(doc, info)
  402. {
  403. const docApp = getDocApp();
  404. const tabs = [
  405. {key: 'outline', icon: 'list-box', title: getLang('docOutline')},
  406. {key: 'history', icon: 'file-log', title: getLang('history')}
  407. ]
  408. /* 定义快捷编辑菜单标签页。 */
  409. const quickEditMenu = docApp.props.quickEditMenu;
  410. if(quickEditMenu && quickEditMenu.length && docApp.mode == 'edit')
  411. {
  412. tabs.push({
  413. key: 'quick-edit-menu',
  414. icon: 'controls',
  415. render: function(doc)
  416. {
  417. const navHtml = [];
  418. const contentHtml = [];
  419. if(!docApp.quickEditMenuActiveTab) docApp.quickEditMenuActiveTab = quickEditMenu[0].key;
  420. for (const tab of quickEditMenu)
  421. {
  422. const isActive = docApp.quickEditMenuActiveTab === tab.key;
  423. const id = `quick-edit-menu-tab-${tab.key}`;
  424. navHtml.push(`<li class="nav-item"><a class="${isActive ? 'active' : ''}" data-toggle="tab" href="#${id}">${tab.text}</a></li>`);
  425. const itemsCode = zui.jsRaw(tab.items).replaceAll('"', "&quot;").replaceAll('<', '&lt;').replaceAll('>', '&gt;');
  426. contentHtml.push(`<div class="tab-pane fade duration-500${isActive ? ' active in' : ''}" id="${id}" data-key="${tab.key}"><menu zui-create="tree" zui-create-tree="{preserve: 'quick-edit-menu-tree-${tab.key}', items: ${itemsCode}, getItem: window.getQuickEditMenuItem}"></menu></div>`);
  427. }
  428. return {html: `<ul class="nav nav-tabs">${navHtml.join('')}</ul><div class="tab-content">${contentHtml.join('')}</div>`, className: 'quick-edit-menu', executeScript: true};
  429. }
  430. });
  431. }
  432. return tabs;
  433. };
  434. /* 插入禅道列表。*/
  435. window.insertZentaoMeasurement = function(type, props, isNewBlock)
  436. {
  437. if(!isNewBlock) return getDocApp().editor.$.updateHolderText({name: `${type}_${props.blockID}`, text: props.text, hint: props.hint});
  438. getDocApp().editor.$.insertHolderText(`${type}_${props.blockID}`, {text: props.text, hint: props.hint}, props);
  439. };
  440. window.insertExecutionMeasurement = function(e, info)
  441. {
  442. getDocApp().editor.$.insertHolderText(info.item['data-type'], {text: info.item.text, hint: info.item.hint});
  443. };
  444. window.clickHolder = function(info)
  445. {
  446. const docApp = getDocApp();
  447. if(docApp.mode != 'edit') return;
  448. if(!info.holder.data) return;
  449. if(!info.holder.data.blockID) return;
  450. const url = $.createLink('reporttemplate', 'ajaxBuildZentaoMeasurementConfig', `type=${info.holder.data.type}&blockID=${info.holder.data.blockID}`);
  451. zui.Modal.open({url: url});
  452. };
  453. /* 插入图表。*/
  454. window.insertZentaoChart = function(type, blockID, props, replaceBlockID)
  455. {
  456. if(Number(replaceBlockID)) return replaceZentaoChart(replaceBlockID, type, blockID, props);
  457. getDocApp().editor.$.insertCustom(getZentaoChartProps(type, blockID, props));
  458. };
  459. /* 设置图表配置。*/
  460. function getZentaoChartProps(type, blockID, props)
  461. {
  462. if(props && props.isTemplate) blockID = '__TML_ZENTAOCHART__' + blockID;
  463. return $.extend(
  464. {
  465. exportUrl: `exportZentaoChart_${blockID}`,
  466. fetcher: $.createLink('reporttemplate', 'ajaxZentaoChart', `type=${type}&blockID=${blockID}`),
  467. clearBeforeLoad: false
  468. }, props);
  469. }
  470. /* 替换禅道图表。*/
  471. window.replaceZentaoChart = function(oldBlockID, newType, newblockID, props)
  472. {
  473. return updateZentaoChart(oldBlockID, {content: getZentaoChartProps(newType, newblockID, props), renderID: $.guid++});
  474. };
  475. /* 更新禅道图表。*/
  476. window.updateZentaoChart = function(blockID, props)
  477. {
  478. const $block = $('#docApp').find(`.zentao-chart[data-id="${blockID}"]`);
  479. if(!$block.length) return false;
  480. getDocApp().editor.$.updateBlock($block[0], props);
  481. };
  482. /* 从编辑器删除图表。*/
  483. window.deleteZentaoChart = function(blockID)
  484. {
  485. const $block = $('#docApp').find(`.zentao-chart[data-id="${blockID}"]`);
  486. if(!$block.length) return false;
  487. getDocApp().editor.$.deleteBlock($block[0]);
  488. };
  489. /* 插入甘特图。*/
  490. window.insertExecutionChart = function(e, info)
  491. {
  492. const doc = getDocApp().doc;
  493. $.ajaxSubmit({
  494. url: $.createLink('reporttemplate', 'ajaxBuildZentaoChartConfig', `type=${info.item['data-type']}`),
  495. data: {templateID: doc.data.id}
  496. });
  497. }
  498. /**
  499. * 检查文档是否符合筛选条件。
  500. * Check if the doc matches the filter condition.
  501. *
  502. * @param {string} type
  503. */
  504. function isMatchFilter(type, filterType, item)
  505. {
  506. if(type === 'doc')
  507. {
  508. if(filterType === 'createdByMe') return item.addedBy === docAppData.currentUser;
  509. if(filterType === 'draft') return item.status === 'draft';
  510. if(filterType === 'paused') return item.status === 'pause';
  511. if(filterType === 'released') return item.status === 'normal';
  512. }
  513. return true;
  514. }
  515. /* 检查是否是开源版。*/
  516. function isOpenVersion(version) {
  517. return /^\d/.test(version || $('#zuiCSS').attr('href').split('?v=').pop());
  518. }