Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
HTML
<style>
@font-face {
  font-family: "IRANSans";
  src: url("/download/attachments/85042597/IRANSansXVF.woff2") format("woff2");
}

@font-face {
  font-family: "Vazir";
  src: url("/download/attachments/85042597/Vazir-Regular.woff2") format("woff2");
}

:root {
  --brand: #bd2b76;
  --brand-soft: #fff5fb;
  --brand-border: #f5c7e2;
}

body {
  background: #f4f5f8;
  font-family: Vazir, IRANSans, Tahoma;
}

#public-resolutions-app {
  direction: rtl;
  max-width: 1100px1150px;
  margin: 30px auto;
  background: #fff;
  border: 1px solid #e6e6e6;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.10);
  font-family: Vazir, IRANSans, Tahoma;
}

.public-header {
  display: flex;
  align-items: center;
  justify-content: space-betweencenter;
  gap: 12px;
  margin-bottom: 18px;
}

.public-title {
  color: var(--brand);
  font-size: 20px;
  font-weight: 900;
  margin: 0;
}

.public-actionsfilters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.public-btn {
  border: none;
  background: background: var(--brand-soft);
  border: 1px solid var(--brand-border);
  color: #fff;
  border-radius: 9px14px;
  padding: 8px 14px;
  cursordisplay: flex;
  gap: pointer12px;
  fontflex-familywrap: inheritwrap;
  fontmargin-sizebottom: 13px16px;
}

.public-btn:hoverfield {
  opacityflex: 0.91 1 180px;
}

.public-filtersfield label {
  backgrounddisplay: var(--brand-soft)block;
  borderfont-weight: 1px solid var(--brand-border)800;
  borderfont-radiussize: 14px13px;
  padding: 14px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-margin-bottom: 16px5px;
}

.public-field {
  flex: 1 1 180px;
}

input,
.public-field labelselect {
  displaywidth: block100%;
  fontbox-weightsizing: 800border-box;
  font-sizeborder: 13px;
  margin-bottom: 5px;
}

.public-field input,
.public-field select {
  width: 100%;
  box-sizing: border-box;
  border: 1px  1px solid #d1d5db;
  border-radius: 9px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
}

.public-field input:focus,
.public-field select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 5px rgba(189,43,118,0.25);
}

.public-table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
}

#publicTable {
  width: 100%;
  min-width: 900px850px;
  border-collapse: collapse;
  background: #fff;
  font-size: 13px;
}

#publicTable th {
  background: #f5f6fb;
  color: #1f2933;
  border: 1px solid #e5e7eb;
  padding: 10px;
  text-align: center;
  font-weight: 900;
}

#publicTable td {
  border: 1px solid #e5e7eb;
  padding: 9px 10px;
  text-align: center;
  vertical-align: middle;
}

#publicTable td.title-cell {
  text-align: right;
  line-height: 2;
  white-space: pre-wrap;
}

#publicTable tbody tr:nth-child(even) {
  background: #fafafa;
}

.public-empty,
.public-loading,
.public-error {
  text-align: center;
  padding: 18px;
  border-radius: 12px;
  margin-top: 14px;
  font-weight: 800;
}

.public-loading {
  background: #f8fafc;
  color: #334155;
}

.public-empty {
  background: #fff7ed;
  color: #9a3412;
}

.public-error {
  background: #fef2f2;
  color: #b91c1c;
}
</style>

.public-link {
  color: #2563eb;
  font-weight: 800;
  text-decoration: none;
}

.public-link:hover {
  text-decoration: underline;
}
</style>

