modx.tree.menu.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /**
  2. * Generates a Tree for managing the Top Menu
  3. *
  4. * @class MODx.tree.Menu
  5. * @extends MODx.tree.Tree
  6. * @param {Object} config An object of options.
  7. * @xtype modx-tree-menu
  8. */
  9. MODx.tree.Menu = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. root_id: 'n_'
  13. ,root_name: _('menu_top')
  14. ,rootVisible: true
  15. ,expandFirst: true
  16. ,enableDrag: true
  17. ,enableDrop: true
  18. ,url: MODx.config.connector_url
  19. ,action: 'system/menu/getNodes'
  20. ,sortAction: 'system/menu/sort'
  21. ,primaryKey: 'text'
  22. ,useDefaultToolbar: true
  23. ,ddGroup: 'modx-menu'
  24. ,tbar: [{
  25. text: _('menu_create')
  26. ,cls:'primary-button'
  27. ,handler: this.createMenu
  28. ,scope: this
  29. }]
  30. });
  31. MODx.tree.Menu.superclass.constructor.call(this,config);
  32. };
  33. Ext.extend(MODx.tree.Menu, MODx.tree.Tree, {
  34. windows: {}
  35. ,createMenu: function(n,e) {
  36. var r = {
  37. parent: ''
  38. };
  39. if (this.cm && this.cm.activeNode && this.cm.activeNode.attributes && this.cm.activeNode.attributes.data) {
  40. r['parent'] = this.cm.activeNode.attributes.data.text;
  41. }
  42. if (!this.windows.create_menu) {
  43. this.windows.create_menu = MODx.load({
  44. xtype: 'modx-window-menu-create'
  45. ,record: r
  46. ,listeners: {
  47. 'success': {fn:function(r) { this.refresh(); },scope:this}
  48. }
  49. });
  50. }
  51. this.windows.create_menu.reset();
  52. this.windows.create_menu.setValues(r);
  53. this.windows.create_menu.show(e.target);
  54. }
  55. ,updateMenu: function(n,e) {
  56. var r = this.cm.activeNode.attributes.data;
  57. Ext.apply(r,{
  58. action_id: r.action
  59. ,new_text: r.text
  60. });
  61. this.windows.update_menu = MODx.load({
  62. xtype: 'modx-window-menu-update'
  63. ,record: r
  64. ,listeners: {
  65. 'success': {fn:function(r) { this.refresh(); },scope:this}
  66. }
  67. });
  68. this.windows.update_menu.setValues(r);
  69. this.windows.update_menu.show(e.target);
  70. }
  71. ,removeMenu: function(n,e) {
  72. MODx.msg.confirm({
  73. title: _('warning')
  74. ,text: _('menu_confirm_remove')
  75. ,url: this.config.url
  76. ,params: {
  77. action: 'system/menu/remove'
  78. ,text: this.cm.activeNode.attributes.pk
  79. }
  80. ,listeners: {
  81. 'success':{fn:this.refresh,scope:this}
  82. }
  83. });
  84. }
  85. ,getMenu: function(n,e) {
  86. var m = [];
  87. switch (n.attributes.type) {
  88. case 'menu':
  89. m.push({
  90. text: _('menu_update')
  91. ,handler: this.updateMenu
  92. });
  93. m.push('-');
  94. m.push({
  95. text: _('menu_remove')
  96. ,handler: this.removeMenu
  97. });
  98. break;
  99. default:
  100. m.push({
  101. text: _('menu_create')
  102. ,handler: this.createMenu
  103. });
  104. break;
  105. }
  106. return m;
  107. }
  108. /**
  109. * Renders the item text without any special formatting. The menu/getnodes processor already protects against XSS.
  110. */
  111. ,renderItemText: function(item) {
  112. return item.text;
  113. }
  114. });
  115. Ext.reg('modx-tree-menu',MODx.tree.Menu);
  116. /**
  117. * Generates the Create Menu window
  118. *
  119. * @class MODx.window.CreateMenu
  120. * @extends MODx.Window
  121. * @param {Object} config An object of options.
  122. * @xtype modx-window-menu-create
  123. */
  124. MODx.window.CreateMenu = function(config) {
  125. config = config || {};
  126. this.ident = config.ident || 'modx-cmenu-'+Ext.id();
  127. Ext.applyIf(config,{
  128. title: _('menu_create')
  129. ,width: 600
  130. // ,height: 400
  131. ,url: MODx.config.connector_url
  132. ,action: 'system/menu/create'
  133. ,fields: [{
  134. xtype: 'modx-combo-menu'
  135. ,name: 'parent'
  136. ,hiddenName: 'parent'
  137. ,anchor: '100%'
  138. ,fieldLabel: _('parent')
  139. },{
  140. layout: 'column'
  141. ,border: false
  142. ,style: 'padding-top: 15px;'
  143. ,defaults: {
  144. layout: 'form'
  145. ,labelAlign: 'top'
  146. ,anchor: '100%'
  147. ,border: false
  148. }
  149. ,items: [{
  150. columnWidth: .5
  151. ,items: [{
  152. xtype: 'hidden'
  153. ,name: 'previous_text'
  154. ,value: config.record && config.record.text ? config.record.text : ''
  155. },{
  156. fieldLabel: _('lexicon_key')
  157. ,description: MODx.expandHelp ? '' : _('lexicon_key_desc')
  158. ,name: 'text'
  159. ,xtype: 'textfield'
  160. ,allowBlank: false
  161. ,anchor: '100%'
  162. ,id: this.ident+'-text'
  163. //,readOnly: config.update ? true : false
  164. },{
  165. xtype: MODx.expandHelp ? 'label' : 'hidden'
  166. ,forId: this.ident+'-text'
  167. ,html: _('lexicon_key_desc')
  168. ,cls: 'desc-under'
  169. },{
  170. fieldLabel: _('description')
  171. ,description: MODx.expandHelp ? '' : _('description_desc')
  172. ,name: 'description'
  173. ,xtype: 'textfield'
  174. ,allowBlank: true
  175. ,anchor: '100%'
  176. ,id: this.ident+'-description'
  177. },{
  178. xtype: MODx.expandHelp ? 'label' : 'hidden'
  179. ,forId: this.ident+'-description'
  180. ,html: _('description_desc')
  181. ,cls: 'desc-under'
  182. },{
  183. fieldLabel: _('handler')
  184. ,description: MODx.expandHelp ? '' : _('handler_desc')
  185. ,name: 'handler'
  186. ,xtype: 'textarea'
  187. ,anchor: '100%'
  188. ,grow: false
  189. ,id: this.ident+'-handler'
  190. },{
  191. xtype: MODx.expandHelp ? 'label' : 'hidden'
  192. ,forId: this.ident+'-handler'
  193. ,html: _('handler_desc')
  194. ,cls: 'desc-under'
  195. },{
  196. fieldLabel: _('permissions')
  197. ,description: MODx.expandHelp ? '' : _('permissions_desc')
  198. ,name: 'permissions'
  199. ,xtype: 'textfield'
  200. ,anchor: '100%'
  201. ,id: this.ident+'-permissions'
  202. },{
  203. xtype: MODx.expandHelp ? 'label' : 'hidden'
  204. ,forId: this.ident+'-permissions'
  205. ,html: _('permissions_desc')
  206. ,cls: 'desc-under'
  207. }]
  208. },{
  209. columnWidth: .5
  210. ,items: [{
  211. fieldLabel: _('action')
  212. ,description: MODx.expandHelp ? '' : _('action_desc')
  213. ,name: 'action_id'
  214. ,hiddenName: 'action_id'
  215. ,xtype: 'textfield'
  216. ,anchor: '100%'
  217. ,id: this.ident+'-action-id'
  218. //,allowBlank: false
  219. },{
  220. xtype: MODx.expandHelp ? 'label' : 'hidden'
  221. ,forId: this.ident+'-action-id'
  222. ,html: _('action_desc')
  223. ,cls: 'desc-under'
  224. },{
  225. fieldLabel: _('parameters')
  226. ,description: MODx.expandHelp ? '' : _('parameters_desc')
  227. ,name: 'params'
  228. ,xtype: 'textfield'
  229. ,anchor: '100%'
  230. ,id: this.ident+'-params'
  231. },{
  232. xtype: MODx.expandHelp ? 'label' : 'hidden'
  233. ,forId: this.ident+'-params'
  234. ,html: _('parameters_desc')
  235. ,cls: 'desc-under'
  236. },{
  237. fieldLabel: _('namespace')
  238. ,description: MODx.expandHelp ? '' : _('namespace_desc')
  239. ,name: 'namespace'
  240. ,xtype: 'textfield'
  241. ,anchor: '100%'
  242. ,value: 'core'
  243. ,id: this.ident+'-namespace'
  244. },{
  245. xtype: MODx.expandHelp ? 'label' : 'hidden'
  246. ,forId: this.ident+'-namespace'
  247. ,html: _('namespace_desc')
  248. ,cls: 'desc-under'
  249. },{
  250. fieldLabel: _('icon')
  251. ,description: MODx.expandHelp ? '' : _('icon_desc')
  252. ,name: 'icon'
  253. ,xtype: 'textfield'
  254. ,anchor: '100%'
  255. ,id: this.ident+'-icon'
  256. },{
  257. xtype: MODx.expandHelp ? 'label' : 'hidden'
  258. ,forId: this.ident+'-icon'
  259. ,html: _('icon_desc')
  260. ,cls: 'desc-under'
  261. }]
  262. }]
  263. }]
  264. });
  265. MODx.window.CreateMenu.superclass.constructor.call(this,config);
  266. };
  267. Ext.extend(MODx.window.CreateMenu,MODx.Window);
  268. Ext.reg('modx-window-menu-create',MODx.window.CreateMenu);
  269. /**
  270. * Generates the Update Menu window
  271. *
  272. * @class MODx.window.UpdateMenu
  273. * @extends MODx.window.CreateMenu
  274. * @constructor
  275. * @param {Object} config An object of options.
  276. * @xtype window-menu-update
  277. */
  278. MODx.window.UpdateMenu = function(config) {
  279. config = config || {};
  280. Ext.applyIf(config,{
  281. title: _('menu_update')
  282. ,action: 'system/menu/update'
  283. });
  284. MODx.window.UpdateMenu.superclass.constructor.call(this,config);
  285. };
  286. Ext.extend(MODx.window.UpdateMenu,MODx.window.CreateMenu);
  287. Ext.reg('modx-window-menu-update',MODx.window.UpdateMenu);
  288. /**
  289. * Displays a dropdown of modMenus
  290. *
  291. * @class MODx.combo.Menu
  292. * @extends MODx.combo.ComboBox
  293. * @param {Object} config An object of options.
  294. * @xtype modx-combo-menu
  295. */
  296. MODx.combo.Menu = function(config) {
  297. config = config || {};
  298. Ext.applyIf(config,{
  299. name: 'menu'
  300. ,hiddenName: 'menu'
  301. ,url: MODx.config.connector_url
  302. ,baseParams: {
  303. action: 'system/menu/getlist'
  304. ,combo: true
  305. ,limit: 0
  306. ,showNone: true
  307. }
  308. ,fields: ['text','text_lex']
  309. ,displayField: 'text_lex'
  310. ,valueField: 'text'
  311. // ,listWidth: 300
  312. ,editable: false
  313. });
  314. MODx.combo.Menu.superclass.constructor.call(this,config);
  315. };
  316. Ext.extend(MODx.combo.Menu,MODx.combo.ComboBox);
  317. Ext.reg('modx-combo-menu',MODx.combo.Menu);