|
1 | 1 | (function () {
|
2 |
| - 'use strict' |
| 2 | + 'use strict' |
3 | 3 |
|
4 |
| - var MultiUrlPickerController = function ($scope, angularHelper, entityResource, iconHelper) { |
| 4 | + var MultiUrlPickerController = function ($scope, angularHelper, entityResource, iconHelper) { |
5 | 5 |
|
6 |
| - this.renderModel = [] |
| 6 | + this.renderModel = [] |
7 | 7 |
|
8 |
| - if ($scope.preview) { |
9 |
| - return |
10 |
| - } |
11 |
| - |
12 |
| - $scope.model.value.forEach(function (link) { |
13 |
| - link.icon = iconHelper.convertFromLegacyIcon(link.icon) |
14 |
| - this.renderModel.push(link) |
15 |
| - }.bind(this)) |
| 8 | + if ($scope.preview) { |
| 9 | + return |
| 10 | + } |
16 | 11 |
|
17 |
| - $scope.$on('formSubmitting', function () { |
18 |
| - $scope.model.value = this.renderModel |
19 |
| - }.bind(this)) |
| 12 | + $scope.model.value.forEach(function (link) { |
| 13 | + link.icon = iconHelper.convertFromLegacyIcon(link.icon) |
| 14 | + this.renderModel.push(link) |
| 15 | + }.bind(this)) |
| 16 | + |
| 17 | + $scope.$on('formSubmitting', function () { |
| 18 | + $scope.model.value = this.renderModel |
| 19 | + }.bind(this)) |
| 20 | + |
| 21 | + $scope.$watch(function () { |
| 22 | + return this.renderModel.length |
| 23 | + }.bind(this), function () { |
| 24 | + $scope.multiUrlPickerForm.minCount.$setValidity('minCount', $scope.model.config && $scope.model.config.minNumberOfItems && +$scope.model.config.minNumberOfItems <= this.renderModel.length) |
| 25 | + $scope.multiUrlPickerForm.maxCount.$setValidity("maxCount", $scope.model.config && $scope.model.config.maxNumberOfItems && +$scope.model.config.maxNumberOfItems >= this.renderModel.length) |
| 26 | + |
| 27 | + this.sortableOptions.disabled = this.renderModel.length === 1 |
| 28 | + }.bind(this)) |
| 29 | + |
| 30 | + this.sortableOptions = { |
| 31 | + distance: 10, |
| 32 | + tolerance: 'pointer', |
| 33 | + scroll: true, |
| 34 | + zIndex: 6000 |
| 35 | + } |
20 | 36 |
|
21 |
| - $scope.$watch(function () { |
22 |
| - return this.renderModel.length |
23 |
| - }.bind(this), function () { |
24 |
| - $scope.multiUrlPickerForm.minCount.$setValidity('minCount', $scope.model.config && $scope.model.config.minNumberOfItems && +$scope.model.config.minNumberOfItems <= this.renderModel.length) |
25 |
| - $scope.multiUrlPickerForm.maxCount.$setValidity("maxCount", $scope.model.config && $scope.model.config.maxNumberOfItems && +$scope.model.config.maxNumberOfItems >= this.renderModel.length) |
| 37 | + this.remove = function ($index) { |
| 38 | + this.renderModel.splice($index, 1) |
26 | 39 |
|
27 |
| - this.sortableOptions.disabled = this.renderModel.length === 1 |
28 |
| - }.bind(this)) |
| 40 | + angularHelper.getCurrentForm($scope).$setDirty(); |
| 41 | + } |
29 | 42 |
|
30 |
| - this.sortableOptions = { |
31 |
| - distance: 10, |
32 |
| - tolerance: 'pointer', |
33 |
| - scroll: true, |
34 |
| - zIndex: 6000 |
35 |
| - } |
| 43 | + this.openLinkPicker = function (link, $index) { |
| 44 | + var target = link ? { |
| 45 | + name: link.name, |
| 46 | + // the linkPicker breaks if it get an id or udi for media |
| 47 | + id: link.isMedia ? null : link.id, |
| 48 | + udi: link.isMedia ? null : link.udi, |
| 49 | + url: link.url, |
| 50 | + target: link.target |
| 51 | + } : null |
| 52 | + |
| 53 | + |
| 54 | + this.linkPickerOverlay = { |
| 55 | + view: 'linkpicker', |
| 56 | + currentTarget: target, |
| 57 | + show: true, |
| 58 | + submit: function (model) { |
| 59 | + if (model.target.url) { |
| 60 | + if (link) { |
| 61 | + if (link.isMedia && link.url === model.target.url) { |
| 62 | + // we can assume the existing media item is changed and no new file has been selected |
| 63 | + // so we don't need to update the id, udi and isMedia fields |
| 64 | + } else { |
| 65 | + link.id = model.target.id |
| 66 | + link.udi = model.target.udi |
| 67 | + link.isMedia = model.target.isMedia |
| 68 | + } |
| 69 | + |
| 70 | + link.name = model.target.name || model.target.url |
| 71 | + link.target = model.target.target |
| 72 | + link.url = model.target.url |
| 73 | + } else { |
| 74 | + link = { |
| 75 | + id: model.target.id, |
| 76 | + isMedia: model.target.isMedia, |
| 77 | + name: model.target.name || model.target.url, |
| 78 | + target: model.target.target, |
| 79 | + udi: model.target.udi, |
| 80 | + url: model.target.url |
| 81 | + } |
| 82 | + this.renderModel.push(link) |
| 83 | + } |
36 | 84 |
|
37 |
| - this.remove = function ($index) { |
38 |
| - this.renderModel.splice($index, 1) |
| 85 | + if (link.udi) { |
| 86 | + var entityType = link.isMedia ? 'media' : 'document' |
| 87 | + |
| 88 | + entityResource.getById(link.udi, entityType) |
| 89 | + .then(function (data) { |
| 90 | + link.icon = iconHelper.convertFromLegacyIcon(data.icon) |
| 91 | + link.published = !(data.metaData && data.metaData.IsPublished === false && entityType === 'document') |
| 92 | + }) |
| 93 | + } else { |
| 94 | + link.published = true |
| 95 | + link.icon = 'icon-link' |
| 96 | + } |
39 | 97 |
|
40 | 98 | angularHelper.getCurrentForm($scope).$setDirty();
|
41 |
| - } |
42 |
| - |
43 |
| - this.openLinkPicker = function (link, $index) { |
44 |
| - var target = link ? { |
45 |
| - name: link.name, |
46 |
| - // the linkPicker breaks if it get an id or udi for media |
47 |
| - id: link.isMedia ? null : link.id, |
48 |
| - udi: link.isMedia ? null : link.udi, |
49 |
| - url: link.url, |
50 |
| - target: link.target |
51 |
| - } : null |
52 |
| - |
53 |
| - |
54 |
| - this.linkPickerOverlay = { |
55 |
| - view: 'linkpicker', |
56 |
| - currentTarget: target, |
57 |
| - show: true, |
58 |
| - submit: function (model) { |
59 |
| - if (model.target.url) { |
60 |
| - if (link) { |
61 |
| - if (link.isMedia && link.url === model.target.url) { |
62 |
| - // we can assume the existing media item is changed and no new file has been selected |
63 |
| - // so we don't need to update the id, udi and isMedia fields |
64 |
| - } else { |
65 |
| - link.id = model.target.id |
66 |
| - link.udi = model.target.udi |
67 |
| - link.isMedia = model.target.isMedia |
68 |
| - } |
69 |
| - |
70 |
| - link.name = model.target.name || model.target.url |
71 |
| - link.target = model.target.target |
72 |
| - link.url = model.target.url |
73 |
| - } else { |
74 |
| - link = { |
75 |
| - id: model.target.id, |
76 |
| - isMedia: model.target.isMedia, |
77 |
| - name: model.target.name || model.target.url, |
78 |
| - target: model.target.target, |
79 |
| - udi: model.target.udi, |
80 |
| - url: model.target.url |
81 |
| - } |
82 |
| - this.renderModel.push(link) |
83 |
| - } |
84 |
| - |
85 |
| - if (link.udi) { |
86 |
| - var entityType = link.isMedia ? 'media' : 'document' |
87 |
| - |
88 |
| - entityResource.getById(link.udi, entityType) |
89 |
| - .then(function (data) { |
90 |
| - link.icon = iconHelper.convertFromLegacyIcon(data.icon) |
91 |
| - link.published = !(data.metaData && data.metaData.IsPublished === false && entityType === 'document') |
92 |
| - }) |
93 |
| - } else { |
94 |
| - link.published = true |
95 |
| - link.icon = 'icon-link' |
96 |
| - } |
97 |
| - |
98 |
| - angularHelper.getCurrentForm($scope).$setDirty(); |
99 |
| - } |
100 |
| - |
101 |
| - this.linkPickerOverlay.show = false |
102 |
| - this.linkPickerOverlay = null |
103 |
| - }.bind(this) |
104 |
| - } |
105 |
| - } |
| 99 | + } |
| 100 | + |
| 101 | + this.linkPickerOverlay.show = false |
| 102 | + this.linkPickerOverlay = null |
| 103 | + }.bind(this) |
| 104 | + } |
106 | 105 | }
|
| 106 | + } |
107 | 107 |
|
108 |
| - angular.module('umbraco') |
109 |
| - .controller('RJP.MultiUrlPickerController', MultiUrlPickerController) |
| 108 | + angular.module('umbraco') |
| 109 | + .controller('RJP.MultiUrlPickerController', MultiUrlPickerController) |
110 | 110 | })()
|
0 commit comments