+
@@ -187,6 +197,63 @@ window.OrgChart = {
}
},
+ /**
+ * Copy referral code to clipboard
+ * @param {string} code - The referral code to copy
+ */
+ copyReferralCode: function(code) {
+ if (navigator.clipboard) {
+ navigator.clipboard.writeText(code).then(() => {
+ // Show toast notification
+ this.showToast('کد معرف کپی شد: ' + code);
+ }).catch(err => {
+ console.error('Failed to copy:', err);
+ this.fallbackCopy(code);
+ });
+ } else {
+ this.fallbackCopy(code);
+ }
+ },
+
+ /**
+ * Fallback copy method for older browsers
+ */
+ fallbackCopy: function(text) {
+ const textArea = document.createElement('textarea');
+ textArea.value = text;
+ textArea.style.position = 'fixed';
+ textArea.style.left = '-999999px';
+ document.body.appendChild(textArea);
+ textArea.select();
+ try {
+ document.execCommand('copy');
+ this.showToast('کد معرف کپی شد: ' + text);
+ } catch (err) {
+ console.error('Fallback copy failed:', err);
+ }
+ document.body.removeChild(textArea);
+ },
+
+ /**
+ * Show toast notification
+ */
+ showToast: function(message) {
+ // Remove existing toast
+ const existingToast = document.querySelector('.org-chart-toast');
+ if (existingToast) existingToast.remove();
+
+ const toast = document.createElement('div');
+ toast.className = 'org-chart-toast';
+ toast.textContent = message;
+ document.body.appendChild(toast);
+
+ setTimeout(() => toast.classList.add('show'), 10);
+ setTimeout(() => {
+ toast.classList.remove('show');
+ setTimeout(() => toast.remove(), 300);
+ }, 2000);
+ },
+
/**
* Dispose the chart
*/