Skip to content

Commit 04c7a8b

Browse files
committed
USERS / CRON / IP ready. DNS (partly). JS form validators written. Added functionality
1 parent ea5a8a2 commit 04c7a8b

File tree

15 files changed

+568
-297
lines changed

15 files changed

+568
-297
lines changed

web/js/_settings.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,38 @@ App.i18n.getMessage = function(key)
88
}
99

1010

11-
1211
// Constants
13-
App.Constants.IP_FORM_ID = 'ip-form';
14-
App.Constants.DNS_FORM_ID = 'dns-form';
15-
App.Constants.USER_FORM_ID = 'user-form';
16-
App.Constants.WEB_DOMAIN_FORM_ID = 'web_domain-form';
17-
App.Constants.DB_FORM_ID = 'db-form';
18-
App.Constants.CRON_FORM_ID = 'cron-form';
19-
20-
App.Settings.ajax_url = 1;
21-
App.Settings.uri = location.href.replace('index.html', '');
22-
App.Settings.popup_conf = { 'centered' : true, 'bgcolor' : '#FF0000', 'lightboxSpeed' : 'fast', 'destroyOnClose': true };
12+
App.Constants.IP_FORM_ID = 'ip-form';
13+
App.Constants.DNS_FORM_ID = 'dns-form';
14+
App.Constants.USER_FORM_ID = 'user-form';
15+
App.Constants.WEB_DOMAIN_FORM_ID = 'web_domain-form';
16+
App.Constants.DB_FORM_ID = 'db-form';
17+
App.Constants.CRON_FORM_ID = 'cron-form';
18+
App.Constants.IP = 'IP';
19+
App.Constants.DNS = 'DNS';
20+
App.Constants.SUSPENDED_YES = 'yes';
21+
App.Constants.DNS_TEMPLATES = {'default': 'Default'};
2322

24-
App.Constants.SUSPENDED_YES = 'yes';
23+
// Settings
24+
App.Settings.USER_VISIBLE_NS = 2;
25+
App.Settings.NS_MIN = 2;
26+
App.Settings.NS_MAX = 8;
27+
App.Settings.ajax_url = 1;
28+
App.Settings.uri = location.href.replace('index.html', '');
29+
App.Settings.popup_conf = { 'centered' : true, 'bgcolor' : '#FF0000', 'lightboxSpeed' : 'fast', 'destroyOnClose': true };
2530

26-
App.Constants.IP = 'IP';
27-
App.Constants.DNS = 'DNS';
28-
29-
App.Constants.DNS_TEMPLATES = {'default': 'Default'};
3031

32+
// Messages
3133
App.Messages.total_dns_records = {single: 'total record', plural: 'total records'};
32-
3334
App.Messages.get = function(key, plural) {
3435
if ('undefined' != typeof App.Messages[key]) {
3536
return plural ? App.Messages[key].plural : App.Messages[key].single;
3637
}
3738
}
3839

