1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*!
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
import { INgModelController, ITimeoutService } from 'angular';
import createAngularJsAdapter from '../createAngularJsAdapter';
import SiteSelector from './SiteSelector.vue';
export default createAngularJsAdapter<[ITimeoutService]>({
component: SiteSelector,
require: '?ngModel',
scope: {
showSelectedSite: {
angularJsBind: '=',
},
showAllSitesItem: {
angularJsBind: '=',
},
switchSiteOnSelect: {
angularJsBind: '=',
},
onlySitesWithAdminAccess: {
angularJsBind: '=',
},
name: {
angularJsBind: '@',
},
allSitesText: {
angularJsBind: '@',
},
allSitesLocation: {
angularJsBind: '@',
},
placeholder: {
angularJsBind: '@',
},
modelValue: {},
},
$inject: ['$timeout'],
directiveName: 'piwikSiteselector',
events: {
'update:modelValue': (newValue, vm, scope, element, attrs, ngModel) => {
if ((newValue && !vm.modelValue)
|| (!newValue && vm.modelValue)
|| newValue.id !== vm.modelValue.id
) {
element.attr('siteid', newValue.id);
element.trigger('change', newValue);
if (ngModel) {
ngModel.$setViewValue(newValue);
}
}
},
blur(event, vm, scope) {
setTimeout(() => scope.$apply());
},
},
postCreate(vm, scope, element, attrs, controller, $timeout: ITimeoutService) {
const ngModel = controller as INgModelController;
// setup ng-model mapping
if (ngModel) {
ngModel.$setViewValue(vm.modelValue);
ngModel.$render = () => {
if (angular.isString(ngModel.$viewValue)) {
vm.modelValue = JSON.parse(ngModel.$viewValue);
} else {
vm.modelValue = ngModel.$viewValue;
}
};
}
$timeout(() => {
if (attrs.siteid && attrs.sitename) {
vm.modelValue = { id: attrs.siteid, name: attrs.sitename };
ngModel.$setViewValue({ ...vm.modelValue });
}
});
},
});
|