-
×
-
البحث عن منصة
-
-
-
-
-
+
+
+
×
+
البحث عن منصة
+
+
+
+
+
+
-
-
+
-
-
-
-
+
+
+
+ // فتح نموذج تعديل منصة
+ function openEditPlatformModal(index) {
+ const platform = platforms[index];
+ document.getElementById("editPlatformName").value = platform.name;
+ document.getElementById("editPlatformIcon").value = platform.icon;
+ document.getElementById("editPlatformPlaceholder").value = platform.placeholder;
+ document.getElementById("editPlatformUrl").value = platform.url;
+ document.getElementById("editPlatformNotes").value = platform.notes;
+ document.getElementById("editPlatformColor").value = platform.color;
+ document.getElementById("editPlatformModal").setAttribute('data-index', index);
+ document.getElementById("editPlatformModal").style.display = "block";
+ resetEditPlatformModalErrors();
+ }
+ // إغلاق نموذج تعديل منصة
+ function closeEditPlatformModal() {
+ document.getElementById("editPlatformModal").style.display = "none";
+ resetEditPlatformModalInputs();
+ resetEditPlatformModalErrors();
+ }
+
+ function resetEditPlatformModalInputs() {
+ document.getElementById("editPlatformName").value = "";
+ document.getElementById("editPlatformIcon").value = "";
+ document.getElementById("editPlatformPlaceholder").value = "";
+ document.getElementById("editPlatformUrl").value = "";
+ document.getElementById("editPlatformNotes").value = "";
+ document.getElementById("editPlatformColor").value = "";
+
+ }
+ function resetEditPlatformModalErrors() {
+ hideError(document.getElementById("editPlatformName"));
+ hideError(document.getElementById("editPlatformIcon"));
+ hideError(document.getElementById("editPlatformPlaceholder"));
+ hideError(document.getElementById("editPlatformUrl"));
+ hideError(document.getElementById("editPlatformColor"));
+
+ }
+ // حفظ تعديلات المنصة
+ function saveEditPlatform() {
+ const index = document.getElementById("editPlatformModal").getAttribute('data-index');
+ const editPlatformName = document.getElementById("editPlatformName");
+ const editPlatformIcon = document.getElementById("editPlatformIcon");
+ const editPlatformPlaceholder = document.getElementById("editPlatformPlaceholder");
+ const editPlatformUrl = document.getElementById("editPlatformUrl");
+ const editPlatformNotes = document.getElementById("editPlatformNotes");
+ const editPlatformColor = document.getElementById("editPlatformColor");
+
+
+ let isValid = true;
+
+ isValid = validateInput(editPlatformName, 'يرجى إدخال اسم المنصة', value => value !== "") && isValid;
+ isValid = validateInput(editPlatformIcon, 'يرجى إدخال الأيقونة', value => value !== "") && isValid;
+ isValid = validateInput(editPlatformPlaceholder, 'يرجى إدخال مثال للمدخل', value => value !== "") && isValid;
+ isValid = validateInput(editPlatformUrl, 'يرجى إدخال الرابط', value => value !== "") && isValid;
+ isValid = validateInput(editPlatformColor, "يرجى إدخال لون", value => /^#([0-9a-f]{3}){1,2}$/i.test(value)) && isValid;
+
+
+
+ if (isValid) {
+ platforms[index] = {
+ name: editPlatformName.value.trim(),
+ icon: editPlatformIcon.value.trim(),
+ placeholder: editPlatformPlaceholder.value.trim(),
+ url: editPlatformUrl.value.trim(),
+ notes: editPlatformNotes.value.trim(),
+ color: editPlatformColor.value.trim(),
+
+ };
+ savePlatforms();
+ createSections();
+ closeEditPlatformModal();
+ toastr.success("تم تعديل المنصة بنجاح!");
+ }
+ }
+
+ // فتح نموذج الإعدادات
+ function openSettingsModal() {
+ document.getElementById("settingsModal").style.display = "block";
+ }
+
+ // إغلاق نموذج الإعدادات
+ function closeSettingsModal() {
+ document.getElementById("settingsModal").style.display = "none";
+ }
+ // تعيين الوضع الفاتح
+ function setLightTheme() {
+ userSettings.darkMode= false;
+ saveUserSettings();
+ updateAppColors();
+ closeSettingsModal();
+ toastr.info("تم تغيير الوضع إلى الفاتح.");
+ }
+
+ // تعيين الوضع الداكن
+ function setDarkTheme() {
+ userSettings.darkMode= true;
+ saveUserSettings();
+ updateAppColors();
+ closeSettingsModal();
+ toastr.info("تم تغيير الوضع إلى الداكن.");
+ }
+ // ترتيب المنصات أبجديا تصاعديا
+ function sortPlatformsByNameAsc() {
+ platforms.sort((a, b) => a.name.localeCompare(b.name));
+ savePlatforms();
+ createSections();
+ closeSettingsModal();
+ toastr.success("تم ترتيب المنصات تصاعدياً!");
+ }
+
+ // ترتيب المنصات أبجديا تنازليا
+ function sortPlatformsByNameDesc() {
+ platforms.sort((a, b) => b.name.localeCompare(a.name));
+ savePlatforms();
+ createSections();
+ closeSettingsModal();
+ toastr.success("تم ترتيب المنصات تنازلياً!");
+ }
+
+ function openCustomSortModal() {
+ document.getElementById("customSortModal").style.display = "block";
+ const sortablePlatformsList = document.getElementById("sortablePlatforms");
+ sortablePlatformsList.innerHTML = "";
+ platforms.forEach((platform, index) => {
+ const listItem = document.createElement("li");
+ listItem.className = "platform-item";
+ listItem.setAttribute("data-index", index);
+ listItem.innerHTML = `
${platform.name}`;
+ sortablePlatformsList.appendChild(listItem);
+ });
+ new Sortable(sortablePlatformsList, {
+ animation: 150,
+ });
+
+ }
+
+ function closeCustomSortModal() {
+ document.getElementById("customSortModal").style.display = "none";
+ }
+ function saveCustomOrder() {
+ const sortablePlatformsList = document.getElementById("sortablePlatforms");
+ const sortedItems = Array.from(sortablePlatformsList.children);
+ const newOrder = sortedItems.map(item => parseInt(item.getAttribute('data-index')));
+ const sortedPlatforms = newOrder.map(index => platforms[index]);
+ platforms = sortedPlatforms;
+ savePlatforms();
+ createSections();
+ closeCustomSortModal();
+ toastr.success("تم حفظ الترتيب المخصص!");
+ }
+ function selectPredefinedColor(color){
+ userSettings.backgroundColor = color;
+ saveUserSettings();
+ document.body.style.background = `linear-gradient(135deg, ${color}, #2a5298)`;
+ $("#colorPicker").spectrum("set", color);
+
+ }
+
+ // إعادة تعيين جميع الإعدادات
+ function resetAllSettings() {
+ localStorage.clear();
+ window.location.reload();
+ toastr.warning("تم إعادة تعيين جميع الإعدادات!");
+ }
+
+ // فتح نموذج الاستيراد والتصدير
+ function openImportExportModal() {
+ document.getElementById("importExportModal").style.display = "block";
+ }
+ // اغلاق نموذج الاستيراد والتصدير
+ function closeImportExportModal() {
+ document.getElementById("importExportModal").style.display = "none";
+ document.getElementById("exportTextArea").value = '';
+ }
+ // تصدير المنصات
+ function exportPlatforms() {
+ const json = JSON.stringify(platforms, null, 2);
+ document.getElementById("exportTextArea").value = json;
+ toastr.info("تم تصدير المنصات إلى مربع النص!");
+ }
+ // استيراد المنصات من ملف
+ function importPlatformsFromFile(event) {
+ const file = event.target.files[0];
+ if (file) {
+ const reader = new FileReader();
+ reader.onload = function (e) {
+ try {
+ const json = e.target.result;
+ const importedPlatforms = JSON.parse(json);
+ if (Array.isArray(importedPlatforms)) {
+ platforms = importedPlatforms;
+ savePlatforms();
+ createSections();
+ closeImportExportModal();
+ toastr.success("تم استيراد المنصات بنجاح من الملف!");
+ } else {
+ toastr.error("تنسيق الملف غير صالح، يجب أن يكون JSON array!");
+ }
+ } catch (error) {
+ toastr.error("حدث خطأ أثناء استيراد المنصات!");
+ console.error("Error importing platforms:", error);
+ }
+ };
+ reader.readAsText(file);
+ }
+ }
+ // استيراد المنصات من مربع النص
+ function importPlatforms() {
+ const json = document.getElementById("exportTextArea").value;
+ try {
+ const importedPlatforms = JSON.parse(json);
+ if (Array.isArray(importedPlatforms)) {
+ platforms = importedPlatforms;
+ savePlatforms();
+ createSections();
+ closeImportExportModal();
+ toastr.success("تم استيراد المنصات بنجاح!");
+ } else {
+ toastr.error("تنسيق JSON غير صالح، يجب أن يكون JSON array!");
+ }
+ } catch (error) {
+ toastr.error("حدث خطأ أثناء استيراد المنصات!");
+ console.error("Error importing platforms:", error);
+ }
+ }
+ // فتح نموذج البحث
+ function openSearchModal() {
+ document.getElementById("searchModal").style.display = "block";
+ $('#searchFieldSelect').select2({
+ placeholder: "اختر حقل البحث",
+ dir: "rtl",
+ });
+ }
+ // إغلاق نموذج البحث
+ function closeSearchModal() {
+ document.getElementById("searchModal").style.display = "none";
+ document.getElementById("searchInput").value = "";
+ document.getElementById("searchResults").innerHTML = "";
+ $('#searchFieldSelect').val(null).trigger('change');
+ }
+ // البحث عن منصة
+ function searchPlatforms() {
+ const searchTerm = document.getElementById("searchInput").value.trim();
+ const searchField = document.getElementById("searchFieldSelect").value;
+ const resultsContainer = document.getElementById("searchResults");
+ resultsContainer.innerHTML = "";
+ if (!searchTerm) {
+ toastr.warning("يرجى إدخال كلمة البحث!");
+ return;
+ }
+ const filteredPlatforms = platforms.filter(platform => {
+ const searchValue = String(platform[searchField]).toLowerCase();
+ return searchValue.includes(searchTerm.toLowerCase());
+ });
+ if (filteredPlatforms.length === 0) {
+ resultsContainer.innerHTML = "
لا توجد نتائج مطابقة.
";
+ return;
+ }
+ filteredPlatforms.forEach(platform => {
+ const resultItem = document.createElement("div");
+ resultItem.className = "search-result-item";
+ resultItem.innerHTML = `
+
الاسم: ${platform.name}
+
الأيقونة: ${platform.icon}
+
مثال الإدخال: ${platform.placeholder}
+
الرابط: ${platform.url}
+
ملاحظات: ${platform.notes}
+ `;
+ resultsContainer.appendChild(resultItem);
+ });
+
+ }
+ // تهيئة لون الخلفية
+ function initColorPicker() {
+ $("#colorPicker").spectrum({
+ type: "color",
+ preferredFormat: "hex",
+ showInput: true,
+ move: function (color) {
+ document.body.style.background = `linear-gradient(135deg, ${color.toHexString()}, #2a5298)`;
+ userSettings.backgroundColor = color.toHexString();
+ },
+ change: function(color){
+ document.body.style.background = `linear-gradient(135deg, ${color.toHexString()}, #2a5298)`;
+ userSettings.backgroundColor = color.toHexString();
+ saveUserSettings();
+ }
+
+ });
+ }
+
+
+ // التهيئة
+ function init() {
+ loadPlatforms();
+ updateAppColors();
+ createSections();
+ initColorPicker();
+ document.body.style.background = `linear-gradient(135deg, ${userSettings.backgroundColor}, #2a5298)`;
+ $("#colorPicker").spectrum("set", userSettings.backgroundColor);
+ if(userSettings.darkMode){
+ document.body.classList.add("dark-mode")
+ }
+ toastr.options = {
+ "closeButton": true,
+ "progressBar": true,
+ "positionClass": "toast-top-right",
+ }
+ }
+ // تنفيذ التهيئة عند التحميل
+ window.onload = init;
+