template.window.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. collections.window.TemplateDuplicate = function(config) {
  2. config = config || {};
  3. Ext.applyIf(config,{
  4. title: _('collections.template.duplicate')
  5. ,closeAction: 'close'
  6. ,isUpdate: false
  7. ,url: collections.config.connectorUrl
  8. ,action: 'mgr/template/duplicate'
  9. ,fields: this.getFields(config)
  10. });
  11. collections.window.TemplateDuplicate.superclass.constructor.call(this,config);
  12. };
  13. Ext.extend(collections.window.TemplateDuplicate,MODx.Window, {
  14. getFields: function(config) {
  15. return [{
  16. xtype: 'textfield'
  17. ,name: 'id'
  18. ,anchor: '100%'
  19. ,hidden: true
  20. },{
  21. xtype: 'textfield'
  22. ,fieldLabel: _('collections.template.name')
  23. ,name: 'name'
  24. ,anchor: '100%'
  25. ,allowBlank: false
  26. },{
  27. xtype: 'textarea'
  28. ,fieldLabel: _('collections.template.description')
  29. ,name: 'description'
  30. ,anchor: '100%'
  31. ,allowBlank: true
  32. }];
  33. }
  34. });
  35. Ext.reg('collections-window-template-duplicate',collections.window.TemplateDuplicate);
  36. collections.window.TemplateImport = function(config) {
  37. config = config || {};
  38. Ext.applyIf(config,{
  39. title: _('collections.template.import')
  40. ,closeAction: 'close'
  41. ,isUpdate: false
  42. ,fileUpload: true
  43. ,url: collections.config.connectorUrl
  44. ,action: 'mgr/template/import'
  45. ,fields: this.getFields(config)
  46. ,autoHeight: true
  47. ,saveBtnText: _('collections.global.import')
  48. });
  49. collections.window.TemplateImport.superclass.constructor.call(this,config);
  50. };
  51. Ext.extend(collections.window.TemplateImport,MODx.Window, {
  52. getFields: function(config) {
  53. return [{
  54. xtype: 'fileuploadfield'
  55. ,fieldLabel: _('collections.template.name')
  56. ,name: 'file'
  57. ,anchor: '100%'
  58. ,allowBlank: false
  59. ,listeners: {
  60. render: function(){
  61. this.fileInput.dom.setAttribute('accept', '.json');
  62. },
  63. fileselected: {
  64. fn: function(field, value){
  65. try {
  66. var text = field.fileInput.dom.files[0];
  67. var reader = new FileReader();
  68. reader.readAsText(text);
  69. var window = this;
  70. reader.onload = function(event) {
  71. var templates = JSON.parse(event.target.result);
  72. var checkboxGroup = Ext.getCmp('template-checkbox-group');
  73. if (checkboxGroup) {
  74. checkboxGroup.destroy();
  75. }
  76. checkboxGroup = {
  77. xtype: 'checkboxgroup',
  78. id: 'template-checkbox-group',
  79. fieldLabel: _('collections.template.import'),
  80. itemCls: 'x-check-group-alt',
  81. columns: 3,
  82. items: []
  83. };
  84. Ext.each(templates, function(template){
  85. checkboxGroup.items.push({
  86. boxLabel: template.name,
  87. name: 'template[]',
  88. value: template.name,
  89. checked: true,
  90. listeners: {
  91. render: function() {
  92. this.el.dom.setAttribute('value', this.value);
  93. }
  94. }
  95. });
  96. });
  97. window.fp.add(checkboxGroup);
  98. window.doLayout();
  99. };
  100. } catch (err) {
  101. var checkboxGroup = Ext.getCmp('template-checkbox-group');
  102. if (checkboxGroup) {
  103. checkboxGroup.destroy();
  104. }
  105. }
  106. },
  107. scope: this
  108. }
  109. }
  110. }];
  111. }
  112. });
  113. Ext.reg('collections-window-template-import', collections.window.TemplateImport);