DocItemPanel.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**
  2. * 文档目录+文档编辑
  3. */
  4. Ext.define('saas.view.help.DocItemPanel', {
  5. extend: 'Ext.container.Container',
  6. xtype: 'help-docitem-panel',
  7. requires: ['Ext.ux.form.FilterField', 'Ext.tree.Panel', 'Ext.tree.plugin.TreeViewDragDrop', 'Ext.form.field.HtmlEditor'],
  8. controller: 'help-docitem-panel',
  9. viewModel: {
  10. data: {
  11. project: {
  12. name: null
  13. },
  14. article: {
  15. id: null,
  16. itemName: null,
  17. contentHtml: null
  18. },
  19. articlePath: null
  20. },
  21. stores: {
  22. treeStore: {
  23. type: 'tree',
  24. filterer: 'bottomup',
  25. itemMapper: function (item) {
  26. var me = this, node = {
  27. raw: item,
  28. id: item.id,
  29. text: item.name
  30. };
  31. if (item.article) {
  32. node.leaf = true;
  33. } else if (item.children) {
  34. node.children = item.children.map(i => {
  35. return me.itemMapper(i);
  36. });
  37. }
  38. return node;
  39. },
  40. transformAndLoad: function (items) {
  41. var me = this, data = items ? items.map(i => {
  42. return me.itemMapper(i);
  43. }) : [];
  44. me.setRoot({
  45. expanded: true,
  46. children: data
  47. });
  48. }
  49. }
  50. }
  51. },
  52. listeners: {
  53. boxready: 'onViewReady'
  54. },
  55. layout: 'border',
  56. items: [{
  57. xtype: 'container',
  58. region: 'center',
  59. layout: {
  60. type: 'vbox',
  61. pack: 'start',
  62. align: 'stretch'
  63. },
  64. items: [{
  65. xtype: 'toolbar',
  66. margin: '0 0 12 0',
  67. padding: '10 5 10 12',
  68. height: 52,
  69. items: [{
  70. xtype: 'tbtext',
  71. bind: {
  72. text: '{articlePath}'
  73. }
  74. }, {
  75. xtype: 'tbfill'
  76. }, {
  77. text: '预览',
  78. handler: 'handleViewArticle',
  79. bind: {
  80. disabled: '{!article.id}'
  81. }
  82. }, {
  83. text: '保存',
  84. handler: 'handleSaveArticle',
  85. bind: {
  86. disabled: '{!article.id}'
  87. }
  88. }]
  89. }, {
  90. flex: 1,
  91. padding: 0,
  92. margin: 0,
  93. xtype: 'htmleditor',
  94. bind: {
  95. readOnly: '{!article.id}',
  96. value: '{article.contentHtml}',
  97. textValue: '{article.contentText}'
  98. },
  99. iframePad: 10,
  100. cls: 'doc-editor'
  101. }]
  102. }, {
  103. region: 'west',
  104. collapsible: true,
  105. width: 300,
  106. ui: 'simple',
  107. bind: {
  108. title: '{project.name}'
  109. },
  110. layout: 'fit',
  111. margin: '0 10 0 0',
  112. tools: [{
  113. iconCls: 'x-fa fa-plus',
  114. items: [{
  115. text: '新建文件夹',
  116. handler: 'handleCreateFolder'
  117. }, {
  118. text: '新建文档',
  119. handler: 'handleCreateItem'
  120. }]
  121. }],
  122. items: [{
  123. ui: 'simple',
  124. xtype: 'treepanel',
  125. reference: 'tree',
  126. checkPropagation: 'both',
  127. rootVisible: false,
  128. bufferedRenderer: false,
  129. animate: true,
  130. bind: {
  131. store: '{treeStore}'
  132. },
  133. tbar: {
  134. ui: 'simple',
  135. layout: 'fit',
  136. padding: '0 8 6 8',
  137. items: [{
  138. xtype: 'filterfield',
  139. bind: {
  140. store: '{treeStore}'
  141. },
  142. filterName: 'text',
  143. emptyText: '搜索'
  144. }]
  145. },
  146. listeners: {
  147. selectionchange: 'onItemSelect'
  148. },
  149. viewConfig: {
  150. plugins: {
  151. treeviewdragdrop: {
  152. containerScroll: true
  153. }
  154. },
  155. listeners: {
  156. drop: 'onItemDragDrop'
  157. }
  158. },
  159. hideHeaders: true,
  160. columns: [{
  161. xtype: 'treecolumn',
  162. dataIndex: 'text',
  163. flex: 1
  164. }, {
  165. xtype: 'actioncolumn',
  166. tdCls: 'x-over-visible',
  167. iconCls: 'x-fa fa-ellipsis-h',
  168. width: 25,
  169. handler: function (view, rowIndex, colIndex, item, e) {
  170. var rec = view.getStore().getAt(rowIndex),
  171. raw = rec.get('raw'), items = [{
  172. text: '重命名',
  173. handler: 'handleEditItem'
  174. }, {
  175. text: '删除',
  176. handler: 'handleDeleteItem'
  177. }];
  178. if (!raw.article) {
  179. items = Ext.Array.merge([/* {
  180. text: '新建文件夹',
  181. handler: 'handleCreateFolder'
  182. }, */{
  183. text: '新建文档',
  184. handler: 'handleCreateItem'
  185. }, '-'], items);
  186. }
  187. Ext.create('Ext.menu.Menu', {
  188. width: 100,
  189. margin: '0 0 10 0',
  190. record: rec,
  191. items: items,
  192. ownerCmp: view
  193. }).showAt(e.getXY());
  194. }
  195. }]
  196. }]
  197. }]
  198. });