forked from syncfusion/ej2-aspnetcore-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCRUD.cshtml
381 lines (357 loc) · 19 KB
/
CRUD.cshtml
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
@using Syncfusion.EJ2.Diagrams;
@using Syncfusion.EJ2.Inputs;
@section ControlsSection{
<div class="control-section">
<div style="width: 100%;height: 10%">
@*Initializes ToolBar control.*@
<ejs-toolbar id="toolbar" clicked="toolbarClick" created="toolbarCreate">
<e-toolbar-items>
<e-toolbar-item id="Add" tooltipText="Add" prefixIcon="e-ddb-icons e-add" text="Add"></e-toolbar-item>
<e-toolbar-item type="Separator"></e-toolbar-item>
<e-toolbar-item id="Edit" tooltipText="Edit" prefixIcon="e-ddb-icons e-update" text="Edit"></e-toolbar-item>
<e-toolbar-item type="Separator"></e-toolbar-item>
<e-toolbar-item id="Delete" tooltipText="Delete" prefixIcon="e-ddb-icons e-delete" text="Delete"></e-toolbar-item>
<e-toolbar-item type="Separator"></e-toolbar-item>
</e-toolbar-items>
</ejs-toolbar>
</div>
<div style="width: 100%;height: 80%;border-width: 0 1px 1px 1px; border-style: solid; border-color:#D7D7D7">
<div id="diagram-space" class="sb-mobile-diagram">
@*Initializes Diagram control.*@
<ejs-diagram id="diagram" dataSourceSettings="ViewBag.DataSourceSettings" width="100%" height="600px" getNodeDefaults="ViewBag.nodeDefaults" getConnectorDefaults="ViewBag.connectorDefaults" selectionChange="selectionChange" sourcePointChange="connectionChange" targetPointChange="connectionChange" setNodeTemplate="ViewBag.setNodeTemplate">
<e-diagram-snapsettings constraints="None"></e-diagram-snapsettings>
<e-diagram-layout type="HierarchicalTree" verticalSpacing="40"></e-diagram-layout>
</ejs-diagram>
</div>
</div>
</div>
@*Initialize Dialog control*@
<ejs-dialog id="editDialog" width="300px" visible="false" isModal="true" showCloseIcon="true">
<e-content-template>
<div class="showLabel">
@*Initialize Textbox control*@
<ejs-textbox id="Description" placeholder="Enter Description"></ejs-textbox>
</div>
<div class="showLabel" style="padding-top: 14px">
@*Initialize Textbox control*@
<ejs-textbox id="Color" placeholder="Enter Color"></ejs-textbox>
</div>
<div class="showDropdown">
@*Initialize Dropdownlist control to display an sourceNodes in diagram.*@
<ejs-dropdownlist id="SourceId" placeholder="select sourceId" created="sourceDropdownCreate" popupHeight="220px" change="sourceDropdownChange">
<e-dropdownlist-fields text="Label" value="Name"></e-dropdownlist-fields>
</ejs-dropdownlist>
</div>
<div class="showDropdown" style="padding-top: 14px">
@*Initialize Dropdownlist control to display an targetNodes in diagram.*@
<ejs-dropdownlist id="TargetId" placeholder="select targetId" created="targetDropdownCreate" popupHeight="220px" change="targetDropdownChange">
<e-dropdownlist-fields text="Label" value="Name"></e-dropdownlist-fields>
</ejs-dropdownlist>
</div>
</e-content-template>
<e-dialog-buttons>
@*Initialize Button control to update the node label and node color.*@
<e-dialog-dialogbutton buttonModel="ViewBag.button" click="dlgButtonClick"></e-dialog-dialogbutton>
</e-dialog-buttons>
</ejs-dialog>
<style>
@@font-face {
font-family: 'e-ddb-icons';
src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMj0gSR8AAAEoAAAAVmNtYXDnKOeBAAABqAAAAEZnbHlmP/EWVwAAAggAAAMMaGVhZBMKQgEAAADQAAAANmhoZWEHnwNtAAAArAAAACRobXR4JygAAAAAAYAAAAAobG9jYQTSBCQAAAHwAAAAFm1heHABGgA+AAABCAAAACBuYW1lmAO1gQAABRQAAALNcG9zdHwLfoAAAAfkAAAAewABAAADUv9qAFoEAAAA//gD8AABAAAAAAAAAAAAAAAAAAAACgABAAAAAQAAJYsEL18PPPUACwPoAAAAANf9/pYAAAAA1/3+lgAAAAAD8APwAAAACAACAAAAAAAAAAEAAAAKADIABgAAAAAAAgAAAAoACgAAAP8AAAAAAAAAAQPqAZAABQAAAnoCvAAAAIwCegK8AAAB4AAxAQIAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABA5wDnCANS/2oAWgPwAJYAAAABAAAAAAAABAAAAAPoAAAD6AAAA+gAAAPoAAAD6AAAA+gAAAPoAAAD6AAAA+gAAAAAAAIAAAADAAAAFAADAAEAAAAUAAQAMgAAAAQABAABAADnCP//AADnAP//AAAAAQAEAAAAAQACAAMABAAFAAYABwAIAAkAAAAAAAAAQgCQAK4A/gEWAS4BRgFoAYYAAAAFAAAAAANyA/AAAwAHAAsADwAlAAABESMRIxEjESMRIxEBFyE3BxEeARchPgE3ETM1IycuASMhIgYPAQJ2P18+Xz8BRBX+yBXzAUc2Afg2RwE/2xsH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AAEECQACAA4A0QADAAEECQADACoA3wADAAEECQAEACoBCQADAAEECQAFABYBMwADAAEECQAGACoBSQADAAEECQAKAFgBcwADAAEECQALACQByyBEaWFncmFtIGJ1aWxkZXIgaWNvbnNSZWd1bGFyRGlhZ3JhbSBidWlsZGVyIGljb25zRGlhZ3JhbSBidWlsZGVyIGljb25zVmVyc2lvbiAxLjBEaWFncmFtIGJ1aWxkZXIgaWNvbnNGb250IGdlbmVyYXRlZCB1c2luZyBTeW5jZnVzaW9uIE1ldHJvIFN0dWRpb3d3dy5zeW5jZnVzaW9uLmNvbQAgAEQAaQBhAGcAcgBhAG0AIABiAHUAaQBsAGQAZQByACAAaQBjAG8AbgBzAFIAZQBnAHUAbABhAHIARABpAGEAZwByAGEAbQAgAGIAdQBpAGwAZABlAHIAIABpAGMAbwBuAHMARABpAGEAZwByAGEAbQAgAGIAdQBpAGwAZABlAHIAIABpAGMAbwBuAHMAVgBlAHIAcwBpAG8AbgAgADEALgAwAEQAaQBhAGcAcgBhAG0AIABiAHUAaQBsAGQAZQByACAAaQBjAG8AbgBzAEYAbwBuAHQAIABnAGUAbgBlAHIAYQB0AGUAZAAgAHUAcwBpAG4AZwAgAFMAeQBuAGMAZgB1AHMAaQBvAG4AIABNAGUAdAByAG8AIABTAHQAdQBkAGkAbwB3AHcAdwAuAHMAeQBuAGMAZgB1AHMAaQBvAG4ALgBjAG8AbQAAAAACAAAAAAAAAAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoBAgEDAQQBBQEGAQcBCAEJAQoBCwAIQl9kZWxldGUIRl9kZWxldGUGTV9FZGl0BkZfRWRpdAVNX0FkZAVGX0FkZAVCX0FkZAhNX2RlbGV0ZQZCX0VkaXQAAAA=) format('truetype');
font-weight: normal;
font-style: normal;
}
.e-ddb-icons {
font-family: 'e-ddb-icons';
speak: none;
font-size: 55px;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.e-add::before {
content: "\e705";
}
.e-update::before {
content: "\e703";
}
.e-delete::before {
content: "\e701";
}
.material .e-add::before {
content: "\e704";
}
.material .e-update::before {
content: "\e702";
}
.material .e-delete::before {
content: "\e707";
}
.bootstrap .e-add::before {
content: "\e706";
}
.bootstrap .e-update::before {
content: "\e708";
}
.bootstrap .e-delete::before {
content: "\e700";
}
.e-toolbar .e-toolbar-items .e-toolbar-item .e-tbar-btn.e-btn.e-tbtn-txt .e-icons.e-btn-icon {
padding: 3px;
}
.showDropdown {
display: none;
}
</style>
<script type="text/javascript">
var diagram;
var dialog;
var toolbarObj;
var sourceDropdown;
var targetDropdown;
var sourceID;
var targetID;
var nodeData = [];
@*custom code start*@
function dlgButtonClick(args) {
diagram = document.getElementById('diagram').ej2_instances[0];
dialog = document.getElementById("editDialog").ej2_instances[0];
var dialogHeader = dialog.header;
var description = document.getElementById("Description").value;
var color = document.getElementById("Color").value;
var selectedItem;
if (diagram.selectedItems.nodes.length > 0) {
selectedItem = diagram.selectedItems.nodes[0];
}
if (diagram.selectedItems.connectors.length > 0) {
selectedItem = diagram.selectedItems.connectors[0];
}
//Add new node and connector in diagram at runtime.
if (dialogHeader === "Add") {
var node = {
id: 'node' + ej.diagrams.randomId(), style: { fill: color }, Description: description, Color: color, Id: Math.floor((Math.random() * 1000) + 100),
};
var connector = {
id: 'connector' + ej.diagrams.randomId(), sourceID: selectedItem.id, targetID: node.id, Id: Math.floor((Math.random() * 1000) + 100),
};
diagram.add(node);
diagram.add(connector);
diagram.doLayout();
//Insert newly added elements into the database.
diagram.insertData();
nodeData.push({ Name: node.id, Label: description });
}
else {
if (selectedItem instanceof ej.diagrams.Connector) {
//Update sourceNode and targetNode at runtime.
selectedItem.sourceID = sourceID ? sourceID : selectedItem.sourceID;
selectedItem.targetID = targetID ? targetID : selectedItem.targetID;
diagram.dataBind();
diagram.doLayout();
}
else {
//update an node text and node bgColor.
selectedItem.Description = description;
selectedItem.Color = color;
selectedItem.annotations[0].content = description;
selectedItem.style.fill = color;
diagram.dataBind();
}
diagram.updateData();
}
dialog.hide();
};
@*custom code end*@
//Set node default properties.
function nodeDefaults(obj, diagram) {
obj.width = 100;
obj.height = 50;
obj.shape = { type: 'Basic', shape: 'Rectangle' };
obj.style = { strokeWidth: 1, strokeColor: '#DDDDDD' };
return obj;
}
//Set connector default properties.
function connectorDefaults(connector, diagram) {
connector.type = 'Orthogonal';
connector.style.fill = '#707070';
connector.style.strokeColor = '#707070';
connector.targetDecorator = {
style: {
strokeColor: '#707070',
fill: '#707070'
},
};
return connector;
}
@*custom code start*@
//Displays nodes name in dropdown.
function sourceDropdownCreate(args) {
var sourceDropdown = document.getElementById('SourceId').ej2_instances[0];
sourceDropdown.dataSource = getDataSource();
sourceDropdown.dataBind();
}
//Displays nodes name in dropdown.
function targetDropdownCreate(args) {
var targetDropdown = document.getElementById('TargetId').ej2_instances[0];
targetDropdown.dataSource = getDataSource();
targetDropdown.dataBind();
}
//Set an sourceId of an selected Connector.
function sourceDropdownChange(args) {
sourceID = args.value;
}
//Set an targetId of an selected Connector.
function targetDropdownChange(args) {
targetID = args.value;
}
//Disable toolbar icon at initial rendering.
function toolbarCreate(args) {
enableToolbarItems(false);
}
@*custom code end*@
//Disable or Enable the toolbar items based on element selection.
function selectionChange(args) {
if (args.state === 'Changing') {
toolbarObj = document.getElementById("toolbar").ej2_instances[0];
if (args.newValue.length > 0) {
if (args.newValue[0] instanceof ej.diagrams.Node) {
enableToolbarItems(true);
}
else {
toolbarObj.enableItems(document.getElementById(toolbarObj.items[0].id).parentElement, false);
toolbarObj.enableItems(document.getElementById(toolbarObj.items[2].id).parentElement, true);
toolbarObj.enableItems(document.getElementById(toolbarObj.items[4].id).parentElement, false);
}
}
else {
enableToolbarItems(false);
}
}
}
@*custom code start*@
//Enable or disable the toolbar items.
function enableToolbarItems(isEnableItem) {
toolbarObj = document.getElementById("toolbar").ej2_instances[0];
toolbarObj.enableItems(document.getElementById(toolbarObj.items[0].id).parentElement, isEnableItem);
toolbarObj.enableItems(document.getElementById(toolbarObj.items[2].id).parentElement, isEnableItem);
toolbarObj.enableItems(document.getElementById(toolbarObj.items[4].id).parentElement, isEnableItem);
}
@*custom code end*@
function connectionChange(args) {
if (args.state === 'Completed') {
if (!args.connector.targetID || !args.connector.sourceID) {
args.cancel = true;
}
}
}
//Set an label for each node.
function setNodeTemplate(obj) {
obj.annotations = [{ style: { color: 'black' } }];
obj.annotations[0].content = obj.Description;
obj.style = { fill: obj.Color };
if (obj.Id === 1) {
//Restrict Delete Constraints for root node.
obj.constraints = ej.diagrams.NodeConstraints.Default & ~ej.diagrams.NodeConstraints.Delete;
}
}
@*custom code start*@
//Opens a dialog with textbox and dropdown control based on toolbar clicked items.
function toolbarClick(args) {
diagram = document.getElementById('diagram').ej2_instances[0];
var selectedItem;
if (diagram.selectedItems.nodes.length > 0) {
selectedItem = diagram.selectedItems.nodes[0];
}
if (diagram.selectedItems.connectors.length > 0) {
selectedItem = diagram.selectedItems.connectors[0];
}
if (selectedItem) {
switch (args.item.tooltipText) {
case 'Add':
openDialog("Add", "", "", true);
break;
case 'Edit':
if (selectedItem instanceof ej.diagrams.Connector) {
var sourceNode = diagram.getObject(selectedItem.sourceID);
var targetNode = diagram.getObject(selectedItem.targetID);
openDialog("Edit", sourceNode.Description, targetNode.Description, false);
}
else {
openDialog("Edit", selectedItem.Description, selectedItem.Color, true);
}
break;
case 'Delete':
diagram.remove(selectedItem);
diagram.doLayout();
diagram.removeData();
var element = { Name: selectedItem.id, Label: selectedItem.Description };
var index = nodeData.indexOf(element);
nodeData.splice(index, 1);
}
}
}
//Show or Hide the Textbox and Dropdown in dialog control
function hideClassElement(className, display) {
var i;
var showDropdown = document.querySelectorAll(className);
for (i = 0; i < showDropdown.length; i++) {
showDropdown[i].style.display = display;
}
}
function openDialog(title, description, color, isNode) {
dialog = document.getElementById("editDialog").ej2_instances[0];
dialog.header = title;
if (isNode) {
hideClassElement('.showDropdown', 'none');
hideClassElement('.showLabel', 'block');
document.getElementById("Description").value = description;
document.getElementById("Color").value = color;
}
else {
hideClassElement('.showDropdown', 'block');
hideClassElement('.showLabel', 'none');
document.getElementById("SourceId").value = description;
document.getElementById("TargetId").value = color;
}
dialog.show();
}
@*custom code end*@
//Returns an node text collection in diagram.
function getDataSource() {
diagram = document.getElementById('diagram').ej2_instances[0];
var i;
nodeData = [];
for (i = 0; i < diagram.nodes.length; i++) {
var node = diagram.nodes[i];
var element = { Name: node.id, Label: node.Description };
nodeData.push(element);
}
return nodeData;
}
</script>
}
@section ActionDescription{
<p>
This sample demonstrates generating a diagram by reading data from the database, and updating it with newly inserted/updated/deleted nodes and connectors through web services.
</p>
}
@section Meta{
<meta name="description" content="This sample demonstrates generating a diagram by reading data from the database, and updating it with newly inserted/updated/deleted nodes and connectors." />
}
@section Description{
<p>
This example shows how the user reads the data source and performs add, edit, delete of data in the data source
at runtime. The <code>crudAction</code> property of the <code>dataSourceSettings</code> and <code>crudAction</code> property of the
<code>connectionDataSource</code> allow you to define the server-side method name for <code>create</code>, <code>read</code>, <code>update</code>, and
<code>delete</code> operations.
</p>
<p>
The <code>insertData</code> method is used to send the newly added/inserted data from client to server side. Likewise,
<code>updateData</code> and <code>removeData</code> are used to send the updated and deleted diagram elements to the server.
</p>
<br>
}