modx.panel.sources.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. MODx.panel.Sources = function(config) {
  2. config = config || {};
  3. Ext.applyIf(config,{
  4. id: 'modx-panel-sources'
  5. ,cls: 'container'
  6. ,bodyStyle: ''
  7. ,defaults: { collapsible: false ,autoHeight: true }
  8. ,items: [{
  9. html: _('sources')
  10. ,id: 'modx-sources-header'
  11. ,xtype: 'modx-header'
  12. },MODx.getPageStructure([{
  13. layout: 'form'
  14. ,title: _('sources')
  15. ,items: [{
  16. html: '<p>'+_('sources.intro_msg')+'</p>'
  17. ,xtype: 'modx-description'
  18. },{
  19. xtype: 'modx-grid-sources'
  20. ,cls: 'main-wrapper'
  21. ,preventRender: true
  22. }]
  23. },{
  24. layout: 'form'
  25. ,title: _('source_types')
  26. ,items: [{
  27. html: '<p>'+_('source_types.intro_msg')+'</p>'
  28. ,xtype: 'modx-description'
  29. },{
  30. xtype: 'modx-grid-source-types'
  31. ,cls: 'main-wrapper'
  32. ,preventRender: true
  33. }]
  34. }],{
  35. stateful: true
  36. ,stateId: 'modx-sources-tabpanel'
  37. ,stateEvents: ['tabchange']
  38. ,getState:function() {
  39. return {activeTab:this.items.indexOf(this.getActiveTab())};
  40. }
  41. })]
  42. });
  43. MODx.panel.Sources.superclass.constructor.call(this,config);
  44. };
  45. Ext.extend(MODx.panel.Sources,MODx.FormPanel);
  46. Ext.reg('modx-panel-sources',MODx.panel.Sources);
  47. MODx.grid.Sources = function(config) {
  48. config = config || {};
  49. this.sm = new Ext.grid.CheckboxSelectionModel();
  50. Ext.applyIf(config,{
  51. url: MODx.config.connector_url
  52. ,baseParams: {
  53. action: 'source/getlist'
  54. }
  55. ,fields: ['id','name','description','class_key','cls']
  56. ,paging: true
  57. ,autosave: true
  58. ,save_action: 'source/updatefromgrid'
  59. ,remoteSort: true
  60. ,sm: this.sm
  61. ,columns: [this.sm,{
  62. header: _('id')
  63. ,dataIndex: 'id'
  64. ,width: 50
  65. ,sortable: true
  66. },{
  67. header: _('name')
  68. ,dataIndex: 'name'
  69. ,width: 150
  70. ,sortable: true
  71. ,editor: { xtype: 'textfield' ,allowBlank: false }
  72. ,renderer: Ext.util.Format.htmlEncode
  73. },{
  74. header: _('description')
  75. ,dataIndex: 'description'
  76. ,width: 300
  77. ,sortable: false
  78. ,editor: { xtype: 'textarea' }
  79. ,renderer: Ext.util.Format.htmlEncode
  80. }]
  81. ,tbar: [{
  82. text: _('source_create')
  83. ,handler: { xtype: 'modx-window-source-create' ,blankValues: true }
  84. ,cls:'primary-button'
  85. },{
  86. text: _('bulk_actions')
  87. ,menu: [{
  88. text: _('selected_remove')
  89. ,handler: this.removeSelected
  90. ,scope: this
  91. }]
  92. },'->',{
  93. xtype: 'textfield'
  94. ,name: 'search'
  95. ,id: 'modx-source-search'
  96. ,cls: 'x-form-filter'
  97. ,emptyText: _('search_ellipsis')
  98. ,listeners: {
  99. 'change': {fn: this.search, scope: this}
  100. ,'render': {fn: function(cmp) {
  101. new Ext.KeyMap(cmp.getEl(), {
  102. key: Ext.EventObject.ENTER
  103. ,fn: this.blur
  104. ,scope: cmp
  105. });
  106. },scope:this}
  107. }
  108. },{
  109. xtype: 'button'
  110. ,text: _('filter_clear')
  111. ,id: 'modx-filter-clear'
  112. ,cls: 'x-form-filter-clear'
  113. ,listeners: {
  114. 'click': {fn: this.clearFilter, scope: this},
  115. 'mouseout': { fn: function(evt){
  116. this.removeClass('x-btn-focus');
  117. }
  118. }
  119. }
  120. }]
  121. });
  122. MODx.grid.Sources.superclass.constructor.call(this,config);
  123. };
  124. Ext.extend(MODx.grid.Sources,MODx.grid.Grid,{
  125. getMenu: function() {
  126. var r = this.getSelectionModel().getSelected();
  127. var p = r.data.cls;
  128. var m = [];
  129. if (this.getSelectionModel().getCount() > 1) {
  130. m.push({
  131. text: _('selected_remove')
  132. ,handler: this.removeSelected
  133. ,scope: this
  134. });
  135. } else {
  136. if (p.indexOf('pupdate') != -1) {
  137. m.push({
  138. text: _('source_update')
  139. ,handler: this.updateSource
  140. });
  141. }
  142. if (p.indexOf('pduplicate') != -1) {
  143. m.push({
  144. text: _('source_duplicate')
  145. ,handler: this.duplicateSource
  146. });
  147. }
  148. if (p.indexOf('premove') != -1 && r.data.id != 1 && r.data.name != 'Filesystem') {
  149. if (m.length > 0) m.push('-');
  150. m.push({
  151. text: _('source_remove')
  152. ,handler: this.removeSource
  153. });
  154. }
  155. }
  156. if (m.length > 0) {
  157. this.addContextMenuItem(m);
  158. }
  159. }
  160. ,duplicateSource: function(btn,e) {
  161. MODx.Ajax.request({
  162. url: this.config.url
  163. ,params: {
  164. action: 'source/duplicate'
  165. ,id: this.menu.record.id
  166. }
  167. ,listeners: {
  168. 'success': {fn:this.refresh,scope:this}
  169. }
  170. });
  171. }
  172. ,createSource: function() {
  173. MODx.loadPage('system/source/create');
  174. }
  175. ,removeSelected: function() {
  176. var cs = this.getSelectedAsList();
  177. if (cs === false) return false;
  178. MODx.msg.confirm({
  179. title: _('source_remove_multiple')
  180. ,text: _('source_remove_multiple_confirm')
  181. ,url: this.config.url
  182. ,params: {
  183. action: 'source/removeMultiple'
  184. ,sources: cs
  185. }
  186. ,listeners: {
  187. 'success': {fn:function(r) {
  188. this.getSelectionModel().clearSelections(true);
  189. this.refresh();
  190. },scope:this}
  191. }
  192. });
  193. return true;
  194. }
  195. ,removeSource: function() {
  196. MODx.msg.confirm({
  197. title: _('source_remove')
  198. ,text: _('source_remove_confirm')
  199. ,url: this.config.url
  200. ,params: {
  201. action: 'source/remove'
  202. ,id: this.menu.record.id
  203. }
  204. ,listeners: {
  205. 'success': {fn:this.refresh,scope:this}
  206. }
  207. });
  208. }
  209. ,updateSource: function() {
  210. MODx.loadPage('source/update', 'id='+this.menu.record.id);
  211. }
  212. ,search: function(tf,newValue,oldValue) {
  213. var nv = newValue || tf;
  214. this.getStore().baseParams.query = Ext.isEmpty(nv) || Ext.isObject(nv) ? '' : nv;
  215. this.getBottomToolbar().changePage(1);
  216. //this.refresh();
  217. return true;
  218. }
  219. ,clearFilter: function() {
  220. this.getStore().baseParams = {
  221. action: 'source/getList'
  222. };
  223. Ext.getCmp('modx-source-search').reset();
  224. this.getBottomToolbar().changePage(1);
  225. //this.refresh();
  226. }
  227. });
  228. Ext.reg('modx-grid-sources',MODx.grid.Sources);
  229. /**
  230. * Generates the create Source window.
  231. *
  232. * @class MODx.window.CreateSource
  233. * @extends MODx.Window
  234. * @param {Object} config An object of options.
  235. * @xtype modx-window-source-create
  236. */
  237. MODx.window.CreateSource = function(config) {
  238. config = config || {};
  239. Ext.applyIf(config,{
  240. title: _('source_create')
  241. ,url: MODx.config.connector_url
  242. ,action: 'source/create'
  243. ,fields: [{
  244. xtype: 'textfield'
  245. ,fieldLabel: _('name')
  246. ,name: 'name'
  247. ,anchor: '100%'
  248. ,allowBlank: false
  249. },{
  250. xtype: 'textarea'
  251. ,fieldLabel: _('description')
  252. ,name: 'description'
  253. ,anchor: '100%'
  254. ,grow: true
  255. },{
  256. name: 'class_key'
  257. ,hiddenName: 'class_key'
  258. ,xtype: 'modx-combo-source-type'
  259. ,fieldLabel: _('source_type')
  260. ,anchor: '100%'
  261. ,allowBlank: false
  262. ,value: MODx.config.default_media_source_type
  263. }]
  264. ,keys: []
  265. });
  266. MODx.window.CreateSource.superclass.constructor.call(this,config);
  267. };
  268. Ext.extend(MODx.window.CreateSource,MODx.Window);
  269. Ext.reg('modx-window-source-create',MODx.window.CreateSource);
  270. MODx.grid.SourceTypes = function(config) {
  271. config = config || {};
  272. Ext.applyIf(config,{
  273. url: MODx.config.connector_url
  274. ,baseParams: {
  275. action: 'source/type/getlist'
  276. }
  277. ,fields: ['class','name','description']
  278. ,paging: true
  279. ,remoteSort: true
  280. ,columns: [{
  281. header: _('name')
  282. ,dataIndex: 'name'
  283. ,width: 150
  284. ,sortable: true
  285. ,renderer: Ext.util.Format.htmlEncode
  286. },{
  287. header: _('description')
  288. ,dataIndex: 'description'
  289. ,width: 300
  290. ,sortable: false
  291. ,renderer: Ext.util.Format.htmlEncode
  292. }]
  293. });
  294. MODx.grid.SourceTypes.superclass.constructor.call(this,config);
  295. };
  296. Ext.extend(MODx.grid.SourceTypes,MODx.grid.Grid);
  297. Ext.reg('modx-grid-source-types',MODx.grid.SourceTypes);