HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/websiteFunctions/templates/websiteFunctions/CreateDockerPackage.html
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Create Docker Package - CyberPanel" %}{% endblock %}

{% block header_scripts %}
<style>
    /* Modern page styles matching new design */
    .page-wrapper {
        background: transparent;
        padding: 20px;
    }
    
    .page-container {
        max-width: 1200px;
        margin: 0 auto;
    }
    
    .page-header {
        margin-bottom: 30px;
    }
    
    .page-title {
        font-size: 28px;
        font-weight: 700;
        color: var(--text-heading, #2f3640);
        margin-bottom: 8px;
    }
    
    .page-subtitle {
        font-size: 14px;
        color: var(--text-secondary, #8893a7);
    }
    
    /* Card styles */
    .content-card {
        background: var(--bg-secondary, white);
        border-radius: 12px;
        padding: 30px;
        box-shadow: 0 2px 8px var(--shadow-color, rgba(0,0,0,0.08));
        border: 1px solid var(--border-color, #e8e9ff);
        margin-bottom: 25px;
    }
    
    .card-title {
        font-size: 18px;
        font-weight: 700;
        color: var(--text-heading, #2f3640);
        margin-bottom: 25px;
        display: flex;
        align-items: center;
        gap: 10px;
    }
    
    .card-title::before {
        content: '';
        width: 4px;
        height: 24px;
        background: var(--accent-color, #5b5fcf);
        border-radius: 2px;
    }
    
    /* Form styles */
    .form-group {
        margin-bottom: 20px;
    }
    
    .form-label {
        display: block;
        font-size: 13px;
        font-weight: 600;
        color: var(--text-secondary, #64748b);
        margin-bottom: 8px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    .form-control {
        width: 100%;
        padding: 10px 14px;
        border: 1px solid var(--border-color, #e8e9ff);
        border-radius: 8px;
        font-size: 14px;
        color: var(--text-primary, #2f3640);
        background: var(--bg-secondary, white);
        transition: all 0.2s ease;
    }
    
    .form-control:hover {
        border-color: var(--accent-color, #5b5fcf);
    }
    
    .form-control:focus {
        outline: none;
        border-color: var(--accent-color, #5b5fcf);
        box-shadow: 0 0 0 3px rgba(91,95,207,0.1);
    }
    
    .form-control[readonly] {
        background: var(--bg-hover, #f8f9ff);
        cursor: not-allowed;
    }
    
    /* Button styles */
    .btn {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 10px 20px;
        border: none;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
        text-decoration: none;
    }
    
    .btn-primary {
        background: var(--accent-color, #5b5fcf);
        color: white;
    }
    
    .btn-primary:hover {
        background: var(--accent-hover, #4a4fc4);
        box-shadow: 0 4px 12px rgba(91,95,207,0.3);
        transform: translateY(-1px);
    }
    
    .btn-warning {
        background: #ff9800;
        color: white;
    }
    
    .btn-warning:hover {
        background: #f57c00;
        box-shadow: 0 4px 12px rgba(255,152,0,0.3);
        transform: translateY(-1px);
    }
    
    .btn-danger {
        background: var(--danger-text, #dc3545);
        color: white;
    }
    
    .btn-danger:hover {
        background: #c82333;
        box-shadow: 0 4px 12px rgba(220,53,69,0.3);
        transform: translateY(-1px);
    }
    
    .btn-secondary {
        background: var(--bg-hover, #f8f9ff);
        color: var(--accent-color, #5b5fcf);
        border: 1px solid var(--border-color, #e8e9ff);
    }
    
    .btn-secondary:hover {
        background: #eef0ff;
        border-color: var(--accent-color, #5b5fcf);
    }
    
    /* Table styles */
    .modern-table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 15px;
    }
    
    .modern-table th {
        text-align: left;
        padding: 12px 15px;
        font-size: 11px;
        font-weight: 700;
        color: var(--text-secondary, #64748b);
        text-transform: uppercase;
        letter-spacing: 0.8px;
        border-bottom: 2px solid var(--border-color, #e8e9ff);
        background: var(--bg-hover, #f8f9ff);
    }
    
    .modern-table td {
        padding: 12px 15px;
        font-size: 13px;
        color: var(--text-primary, #2f3640);
        border-bottom: 1px solid var(--border-color, #f0f0ff);
    }
    
    .modern-table tr:hover {
        background: var(--bg-hover, #f8f9ff);
    }
    
    .action-buttons {
        display: flex;
        gap: 8px;
    }
    
    .action-buttons .btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    /* Modal styles */
    .modal-content {
        border-radius: 12px;
        border: none;
        box-shadow: 0 8px 32px var(--shadow-color, rgba(0,0,0,0.1));
        background: var(--bg-secondary, white);
    }
    
    .modal-header {
        background: var(--bg-hover, #f8f9ff);
        border-bottom: 1px solid var(--border-color, #e8e9ff);
        border-radius: 12px 12px 0 0;
        padding: 20px 25px;
    }
    
    .modal-title {
        font-size: 18px;
        font-weight: 700;
        color: var(--text-heading, #2f3640);
        display: flex;
        align-items: center;
        gap: 10px;
    }
    
    .modal-body {
        padding: 25px;
    }
    
    .modal-footer {
        background: var(--bg-hover, #f8f9ff);
        border-top: 1px solid var(--border-color, #e8e9ff);
        border-radius: 0 0 12px 12px;
        padding: 15px 25px;
        display: flex;
        justify-content: flex-end;
        gap: 10px;
    }
    
    /* Loading spinner */
    .loading-spinner {
        display: inline-block;
        width: 16px;
        height: 16px;
        border: 2px solid #f3f3f3;
        border-top: 2px solid #5b5fcf;
        border-radius: 50%;
        animation: spin 1s linear infinite;
        margin-left: 10px;
    }
    
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
    
    /* Alert styles */
    .alert {
        padding: 16px 20px;
        border-radius: 10px;
        margin-bottom: 20px;
        display: flex;
        align-items: center;
        gap: 12px;
    }
    
    .alert-info {
        background: var(--info-bg, #e3f2fd);
        border: 1px solid #bbdefb;
        color: var(--info-text, #1565c0);
    }
    
    /* Form row */
    .form-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }
    
    @media (max-width: 768px) {
        .form-row {
            grid-template-columns: 1fr;
        }
    }
    
    /* Responsive */
    @media (max-width: 768px) {
        .content-card {
            padding: 20px;
        }
        
        .action-buttons {
            flex-direction: column;
        }
        
        .action-buttons .btn {
            width: 100%;
            justify-content: center;
        }
        
        .modern-table {
            font-size: 12px;
        }
        
        .modern-table th,
        .modern-table td {
            padding: 8px;
        }
    }
</style>
{% endblock %}

{% block content %}
{% load static %}
{% get_current_language as LANGUAGE_CODE %}

<div class="page-wrapper" ng-controller="createDockerPackage">
    <div class="page-container">
        <div class="page-header">
            <h1 class="page-title">{% trans "Docker Packages" %}</h1>
            <p class="page-subtitle">{% trans "Create and manage Docker packages with resource limits for your containers" %}</p>
        </div>

        <!-- Create Package Form -->
        <div class="content-card">
            <h2 class="card-title">
                {% trans "Create New Package" %}
                <span ng-hide="cyberpanelLoading" class="loading-spinner"></span>
            </h2>
            
            <form name="websiteCreationForm">
                <div class="form-row">
                    <div class="form-group">
                        <label class="form-label">{% trans "Package Name" %}</label>
                        <input type="text" class="form-control" ng-model="packagesname"
                               placeholder="{% trans "Enter package name" %}" required>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label">{% trans "CPU Cores" %}</label>
                        <input type="number" class="form-control" ng-model="CPU"
                               placeholder="{% trans "e.g. 2, 3, 4" %}" required>
                    </div>
                </div>
                
                <div class="form-row">
                    <div class="form-group">
                        <label class="form-label">{% trans "Memory (MB)" %}</label>
                        <input type="number" class="form-control" ng-model="Memory"
                               placeholder="{% trans "e.g. 256, 512, 1024" %}" required>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label">{% trans "Bandwidth" %}</label>
                        <input type="text" class="form-control" ng-model="Bandwidth"
                               placeholder="{% trans "Enter bandwidth limit" %}" required>
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="form-label">{% trans "Disk Space" %}</label>
                    <input type="text" class="form-control" ng-model="disk"
                           placeholder="{% trans "Enter disk space limit" %}" required>
                </div>
                
                <button type="button" ng-click="createdockerpackage()" class="btn btn-primary">
                    <i class="fas fa-plus"></i>
                    {% trans "Create Docker Package" %}
                </button>
            </form>
        </div>

        <!-- Existing Packages -->
        <div class="content-card">
            <h2 class="card-title">{% trans "Existing Docker Packages" %}</h2>
            
            {% if packages %}
            <table class="modern-table">
                <thead>
                    <tr>
                        <th>{% trans "Package Name" %}</th>
                        <th>{% trans "CPU Cores" %}</th>
                        <th>{% trans "Memory" %}</th>
                        <th>{% trans "Bandwidth" %}</th>
                        <th>{% trans "Disk Space" %}</th>
                        <th>{% trans "Actions" %}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for pack in packages %}
                    <tr>
                        <td>{{ pack.Name }}</td>
                        <td>{{ pack.CPUs }}</td>
                        <td>{{ pack.Ram }} MB</td>
                        <td>{{ pack.Bandwidth }}</td>
                        <td>{{ pack.DiskSpace }}</td>
                        <td>
                            <div class="action-buttons">
                                <button type="button" class="btn btn-warning" onclick="editPackage({{ pack.id }})" data-toggle="modal" data-target="#EditPackage">
                                    <i class="fas fa-edit"></i> {% trans "Edit" %}
                                </button>
                                <button type="button" class="btn btn-danger" onclick="deletePackage('{% url 'CreateDockerPackage' %}?DeleteID={{ pack.id }}')" data-toggle="modal" data-target="#packagedelete">
                                    <i class="fas fa-trash"></i> {% trans "Delete" %}
                                </button>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% else %}
            <div class="alert alert-info">
                <i class="fas fa-info-circle"></i>
                <span>{% trans "No Docker packages have been created yet. Create your first package above." %}</span>
            </div>
            {% endif %}
        </div>
    </div>
</div>

<!-- Edit Package Modal -->
<div id="EditPackage" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">
                    {% trans "Edit Package" %}
                    <span ng-hide="cyberpanelLoading" class="loading-spinner"></span>
                </h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            </div>
            <div class="modal-body">
                <form name="editPackageForm">
                    <div class="form-row">
                        <div class="form-group">
                            <label class="form-label">{% trans "Package Name" %}</label>
                            <input type="text" class="form-control" ng-model="U_Name" readonly>
                        </div>
                        
                        <div class="form-group">
                            <label class="form-label">{% trans "CPU Cores" %}</label>
                            <input type="number" class="form-control" ng-model="U_CPU"
                                   placeholder="{% trans "e.g. 2, 3, 4" %}" required>
                        </div>
                    </div>
                    
                    <div class="form-row">
                        <div class="form-group">
                            <label class="form-label">{% trans "Memory (MB)" %}</label>
                            <input type="number" class="form-control" ng-model="U_Memory"
                                   placeholder="{% trans "e.g. 256, 512, 1024" %}" required>
                        </div>
                        
                        <div class="form-group">
                            <label class="form-label">{% trans "Bandwidth" %}</label>
                            <input type="text" class="form-control" ng-model="U_Bandwidth"
                                   placeholder="{% trans "Enter bandwidth limit" %}" required>
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label">{% trans "Disk Space" %}</label>
                        <input type="text" class="form-control" ng-model="U_DiskSpace"
                               placeholder="{% trans "Enter disk space limit" %}" required>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">
                    {% trans "Cancel" %}
                </button>
                <button type="button" ng-click="SaveUpdate()" class="btn btn-primary">
                    <i class="fas fa-save"></i>
                    {% trans "Update Package" %}
                </button>
            </div>
        </div>
    </div>
</div>

<!-- Delete Package Modal -->
<div id="packagedelete" class="modal fade" role="dialog">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">
                    {% trans "Delete Package" %}
                    <span ng-hide="cyberpanelLoading" class="loading-spinner"></span>
                </h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            </div>
            <div class="modal-body">
                <p style="font-size: 14px; color: #2f3640;">
                    <i class="fas fa-exclamation-triangle" style="color: #ff9800; margin-right: 8px;"></i>
                    {% trans "Are you sure you want to delete this package?" %}
                </p>
                <p style="font-size: 13px; color: #8893a7; margin-top: 10px;">
                    {% trans "This action cannot be undone." %}
                </p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">
                    {% trans "Cancel" %}
                </button>
                <button type="button" class="btn btn-danger" ng-click="ConfirmDelete()">
                    <i class="fas fa-trash"></i>
                    {% trans "Delete" %}
                </button>
            </div>
        </div>
    </div>
</div>

{% endblock %}

{% block footer_scripts %}
<script>
// Global functions to handle button clicks
window.editPackage = function(packId) {
    console.log('editPackage called with ID:', packId);
    
    // Use a timeout to ensure Angular is ready
    setTimeout(function() {
        var element = document.querySelector('[ng-controller="createDockerPackage"]');
        var scope = angular.element(element).scope();
        
        if (scope && scope.Getpackage) {
            console.log('Calling Getpackage with scope');
            
            // Call within Angular's digest cycle
            scope.$apply(function() {
                scope.Getpackage(packId);
            });
        } else {
            console.error('Scope not found or Getpackage not available');
            console.log('Scope:', scope);
            if (scope) {
                console.log('Available functions:', Object.keys(scope).filter(k => typeof scope[k] === 'function'));
            }
        }
    }, 100);
};

window.deletePackage = function(url) {
    console.log('deletePackage called with URL:', url);
    
    setTimeout(function() {
        var element = document.querySelector('[ng-controller="createDockerPackage"]');
        var scope = angular.element(element).scope();
        
        if (scope && scope.Deletepackage) {
            console.log('Calling Deletepackage with scope');
            scope.Deletepackage(url);
            
            if (!scope.$$phase) {
                scope.$apply();
            }
        } else {
            console.error('Scope not found or Deletepackage not available');
        }
    }, 100);
};

// Debug and ensure Angular is ready
$(document).ready(function() {
    // Check if Angular is bootstrapped
    function checkAngular() {
        var element = document.querySelector('[ng-controller="createDockerPackage"]');
        if (!element) {
            console.error('Controller element not found');
            return;
        }
        
        var scope = angular.element(element).scope();
        console.log('Angular check - scope exists:', !!scope);
        
        if (!scope) {
            console.log('Angular not ready, checking if manual bootstrap needed...');
            // Check if angular is loaded
            if (typeof angular !== 'undefined') {
                console.log('Angular is loaded but app might not be bootstrapped');
                
                // Try to get the injector
                try {
                    var injector = angular.element(document.body).injector();
                    console.log('Injector exists:', !!injector);
                } catch(e) {
                    console.error('No injector found:', e);
                }
            }
        } else {
            console.log('Controller functions:', Object.keys(scope).filter(function(key) {
                return typeof scope[key] === 'function' && key.charAt(0) !== '$';
            }));
            
            // Test direct function call
            if (scope.Getpackage) {
                console.log('Getpackage function is available');
            }
        }
    }
    
    // Check immediately and after delays
    checkAngular();
    setTimeout(checkAngular, 1000);
    setTimeout(checkAngular, 3000);
});
</script>

<script>
// Alternative approach: Use jQuery to bind events after page load
$(document).ready(function() {
    // Wait for Angular to be ready
    setTimeout(function() {
        console.log('Setting up alternative click handlers');
        
        // Remove onclick attributes and use jQuery events
        $('.btn-warning[data-target="#EditPackage"]').each(function() {
            var btn = $(this);
            var onclickAttr = btn.attr('onclick');
            if (onclickAttr) {
                // Extract package ID from onclick
                var match = onclickAttr.match(/editPackage\((\d+)\)/);
                if (match) {
                    var packId = parseInt(match[1]);
                    console.log('Found edit button for package:', packId);
                    
                    // Remove onclick and bind jQuery event
                    btn.removeAttr('onclick');
                    btn.off('click').on('click', function(e) {
                        e.preventDefault();
                        e.stopPropagation();
                        console.log('Edit button clicked for package:', packId);
                        editPackage(packId);
                    });
                }
            }
        });
        
        // Do the same for delete buttons
        $('.btn-danger[data-target="#packagedelete"]').each(function() {
            var btn = $(this);
            var onclickAttr = btn.attr('onclick');
            if (onclickAttr) {
                // Extract URL from onclick
                var match = onclickAttr.match(/deletePackage\('([^']+)'\)/);
                if (match) {
                    var url = match[1];
                    console.log('Found delete button with URL:', url);
                    
                    // Remove onclick and bind jQuery event
                    btn.removeAttr('onclick');
                    btn.off('click').on('click', function(e) {
                        e.preventDefault();
                        e.stopPropagation();
                        console.log('Delete button clicked with URL:', url);
                        deletePackage(url);
                    });
                }
            }
        });
    }, 1500);
});
</script>

<script>
// Ensure Update button works
$(document).ready(function() {
    // Wait a bit for Angular to initialize
    setTimeout(function() {
        // Check if ng-click is working, if not add our handler
        var updateBtn = $('#EditPackage').find('button').filter(function() {
            return $(this).text().indexOf('Update Package') > -1;
        });
        
        if (updateBtn.length) {
            console.log('Found update button, checking if ng-click works');
            
            // Check if Angular click handler is attached
            var hasNgClick = updateBtn.attr('ng-click');
            if (hasNgClick && !updateBtn.data('manual-handler')) {
                console.log('ng-click found, ensuring it works within modal context');
                
                // Mark that we've added our handler
                updateBtn.data('manual-handler', true);
                
                // Override click to ensure it works
                updateBtn.off('click.manual').on('click.manual', function(e) {
                    console.log('Update button clicked via manual handler');
                    
                    var element = document.querySelector('[ng-controller="createDockerPackage"]');
                    var scope = angular.element(element).scope();
                    
                    if (scope && scope.SaveUpdate) {
                        // Ensure we have the latest values
                        var cpuInput = document.querySelector('#EditPackage input[ng-model="U_CPU"]');
                        var memInput = document.querySelector('#EditPackage input[ng-model="U_Memory"]');
                        var bwInput = document.querySelector('#EditPackage input[ng-model="U_Bandwidth"]');
                        var diskInput = document.querySelector('#EditPackage input[ng-model="U_DiskSpace"]');
                        
                        if (cpuInput) scope.U_CPU = cpuInput.value;
                        if (memInput) scope.U_Memory = memInput.value;
                        if (bwInput) scope.U_Bandwidth = bwInput.value;
                        if (diskInput) scope.U_DiskSpace = diskInput.value;
                        
                        console.log('Calling SaveUpdate with:', {
                            CPU: scope.U_CPU,
                            Memory: scope.U_Memory,
                            Bandwidth: scope.U_Bandwidth,
                            DiskSpace: scope.U_DiskSpace,
                            EditID: scope.EditID
                        });
                        
                        // Call within digest cycle
                        if (scope.$$phase) {
                            scope.SaveUpdate();
                        } else {
                            scope.$apply(function() {
                                scope.SaveUpdate();
                            });
                        }
                    } else {
                        console.error('SaveUpdate not found on scope');
                    }
                });
            }
        }
        
        // Also ensure delete confirm button works
        var deleteBtn = $('#packagedelete').find('button').filter(function() {
            return $(this).text().indexOf('Delete') > -1 && $(this).hasClass('btn-danger');
        });
        
        if (deleteBtn.length && !deleteBtn.data('manual-handler')) {
            console.log('Setting up delete confirm button handler');
            deleteBtn.data('manual-handler', true);
            
            deleteBtn.off('click.manual').on('click.manual', function(e) {
                console.log('Delete confirm button clicked');
                
                var element = document.querySelector('[ng-controller="createDockerPackage"]');
                var scope = angular.element(element).scope();
                
                if (scope && scope.ConfirmDelete) {
                    scope.$apply(function() {
                        scope.ConfirmDelete();
                    });
                } else {
                    console.error('ConfirmDelete not found on scope');
                }
            });
        }
    }, 1000);
});
</script>
{% endblock %}