-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewItemDialog.lua
106 lines (96 loc) · 2.95 KB
/
NewItemDialog.lua
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
local u = require('common/Utils')
local class = require('thirdparty/middleclass/middleclass');
local nid = class("NewItemDialog");
local function itemText(item)
if item and item.class then
return tostring(item.class).." : "..tostring(item);
else
return "";
end
end
function nid:initialize(id, parent, list, title)
if title == nil then
title = "Create new item";
end
self.newItemData = { id = id, parent = parent };
self._parentItemsList = list;
self.open = true;
self.canceled = false;
self.title = title;
Slab.OpenDialog("NewItemDialog");
end
function nid:parentItemSelection()
local parent = self.newItemData.parent;
if parent then
Slab.Text("Parent");
Slab.BeginLayout("ParentInfoLayout", { Columns = 2 });
Slab.SetLayoutColumn(1);
Slab.Text("Parent type:");
Slab.Text("Parent id:");
Slab.SetLayoutColumn(2);
Slab.Text(parent.class.name);
Slab.Text(tostring(parent));
Slab.EndLayout();
Slab.Separator();
end
local list = self._parentItemsList;
if list ~= nil and #list > 0 then
Slab.BeginLayout("ParentSelectionLayout", { Columns = 1 })
Slab.SetLayoutColumn(1);
if parent == nil then
parent = list[1];
end
if Slab.BeginComboBox("ActiveParents", { Selected = itemText(parent) }) then
for _, item in ipairs(list) do
if type(item) == 'table' then
if Slab.TextSelectable(itemText(item)) then
parent = item;
end
else
if Slab.TextSelectable(item) then
parent = nil;
end
end
end
Slab.EndComboBox();
end
Slab.EndLayout();
end
self.newItemData.parent = parent;
end
function nid:idInput()
Slab.BeginLayout("NewSourceDialogLayout", { Columns = 2 });
Slab.SetLayoutColumn(1);
Slab.Text("Name:");
Slab.SetLayoutColumn(2);
if Slab.Input("SourceId", { Text = self.newItemData.id, ReturnOnText = true }) then
self.newItemData.id = Slab.GetInputText();
end
Slab.EndLayout();
end
function nid:buttons()
Slab.BeginLayout("ButtonsLayout", { Columns = 2, AlignX = "center" });
Slab.SetLayoutColumn(1);
if Slab.Button("Create") then
Slab.CloseDialog("NewItemDialog");
self.open = false;
end
Slab.SetLayoutColumn(2);
if Slab.Button("Cancel") then
Slab.CloseDialog("NewItemDialog");
self.open = false;
self.canceled = true;
end
Slab.EndLayout();
end
function nid:update()
if Slab.BeginDialog("NewItemDialog", { Title = self.title, AllowResize = true, IsOpen = self.open }) then
self:parentItemSelection();
Slab.Separator();
self:idInput();
Slab.Separator();
self:buttons();
Slab.EndDialog();
end
end
return nid;