SourceWindow.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. Ext.define('erp.view.ma.datalimit.SourceWindow', {
  2. extend : 'Ext.window.Window',
  3. alias : 'widget.sourcewindow',
  4. width : '85%',
  5. height :'90%',
  6. layout:'border',
  7. limitId_:null,
  8. title:'<div align="center">设置权限</div>',
  9. closeAction : 'destroy',
  10. table:null,
  11. LimitType:null,
  12. initComponent : function() {
  13. var me = this;
  14. Ext.apply(me,{
  15. items:[me.createQueryGrid(),me.createDataGrid()],
  16. dockedItems: [{
  17. xtype: 'toolbar',
  18. dock: 'top',
  19. ui: 'footer',
  20. items: [{
  21. text: '筛选',
  22. itemId:'query',
  23. iconCls:'x-button-icon-query'
  24. },{
  25. text:'选择数据',
  26. itemId:'selectdata',
  27. iconCls:'x-button-icon-execute',
  28. hidden:me.LimitType!='detail'
  29. },{
  30. text:'生成条件',
  31. itemId:'createSql',
  32. iconCls:'x-button-icon-scan',
  33. hidden:me.LimitType=='detail'
  34. }]
  35. }]
  36. });
  37. this.callParent(arguments);
  38. },
  39. createQueryGrid:function(){
  40. var config={
  41. id:'querygrid',
  42. region:'west',
  43. width:'50%',
  44. foreceFit:true,
  45. columnLines:true,
  46. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  47. clicksToEdit: 1,
  48. listeners: {
  49. beforeedit: function(e){
  50. if(e.field == 'value'){
  51. var record = e.record;
  52. var column = e.column;
  53. var f = record.data['type'];
  54. switch(f){
  55. case 'D':
  56. switch(record.data['relative']){
  57. case 'Between And':
  58. column.setEditor(new erp.view.core.form.FtDateField({
  59. id: f,
  60. name: f
  61. }));break;
  62. default:
  63. column.setEditor(new Ext.form.field.Date({
  64. id: f,
  65. name: f
  66. }));break;
  67. }
  68. break;
  69. case 'S':
  70. switch(record.data['relative']){
  71. case 'Between And':
  72. column.setEditor(new erp.view.core.form.FtField({
  73. id: f,
  74. name: f,
  75. value: e.value
  76. }));break;
  77. default:
  78. column.setEditor(new Ext.form.field.Text({
  79. id: f,
  80. name: f
  81. }));break;
  82. }
  83. break;
  84. case 'N':
  85. switch(record.data['relative']){
  86. case 'Between And':
  87. column.setEditor(new erp.view.core.form.FtNumberField({
  88. id: f,
  89. name: f
  90. }));break;
  91. default:
  92. column.setEditor(new Ext.form.field.Number({
  93. id: f,
  94. name: f
  95. }));break;
  96. }
  97. break;
  98. case 'T':
  99. column.dbfind = record.get('sl_dbfind');
  100. switch(record.data['relative']){
  101. case 'Between And':
  102. column.setEditor(new erp.view.core.form.FtFindField({
  103. id: f,
  104. name: f
  105. }));break;
  106. default:
  107. column.setEditor(new erp.view.core.trigger.DbfindTrigger({
  108. id: f,
  109. name: f
  110. }));break;
  111. }
  112. break;
  113. default:
  114. column.setEditor(null);
  115. }
  116. }
  117. }
  118. }
  119. })],
  120. columns:[{
  121. text:'字段',
  122. dataIndex:'field',
  123. flex:1,
  124. sortable:false,
  125. editor:{
  126. xtype: 'combo',
  127. listConfig:{
  128. maxHeight:180
  129. },
  130. store: Ext.create('Ext.data.Store', {
  131. fields: ['display', 'value','type'],
  132. data :[]
  133. }),
  134. displayField: 'display',
  135. valueField: 'value',
  136. queryMode: 'local',
  137. onTriggerClick:function(trigger){
  138. var me=this,grid=Ext.getCmp('querygrid'),store=this.getStore();
  139. if(store.totalCount<1){
  140. var data=grid.getDataDictionaryData(grid.ownerCt.table);
  141. store.loadData(data);
  142. }
  143. if (!me.readOnly && !me.disabled) {
  144. if (me.isExpanded) {
  145. me.collapse();
  146. } else {
  147. me.expand();
  148. }
  149. me.inputEl.focus();
  150. }
  151. }
  152. },
  153. processEvent : function(type, view, cell, recordIndex, cellIndex, e) {
  154. if (type == 'click' || type == 'dbclick') {
  155. return true;
  156. }
  157. return false;
  158. },
  159. renderer : function(val, meta, record, x, y, store, view) {
  160. if (val) {
  161. var column = view.ownerCt.headerCt.getHeaderAtIndex(y);
  162. if(column && typeof column.getEditor != 'undefined') {
  163. var editor = column.getEditor(record);
  164. if (editor && editor.lastSelection.length > 0) {
  165. var t=editor.lastSelection[0].get('type');
  166. if (record.get('type') != t)
  167. record.set('type', t);
  168. return editor.lastSelection[0].get('display');
  169. }
  170. }
  171. }
  172. return val;
  173. }
  174. },{
  175. text: '关系',
  176. flex: 1,
  177. dataIndex: 'relative',
  178. xtype:'combocolumn',
  179. sortable:false,
  180. editor: {
  181. xtype: 'combo',
  182. store: Ext.create('Ext.data.Store', {
  183. fields: ['display', 'value'],
  184. data : [{"display": '等于', "value": '='},
  185. {"display": '大于', "value": '>'},
  186. {"display": '大于等于', "value": '>='},
  187. {"display": '小于', "value": '<'},
  188. {"display": '小于等于', "value": '<='},
  189. {"display": '不等于', "value": '<>'},
  190. {"display": '介于', "value": 'Between And'},
  191. {"display": '包含', "value": 'like'},
  192. {"display": '不包含', "value": 'not like'},
  193. {"display": '开头是', "value": 'begin like'},
  194. {"display": '开头不是', "value": 'begin not like'},
  195. {"display": '结尾是', "value": 'end like'},
  196. {"display": '结尾不是', "value": 'end not like'}]
  197. }),
  198. displayField: 'display',
  199. valueField: 'value',
  200. queryMode: 'local',
  201. editable: false
  202. },
  203. processEvent : function(type, view, cell, recordIndex, cellIndex, e) {
  204. if (type == 'click' || type == 'dbclick') {
  205. return true;
  206. }
  207. return false;
  208. },
  209. renderer : function(val, meta, record, x, y, store, view) {
  210. var g = view.ownerCt,h = g.columns[y],field=h.field;
  211. if (val && field) {
  212. var t = field.store.findRecord('value', val);
  213. if (t)
  214. return t.get('display');
  215. }else if(record.get('field')){
  216. if (record.get('relative') != "=") record.set('relative',"=");
  217. val="等于";
  218. }
  219. return val;
  220. }
  221. },{
  222. text:'值',
  223. dataIndex:'value',
  224. sortable:false,
  225. flex:1,
  226. renderer: function(val){
  227. if(Ext.isDate(val)){
  228. return Ext.Date.format(val, 'Y-m-d');
  229. }
  230. return val;
  231. }
  232. },{
  233. dataIndex:'type',
  234. flex:0,
  235. width:0
  236. }],
  237. store:Ext.create('Ext.data.Store',{
  238. fields:['field','relative','value','type'],
  239. data:[{},{},{},{},{},{},{},{},{},{},{}]
  240. }),
  241. getDataDictionaryData: function(tablename){
  242. var me = this, grid = Ext.getCmp('querygrid'),data=[];
  243. Ext.Ajax.request({
  244. url : basePath + 'ma/getDataDictionary.action',
  245. async: false,
  246. params: {
  247. table: tablename
  248. },
  249. method : 'post',
  250. callback : function(options,success,response){
  251. var res = new Ext.decode(response.responseText);
  252. if(res.exceptionInfo){
  253. showError(res.exceptionInfo);return;
  254. } else if(res.success) {
  255. data=me.parseDictionary(res.datadictionary);
  256. }
  257. }
  258. });
  259. return data;
  260. },
  261. getCondition: function(){
  262. var condition="",store=this.getStore(),data;
  263. Ext.each(store.data.items, function(d){
  264. data=d.data;
  265. if(data.field && data.relative && data.value){
  266. if(data.relative == 'Between And'){
  267. var v1 = data.value.split('~')[0];
  268. var v2 = data.value.split('~')[1];
  269. if(data.type == 'D'){
  270. if(condition == ''){
  271. condition = '(' + data.field + " BETWEEN to_date('" + v1 + " 00:00:00','yyyy-MM-dd HH24:mi:ss') AND to_date('"
  272. + v2 + " 23:59:59','yyyy-MM-dd HH24:mi:ss')" + ') ';
  273. } else {
  274. condition += ' AND (' + data.field + " BETWEEN to_date('" + v1 + " 00:00:00','yyyy-MM-dd HH24:mi:ss') AND to_date('"
  275. + v2 + " 23:59:59','yyyy-MM-dd HH24:mi:ss')" + ') ';
  276. }
  277. } else if(data.type == 'N'){
  278. if(condition == ''){
  279. condition = '(' + data.field + " BETWEEN " + v1 + ' AND ' + v2 + ') ';
  280. } else {
  281. condition += ' AND (' + data.field + " BETWEEN " + v1 + ' AND ' + v2 + ') ';
  282. }
  283. } else{
  284. if(condition == ''){
  285. condition = '(' + data.field + " BETWEEN '" + v1 + "' AND '" + v2 + "') ";
  286. } else {
  287. condition += ' AND (' + data.field + " BETWEEN '" + v1 + "' AND '" + v2 + "') ";
  288. }
  289. }
  290. } else {
  291. if(data.type == 'D'){
  292. var v = data.value, field = data.field;
  293. if(Ext.isDate(v)) {
  294. v = Ext.Date.format(v, 'Y-m-d');
  295. }
  296. if(data.relative == '<' || data.relative == '<=' || data.relative == '>' || data.relative == '>='){
  297. v = "to_date('" + v + "','yyyy-MM-dd')";
  298. }else {
  299. v = Ext.Date.format(data.value, 'Ymd');
  300. field = "to_char(" + field + ",'yyyymmdd')";
  301. }
  302. if(condition == ''){
  303. condition = '(' + field + data.relative + v + ') ';
  304. } else {
  305. condition += ' AND (' + field + data.relative + v + ') ';
  306. }
  307. } else {
  308. var v = data.value;
  309. if(data.relative == 'like' || data.relative=='not like'){
  310. v = " '%" + data.value + "%'";
  311. }else if(data.relative =='begin like' || data.relative =='begin not like'){
  312. v = " '" + data.value + "%'";
  313. data.relative=data.relative.substring(5);
  314. }else if(data.relative =='end like' || data.relative=='end not like'){
  315. v = " '%" + data.value + "'";
  316. data.relative=data.relative.substring(3);
  317. }else {
  318. v = " '" + data.value + "'";
  319. }
  320. console.log(data);
  321. if(condition == ''){
  322. condition = '(' + data.field + " " + data.relative + v + ") ";
  323. } else {
  324. condition += ' AND (' + data.field + " " + data.relative + v + ") ";
  325. }
  326. }
  327. }
  328. }
  329. });
  330. return condition;
  331. },
  332. parseDictionary: function(dictionary) {
  333. var me = this, data = this.data;
  334. var combodata=new Array(),o=null;
  335. Ext.each(dictionary, function(d, index){
  336. o={
  337. value:d.column_name,
  338. display:d.comments
  339. };
  340. if(contains(d.data_type, 'VARCHAR2', true)){
  341. o.type = 'S';
  342. } else if(contains(d.data_type, 'TIMESTAMP', true)){
  343. o.type = 'DT';
  344. } else if(d.ddd_fieldtype == 'DATE'){
  345. o.type = 'D';
  346. } else if(d.ddd_fieldtype == 'NUMBER'){
  347. o.type = 'N';
  348. } else if(d.ddd_fieldtype == 'FLOAT'){
  349. o.type = 'F';
  350. } else {
  351. o.type = 'S';
  352. }
  353. combodata.push(o);
  354. });
  355. return combodata;
  356. }
  357. };
  358. return Ext.create('Ext.grid.Panel',config);
  359. },
  360. createDataGrid:function(){
  361. var me=this;
  362. var config={
  363. id:'datagrid',
  364. region:'center',
  365. columnLines:true,
  366. foreceFit:true,
  367. requires: ['erp.view.core.grid.HeaderFilter'],
  368. plugins : [Ext.create('erp.view.core.grid.HeaderFilter'),Ext.create('erp.view.core.plugin.CopyPasteMenu')],
  369. selModel: Ext.create('Ext.selection.CheckboxModel',{
  370. checkOnly : true,
  371. ignoreRightMouseSelection : false,
  372. getEditor: function(){
  373. return null;
  374. },
  375. onHeaderClick: function(headerCt, header, e) {
  376. if (header.isCheckerHd) {
  377. e.stopEvent();
  378. var isChecked = header.el.hasCls(Ext.baseCSSPrefix + 'grid-hd-checker-on');
  379. if (isChecked && this.getSelection().length > 0) {
  380. this.deselectAll(true);
  381. } else {
  382. this.selectAll(true);
  383. this.view.ownerCt.selectall = true;
  384. }
  385. }
  386. }
  387. }),
  388. columns:[{
  389. text:'代码',
  390. flex:0.5,
  391. dataIndex:'CODE_',
  392. filter: {xtype: 'textfield', filterName: 'CODE_'},
  393. },{
  394. text:'名称',
  395. flex:1,
  396. dataIndex:'DESC_',
  397. filter: {xtype: 'textfield', filterName: 'DESC_'},
  398. }],
  399. store:Ext.create('Ext.data.Store',{
  400. fields:['CODE_','DESC_'],
  401. proxy: {
  402. type: 'ajax',
  403. url : basePath+'/ma/datalimit/getSourceData.action',
  404. extraParams:{
  405. limitId_:me.limitId_
  406. },
  407. reader: {
  408. type: 'json',
  409. root: 'jobs'
  410. }
  411. },
  412. autoLoad: true
  413. })
  414. };
  415. return Ext.create('Ext.grid.Panel',config);
  416. },
  417. setDefaultValue : function(form) {
  418. var me = this;
  419. me.down('textfield[name=name]').setValue(form.title);
  420. if (form.codeField) {
  421. var c = form.down('#' + form.codeField);
  422. if (c) {
  423. me.down('textfield[name=sourcecode]').setValue(c.getValue());
  424. }
  425. var u = new String(window.location.href);
  426. u = u.substr(u.indexOf('jsps'));
  427. me.down('field[name=sourcelink]').setValue(u);
  428. }
  429. if (form.uulistener) {
  430. var t = me.down('fieldcontainer[name=resourcename]');
  431. Ext.each(form.uulistener, function(u){
  432. var f = form.down('#' + u.uu_field);
  433. if(f) {
  434. if(!(u.uu_ftype == 1 && f.value == em_code) && !(u.uu_ftype == 2 && f.value == em_name)) {//排除自己
  435. if(f.value && !t.down('checkbox[boxLabel=' + f.value + ']')) {
  436. t.insert(0, {
  437. xtype : 'checkbox',
  438. name : 'man',
  439. isFormField : false,
  440. checked : true,
  441. boxLabel : f.value
  442. });
  443. }
  444. }
  445. }
  446. });
  447. }
  448. }
  449. });