odant-work 1.0.74 → 1.0.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,343 +1,702 @@
1
+ function parseDroppedItem(e) {
2
+ const dt = e?.dataTransfer;
3
+ if (!dt)
4
+ return null;
5
+ const rawJson = dt.getData('data') || dt.getData('application/json') || dt.getData('application/oda.work.shortcut');
6
+ if (rawJson) {
7
+ try {
8
+ const parsed = JSON.parse(rawJson);
9
+ if (parsed && typeof parsed === 'object') {
10
+ const p = String(parsed.path || parsed.short || '').replace(/\/+$/, '');
11
+ return {
12
+ id: parsed.id || p.split('/').pop() || '',
13
+ path: p,
14
+ type: parsed.type || '',
15
+ label: parsed.label || parsed.DATA?.label || parsed.id || p,
16
+ };
17
+ }
18
+ }
19
+ catch { /* ignore */ }
20
+ }
21
+ const text = String(dt.getData('text/plain') || '').trim().replace(/\/+$/, '');
22
+ if (!text.startsWith('/'))
23
+ return null;
24
+ return { id: text.split('/').pop() || '', path: text, type: '', label: text.split('/').pop() || text };
25
+ }
26
+
27
+ function isDroppedUser(info) {
28
+ if (!info)
29
+ return false;
30
+ return info.type === '$user' || /^\/users\/[^/]+$/i.test(info.path || '');
31
+ }
32
+
33
+ function isDroppedStructure(info) {
34
+ if (!info)
35
+ return false;
36
+ if (['$structure', '$base', '$project', '$server'].includes(info.type))
37
+ return true;
38
+ return /^\/(?:ORGANIZATIONS|PROJECTS)\/[^/]+(?:\/[^/]+)*$/.test(info.path || '')
39
+ && !String(info.path || '').includes('/MODULES/');
40
+ }
41
+
42
+ function isDroppedClass(info) {
43
+ if (!info)
44
+ return false;
45
+ if (['$catalog', '$virtual', '$operation', '$register', '$account', '$struct', '$module'].includes(info.type))
46
+ return true;
47
+ return String(info.path || '').includes('/MODULES/');
48
+ }
49
+
50
+ function splitClassTitle(rawPath, mapEntry) {
51
+ if (mapEntry && typeof mapEntry === 'object')
52
+ return mapEntry;
53
+ const clean = String(rawPath || '')
54
+ .replace(/^\/(?:ORGANIZATIONS|PROJECTS)\/[^/]+\/MODULES\//, '')
55
+ .replace(/^\/MODULES\//, '');
56
+ const parts = clean.split('/').filter(Boolean);
57
+ const title = parts.length ? parts[parts.length - 1] : clean;
58
+ const section = parts.length > 1 ? parts.slice(0, -1).join(' / ') : '';
59
+ return { title, section, icon: 'odant:class' };
60
+ }
61
+
1
62
  export default {
2
- imports: 'oda//icon, oda//button, /~/lib//messenger-settings.js',
63
+ imports: 'oda//icon, oda//button',
3
64
  template: /*html*/`
4
65
  <style>
5
66
  :host {
6
67
  @apply --vertical;
7
68
  @apply --flex;
8
- padding: 16px 20px;
9
- gap: 16px;
69
+ padding: 14px 18px;
70
+ gap: 10px;
10
71
  overflow-y: auto;
11
72
  background: var(--content-background);
12
73
  color: var(--content-color);
74
+ font-size: 13px;
13
75
  }
14
- .card {
15
- @apply --vertical;
16
- gap: 10px;
17
- padding: 14px 16px;
18
- border: 1px solid var(--subtle-border);
19
- border-radius: 8px;
20
- background: var(--subtle-background);
21
- }
22
- .place-card {
76
+ .tree-box {
23
77
  @apply --vertical;
24
- gap: 10px;
25
- padding: 12px 14px;
26
78
  border: 1px solid var(--subtle-border);
27
- border-radius: 8px;
79
+ border-radius: 10px;
28
80
  background: var(--content-background);
81
+ overflow: hidden;
29
82
  }
30
- .place-card.active-place {
31
- border-color: var(--accent-color);
32
- box-shadow: 0 0 0 2px var(--accent-soft);
33
- }
34
- .card-header {
83
+ .root-row {
35
84
  @apply --horizontal;
36
85
  align-items: center;
37
86
  gap: 8px;
87
+ padding: 10px 14px;
88
+ background: var(--subtle-background);
89
+ border-bottom: 1px solid var(--subtle-border);
90
+ flex-wrap: wrap;
91
+ transition: background .15s;
92
+ }
93
+ .root-row.drop-hover, .tree-row.drop-hover {
94
+ background: color-mix(in srgb, var(--accent-color, #2563eb) 10%, var(--content-background));
95
+ outline: 1px dashed var(--accent-color, #2563eb);
96
+ outline-offset: -2px;
97
+ }
98
+ .root-title {
38
99
  font-weight: 700;
39
- font-size: 15px;
100
+ font-size: 14px;
101
+ margin-right: 4px;
40
102
  }
41
- .role-row {
103
+ .boss-label {
104
+ font-size: 12px;
105
+ color: var(--muted-color);
106
+ }
107
+ .tree-row {
42
108
  @apply --horizontal;
43
109
  align-items: center;
110
+ gap: 6px;
111
+ padding: 6px 12px;
112
+ min-height: 34px;
113
+ border-bottom: 1px solid color-mix(in srgb, var(--subtle-border) 55%, transparent);
44
114
  flex-wrap: wrap;
45
- gap: 8px;
46
115
  }
47
- .role-title {
48
- font-size: 13px;
49
- font-weight: 600;
116
+ .tree-row:last-child {
117
+ border-bottom: none;
118
+ }
119
+ .tree-row.role-row {
120
+ background: var(--content-background);
121
+ }
122
+ .tree-row.role-row:hover {
123
+ background: color-mix(in srgb, var(--subtle-background) 65%, transparent);
124
+ }
125
+ .tree-row.class-row {
126
+ min-height: 30px;
127
+ padding-top: 4px;
128
+ padding-bottom: 4px;
129
+ background: color-mix(in srgb, var(--subtle-background) 35%, var(--content-background));
130
+ }
131
+ .tree-row.class-row:hover {
132
+ background: var(--subtle-background);
133
+ }
134
+ .expander {
135
+ width: 18px;
136
+ height: 18px;
137
+ display: inline-flex;
138
+ align-items: center;
139
+ justify-content: center;
140
+ cursor: pointer;
50
141
  color: var(--muted-color);
142
+ user-select: none;
143
+ border-radius: 4px;
144
+ }
145
+ .expander:hover {
146
+ background: var(--subtle-background);
147
+ color: var(--content-color);
148
+ }
149
+ .role-name {
150
+ font-weight: 600;
151
+ font-size: 13.5px;
152
+ }
153
+ .members-wrap {
154
+ @apply --horizontal;
155
+ align-items: center;
156
+ gap: 5px;
157
+ flex-wrap: wrap;
158
+ flex: 1;
51
159
  min-width: 140px;
52
160
  }
53
- .user-chip {
161
+ .chip {
54
162
  @apply --horizontal;
55
163
  align-items: center;
56
- gap: 6px;
57
- padding: 3px 8px;
164
+ gap: 5px;
165
+ padding: 2px 8px 2px 4px;
58
166
  border-radius: 14px;
59
167
  background: var(--accent-soft);
60
168
  color: var(--content-color);
61
- font-size: 13px;
62
- }
63
- .user-chip.clickable {
169
+ font-size: 12.5px;
64
170
  cursor: pointer;
65
171
  }
66
- .user-chip.clickable:hover {
172
+ .chip.inherited {
173
+ opacity: .75;
174
+ }
175
+ .chip.node-chip {
176
+ background: color-mix(in srgb, #0284c7 13%, var(--content-background));
177
+ border: 1px solid color-mix(in srgb, #0284c7 28%, transparent);
178
+ }
179
+ .chip:hover {
67
180
  filter: brightness(0.95);
68
181
  }
182
+ .chip .rm {
183
+ font-weight: 700;
184
+ opacity: .6;
185
+ padding: 0 2px;
186
+ cursor: pointer;
187
+ }
188
+ .chip .rm:hover {
189
+ opacity: 1;
190
+ color: var(--error-color, #dc2626);
191
+ }
69
192
  .badge {
70
193
  font-size: 11px;
71
194
  font-weight: 600;
72
- padding: 2px 7px;
73
- border-radius: 10px;
195
+ padding: 1px 6px;
196
+ border-radius: 8px;
74
197
  background: var(--accent-soft);
75
198
  color: var(--accent-color);
76
199
  }
77
- .badge.external {
200
+ .badge.ext {
78
201
  background: light-dark(#fef3c7, #422006);
79
202
  color: light-dark(#92400e, #fcd34d);
80
203
  }
81
- .ext-toggle {
82
- @apply --horizontal;
83
- align-items: center;
84
- gap: 5px;
85
- font-size: 12px;
204
+ .icon-btn {
205
+ border: 1px solid transparent;
206
+ background: transparent;
86
207
  color: var(--muted-color);
208
+ border-radius: 6px;
209
+ padding: 3px 7px;
210
+ font: inherit;
211
+ font-size: 12px;
87
212
  cursor: pointer;
88
- user-select: none;
213
+ display: inline-flex;
214
+ align-items: center;
215
+ gap: 4px;
89
216
  }
90
- .link-title {
91
- flex: 1;
217
+ .icon-btn:hover {
218
+ background: var(--subtle-background);
219
+ border-color: var(--subtle-border);
220
+ color: var(--content-color);
221
+ }
222
+ .icon-btn.active {
223
+ background: var(--accent-soft);
224
+ color: var(--accent-color);
225
+ border-color: color-mix(in srgb, var(--accent-color) 35%, transparent);
226
+ }
227
+ .icon-btn.danger:hover {
228
+ color: var(--error-color, #dc2626);
229
+ }
230
+ .row-actions {
231
+ @apply --horizontal;
232
+ align-items: center;
233
+ gap: 2px;
234
+ margin-left: auto;
235
+ }
236
+ .class-title {
92
237
  font-weight: 500;
93
238
  cursor: pointer;
94
239
  }
95
- .link-title:hover {
240
+ .class-title:hover {
96
241
  color: var(--accent-color);
97
242
  text-decoration: underline;
98
243
  }
99
- .user-chip .rm {
100
- cursor: pointer;
101
- font-weight: bold;
102
- opacity: .65;
103
- padding: 0 2px;
244
+ .class-section {
245
+ font-size: 11.5px;
246
+ color: var(--muted-color);
104
247
  }
105
- .user-chip .rm:hover {
106
- opacity: 1;
107
- color: var(--error-color);
248
+ .write-check {
249
+ @apply --horizontal;
250
+ align-items: center;
251
+ gap: 5px;
252
+ font-size: 12.5px;
253
+ cursor: pointer;
254
+ user-select: none;
255
+ margin-left: auto;
256
+ padding-right: 6px;
108
257
  }
109
- select, input[type="text"] {
110
- padding: 4px 8px;
111
- border: 1px solid var(--control-border-color);
112
- border-radius: 6px;
113
- font: inherit;
114
- font-size: 13px;
115
- background: var(--control-background);
116
- color: var(--control-color);
258
+ .inline-panel {
259
+ @apply --vertical;
260
+ gap: 8px;
261
+ padding: 10px 14px;
262
+ background: var(--subtle-background);
263
+ border-bottom: 1px solid var(--subtle-border);
117
264
  }
118
- .links-box {
265
+ .panel-list {
119
266
  @apply --vertical;
120
- gap: 6px;
121
- padding-top: 6px;
122
- border-top: 1px dashed var(--subtle-border);
267
+ gap: 2px;
268
+ max-height: 220px;
269
+ overflow-y: auto;
270
+ border: 1px solid var(--subtle-border);
271
+ border-radius: 6px;
272
+ padding: 4px;
273
+ background: var(--content-background);
123
274
  }
124
- .link-row {
275
+ .panel-item {
125
276
  @apply --horizontal;
126
277
  align-items: center;
127
278
  gap: 8px;
279
+ padding: 5px 8px;
280
+ border-radius: 5px;
281
+ cursor: pointer;
128
282
  font-size: 13px;
129
- padding: 3px 6px;
283
+ }
284
+ .panel-item:hover {
130
285
  background: var(--subtle-background);
286
+ }
287
+ input[type="text"] {
288
+ padding: 5px 8px;
289
+ border: 1px solid var(--control-border-color, var(--subtle-border));
131
290
  border-radius: 6px;
291
+ font: inherit;
292
+ font-size: 13px;
293
+ background: var(--content-background);
294
+ color: var(--control-color, inherit);
132
295
  }
133
296
  .muted {
134
297
  color: var(--muted-color);
135
- font-size: 13px;
298
+ font-size: 12px;
136
299
  }
137
300
  </style>
138
301
 
139
- <div class="card">
140
- <div class="card-header">
141
- <oda-icon :icon="$item?.icon || 'odant:structure'" icon-size="24"></oda-icon>
142
- <span>{{$item?.label || $item?.id}} — Руководство подразделения</span>
302
+ <div class="tree-box">
303
+ <!-- Корень дерева: BOSS подразделения -->
304
+ <div class="root-row" ~class="{ 'drop-hover': bossDropHover }"
305
+ @dragover="onBossDragOver" @dragleave="bossDropHover = false" @drop="onBossDrop">
306
+ <oda-icon :icon="$item?.icon || 'odant:structure'" icon-size="20"></oda-icon>
307
+ <span class="root-title">{{$item?.label || $item?.id}}</span>
308
+ <span class="boss-label">Руководитель (BOSS):</span>
309
+
310
+ <div ~if="visibleCurrentBoss" class="chip" title="Открыть профиль" @tap="openUser(visibleCurrentBoss)">
311
+ <oda-icon round :icon="userIcon(visibleCurrentBoss)" :icon-color="userColor(visibleCurrentBoss)" icon-size="18"></oda-icon>
312
+ <span>{{userLabel(visibleCurrentBoss)}}</span>
313
+ <span ~if="canEdit" class="rm" title="Снять локального руководителя" @tap.stop="clearBoss()">×</span>
314
+ </div>
315
+
316
+ <div ~if="!visibleCurrentBoss && visibleInheritedBoss" class="chip inherited" title="Наследуется сверху" @tap="openUser(visibleInheritedBoss)">
317
+ <oda-icon round :icon="userIcon(visibleInheritedBoss)" :icon-color="userColor(visibleInheritedBoss)" icon-size="18"></oda-icon>
318
+ <span>{{userLabel(visibleInheritedBoss)}}</span>
319
+ <span class="muted">({{inheritedBossInfo.fromLabel}})</span>
320
+ </div>
321
+
322
+ <span ~if="!visibleCurrentBoss && !visibleInheritedBoss" class="muted">не назначен</span>
323
+
324
+ <div ~if="canEdit" class="row-actions">
325
+ <button type="button" class="icon-btn" @tap="toggleBossPicker()">
326
+ <oda-icon icon="editor:mode-edit" icon-size="14"></oda-icon>
327
+ <span>{{visibleCurrentBoss ? 'Сменить' : 'Назначить'}}</span>
328
+ </button>
329
+ <button type="button" class="icon-btn" @tap="openAddRole('')">
330
+ <oda-icon icon="icons:add" icon-size="15"></oda-icon>
331
+ <span>Роль</span>
332
+ </button>
333
+ </div>
143
334
  </div>
144
335
 
145
- <div class="role-row">
146
- <span class="role-title">Руководитель (BOSS):</span>
147
- <div class="user-chip clickable" ~for="bossList" title="Открыть диалог с руководителем" @tap="openUser($for.item)">
148
- <oda-icon round :icon="userIcon($for.item)" :icon-color="userColor($for.item)" icon-size="20"></oda-icon>
149
- <span>{{userLabel($for.item)}}</span>
150
- <span ~if="canEdit" class="rm" title="Снять руководителя" @tap.stop="removeRoleUser('BOSS', $for.item)">×</span>
336
+ <!-- Выбор руководителя -->
337
+ <div ~if="canEdit && bossPickerOpen" class="inline-panel">
338
+ <div class="horizontal" style="gap:8px;align-items:center;">
339
+ <input type="text" placeholder="Поиск сотрудника…" ::value="bossSearch" style="flex:1;">
340
+ <oda-button ~if="currentBoss" @tap="clearBoss()">Наследовать сверху</oda-button>
341
+ <oda-button icon="icons:close" @tap="bossPickerOpen = false">Закрыть</oda-button>
151
342
  </div>
152
- <span ~if="!bossList.length && !inheritedBossInfo?.users?.length" class="muted">не назначен (наследуется сверху)</span>
153
- <span ~if="!bossList.length && inheritedBossInfo?.users?.length" class="muted">не назначен — наследуется от «{{inheritedBossInfo.fromLabel}}»:</span>
154
- <div ~if="!bossList.length && inheritedBossInfo?.users?.length" class="user-chip clickable" style="opacity:0.85;" ~for="inheritedBossInfo.users" title="Наследуемый руководитель (открыть диалог)" @tap="openUser($for.item)">
155
- <oda-icon round :icon="userIcon($for.item)" :icon-color="userColor($for.item)" icon-size="20"></oda-icon>
156
- <span>{{userLabel($for.item)}}</span>
343
+ <div class="panel-list">
344
+ <div ~if="!filteredBossUsers.length" class="muted" style="padding:6px;">Пользователи не найдены</div>
345
+ <div class="panel-item" ~for="filteredBossUsers" @tap="pickBoss($for.item.id)">
346
+ <oda-icon round :icon="userIcon($for.item.id)" :icon-color="userColor($for.item.id)" icon-size="18"></oda-icon>
347
+ <span>{{$for.item.label}}</span>
348
+ </div>
157
349
  </div>
158
- <select ~if="canEdit" @change="addRoleUser('BOSS', $event)">
159
- <option value="">+ Назначить руководителя…</option>
160
- <option ~for="allUsers" :value="$for.item.id">{{$for.item.label}} ({{$for.item.id}})</option>
161
- </select>
162
350
  </div>
163
- </div>
164
351
 
165
- <div class="card">
166
- <div class="card-header">
167
- <oda-icon icon="odant:workplace" icon-size="22"></oda-icon>
168
- <span>Рабочие места подразделения ({{flatPlaces.length}})</span>
169
- <div ~if="canEdit" class="horizontal" style="margin-left:auto;gap:8px;align-items:center;">
170
- <label class="ext-toggle" title="Внешний клиент (CLIENT) без доступа к внутренним файлам и чату отдела">
171
- <input type="checkbox" :checked="newPlaceExternal" @change="newPlaceExternal = $event.target.checked">
172
- <span>Клиент</span>
173
- </label>
174
- <input type="text" placeholder="Название нового рабочего места…" :value="newPlaceLabel" @input="newPlaceLabel = $event.target.value" style="width:220px;">
175
- <oda-button icon="icons:add" @tap="addPlace('')">Добавить место</oda-button>
352
+ <!-- Добавление корневой роли -->
353
+ <div ~if="canEdit && addingRoleParent === ''" class="inline-panel">
354
+ <div class="horizontal" style="gap:8px;align-items:center;">
355
+ <input type="text" placeholder="Название новой роли…" ::value="newRoleLabel" style="flex:1;" @keydown="onNewRoleKey($event)">
356
+ <oda-button icon="icons:check" info-invert @tap="confirmAddRole()">Добавить</oda-button>
357
+ <oda-button icon="icons:close" @tap="cancelAddRole()">Отмена</oda-button>
176
358
  </div>
177
359
  </div>
178
360
 
179
- <div ~if="!flatPlaces.length" class="muted">В этом подразделении ещё нет рабочих мест.</div>
361
+ <div ~if="!treeRows.length" class="muted" style="padding:16px;">Ролей пока нет</div>
362
+
363
+ <!-- Единое дерево ролей и классов -->
364
+ <div ~for="treeRows" style="display:contents;">
365
+ <!-- Строка роли -->
366
+ <div ~if="$for.item.kind === 'role'" class="tree-row role-row"
367
+ ~class="{ 'drop-hover': dropHoverTrail === $for.item.trail }"
368
+ :style="'padding-left:' + (12 + $for.item.depth * 24) + 'px'"
369
+ @dragover="onRoleDragOver($event, $for.item.trail)"
370
+ @dragleave="onRoleDragLeave($for.item.trail)"
371
+ @drop="onRoleDrop($event, $for.item.trail)">
180
372
 
181
- <div ~for="flatPlaces" class="place-card" ~class="{'active-place': focusedTrail === $for.item.trail || $for.item.mine}" :style="'margin-left:' + ($for.item.depth * 24) + 'px'">
182
- <div class="card-header">
183
- <oda-icon :icon="$for.item.external ? 'icons:public' : 'fontawesome:s-user-tie'" icon-size="20"></oda-icon>
184
- <span>{{$for.item.node.label || $for.item.node.id}}</span>
185
- <span class="muted">({{$for.item.trail}})</span>
186
- <span ~if="$for.item.mine" class="badge">Ваше место</span>
187
- <span ~if="$for.item.external" class="badge external" title="Внешний клиент: только клиентские ссылки без внутренних файлов и чата">Клиент</span>
188
- <div ~if="canEdit" class="horizontal" style="margin-left:auto;gap:6px;align-items:center;">
189
- <label class="ext-toggle" title="Пометить место как контур внешнего клиента (CLIENT)">
190
- <input type="checkbox" :checked="$for.item.external" @change="togglePlaceExternal($for.item.trail, $event.target.checked)">
191
- <span>Клиент</span>
192
- </label>
193
- <oda-button icon="icons:send" title="Пригласить сотрудника по ссылке, Email, Telegram или MAX" @tap="openInvite($for.item.trail)">Пригласить</oda-button>
194
- <oda-button icon="icons:add" title="Добавить подчинённое рабочее место" @tap="promptSubPlace($for.item.trail)">Подчинённое место</oda-button>
195
- <oda-button icon="icons:delete" title="Удалить рабочее место" @tap="removePlace($for.item.trail)"></oda-button>
373
+ <span class="expander" @tap="toggleRoleExpand($for.item.trail)">
374
+ {{$for.item.hasChildren ? ($for.item.expanded ? '▾' : '▸') : ''}}
375
+ </span>
376
+ <oda-icon :icon="$for.item.external ? 'icons:public' : 'fontawesome:s-user-tie'" icon-size="16"></oda-icon>
377
+ <span class="role-name">{{$for.item.label}}</span>
378
+ <span ~if="$for.item.external" class="badge ext">клиент</span>
379
+ <span ~if="$for.item.mine" class="badge">ваша роль</span>
380
+
381
+ <div class="members-wrap">
382
+ <div class="chip" ~for="$for.item.memberEntries"
383
+ ~class="{ 'node-chip': $for.$for.item.isNode }"
384
+ @tap="openMember($for.$for.item)">
385
+ <oda-icon :round="!$for.$for.item.isNode && !$for.$for.item.isGroup" :icon="$for.$for.item.icon" :icon-color="$for.$for.item.iconColor" icon-size="16"></oda-icon>
386
+ <span>{{$for.$for.item.label}}</span>
387
+ <span ~if="canEdit" class="rm" title="Убрать из роли" @tap.stop="removeRoleMember($for.item.trail, $for.$for.item.id)">×</span>
388
+ </div>
389
+ <button ~if="canEdit" type="button" class="icon-btn" title="Добавить участника (человека или подразделение)" @tap="toggleMemberPicker($for.item.trail)">
390
+ <oda-icon icon="icons:add" icon-size="14"></oda-icon>
391
+ </button>
196
392
  </div>
197
- </div>
198
393
 
199
- <div ~if="canEdit && inviteTrail === $for.item.trail" class="card" style="padding:10px 12px;gap:8px;background:var(--subtle-background);">
200
- <div class="role-row">
201
- <span class="role-title">Канал приглашения:</span>
202
- <select ::value="inviteChannel">
203
- <option value="link">🔗 Одноразовая ссылка</option>
204
- <option value="email">✉️ Email (почта)</option>
205
- <option value="telegram">✈️ Telegram</option>
206
- <option value="max">💬 Мессенджер MAX</option>
207
- </select>
208
- <input ~if="inviteChannel === 'email'" type="text" placeholder="Email сотрудника (name@company.ru)…" ::value="inviteRecipient" style="flex:1;min-width:200px;">
209
- <input ~if="inviteChannel === 'telegram' || inviteChannel === 'max'" type="text" placeholder="Chat ID (для отправки ботом) или имя для заметки…" ::value="inviteRecipient" style="flex:1;min-width:200px;">
210
- <input type="text" placeholder="Комментарий (опционально)" ::value="inviteNote" style="width:180px;">
211
- <oda-button icon="icons:check" :disabled="inviteBusy" @tap="sendInvite()">{{inviteBusy ? 'Отправка…' : 'Создать'}}</oda-button>
212
- <oda-button icon="icons:close" @tap="(inviteTrail = '', inviteResult = null)">Закрыть</oda-button>
394
+ <div ~if="canEdit" class="row-actions">
395
+ <button type="button" class="icon-btn" title="Привязать классы" @tap="toggleClassPicker($for.item.trail)">
396
+ <oda-icon icon="icons:add" icon-size="14"></oda-icon>
397
+ <span>Класс</span>
398
+ </button>
399
+ <button type="button" class="icon-btn" title="Добавить дочернюю роль" @tap="openAddRole($for.item.trail)">
400
+ <oda-icon icon="icons:add" icon-size="14"></oda-icon>
401
+ <span>Подроль</span>
402
+ </button>
403
+ <button type="button" class="icon-btn" ~class="{ active: $for.item.external }" title="Режим внешнего клиента (CLIENT)" @tap="toggleRoleExternal($for.item.trail, !$for.item.external)">
404
+ <oda-icon icon="icons:public" icon-size="14"></oda-icon>
405
+ </button>
406
+ <button type="button" class="icon-btn danger" title="Удалить роль" @tap="removeRole($for.item.trail)">
407
+ <oda-icon icon="icons:delete" icon-size="14"></oda-icon>
408
+ </button>
213
409
  </div>
214
- <div ~if="inviteResult" class="role-row" style="gap:8px;flex-wrap:wrap;">
215
- <input type="text" readonly :value="inviteResult.url" style="flex:1;min-width:260px;font-family:monospace;font-size:12px;">
216
- <oda-button icon="icons:content-copy" @tap="copyText(inviteResult.url)">Копировать ссылку</oda-button>
217
- <a ~if="inviteResult.shareUrl" :href="inviteResult.shareUrl" target="_blank" rel="noopener" style="font-size:13px;color:var(--accent-color);text-decoration:none;font-weight:600;">Отправить в Telegram ↗</a>
218
- <span ~if="inviteResult.sent" style="color:var(--success-color, #15803d);font-size:13px;font-weight:600;">✓ Отправлено ({{inviteResult.sentVia}})</span>
219
- <span ~if="inviteResult.warning" class="muted" style="color:#b45309;">{{inviteResult.warning}}</span>
410
+ </div>
411
+
412
+ <!-- Инлайн-добавление дочерней роли -->
413
+ <div ~if="$for.item.kind === 'role' && canEdit && addingRoleParent === $for.item.trail"
414
+ class="inline-panel" :style="'padding-left:' + (36 + $for.item.depth * 24) + 'px'">
415
+ <div class="horizontal" style="gap:8px;align-items:center;">
416
+ <input type="text" placeholder="Название дочерней роли…" ::value="newRoleLabel" style="flex:1;" @keydown="onNewRoleKey($event)">
417
+ <oda-button icon="icons:check" info-invert @tap="confirmAddRole()">Добавить</oda-button>
418
+ <oda-button icon="icons:close" @tap="cancelAddRole()">Отмена</oda-button>
220
419
  </div>
221
420
  </div>
222
421
 
223
- <div class="role-row">
224
- <span class="role-title">Сотрудники места:</span>
225
- <div class="user-chip clickable" ~for="$for.item.users" title="Открыть диалог с пользователем" @tap="openUser($for.$for.item)">
226
- <oda-icon icon="icons:person" icon-size="14"></oda-icon>
227
- <span>{{userLabel($for.$for.item)}}</span>
228
- <span ~if="canEdit" class="rm" title="Снять с рабочего места" @tap.stop="removePlaceUser($for.item.trail, $for.$for.item)">×</span>
422
+ <!-- Инлайн-выбор участника (сотрудники / подразделения) -->
423
+ <div ~if="$for.item.kind === 'role' && canEdit && memberPickerTrail === $for.item.trail"
424
+ class="inline-panel" :style="'padding-left:' + (36 + $for.item.depth * 24) + 'px'">
425
+ <div class="horizontal" style="gap:8px;align-items:center;">
426
+ <input type="text" placeholder="Поиск человека или подразделения…" ::value="memberSearch" style="flex:1;">
427
+ <oda-button icon="icons:close" @tap="closeMemberPicker()">Закрыть</oda-button>
428
+ </div>
429
+ <div class="panel-list">
430
+ <div class="panel-item" ~for="filteredUsers" @tap="pickMember($for.item.trail, $for.$for.item.id)">
431
+ <oda-icon round :icon="userIcon($for.$for.item.id)" :icon-color="userColor($for.$for.item.id)" icon-size="18"></oda-icon>
432
+ <span>{{$for.$for.item.label}}</span>
433
+ </div>
434
+ <div class="panel-item" ~for="filteredStructures" @tap="pickMember($for.item.trail, $for.$for.item.path)">
435
+ <oda-icon :icon="$for.$for.item.icon || 'odant:structure'" icon-size="18"></oda-icon>
436
+ <span>{{$for.$for.item.label}}</span>
437
+ <span class="muted">подразделение</span>
438
+ </div>
439
+ <div class="panel-item" @tap="pickMember($for.item.trail, 'USERS')">
440
+ <oda-icon icon="social:people" icon-size="18"></oda-icon>
441
+ <span>Все сотрудники</span>
442
+ </div>
443
+ <div class="panel-item" @tap="pickMember($for.item.trail, 'GUESTS')">
444
+ <oda-icon icon="icons:public" icon-size="18"></oda-icon>
445
+ <span>Все гости</span>
446
+ </div>
229
447
  </div>
230
- <span ~if="!$for.item.users.length" class="muted">сотрудники не назначены</span>
231
- <select ~if="canEdit" @change="addPlaceUser($for.item.trail, $event)">
232
- <option value="">+ Назначить сотрудника…</option>
233
- <option value="USERS">👥 Все пользователи (USERS)</option>
234
- <option value="GUESTS">🌐 Все гости (GUESTS)</option>
235
- <option ~for="allUsers" :value="$for.$for.item.id">{{$for.$for.item.label}} ({{$for.$for.item.id}})</option>
236
- </select>
237
448
  </div>
238
449
 
239
- <div class="links-box">
240
- <div class="role-row">
241
- <span class="role-title">Привязанные классы ({{$for.item.links.length}}):</span>
242
- <select ~if="canEdit && availableClasses.length" @change="addPlaceLink($for.item.trail, $event)" style="max-width:340px;">
243
- <option value="">+ Привязать учётный класс…</option>
244
- <option ~for="availableClasses" :value="$for.$for.item.path">{{$for.$for.item.title}} ({{$for.$for.item.shortPath}})</option>
245
- </select>
450
+ <!-- Инлайн-дерево выбора классов -->
451
+ <div ~if="$for.item.kind === 'role' && canEdit && pickerTrail === $for.item.trail"
452
+ class="inline-panel" :style="'padding-left:' + (36 + $for.item.depth * 24) + 'px'">
453
+ <div class="horizontal" style="gap:8px;align-items:center;">
454
+ <input type="text" placeholder="Поиск класса…" ::value="classSearch" style="flex:1;">
455
+ <oda-button icon="icons:check" info-invert :disabled="!selectedPickerCount" @tap="applyClassPicker($for.item.trail)">
456
+ Добавить ({{selectedPickerCount}})
457
+ </oda-button>
458
+ <oda-button icon="icons:close" @tap="closeClassPicker()">Закрыть</oda-button>
246
459
  </div>
247
- <div class="link-row" ~for="$for.item.links">
248
- <oda-icon icon="odant:class" icon-size="16"></oda-icon>
249
- <span class="link-title" title="Открыть класс" @tap="openClass($for.$for.item.id)">{{classTitle($for.$for.item.id)}}</span>
250
- <select :disabled="!canEdit" @change="updatePlaceLinkAccess($for.item.trail, $for.$for.item.id, $event.target.value)">
251
- <option value="read" :selected="$for.$for.item.access === 'read'">Чтение (R)</option>
252
- <option value="write" :selected="$for.$for.item.access === 'write'">Запись (A)</option>
253
- </select>
254
- <select :disabled="!canEdit" @change="updatePlaceLinkScope($for.item.trail, $for.$for.item.id, $event.target.value)">
255
- <option value="" :selected="!$for.$for.item.scope">По умолчанию</option>
256
- <option value="own" :selected="$for.$for.item.scope === 'own'">Свои (own)</option>
257
- <option value="place" :selected="$for.$for.item.scope === 'place'">Место (place)</option>
258
- <option value="unit" :selected="$for.$for.item.scope === 'unit'">Подразделение (unit)</option>
259
- <option value="all" :selected="$for.$for.item.scope === 'all'">Все (all)</option>
260
- </select>
261
- <span ~if="canEdit" style="cursor:pointer;color:#b91c1c;font-weight:bold;padding:0 4px;" title="Отвязать класс" @tap="removePlaceLink($for.item.trail, $for.$for.item.id)">×</span>
460
+ <div class="panel-list">
461
+ <div ~if="!visibleClassNodes.length" class="muted" style="padding:6px;">Классы не найдены</div>
462
+ <div class="panel-item" ~for="visibleClassNodes" :style="'padding-left:' + (6 + $for.$for.item.depth * 18) + 'px'">
463
+ <span ~if="$for.$for.item.hasChildren" style="width:14px;text-align:center;font-weight:700;" @tap.stop="toggleClassExpand($for.$for.item.path)">
464
+ {{$for.$for.item.expanded ? '▾' : '▸'}}
465
+ </span>
466
+ <span ~if="!$for.$for.item.hasChildren" style="width:14px;"></span>
467
+ <input ~if="$for.$for.item.selectable" type="checkbox" :checked="$for.$for.item.checked" @change="togglePickerCheck($for.$for.item.path, $event.target.checked)">
468
+ <oda-icon :icon="$for.$for.item.icon" icon-size="16"></oda-icon>
469
+ <span style="flex:1;" @tap="onPickerLabelTap($for.$for.item)">{{$for.$for.item.label}}</span>
470
+ </div>
262
471
  </div>
263
472
  </div>
264
- </div>
265
- </div>
266
- <div ~if="canEdit && invitesList.length" class="card">
267
- <div class="card-header">
268
- <oda-icon icon="icons:send" icon-size="20"></oda-icon>
269
- <span>Приглашения ({{invitesList.length}})</span>
270
- </div>
271
- <div class="link-row" ~for="invitesList" style="justify-content:space-between;flex-wrap:wrap;">
272
- <span><b>{{$for.item.placeLabel}}</b> · {{$for.item.channel}}{{$for.item.recipient ? ' (' + $for.item.recipient + ')' : ''}}</span>
273
- <span class="muted">Статус: {{inviteStatusLabel($for.item.effectiveStatus)}}</span>
274
- <div class="horizontal" style="gap:6px;">
275
- <oda-button ~if="$for.item.effectiveStatus === 'active'" icon="icons:content-copy" @tap="copyText(inviteLinkOf($for.item.token))">Ссылка</oda-button>
276
- <oda-button ~if="$for.item.effectiveStatus === 'active'" icon="icons:close" @tap="revokeInvite($for.item.id)">Отозвать</oda-button>
473
+
474
+ <!-- Строка привязанного класса внутри роли -->
475
+ <div ~if="$for.item.kind === 'class'" class="tree-row class-row"
476
+ :style="'padding-left:' + (28 + $for.item.depth * 24) + 'px'">
477
+ <oda-icon :icon="$for.item.icon" icon-size="15"></oda-icon>
478
+ <span class="class-title" :title="$for.item.id" @tap="openClass($for.item.id)">{{$for.item.title}}</span>
479
+ <span ~if="$for.item.section" class="class-section">{{$for.item.section}}</span>
480
+ <label class="write-check" title="Разрешить создание и изменение записей">
481
+ <input type="checkbox" :checked="$for.item.isWrite" :disabled="!canEdit"
482
+ @change="updateRoleLinkAccess($for.item.trail, $for.item.id, $event.target.checked ? 'write' : 'read')">
483
+ <span>Изменение</span>
484
+ </label>
485
+ <button ~if="canEdit" type="button" class="icon-btn danger" title="Отвязать класс" @tap="removeRoleLink($for.item.trail, $for.item.id)">×</button>
277
486
  </div>
278
487
  </div>
279
488
  </div>
280
- <oda-messenger-settings ~if="canEdit" :$item="$item" :can-edit="canEdit" :user-map="userMap"></oda-messenger-settings>
281
- <div ~if="error" style="color:var(--error-color, #c00);">{{error}}</div>
489
+
490
+ <div ~if="error" style="color:var(--error-color, #dc2626);font-size:12.5px;">{{error}}</div>
282
491
  `,
492
+ $item: {
493
+ $def: null,
494
+ set(n) {
495
+ if (n)
496
+ this.reload();
497
+ }
498
+ },
283
499
  security: null,
284
500
  allUsers: [],
285
501
  userMap: {},
286
502
  userMetaMap: {},
503
+ availableStructures: [],
504
+ structureMap: {},
287
505
  inheritedBossInfo: null,
288
- availableClasses: [],
506
+ classTreeRoots: [],
289
507
  classMap: {},
290
508
  canEdit: false,
291
509
  focusedTrail: '',
292
- newPlaceLabel: '',
293
- newPlaceExternal: false,
294
- inviteTrail: '',
295
- inviteChannel: 'link',
296
- inviteRecipient: '',
297
- inviteNote: '',
298
- inviteBusy: false,
299
- inviteResult: null,
300
- invitesList: [],
510
+ expandedRoles: {},
511
+ bossPickerOpen: false,
512
+ bossSearch: '',
513
+ addingRoleParent: null,
514
+ newRoleLabel: '',
515
+ memberPickerTrail: '',
516
+ memberSearch: '',
517
+ pickerTrail: '',
518
+ classSearch: '',
519
+ expandedClassPaths: {},
520
+ pickerChecked: {},
521
+ bossDropHover: false,
522
+ dropHoverTrail: '',
301
523
  error: '',
302
524
  async attached() {
303
- await this.reload();
525
+ if (this.$item)
526
+ await this.reload();
304
527
  },
305
528
  async applyNav(nav = {}) {
306
529
  if (nav.place)
307
530
  this.focusedTrail = String(nav.place);
308
531
  await this.reload();
309
532
  },
310
- get bossList() {
311
- return Array.isArray(this.security?.BOSS) ? this.security.BOSS : [];
533
+ get currentBoss() {
534
+ const list = Array.isArray(this.security?.BOSS) ? this.security.BOSS : [];
535
+ return list[0] || '';
312
536
  },
313
- get flatPlaces() {
314
- const out = [];
537
+ get visibleCurrentBoss() {
538
+ const id = this.currentBoss;
539
+ if (!id)
540
+ return '';
541
+ return this.userMap?.[id] ? id : '';
542
+ },
543
+ get visibleInheritedBoss() {
544
+ const id = this.inheritedBossInfo?.users?.[0] || '';
545
+ if (!id)
546
+ return '';
547
+ return this.userMap?.[id] ? id : '';
548
+ },
549
+ get filteredBossUsers() {
550
+ const q = String(this.bossSearch || '').trim().toLowerCase();
551
+ return (this.allUsers || []).filter(u =>
552
+ !q || u.label.toLowerCase().includes(q)
553
+ );
554
+ },
555
+ get filteredUsers() {
556
+ const q = String(this.memberSearch || '').trim().toLowerCase();
557
+ if (!q)
558
+ return this.allUsers || [];
559
+ return (this.allUsers || []).filter(u => u.label.toLowerCase().includes(q));
560
+ },
561
+ get filteredStructures() {
562
+ const q = String(this.memberSearch || '').trim().toLowerCase();
563
+ if (!q)
564
+ return this.availableStructures || [];
565
+ return (this.availableStructures || []).filter(s => String(s.label || '').toLowerCase().includes(q));
566
+ },
567
+ get treeRows() {
568
+ const rows = [];
315
569
  const walk = (roles, prefix = '', depth = 0) => {
316
570
  for (const r of Array.isArray(roles) ? roles : []) {
317
571
  if (!r?.id)
318
572
  continue;
319
573
  const trail = prefix ? `${prefix}/${r.id}` : r.id;
320
- out.push({
574
+ const links = Array.isArray(r.LINKS) ? r.LINKS : [];
575
+ const childRoles = Array.isArray(r.ROLES) ? r.ROLES : [];
576
+ const hasChildren = links.length > 0 || childRoles.length > 0;
577
+ const expanded = this.expandedRoles?.[trail] !== false;
578
+
579
+ const memberEntries = [];
580
+ for (const id of Array.isArray(r.USERS) ? r.USERS : []) {
581
+ if (typeof id === 'string' && id.startsWith('/')) {
582
+ const st = this.structureMap?.[id];
583
+ if (!st && !Object.keys(this.structureMap || {}).length) {
584
+ memberEntries.push({
585
+ id,
586
+ isNode: true,
587
+ isGroup: false,
588
+ label: id.split('/').pop() || id,
589
+ icon: 'odant:structure',
590
+ iconColor: '',
591
+ });
592
+ }
593
+ else if (st) {
594
+ memberEntries.push({
595
+ id,
596
+ isNode: true,
597
+ isGroup: false,
598
+ label: st.label || id.split('/').pop() || id,
599
+ icon: st.icon || 'odant:structure',
600
+ iconColor: '',
601
+ });
602
+ }
603
+ }
604
+ else if (id === 'USERS' || id === 'GUESTS' || id === 'GUEST') {
605
+ memberEntries.push({
606
+ id,
607
+ isNode: false,
608
+ isGroup: true,
609
+ label: id === 'USERS' ? 'Все сотрудники' : 'Все гости',
610
+ icon: id === 'USERS' ? 'social:people' : 'icons:public',
611
+ iconColor: '',
612
+ });
613
+ }
614
+ else if (this.userMap?.[id]) {
615
+ memberEntries.push({
616
+ id,
617
+ isNode: false,
618
+ isGroup: false,
619
+ label: this.userLabel(id),
620
+ icon: this.userIcon(id),
621
+ iconColor: this.userColor(id),
622
+ });
623
+ }
624
+ }
625
+
626
+ rows.push({
627
+ kind: 'role',
321
628
  trail,
629
+ id: r.id,
630
+ label: r.label || r.id,
322
631
  depth,
323
- node: r,
324
- mine: Boolean(r.mine),
632
+ hasChildren,
633
+ expanded,
325
634
  external: Boolean(r.external),
326
- users: Array.isArray(r.USERS) ? [...r.USERS] : [],
327
- links: Array.isArray(r.LINKS) ? [...r.LINKS] : [],
635
+ mine: Boolean(r.mine),
636
+ memberEntries,
328
637
  });
329
- if (Array.isArray(r.ROLES) && r.ROLES.length)
330
- walk(r.ROLES, trail, depth + 1);
638
+
639
+ if (expanded) {
640
+ for (const l of links) {
641
+ if (!l?.id)
642
+ continue;
643
+ const info = splitClassTitle(l.id, this.classMap?.[l.id]);
644
+ rows.push({
645
+ kind: 'class',
646
+ trail,
647
+ id: l.id,
648
+ depth,
649
+ title: info.title,
650
+ section: info.section,
651
+ icon: info.icon || 'odant:class',
652
+ isWrite: l.access === 'write',
653
+ });
654
+ }
655
+ if (childRoles.length)
656
+ walk(childRoles, trail, depth + 1);
657
+ }
331
658
  }
332
659
  };
333
- walk(this.security?.ROLES || []);
660
+ walk(this.security?.ROLES || [], '', 0);
661
+ return rows;
662
+ },
663
+ get selectedPickerCount() {
664
+ return Object.keys(this.pickerChecked || {}).filter(k => this.pickerChecked[k]).length;
665
+ },
666
+ get visibleClassNodes() {
667
+ const q = String(this.classSearch || '').trim().toLowerCase();
668
+ const out = [];
669
+ const matchSubtree = (node) => {
670
+ const selfMatch = String(node.label || '').toLowerCase().includes(q);
671
+ const kids = Array.isArray(node.children) ? node.children : [];
672
+ if (!q)
673
+ return { match: true };
674
+ return { match: selfMatch || kids.some(k => matchSubtree(k).match) };
675
+ };
676
+ const walk = (nodes, depth = 0) => {
677
+ for (const n of Array.isArray(nodes) ? nodes : []) {
678
+ const kids = Array.isArray(n.children) ? n.children : [];
679
+ if (!matchSubtree(n).match)
680
+ continue;
681
+ const expanded = q ? true : Boolean(this.expandedClassPaths?.[n.path] ?? (depth === 0));
682
+ out.push({
683
+ path: n.path,
684
+ label: n.label,
685
+ depth,
686
+ icon: n.icon || 'odant:class',
687
+ selectable: Boolean(n.selectable),
688
+ hasChildren: kids.length > 0,
689
+ expanded,
690
+ checked: Boolean(this.pickerChecked?.[n.path]),
691
+ });
692
+ if (kids.length && expanded)
693
+ walk(kids, depth + 1);
694
+ }
695
+ };
696
+ walk(this.classTreeRoots || [], 0);
334
697
  return out;
335
698
  },
336
699
  userLabel(uid) {
337
- if (uid === 'USERS')
338
- return '👥 Все пользователи (USERS)';
339
- if (uid === 'GUESTS' || uid === 'GUEST')
340
- return '🌐 Все гости (GUESTS)';
341
700
  return this.userMap?.[uid] || uid;
342
701
  },
343
702
  userIcon(uid) {
@@ -355,19 +714,20 @@ export default {
355
714
  return meta?.iconColor || '#3b82f6';
356
715
  return '';
357
716
  },
358
- classTitle(path) {
359
- return this.classMap?.[path] || String(path || '').replace(/^\/(?:ORGANIZATIONS|PROJECTS)\/[^/]+\/MODULES\/[^/]+\//, '');
360
- },
361
717
  async reload() {
362
718
  this.error = '';
363
719
  if (!this.$item)
364
720
  return;
365
721
  try {
366
- this.canEdit = !!(WORK?.DEV_MODE || await this.$item.isAdmin);
722
+ this.canEdit = !!(WORK?.DEV_MODE || await (this.$item.isBoss ?? this.$item.isAdmin));
367
723
  if (this.canEdit) {
368
724
  const body = await this.$item.body;
369
725
  this.security = JSON.parse(JSON.stringify(body?.['#security'] || {}));
370
- await Promise.all([this.loadUsers(), this.loadAvailableClasses(), this.loadInvites()]);
726
+ await Promise.all([
727
+ this.loadUsers(),
728
+ this.loadAvailableClasses(),
729
+ this.loadAvailableStructures(),
730
+ ]);
371
731
  }
372
732
  else {
373
733
  const [bossList, placesRes] = await Promise.all([
@@ -382,15 +742,15 @@ export default {
382
742
  ...(p.external ? { external: true } : {}),
383
743
  ...(p.mine ? { mine: true } : {}),
384
744
  USERS: Array.isArray(p.users) ? p.users : [],
385
- LINKS: Array.isArray(p.links) ? p.links.map(l => ({ id: l.id, access: l.access || 'read', scope: l.scope || '' })) : [],
745
+ LINKS: Array.isArray(p.links) ? p.links.map(l => ({ id: l.id, access: l.access || 'read', ...(l.scope ? { scope: l.scope } : {}) })) : [],
386
746
  ROLES: toRoles(p.roles),
387
747
  }));
388
748
  this.security = {
389
- BOSS: Array.isArray(bossList) ? bossList.map(u => u?.id || u).filter(Boolean) : [],
749
+ BOSS: Array.isArray(bossList) ? bossList.map(u => u?.id || u).filter(Boolean).slice(0, 1) : [],
390
750
  ROLES: toRoles(placesRes?.places),
391
751
  };
392
- this.availableClasses = [];
393
- this.invitesList = [];
752
+ this.classTreeRoots = [];
753
+ this.availableStructures = [];
394
754
  }
395
755
  await this.loadInheritedBoss();
396
756
  }
@@ -398,22 +758,6 @@ export default {
398
758
  this.error = String(e?.message || e);
399
759
  }
400
760
  },
401
- async openUser(uid) {
402
- if (!uid || uid === 'USERS' || uid === 'GUESTS' || uid === 'GUEST')
403
- return;
404
- if (typeof window?.execute !== 'function')
405
- return;
406
- const target = await WORK.get_item(`/USERS/${uid}`).catch(() => null);
407
- if (target)
408
- window.execute(target);
409
- },
410
- async openClass(clsPath) {
411
- if (!clsPath || typeof window?.execute !== 'function')
412
- return;
413
- const target = await WORK.get_item(clsPath).catch(() => null);
414
- if (target)
415
- window.execute(target);
416
- },
417
761
  async loadUsers() {
418
762
  try {
419
763
  const uRoot = (await WORK.get_item('/USERS')) || (await WORK.get_item('/users'));
@@ -439,8 +783,26 @@ export default {
439
783
  }
440
784
  catch { /* ignore */ }
441
785
  },
786
+ async loadAvailableStructures() {
787
+ if (!this.$item?.fetch)
788
+ return;
789
+ try {
790
+ const res = await this.$item.fetch('agent_structures_list');
791
+ const list = Array.isArray(res?.structures) ? res.structures : [];
792
+ const map = {};
793
+ for (const s of list) {
794
+ if (s?.path)
795
+ map[s.path] = s;
796
+ }
797
+ this.availableStructures = list;
798
+ this.structureMap = map;
799
+ }
800
+ catch {
801
+ this.availableStructures = [];
802
+ }
803
+ },
442
804
  async loadInheritedBoss() {
443
- if (this.bossList.length || !this.$item?.path) {
805
+ if (this.currentBoss || !this.$item?.path) {
444
806
  this.inheritedBossInfo = null;
445
807
  return;
446
808
  }
@@ -460,7 +822,7 @@ export default {
460
822
  this.inheritedBossInfo = {
461
823
  fromPath: pPath,
462
824
  fromLabel: anc.label || anc.DATA?.label || anc.id || (pPath === '/' ? 'WORK' : pPath),
463
- users: ids,
825
+ users: ids.slice(0, 1),
464
826
  };
465
827
  return;
466
828
  }
@@ -471,45 +833,46 @@ export default {
471
833
  },
472
834
  async loadAvailableClasses() {
473
835
  try {
474
- const p = String(this.$item?.path || '');
475
- const m = /^(\/(?:ORGANIZATIONS|PROJECTS)\/[^/]+)/.exec(p);
476
- const basePath = m ? m[1] : '';
477
- if (!basePath)
478
- return;
479
- const modRoot = await WORK.get_item(basePath + '/MODULES/Register');
480
- if (!modRoot?.fetch)
481
- return;
482
- const info = await WORK.fetch(location.origin + basePath + '/MODULES/Register', 'info', { deep: 4, branch: 'classes' });
483
- const list = [];
836
+ const res = this.$item?.fetch ? await this.$item.fetch('agent_available_classes').catch(() => null) : null;
837
+ const roots = Array.isArray(res?.roots) ? res.roots : [];
484
838
  const map = {};
485
- const prefix = basePath + '/MODULES/Register/';
486
- const visit = (nodes) => {
839
+ const indexNodes = (nodes) => {
487
840
  for (const n of Array.isArray(nodes) ? nodes : []) {
488
- if (!n?.path || !n.id || n.id[0] === '$')
489
- continue;
490
- if (['$catalog', '$virtual', '$operation', '$register', '$account'].includes(n.type)) {
491
- const shortPath = n.path.startsWith(prefix) ? n.path.slice(prefix.length) : n.path;
492
- const title = n.label || n.id;
493
- list.push({ path: n.path, title, shortPath });
494
- map[n.path] = `${title} (${shortPath})`;
841
+ if (n?.path && n.selectable) {
842
+ const base = splitClassTitle(n.shortPath || n.path);
843
+ map[n.path] = {
844
+ title: n.label || base.title,
845
+ section: base.section,
846
+ icon: n.icon || 'odant:class',
847
+ };
495
848
  }
496
- if (Array.isArray(n.items))
497
- visit(n.items);
849
+ if (Array.isArray(n?.children))
850
+ indexNodes(n.children);
498
851
  }
499
852
  };
500
- visit(info?.items || []);
501
- this.availableClasses = list;
853
+ indexNodes(roots);
854
+ this.classTreeRoots = roots;
502
855
  this.classMap = map;
503
856
  }
504
857
  catch { /* ignore */ }
505
858
  },
506
- async persist(nextSec) {
859
+ async persist(nextSec, auditTitle = '', auditSummary = '') {
507
860
  this.error = '';
508
861
  try {
509
- const body = await this.$item.body;
510
- body['#security'] = nextSec;
511
- await this.$item.save(body);
512
- this.security = JSON.parse(JSON.stringify(nextSec));
862
+ if (typeof this.$item?.fetch === 'function') {
863
+ const res = await this.$item.fetch('security_update', {}, JSON.stringify({
864
+ security: nextSec,
865
+ title: auditTitle || 'Обновлены права и роли подразделения',
866
+ summary: auditSummary || '',
867
+ }));
868
+ this.security = JSON.parse(JSON.stringify(res?.security || nextSec));
869
+ }
870
+ else {
871
+ const body = await this.$item.body;
872
+ body['#security'] = nextSec;
873
+ await this.$item.save(body);
874
+ this.security = JSON.parse(JSON.stringify(nextSec));
875
+ }
513
876
  this.$item.reset?.();
514
877
  this.$item.fire?.('changed', { value: null });
515
878
  await this.loadInheritedBoss();
@@ -525,32 +888,117 @@ export default {
525
888
  }
526
889
  }
527
890
  catch { /* ignore cross-origin */ }
528
- this.shadowRoot?.querySelector?.('oda-messenger-settings')?.reload?.();
529
891
  }
530
892
  catch (e) {
531
893
  this.error = String(e?.message || e);
532
894
  }
533
895
  },
534
- async addRoleUser(role, e) {
535
- const uid = e?.target?.value;
536
- if (e?.target)
537
- e.target.value = '';
538
- if (!uid)
896
+ async openUser(uid) {
897
+ if (!uid || uid === 'USERS' || uid === 'GUESTS' || uid === 'GUEST' || typeof window?.execute !== 'function')
539
898
  return;
540
- const sec = JSON.parse(JSON.stringify(this.security || {}));
541
- sec[role] = Array.isArray(sec[role]) ? sec[role] : [];
542
- if (!sec[role].includes(uid))
543
- sec[role].push(uid);
544
- await this.persist(sec);
899
+ const target = await WORK.get_item(`/USERS/${uid}`).catch(() => null);
900
+ if (target)
901
+ window.execute(target);
902
+ },
903
+ async openMember(entry) {
904
+ if (!entry || entry.isGroup || typeof window?.execute !== 'function')
905
+ return;
906
+ if (entry.isNode) {
907
+ const target = await WORK.get_item(entry.id).catch(() => null);
908
+ if (target)
909
+ window.execute(target);
910
+ return;
911
+ }
912
+ await this.openUser(entry.id);
913
+ },
914
+ async openClass(clsPath) {
915
+ if (!clsPath || typeof window?.execute !== 'function')
916
+ return;
917
+ const target = await WORK.get_item(clsPath).catch(() => null);
918
+ if (target)
919
+ window.execute(target);
545
920
  },
546
- async removeRoleUser(role, uid) {
921
+ toggleBossPicker() {
922
+ this.bossPickerOpen = !this.bossPickerOpen;
923
+ this.bossSearch = '';
924
+ },
925
+ async pickBoss(uid) {
926
+ this.bossPickerOpen = false;
927
+ await this.setBoss(uid);
928
+ },
929
+ async setBoss(uid) {
547
930
  const sec = JSON.parse(JSON.stringify(this.security || {}));
548
- if (!Array.isArray(sec[role]))
931
+ const cleanUid = String(uid || '').trim();
932
+ sec.BOSS = cleanUid ? [cleanUid] : [];
933
+ const label = cleanUid ? this.userLabel(cleanUid) : 'наследуется сверху';
934
+ await this.persist(sec, `Назначен руководитель: ${label}`, `В подразделении ${this.$item?.path || ''} руководитель (BOSS): ${label}.`);
935
+ },
936
+ async clearBoss() {
937
+ this.bossPickerOpen = false;
938
+ await this.setBoss('');
939
+ },
940
+ onBossDragOver(e) {
941
+ if (!this.canEdit)
549
942
  return;
550
- sec[role] = sec[role].filter(id => id !== uid);
551
- await this.persist(sec);
943
+ e.preventDefault();
944
+ if (e.dataTransfer)
945
+ e.dataTransfer.dropEffect = 'copy';
946
+ this.bossDropHover = true;
552
947
  },
553
- _findPlaceMut(sec, trail) {
948
+ async onBossDrop(e) {
949
+ this.bossDropHover = false;
950
+ if (!this.canEdit)
951
+ return;
952
+ e.preventDefault();
953
+ const dropped = parseDroppedItem(e);
954
+ if (!isDroppedUser(dropped)) {
955
+ this.error = 'Для назначения руководителя перетащите пользователя из дерева.';
956
+ return;
957
+ }
958
+ const uid = dropped.id || dropped.path.split('/').pop();
959
+ if (uid)
960
+ await this.setBoss(uid);
961
+ },
962
+ onRoleDragOver(e, trail) {
963
+ if (!this.canEdit)
964
+ return;
965
+ e.preventDefault();
966
+ if (e.dataTransfer)
967
+ e.dataTransfer.dropEffect = 'copy';
968
+ this.dropHoverTrail = trail;
969
+ },
970
+ onRoleDragLeave(trail) {
971
+ if (this.dropHoverTrail === trail)
972
+ this.dropHoverTrail = '';
973
+ },
974
+ async onRoleDrop(e, trail) {
975
+ this.dropHoverTrail = '';
976
+ if (!this.canEdit)
977
+ return;
978
+ e.preventDefault();
979
+ const dropped = parseDroppedItem(e);
980
+ if (!dropped)
981
+ return;
982
+ if (isDroppedUser(dropped)) {
983
+ const uid = dropped.id || dropped.path.split('/').pop();
984
+ if (uid)
985
+ await this._addMemberToRole(trail, uid);
986
+ return;
987
+ }
988
+ if (isDroppedStructure(dropped)) {
989
+ if (dropped.path && dropped.path !== this.$item?.path)
990
+ await this._addMemberToRole(trail, dropped.path);
991
+ return;
992
+ }
993
+ if (isDroppedClass(dropped) && dropped.path) {
994
+ await this._addLinksToRole(trail, [dropped.path]);
995
+ }
996
+ },
997
+ toggleRoleExpand(trail) {
998
+ const cur = this.expandedRoles?.[trail] !== false;
999
+ this.expandedRoles = { ...this.expandedRoles, [trail]: !cur };
1000
+ },
1001
+ _findRoleMut(sec, trail) {
554
1002
  const steps = String(trail || '').split('/').filter(Boolean);
555
1003
  let list = Array.isArray(sec.ROLES) ? sec.ROLES : [];
556
1004
  let node = null;
@@ -562,55 +1010,50 @@ export default {
562
1010
  }
563
1011
  return node;
564
1012
  },
565
- async addPlace(parentTrail = '', customLabel = '') {
566
- const label = String(customLabel || this.newPlaceLabel || '').trim();
1013
+ openAddRole(parentTrail = '') {
1014
+ this.addingRoleParent = this.addingRoleParent === parentTrail ? null : parentTrail;
1015
+ this.newRoleLabel = '';
1016
+ },
1017
+ cancelAddRole() {
1018
+ this.addingRoleParent = null;
1019
+ this.newRoleLabel = '';
1020
+ },
1021
+ onNewRoleKey(e) {
1022
+ if (e?.key === 'Enter')
1023
+ this.confirmAddRole();
1024
+ else if (e?.key === 'Escape')
1025
+ this.cancelAddRole();
1026
+ },
1027
+ async confirmAddRole() {
1028
+ const label = String(this.newRoleLabel || '').trim();
567
1029
  if (!label)
568
1030
  return;
569
- const id = label.toLowerCase().replace(/[^a-zа-яё0-9_-]+/gi, '_').replace(/^_+|_+$/g, '') || ('place_' + Date.now());
1031
+ const parentTrail = this.addingRoleParent || '';
1032
+ const id = label.toLowerCase().replace(/[^a-zа-яё0-9_-]+/gi, '_').replace(/^_+|_+$/g, '') || ('role_' + Date.now());
570
1033
  const sec = JSON.parse(JSON.stringify(this.security || {}));
571
- const newNode = {
572
- id,
573
- label,
574
- ...(this.newPlaceExternal && !parentTrail ? { external: true } : {}),
575
- USERS: [],
576
- LINKS: [],
577
- };
578
- if (parentTrail) {
579
- const parent = this._findPlaceMut(sec, parentTrail);
580
- if (!parent)
581
- return;
582
- if (parent.external)
583
- newNode.external = true;
584
- parent.ROLES = Array.isArray(parent.ROLES) ? parent.ROLES : [];
585
- if (!parent.ROLES.some(r => r.id === id))
586
- parent.ROLES.push(newNode);
1034
+ const targetList = parentTrail
1035
+ ? ((this._findRoleMut(sec, parentTrail) || {}).ROLES ??= [])
1036
+ : (sec.ROLES ??= []);
1037
+ if (!targetList.some(r => r.id === id)) {
1038
+ targetList.push({ id, label, USERS: [], LINKS: [] });
587
1039
  }
588
- else {
589
- sec.ROLES = Array.isArray(sec.ROLES) ? sec.ROLES : [];
590
- if (!sec.ROLES.some(r => r.id === id))
591
- sec.ROLES.push(newNode);
592
- this.newPlaceLabel = '';
593
- this.newPlaceExternal = false;
594
- }
595
- await this.persist(sec);
1040
+ if (parentTrail)
1041
+ this.expandedRoles = { ...this.expandedRoles, [parentTrail]: true };
1042
+ this.cancelAddRole();
1043
+ await this.persist(sec, `Создана роль «${label}»`, `В подразделении ${this.$item?.path || ''} добавлена роль «${label}».`);
596
1044
  },
597
- async togglePlaceExternal(trail, checked) {
1045
+ async toggleRoleExternal(trail, checked) {
598
1046
  const sec = JSON.parse(JSON.stringify(this.security || {}));
599
- const node = this._findPlaceMut(sec, trail);
1047
+ const node = this._findRoleMut(sec, trail);
600
1048
  if (!node)
601
1049
  return;
602
1050
  if (checked)
603
1051
  node.external = true;
604
1052
  else
605
1053
  delete node.external;
606
- await this.persist(sec);
1054
+ await this.persist(sec, `Обновлена роль «${node.label || node.id}»`, `Роль «${node.label || node.id}»: внешний клиент = ${checked ? 'да' : 'нет'}.`);
607
1055
  },
608
- async promptSubPlace(parentTrail) {
609
- const name = window.prompt?.('Название подчинённого рабочего места:');
610
- if (name && name.trim())
611
- await this.addPlace(parentTrail, name.trim());
612
- },
613
- async removePlace(trail) {
1056
+ async removeRole(trail) {
614
1057
  const steps = String(trail || '').split('/').filter(Boolean);
615
1058
  if (!steps.length)
616
1059
  return;
@@ -620,149 +1063,122 @@ export default {
620
1063
  sec.ROLES = (sec.ROLES || []).filter(r => r?.id !== targetId);
621
1064
  }
622
1065
  else {
623
- const parent = this._findPlaceMut(sec, steps.join('/'));
1066
+ const parent = this._findRoleMut(sec, steps.join('/'));
624
1067
  if (parent && Array.isArray(parent.ROLES))
625
1068
  parent.ROLES = parent.ROLES.filter(r => r?.id !== targetId);
626
1069
  }
627
- await this.persist(sec);
1070
+ await this.persist(sec, `Удалена роль «${targetId}»`, `Из подразделения ${this.$item?.path || ''} удалена роль «${targetId}».`);
628
1071
  },
629
- async addPlaceUser(trail, e) {
630
- const uid = e?.target?.value;
631
- if (e?.target)
632
- e.target.value = '';
633
- if (!uid)
1072
+ toggleMemberPicker(trail) {
1073
+ this.pickerTrail = '';
1074
+ if (this.memberPickerTrail === trail) {
1075
+ this.closeMemberPicker();
634
1076
  return;
1077
+ }
1078
+ this.memberPickerTrail = trail;
1079
+ this.memberSearch = '';
1080
+ },
1081
+ closeMemberPicker() {
1082
+ this.memberPickerTrail = '';
1083
+ this.memberSearch = '';
1084
+ },
1085
+ async pickMember(trail, memberId) {
1086
+ this.closeMemberPicker();
1087
+ await this._addMemberToRole(trail, memberId);
1088
+ },
1089
+ async _addMemberToRole(trail, memberId) {
635
1090
  const sec = JSON.parse(JSON.stringify(this.security || {}));
636
- const node = this._findPlaceMut(sec, trail);
1091
+ const node = this._findRoleMut(sec, trail);
637
1092
  if (!node)
638
1093
  return;
639
1094
  node.USERS = Array.isArray(node.USERS) ? node.USERS : [];
640
- if (!node.USERS.includes(uid))
641
- node.USERS.push(uid);
642
- await this.persist(sec);
1095
+ if (!node.USERS.includes(memberId))
1096
+ node.USERS.push(memberId);
1097
+ await this.persist(sec, `В роль «${node.label || node.id}» добавлен участник`, `В роль «${node.label || node.id}» добавлен ${memberId}.`);
643
1098
  },
644
- async removePlaceUser(trail, uid) {
1099
+ async removeRoleMember(trail, memberId) {
645
1100
  const sec = JSON.parse(JSON.stringify(this.security || {}));
646
- const node = this._findPlaceMut(sec, trail);
1101
+ const node = this._findRoleMut(sec, trail);
647
1102
  if (!node || !Array.isArray(node.USERS))
648
1103
  return;
649
- node.USERS = node.USERS.filter(id => id !== uid);
650
- await this.persist(sec);
651
- },
652
- async addPlaceLink(trail, e) {
653
- const clsPath = e?.target?.value;
654
- if (e?.target)
655
- e.target.value = '';
656
- if (!clsPath)
1104
+ node.USERS = node.USERS.filter(id => id !== memberId);
1105
+ await this.persist(sec, `Из роли «${node.label || node.id}» исключён участник`, `Из роли «${node.label || node.id}» удалён ${memberId}.`);
1106
+ },
1107
+ toggleClassPicker(trail) {
1108
+ this.memberPickerTrail = '';
1109
+ if (this.pickerTrail === trail) {
1110
+ this.closeClassPicker();
657
1111
  return;
1112
+ }
1113
+ this.pickerTrail = trail;
1114
+ this.classSearch = '';
1115
+ this.pickerChecked = {};
1116
+ },
1117
+ closeClassPicker() {
1118
+ this.pickerTrail = '';
1119
+ this.classSearch = '';
1120
+ this.pickerChecked = {};
1121
+ },
1122
+ toggleClassExpand(path) {
1123
+ this.expandedClassPaths = {
1124
+ ...this.expandedClassPaths,
1125
+ [path]: !this.expandedClassPaths?.[path],
1126
+ };
1127
+ },
1128
+ togglePickerCheck(path, checked) {
1129
+ this.pickerChecked = {
1130
+ ...this.pickerChecked,
1131
+ [path]: Boolean(checked),
1132
+ };
1133
+ },
1134
+ onPickerLabelTap(node) {
1135
+ if (node.hasChildren && !node.selectable) {
1136
+ this.toggleClassExpand(node.path);
1137
+ return;
1138
+ }
1139
+ if (node.selectable)
1140
+ this.togglePickerCheck(node.path, !node.checked);
1141
+ },
1142
+ async applyClassPicker(trail) {
1143
+ const paths = Object.keys(this.pickerChecked || {}).filter(k => this.pickerChecked[k]);
1144
+ if (!paths.length)
1145
+ return;
1146
+ await this._addLinksToRole(trail, paths);
1147
+ this.closeClassPicker();
1148
+ },
1149
+ async _addLinksToRole(trail, paths) {
658
1150
  const sec = JSON.parse(JSON.stringify(this.security || {}));
659
- const node = this._findPlaceMut(sec, trail);
1151
+ const node = this._findRoleMut(sec, trail);
660
1152
  if (!node)
661
1153
  return;
662
1154
  node.LINKS = Array.isArray(node.LINKS) ? node.LINKS : [];
663
- if (!node.LINKS.some(l => l?.id === clsPath))
664
- node.LINKS.push({ id: clsPath, access: 'read' });
665
- await this.persist(sec);
1155
+ let added = 0;
1156
+ for (const p of paths) {
1157
+ if (p && !node.LINKS.some(l => l?.id === p)) {
1158
+ node.LINKS.push({ id: p, access: 'read' });
1159
+ added++;
1160
+ }
1161
+ }
1162
+ if (added) {
1163
+ this.expandedRoles = { ...this.expandedRoles, [trail]: true };
1164
+ await this.persist(sec, `К роли «${node.label || node.id}» привязаны классы (${added})`, `К роли «${node.label || node.id}» привязаны классы: ${paths.join(', ')}.`);
1165
+ }
666
1166
  },
667
- async updatePlaceLinkAccess(trail, clsPath, access) {
1167
+ async updateRoleLinkAccess(trail, clsPath, access) {
668
1168
  const sec = JSON.parse(JSON.stringify(this.security || {}));
669
- const node = this._findPlaceMut(sec, trail);
1169
+ const node = this._findRoleMut(sec, trail);
670
1170
  const link = node?.LINKS?.find(l => l?.id === clsPath);
671
1171
  if (!link)
672
1172
  return;
673
1173
  link.access = access === 'write' ? 'write' : 'read';
674
- await this.persist(sec);
1174
+ await this.persist(sec, `Изменён доступ роли к классу`, `Роль «${node.label || node.id}»: для ${clsPath} установлен доступ «${link.access}».`);
675
1175
  },
676
- async updatePlaceLinkScope(trail, clsPath, scope) {
1176
+ async removeRoleLink(trail, clsPath) {
677
1177
  const sec = JSON.parse(JSON.stringify(this.security || {}));
678
- const node = this._findPlaceMut(sec, trail);
679
- const link = node?.LINKS?.find(l => l?.id === clsPath);
680
- if (!link)
681
- return;
682
- if (scope)
683
- link.scope = scope;
684
- else
685
- delete link.scope;
686
- await this.persist(sec);
687
- },
688
- async removePlaceLink(trail, clsPath) {
689
- const sec = JSON.parse(JSON.stringify(this.security || {}));
690
- const node = this._findPlaceMut(sec, trail);
1178
+ const node = this._findRoleMut(sec, trail);
691
1179
  if (!node || !Array.isArray(node.LINKS))
692
1180
  return;
693
1181
  node.LINKS = node.LINKS.filter(l => l?.id !== clsPath);
694
- await this.persist(sec);
695
- },
696
- inviteStatusLabel(st) {
697
- return ({ active: 'активно', used: 'принято', revoked: 'отозвано', expired: 'истекло' })[st] || st;
698
- },
699
- inviteLinkOf(token) {
700
- return `${location.origin}/?invite=${encodeURIComponent(token || '')}`;
701
- },
702
- async copyText(text) {
703
- try {
704
- await navigator.clipboard?.writeText(String(text || ''));
705
- }
706
- catch {
707
- window.prompt?.('Скопируйте ссылку приглашения:', String(text || ''));
708
- }
709
- },
710
- async loadInvites() {
711
- if (!this.canEdit || !this.$item?.fetch) {
712
- this.invitesList = [];
713
- return;
714
- }
715
- try {
716
- const list = await this.$item.fetch('invite_list', {});
717
- this.invitesList = Array.isArray(list) ? list : [];
718
- }
719
- catch {
720
- this.invitesList = [];
721
- }
722
- },
723
- openInvite(trail) {
724
- if (this.inviteTrail === trail) {
725
- this.inviteTrail = '';
726
- this.inviteResult = null;
727
- return;
728
- }
729
- this.inviteTrail = trail;
730
- this.inviteChannel = 'link';
731
- this.inviteRecipient = '';
732
- this.inviteNote = '';
733
- this.inviteResult = null;
734
- },
735
- async sendInvite() {
736
- if (!this.inviteTrail || this.inviteBusy)
737
- return;
738
- this.inviteBusy = true;
739
- this.error = '';
740
- try {
741
- const res = await this.$item.fetch('invite_create', {}, {
742
- trail: this.inviteTrail,
743
- channel: this.inviteChannel,
744
- recipient: this.inviteRecipient,
745
- note: this.inviteNote,
746
- origin: location.origin,
747
- });
748
- this.inviteResult = res;
749
- await this.loadInvites();
750
- }
751
- catch (e) {
752
- this.error = String(e?.message || e);
753
- }
754
- finally {
755
- this.inviteBusy = false;
756
- }
757
- },
758
- async revokeInvite(id) {
759
- this.error = '';
760
- try {
761
- await this.$item.fetch('invite_revoke', {}, { id });
762
- await this.loadInvites();
763
- }
764
- catch (e) {
765
- this.error = String(e?.message || e);
766
- }
1182
+ await this.persist(sec, `Отвязан класс от роли`, `От роли «${node.label || node.id}» отвязан класс ${clsPath}.`);
767
1183
  },
768
1184
  }