refactor: migrate templates and static files to self-contained modules
Templates Migration: - Migrate admin templates to modules (tenancy, billing, monitoring, marketplace, etc.) - Migrate vendor templates to modules (tenancy, billing, orders, messaging, etc.) - Migrate storefront templates to modules (catalog, customers, orders, cart, checkout, cms) - Migrate public templates to modules (billing, marketplace, cms) - Keep shared templates in app/templates/ (base.html, errors/, partials/, macros/) - Migrate letzshop partials to marketplace module Static Files Migration: - Migrate admin JS to modules: tenancy (23 files), core (5 files), monitoring (1 file) - Migrate vendor JS to modules: tenancy (4 files), core (2 files) - Migrate shared JS: vendor-selector.js to core, media-picker.js to cms - Migrate storefront JS: storefront-layout.js to core - Keep framework JS in static/ (api-client, utils, money, icons, log-config, lib/) - Update all template references to use module_static paths Naming Consistency: - Rename static/platform/ to static/public/ - Rename app/templates/platform/ to app/templates/public/ - Update all extends and static references Documentation: - Update module-system.md with shared templates documentation - Update frontend-structure.md with new module JS organization Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
206
app/modules/tenancy/static/admin/js/vendor-create.js
Normal file
206
app/modules/tenancy/static/admin/js/vendor-create.js
Normal file
@@ -0,0 +1,206 @@
|
||||
// static/admin/js/vendor-create.js
|
||||
/**
|
||||
* Admin Vendor Create Page
|
||||
* Handles vendor creation form with company selection
|
||||
*/
|
||||
|
||||
// Use centralized logger
|
||||
const vendorCreateLog = window.LogConfig.loggers.vendors;
|
||||
|
||||
vendorCreateLog.info('Loading vendor create module...');
|
||||
|
||||
function adminVendorCreate() {
|
||||
vendorCreateLog.debug('adminVendorCreate() called');
|
||||
|
||||
return {
|
||||
// Inherit base layout functionality
|
||||
...data(),
|
||||
|
||||
// Page identifier
|
||||
currentPage: 'vendors',
|
||||
|
||||
// Companies list for dropdown
|
||||
companies: [],
|
||||
loadingCompanies: true,
|
||||
|
||||
// Platforms list for selection
|
||||
platforms: [],
|
||||
|
||||
// Form data matching VendorCreate schema
|
||||
formData: {
|
||||
company_id: '',
|
||||
vendor_code: '',
|
||||
subdomain: '',
|
||||
name: '',
|
||||
description: '',
|
||||
letzshop_csv_url_fr: '',
|
||||
letzshop_csv_url_en: '',
|
||||
letzshop_csv_url_de: '',
|
||||
platform_ids: []
|
||||
},
|
||||
|
||||
// UI state
|
||||
loading: false,
|
||||
successMessage: false,
|
||||
errorMessage: '',
|
||||
createdVendor: null,
|
||||
|
||||
// Initialize
|
||||
async init() {
|
||||
// Guard against multiple initialization
|
||||
if (window._adminVendorCreateInitialized) return;
|
||||
window._adminVendorCreateInitialized = true;
|
||||
|
||||
try {
|
||||
vendorCreateLog.info('Initializing vendor create page');
|
||||
await Promise.all([
|
||||
this.loadCompanies(),
|
||||
this.loadPlatforms()
|
||||
]);
|
||||
} catch (error) {
|
||||
vendorCreateLog.error('Failed to initialize vendor create:', error);
|
||||
}
|
||||
},
|
||||
|
||||
// Load companies for dropdown
|
||||
async loadCompanies() {
|
||||
this.loadingCompanies = true;
|
||||
try {
|
||||
const response = await apiClient.get('/admin/companies?limit=1000');
|
||||
this.companies = response.companies || [];
|
||||
vendorCreateLog.debug('Loaded companies:', this.companies.length);
|
||||
} catch (error) {
|
||||
vendorCreateLog.error('Failed to load companies:', error);
|
||||
this.errorMessage = 'Failed to load companies. Please refresh the page.';
|
||||
} finally {
|
||||
this.loadingCompanies = false;
|
||||
}
|
||||
},
|
||||
|
||||
// Load platforms for selection
|
||||
async loadPlatforms() {
|
||||
try {
|
||||
const response = await apiClient.get('/admin/platforms');
|
||||
this.platforms = response.platforms || response.items || [];
|
||||
vendorCreateLog.debug('Loaded platforms:', this.platforms.length);
|
||||
} catch (error) {
|
||||
vendorCreateLog.error('Failed to load platforms:', error);
|
||||
this.platforms = [];
|
||||
}
|
||||
},
|
||||
|
||||
// Auto-generate subdomain from vendor name
|
||||
autoGenerateSubdomain() {
|
||||
if (!this.formData.name) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert name to subdomain format
|
||||
const subdomain = this.formData.name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9\s-]/g, '') // Remove special chars
|
||||
.replace(/\s+/g, '-') // Replace spaces with hyphens
|
||||
.replace(/-+/g, '-') // Replace multiple hyphens with single
|
||||
.replace(/^-|-$/g, ''); // Remove leading/trailing hyphens
|
||||
|
||||
this.formData.subdomain = subdomain;
|
||||
vendorCreateLog.debug('Auto-generated subdomain:', subdomain);
|
||||
},
|
||||
|
||||
// Create vendor
|
||||
async createVendor() {
|
||||
this.loading = true;
|
||||
this.errorMessage = '';
|
||||
this.successMessage = false;
|
||||
this.createdVendor = null;
|
||||
|
||||
try {
|
||||
vendorCreateLog.info('Creating vendor:', {
|
||||
company_id: this.formData.company_id,
|
||||
vendor_code: this.formData.vendor_code,
|
||||
name: this.formData.name
|
||||
});
|
||||
|
||||
// Prepare payload - only include non-empty values
|
||||
const payload = {
|
||||
company_id: parseInt(this.formData.company_id),
|
||||
vendor_code: this.formData.vendor_code.toUpperCase(),
|
||||
subdomain: this.formData.subdomain.toLowerCase(),
|
||||
name: this.formData.name
|
||||
};
|
||||
|
||||
// Add optional fields if provided
|
||||
if (this.formData.description) {
|
||||
payload.description = this.formData.description;
|
||||
}
|
||||
if (this.formData.letzshop_csv_url_fr) {
|
||||
payload.letzshop_csv_url_fr = this.formData.letzshop_csv_url_fr;
|
||||
}
|
||||
if (this.formData.letzshop_csv_url_en) {
|
||||
payload.letzshop_csv_url_en = this.formData.letzshop_csv_url_en;
|
||||
}
|
||||
if (this.formData.letzshop_csv_url_de) {
|
||||
payload.letzshop_csv_url_de = this.formData.letzshop_csv_url_de;
|
||||
}
|
||||
|
||||
// Add platform assignments
|
||||
if (this.formData.platform_ids && this.formData.platform_ids.length > 0) {
|
||||
payload.platform_ids = this.formData.platform_ids.map(id => parseInt(id));
|
||||
}
|
||||
|
||||
const response = await apiClient.post('/admin/vendors', payload);
|
||||
|
||||
vendorCreateLog.info('Vendor created successfully:', response.vendor_code);
|
||||
|
||||
// Store created vendor details
|
||||
this.createdVendor = {
|
||||
vendor_code: response.vendor_code,
|
||||
name: response.name,
|
||||
subdomain: response.subdomain,
|
||||
company_name: response.company_name
|
||||
};
|
||||
|
||||
this.successMessage = true;
|
||||
|
||||
// Reset form
|
||||
this.formData = {
|
||||
company_id: '',
|
||||
vendor_code: '',
|
||||
subdomain: '',
|
||||
name: '',
|
||||
description: '',
|
||||
letzshop_csv_url_fr: '',
|
||||
letzshop_csv_url_en: '',
|
||||
letzshop_csv_url_de: '',
|
||||
platform_ids: []
|
||||
};
|
||||
|
||||
// Scroll to top to show success message
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
|
||||
// Redirect after 3 seconds
|
||||
setTimeout(() => {
|
||||
window.location.href = `/admin/vendors/${response.vendor_code}`;
|
||||
}, 3000);
|
||||
|
||||
} catch (error) {
|
||||
vendorCreateLog.error('Failed to create vendor:', error);
|
||||
|
||||
// Parse error message
|
||||
if (error.message) {
|
||||
this.errorMessage = error.message;
|
||||
} else if (error.detail) {
|
||||
this.errorMessage = error.detail;
|
||||
} else {
|
||||
this.errorMessage = 'Failed to create vendor. Please try again.';
|
||||
}
|
||||
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
vendorCreateLog.info('Vendor create module loaded');
|
||||
Reference in New Issue
Block a user