1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://flipboxfactory.com/software/organization/license |
6
|
|
|
* @link https://www.flipboxfactory.com/software/organization/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\organizations\elements\actions; |
10
|
|
|
|
11
|
|
|
use Craft; |
12
|
|
|
use craft\base\ElementAction; |
13
|
|
|
use craft\helpers\Json; |
14
|
|
|
use flipbox\organizations\objects\OrganizationAttributeTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Flipbox Factory <[email protected]> |
18
|
|
|
* @since 1.0.0 |
19
|
|
|
*/ |
20
|
|
|
class EditUserAssociation extends ElementAction |
21
|
|
|
{ |
22
|
|
|
use OrganizationAttributeTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
public function settingsAttributes(): array |
28
|
|
|
{ |
29
|
|
|
return array_merge( |
30
|
|
|
parent::settingsAttributes(), |
31
|
|
|
[ |
32
|
|
|
'organization' |
33
|
|
|
] |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @inheritdoc |
39
|
|
|
*/ |
40
|
|
|
public function getTriggerLabel(): string |
41
|
|
|
{ |
42
|
|
|
return Craft::t('organizations', 'Edit'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @inheritdoc |
47
|
|
|
*/ |
48
|
|
|
public function getTriggerHtml() |
49
|
|
|
{ |
50
|
|
|
$type = Json::encode(static::class); |
51
|
|
|
$organizationId = $this->getOrganizationId(); |
52
|
|
|
|
53
|
|
|
$js = <<<EOT |
54
|
|
|
(function() |
55
|
|
|
{ |
56
|
|
|
|
57
|
|
|
var trigger = new Craft.NestedIndexElementActionTrigger( |
58
|
|
|
index_nested_index_organization_users, |
59
|
|
|
{ |
60
|
|
|
type: {$type}, |
61
|
|
|
batch: false, |
62
|
|
|
validateSelection: function(\$selectedItems) |
63
|
|
|
{ |
64
|
|
|
return Garnish.hasAttr(\$selectedItems.find('.element'), 'data-editable'); |
65
|
|
|
}, |
66
|
|
|
activate: function(\$selectedItems) |
67
|
|
|
{ |
68
|
|
|
var \$element = \$selectedItems.find('.element:first'); |
69
|
|
|
|
70
|
|
|
if (index_nested_index_organization_users.viewMode === 'table') { |
71
|
|
|
new Craft.UserAssociationEditor(\$element, { |
72
|
|
|
params: { |
73
|
|
|
organization: {$organizationId}, |
74
|
|
|
includeTableAttributesForSource: 'organizations:' + |
75
|
|
|
index_nested_index_organization_users.sourceKey |
76
|
|
|
}, |
77
|
|
|
onSaveElement: $.proxy(function(response) { |
78
|
|
|
if (response.tableAttributes) { |
79
|
|
|
index_nested_index_organization_users.view._updateTableAttributes( |
80
|
|
|
\$element, |
81
|
|
|
response.tableAttributes |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
}, this) |
85
|
|
|
}); |
86
|
|
|
} else { |
87
|
|
|
new Craft.UserAssociationEditor(\$element); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
); |
92
|
|
|
})(); |
93
|
|
|
EOT; |
94
|
|
|
|
95
|
|
|
Craft::$app->getView()->registerJs($js); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|