Skip to content

Commit 2ae5acb

Browse files
committed
Update to Umbraco v8 preview
1 parent 7b139d4 commit 2ae5acb

19 files changed

+392
-1043
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Multi Url Picker for Umbraco 7
1+
# Multi Url Picker for Umbraco 8
22

33
[![NuGet release](https://img.shields.io/nuget/v/RJP.UmbracoMultiUrlPicker.svg)](https://www.nuget.org/packages/RJP.UmbracoMultiUrlPicker)
44
[![Our Umbraco project page](https://img.shields.io/badge/our-umbraco-orange.svg)](https://our.umbraco.org/projects/backoffice-extensions/multi-url-picker)

build/version.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
2.1.0
1+
3.0.0
2+
alpha

src/RJP.MultiUrlPicker.Web.UI/MultiUrlPicker.html

+40-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<div ng-controller="RJP.MultiUrlPickerController as ctrl" class="umb-editor umb-contentpicker">
1+
<div ng-controller="RJP.MultiUrlPickerController as ctrl" class="umb-property-editor umb-contentpicker">
2+
<p ng-if="(ctrl.renderModel|filter:{trashed:true}).length == 1"><localize key="contentPicker_pickedTrashedItem"></localize></p>
3+
<p ng-if="(ctrl.renderModel|filter:{trashed:true}).length > 1"><localize key="contentPicker_pickedTrashedItems"></localize></p>
4+
25
<ng-form name="multiUrlPickerForm">
36
<div ui-sortable="ctrl.sortableOptions" ng-model="ctrl.renderModel">
47
<div ng-repeat="link in ctrl.renderModel">
@@ -14,7 +17,6 @@
1417
</umb-node-preview>
1518
</div>
1619
</div>
17-
1820
<a ng-show="!model.config.maxNumberOfItems || ctrl.renderModel.length < model.config.maxNumberOfItems"
1921
class="umb-node-preview-add"
2022
href
@@ -23,15 +25,49 @@
2325
<localize key="general_add">Add</localize>
2426
</a>
2527

28+
<div class="umb-contentpicker__min-max-help" ng-if="model.config.minNumberOfItems || model.config.maxNumberOfItems">
29+
30+
<!-- Both min and max items -->
31+
<span ng-if="model.config.minNumberOfItems && model.config.maxNumberOfItems && model.config.minNumberOfItems !== model.config.maxNumberOfItems">
32+
<span ng-if="ctrl.renderModel.length < model.config.maxNumberOfItems">Add between {{model.config.minNumberOfItems}} and {{model.config.maxNumberOfItems}} items</span>
33+
<span ng-if="ctrl.renderModel.length > model.config.maxNumberOfItems">
34+
<localize key="validation_maxCount">You can only have</localize> {{model.config.maxNumberOfItems}} <localize key="validation_itemsSelected"> items selected</localize>
35+
</span>
36+
</span>
37+
38+
<!-- Equal min and max -->
39+
<span ng-if="model.config.minNumberOfItems && model.config.maxNumber && model.config.minNumberOfItems === model.config.maxNumberOfItems">
40+
<span ng-if="ctrl.renderModel.length < model.config.maxNumberOfItems">Add {{model.config.minNumberOfItems - renderModel.length}} item(s)</span>
41+
<span ng-if="ctrl.renderModel.length > model.config.maxNumberOfItems">
42+
<localize key="validation_maxCount">You can only have</localize> {{model.config.maxNumberOfItems}} <localize key="validation_itemsSelected"> items selected</localize>
43+
</span>
44+
</span>
45+
46+
<!-- Only max -->
47+
<span ng-if="!model.config.minNumberOfItems && model.config.maxNumberOfItems">
48+
<span ng-if="ctrl.renderModel.length < model.config.maxNumberOfItems">Add up to {{model.config.maxNumberOfItems}} items</span>
49+
<span ng-if="ctrl.renderModel.length > model.config.maxNumberOfItems">
50+
<localize key="validation_maxCount">You can only have</localize> {{model.config.maxNumberOfItems}} <localize key="validation_itemsSelected">items selected</localize>
51+
</span>
52+
</span>
53+
54+
<!-- Only min -->
55+
<span ng-if="model.config.minNumberOfItems && !model.config.maxNumberOfItems && ctrl.renderModel.length < model.config.minNumberOfItems">
56+
Add at least {{model.config.minNumberOfItems}} item(s)
57+
</span>
58+
59+
</div>
60+
61+
2662
<input type="hidden" name="minCount" ng-model="ctrl.renderModel" />
2763
<input type="hidden" name="maxCount" ng-model="ctrl.renderModel" />
2864

2965
<div class="help-inline" val-msg-for="minCount" val-toggle-msg="minCount">
30-
You need to add at least {{model.config.minNumberOfItems}} items
66+
<localize key="validation_minCount">You need to add at least</localize> {{model.config.minNumberOfItems}} <localize key="validation_items">items</localize>
3167
</div>
3268

3369
<div class="help-inline" val-msg-for="maxCount" val-toggle-msg="maxCount">
34-
You can only have {{model.config.maxNumberOfItems}} items selected
70+
<localize key="validation_maxCount">You can only have</localize> {{model.config.maxNumberOfItems}} <localize key="validation_itemsSelected">items selected</localize>
3571
</div>
3672
</ng-form>
3773

src/RJP.MultiUrlPicker.Web.UI/MultiUrlPicker.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict'
33

44
var MultiUrlPickerController = function ($scope, angularHelper, entityResource, iconHelper) {
5+
56
this.renderModel = []
67

78
if ($scope.preview) {
@@ -126,7 +127,7 @@
126127
// Inject the querystring field
127128
var $markup = $(response.data)
128129
var $urlField = $markup.find('[label="@defaultdialogs_urlLinkPicker"]')
129-
$urlField.after('<umb-control-group label="Query String" ng-if="model.querystring"><input type="text" placeholder="Query String" class="umb-editor umb-textstring" ng-model="model.target.querystring"/></umb-control-group>')
130+
$urlField.after('<umb-control-group label="Query String" ng-if="model.querystring"><input type="text" placeholder="Query String" class="umb-property-editor umb-textstring" ng-model="model.target.querystring"/></umb-control-group>')
130131
response.data = $markup[0]
131132
}
132133
return response
@@ -136,5 +137,5 @@
136137
}
137138

138139
angular.module('umbraco').controller('RJP.MultiUrlPickerController', MultiUrlPickerController)
139-
angular.module("umbraco.services").config(['$httpProvider', mupHttpProvider]);
140+
angular.module('umbraco.services').config(['$httpProvider', mupHttpProvider])
140141
})()

src/RJP.MultiUrlPicker/Information.cs

-23
This file was deleted.

src/RJP.MultiUrlPicker/Models/Link.cs

+6-221
Original file line numberDiff line numberDiff line change
@@ -1,228 +1,13 @@
1-
namespace RJP.MultiUrlPicker.Models
1+
namespace RJP.MultiUrlPicker.Models
22
{
3-
using System;
4-
5-
using Newtonsoft.Json.Linq;
6-
7-
using Umbraco.Core.Models;
83
using Umbraco.Core;
94

10-
using Umbraco.Web;
11-
using Umbraco.Web.Extensions;
12-
using Umbraco.Core.Models.PublishedContent;
13-
145
public class Link
156
{
16-
private readonly JToken _linkItem;
17-
private bool _publishedContentInitialized = false;
18-
private string _name;
19-
private string _url;
20-
private string _target;
21-
private bool? _deleted;
22-
private LinkType? _linkType;
23-
private IPublishedContent _content;
24-
private Udi _udi;
25-
private int? _id;
26-
27-
public Link(JToken linkItem)
28-
{
29-
_linkItem = linkItem;
30-
}
31-
32-
private IPublishedContent PublishedContent
33-
{
34-
get
35-
{
36-
InitPublishedContent();
37-
return _content;
38-
}
39-
}
40-
41-
[Obsolete("Use Udi instead")]
42-
public int? Id
43-
{
44-
get
45-
{
46-
if (_id == null)
47-
{
48-
_id = _linkItem.Value<int?>("id");
49-
if (!_id.HasValue)
50-
{
51-
InitPublishedContent();
52-
}
53-
}
54-
return _id;
55-
}
56-
57-
}
58-
59-
public Udi Udi
60-
{
61-
get
62-
{
63-
if (_udi == null)
64-
{
65-
if (!Udi.TryParse(_linkItem.Value<string>("udi"), out _udi))
66-
{
67-
InitPublishedContent();
68-
}
69-
}
70-
return _udi;
71-
}
72-
}
73-
74-
public string Name
75-
{
76-
get
77-
{
78-
if (string.IsNullOrEmpty(_name))
79-
{
80-
_name = _linkItem.Value<string>("name");
81-
}
82-
return _name;
83-
}
84-
}
85-
86-
internal bool Deleted
87-
{
88-
get
89-
{
90-
if (_deleted == null)
91-
{
92-
if (Id.HasValue || Udi != null)
93-
{
94-
_deleted = PublishedContent == null;
95-
}
96-
else
97-
{
98-
_deleted = false;
99-
}
100-
}
101-
return (bool)_deleted;
102-
}
103-
}
104-
105-
public string Url
106-
{
107-
get
108-
{
109-
if (string.IsNullOrEmpty(_url))
110-
{
111-
_url = PublishedContent?.Url ?? _linkItem.Value<string>("url");
112-
113-
var qs = _linkItem.Value<string>("querystring");
114-
if (!string.IsNullOrWhiteSpace(qs))
115-
{
116-
_url += qs;
117-
}
118-
}
119-
return _url;
120-
}
121-
}
122-
123-
public string Target
124-
{
125-
get
126-
{
127-
if (string.IsNullOrEmpty(_target))
128-
{
129-
_target = _linkItem.Value<string>("target");
130-
}
131-
return _target == string.Empty ? null : _target;
132-
}
133-
}
134-
135-
public LinkType Type
136-
{
137-
get
138-
{
139-
if (_linkType == null)
140-
{
141-
if (Udi != null)
142-
{
143-
if (Udi.EntityType == Constants.UdiEntityType.Media)
144-
{
145-
_linkType = LinkType.Media;
146-
}
147-
else
148-
{
149-
_linkType = LinkType.Content;
150-
}
151-
}
152-
else
153-
{
154-
_linkType = LinkType.External;
155-
}
156-
}
157-
return _linkType.Value;
158-
}
159-
}
160-
161-
162-
private void InitPublishedContent()
163-
{
164-
if (!_publishedContentInitialized)
165-
{
166-
_publishedContentInitialized = true;
167-
168-
if (UmbracoContext.Current == null)
169-
{
170-
return;
171-
}
172-
173-
if (Udi.TryParse(_linkItem.Value<string>("udi"), out _udi))
174-
{
175-
_content = _udi.ToPublishedContent();
176-
_id = _content?.Id;
177-
}
178-
else
179-
{
180-
var helper = new UmbracoHelper(UmbracoContext.Current);
181-
182-
// there were no Udi so let's try the legacy way
183-
_id = _linkItem.Value<int?>("id");
184-
185-
if (_id.HasValue)
186-
{
187-
bool isMedia = _linkItem.Value<bool>("isMedia");
188-
189-
if (_linkItem.Value<bool>("isMedia"))
190-
{
191-
_content = helper.TypedMedia(_id.Value);
192-
}
193-
else
194-
{
195-
_content = helper.TypedContent(_id.Value);
196-
}
197-
SetUdi();
198-
}
199-
}
200-
}
201-
}
202-
203-
private void SetUdi()
204-
{
205-
if (_content != null && _udi == null)
206-
{
207-
Guid? key = _content.GetKey();
208-
if (key == Guid.Empty)
209-
{
210-
// if the key is Guid.Empty the model might be created by the ModelsBuilder,
211-
// if so it, by default, derives from PublishedContentModel.
212-
// By calling UnWrap() we get the original content, which probably implements
213-
// IPublishedContentWithKey, so we can get the key
214-
key = (_content as PublishedContentWrapped)?.Unwrap().GetKey();
215-
}
216-
217-
if (key.HasValue && key != Guid.Empty)
218-
{
219-
string udiType = _content.ItemType == PublishedItemType.Media ?
220-
Constants.UdiEntityType.Media :
221-
Constants.UdiEntityType.Document;
222-
223-
_udi = Udi.Create(udiType, key.Value);
224-
}
225-
}
226-
}
7+
public string Name { get; set; }
8+
public string Target { get; set; }
9+
public LinkType Type { get; set; }
10+
public Udi Udi { get; set; }
11+
public string Url { get; set; }
22712
}
22813
}

0 commit comments

Comments
 (0)