blueprint.window.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. fred.window.Blueprint = function (config) {
  2. config = config || {};
  3. Ext.applyIf(config, {
  4. title: _('fred.blueprints.quick_update'),
  5. closeAction: 'close',
  6. isUpdate: false,
  7. url: fred.config.connectorUrl,
  8. action: 'mgr/blueprints/update',
  9. modal: true,
  10. fields: this.getFields(config),
  11. autoHeight: true,
  12. buttonAlign: 'left',
  13. buttons: [
  14. {
  15. xtype: 'fred-button-help',
  16. path: 'cmp/blueprints/'
  17. },
  18. '->',
  19. {
  20. text: config.cancelBtnText || _('cancel'),
  21. scope: this,
  22. handler: function() { config.closeAction !== 'close' ? this.hide() : this.close(); }
  23. },
  24. {
  25. text: config.saveBtnText || _('save'),
  26. cls: 'primary-button',
  27. scope: this,
  28. handler: this.submit
  29. }
  30. ],
  31. width: 800
  32. });
  33. this.theme_folder = config.record.theme_theme_folder;
  34. fred.window.Blueprint.superclass.constructor.call(this, config);
  35. };
  36. Ext.extend(fred.window.Blueprint, MODx.Window, {
  37. getFields: function (config) {
  38. return [
  39. {
  40. xtype: 'hidden',
  41. name: 'id'
  42. },
  43. {
  44. xtype: 'hidden',
  45. name: 'rank'
  46. },
  47. {
  48. layout: 'column',
  49. border: false,
  50. anchor: '100%',
  51. defaults: {
  52. layout: 'form',
  53. labelAlign: 'top',
  54. labelSeparator: '',
  55. anchor: '100%',
  56. border: false
  57. },
  58. items: [
  59. {
  60. columnWidth: .5,
  61. border: false,
  62. defaults: {
  63. msgTarget: 'under',
  64. anchor: '100%'
  65. },
  66. items: [
  67. {
  68. xtype: 'textfield',
  69. fieldLabel: _('fred.blueprints.name'),
  70. name: 'name',
  71. anchor: '100%',
  72. allowBlank: false
  73. },
  74. {
  75. xtype: 'textarea',
  76. fieldLabel: _('fred.blueprints.description'),
  77. name: 'description',
  78. anchor: '100%',
  79. allowBlank: true,
  80. height: 100
  81. }
  82. ]
  83. },
  84. {
  85. columnWidth: .5,
  86. border: false,
  87. defaults: {
  88. msgTarget: 'under',
  89. anchor: '100%'
  90. },
  91. items: [
  92. {
  93. xtype: 'fred-combo-themes',
  94. fieldLabel: _('fred.blueprints.theme'),
  95. name: 'theme_id',
  96. hiddenName: 'theme_id',
  97. anchor: '100%',
  98. isUpdate: config.isUpdate,
  99. listeners: {
  100. select: function(combo, record) {
  101. var category = this.find('name', 'category');
  102. if (!category[0]) return;
  103. this.theme_folder = record.data.theme_folder;
  104. category = category[0];
  105. category.setValue();
  106. category.enable();
  107. category.baseParams.theme = record.id;
  108. category.store.load();
  109. var image = Ext.getCmp('fred-blueprint-image-field');
  110. if (image) {
  111. image.updatePreview(this.theme_folder);
  112. }
  113. },
  114. scope: this
  115. },
  116. allowBlank: false
  117. },
  118. {
  119. xtype: 'fred-combo-blueprint-categories',
  120. fieldLabel: _('fred.blueprints.category'),
  121. name: 'category',
  122. hiddenName: 'category',
  123. anchor: '100%'
  124. },
  125. {
  126. xtype: 'fred-combo-boolean',
  127. useInt: true,
  128. fieldLabel: _('fred.blueprints.public'),
  129. name: 'public',
  130. hiddenName: 'public',
  131. anchor: '100%',
  132. disabled: !config.canPublic,
  133. value: config.canPublic ? 1 : 0
  134. }
  135. ]
  136. }
  137. ]
  138. },
  139. {
  140. layout: 'column',
  141. border: false,
  142. anchor: '100%',
  143. defaults: {
  144. layout: 'form',
  145. labelAlign: 'top',
  146. labelSeparator: '',
  147. anchor: '100%',
  148. border: false
  149. },
  150. items: [
  151. {
  152. columnWidth: 1,
  153. border: false,
  154. defaults: {
  155. msgTarget: 'under',
  156. anchor: '100%'
  157. },
  158. items: [
  159. {
  160. id: 'fred-blueprint-image-field',
  161. xtype: 'modx-combo-browser',
  162. fieldLabel: _('fred.blueprints.image'),
  163. triggerClass: 'x-form-image-trigger',
  164. name: 'image',
  165. anchor: '100%',
  166. allowBlank: true,
  167. updatePreview: function (theme_folder) {
  168. var value = this.getValue();
  169. if (value) {
  170. value = fred.prependBaseUrl(value, theme_folder);
  171. } else {
  172. value = "https://via.placeholder.com/300x150?text=No+image";
  173. }
  174. Ext.getCmp('image_preview').el.dom.querySelector('img').src = value;
  175. },
  176. listeners: {
  177. select: function (data) {
  178. this.setValue(data.fullRelativeUrl);
  179. this.updatePreview('');
  180. },
  181. change: {
  182. fn:function (cb, nv) {
  183. cb.updatePreview(this.theme_folder);
  184. },
  185. scope: this
  186. }
  187. }
  188. },
  189. {
  190. id: 'image_preview',
  191. html: '<img src="' + (config.record.image ? fred.prependBaseUrl(config.record.image, config.record.theme_theme_folder) : "https://via.placeholder.com/300x150?text=No+image") + '" style="max-height: 400px;max-width: 770px;margin-top: 15px;">'
  192. }
  193. ]
  194. }
  195. ]
  196. }];
  197. }
  198. });
  199. Ext.reg('fred-window-blueprint', fred.window.Blueprint);