1
|
define([
|
2
|
"dojo/_base/array",
|
3
|
"dojo/_base/connect",
|
4
|
"stabile/grid",
|
5
|
"steam2/user",
|
6
|
"steam2/models/Server",
|
7
|
"dojox/validate",
|
8
|
"dijit/form/ValidationTextBox",
|
9
|
"dojox/validate/web",
|
10
|
"dojox/grid/cells/_base"
|
11
|
],function(arrayUtil, connect, grid, user, Server, validate){
|
12
|
|
13
|
var users = {
|
14
|
|
15
|
grid: {},
|
16
|
|
17
|
_searchQuery: "username:*",
|
18
|
_statusQuery: "status:all",
|
19
|
_inited: false,
|
20
|
storeQuery: "username:*",
|
21
|
model : function(args){
|
22
|
return dojo.mixin({
|
23
|
username: "",
|
24
|
password: "",
|
25
|
fullname: "",
|
26
|
email: "",
|
27
|
phone: "",
|
28
|
alertemail: "",
|
29
|
alertphone: "",
|
30
|
opemail: "",
|
31
|
opphone: "",
|
32
|
privileges: "",
|
33
|
accounts: "",
|
34
|
accountsprivileges: "",
|
35
|
allowfrom: "",
|
36
|
storagequota: 0,
|
37
|
nodestoragequota: 0,
|
38
|
memoryquota: 0,
|
39
|
vcpuquota: 0,
|
40
|
externalipquota: 0,
|
41
|
status: "new"
|
42
|
}, args || {});
|
43
|
},
|
44
|
|
45
|
/** object name - for reflective lookup */
|
46
|
name : "users",
|
47
|
|
48
|
sortInfo: 0,
|
49
|
|
50
|
structure : [
|
51
|
{ field : 'username', name : "Username", width : "170px", hidden: true },
|
52
|
{ field : 'fullname', name : 'Full name', width : "auto" },
|
53
|
{ field : 'email', name : 'Email', width : "auto" },
|
54
|
{ field : 'privileges', name : 'Privileges <a href="//www.origo.io/info/stabiledocs/web/users/privileges" rel="help" target="_blank" class="irigo-tooltip">help</a>', width : "100px" },
|
55
|
{ field : 'action', name : 'Action', width : 'auto', hidden: user.is_readonly,
|
56
|
formatter : function(val, rowIdx, cell) {
|
57
|
var item = this.grid.getItem(rowIdx);
|
58
|
return users.getActionButtons(item);
|
59
|
}
|
60
|
}
|
61
|
],
|
62
|
|
63
|
dialogStructure : [
|
64
|
{ field : "username", name : "Username", type : "dijit.form.ValidationTextBox", attrs: {
|
65
|
required: "true",
|
66
|
onChange: "if ((this.value.indexOf('@')!=-1) && $('#email').val()=='') {$('#email').val(this.value);}"
|
67
|
}
|
68
|
},
|
69
|
{ field : "password", name : "Password", type : "dijit.form.TextBox", attrs: {type:"password"}},
|
70
|
{ field : "fullname", name : "Full name", type: "dijit.form.ValidationTextBox", attrs: {regExp: ".+", required:true}},
|
71
|
{ field : "email", name : "Email", type: "dijit.form.ValidationTextBox", attrs: {regExp: ".+", required:true}},
|
72
|
{ field : "alertemail", name : "Alert email", type: "dijit.form.TextBox", help: "users/alert-email"},
|
73
|
{ field : "phone", name : "Phone", type: "dijit.form.TextBox"},
|
74
|
{ field : "privileges", name : "Privileges", type: "dijit.form.TextBox", help: "users/privileges"},
|
75
|
{ field : "accounts", name : "Other accounts", type: "dijit.form.TextBox", help: "users/accounts"},
|
76
|
{ field : "accountsprivileges", name : "Privileges to other accounts", type: "dijit.form.TextBox", help: "users/accounts"},
|
77
|
{ field : "allowfrom", name : "Allow login from", type: "dijit.form.TextBox", help: "dashboard/info-tab/allowloginfrom"},
|
78
|
|
79
|
{ field : "storagequota", name : "Storage quota", type: "dijit.form.TextBox", help: "users/quotas", style: "width: 80px;",
|
80
|
extra: function(item) {return "GB (default: " + home.formatters.readableMBytes(IRIGO.user.defaultstoragequota) + " <span id='storage_usage'></span>)";}
|
81
|
},
|
82
|
{ field : "nodestoragequota", name : "Node storage quota", type: "dijit.form.TextBox", help: "users/quotas", style: "width: 80px;",
|
83
|
extra: function(item) {return "GB (default: " + home.formatters.readableMBytes(IRIGO.user.defaultnodestoragequota) + " <span id='nodestorage_usage'></span>)";}
|
84
|
},
|
85
|
{ field : "memoryquota", name : "Memory quota", type: "dijit.form.TextBox", help: "users/quotas", style: "width: 80px;",
|
86
|
extra: function(item) {return "GB (default: " + home.formatters.readableMBytes(IRIGO.user.defaultmemoryquota) + " <span id='memory_usage'></span>)";}
|
87
|
},
|
88
|
{ field : "vcpuquota", name : "vCPU quota", type: "dijit.form.TextBox", help: "users/quotas", style: "width: 80px;",
|
89
|
extra: function(item) {return " (default: " + IRIGO.user.defaultvcpuquota + " <span id='vcpu_usage'></span>)";}
|
90
|
},
|
91
|
{ field : "externalipquota", name : "External IP quota", type: "dijit.form.TextBox", help: "users/quotas", style: "width: 80px;",
|
92
|
extra: function(item) {return " (default: " + IRIGO.user.defaultexternalipquota + " <span id='externalip_usage'></span>)";}
|
93
|
},
|
94
|
{
|
95
|
formatter: function(item) {
|
96
|
return '<td>DNS domains</td><td>' + (item.dnsdomains || IRIGO.user.dnsdomain) + '</td>';
|
97
|
}
|
98
|
},
|
99
|
{
|
100
|
formatter: function(item) {
|
101
|
return '<td>Created</td><td>' + home.timestampToLocaleString(item.created) + '</td>';
|
102
|
}
|
103
|
},
|
104
|
{
|
105
|
formatter: function(item) {
|
106
|
if (item.status == "new") {
|
107
|
return "--";
|
108
|
} else {
|
109
|
return '<td>Modified</td><td>' + home.timestampToLocaleString(item.modified) + '</td>';
|
110
|
}
|
111
|
}
|
112
|
}
|
113
|
],
|
114
|
|
115
|
store : null,
|
116
|
|
117
|
getActionButtons : function(item, include_save){
|
118
|
var busy = ' <img height="18px" alt="busy" src="/stabile/static/img/loader.gif"> ';
|
119
|
if (user.is_readonly) return "";
|
120
|
if (item.status == 'deleting') return busy;
|
121
|
|
122
|
var username = item.username;
|
123
|
var type = this.name;
|
124
|
var privileges = item.privileges;
|
125
|
|
126
|
function actionButton(args){
|
127
|
args.name = username;
|
128
|
args.type = type;
|
129
|
return grid.actionButton(args);
|
130
|
}
|
131
|
|
132
|
var enable = actionButton({'action' :"enable", 'id' :username});
|
133
|
var disable = actionButton({'action' :"disable", 'id' :username});
|
134
|
var resetpassword = actionButton({'action' :"resetpassword", 'id' :username});
|
135
|
var _delete = actionButton({'action' :"deleteentirely", 'id' :username, 'confirm' :true});
|
136
|
var save = (include_save) ? grid.saveButton(type) : "";
|
137
|
var actions = '';
|
138
|
if (privileges.indexOf('d')!=-1) actions += enable;
|
139
|
else if (item.username!=user.username) actions += disable;
|
140
|
if (privileges.indexOf('d')!=-1) actions += _delete;
|
141
|
else actions += resetpassword;
|
142
|
actions += save;
|
143
|
return actions;
|
144
|
},
|
145
|
rowStyler : function(row, item){
|
146
|
if(item.privileges.indexOf("a") != -1){
|
147
|
row.customStyles += "font-weight:bold;";
|
148
|
} else {
|
149
|
row.customStyles = "cursor:pointer;";
|
150
|
}
|
151
|
},
|
152
|
onBeforeDialog : function(item) {
|
153
|
$.get("/stabile/users?action=usagestatus&username="+item.username, function(data) {
|
154
|
$("#storage_usage").text(", usage: " + data.shared_storage.quantity + " GB");
|
155
|
$("#nodestorage_usage").text(", usage: " + data.node_storage.quantity + " GB");
|
156
|
$("#memory_usage").text(", usage: " + data.memory.quantity + " GB");
|
157
|
$("#vcpu_usage").text(", usage: " + data.vcpus.quantity);
|
158
|
$("#externalip_usage").text(", usage: " + data.external_ips.quantity);
|
159
|
})
|
160
|
},
|
161
|
};
|
162
|
|
163
|
users.init = function(){
|
164
|
if (users._inited === true) return "OK";
|
165
|
else users._inited = true;
|
166
|
console.log("initializing users", user);
|
167
|
|
168
|
connect.connect(dijit.byId('users_status_filter_select'), 'onChange', this, this.onStatusFilterChange);
|
169
|
connect.connect(dijit.byId('users_search_query'), 'onChange', this, this.onSearchQueryChange);
|
170
|
|
171
|
users.store = stores.users;
|
172
|
users.domnode = "users-grid";
|
173
|
users.grid = grid.create(users);
|
174
|
users.grid.startup();
|
175
|
|
176
|
dojo.subscribe("users:update", function(task){
|
177
|
if (task.username) {
|
178
|
users.grid.refreshRow(task, "username");
|
179
|
} else {
|
180
|
users.grid.refresh();
|
181
|
}
|
182
|
});
|
183
|
|
184
|
connect.connect(this.grid, '_onFetchComplete', this, function(rows){
|
185
|
if (!user.is_readonly) $("#usersNewButton").show();
|
186
|
if (IRIGO.user.enginelinked) $("#syncusers").show();
|
187
|
});
|
188
|
|
189
|
connect.connect(this.grid, 'onDialog', function(item) {
|
190
|
if (item.status=="new") {
|
191
|
dijit.byId("username").set("readonly", false).focus();
|
192
|
} else {
|
193
|
dijit.byId("username").set("readonly", true);
|
194
|
}
|
195
|
});
|
196
|
|
197
|
this.onShowItem();
|
198
|
};
|
199
|
|
200
|
users.onShowItem = function() {
|
201
|
if (home.usersOnShowItem != null && users.grid.dialog) {
|
202
|
users.grid.dialog.show(home.usersOnShowItem);
|
203
|
home.usersOnShowItem = null;
|
204
|
}
|
205
|
};
|
206
|
|
207
|
|
208
|
users.updateFilter = function(){
|
209
|
var query = this._searchQuery + " AND " + this._statusQuery;
|
210
|
this.grid.store.query = query;
|
211
|
this.grid.filter(query, /*rerender*/true);
|
212
|
};
|
213
|
|
214
|
users.onSearchQueryChange = function(v){
|
215
|
if(v){
|
216
|
this._searchQuery = "username:" +v + "*";
|
217
|
}
|
218
|
else{
|
219
|
this._searchQuery = "username:*";
|
220
|
}
|
221
|
this.updateFilter();
|
222
|
};
|
223
|
|
224
|
users.onStatusFilterChange = function(value){
|
225
|
switch(value){
|
226
|
case "all":
|
227
|
this._statusQuery = "status:all";
|
228
|
break;
|
229
|
default:
|
230
|
this._statusQuery = "status:" + value;
|
231
|
}
|
232
|
this.updateFilter();
|
233
|
};
|
234
|
|
235
|
users.syncUsers = function() {
|
236
|
$("#syncusers").html('Syncing users… <i class="fa fa-cog fa-spin"></i>').prop("disabled", true);
|
237
|
return $.get("/stabile/users?action=syncusers", function(res){$("#syncusers").html('Sync users').prop("disabled", false); server.parseResponse(res);});
|
238
|
}
|
239
|
|
240
|
window.users = users;
|
241
|
return users;
|
242
|
});
|