<div id="public-<div id="public-resolutions-app">
  <div class="public-header">
    <h1 class="public-title">📌 مصوبات عمومی</h1>
  </div>

  <div class="public-actionsfilters">
    <div  <button type="button" class="public-btn" id="refreshPublicBtn">🔄 بروزرسانی</button>
    </div>
  </div>

  <div class="public-filters">
    <div class="class="public-field">
      <label>جستجو در عنوان مصوبه</label>
      <input type="text" id="searchText" placeholder="مثلاً بخشی از عنوان مصوبه">
    </div>

    <div class="public-field">
      <label>کمیته</label>
      <select id="committeeFilter">
        <option value="">همه کمیته‌ها</option>
      </select>
    </div>

    <div class="public-field">
      <label>تاریخ جلسه</label>
      <input type="text" id="dateFilter" placeholder="مثلاً 1405/03/24">
    </div>
  </div>

  <div id="publicStatus" class="public-loading">در حال بارگذاری مصوبات عمومی...</div>

  <div class="public-table-wrap" style="display:none;" id="publicTableWrap">
    <table id="publicTable">
      <thead>
        <tr>
          <th style="width:5%;">ردیف</th>
          <th style="width:18%;">کمیته</th>
          <th style="width:12%;">تاریخ جلسه</th>
          <th style="width:35%;">عنوان مصوبه</th>
          <th style="width:12%;">مسئول پیگیری</th>
          <th style="width:12%;">مسئول اجرا</th>
          <th style="width:10%;">مهلت مقرر</th>
          <th style="width:8%;">صورتجلسه</th></tr>
        </tr>
      </</thead>
      <tbody id="publicBody"></tbody>
    </table>
  </div>
</div>

