HelpDocScan.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.ma.HelpDocScan', {
  3. extend: 'Ext.app.Controller',
  4. stores: ['TreeStore'],
  5. views: ['common.main.TreePanel','ma.logic.Config', 'core.form.ColorField','core.form.FileField',
  6. 'common.main.Toolbar','core.trigger.SearchField', 'core.trigger.DbfindTrigger'],
  7. FormUtil:Ext.create('erp.util.FormUtil'),
  8. refs: [{
  9. ref: 'tree',
  10. selector: '#tree-panel'
  11. },{
  12. ref: 'tabPanel',
  13. selector: '#tabpanel'
  14. }],
  15. init: function(){
  16. var me = this;
  17. me.FormUtil = Ext.create('erp.util.FormUtil');
  18. me.Toast = Ext.create('erp.view.core.window.Toast');
  19. this.control({
  20. 'erpTreePanel': {
  21. itemmousedown: function(selModel, record){
  22. Ext.defer(function(){
  23. me.onNodeClick(selModel, record);
  24. }, 20);
  25. },
  26. beforerender: function(tree) {
  27. if(window.whoami)
  28. tree.hide();
  29. },
  30. afterrender: function(){
  31. var panel = parent.Ext.getCmp('tree-panel');
  32. if(panel && !panel.collapsed) {
  33. panel.toggleCollapse();
  34. }
  35. }
  36. },
  37. 'button[itemId=btn-save]':{
  38. click:function(btn){
  39. me.setHelpDoc(btn.ownerCt.ownerCt);
  40. }
  41. },
  42. 'button[id=btn-scan]':{
  43. click:function(btn){
  44. me.scan();
  45. }
  46. },
  47. 'textfield[name=CALLER_]':{
  48. change:function(field){
  49. Ext.defer(function(){
  50. var field=Ext.ComponentQuery.query('textfield[name=CALLER_]')[0];
  51. var mfield=field.ownerCt.down('mfilefield[name=PATH_]');
  52. if(mfield.items.items[0].value){
  53. mfield.download(mfield.items.items[0].value);
  54. }
  55. },100);
  56. }
  57. }
  58. });
  59. },
  60. onNodeClick: function(selModel, record){
  61. var me = this;
  62. if (record.get('leaf')) {
  63. caller=record.raw.caller;
  64. me.scan(caller);
  65. } else {
  66. if(record.isExpanded() && record.childNodes.length > 0){
  67. record.collapse(true, true);// 已展开则收拢
  68. } else {
  69. //未展开看是否加载了children
  70. if(record.childNodes.length == 0){
  71. me.getChildren(record);
  72. } else {
  73. record.expand(false, true);//展开
  74. }
  75. }
  76. }
  77. },
  78. scan:function(){
  79. Ext.Ajax.request({
  80. url: basePath + 'ma/help/scan.action?caller=' + caller,
  81. method: 'GET',
  82. callback: function(opt, s, r) {
  83. if(r && r.status == 200) {
  84. var res = Ext.JSON.decode(r.responseText);
  85. if(!res.path){
  86. res.path='jsps/ma/helpdocremind.html';
  87. }
  88. var panel=Ext.getCmp('doc-panel');
  89. panel.removeAll();
  90. panel.add({
  91. tag : 'iframe',
  92. layout : 'fit',
  93. html : '<iframe src="' + basePath + res.path + '" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  94. });
  95. }
  96. }
  97. });
  98. },
  99. refreshScan:function(bool){
  100. var btn=Ext.getCmp('btn-scan');
  101. if(btn) btn.setDisabled(!bool);
  102. },
  103. /**
  104. * 从后台加载树节点
  105. */
  106. getChildren: function(record) {
  107. var tree = this.getTree();
  108. tree.setLoading(true, tree.body);
  109. Ext.Ajax.request({//拿到tree数据
  110. url : basePath + 'common/lazyTree.action',
  111. params: {
  112. parentId: record.get('id')
  113. },
  114. callback : function(opt, s, r){
  115. tree.setLoading(false);
  116. var res = new Ext.decode(r.responseText);
  117. if(res.tree && record.childNodes.length == 0){
  118. record.appendChild(res.tree);
  119. record.expand(false, true);//展开
  120. } else if(res.exceptionInfo){
  121. showError(res.exceptionInfo);
  122. }
  123. }
  124. });
  125. },
  126. getSetting: function(caller, title){
  127. var me = this;
  128. if(caller) {
  129. if(caller != me.currCaller) {
  130. me.loadConfigs(caller, function(configs){
  131. me.currCaller = caller;
  132. me.setConfigs(configs);
  133. title && me.getConfigPanel().setTitle(title);
  134. });
  135. me.loadInterceptors(caller, function(interceptors){
  136. me.setInterceptors(interceptors);
  137. var tab = me.getTabPanel();
  138. if(interceptors.length == 0 && !tab.collapsed)
  139. tab.collapse();
  140. else if(interceptors.length > 0 && tab.collapsed)
  141. tab.expand();
  142. });
  143. }
  144. } else {
  145. me.currCaller = null;
  146. }
  147. },
  148. /**
  149. * 配置参数
  150. */
  151. loadConfigs: function(caller, callback) {
  152. Ext.Ajax.request({
  153. url: basePath + 'ma/setting/configs.action?caller=' + caller,
  154. method: 'GET',
  155. callback: function(opt, s, r) {
  156. if(r && r.status == 200) {
  157. var res = Ext.JSON.decode(r.responseText);
  158. callback.call(null, res);
  159. }
  160. }
  161. });
  162. },
  163. /**
  164. * 配置逻辑
  165. */
  166. loadInterceptors: function(caller, callback) {
  167. Ext.Ajax.request({
  168. url: basePath + 'ma/setting/interceptors.action?caller=' + caller,
  169. method: 'GET',
  170. callback: function(opt, s, r) {
  171. if(r && r.status == 200) {
  172. var res = Ext.JSON.decode(r.responseText);
  173. callback.call(null, res);
  174. }
  175. }
  176. });
  177. },
  178. setConfigs: function(configs) {
  179. var me = this, pane = me.getConfigPanel(), items = [];
  180. Ext.Array.each(configs, function(c, i){
  181. switch(c.data_type) {
  182. case 'YN':
  183. items.push({
  184. xtype: 'checkbox',
  185. boxLabel: c.title,
  186. name: c.code,
  187. id: c.id,
  188. checked: c.data == 1,
  189. columnWidth: 1,
  190. margin: c.help ? '4 8 0 8' : '4 8 4 8'
  191. });
  192. break;
  193. case 'RADIO':
  194. var s = [];
  195. Ext.Array.each(c.properties, function(p){
  196. s.push({
  197. name: c.code,
  198. boxLabel: p.display,
  199. inputValue: p.value,
  200. checked: p.value == c.data
  201. });
  202. });
  203. items.push({
  204. xtype: 'radiogroup',
  205. id: c.id,
  206. fieldLabel: c.title,
  207. columnWidth: 1,
  208. columns: 2,
  209. vertical: true,
  210. items: s
  211. });
  212. break;
  213. case 'COLOR':
  214. items.push({
  215. xtype: 'colorfield',
  216. fieldLabel: c.title,
  217. id: c.id,
  218. name: c.code,
  219. value: c.data,
  220. readOnly: c.editable == 0,
  221. editable: c.editable == 1,
  222. labelWidth: 150
  223. });
  224. break;
  225. case 'NUMBER':
  226. items.push({
  227. xtype: 'numberfield',
  228. fieldLabel: c.title,
  229. id: c.id,
  230. name: c.code,
  231. value: c.data,
  232. readOnly: c.editable == 0,
  233. labelWidth: 150
  234. });
  235. break;
  236. default :
  237. if(c.multi == 1) {
  238. var data = c.data ? c.data.split('\n') : [null], s = [];
  239. Ext.Array.each(data, function(d){
  240. s.push({
  241. xtype: (c.dbfind ? 'dbfindtrigger' : 'textfield'),
  242. name: c.dbfind || c.code,
  243. value: d,
  244. readOnly: !c.dbfind && c.editable == 0,
  245. editable: c.editable == 1,
  246. clearable: true
  247. });
  248. });
  249. s.push({
  250. xtype: 'button',
  251. text: '添加',
  252. width: 22,
  253. cls: 'x-dd-drop-ok-add',
  254. iconCls: 'x-dd-drop-icon',
  255. iconAlign: 'right',
  256. config: c
  257. });
  258. items.push({
  259. xtype: 'fieldset',
  260. title: c.title,
  261. id: c.id,
  262. name: c.code,
  263. columnWidth: 1,
  264. layout: 'column',
  265. defaults: {
  266. columnWidth: .25,
  267. margin: '4 8 4 8'
  268. },
  269. items: s
  270. });
  271. } else {
  272. items.push({
  273. xtype: (c.dbfind ? 'dbfindtrigger' : 'textfield'),
  274. fieldLabel: c.title,
  275. id: c.id,
  276. name: c.dbfind || c.code,
  277. value: c.data,
  278. readOnly: !c.dbfind && c.editable == 0,
  279. editable: c.editable == 1,
  280. clearable: true,
  281. columnWidth: .5,
  282. labelWidth: 150
  283. });
  284. }
  285. break;
  286. }
  287. if(c.help) {
  288. items.push({
  289. xtype: 'displayfield',
  290. value: c.help,
  291. columnWidth: ['NUMBER', 'VARCHAR2'].indexOf(c.data_type) > -1 ? .5 : 1,
  292. cls: 'help-block',
  293. margin: '4 8 8 8'
  294. });
  295. } else {
  296. if(['NUMBER', 'VARCHAR2'].indexOf(c.data_type) > -1) {
  297. items.push({
  298. xtype: 'displayfield'
  299. });
  300. }
  301. }
  302. });
  303. pane.removeAll();
  304. if(items.length == 0)
  305. items.push({
  306. html: '没有参数配置',
  307. cls: 'x-form-empty'
  308. });
  309. pane.add(items);
  310. },
  311. /**
  312. * 字符长度
  313. */
  314. getCharLength: function(str) {
  315. if(str) {
  316. for (var len = str.length, c = 0, i = 0; i < len; i++)
  317. str.charCodeAt(i) < 27 || str.charCodeAt(i) > 126 ? c += 2 : c++;
  318. return c;
  319. }
  320. return 0;
  321. }
  322. });