combos.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. fred.combo.ExtendedBoolean = function (config) {
  2. config.useInt = config.useInt || false;
  3. var data = [
  4. [
  5. _('fred.global.any'),
  6. null,
  7. _('fred.global.any')
  8. ],
  9. [
  10. _('yes'),
  11. (config.useInt ? 1 : true),
  12. _('yes')
  13. ],
  14. [
  15. _('no'),
  16. (config.useInt ? 0 : false),
  17. _('no')
  18. ]
  19. ];
  20. if (config.dataLabel) {
  21. data = [
  22. [
  23. config.dataLabel + ': ' + _('fred.global.any'),
  24. null,
  25. _('fred.global.any')
  26. ],
  27. [
  28. config.dataLabel + ': ' + _('yes'),
  29. (config.useInt ? 1 : true),
  30. _('yes')
  31. ],
  32. [
  33. config.dataLabel + ': ' + _('no'),
  34. (config.useInt ? 0 : false),
  35. _('no')
  36. ]
  37. ];
  38. }
  39. config = config || {};
  40. Ext.applyIf(config, {
  41. store: new Ext.data.SimpleStore({
  42. fields: ['d', 'v', 'cleanLabel'],
  43. data: data
  44. }),
  45. displayField: 'd',
  46. valueField: 'v',
  47. mode: 'local',
  48. triggerAction: 'all',
  49. editable: false,
  50. selectOnFocus: false,
  51. preventRender: true,
  52. forceSelection: true,
  53. enableKeyEvents: true,
  54. tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item">{cleanLabel}</div></tpl>')
  55. });
  56. fred.combo.ExtendedBoolean.superclass.constructor.call(this, config);
  57. };
  58. Ext.extend(fred.combo.ExtendedBoolean, MODx.combo.ComboBox);
  59. Ext.reg('fred-combo-extended-boolean', fred.combo.ExtendedBoolean);
  60. fred.combo.Boolean = function (config) {
  61. config.useInt = config.useInt || false;
  62. var data = [
  63. [
  64. _('yes'),
  65. (config.useInt ? 1 : true),
  66. _('yes')
  67. ],
  68. [
  69. _('no'),
  70. (config.useInt ? 0 : false),
  71. _('no')
  72. ]
  73. ];
  74. if (config.dataLabel) {
  75. data = [
  76. [
  77. config.dataLabel + ': ' + _('yes'),
  78. (config.useInt ? 1 : true), _('yes')
  79. ],
  80. [
  81. config.dataLabel + ': ' + _('no'),
  82. (config.useInt ? 0 : false), _('no')
  83. ]
  84. ];
  85. }
  86. config = config || {};
  87. Ext.applyIf(config, {
  88. store: new Ext.data.SimpleStore({
  89. fields: ['d', 'v', 'cleanLabel'],
  90. data: data
  91. }),
  92. displayField: 'd',
  93. valueField: 'v',
  94. mode: 'local',
  95. triggerAction: 'all',
  96. editable: false,
  97. selectOnFocus: false,
  98. preventRender: true,
  99. forceSelection: true,
  100. enableKeyEvents: true,
  101. tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item">{cleanLabel}</div></tpl>')
  102. });
  103. fred.combo.Boolean.superclass.constructor.call(this, config);
  104. };
  105. Ext.extend(fred.combo.Boolean, MODx.combo.ComboBox, {
  106. setValue: function (value) {
  107. if ((value !== undefined) && (this.config.useInt === true)) {
  108. if (value === '') {
  109. value = null;
  110. }
  111. if (value !== '') {
  112. value = +value;
  113. }
  114. }
  115. fred.combo.Boolean.superclass.setValue.call(this, value);
  116. }
  117. });
  118. Ext.reg('fred-combo-boolean', fred.combo.Boolean);
  119. fred.combo.BlueprintCategories = function (config) {
  120. config = config || {};
  121. Ext.applyIf(config, {
  122. name: 'category',
  123. hiddenName: 'category',
  124. displayField: 'name',
  125. valueField: 'id',
  126. fields: ['name', 'id'],
  127. pageSize: 20,
  128. url: fred.config.connectorUrl,
  129. baseParams: {
  130. action: 'mgr/blueprint_categories/getlist',
  131. addAll: config.addAll || 0
  132. }
  133. });
  134. fred.combo.BlueprintCategories.superclass.constructor.call(this, config);
  135. };
  136. Ext.extend(fred.combo.BlueprintCategories, MODx.combo.ComboBox);
  137. Ext.reg('fred-combo-blueprint-categories', fred.combo.BlueprintCategories);
  138. fred.combo.ElementCategories = function (config) {
  139. config = config || {};
  140. Ext.applyIf(config, {
  141. name: 'category',
  142. hiddenName: 'category',
  143. displayField: 'name',
  144. valueField: 'id',
  145. fields: ['name', 'id'],
  146. pageSize: 20,
  147. url: fred.config.connectorUrl,
  148. baseParams: {
  149. action: 'mgr/element_categories/getlist',
  150. addAll: config.addAll || 0
  151. }
  152. });
  153. fred.combo.ElementCategories.superclass.constructor.call(this, config);
  154. };
  155. Ext.extend(fred.combo.ElementCategories, MODx.combo.ComboBox);
  156. Ext.reg('fred-combo-element-categories', fred.combo.ElementCategories);
  157. fred.combo.ElementOptionSets = function (config) {
  158. config = config || {};
  159. Ext.applyIf(config, {
  160. name: 'option_set',
  161. hiddenName: 'option_set',
  162. displayField: 'name',
  163. valueField: 'id',
  164. fields: ['name', 'id', 'description'],
  165. tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item"><span style="font-weight: bold">{name:htmlEncode}</span>',
  166. '<tpl if="description"> - <span style="font-style:italic">{description:htmlEncode}</span></tpl>',
  167. '</div></tpl>'),
  168. pageSize: 20,
  169. url: fred.config.connectorUrl,
  170. baseParams: {
  171. action: 'mgr/element_option_sets/getlist',
  172. addEmpty: config.addEmpty || 0
  173. }
  174. });
  175. fred.combo.ElementOptionSets.superclass.constructor.call(this, config);
  176. };
  177. Ext.extend(fred.combo.ElementOptionSets, MODx.combo.ComboBox);
  178. Ext.reg('fred-combo-element-option-sets', fred.combo.ElementOptionSets);
  179. fred.combo.Themes = function (config) {
  180. config = config || {};
  181. Ext.applyIf(config, {
  182. name: 'theme',
  183. hiddenName: 'theme',
  184. displayField: 'name',
  185. valueField: 'id',
  186. fields: ['name', 'id', 'theme_folder'],
  187. pageSize: 20,
  188. isUpdate: false,
  189. url: fred.config.connectorUrl,
  190. baseParams: {
  191. action: 'mgr/themes/getlist',
  192. addAll: config.addAll || 0
  193. }
  194. });
  195. fred.combo.Themes.superclass.constructor.call(this, config);
  196. if (config.isUpdate === false) {
  197. this.store.load();
  198. this.store.on('load', function(store, r) {
  199. this.setValue(r[0].id);
  200. this.fireEvent('select', this, r[0]);
  201. }, this, {single: true});
  202. }
  203. };
  204. Ext.extend(fred.combo.Themes, MODx.combo.ComboBox);
  205. Ext.reg('fred-combo-themes', fred.combo.Themes);
  206. fred.combo.Template = function (config, getStore) {
  207. config = config || {};
  208. if (!config.clearBtnCls) {
  209. if (MODx.config.connector_url) {
  210. config.clearBtnCls = 'x-form-trigger';
  211. } else {
  212. config.clearBtnCls = null;
  213. }
  214. }
  215. if (!config.expandBtnCls) {
  216. if (MODx.config.connector_url) {
  217. config.expandBtnCls = 'x-form-trigger';
  218. } else {
  219. config.expandBtnCls = null;
  220. }
  221. }
  222. Ext.applyIf(config, {
  223. name: 'templates',
  224. hiddenName: 'templates[]',
  225. displayField: 'templatename',
  226. valueField: 'id',
  227. fields: ['templatename', 'id'],
  228. mode: 'remote',
  229. triggerAction: 'all',
  230. typeAhead: true,
  231. editable: true,
  232. forceSelection: false,
  233. pageSize: 20,
  234. url: fred.config.connectorUrl,
  235. baseParams: {
  236. action: 'mgr/extra/gettemplates',
  237. hideUsed: 1
  238. }
  239. });
  240. Ext.applyIf(config, {
  241. store: new Ext.data.JsonStore({
  242. url: config.url,
  243. root: 'results',
  244. totalProperty: 'total',
  245. fields: config.fields,
  246. errorReader: MODx.util.JSONReader,
  247. baseParams: config.baseParams || {},
  248. remoteSort: config.remoteSort || false,
  249. autoDestroy: true
  250. })
  251. });
  252. if (getStore === true) {
  253. config.store.load();
  254. return config.store;
  255. }
  256. fred.combo.Template.superclass.constructor.call(this, config);
  257. this.config = config;
  258. return this;
  259. };
  260. Ext.extend(fred.combo.Template, Ext.ux.form.SuperBoxSelect);
  261. Ext.reg('fred-combo-template', fred.combo.Template);
  262. fred.combo.RootCategory = function (config, getStore) {
  263. config = config || {};
  264. if (!config.clearBtnCls) {
  265. if (MODx.config.connector_url) {
  266. config.clearBtnCls = 'x-form-trigger';
  267. } else {
  268. config.clearBtnCls = null;
  269. }
  270. }
  271. if (!config.expandBtnCls) {
  272. if (MODx.config.connector_url) {
  273. config.expandBtnCls = 'x-form-trigger';
  274. } else {
  275. config.expandBtnCls = null;
  276. }
  277. }
  278. Ext.applyIf(config, {
  279. name: 'categories',
  280. hiddenName: 'categories[]',
  281. displayField: 'category',
  282. valueField: 'category',
  283. fields: ['category'],
  284. mode: 'remote',
  285. triggerAction: 'all',
  286. typeAhead: true,
  287. editable: true,
  288. forceSelection: false,
  289. pageSize: 20,
  290. url: fred.config.connectorUrl,
  291. baseParams: {
  292. action: 'mgr/extra/getcategories',
  293. parent: 0
  294. }
  295. });
  296. Ext.applyIf(config, {
  297. store: new Ext.data.JsonStore({
  298. url: config.url,
  299. root: 'results',
  300. totalProperty: 'total',
  301. fields: config.fields,
  302. errorReader: MODx.util.JSONReader,
  303. baseParams: config.baseParams || {},
  304. remoteSort: config.remoteSort || false,
  305. autoDestroy: true
  306. })
  307. });
  308. if (getStore === true) {
  309. config.store.load();
  310. return config.store;
  311. }
  312. fred.combo.RootCategory.superclass.constructor.call(this, config);
  313. this.config = config;
  314. return this;
  315. };
  316. Ext.extend(fred.combo.RootCategory, Ext.ux.form.SuperBoxSelect);
  317. Ext.reg('fred-combo-root-category', fred.combo.RootCategory);
  318. fred.combo.InstalledPackages = function (config) {
  319. config = config || {};
  320. Ext.applyIf(config, {
  321. name: 'package',
  322. hiddenName: 'package',
  323. displayField: 'package_name',
  324. valueField: 'package_name',
  325. fields: ['package_name'],
  326. pageSize: 20,
  327. isUpdate: false,
  328. url: fred.config.connectorUrl,
  329. editable: true,
  330. forceSelection: false,
  331. typeAhead: false,
  332. selectOnFocus: false,
  333. baseParams: {
  334. action: 'mgr/extra/getinstalledpackages'
  335. }
  336. });
  337. fred.combo.Themes.superclass.constructor.call(this, config);
  338. if (config.isUpdate === false) {
  339. this.store.load();
  340. this.store.on('load', function(store, r) {
  341. this.setValue(r[0].id);
  342. this.fireEvent('select', this, r[0]);
  343. }, this, {single: true});
  344. }
  345. };
  346. Ext.extend(fred.combo.InstalledPackages, MODx.combo.ComboBox);
  347. Ext.reg('fred-combo-installed-packages', fred.combo.InstalledPackages);