-
Notifications
You must be signed in to change notification settings - Fork 18
/
CollectionPropertyEditor.js
67 lines (56 loc) · 2.83 KB
/
CollectionPropertyEditor.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
(function (propertyEditor) {
propertyEditor.collection = propertyEditor.collection || {
openDialog: function (container, valueField, className) {
var callback = function (val, exerpt) {
var list = $(container).find("ul.sortable-collection");
var content = '<a href="#" onclick="top.propertyEditor.collection.editField(this);return false;" class="pull-right"><i class="icon icon-edit"></i>edit</a><i class="icon icon-sort"></i> ' + exerpt;
if (valueField == null && val != null) {
var newField = $('<li class="btn btn-default collection-item"></li>');
newField.attr('data-value', encodeURIComponent(val)).html(content);
list.append(newField);
}
else if (val == null) {
$(valueField).remove();
}
else {
$(valueField).attr('data-value', encodeURIComponent(val)).html(content);
}
list.trigger('sortupdate');
};
top.registerCallback(callback);
var value = null;
if (valueField != null) {
value = decodeURIComponent($(valueField).attr('data-value'));
}
top.propertyEditor.dialogs.openEditCollectionPropertyDialog(className, value);
},
editField: function (element) {
var listItem = $(element).parent();
var list = $(listItem).parent();
var className = list.attr("data-type");
var containerId = $(list).parent().attr('id');
propertyEditor.collection.openDialog('#' + containerId, listItem, className);
}
};
})(top.propertyEditor || (top.propertyEditor = {}));
(function (dialogs) {
dialogs.openEditCollectionPropertyDialog = dialogs.openEditCollectionPropertyDialog || function(className, value) {
parent.openModalViaPost('Content/Dialogs/EditCollectionPropertyDialog.aspx', { propertyType: className, value: value }, 780, 460);
return false;
};
})(top.propertyEditor.dialogs || (top.propertyEditor.dialogs = {}));
$(document).ready(function () {
$(".sortable-collection")
.sortable({ update: sortUpdate })
.bind("sortupdate", sortUpdate)
.disableSelection();
function sortUpdate(event, ui) {
var className = $(this).attr("data-type");
var value = '{"$type":"KalikoCMS.PropertyType.CollectionProperty`1[[' + className +']], KalikoCMS.Engine", "Items": [';
$(this).children("li").each(function () {
value += $(this).attr("data-value") + ",";
});
value = value.replace(/,$/, "") + "]}";
$(this).parent().find(".collection-value").val(value);
}
});