AddUsersToRoomPopup.qml 6.21 KB
Newer Older
armin's avatar
armin committed
1
2
3
4
5
import QtQuick 2.8
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
import "qrc:/qml/various"

6
import "qrc:/javascript/print.js" as Print
armin's avatar
armin committed
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

Popup {
    id: addUsersToRoomPopup
    x: 50
    y: 25
    property string channelName
    modal: true
    focus: true
    closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
    ColumnLayout {
        anchors.fill: parent

        TextField {
            id: addUserToRoom
            placeholderText: qsTr("add user to room")
            background: Rectangle {
                //                    anchors.horizontalCenter: parent
                implicitWidth: 200
                implicitHeight: 31

                color: "#ffffff"
                Rectangle {
                    height: 1
                    anchors.left:parent.left
                    anchors.right: parent.right
                    color: "#dfdfdf"
                    anchors.bottom: parent.bottom
                }
            }
            onTextChanged: {
                if (addUserToRoom.text !== "") {
                    rocketChatController.getUserSuggestions(
                                addUserToRoom.text)
                } else {
                    userSuggestionsModel.clear()
                }
            }
            Connections {
                target: rocketChatController
                onSuggestionsReady: {
                    var suggestionsParsed = suggestions
                    userSuggestionsModel.clear()
                    for (var currentSuggestion in suggestionsParsed) {
                        var val = suggestionsParsed[currentSuggestion]
                        userSuggestionsModel.append(val)
                    }
                }
            }
        }
        RowLayout{
            spacing: 1
            height: 300
            width: 500
            implicitWidth: 500
            ListModel {
                id: userSuggestionsModel
            }

            ListView {
                id: userSuggestions
                model: userSuggestionsModel
                width: parent.width/3
                height: 150
                clip: true
                delegate: Rectangle {
                    height: 30;
                    anchors.left:parent.left
                    anchors.right: parent.right
                    Row {
                        anchors.left:parent.left
                        anchors.right: parent.right
                        height: 20
                        Button {
                            text: model.username
                            background:
                                Rectangle{
                                    implicitHeight: 20
                                   // implicitWidth: 20
                                }


                            onPressed: {
                                var duplicateEntry = false
                                for (var i=0; i<userSelectedModel.count;i++){
                                    var username = userSelectedModel.get(i).username;
                                    if(username === model.username){
                                        duplicateEntry = true;
                                        break;
                                    }

                                }
                                if(!duplicateEntry){
                                    userSelectedModel.append({"username":model.username});
                                }
                            }
                        }
                    }
                }
            }
            ListModel{
                id: userSelectedModel
            }
            ListView{
                id: userSelected
                model: userSelectedModel
                width: parent.width/3
                height: 150
                clip: true
                delegate: Row{
                    anchors.left:parent.left
                    anchors.right: parent.right
                    Text{
                        text:model.username
                    }
                    Button{
                        font.family: Fonts.fontello.name
                        text:"\u0052"
                        background: Rectangle{
                            width: 20
                            height: 20
                        }

                        onPressed: {
                            for (var i=0; i<userSelectedModel.count;i++){
                                var username = userSelectedModel.get(i).username;
                                if(username === model.username){
                                    userSelectedModel.remove(i);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }

        RowLayout {
            spacing: 2
            Button {
                id: createNewRoomButton
                text: qsTr("add")
                onPressed: {
                    var userArray = [];
                    var userList="";
                    for(var i=0; i< userSelectedModel.count; i++){
                        userArray.push(userSelectedModel.get(i));
                        var userObj = userSelectedModel.get(i)
                        userList += userSelectedModel.get(i).username+",";
                    }

                    rocketChatController.addUsersToChannel(
                                "default", channelName, userList)

                    addUserToRoom.text = ""
                    userSuggestionsModel.clear()
                    userSelectedModel.clear()
                    addUserToRoom.clear()
                    addUsersToRoomPopup.close()
                }

            }
            Button {
                id: cancel
                text: qsTr("cancel")
                onPressed: {
                    addUserToRoom.text = ""
                    userSuggestionsModel.clear()
                    userSelectedModel.clear()
                    addUserToRoom.clear()
                    addUsersToRoomPopup.close()
                }
            }
        }
    }
}