-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathMultiUrlPicker.js
122 lines (103 loc) · 3.81 KB
/
MultiUrlPicker.js
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
(function () {
'use strict'
var MultiUrlPickerController = function ($scope, angularHelper, entityResource, iconHelper) {
this.renderModel = []
if ($scope.preview) {
return
}
if (!Array.isArray($scope.model.value)) {
$scope.model.value = []
}
if ($scope.model.value) {
$scope.model.value.forEach(function (link) {
link.icon = iconHelper.convertFromLegacyIcon(link.icon)
this.renderModel.push(link)
}.bind(this))
}
$scope.$on('formSubmitting', function () {
$scope.model.value = this.renderModel
}.bind(this))
$scope.$watch(function () {
return this.renderModel.length
}.bind(this), function () {
if ($scope.model.config && $scope.model.config.minNumberOfItems) {
$scope.multiUrlPickerForm.minCount.$setValidity('minCount', +$scope.model.config.minNumberOfItems <= this.renderModel.length)
}
if ($scope.model.config && $scope.model.config.maxNumberOfItems) {
$scope.multiUrlPickerForm.maxCount.$setValidity("maxCount", +$scope.model.config.maxNumberOfItems >= this.renderModel.length)
}
this.sortableOptions.disabled = this.renderModel.length === 1
}.bind(this))
this.sortableOptions = {
distance: 10,
tolerance: 'pointer',
scroll: true,
zIndex: 6000,
update: function () {
angularHelper.getCurrentForm($scope).$setDirty()
}
}
this.remove = function ($index) {
this.renderModel.splice($index, 1)
angularHelper.getCurrentForm($scope).$setDirty()
}
this.openLinkPicker = function (link, $index) {
var target = link ? {
name: link.name,
// the linkPicker breaks if it get an id or udi for media
id: link.isMedia ? null : link.id,
udi: link.isMedia ? null : link.udi,
url: link.url,
target: link.target
} : null
this.linkPickerOverlay = {
view: 'linkpicker',
currentTarget: target,
show: true,
submit: function (model) {
if (model.target.url) {
if (link) {
if (link.isMedia && link.url === model.target.url) {
// we can assume the existing media item is changed and no new file has been selected
// so we don't need to update the id, udi and isMedia fields
} else {
link.id = model.target.id
link.udi = model.target.udi
link.isMedia = model.target.isMedia
}
link.name = model.target.name || model.target.url
link.target = model.target.target
link.url = model.target.url
} else {
link = {
id: model.target.id,
isMedia: model.target.isMedia,
name: model.target.name || model.target.url,
target: model.target.target,
udi: model.target.udi,
url: model.target.url
}
this.renderModel.push(link)
}
if (link.udi) {
var entityType = link.isMedia ? 'media' : 'document'
entityResource.getById(link.udi, entityType)
.then(function (data) {
link.icon = iconHelper.convertFromLegacyIcon(data.icon)
link.published = !(data.metaData && data.metaData.IsPublished === false && entityType === 'document')
})
} else {
link.published = true
link.icon = 'icon-link'
}
angularHelper.getCurrentForm($scope).$setDirty()
}
this.linkPickerOverlay.show = false
this.linkPickerOverlay = null
}.bind(this)
}
}
}
angular.module('umbraco')
.controller('RJP.MultiUrlPickerController', MultiUrlPickerController)
})()