| 1 |
|
| 2 |
* GoingsOn - Unified Namespace |
| 3 |
* Central namespace for the entire application, reducing window pollution |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
window.GoingsOn = { |
| 9 |
|
| 10 |
version: '1.0.0', |
| 11 |
|
| 12 |
|
| 13 |
state: null, |
| 14 |
|
| 15 |
|
| 16 |
api: null, |
| 17 |
|
| 18 |
|
| 19 |
utils: {}, |
| 20 |
|
| 21 |
|
| 22 |
ui: {}, |
| 23 |
|
| 24 |
|
| 25 |
projects: {}, |
| 26 |
tasks: {}, |
| 27 |
events: {}, |
| 28 |
emails: {}, |
| 29 |
|
| 30 |
|
| 31 |
dayPlan: {}, |
| 32 |
snooze: {}, |
| 33 |
search: {}, |
| 34 |
navigation: {}, |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
* Get projects cache from centralized state |
| 40 |
* @returns {Array} Projects array |
| 41 |
|
| 42 |
getProjectsCache: function() { |
| 43 |
return this.state?.projects || []; |
| 44 |
}, |
| 45 |
|
| 46 |
|
| 47 |
* Get current project ID |
| 48 |
* @returns {string|null} |
| 49 |
|
| 50 |
getCurrentProjectId: function() { |
| 51 |
return this.state?.currentProjectId ?? null; |
| 52 |
}, |
| 53 |
|
| 54 |
|
| 55 |
* Get tasks cache from centralized state |
| 56 |
* @returns {Array} Tasks array |
| 57 |
|
| 58 |
getTasksCache: function() { |
| 59 |
return this.state?.tasks || []; |
| 60 |
}, |
| 61 |
|
| 62 |
|
| 63 |
* Get emails cache from centralized state |
| 64 |
* @returns {Array} Emails array |
| 65 |
|
| 66 |
getEmailsCache: function() { |
| 67 |
return this.state?.emails || []; |
| 68 |
}, |
| 69 |
|
| 70 |
|
| 71 |
* Get email accounts cache from centralized state |
| 72 |
* @returns {Array} Email accounts array |
| 73 |
|
| 74 |
getEmailAccountsCache: function() { |
| 75 |
return this.state?.emailAccounts || []; |
| 76 |
}, |
| 77 |
|
| 78 |
|
| 79 |
* Get current view name |
| 80 |
* @returns {string} |
| 81 |
|
| 82 |
getCurrentView: function() { |
| 83 |
if (this.navigation?.getCurrentView) return this.navigation.getCurrentView(); |
| 84 |
return this.state?.currentView || 'projects'; |
| 85 |
}, |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
* Universal handler for onclick attributes |
| 91 |
* Usage: onclick="GoingsOn.handle('tasks.openNew')" |
| 92 |
* @param {string} path - Dot-separated path to function (e.g., 'tasks.openNew') |
| 93 |
* @param {...*} args - Arguments to pass to the function |
| 94 |
|
| 95 |
handle: function(path, ...args) { |
| 96 |
const parts = path.split('.'); |
| 97 |
let target = this; |
| 98 |
|
| 99 |
for (const part of parts) { |
| 100 |
if (target && typeof target === 'object' && part in target) { |
| 101 |
target = target[part]; |
| 102 |
} else { |
| 103 |
console.error(`GoingsOn.handle: Path "${path}" not found at "${part}"`); |
| 104 |
return; |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
if (typeof target === 'function') { |
| 109 |
return target.apply(this, args); |
| 110 |
} else { |
| 111 |
console.error(`GoingsOn.handle: "${path}" is not a function`); |
| 112 |
} |
| 113 |
} |
| 114 |
}; |
| 115 |
|