modx.combo.js 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. Ext.namespace('MODx.combo');
  2. /* disable shadows for the combo-list globally, saves a few dom nodes as it's not used anyways */
  3. Ext.form.ComboBox.prototype.shadow = false;
  4. /* replaces the default img tag for the combo trigger with a div to make the use of iconfonts with :before possible */
  5. Ext.override(Ext.form.TriggerField, {
  6. // this is the exact method from the source code, just the triggerConfig is modified to not use an img tag
  7. // We cannot override the prototype Ext.form.TriggerField.prototype.triggerConfig because we loose the option to add a custom triggerClass
  8. onRender: function(ct, position){
  9. this.doc = Ext.isIE ? Ext.getBody() : Ext.getDoc();
  10. Ext.form.TriggerField.superclass.onRender.call(this, ct, position);
  11. this.wrap = this.el.wrap({cls: 'x-form-field-wrap x-form-field-trigger-wrap'});
  12. this.trigger = this.wrap.createChild(this.triggerConfig ||
  13. {tag: 'div', cls: 'x-form-trigger ' + (this.triggerClass || '')});
  14. this.initTrigger();
  15. if(!this.width){
  16. this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
  17. }
  18. this.resizeEl = this.positionEl = this.wrap;
  19. }
  20. });
  21. /* store the original onLoad method to have acces to it in the override */
  22. var originalComboBoxOnLoad = Ext.form.ComboBox.prototype.onLoad;
  23. /* fixes combobox value loading issue */
  24. Ext.override(Ext.form.ComboBox, {
  25. loaded: false
  26. ,setValue: Ext.form.ComboBox.prototype.setValue.createSequence(function(v) {
  27. var a = this.store.find(this.valueField, v);
  28. if (typeof v !== 'undefined' && v !== null && this.mode == 'remote' && a == -1 && !this.loaded) {
  29. var p = {};
  30. p[this.valueField] = v;
  31. this.loaded = true;
  32. this.store.load({
  33. scope: this
  34. ,params: p
  35. ,callback: function() {
  36. this.setValue(v);
  37. this.collapse()
  38. }
  39. })
  40. }
  41. })
  42. // this sets the width of combobox dropdown lists automatically to the width of the combobox element
  43. // and thus prevents the sometimes unnecessary wide dropdowns
  44. ,onLoad: function() {
  45. var ret = originalComboBoxOnLoad.apply(this,arguments);
  46. // true flag on getWidth() to ignore border and padding
  47. var maxwidth = Math.max(this.minListWidth || 0, this.wrap.getWidth(true));
  48. this.list.setWidth(maxwidth);
  49. return ret;
  50. }
  51. });
  52. MODx.combo.ComboBox = function(config,getStore) {
  53. config = config || {};
  54. Ext.applyIf(config,{
  55. displayField: 'name'
  56. ,valueField: 'id'
  57. ,triggerAction: 'all'
  58. ,fields: ['id','name']
  59. ,baseParams: {
  60. action: 'getList'
  61. }
  62. ,width: 150
  63. // ,listWidth: 300
  64. ,editable: false
  65. ,resizable: true
  66. ,typeAhead: false
  67. ,forceSelection: true
  68. ,minChars: 3
  69. ,cls: 'modx-combo'
  70. ,tries: 0
  71. });
  72. Ext.applyIf(config,{
  73. store: new Ext.data.JsonStore({
  74. url: config.connector || config.url
  75. ,root: 'results'
  76. ,totalProperty: 'total'
  77. ,fields: config.fields
  78. ,errorReader: MODx.util.JSONReader
  79. ,baseParams: config.baseParams || {}
  80. ,remoteSort: config.remoteSort || false
  81. ,autoDestroy: true
  82. ,listeners: {
  83. 'loadexception': {fn: function(o,trans,resp) {
  84. var status = _('code') + ': ' + resp.status + ' ' + resp.statusText + '<br/>';
  85. MODx.msg.alert(_('error'), status + resp.responseText);
  86. }}
  87. }
  88. })
  89. });
  90. if (getStore === true) {
  91. config.store.load();
  92. return config.store;
  93. }
  94. MODx.combo.ComboBox.superclass.constructor.call(this,config);
  95. this.config = config;
  96. this.addEvents({
  97. 'loaded': true
  98. });
  99. // remove the custom open class on collapse
  100. this.on('collapse', function() {
  101. this.wrap.removeClass('x-trigger-wrap-open');
  102. });
  103. this.store.on('load', function() {
  104. // Workaround to let the combobox know the store is loaded (to help hide/display the pagination if required)
  105. this.fireEvent('loaded', this);
  106. this.loaded = true;
  107. }, this, {
  108. single: true
  109. });
  110. return this;
  111. };
  112. Ext.extend(MODx.combo.ComboBox,Ext.form.ComboBox, {
  113. expand : function(){
  114. if(this.isExpanded() || !this.hasFocus){
  115. return;
  116. }
  117. // unfortunately there is no default indicator wether a combo is open or not, so we add a class here
  118. this.wrap.addClass('x-trigger-wrap-open');
  119. if (this.mode == 'remote' && !this.loaded && this.tries < 4) {
  120. // Store not yet loaded, let's wait a little bit
  121. this.tries += 1;
  122. Ext.defer(this.expand, 250, this);
  123. return false;
  124. }
  125. this.tries = 0;
  126. if(this.title || this.pageSize){
  127. this.assetHeight = 0;
  128. if(this.title){
  129. this.assetHeight += this.header.getHeight();
  130. }
  131. if(this.pageSize < this.store.getTotalCount()){
  132. this.assetHeight += this.footer.getHeight();
  133. } else {
  134. this.list.setHeight(this.list.getHeight() - this.footer.getHeight());
  135. this.pageTb.hide();
  136. }
  137. }
  138. if(this.bufferSize){
  139. this.doResize(this.bufferSize);
  140. delete this.bufferSize;
  141. }
  142. this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
  143. // zindex can change, re-check it and set it if necessary
  144. this.list.setZIndex(this.getZIndex());
  145. this.list.show();
  146. if(Ext.isGecko2){
  147. this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
  148. }
  149. this.mon(Ext.getDoc(), {
  150. scope: this,
  151. mousewheel: this.collapseIf,
  152. mousedown: this.collapseIf
  153. });
  154. this.fireEvent('expand', this);
  155. }
  156. });
  157. Ext.reg('modx-combo',MODx.combo.ComboBox);
  158. Ext.util.Format.comboRenderer = function (combo,val) {
  159. return function (v,md,rec,ri,ci,s) {
  160. if (!s) return v;
  161. if (!combo.findRecord) return v;
  162. var record = combo.findRecord(combo.valueField, v);
  163. return record ? record.get(combo.displayField) : val;
  164. }
  165. };
  166. /** @deprecated MODX 2.2 */
  167. MODx.combo.Renderer = function(combo) {
  168. var loaded = false;
  169. return (function(v) {
  170. var idx,rec;
  171. if (!combo.store) return v;
  172. if (!loaded) {
  173. if (combo.store.proxy !== undefined && combo.store.proxy !== null) {
  174. combo.store.load();
  175. }
  176. loaded = true;
  177. }
  178. var v2 = combo.getValue();
  179. idx = combo.store.find(combo.valueField,v2 ? v2 : v);
  180. rec = combo.store.getAt(idx);
  181. return (rec === undefined || rec === null ? (v2 ? v2 : v) : rec.get(combo.displayField));
  182. });
  183. };
  184. MODx.combo.Boolean = function(config) {
  185. config = config || {};
  186. Ext.applyIf(config,{
  187. store: new Ext.data.SimpleStore({
  188. fields: ['d','v']
  189. ,data: [[_('yes'),true],[_('no'),false]]
  190. })
  191. ,displayField: 'd'
  192. ,valueField: 'v'
  193. ,mode: 'local'
  194. ,triggerAction: 'all'
  195. ,editable: false
  196. ,selectOnFocus: false
  197. ,preventRender: true
  198. ,forceSelection: true
  199. ,enableKeyEvents: true
  200. });
  201. MODx.combo.Boolean.superclass.constructor.call(this,config);
  202. };
  203. Ext.extend(MODx.combo.Boolean,MODx.combo.ComboBox);
  204. Ext.reg('combo-boolean',MODx.combo.Boolean);
  205. Ext.reg('modx-combo-boolean',MODx.combo.Boolean);
  206. MODx.util.PasswordField = function(config) {
  207. config = config || {};
  208. delete config.xtype;
  209. Ext.applyIf(config,{
  210. xtype: 'textfield'
  211. ,inputType: 'password'
  212. });
  213. MODx.util.PasswordField.superclass.constructor.call(this,config);
  214. };
  215. Ext.extend(MODx.util.PasswordField,Ext.form.TextField);
  216. Ext.reg('text-password',MODx.util.PasswordField);
  217. Ext.reg('modx-text-password',MODx.util.PasswordField);
  218. MODx.combo.User = function(config) {
  219. config = config || {};
  220. Ext.applyIf(config,{
  221. name: 'user'
  222. ,hiddenName: 'user'
  223. ,displayField: 'username'
  224. ,valueField: 'id'
  225. ,fields: ['username','id']
  226. ,pageSize: 20
  227. ,url: MODx.config.connector_url
  228. ,baseParams: {
  229. action: 'security/user/getlist'
  230. }
  231. ,typeAhead: true
  232. ,editable: true
  233. });
  234. MODx.combo.User.superclass.constructor.call(this,config);
  235. };
  236. Ext.extend(MODx.combo.User,MODx.combo.ComboBox);
  237. Ext.reg('modx-combo-user',MODx.combo.User);
  238. MODx.combo.UserGroup = function(config) {
  239. config = config || {};
  240. Ext.applyIf(config,{
  241. name: 'group'
  242. ,hiddenName: 'group'
  243. ,displayField: 'name'
  244. ,valueField: 'id'
  245. ,fields: ['name','id','description']
  246. // ,listWidth: 300
  247. ,pageSize: 20
  248. ,url: MODx.config.connector_url
  249. ,baseParams: {
  250. action: 'security/group/getlist'
  251. }
  252. ,tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item"><span style="font-weight: bold">{name:htmlEncode}</span>'
  253. ,'<br />{description:htmlEncode}</div></tpl>')
  254. });
  255. MODx.combo.UserGroup.superclass.constructor.call(this,config);
  256. };
  257. Ext.extend(MODx.combo.UserGroup,MODx.combo.ComboBox);
  258. Ext.reg('modx-combo-usergroup',MODx.combo.UserGroup);
  259. MODx.combo.UserGroupRole = function(config) {
  260. config = config || {};
  261. Ext.applyIf(config,{
  262. name: 'role'
  263. ,hiddenName: 'role'
  264. ,displayField: 'name'
  265. ,valueField: 'id'
  266. ,fields: ['name','id']
  267. ,pageSize: 20
  268. ,url: MODx.config.connector_url
  269. ,baseParams: {
  270. action: 'security/role/getlist'
  271. }
  272. });
  273. MODx.combo.UserGroupRole.superclass.constructor.call(this,config);
  274. };
  275. Ext.extend(MODx.combo.UserGroupRole,MODx.combo.ComboBox);
  276. Ext.reg('modx-combo-usergrouprole',MODx.combo.UserGroupRole);
  277. MODx.combo.EventGroup = function(config) {
  278. config = config || {};
  279. Ext.applyIf(config,{
  280. name: 'group'
  281. ,hiddenName: 'group'
  282. ,displayField: 'name'
  283. ,valueField: 'name'
  284. ,fields: ['name']
  285. ,pageSize: 20
  286. ,url: MODx.config.connector_url
  287. ,baseParams: {
  288. action: 'system/event/grouplist'
  289. }
  290. ,tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item"><span style="font-weight: bold">{name:htmlEncode}</span>','</div></tpl>')
  291. });
  292. MODx.combo.EventGroup.superclass.constructor.call(this,config);
  293. };
  294. Ext.extend(MODx.combo.EventGroup,MODx.combo.ComboBox);
  295. Ext.reg('modx-combo-eventgroup',MODx.combo.EventGroup);
  296. MODx.combo.ResourceGroup = function(config) {
  297. config = config || {};
  298. Ext.applyIf(config,{
  299. name: 'resourcegroup'
  300. ,hiddenName: 'resourcegroup'
  301. ,displayField: 'name'
  302. ,valueField: 'id'
  303. ,fields: ['name','id']
  304. ,pageSize: 20
  305. ,url: MODx.config.connector_url
  306. ,baseParams: {
  307. action: 'security/resourcegroup/getlist'
  308. }
  309. });
  310. MODx.combo.ResourceGroup.superclass.constructor.call(this,config);
  311. };
  312. Ext.extend(MODx.combo.ResourceGroup,MODx.combo.ComboBox);
  313. Ext.reg('modx-combo-resourcegroup',MODx.combo.ResourceGroup);
  314. MODx.combo.Context = function(config) {
  315. config = config || {};
  316. Ext.applyIf(config,{
  317. name: 'context'
  318. ,hiddenName: 'context'
  319. ,displayField: 'key'
  320. ,valueField: 'key'
  321. ,fields: ['key', 'name']
  322. ,pageSize: 20
  323. ,url: MODx.config.connector_url
  324. ,baseParams: {
  325. action: 'context/getlist',
  326. exclude: config.exclude || ''
  327. }
  328. ,tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item"><span style="font-weight: bold">{name:htmlEncode}</span> <span style="font-style: italic; font-size: small;">({key:htmlEncode})</span></div></tpl>')
  329. });
  330. MODx.combo.Context.superclass.constructor.call(this,config);
  331. };
  332. Ext.extend(MODx.combo.Context,MODx.combo.ComboBox);
  333. Ext.reg('modx-combo-context',MODx.combo.Context);
  334. MODx.combo.Policy = function(config) {
  335. config = config || {};
  336. Ext.applyIf(config,{
  337. name: 'policy'
  338. ,hiddenName: 'policy'
  339. ,displayField: 'name'
  340. ,valueField: 'id'
  341. ,fields: ['id','name','permissions']
  342. ,allowBlank: false
  343. ,editable: false
  344. ,pageSize: 20
  345. ,url: MODx.config.connector_url
  346. ,baseParams: {
  347. action: 'security/access/policy/getlist'
  348. }
  349. });
  350. MODx.combo.Policy.superclass.constructor.call(this,config);
  351. };
  352. Ext.extend(MODx.combo.Policy,MODx.combo.ComboBox);
  353. Ext.reg('modx-combo-policy',MODx.combo.Policy);
  354. MODx.combo.Template = function(config) {
  355. config = config || {};
  356. Ext.applyIf(config,{
  357. name: 'template'
  358. ,hiddenName: 'template'
  359. ,displayField: 'templatename'
  360. ,valueField: 'id'
  361. ,pageSize: 20
  362. ,fields: ['id','templatename','description','category_name']
  363. ,tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item"><span style="font-weight: bold">{templatename:htmlEncode}</span>'
  364. ,'<tpl if="category_name"> - <span style="font-style:italic">{category_name:htmlEncode}</span></tpl>'
  365. ,'<br />{description:htmlEncode()}</div></tpl>')
  366. ,url: MODx.config.connector_url
  367. ,baseParams: {
  368. action: 'element/template/getlist'
  369. ,combo: 1
  370. }
  371. // ,listWidth: 350
  372. ,allowBlank: true
  373. });
  374. MODx.combo.Template.superclass.constructor.call(this,config);
  375. };
  376. Ext.extend(MODx.combo.Template,MODx.combo.ComboBox);
  377. Ext.reg('modx-combo-template',MODx.combo.Template);
  378. MODx.combo.Category = function(config) {
  379. config = config || {};
  380. Ext.applyIf(config,{
  381. name: 'category'
  382. ,hiddenName: 'category'
  383. ,displayField: 'name'
  384. ,valueField: 'id'
  385. ,mode: 'remote'
  386. ,fields: ['id','category','parent','name']
  387. ,forceSelection: true
  388. ,typeAhead: false
  389. ,allowBlank: true
  390. ,editable: false
  391. ,enableKeyEvents: true
  392. ,pageSize: 20
  393. ,url: MODx.config.connector_url
  394. ,baseParams: {
  395. action: 'element/category/getlist'
  396. ,showNone: true
  397. ,limit: 0
  398. }
  399. });
  400. MODx.combo.Category.superclass.constructor.call(this,config);
  401. };
  402. Ext.extend(MODx.combo.Category,MODx.combo.ComboBox,{
  403. _onblur: function(t,e) {
  404. var v = this.getRawValue();
  405. this.setRawValue(v);
  406. this.setValue(v,true);
  407. }
  408. });
  409. Ext.reg('modx-combo-category',MODx.combo.Category);
  410. MODx.combo.Language = function(config) {
  411. config = config || {};
  412. Ext.applyIf(config,{
  413. name: 'language'
  414. ,hiddenName: 'language'
  415. ,displayField: 'name'
  416. ,valueField: 'name'
  417. ,fields: ['name']
  418. ,typeAhead: true
  419. ,minChars: 1
  420. ,editable: true
  421. ,allowBlank: true
  422. // ,pageSize: 20
  423. ,url: MODx.config.connector_url
  424. ,baseParams: {
  425. action: 'system/language/getlist'
  426. }
  427. });
  428. MODx.combo.Language.superclass.constructor.call(this,config);
  429. };
  430. Ext.extend(MODx.combo.Language,MODx.combo.ComboBox);
  431. Ext.reg('modx-combo-language',MODx.combo.Language);
  432. MODx.combo.Charset = function(config) {
  433. config = config || {};
  434. Ext.applyIf(config,{
  435. name: 'charset'
  436. ,hiddenName: 'charset'
  437. ,displayField: 'text'
  438. ,valueField: 'value'
  439. ,fields: ['value','text']
  440. ,forceSelection: true
  441. ,typeAhead: false
  442. ,editable: false
  443. ,allowBlank: false
  444. // ,listWidth: 300
  445. ,url: MODx.config.connector_url
  446. ,baseParams: {
  447. action: 'system/charset/getlist'
  448. }
  449. });
  450. MODx.combo.Charset.superclass.constructor.call(this,config);
  451. };
  452. Ext.extend(MODx.combo.Charset,MODx.combo.ComboBox);
  453. Ext.reg('modx-combo-charset',MODx.combo.Charset);
  454. MODx.combo.RTE = function(config) {
  455. config = config || {};
  456. Ext.applyIf(config,{
  457. name: 'rte'
  458. ,hiddenName: 'rte'
  459. ,displayField: 'value'
  460. ,valueField: 'value'
  461. ,fields: ['value']
  462. ,forceSelection: true
  463. ,typeAhead: false
  464. ,editable: false
  465. ,allowBlank: false
  466. // ,listWidth: 300
  467. ,url: MODx.config.connector_url
  468. ,baseParams: {
  469. action: 'system/rte/getlist'
  470. }
  471. });
  472. MODx.combo.RTE.superclass.constructor.call(this,config);
  473. };
  474. Ext.extend(MODx.combo.RTE,MODx.combo.ComboBox);
  475. Ext.reg('modx-combo-rte',MODx.combo.RTE);
  476. MODx.combo.Role = function(config) {
  477. config = config || {};
  478. Ext.applyIf(config,{
  479. name: 'role'
  480. ,hiddenName: 'role'
  481. ,forceSelection: true
  482. ,typeAhead: false
  483. ,editable: false
  484. ,allowBlank: false
  485. // ,listWidth: 300
  486. ,pageSize: 20
  487. ,url: MODx.config.connector_url
  488. ,baseParams: {
  489. action: 'security/role/getlist'
  490. ,addNone: true
  491. }
  492. });
  493. MODx.combo.Role.superclass.constructor.call(this,config);
  494. };
  495. Ext.extend(MODx.combo.Role,MODx.combo.ComboBox);
  496. Ext.reg('modx-combo-role',MODx.combo.Role);
  497. MODx.combo.ContentType = function(config) {
  498. config = config || {};
  499. Ext.applyIf(config,{
  500. name: 'content_type'
  501. ,hiddenName: 'content_type'
  502. ,forceSelection: true
  503. ,typeAhead: false
  504. ,editable: false
  505. ,allowBlank: false
  506. // ,listWidth: 300
  507. ,pageSize: 20
  508. ,url: MODx.config.connector_url
  509. ,baseParams: {
  510. action: 'system/contenttype/getlist'
  511. }
  512. });
  513. MODx.combo.ContentType.superclass.constructor.call(this,config);
  514. };
  515. Ext.extend(MODx.combo.ContentType,MODx.combo.ComboBox);
  516. Ext.reg('modx-combo-content-type',MODx.combo.ContentType);
  517. MODx.combo.ContentDisposition = function(config) {
  518. config = config || {};
  519. Ext.applyIf(config,{
  520. store: new Ext.data.SimpleStore({
  521. fields: ['d','v']
  522. ,data: [[_('inline'),0],[_('attachment'),1]]
  523. })
  524. ,name: 'content_dispo'
  525. ,hiddenName: 'content_dispo'
  526. ,displayField: 'd'
  527. ,valueField: 'v'
  528. ,mode: 'local'
  529. ,triggerAction: 'all'
  530. ,editable: false
  531. ,pageSize: 20
  532. ,selectOnFocus: false
  533. ,preventRender: true
  534. });
  535. MODx.combo.ContentDisposition.superclass.constructor.call(this,config);
  536. };
  537. Ext.extend(MODx.combo.ContentDisposition,MODx.combo.ComboBox);
  538. Ext.reg('modx-combo-content-disposition',MODx.combo.ContentDisposition);
  539. MODx.combo.ClassMap = function(config) {
  540. config = config || {};
  541. Ext.applyIf(config,{
  542. name: 'class'
  543. ,hiddenName: 'class'
  544. ,url: MODx.config.connector_url
  545. ,baseParams: {
  546. action: 'system/classmap/getlist'
  547. }
  548. ,displayField: 'class'
  549. ,valueField: 'class'
  550. ,fields: ['class']
  551. ,editable: false
  552. ,pageSize: 20
  553. });
  554. MODx.combo.ClassMap.superclass.constructor.call(this,config);
  555. };
  556. Ext.extend(MODx.combo.ClassMap,MODx.combo.ComboBox);
  557. Ext.reg('modx-combo-class-map',MODx.combo.ClassMap);
  558. MODx.combo.ClassDerivatives = function(config) {
  559. config = config || {};
  560. Ext.applyIf(config,{
  561. name: 'class'
  562. ,hiddenName: 'class'
  563. ,url: MODx.config.connector_url
  564. ,baseParams: {
  565. action: 'system/derivatives/getList'
  566. ,skip: 'modXMLRPCResource'
  567. ,'class': 'modResource'
  568. }
  569. ,displayField: 'name'
  570. ,valueField: 'id'
  571. ,fields: ['id','name']
  572. ,forceSelection: true
  573. ,typeAhead: false
  574. ,editable: false
  575. ,allowBlank: false
  576. // ,listWidth: 300
  577. ,pageSize: 20
  578. });
  579. MODx.combo.ClassDerivatives.superclass.constructor.call(this,config);
  580. };
  581. Ext.extend(MODx.combo.ClassDerivatives,MODx.combo.ComboBox);
  582. Ext.reg('modx-combo-class-derivatives',MODx.combo.ClassDerivatives);
  583. MODx.combo.Object = function(config) {
  584. config = config || {};
  585. Ext.applyIf(config,{
  586. name: 'object'
  587. ,hiddenName: 'object'
  588. ,url: MODx.config.connector_url
  589. ,baseParams: {
  590. action: 'workspace/builder/getAssocObject'
  591. ,class_key: 'modResource'
  592. }
  593. ,displayField: 'name'
  594. ,valueField: 'id'
  595. ,fields: ['id','name']
  596. ,pageSize: 10
  597. ,editable: false
  598. });
  599. MODx.combo.Object.superclass.constructor.call(this,config);
  600. };
  601. Ext.extend(MODx.combo.Object,MODx.combo.ComboBox);
  602. Ext.reg('modx-combo-object',MODx.combo.Object);
  603. MODx.combo.Namespace = function(config) {
  604. config = config || {};
  605. Ext.applyIf(config,{
  606. name: 'namespace'
  607. ,hiddenName: 'namespace'
  608. ,typeAhead: true
  609. ,minChars: 1
  610. ,queryParam: 'search'
  611. ,editable: true
  612. ,allowBlank: true
  613. ,preselectValue: false
  614. // ,listWidth: 300
  615. ,pageSize: 20
  616. ,url: MODx.config.connector_url
  617. ,baseParams: {
  618. action: 'workspace/namespace/getlist'
  619. }
  620. ,fields: ['name']
  621. ,displayField: 'name'
  622. ,valueField: 'name'
  623. });
  624. MODx.combo.Namespace.superclass.constructor.call(this,config);
  625. if (config.preselectValue !== false) {
  626. this.store.on('load', this.preselectFirstValue, this, {single: true});
  627. this.store.load();
  628. }
  629. };
  630. Ext.extend(MODx.combo.Namespace,MODx.combo.ComboBox, {
  631. preselectFirstValue: function(r) {
  632. var item;
  633. if (this.config.preselectValue == '') {
  634. item = r.getAt(0);
  635. } else {
  636. var found = r.find('name', this.config.preselectValue);
  637. if (found != -1) {
  638. item = r.getAt(found);
  639. } else {
  640. item = r.getAt(0);
  641. }
  642. }
  643. if (item) {
  644. this.setValue(item.data.name);
  645. this.fireEvent('select', this, item);
  646. }
  647. }
  648. });
  649. Ext.reg('modx-combo-namespace',MODx.combo.Namespace);
  650. MODx.combo.Browser = function(config) {
  651. config = config || {};
  652. Ext.applyIf(config,{
  653. width: 400
  654. ,triggerAction: 'all'
  655. ,triggerClass: 'x-form-file-trigger'
  656. ,source: config.source || MODx.config.default_media_source
  657. });
  658. MODx.combo.Browser.superclass.constructor.call(this,config);
  659. this.config = config;
  660. };
  661. Ext.extend(MODx.combo.Browser,Ext.form.TriggerField,{
  662. browser: null
  663. ,onTriggerClick : function(btn){
  664. if (this.disabled){
  665. return false;
  666. }
  667. //if (this.browser === null) {
  668. this.browser = MODx.load({
  669. xtype: 'modx-browser'
  670. ,closeAction: 'close'
  671. ,id: Ext.id()
  672. ,multiple: true
  673. ,source: this.config.source || MODx.config.default_media_source
  674. ,hideFiles: this.config.hideFiles || false
  675. ,rootVisible: this.config.rootVisible || false
  676. ,allowedFileTypes: this.config.allowedFileTypes || ''
  677. ,wctx: this.config.wctx || 'web'
  678. ,openTo: this.config.openTo || ''
  679. ,rootId: this.config.rootId || '/'
  680. ,hideSourceCombo: this.config.hideSourceCombo || false
  681. ,listeners: {
  682. 'select': {fn: function(data) {
  683. this.setValue(data.relativeUrl);
  684. this.fireEvent('select',data);
  685. },scope:this}
  686. }
  687. });
  688. //}
  689. this.browser.show(btn);
  690. return true;
  691. }
  692. ,onDestroy: function(){
  693. MODx.combo.Browser.superclass.onDestroy.call(this);
  694. }
  695. });
  696. Ext.reg('modx-combo-browser',MODx.combo.Browser);
  697. MODx.combo.Country = function(config) {
  698. config = config || {};
  699. Ext.applyIf(config,{
  700. name: 'country'
  701. ,hiddenName: 'country'
  702. ,url: MODx.config.connector_url
  703. ,baseParams: {
  704. action: 'system/country/getlist'
  705. }
  706. ,displayField: 'country'
  707. ,valueField: 'iso'
  708. ,fields: [
  709. 'iso',
  710. 'country',
  711. 'value' // Deprecated (available for BC)
  712. ]
  713. ,editable: true
  714. ,value: 0
  715. ,typeAhead: true
  716. });
  717. MODx.combo.Country.superclass.constructor.call(this,config);
  718. };
  719. Ext.extend(MODx.combo.Country,MODx.combo.ComboBox);
  720. Ext.reg('modx-combo-country',MODx.combo.Country);
  721. MODx.combo.PropertySet = function(config) {
  722. config = config || {};
  723. Ext.applyIf(config,{
  724. name: 'propertyset'
  725. ,hiddenName: 'propertyset'
  726. ,url: MODx.config.connector_url
  727. ,baseParams: {
  728. action: 'element/propertyset/getlist'
  729. }
  730. ,displayField: 'name'
  731. ,valueField: 'id'
  732. ,fields: ['id','name']
  733. ,editable: false
  734. ,pageSize: 20
  735. ,width: 300
  736. });
  737. MODx.combo.PropertySet.superclass.constructor.call(this,config);
  738. };
  739. Ext.extend(MODx.combo.PropertySet,MODx.combo.ComboBox);
  740. Ext.reg('modx-combo-property-set',MODx.combo.PropertySet);
  741. MODx.ChangeParentField = function(config) {
  742. config = config || {};
  743. Ext.applyIf(config,{
  744. triggerAction: 'all'
  745. ,editable: false
  746. ,readOnly: false
  747. ,formpanel: 'modx-panel-resource'
  748. ,parentcmp: 'modx-resource-parent-hidden'
  749. ,contextcmp: 'modx-resource-context-key'
  750. ,currentid: MODx.request.id
  751. });
  752. MODx.ChangeParentField.superclass.constructor.call(this,config);
  753. this.config = config;
  754. this.on('click',this.onTriggerClick,this);
  755. this.addEvents({ end: true });
  756. this.on('end',this.end,this);
  757. };
  758. Ext.extend(MODx.ChangeParentField,Ext.form.TriggerField,{
  759. oldValue: false
  760. ,oldDisplayValue: false
  761. ,end: function(p) {
  762. var t = Ext.getCmp('modx-resource-tree');
  763. if (!t) return;
  764. p.d = p.d || p.v;
  765. t.removeListener('click',this.handleChangeParent,this);
  766. t.on('click',t._handleClick,t);
  767. t.disableHref = false;
  768. MODx.debug('Setting parent to: '+p.v);
  769. Ext.getCmp(this.config.parentcmp).setValue(p.v);
  770. this.setValue(p.d);
  771. this.oldValue = false;
  772. Ext.getCmp(this.config.formpanel).fireEvent('fieldChange');
  773. }
  774. ,onTriggerClick: function() {
  775. if (this.disabled) { return false; }
  776. if (this.oldValue) {
  777. this.fireEvent('end',{
  778. v: this.oldValue
  779. ,d: this.oldDisplayValue
  780. });
  781. return false;
  782. }
  783. MODx.debug('onTriggerClick');
  784. var t = Ext.getCmp('modx-resource-tree');
  785. if (!t) {
  786. MODx.debug('no tree found, trying to activate');
  787. var tp = Ext.getCmp('modx-leftbar-tabpanel');
  788. if (tp) {
  789. tp.on('tabchange',function(tbp,tab) {
  790. if (tab.id == 'modx-resource-tree-ct') {
  791. this.disableTreeClick();
  792. }
  793. },this);
  794. tp.activate('modx-resource-tree-ct');
  795. } else {
  796. MODx.debug('no tabpanel');
  797. }
  798. return false;
  799. }
  800. this.disableTreeClick();
  801. }
  802. ,disableTreeClick: function() {
  803. MODx.debug('Disabling tree click');
  804. t = Ext.getCmp('modx-resource-tree');
  805. if (!t) {
  806. MODx.debug('No tree found in disableTreeClick!');
  807. return false;
  808. }
  809. this.oldDisplayValue = this.getValue();
  810. this.oldValue = Ext.getCmp(this.config.parentcmp).getValue();
  811. this.setValue(_('resource_parent_select_node'));
  812. t.expand();
  813. t.removeListener('click',t._handleClick);
  814. t.on('click',this.handleChangeParent,this);
  815. t.disableHref = true;
  816. return true;}
  817. ,handleChangeParent: function(node,e) {
  818. var t = Ext.getCmp('modx-resource-tree');
  819. if (!t) { return false; }
  820. t.disableHref = true;
  821. var id = node.id.split('_'); id = id[1];
  822. if (id == this.config.currentid) {
  823. MODx.msg.alert('',_('resource_err_own_parent'));
  824. return false;
  825. }
  826. var ctxf = Ext.getCmp(this.config.contextcmp);
  827. if (ctxf) {
  828. var ctxv = ctxf.getValue();
  829. if (node.attributes && node.attributes.ctx != ctxv) {
  830. ctxf.setValue(node.attributes.ctx);
  831. }
  832. }
  833. this.fireEvent('end',{
  834. v: node.attributes.type != 'modContext' ? id : node.attributes.pk
  835. ,d: Ext.util.Format.stripTags(node.text)
  836. });
  837. e.preventDefault();
  838. e.stopEvent();
  839. return true;
  840. }
  841. });
  842. Ext.reg('modx-field-parent-change',MODx.ChangeParentField);
  843. MODx.combo.TVWidget = function(config) {
  844. config = config || {};
  845. Ext.applyIf(config,{
  846. name: 'widget'
  847. ,hiddenName: 'widget'
  848. ,displayField: 'name'
  849. ,valueField: 'value'
  850. ,fields: ['value','name']
  851. ,editable: false
  852. ,url: MODx.config.connector_url
  853. ,baseParams: {
  854. action: 'element/tv/renders/getOutputs'
  855. }
  856. ,value: 'default'
  857. });
  858. MODx.combo.TVWidget.superclass.constructor.call(this,config);
  859. };
  860. Ext.extend(MODx.combo.TVWidget,MODx.combo.ComboBox);
  861. Ext.reg('modx-combo-tv-widget',MODx.combo.TVWidget);
  862. MODx.combo.TVInputType = function(config) {
  863. config = config || {};
  864. Ext.applyIf(config,{
  865. name: 'type'
  866. ,hiddenName: 'type'
  867. ,displayField: 'name'
  868. ,valueField: 'value'
  869. ,editable: false
  870. ,fields: ['value','name']
  871. ,url: MODx.config.connector_url
  872. ,baseParams: {
  873. action: 'element/tv/renders/getInputs'
  874. }
  875. ,value: 'text'
  876. });
  877. MODx.combo.TVInputType.superclass.constructor.call(this,config);
  878. };
  879. Ext.extend(MODx.combo.TVInputType,MODx.combo.ComboBox);
  880. Ext.reg('modx-combo-tv-input-type',MODx.combo.TVInputType);
  881. MODx.combo.Action = function(config) {
  882. config = config || {};
  883. Ext.applyIf(config,{
  884. name: 'action'
  885. ,hiddenName: 'action'
  886. ,displayField: 'controller'
  887. ,valueField: 'id'
  888. ,fields: ['id','controller','namespace']
  889. ,pageSize: 20
  890. ,url: MODx.config.connector_url
  891. ,baseParams: {
  892. action: 'system/action/getlist'
  893. }
  894. ,tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item"><tpl if="namespace">{namespace:htmlEncode} - </tpl>{controller:htmlEncode}</div></tpl>')
  895. });
  896. MODx.combo.Action.superclass.constructor.call(this,config);
  897. };
  898. Ext.extend(MODx.combo.Action,MODx.combo.ComboBox);
  899. Ext.reg('modx-combo-action',MODx.combo.Action);
  900. MODx.combo.Dashboard = function(config) {
  901. config = config || {};
  902. Ext.applyIf(config,{
  903. name: 'dashboard'
  904. ,hiddenName: 'dashboard'
  905. ,displayField: 'name'
  906. ,valueField: 'id'
  907. ,fields: ['id','name','description']
  908. // ,listWidth: 400
  909. ,pageSize: 20
  910. ,url: MODx.config.connector_url
  911. ,baseParams: {
  912. action: 'system/dashboard/getlist'
  913. }
  914. ,tpl: new Ext.XTemplate('<tpl for=".">'
  915. ,'<div class="x-combo-list-item">'
  916. ,'<h4 class="modx-combo-title">{name:htmlEncode}</h4>'
  917. ,'<p class="modx-combo-desc">{description:htmlEncode}</p>'
  918. ,'</div></tpl>')
  919. });
  920. MODx.combo.Dashboard.superclass.constructor.call(this,config);
  921. };
  922. Ext.extend(MODx.combo.Dashboard,MODx.combo.ComboBox);
  923. Ext.reg('modx-combo-dashboard',MODx.combo.Dashboard);
  924. MODx.combo.MediaSource = function(config) {
  925. config = config || {};
  926. Ext.applyIf(config,{
  927. name: 'source'
  928. ,hiddenName: 'source'
  929. ,displayField: 'name'
  930. ,valueField: 'id'
  931. ,fields: ['id','name','description']
  932. // ,listWidth: 400
  933. ,pageSize: 20
  934. ,url: MODx.config.connector_url
  935. ,baseParams: {
  936. action: 'source/getlist'
  937. }
  938. ,tpl: new Ext.XTemplate('<tpl for=".">'
  939. ,'<div class="x-combo-list-item">'
  940. ,'<h4 class="modx-combo-title">{name:htmlEncode}</h4>'
  941. ,'<p class="modx-combo-desc">{description:htmlEncode}</p>'
  942. ,'</div></tpl>')
  943. });
  944. MODx.combo.MediaSource.superclass.constructor.call(this,config);
  945. };
  946. Ext.extend(MODx.combo.MediaSource,MODx.combo.ComboBox);
  947. Ext.reg('modx-combo-source',MODx.combo.MediaSource);
  948. MODx.combo.MediaSourceType = function(config) {
  949. config = config || {};
  950. Ext.applyIf(config,{
  951. name: 'class_key'
  952. ,hiddenName: 'class_key'
  953. ,displayField: 'name'
  954. ,valueField: 'class'
  955. ,fields: ['id','class','name','description']
  956. // ,listWidth: 400
  957. ,pageSize: 20
  958. ,url: MODx.config.connector_url
  959. ,baseParams: {
  960. action: 'source/type/getlist'
  961. }
  962. ,tpl: new Ext.XTemplate('<tpl for=".">'
  963. ,'<div class="x-combo-list-item">'
  964. ,'<h4 class="modx-combo-title">{name:htmlEncode}</h4>'
  965. ,'<p class="modx-combo-desc">{description:htmlEncode}</p>'
  966. ,'</div></tpl>')
  967. });
  968. MODx.combo.MediaSourceType.superclass.constructor.call(this,config);
  969. };
  970. Ext.extend(MODx.combo.MediaSourceType,MODx.combo.ComboBox);
  971. Ext.reg('modx-combo-source-type',MODx.combo.MediaSourceType);
  972. MODx.combo.Authority = function(config) {
  973. config = config || {};
  974. Ext.applyIf(config,{
  975. name: 'authority'
  976. ,hiddenName: 'authority'
  977. ,forceSelection: true
  978. ,typeAhead: false
  979. ,editable: false
  980. ,allowBlank: false
  981. // ,listWidth: 300
  982. ,pageSize: 20
  983. ,url: MODx.config.connector_url
  984. ,baseParams: {
  985. action: 'security/role/getAuthorityList'
  986. ,addNone: true
  987. }
  988. });
  989. MODx.combo.Authority.superclass.constructor.call(this,config);
  990. };
  991. Ext.extend(MODx.combo.Authority,MODx.combo.ComboBox);
  992. Ext.reg('modx-combo-authority',MODx.combo.Authority);
  993. MODx.combo.ManagerTheme = function(config) {
  994. config = config || {};
  995. Ext.applyIf(config,{
  996. name: 'theme'
  997. ,hiddenName: 'theme'
  998. ,displayField: 'theme'
  999. ,valueField: 'theme'
  1000. ,fields: ['theme']
  1001. ,url: MODx.config.connector_url
  1002. ,baseParams: {
  1003. action: 'workspace/theme/getlist'
  1004. }
  1005. ,typeAhead: false
  1006. ,editable: false
  1007. });
  1008. MODx.combo.ManagerTheme.superclass.constructor.call(this,config);
  1009. };
  1010. Ext.extend(MODx.combo.ManagerTheme,MODx.combo.ComboBox);
  1011. Ext.reg('modx-combo-manager-theme',MODx.combo.ManagerTheme);
  1012. MODx.combo.SettingKey = function(config) {
  1013. config = config || {};
  1014. Ext.applyIf(config,{
  1015. name: 'key'
  1016. ,hiddenName: 'key'
  1017. ,displayField: 'key'
  1018. ,valueField: 'key'
  1019. ,fields: ['key']
  1020. ,url: MODx.config.connector_url
  1021. ,baseParams: {
  1022. action: 'system/settings/getlist'
  1023. }
  1024. ,typeAhead: false
  1025. ,triggerAction: 'all'
  1026. ,editable: true
  1027. ,forceSelection: false
  1028. ,queryParam: 'key'
  1029. ,pageSize: 20
  1030. });
  1031. MODx.combo.SettingKey.superclass.constructor.call(this,config);
  1032. };
  1033. Ext.extend(MODx.combo.SettingKey,MODx.combo.ComboBox);
  1034. Ext.reg('modx-combo-setting-key',MODx.combo.SettingKey);