-
Notifications
You must be signed in to change notification settings - Fork 0
/
dhx.ui.desktop.js
executable file
·264 lines (238 loc) · 8.25 KB
/
dhx.ui.desktop.js
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
/*jslint browser: true, devel: true, eqeq: true, newcap: true, nomen: true, white: true */
/*global $dhx, dhtmlx, dhtmlXLayoutObject */
$dhx.ui.desktop = {
version: '1.0.3'
, database : 'juris'
, ws : 'ws://10.0.0.9:4000/'
, socket : ''
, user_settings : null
, wallpappers_path : $dhx.ui.cdn_address + "/dhx/ui/desktop/assets/wallpapers/"
, readUserSettings : function( c ){
var that = $dhx.ui
, self = that.desktop,
schema = that.data.model.db[self.database].schema;
schema.desktop_config.search.where({
query: {
and: { user_id : $dhx.ui.$Session.user_id},
},
onFound: function(record_id, record, tx, event) {
},
onReady: function(records, tx, event) {
if( records.length > 0 )
{
//$dhx.debug.log( records[0] );
$dhx.ui.desktop.user_settings = records[0];
$dhx.ui.$Session.latinize = $dhx.ui.desktop.user_settings.latinize;
$dhx.ui.$Session.capitalize = $dhx.ui.desktop.user_settings.capitalize;
if( c.onSuccess ) c.onSuccess()
}
else
{
$dhx.notify('Settings error', 'could not find settings for this user: ' + $dhx.ui.$Session.user_id + '\nDesktop can not start', 'icons/db.png');
}
},
onerror: function() {
$dhx.notify('Settings error', 'could not find settings for this user: ' + $dhx.ui.$Session.user_id + '\nDesktop can not start', 'icons/db.png');
}
});
}
, start: function (c) {
var that = $dhx.ui
, self = that.desktop,
tmessage = 'T-Rex is attacking in';
if( $dhx.jDBdStorage.get('$dhx.ui.desktop.isOnline') == 'yes' )
{
$dhx.notify('Loading error', 'You can not use this application in two tabs. Please use another browser', 'icons/db.png');
return;
}
$dhx.debug.time(tmessage);
dhtmlx.message.position="bottom";
$dhx.REST.API.login({
onSuccess : function(){
$dhx.REST.API.get({
resource: "/database/getmodel"
, format: "json"
, payload: ""
, onSuccess: function (request) {
var json = JSON.parse(request.response);
if (json.status == "success") {
//$dhx.debug.log(json);
$dhx.ui.data.model.start({
db: $dhx.ui.temp.db
, version: json.version
, schema: json.schema
, settings: json.settings
, records: json.records
, output_tables: json.output_tables
, onSuccess: function () {
self.readUserSettings({
onSuccess: function () {
$dhx.ui.desktop.socket = new $dhx.socket.service({
resource: $dhx.ui.desktop.ws
, reConnect: true
, onOpen: function (messageEvent, isReconnect) {
$dhx.ui.desktop.socket.send({
message: $dhx.ui.$Session.user + ' is online'
, action: 'notify all users'
});
if(self.view.TopBar.quick_tools_socket)
{
self.view.TopBar.quick_tools_socket.style.backgroundImage = 'url('+ $dhx.ui.cdn_address + 'dhx/ui/desktop/assets/icons/socket.gif)';
self.view.TopBar.quick_tools_socket.title = $dhx.ui.language.realtime_communication_is_on;
}
if( isReconnect )
{
}
else
{
$dhx.jDBdStorage.storeObject('$dhx.ui.desktop.isOnline', 'yes');
window.onbeforeunload = function(e) {
$dhx.jDBdStorage.storeObject('$dhx.ui.desktop.isOnline', 'no');
};
$dhx.ui.desktop.view.render({});
$dhx.debug.timeEnd(tmessage);
}
}
, onClose: function (messageEvent) {
if(self.TopBar.quick_tools_socket)
{
self.view.TopBar.quick_tools_socket.style.backgroundImage = 'url('+ $dhx.ui.cdn_address + 'dhx/ui/desktop/assets/icons/socket_disconnected.png)';
self.view.TopBar.quick_tools_socket.title = $dhx.ui.language.realtime_communication_is_off;
}
}
, onBeforeClose: function (user_id) {
}
, onBeforeSend: function () {
}
, onMessage: function (message, messageEvent) {
if(self.view.TopBar.quick_tools_socket)
{
var myImage = new Image();
myImage.src = $dhx.ui.cdn_address + 'dhx/ui/desktop/assets/icons/socket.gif?uid=' + (new Date().getTime());
myImage.onload = function(){
//self.view.TopBar.quick_tools_socket.style.backgroundImage = 'none';
self.view.TopBar.quick_tools_socket.style.backgroundImage = 'url('+myImage.src+')';
}
}
if (message.action) {
if (message.action == 'notify all users') {
dhtmlx.message({
//type: "error",
text: message.message
});
}
else {
$dhx.jDBdStorage.storeObject('message.' + message.topic, JSON.stringify(message));
$dhx.MQ.oldPublish(message.topic, message);
}
}
}
, onError: function (messageEvent) {
$dhx.debug.timeEnd(tmessage);
}
});
}
, onFail: function () {
$dhx.debug.timeEnd(tmessage);
dhtmlx.message({
type: "error"
, text: 'Any configuration was found for user ' + $dhx.ui.$Session.user_id
});
}
}); // end readUserSettings
}
, onFail: function () {
$dhx.debug.timeEnd(tmessage);
}
}); // end model start
}
}
, onFail: function (request) {
//var json = JSON.parse(request.response);
$dhx.debug.timeEnd(tmessage);
} // end request model
});
}
,onFail : function(){
$dhx.debug.timeEnd(tmessage);
dhtmlx.message({
type: "error",
text: 'Denied access'
});
}
})
}
};
$dhx.ui.desktop.application = {
cruder: function (c) {
this.summary = c.summary || '$dhx application';
this.icon = c.icon || 'bogus.png';
this.database = c.database
this.collection = c.collection
this.appId = '$dhx.ui.crud.simple.' + c.collection + '_app';
this.appName = 'cruder ' + c.collection;
this.module = {};
this.summary = c.summary || '$dhx application';
this.column_to_search_id = c.column_to_search_id || false;
this.column_to_search_index = c.column_to_search_index || false;
}
, custom: function (c) {
this.appName = c.appName;
this.appId = c.appId;
this.database = c.database
this.collection = c.collection
this.summary = c.summary || '$dhx application';
this.icon = c.icon || 'bogus.png';
this.module = c.module;
}
}
$dhx.ui.desktop.Registry = {
programs: [
]
, cruders: [
new $dhx.ui.desktop.application.cruder({
summary: ''
, icon: 'persons.png'
, collection: 'entidades'
, database: 'juris'
, summary: 'Cadastro de pessoas'
, column_to_search_id : 'entidade_id'
, column_to_search_index : 'nome'
})
, new $dhx.ui.desktop.application.cruder({
summary: ''
, icon: 'group.png'
, collection: 'grupos'
, database: 'juris'
, summary: 'Cadastro de grupo de usuário'
, column_to_search_id : 'grupo_id'
, column_to_search_index : 'grupo'
})
, new $dhx.ui.desktop.application.cruder({
summary: ''
, icon: 'foo.png'
, collection: 'empresas'
, database: 'juris'
, summary: 'Cadastro de Empresas'
, column_to_search_id : 'empresa_id'
, column_to_search_index : 'empresa'
})
, new $dhx.ui.desktop.application.cruder({
summary: ''
, icon: 'foo.png'
, collection: 'desktop_wallpapers'
, database: 'juris'
, summary: 'Cadastro de wallpapers'
, column_to_search_id : 'desktop_wallpaper_id'
, column_to_search_index : 'name'
}), new $dhx.ui.desktop.application.cruder({
summary: ''
, icon: 'foo.png'
, collection: 'desktop_config'
, database: 'juris'
, summary: 'Configurações de desktop'
//, column_to_search_id : 'desktop_config_id'
//, column_to_search_index : 'desktop_config'
})
]
};