element.window.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. fred.window.Element = function (config) {
  2. config = config || {};
  3. Ext.applyIf(config, {
  4. title: _('fred.elements.quick_update'),
  5. closeAction: 'close',
  6. isUpdate: false,
  7. url: fred.config.connectorUrl,
  8. action: 'mgr/elements/update',
  9. modal: false,
  10. fields: this.getFields(config),
  11. autoHeight: true,
  12. width: 800,
  13. buttonAlign: 'left',
  14. buttons: [
  15. {
  16. xtype: 'fred-button-help',
  17. path: 'cmp/elements/'
  18. },
  19. '->',
  20. {
  21. text: config.cancelBtnText || _('cancel'),
  22. scope: this,
  23. handler: function () {
  24. config.closeAction !== 'close' ? this.hide() : this.close();
  25. }
  26. },
  27. {
  28. text: config.saveBtnText || _('save'),
  29. scope: this,
  30. handler: function() { this.submit(false); }
  31. },
  32. {
  33. text: config.saveBtnText || _('save_and_close'),
  34. cls: 'primary-button',
  35. scope: this,
  36. handler: this.submit
  37. }
  38. ],
  39. keys: [
  40. {
  41. key: Ext.EventObject.ENTER,
  42. shift: true,
  43. fn: this.submit,
  44. scope: this
  45. }
  46. ]
  47. });
  48. fred.window.Element.superclass.constructor.call(this, config);
  49. };
  50. Ext.extend(fred.window.Element, MODx.Window, {
  51. getFields: function (config) {
  52. return [
  53. {
  54. xtype: 'hidden',
  55. name: 'id',
  56. },
  57. {
  58. xtype: 'hidden',
  59. name: 'rank'
  60. },
  61. {
  62. layout: 'column',
  63. border: false,
  64. anchor: '100%',
  65. defaults: {
  66. layout: 'form',
  67. labelAlign: 'top',
  68. labelSeparator: '',
  69. anchor: '100%',
  70. border: false
  71. },
  72. items: [
  73. {
  74. columnWidth: .5,
  75. border: false,
  76. defaults: {
  77. msgTarget: 'under',
  78. anchor: '100%'
  79. },
  80. items: [
  81. {
  82. xtype: 'textfield',
  83. fieldLabel: _('fred.elements.name'),
  84. name: 'name',
  85. anchor: '100%',
  86. allowBlank: false
  87. },
  88. {
  89. xtype: 'textarea',
  90. fieldLabel: _('fred.elements.description'),
  91. name: 'description',
  92. anchor: '100%',
  93. allowBlank: true,
  94. height: 100
  95. }
  96. ]
  97. },
  98. {
  99. columnWidth: .5,
  100. border: false,
  101. defaults: {
  102. msgTarget: 'under',
  103. anchor: '100%'
  104. },
  105. items: [
  106. {
  107. xtype: 'fred-combo-themes',
  108. fieldLabel: _('fred.elements.theme'),
  109. name: 'theme_id',
  110. hiddenName: 'theme_id',
  111. anchor: '100%',
  112. listeners: {
  113. select: function(combo, record) {
  114. var category = this.find('name', 'category');
  115. if (!category[0]) return;
  116. category = category[0];
  117. category.setValue();
  118. category.enable();
  119. category.baseParams.theme = record.id;
  120. category.store.load();
  121. var optionSet = this.find('name', 'option_set');
  122. if (!optionSet[0]) return;
  123. optionSet = optionSet[0];
  124. optionSet.setValue(0);
  125. optionSet.enable();
  126. optionSet.baseParams.theme = record.id;
  127. optionSet.store.load();
  128. },
  129. scope: this
  130. },
  131. allowBlank: false,
  132. isUpdate: config.isUpdate
  133. },
  134. {
  135. xtype: 'fred-combo-element-categories',
  136. fieldLabel: _('fred.elements.category'),
  137. name: 'category',
  138. hiddenName: 'category',
  139. anchor: '100%',
  140. allowBlank: false
  141. },
  142. {
  143. xtype: 'fred-combo-element-option-sets',
  144. name: 'option_set',
  145. hiddenName: 'option_set',
  146. anchor: '100%',
  147. baseParams: {
  148. action: 'mgr/element_option_sets/getlist',
  149. addEmpty: 1,
  150. complete: 1
  151. },
  152. fieldLabel: _('fred.elements.option_set')
  153. }
  154. ]
  155. }
  156. ]
  157. },
  158. {
  159. layout: 'column',
  160. border: false,
  161. anchor: '100%',
  162. defaults: {
  163. layout: 'form',
  164. labelAlign: 'top',
  165. labelSeparator: '',
  166. anchor: '100%',
  167. border: false
  168. },
  169. items: [
  170. {
  171. columnWidth: 1,
  172. border: false,
  173. defaults: {
  174. msgTarget: 'under',
  175. anchor: '100%'
  176. },
  177. items: [
  178. {
  179. xtype: 'modx-combo-browser',
  180. fieldLabel: _('fred.elements.image'),
  181. triggerClass: 'x-form-image-trigger',
  182. name: 'image',
  183. anchor: '100%',
  184. allowBlank: true,
  185. listeners: {
  186. select: function (data) {
  187. this.setValue(data.fullRelativeUrl);
  188. }
  189. }
  190. },
  191. {
  192. xtype: Ext.ComponentMgr.isRegistered('modx-texteditor') ? 'modx-texteditor' : 'textarea',
  193. mimeType: 'text/html',
  194. name: 'content',
  195. fieldLabel: _('fred.elements.content'),
  196. anchor: '100%',
  197. height: 400,
  198. grow: false,
  199. value: '',
  200. listeners: {
  201. render: function () {
  202. if ((this.xtype === 'modx-texteditor') && this.editor)
  203. this.editor.getSession().setMode('ace/mode/twig')
  204. }
  205. }
  206. }
  207. ]
  208. }
  209. ]
  210. }]
  211. ;
  212. }
  213. });
  214. Ext.reg('fred-window-element', fred.window.Element);
  215. fred.window.ElementDuplicate = function (config) {
  216. config = config || {};
  217. Ext.applyIf(config, {
  218. title: _('fred.elements.duplicate'),
  219. closeAction: 'close',
  220. isUpdate: false,
  221. url: fred.config.connectorUrl,
  222. action: 'mgr/elements/duplicate',
  223. modal: true,
  224. fields: this.getFields(config),
  225. autoHeight: true,
  226. width: 800,
  227. keys: [
  228. {
  229. key: Ext.EventObject.ENTER,
  230. shift: true,
  231. fn: this.submit,
  232. scope: this
  233. }
  234. ]
  235. });
  236. fred.window.ElementDuplicate.superclass.constructor.call(this, config);
  237. };
  238. Ext.extend(fred.window.ElementDuplicate, MODx.Window, {
  239. firstCategorySelect: true,
  240. getFields: function (config) {
  241. return [
  242. {
  243. xtype: 'textfield',
  244. name: 'id',
  245. anchor: '100%',
  246. hidden: true
  247. },
  248. {
  249. xtype: 'textfield',
  250. fieldLabel: _('fred.elements.new_name'),
  251. name: 'name',
  252. anchor: '100%',
  253. allowBlank: true
  254. },
  255. {
  256. xtype: 'fred-combo-themes',
  257. fieldLabel: _('fred.elements.theme'),
  258. name: 'theme_id',
  259. hiddenName: 'theme_id',
  260. anchor: '100%',
  261. listeners: {
  262. select: function(combo, record) {
  263. if (this.firstCategorySelect === true) {
  264. this.firstCategorySelect = false;
  265. return;
  266. }
  267. var category = this.find('name', 'category');
  268. if (!category[0]) return;
  269. category = category[0];
  270. category.setValue();
  271. category.enable();
  272. category.baseParams.theme = record.id;
  273. category.store.load();
  274. },
  275. scope: this
  276. },
  277. allowBlank: false
  278. },
  279. {
  280. xtype: 'fred-combo-element-categories',
  281. fieldLabel: _('fred.elements.category'),
  282. name: 'category',
  283. hiddenName: 'category',
  284. anchor: '100%',
  285. allowBlank: false
  286. }
  287. ]
  288. }
  289. });
  290. Ext.reg('fred-window-element-duplicate', fred.window.ElementDuplicate);