lexicon.grid.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /**
  2. * Loads a grid for managing lexicons.
  3. *
  4. * @class MODx.grid.Lexicon
  5. * @extends MODx.grid.Grid
  6. * @param {Object} config An object of configuration properties
  7. * @xtype modx-grid-lexicon
  8. */
  9. MODx.grid.Lexicon = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. id: 'modx-grid-lexicon'
  13. ,url: MODx.config.connector_url
  14. ,fields: ['name','value','namespace','topic','language','editedon','overridden']
  15. ,baseParams: {
  16. action: 'workspace/lexicon/getList'
  17. ,'namespace': MODx.request['ns'] ? MODx.request['ns'] : 'core'
  18. ,topic: ''
  19. ,language: MODx.config.manager_language || 'en'
  20. }
  21. ,width: '98%'
  22. ,paging: true
  23. ,autosave: true
  24. ,save_action: 'workspace/lexicon/updatefromgrid'
  25. ,columns: [{
  26. header: _('name')
  27. ,dataIndex: 'name'
  28. ,width: 200
  29. ,sortable: true
  30. ,renderer: this._renderStatus
  31. },{
  32. header: _('value')
  33. ,dataIndex: 'value'
  34. ,width: 500
  35. ,sortable: false
  36. ,editor: {xtype: 'textarea'}
  37. ,renderer: this._renderStatus
  38. },{
  39. header: _('last_modified')
  40. ,dataIndex: 'editedon'
  41. ,width: 125
  42. ,renderer: this._renderLastModDate
  43. }]
  44. ,tbar: [{
  45. xtype: 'tbtext'
  46. ,text: _('namespace')+':'
  47. },{
  48. xtype: 'modx-combo-namespace'
  49. ,id: 'modx-lexicon-filter-namespace'
  50. ,itemId: 'namespace'
  51. ,preselectValue: MODx.request['ns'] ? MODx.request['ns'] : ''
  52. ,width: 120
  53. ,listeners: {
  54. 'select': {fn: this.changeNamespace,scope:this}
  55. }
  56. },{
  57. xtype: 'tbtext'
  58. ,text: _('topic')+':'
  59. },{
  60. xtype: 'modx-combo-lexicon-topic'
  61. ,id: 'modx-lexicon-filter-topic'
  62. ,itemId: 'topic'
  63. ,value: 'default'
  64. ,width: 120
  65. ,baseParams: {
  66. action: 'workspace/lexicon/topic/getList'
  67. ,'namespace': MODx.request['ns'] ? MODx.request['ns'] : ''
  68. ,'language': 'en'
  69. }
  70. ,listeners: {
  71. 'select': {fn:this.changeTopic,scope:this}
  72. }
  73. },{
  74. xtype: 'tbtext'
  75. ,text: _('language')+':'
  76. },{
  77. xtype: 'modx-combo-language'
  78. ,name: 'language'
  79. ,id: 'modx-lexicon-filter-language'
  80. ,itemId: 'language'
  81. ,value: MODx.config.manager_language || 'en'
  82. ,width: 100
  83. ,baseParams: {
  84. action: 'system/language/getlist'
  85. ,'namespace': MODx.request['ns'] ? MODx.request['ns'] : ''
  86. }
  87. ,listeners: {
  88. 'select': {fn:this.changeLanguage,scope:this}
  89. }
  90. }
  91. ,'->'
  92. ,{
  93. xtype: 'button'
  94. ,text: _('entry_create')
  95. ,cls:'primary-button'
  96. ,handler: this.createEntry
  97. ,scope: this
  98. },{
  99. xtype: 'textfield'
  100. ,name: 'name'
  101. ,id: 'modx-lexicon-filter-search'
  102. ,cls: 'x-form-filter'
  103. ,itemId: 'search'
  104. ,width: 120
  105. ,emptyText: _('search')+'...'
  106. ,listeners: {
  107. 'change': {fn:this.filter.createDelegate(this,['search'],true),scope:this}
  108. ,'render': {fn: function(cmp) {
  109. new Ext.KeyMap(cmp.getEl(), {
  110. key: Ext.EventObject.ENTER
  111. ,fn: this.blur
  112. ,scope: cmp
  113. });
  114. },scope:this}
  115. }
  116. },{
  117. xtype: 'button'
  118. ,id: 'modx-lexicon-filter-clear'
  119. ,cls: 'x-form-filter-clear'
  120. ,itemId: 'clear'
  121. ,text: _('filter_clear')
  122. ,listeners: {
  123. 'click': {fn: this.clearFilter, scope: this},
  124. 'mouseout': { fn: function(evt){
  125. this.removeClass('x-btn-focus');
  126. }
  127. }
  128. }
  129. }]
  130. ,pagingItems: [{
  131. text: _('reload_from_base')
  132. ,handler: this.reloadFromBase
  133. ,scope: this
  134. }
  135. /*
  136. ,{
  137. xtype: 'button'
  138. ,id: 'modx-lexicon-import-btn'
  139. ,text: _('lexicon_import')
  140. ,handler: function(btn,e) {
  141. this.loadWindow2(btn,e,{
  142. xtype: 'modx-window-lexicon-import'
  143. ,listeners: {
  144. 'success': {fn:function(o) {
  145. var r = o.a.result.object;
  146. this.setFilterParams(r['namespace'],r.topic);
  147. },scope:this}
  148. ,'show': {fn:function() {
  149. var w = this.windows['modx-window-lexicon-import'];
  150. if (w) {
  151. var tf = w.fp.getComponent('topic');
  152. var tb = this.getTopToolbar();
  153. if (tf && tb) {
  154. tf.setValue(tb.getComponent('topic').getRawValue());
  155. }
  156. }
  157. },scope: this}
  158. }
  159. });
  160. }
  161. ,scope: this
  162. },{
  163. xtype: 'button'
  164. ,id: 'modx-lexicon-export-btn'
  165. ,text: _('lexicon_export')
  166. ,handler: function(btn,e) {
  167. this.loadWindow2(btn,e,{
  168. xtype: 'modx-window-lexicon-export'
  169. ,listeners: {
  170. 'success': {fn:function(o) {
  171. location.href = MODx.config.connector_url+'?action=workspace/lexicon/export&HTTP_MODAUTH='+MODx.siteId+'&download='+o.a.result.message;
  172. },scope:this}
  173. ,'show': {fn:function() {
  174. var w = this.windows['modx-window-lexicon-export'];
  175. var cb = w.fp.getComponent('topic');
  176. if (cb) {
  177. var tb = this.getTopToolbar();
  178. cb.setNamespace(tb.getComponent('namespace').getValue(),tb.getComponent('topic').getValue());
  179. }
  180. },scope: this}
  181. }
  182. });
  183. }
  184. ,scope: this
  185. }*/]
  186. });
  187. MODx.grid.Lexicon.superclass.constructor.call(this,config);
  188. };
  189. Ext.extend(MODx.grid.Lexicon,MODx.grid.Grid,{
  190. console: null
  191. ,_renderStatus: function(v,md,rec,ri) {
  192. switch (rec.data.overridden) {
  193. case 1:
  194. return '<span style="color: green;">'+v+'</span>';break;
  195. case 2:
  196. return '<span style="color: purple;">'+v+'</span>';
  197. default:
  198. return '<span>'+v+'</span>';
  199. }
  200. }
  201. ,_renderLastModDate: function(value) {
  202. if (Ext.isEmpty(value)) {
  203. return '—';
  204. }
  205. return new Date(value*1000).format(MODx.config.manager_date_format + ' ' + MODx.config.manager_time_format);
  206. }
  207. ,filter: function(cb,r,i,name) {
  208. if (!name) {return false;}
  209. this.store.baseParams[name] = cb.getValue();
  210. this.getBottomToolbar().changePage(1);
  211. //this.refresh();
  212. return true;
  213. }
  214. ,clearFilter: function() {
  215. this.store.baseParams = {
  216. action: 'workspace/lexicon/getList'
  217. ,'namespace': 'core'
  218. ,topic: 'default'
  219. ,language: 'en'
  220. };
  221. this.getBottomToolbar().changePage(1);
  222. var tb = this.getTopToolbar();
  223. tb.getComponent('namespace').setValue('core');
  224. var tcb = tb.getComponent('topic');
  225. tcb.store.baseParams['namespace'] = 'core';
  226. tcb.store.load();
  227. tcb.setValue('default');
  228. var tcl = tb.getComponent('language');
  229. tcb.store.baseParams['namespace'] = 'core';
  230. tcb.store.load();
  231. tcl.setValue('en');
  232. tb.getComponent('search').setValue('');
  233. //this.refresh();
  234. }
  235. ,changeNamespace: function(cb,nv,ov) {
  236. this.setFilterParams(cb.getValue(),'default','en');
  237. }
  238. ,changeTopic: function(cb,nv,ov) {
  239. this.setFilterParams(null,cb.getValue());
  240. }
  241. ,changeLanguage: function(cb,nv,ov) {
  242. this.setFilterParams(null,null,cb.getValue());
  243. }
  244. ,setFilterParams: function(ns,t,l) {
  245. var tb = this.getTopToolbar();
  246. if (!tb) {return false;}
  247. var tcb,tcl;
  248. if (ns) {
  249. tb.getComponent('namespace').setValue(ns);
  250. tcl = tb.getComponent('language');
  251. if (tcl) {
  252. tcl.store.baseParams['namespace'] = ns;
  253. tcl.store.load({
  254. callback: function() {
  255. tcl.setValue(l || 'en');
  256. }
  257. });
  258. }
  259. tcb = tb.getComponent('topic');
  260. if (tcb) {
  261. tcb.store.baseParams['namespace'] = ns;
  262. tcb.store.baseParams['language'] = l ? l : (tcl ? tcl.getValue() : 'en');
  263. tcb.store.load({
  264. callback: function() {
  265. tcb.setValue(t || 'default');
  266. }
  267. });
  268. }
  269. } else if (t) {
  270. tcb = tb.getComponent('topic');
  271. if (tcb) {tcb.setValue(t);}
  272. }
  273. var s = this.getStore();
  274. if (s) {
  275. if (ns) {s.baseParams['namespace'] = ns;}
  276. if (t) {s.baseParams['topic'] = t || 'default';}
  277. if (l) {s.baseParams['language'] = l || 'en';}
  278. s.removeAll();
  279. }
  280. this.getBottomToolbar().changePage(1);
  281. //this.refresh();
  282. }
  283. ,loadWindow2: function(btn,e,o) {
  284. var tb = this.getTopToolbar();
  285. this.menu.record = {
  286. 'namespace': tb.getComponent('namespace').getValue()
  287. ,language: tb.getComponent('language').getValue()
  288. };
  289. if (o.xtype != 'modx-window-lexicon-import') {
  290. this.menu.record.topic = tb.getComponent('topic').getValue();
  291. }
  292. this.loadWindow(btn, e, o);
  293. }
  294. ,reloadFromBase: function() {
  295. Ext.Ajax.timeout = 0;
  296. var topic = '/workspace/lexicon/reload/';
  297. this.console = MODx.load({
  298. xtype: 'modx-console'
  299. ,register: 'mgr'
  300. ,topic: topic
  301. });
  302. this.console.on('complete',function(){
  303. this.refresh();
  304. },this);
  305. this.console.show(Ext.getBody());
  306. MODx.Ajax.request({
  307. url: this.config.url
  308. ,params: {action: 'workspace/lexicon/reloadFromBase' ,register: 'mgr' ,topic: topic}
  309. ,listeners: {
  310. 'success': {fn:function(r) {
  311. this.refresh();
  312. },scope:this}
  313. }
  314. });
  315. }
  316. ,revertEntry: function() {
  317. var p = this.menu.record;
  318. p.action = 'workspace/lexicon/revert';
  319. MODx.Ajax.request({
  320. url: this.config.url
  321. ,params: p
  322. ,listeners: {
  323. 'success': {fn:function(r) {
  324. this.refresh();
  325. },scope:this}
  326. }
  327. });
  328. }
  329. ,getMenu: function() {
  330. var r = this.getSelectionModel().getSelected();
  331. var m = [];
  332. if (r.data.overridden) {
  333. m.push({
  334. text: _('entry_revert')
  335. ,handler: this.revertEntry
  336. });
  337. }
  338. return m;
  339. }
  340. ,createEntry: function(btn,e) {
  341. var r = this.menu.record || {};
  342. var tb = this.getTopToolbar();
  343. r['namespace'] = tb.getComponent('namespace').getValue();
  344. r.language = tb.getComponent('language').getValue();
  345. r.topic = tb.getComponent('topic').getValue();
  346. if (!this.createEntryWindow) {
  347. this.createEntryWindow = MODx.load({
  348. xtype: 'modx-window-lexicon-entry-create'
  349. ,record: r
  350. ,listeners: {
  351. 'success':{fn:function(o) {
  352. this.refresh();
  353. },scope:this}
  354. }
  355. });
  356. }
  357. this.createEntryWindow.reset();
  358. this.createEntryWindow.setValues(r);
  359. this.createEntryWindow.show(e.target);
  360. }
  361. });
  362. Ext.reg('modx-grid-lexicon',MODx.grid.Lexicon);
  363. /**
  364. * Generates the export lexicon window.
  365. *
  366. * @class MODx.window.ExportLexicon
  367. * @extends MODx.Window
  368. * @param {Object} config An object of options.
  369. * @xtype modx-window-lexicon-export
  370. */
  371. MODx.window.ExportLexicon = function(config) {
  372. config = config || {};
  373. this.ident = config.ident || 'explex'+Ext.id();
  374. var r = config.record;
  375. Ext.applyIf(config,{
  376. title: _('lexicon_export')
  377. ,url: MODx.config.connector_url
  378. ,action: 'workspace/lexicon/export'
  379. ,fileUpload: true
  380. ,fields: [{
  381. html: _('lexicon_export_desc')
  382. ,border: false
  383. ,bodyStyle: 'margin: 10px;'
  384. ,id: 'modx-'+this.ident+'-desc'
  385. ,itemId: 'desc'
  386. ,anchor: '100%'
  387. },{
  388. xtype: 'modx-combo-namespace'
  389. ,fieldLabel: _('namespace')
  390. ,name: 'namespace'
  391. ,id: 'modx-'+this.ident+'-namespace'
  392. ,itemId: 'namespace'
  393. ,anchor: '100%'
  394. ,listeners: {
  395. 'select': {fn: function(cb,r,i) {
  396. cle = this.fp.getComponent('topic');
  397. if (cle) {
  398. cle.store.baseParams['namespace'] = cb.getValue();
  399. cle.setValue('');
  400. cle.store.reload();
  401. } else {MODx.debug('cle not found');}
  402. },scope:this}
  403. }
  404. },{
  405. xtype: 'modx-combo-lexicon-topic'
  406. ,fieldLabel: _('topic')
  407. ,name: 'topic'
  408. ,id: 'modx-'+this.ident+'-topic'
  409. ,itemId: 'topic'
  410. ,anchor: '100%'
  411. },{
  412. xtype: 'modx-combo-language'
  413. ,fieldLabel: _('language')
  414. ,name: 'language'
  415. ,id: 'modx-'+this.ident+'-language'
  416. ,itemId: 'language'
  417. ,anchor: '100%'
  418. }]
  419. });
  420. MODx.window.ExportLexicon.superclass.constructor.call(this,config);
  421. };
  422. Ext.extend(MODx.window.ExportLexicon,MODx.Window);
  423. Ext.reg('modx-window-lexicon-export',MODx.window.ExportLexicon);
  424. MODx.window.LexiconEntryCreate = function(config) {
  425. config = config || {};
  426. this.ident = config.ident || 'lexentc'+Ext.id();
  427. var r = config.record;
  428. Ext.applyIf(config,{
  429. title: _('entry_create')
  430. ,url: MODx.config.connector_url
  431. ,action: 'workspace/lexicon/create'
  432. ,fileUpload: true
  433. ,fields: [{
  434. xtype: 'textfield'
  435. ,fieldLabel: _('name')
  436. ,id: 'modx-'+this.ident+'-name'
  437. ,itemId: 'name'
  438. ,name: 'name'
  439. ,anchor: '100%'
  440. },{
  441. xtype: 'modx-combo-namespace'
  442. ,fieldLabel: _('namespace')
  443. ,name: 'namespace'
  444. ,id: 'modx-'+this.ident+'-namespace'
  445. ,itemId: 'namespace'
  446. ,anchor: '100%'
  447. ,listeners: {
  448. 'select': {fn: function(cb,r,i) {
  449. cle = this.fp.getComponent('topic');
  450. if (cle) {
  451. cle.store.baseParams['namespace'] = cb.getValue();
  452. cle.setValue('');
  453. cle.store.reload();
  454. } else {MODx.debug('cle not found');}
  455. },scope:this}
  456. }
  457. },{
  458. xtype: 'modx-combo-lexicon-topic'
  459. ,fieldLabel: _('topic')
  460. ,name: 'topic'
  461. ,id: 'modx-'+this.ident+'-topic'
  462. ,itemId: 'topic'
  463. ,anchor: '100%'
  464. },{
  465. xtype: 'modx-combo-language'
  466. ,fieldLabel: _('language')
  467. ,name: 'language'
  468. ,id: 'modx-'+this.ident+'-language'
  469. ,itemId: 'language'
  470. ,anchor: '100%'
  471. },{
  472. xtype: 'textarea'
  473. ,fieldLabel: _('value')
  474. ,id: 'modx-'+this.ident+'-value'
  475. ,itemId: 'value'
  476. ,name: 'value'
  477. ,anchor: '100%'
  478. }]
  479. });
  480. MODx.window.LexiconEntryCreate.superclass.constructor.call(this,config);
  481. };
  482. Ext.extend(MODx.window.LexiconEntryCreate,MODx.Window);
  483. Ext.reg('modx-window-lexicon-entry-create',MODx.window.LexiconEntryCreate);