Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MultiPairField.adapter.ts « MultiPairField « src « vue « CoreHome « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e7c379ef8858768876ce55f4d84c8632b8941f48 (plain)
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
/*!
 * 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 } from 'angular';
import createAngularJsAdapter from '../createAngularJsAdapter';
import MultiPairField from './MultiPairField.vue';

export default createAngularJsAdapter({
  component: MultiPairField,
  require: '?ngModel',
  scope: {
    name: {
      angularJsBind: '=',
    },
    field1: {
      angularJsBind: '=',
    },
    field2: {
      angularJsBind: '=',
    },
    field3: {
      angularJsBind: '=',
    },
    field4: {
      angularJsBind: '=',
    },
  },
  directiveName: 'matomoMultiPairField',
  events: {
    'update:modelValue': (newValue, vm, scope, element, attrs, ngModel) => {
      if (newValue !== vm.modelValue) {
        element.trigger('change', newValue);

        if (ngModel) {
          ngModel.$setViewValue(newValue);
        }
      }
    },
  },
  postCreate(vm, scope, element, attrs, controller) {
    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;
        }
      };
    }
  },
});