/
asset.js
207 lines (169 loc) · 6.1 KB
/
asset.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/
pimcore.registerNS("pimcore.settings.user.workspace.asset");
pimcore.settings.user.workspace.asset = Class.create({
initialize: function (parent) {
this.parent = parent;
if(typeof this.parent.data["user"] != "undefined") {
this.data = this.parent.data.user;
} else if(typeof this.parent.data["role"] != "undefined") {
this.data = this.parent.data.role;
}
},
getPanel: function () {
var availableRights = ["list","view","publish","delete","rename","create","settings","versions","properties"];
var gridPlugins = [];
var storeFields = ["path"];
var typesColumns = [
{text: t("path"), width: 200, sortable: false, dataIndex: 'path',
editor: new Ext.form.TextField({}),
renderer: Ext.util.Format.htmlEncode,
tdCls: "pimcore_property_droptarget"
}
];
var check;
for (var i=0; i<availableRights.length; i++) {
// columns
check = new Ext.grid.column.Check({
text: t(availableRights[i]),
dataIndex: availableRights[i],
width: 50,
flex: 1
});
typesColumns.push(check);
gridPlugins.push(check);
// store fields
storeFields.push({name:availableRights[i], type: 'bool'});
}
typesColumns.push({
xtype: 'actioncolumn',
menuText: t('delete'),
width: 40,
items: [{
tooltip: t('delete'),
icon: "/bundles/pimcoreadmin/img/flat-color-icons/delete.svg",
handler: function (grid, rowIndex) {
grid.getStore().removeAt(rowIndex);
this.updateRows();
}.bind(this)
}]
});
this.store = new Ext.data.JsonStore({
autoDestroy: true,
proxy: {
type: 'memory',
reader: {
rootProperty: 'workspacesAsset'
}
},
fields: storeFields,
data: this.data
});
this.cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
this.grid = Ext.create('Ext.grid.Panel', {
frame: false,
autoScroll: true,
store: this.store,
columns : typesColumns,
trackMouseOver: true,
columnLines: true,
stripeRows: true,
autoExpandColumn: "path",
autoHeight: true,
style: "margin-bottom:20px;",
plugins: [
this.cellEditing
],
tbar: [
{
xtype: "tbtext",
text: "<b>" + t("assets") + "</b>"
},
"-","-",
{
iconCls: "pimcore_icon_add",
text: t("add"),
handler: this.onAdd.bind(this)
}
],
viewConfig: {
forceFit: true,
listeners: {
rowupdated: this.updateRows.bind(this),
refresh: this.updateRows.bind(this)
}
}
});
this.store.on("update", this.updateRows.bind(this));
this.grid.on("viewready", this.updateRows.bind(this));
return this.grid;
},
updateRows: function () {
var rows = Ext.get(this.grid.getEl().dom).query(".x-grid-row");
for (var i = 0; i < rows.length; i++) {
var dd = new Ext.dd.DropZone(rows[i], {
ddGroup: "element",
getTargetFromEvent: function(e) {
return this.getEl();
},
onNodeOver : function(target, dd, e, data) {
if (data.records.length == 1 && data.records[0].data.elementType == "asset") {
return Ext.dd.DropZone.prototype.dropAllowed;
}
},
onNodeDrop : function(myRowIndex, target, dd, e, data) {
if (pimcore.helpers.dragAndDropValidateSingleItem(data)) {
try {
var record = data.records[0];
var data = record.data;
// check for duplicate records
var index = this.grid.getStore().findExact("path", data.path);
if (index >= 0) {
return false;
}
if (data.elementType != "asset") {
return false;
}
var rec = this.grid.getStore().getAt(myRowIndex);
rec.set("path", data.path);
this.updateRows();
return true;
} catch (e) {
console.log(e);
}
}
}.bind(this, i)
});
}
},
onAdd: function (btn, ev) {
this.grid.store.insert(0, {
path: ""
});
this.updateRows();
},
getValues: function () {
var values = [];
this.store.commitChanges();
var records = this.store.getRange();
for (var i = 0; i < records.length; i++) {
var currentData = records[i];
if (currentData) {
values.push(currentData.data);
}
}
return values;
}
});