# -*- coding: utf-8 -*- """ 在崗位描述模組中添加部門職責關聯欄位 """ import sys import codecs if sys.platform == 'win32': sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict') sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict') # 讀取 index.html with open('index.html', 'r', encoding='utf-8') as f: content = f.read() # ==================== 1. 在崗位描述表單中添加部門職責欄位 ==================== # 在「所屬部門」欄位後面添加「部門職責」下拉選單 old_dept_field = '''
''' new_dept_field = '''
''' if old_dept_field in content and 'jd_deptFunction' not in content: content = content.replace(old_dept_field, new_dept_field) print("[OK] Added Department Function dropdown to Job Description form") else: print("[INFO] Department Function field already exists or pattern not found") # ==================== 2. 添加部門職責資訊顯示區塊 ==================== # 在崗位基本信息 section 後面添加部門職責資訊區塊 old_section_end = '''
''' # 找到直接下級後面的結構 new_section_end = '''
''' if jobdesc_section_pattern in content and 'deptFunctionInfoSection' not in content: content = content.replace(old_section_end + ''' ''', new_section_end + '''-->''') print("[OK] Added Department Function info section to Job Description") else: print("[INFO] Dept Function info section already exists or pattern not found - trying alternative approach") # ==================== 3. 添加相關 JavaScript 函數 ==================== dept_relation_js = ''' // ==================== 部門職責關聯功能 ==================== // 重新載入部門職責下拉選單 function refreshDeptFunctionList() { const select = document.getElementById('jd_deptFunction'); if (!select) return; // 清空現有選項 select.innerHTML = ''; // 從 deptFunctionData 載入選項 if (typeof deptFunctionData !== 'undefined' && deptFunctionData.length > 0) { deptFunctionData.forEach(df => { const option = document.createElement('option'); option.value = df.deptFunctionCode; option.textContent = `${df.deptFunctionCode} - ${df.deptFunctionName} (${df.deptFunctionDept})`; select.appendChild(option); }); showToast('已載入 ' + deptFunctionData.length + ' 筆部門職責資料'); } else { showToast('尚無部門職責資料,請先建立部門職責'); } } // 載入選中的部門職責資訊 function loadDeptFunctionInfo() { const select = document.getElementById('jd_deptFunction'); const infoSection = document.getElementById('deptFunctionInfoSection'); if (!select || !infoSection) return; const selectedCode = select.value; if (!selectedCode) { infoSection.style.display = 'none'; return; } // 從 deptFunctionData 找到對應的資料 if (typeof deptFunctionData !== 'undefined') { const deptFunc = deptFunctionData.find(d => d.deptFunctionCode === selectedCode); if (deptFunc) { // 填入部門職責資訊 document.getElementById('jd_deptFunctionCode').value = deptFunc.deptFunctionCode || ''; document.getElementById('jd_deptFunctionBU').value = deptFunc.deptFunctionBU || ''; document.getElementById('jd_deptMission').value = deptFunc.deptMission || ''; document.getElementById('jd_deptCoreFunctions').value = deptFunc.deptCoreFunctions || ''; document.getElementById('jd_deptKPIs').value = deptFunc.deptKPIs || ''; // 自動填入所屬部門 const deptInput = document.getElementById('jd_department'); if (deptInput && !deptInput.value) { deptInput.value = deptFunc.deptFunctionDept; } // 顯示部門職責資訊區塊 infoSection.style.display = 'block'; showToast('已載入部門職責: ' + deptFunc.deptFunctionName); } } } // 在頁面載入時初始化部門職責下拉選單 document.addEventListener('DOMContentLoaded', function() { // 延遲載入,確保 deptFunctionData 已初始化 setTimeout(refreshDeptFunctionList, 500); }); ''' # 在部門職責模組功能之後插入 dept_module_js_end = ' // ==================== 管理者頁面功能 ====================' if dept_module_js_end in content and 'refreshDeptFunctionList' not in content: content = content.replace(dept_module_js_end, dept_relation_js + dept_module_js_end) print("[OK] Added Department Function relation JavaScript functions") else: print("[INFO] Dept Function relation JS already exists or pattern not found") # 寫回檔案 with open('index.html', 'w', encoding='utf-8') as f: f.write(content) print("\n[DONE] Department Function relation added!") print("- Added Department Function dropdown to Job Description form") print("- Added Department Function info display section") print("- Added JavaScript functions for loading dept function data")