40+
// Empty
41+
App.Empty = {};
42+
App.Empty.USER = {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','LNAME':'', 'FNAME':'','NS1':'','NS2':'','NS3':'','NS4':'','NS5':'','NS6':'','NS7':'','NS8':''};
3943

4044
App.Settings.getMethodName = function(action)
4145
{

web/js/actions.js

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ App.Actions.save_form = function(evt) {
103103
else { // OLD ITEM, UPDATING IT
104104
var source = $(elm).find('.source').val();
105105
var values = App.Helpers.getFormValues(elm);
106-
if(App.Validate.form(values, $('#'+elm_id))) {
107-
App.Model.add(values, source);
106+
if(App.Validate.form(values, $('#'+elm_id))) {
108107
App.Model.update(values, source, elm);
109108
}
110109
}
@@ -146,12 +145,49 @@ App.Actions.cancel_form = function(evt, params) {
146145

147146
App.Actions.suspend = function(evt)
148147
{
149-
alert('Suspend?');
148+
var confirmed = confirm('Suspend?');
149+
if (!confirmed) {
150+
return ;
151+
}
152+
var elm = $(evt.target);
153+
var row = elm.parents('.row');
154+
155+
var options = row.find('.source').val();
156+
App.Ajax.request(App.Env.world+'.suspend', {spell: options}, function(reply) {
157+
if (reply.result) {
158+
//var tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general');
159+
//$(elm).replaceWith(tpl.finalize());
160+
App.Pages.prepareHTML();
161+
App.Helpers.updateScreen();
162+
}
163+
else {
164+
return App.Helpers.alert('Failed to suspend');
165+
}
166+
});
150167
}
151168

152169
App.Actions.unsuspend = function(evt)
153170
{
154-
alert('Unsuspend?');
171+
var confirmed = confirm('Unsuspend?');
172+
if (!confirmed) {
173+
return ;
174+
}
175+
176+
var elm = $(evt.target);
177+
var row = elm.parents('.row');
178+
179+
var options = row.find('.source').val();
180+
App.Ajax.request(App.Env.world+'.unsuspend', {spell: options}, function(reply) {
181+
if (reply.result) {
182+
//var tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general');
183+
//$(elm).replaceWith(tpl.finalize());
184+
App.Pages.prepareHTML();
185+
App.Helpers.updateScreen();
186+
}
187+
else {
188+
return App.Helpers.alert('Failed to suspend');
189+
}
190+
});
155191
}
156192

157193
// do_action_form_help
@@ -230,3 +266,56 @@ App.Actions.backup_db = function(evt)
230266
{
231267
alert('TODO');
232268
}
269+
270+
App.Actions.add_form_ns = function(evt)
271+
{
272+
var elm = $(evt.target);
273+
274+
form = elm.parents('.form:first');
275+
var total_nses = $(form).find('.ns-entry').length;
276+
if (total_nses == App.Settings.NS_MAX) {
277+
return App.Helpers.alert('Maximum number of NS cannot be more than ' + App.Settings.NS_MAX);
278+
}
279+
280+
var tpl = App.Templates.get('NS_INPUT', 'user');
281+
tpl.set(':NAME', '');
282+
tpl.set(':NS_LABEL', 'NS');
283+
elm.before(tpl.finalize());
284+
285+
if ((total_nses + 1) == App.Settings.NS_MAX ) { // added last NS
286+
$('.additional-ns-add', form).addClass('hidden');
287+
}
288+
289+
$(form).find('.ns-entry').each(function(i, o)
290+
{
291+
$(o).find('label').text('NS #' + (i + 1));
292+
$(o).find('input').attr('name', 'NS' + (i + 1));
293+
});
294+
}
295+
296+
App.Actions.delete_ns = function(evt)
297+
{
298+
var elm = $(evt.target);
299+
300+
form = elm.parents('.form:first');
301+
var total_nses = $(form).find('.ns-entry').length;
302+
if (total_nses == App.Settings.NS_MIN) {
303+
return App.Helpers.alert('Minimum number of NS is ' + App.Settings.NS_MIN);
304+
}
305+
306+
var form = elm.parents('.form:first');
307+
$(elm).parents('.form:first').find('.additional-ns-add').removeClass('hidden');
308+
$(elm).parents('.ns-entry').remove();
309+
310+
$(form).find('.ns-entry').each(function(i, o)
311+
{
312+
$(o).find('label').text('NS #' + (i + 1));
313+
$(o).find('input').attr('name', 'NS' + (i + 1));
314+
});
315+
}
316+
317+
App.Actions.view_full_ns_list = function(evt)
318+
{
319+
var elm = $(evt.target);
320+
App.Helpers.openInnerPopup(elm, $(elm).parents('.prop-box').find('.ns-full-list:first').html());
321+
}

web/js/html.js

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
App.HTML.setTplKeys = function(tpl, o, empty)
22
{
3-
var empty = empty || '-';
3+
var empty = empty || '';
44
fb.log(empty);
55
tpl.set(':source', $.toJSON(o).replace(/'/gi, "\\'"))
66
$(o).each(function(i, object)
@@ -12,7 +12,7 @@ App.HTML.setTplKeys = function(tpl, o, empty)
1212
tpl.set(':' + key, val || '');
1313
}
1414
else {
15-
tpl.set(':' + key, val || '-');
15+
tpl.set(':' + key, val || '');
1616
}
1717
});
1818
});
@@ -138,14 +138,14 @@ App.HTML.Build.ip_entry = function(o)
138138
var tpl = App.Templates.get('ENTRY', 'ip');
139139
tpl = App.HTML.setTplKeys(tpl, o);
140140

141-
if (App.Constants.SUSPENDED_YES == o.SUSPENDED) {
141+
/*if (App.Constants.SUSPENDED_YES == o.SUSPENDED) {
142142
var sub_tpl = App.Templates.get('SUSPENDED_TPL_ENABLED', 'ip');
143143
}
144144
else {
145145
var sub_tpl = App.Templates.get('SUSPENDED_TPL_DISABLED', 'ip');
146-
}
146+
}*/
147147

148-
tpl.set(':SUSPENDED_TPL', sub_tpl.finalize());
148+
tpl.set(':SUSPENDED_TPL', '');
149149

150150
return tpl.finalize();
151151
}
@@ -163,14 +163,14 @@ App.HTML.Build.dns_entry = function(o, is_new)
163163
tpl.set(':DATE', now.format("d.mm.yyyy"));
164164
}
165165

166-
if (App.Constants.SUSPENDED_YES == o.SUSPEND) {
166+
/*if (App.Constants.SUSPENDED_YES == o.SUSPEND) {
167167
var sub_tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general');
168168
}
169169
else {
170170
var sub_tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general');
171-
}
171+
}*/
172172

173-
tpl.set(':SUSPENDED_TPL', sub_tpl.finalize());
173+
tpl.set(':SUSPENDED_TPL', '');
174174

175175
return tpl.finalize();
176176
}
@@ -190,13 +190,41 @@ App.HTML.Build.user_entry = function(o, key)
190190
var tpl = App.Templates.get('ENTRY', 'user');
191191
tpl = App.HTML.setTplKeys(tpl, o);
192192

193-
if (App.Constants.SUSPENDED_YES == o.SUSPENDED) {
193+
/*if (App.Constants.SUSPENDED_YES == o.SUSPENDED) {
194194
var sub_tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general');
195195
}
196196
else {
197197
var sub_tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general');
198+
}*/
199+
tpl.set(':SUSPENDED_TPL', '');//sub_tpl.finalize());
200+
201+
var ns = [];
202+
var ns_full = [];
203+
fb.info(o);
204+
$([1,2,3,4,5,6,7,8]).each(function(i, index)
205+
{
206+
if (o['NS'+index].trim() != '') {
207+
var tpl_ns = App.Templates.get('NS_RECORD', 'user');
208+
tpl_ns.set(':NAME', o['NS'+index]);
209+
var tpl_finalized = tpl_ns.finalize();
210+
ns_full[ns_full.length++] = tpl_finalized;
211+
if (i < App.Settings.USER_VISIBLE_NS) {
212+
ns[ns.length++] = tpl_finalized;
213+
}
214+
}
215+
});
216+
217+
if (ns_full.length <= App.Settings.USER_VISIBLE_NS) {
218+
tpl.set(':NS', ns.done());
219+
}
220+
else {
221+
var ns_custom = App.Templates.get('NS_MINIMIZED', 'user');
222+
ns_custom.set(':NS_MINI', ns.done());
223+
ns_custom.set(':NS_FULL', ns_full.done());
224+
ns_custom.set(':MORE_NUMBER', Math.abs(App.Settings.USER_VISIBLE_NS - ns_full.length));
225+
tpl.set(':NS', ns_custom.finalize());
198226
}
199-
tpl.set(':SUSPENDED_TPL', sub_tpl.finalize());
227+
200228

201229
return tpl.finalize();
202230
}
@@ -220,7 +248,22 @@ App.HTML.Build.user_form = function(options, id)
220248
tpl.set(':save_button', 'SAVE');
221249
}
222250

223-
options = !App.Helpers.isEmpty(options) ? options : {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','LNAME':'', 'FNAME':''};
251+
options = !App.Helpers.isEmpty(options) ? options : App.Empty.USER;
252+
253+
// NS
254+
var ns = [];
255+
$([3,4,5,6,7,8]).each(function(i, index)
256+
{fb.warn(options);
257+
if (options['NS'+index].trim() != '') {
258+
var tpl_ns = App.Templates.get('NS_INPUT', 'user');
259+
tpl_ns.set(':NS_LABEL', 'NS #' + (index));
260+
tpl_ns.set(':NAME', options['NS'+index]);
261+
ns[ns.length++] = tpl_ns.finalize();
262+
}
263+
});
264+
ns[ns.length++] = App.Templates.get('PLUS_ONE_NS', 'user').finalize();
265+
266+
tpl.set(':NS', ns.done());
224267

225268
tpl = App.HTML.setTplKeys(tpl, options, true);
226269
tpl = App.HTML.Build.user_selects(tpl, options);
@@ -491,7 +534,7 @@ App.HTML.Build.db_selects = function(tpl, options)
491534
App.HTML.Build.ip_selects = function(tpl, options)
492535
{
493536
// OWNER
494-
var users = App.Env.initialParams.IP.SYS_USERS || ['Skid'];
537+
var users = App.Env.initialParams.IP.SYS_USERS;
495538
var opts = App.HTML.Build.options(users, options.OWNER);
496539
tpl.set(':owner_options', opts);
497540

web/js/model.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ App.Model.add = function(values, source_json)
7777
App.Ref.CONTENT..replaceWith(tpl);*/
7878
// todo: reply.data;
7979
App.Pages.prepareHTML();
80+
App.Helpers.updateScreen();
8081
}
8182
});
8283
}
@@ -114,8 +115,11 @@ App.Model.update = function(values, source_json, elm)
114115
App.Helpers.Warn('Changes were not applied');
115116
}
116117
else {
117-
var tpl = App.HTML.Build[build_method](reply.data);
118+
/*var tpl = App.HTML.Build[build_method](reply.data);
118119
$(elm).replaceWith(tpl);
120+
App.Helpers.updateScreen();*/
121+
// todo: reply.data;
122+
App.Pages.prepareHTML();
119123
App.Helpers.updateScreen();
120124
}
121125
// TODO: !

0 commit comments

Comments
 (0)