/
form_remove_from_cloud.go
137 lines (121 loc) · 3.83 KB
/
form_remove_from_cloud.go
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
package forms
import (
"github.com/gazercloud/gazernode/client"
"github.com/gazercloud/gazernode/system/public_channel"
"github.com/gazercloud/gazerui/uicontrols"
"github.com/gazercloud/gazerui/uiinterfaces"
)
type FormRemoveFromCloud struct {
uicontrols.Dialog
client *client.Client
txtUnitName *uicontrols.TextBox
txtError *uicontrols.TextBlock
lvChannels *uicontrols.ListView
chkAllItems *uicontrols.CheckBox
items []string
allItems []string
currentChannelIds []string
preferredChannels []string
}
func NewFormRemoveFromCloud(parent uiinterfaces.Widget, client *client.Client, items []string, allItems []string, preferredChannels []string) *FormRemoveFromCloud {
var c FormRemoveFromCloud
c.client = client
c.items = items
c.allItems = allItems
c.preferredChannels = preferredChannels
c.InitControl(parent, &c)
pContent := c.ContentPanel().AddPanelOnGrid(0, 0)
pLeft := pContent.AddPanelOnGrid(0, 0)
pLeft.SetPanelPadding(0)
//pLeft.SetBorderRight(1, c.ForeColor())
pLeft.SetMinWidth(100)
pRight := pContent.AddPanelOnGrid(1, 0)
pButtons := c.ContentPanel().AddPanelOnGrid(0, 1)
/*img := pLeft.AddImageBoxOnGrid(0, 0, uiresources.ResImageAdjusted("icons/material/image/drawable-hdpi/ic_blur_on_black_48dp.png", c.ForeColor()))
img.SetScaling(uicontrols.ImageBoxScaleAdjustImageKeepAspectRatio)
img.SetMinHeight(64)
img.SetMinWidth(64)*/
pLeft.AddVSpacerOnGrid(0, 1)
pRight.AddTextBlockOnGrid(0, 0, "Select cloud channel:")
c.lvChannels = pRight.AddListViewOnGrid(0, 1)
c.lvChannels.AddColumn("Channel Id", 200)
c.lvChannels.AddColumn("Name", 200)
c.lvChannels.OnSelectionChanged = func() {
c.currentChannelIds = make([]string, 0)
if len(c.lvChannels.SelectedItems()) > 0 {
for _, acc := range c.lvChannels.SelectedItems() {
channelId := acc.TempData
c.currentChannelIds = append(c.currentChannelIds, channelId)
}
}
}
c.chkAllItems = pRight.AddCheckBoxOnGrid(0, 2, "All the items of the unit")
c.chkAllItems.SetChecked(true)
c.loadChannels()
pButtons.AddHSpacerOnGrid(0, 0)
btnOK := pButtons.AddButtonOnGrid(1, 0, "OK", nil)
btnOK.SetMinWidth(70)
btnCancel := pButtons.AddButtonOnGrid(2, 0, "Cancel", nil)
btnCancel.SetMinWidth(70)
c.TryAccept = func() bool {
c.currentChannelIds = make([]string, 0)
if len(c.lvChannels.SelectedItems()) > 0 {
for _, ch := range c.lvChannels.SelectedItems() {
channelId := ch.TempData
c.currentChannelIds = append(c.currentChannelIds, channelId)
}
}
if len(c.currentChannelIds) > 0 {
itemsToRemove := c.items
if c.chkAllItems.IsChecked() {
itemsToRemove = c.allItems
}
c.client.CloudRemoveItems(c.currentChannelIds, itemsToRemove, func(err error) {
if err == nil {
c.TryAccept = nil
c.Accept()
} else {
c.txtError.SetText(err.Error())
}
})
}
return false
}
c.SetAcceptButton(btnOK)
c.SetRejectButton(btnCancel)
return &c
}
func (c *FormRemoveFromCloud) loadChannels() {
c.client.GetCloudChannels(func(channels []public_channel.ChannelInfo, err error) {
c.lvChannels.RemoveItems()
for _, s := range channels {
lvItem := c.lvChannels.AddItem(s.Id)
lvItem.SetValue(1, s.Name)
lvItem.TempData = s.Id
lvItem.SetUserData("channelName", s.Name)
}
c.lvChannels.ClearSelection()
if len(c.preferredChannels) > 0 {
for i := 0; i < c.lvChannels.ItemsCount(); i++ {
item := c.lvChannels.Item(i)
for _, pCh := range c.preferredChannels {
if pCh == item.TempData {
c.lvChannels.SelectItemSelection(i, true)
}
}
}
} else {
if c.lvChannels.ItemsCount() > 0 {
c.lvChannels.SelectItem(0)
}
}
})
}
func (c *FormRemoveFromCloud) OnInit() {
c.Dialog.OnInit()
c.SetTitle("Remove from cloud")
c.Resize(600, 400)
}
func (c *FormRemoveFromCloud) SetAllItemsCheckBox(checked bool) {
c.chkAllItems.SetChecked(checked)
}