<script>
(function () {
  const PUBLIC_RESOLUTIONS_PAGE_ID = 120520717;
  const PUBLIC_RESOLUTIONS_FILE = "public_resolutions.json";

  const BASE = (() => {
    try {
      if (window.AJS && typeof AJS.contextPath === "function") return AJS.contextPath();
    } catch (e) {}

    const m = location.pathname.match(/^(.+?)\/pages\//);
    return m ? m[1] : "";
  })();

  const baseUrl =
    (window.AJS && window.AJS.params && (window.AJS.params.baseURL || window.AJS.params.baseUrl)) ||
    (location.origin + BASE);

  let allRows = [];

  const statusBox = document.getElementById("publicStatus");
  const tableWrap = document.getElementById("publicTableWrap");
  const tbody = document.getElementById("publicBody");
  const searchText = document.getElementById("searchText");
  const committeeFilter = document.getElementById("committeeFilter");
  const dateFilter = document.getElementById("dateFilter");
  const refreshBtn = document.getElementById("refreshPublicBtn");

  function safeText(v) {
    v = String(v || "");
    var amp = String.fromCharCode(38);

    v = v.replace(/&/g, amp + "amp;");
    v = v.replace(/</g, amp + "lt;");
    v = v.replace(/>/g, amp + "gt;");
    v = v.replace(/"/g, amp + "quot;");
    v = v.replace(/'/g, amp + "#39;");

    return v;
  }

  function normalize(v) {
    return String(v || "")
      .replace(/\u200c/g, "")
      .replace(/\s+/g, " ")
      .trim();
  }

  function toPersianDigits(v) {
    return String(v || "").replace(/\d/g, function (d) {
      return "۰۱۲۳۴۵۶۷۸۹"[d];
    });
  }

  async function loadJSON(pageId, filename) {
    try {
      const directUrl =
        `${BASE}/download/attachments/${pageId}/${encodeURIComponent(filename)}?api=v2&cb=${Date.now()}`;

      const r1 = await fetch(directUrl, {
        credentials: "include",
        headers: { Accept: "application/json,text/plain,*/*" }
      });

      if (r1.ok) {
        const txt = await r1.text();
        if (txt && txt.trim()) return JSON.parse(txt);
      }
    } catch (e1) {
      console.warn("direct loadloadJSON failed:", e1);
    }

    try {
      const metaUrl =
        `${BASE}/rest/api/content/${pageId}/child/attachment?filename=${encodeURIComponent(filename)}&expand=version`;

      const r2 = await fetch(metaUrl, {
        credentials: "include",
        headers: { Accept: "application/json" }
      });

      if (!r2.ok) return [];

      const meta = await r2.json();
      const att = meta && meta.results && meta.results[0] ? meta.results[0] : null;

      if (!att || !att._links || !att._links.download) return [];

      let dl = att._links.download;
      let downloadUrl = dl.indexOf("http") === 0 ? dl : (baseUrl + dl);
      downloadUrl += (downloadUrl.indexOf("?") >= 0 ? "&" : "?") + "cb=" + Date.now();

      const r3 = await fetch(downloadUrl, {
        credentials: "include",
        headers: { Accept: "application/json,text/plain,*/*" }
      });

      if (!r3.ok) return [];

      const txt = await r3.text();
      if (!txt || !txt.trim()) return [];

      return JSON.parse(txt);
    } catch (e2) {
      console.error("loadJSON error:", e2);
      return [];
    }
  }

  async function fillCommitteeFilterpageExists(rowspageId) {
    constpageId oldValue = committeeFilter.valueString(pageId || "").trim();

    if (!pageId) return false;

    try {
      const res = await fetch(`${baseUrl}/rest/api/content/${encodeURIComponent(pageId)}`, {
        credentials: "include",
        headers: { Accept: "application/json" }
      });

      return res.ok;
    } catch (e) {
      return false;
    }
  }

  async function getAttachmentByName(pageId, filename) {
    try {
      const url =
        `${BASE}/rest/api/content/${pageId}/child/attachment?filename=${encodeURIComponent(filename)}&expand=version`;

      const r = await fetch(url, {
        credentials: "include",
        headers: { Accept: "application/json" }
      });

      if (!r.ok) return null;

      const j = await r.json();
      return j.results && j.results[0] ? j.results[0] : null;
    } catch (e) {
      console.error("getAttachmentByName error:", e);
      return null;
    }
  }

  async function updateData(pageId, attachmentId, file, filename) {
    const fd = new FormData();
    fd.append("file", file, filename);

    const r = await fetch(`${BASE}/rest/api/content/${pageId}/child/attachment/${attachmentId}/data`, {
      method: "POST",
      credentials: "include",
      headers: {
        "X-Atlassian-Token": "no-check",
        Accept: "application/json"
      },
      body: fd
    });

    if (!r.ok) {
      throw new Error(await r.text());
    }
  }

  async function uploadNew(pageId, file, filename) {
    const fd = new FormData();
    fd.append("file", file, filename);

    const r = await fetch(`${BASE}/rest/api/content/${pageId}/child/attachment`, {
      method: "POST",
      credentials: "include",
      headers: {
        "X-Atlassian-Token": "no-check",
        Accept: "application/json"
      },
      body: fd
    });

    if (!r.ok) {
      throw new Error(await r.text());
    }
  }

  async function savePublicRows(rows) {
    const blob = new Blob([JSON.stringify(rows, null, 2)], {
      type: "application/json"
    });

    const existing = await getAttachmentByName(PUBLIC_RESOLUTIONS_PAGE_ID, PUBLIC_RESOLUTIONS_FILE);

    if (existing) {
      await updateData(PUBLIC_RESOLUTIONS_PAGE_ID, existing.id, blob, PUBLIC_RESOLUTIONS_FILE);
    } else {
      await uploadNew(PUBLIC_RESOLUTIONS_PAGE_ID, blob, PUBLIC_RESOLUTIONS_FILE);
    }
  }

  async function removeDeletedMeetingRows(rows) {
    const validRows = [];

    for (const r of rows) {
      if (!r || !String(r.title || "").trim()) continue;

      const committeespageId = Array.from(new Set(String(r.pageId || "").trim();

      rows.map(r => normalize(r.committee)).filter(Boolean)if (!pageId) continue;

    )).sort(  const exists = await pageExists(pageId);

     committeeFilter.innerHTML =if `<option value="">همه کمیته‌ها</option>` +
(exists) {
        committeesvalidRows.map(c => `<option value="${safeText(c)}">${safeText(c)}</option>`).join("");

    committeeFilter.value = oldValuepush(r);
      }
    }

    return validRows;
  }

  function getFilteredRowsfillCommitteeFilter(rows) {
    const qoldValue = normalize(searchTextcommitteeFilter.value) || "";

    const ccommittees = normalize(committeeFilter.value);
Array.from(new Set(
     const drows.map(r => normalize(dateFilter.value);
r.committee)).filter(Boolean)
    return allRows.filter(function (r) {
   )).sort();

   const titlecommitteeFilter.innerHTML = normalize(r.title);
      const committee = normalize(r.committee);`<option value="">همه کمیته‌ها</option>` +
      const meetingDate = normalize(r.meetingDate committees.map(c => `<option value="${safeText(c)}">${safeText(c)}</option>`).join("");

      if (q && !title.includes(q)) return false committeeFilter.value = oldValue;
  }

  function getFilteredRows() {
 if  (c &&const committeeq !== c) return falsenormalize(searchText.value);
    const c if= (d && !meetingDate.includes(d)) return false;

  normalize(committeeFilter.value);
    returnconst true;
d    }= normalize(dateFilter.value);

   }

 return allRows.filter(function render(r) {
      const rowstitle = getFilteredRowsnormalize(r.title);

      tbody.innerHTMLconst committee = ""normalize(r.committee);

      const ifmeetingDate = normalize(!rowsr.lengthmeetingDate) {
;

      if (q && tableWrap.style.display = "none"!title.includes(q)) return false;
      statusBox.style.display = "block";
      statusBox.className = "public-empty"if (c && committee !== c) return false;
      statusBox.textContent = "موردی برای نمایش وجود ندارد.";
if (d && !meetingDate.includes(d)) return false;

      return true;
    });

  }

  rows.forEach(function render(r, index) {
      const pageIdrows = r.pageId || ""getFilteredRows();

      const pageLink = pageId
     tbody.innerHTML = "";

   ? `${baseUrl}/pages/viewpage.action?pageId=${encodeURIComponent(pageId)}` if (!rows.length) {
      tableWrap.style.display = : "none";

      const tr statusBox.style.display = document.createElement("trblock");
      trstatusBox.innerHTMLclassName = `"public-empty";
      statusBox.textContent = "موردی برای <td>${toPersianDigits(index + 1)}</td>نمایش وجود ندارد.";
      return;
  <td>${safeText(r.committee || "")}</td>}

        <td>${safeText(toPersianDigits(r.meetingDate || ""))}</td>rows.forEach(function (r, index) {
      const tr <td class="title-cell">${safeText(r.title || "")}</td>= document.createElement("tr");

      tr.innerHTML = `
        <td>${safeTexttoPersianDigits(r.followup || ""index + 1)}</td>
        <td>${safeText(r.executorcommittee || "")}</td>
        <td>${safeText(toPersianDigits(r.deadlinemeetingDate || ""))}</td>
        <td>
          ${
            pageLink
    td>
          ?<td `<a class="publictitle-link" href="${pageLink}" target="_self">مشاهده</a>`cell">${safeText(r.title || "")}</td>
        <td>${safeText(r.followup || "")}</td>
         :<td>${safeText(r.executor || "")}</td>
        <td>${safeText(toPersianDigits(r.deadline || }
        ""))}</td>
      `;

      tbody.appendChild(tr);
    });

    statusBox.style.display = "none";
    tableWrap.style.display = "block";
  }

  async function loadPublicResolutions() {
    statusBox.style.display = "block";
    statusBox.className = "public-loading";
    statusBox.textContent = "در حال بارگذاری مصوبات عمومی...";
    tableWrap.style.display = "none";

    try {
      const data = await loadJSON(PUBLIC_RESOLUTIONS_PAGE_ID, PUBLIC_RESOLUTIONS_FILE);
      const rows = Array.isArray(data) ? data : [];

      const validRows = await removeDeletedMeetingRows(rows);

      allRows = Array.isArray(data) ? data : []validRows;

      if allRows (validRows.length !== allRows.filter(function (rrows.length) {
        return r && String(r.title || "").trim(await savePublicRows(validRows);
      });

      fillCommitteeFilter(allRows);
      render();

    } catch (e) {
      console.error(e);
      statusBox.style.display = "block";
      statusBox.className = "public-error";
      statusBox.textContent = "خطا در بارگذاری مصوبات عمومی.";
      tableWrap.style.display = "none";
    }
  }

  searchText.addEventListener("input", render);
  committeeFilter.addEventListener("change", render);
  dateFilter.addEventListener("input", render);
  refreshBtn.addEventListener("click", loadPublicResolutions);

  loadPublicResolutions();
})();
</script>