diff --git a/web/js/_settings.js b/web/js/_settings.js index a70b181f..b2e51b28 100644 --- a/web/js/_settings.js +++ b/web/js/_settings.js @@ -8,34 +8,38 @@ App.i18n.getMessage = function(key) } - // Constants -App.Constants.IP_FORM_ID = 'ip-form'; -App.Constants.DNS_FORM_ID = 'dns-form'; -App.Constants.USER_FORM_ID = 'user-form'; -App.Constants.WEB_DOMAIN_FORM_ID = 'web_domain-form'; -App.Constants.DB_FORM_ID = 'db-form'; -App.Constants.CRON_FORM_ID = 'cron-form'; +App.Constants.IP_FORM_ID = 'ip-form'; +App.Constants.DNS_FORM_ID = 'dns-form'; +App.Constants.USER_FORM_ID = 'user-form'; +App.Constants.WEB_DOMAIN_FORM_ID = 'web_domain-form'; +App.Constants.DB_FORM_ID = 'db-form'; +App.Constants.CRON_FORM_ID = 'cron-form'; +App.Constants.IP = 'IP'; +App.Constants.DNS = 'DNS'; +App.Constants.SUSPENDED_YES = 'yes'; +App.Constants.DNS_TEMPLATES = {'default': 'Default'}; -App.Settings.ajax_url = 1; -App.Settings.uri = location.href.replace('index.html', ''); -App.Settings.popup_conf = { 'centered' : true, 'bgcolor' : '#FF0000', 'lightboxSpeed' : 'fast', 'destroyOnClose': true }; +// Settings +App.Settings.USER_VISIBLE_NS = 2; +App.Settings.NS_MIN = 2; +App.Settings.NS_MAX = 8; +App.Settings.ajax_url = 1; +App.Settings.uri = location.href.replace('index.html', ''); +App.Settings.popup_conf = { 'centered' : true, 'bgcolor' : '#FF0000', 'lightboxSpeed' : 'fast', 'destroyOnClose': true }; -App.Constants.SUSPENDED_YES = 'yes'; - -App.Constants.IP = 'IP'; -App.Constants.DNS = 'DNS'; - -App.Constants.DNS_TEMPLATES = {'default': 'Default'}; +// Messages App.Messages.total_dns_records = {single: 'total record', plural: 'total records'}; - App.Messages.get = function(key, plural) { if ('undefined' != typeof App.Messages[key]) { return plural ? App.Messages[key].plural : App.Messages[key].single; } } +// Empty +App.Empty = {}; +App.Empty.USER = {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','LNAME':'', 'FNAME':'','NS1':'','NS2':'','NS3':'','NS4':'','NS5':'','NS6':'','NS7':'','NS8':''}; App.Settings.getMethodName = function(action) { diff --git a/web/js/actions.js b/web/js/actions.js index 299093f3..ef27f0f4 100644 --- a/web/js/actions.js +++ b/web/js/actions.js @@ -103,8 +103,7 @@ App.Actions.save_form = function(evt) { else { // OLD ITEM, UPDATING IT var source = $(elm).find('.source').val(); var values = App.Helpers.getFormValues(elm); - if(App.Validate.form(values, $('#'+elm_id))) { - App.Model.add(values, source); + if(App.Validate.form(values, $('#'+elm_id))) { App.Model.update(values, source, elm); } } @@ -146,12 +145,49 @@ App.Actions.cancel_form = function(evt, params) { App.Actions.suspend = function(evt) { - alert('Suspend?'); + var confirmed = confirm('Suspend?'); + if (!confirmed) { + return ; + } + var elm = $(evt.target); + var row = elm.parents('.row'); + + var options = row.find('.source').val(); + App.Ajax.request(App.Env.world+'.suspend', {spell: options}, function(reply) { + if (reply.result) { + //var tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general'); + //$(elm).replaceWith(tpl.finalize()); + App.Pages.prepareHTML(); + App.Helpers.updateScreen(); + } + else { + return App.Helpers.alert('Failed to suspend'); + } + }); } App.Actions.unsuspend = function(evt) { - alert('Unsuspend?'); + var confirmed = confirm('Unsuspend?'); + if (!confirmed) { + return ; + } + + var elm = $(evt.target); + var row = elm.parents('.row'); + + var options = row.find('.source').val(); + App.Ajax.request(App.Env.world+'.unsuspend', {spell: options}, function(reply) { + if (reply.result) { + //var tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general'); + //$(elm).replaceWith(tpl.finalize()); + App.Pages.prepareHTML(); + App.Helpers.updateScreen(); + } + else { + return App.Helpers.alert('Failed to suspend'); + } + }); } // do_action_form_help @@ -230,3 +266,56 @@ App.Actions.backup_db = function(evt) { alert('TODO'); } + +App.Actions.add_form_ns = function(evt) +{ + var elm = $(evt.target); + + form = elm.parents('.form:first'); + var total_nses = $(form).find('.ns-entry').length; + if (total_nses == App.Settings.NS_MAX) { + return App.Helpers.alert('Maximum number of NS cannot be more than ' + App.Settings.NS_MAX); + } + + var tpl = App.Templates.get('NS_INPUT', 'user'); + tpl.set(':NAME', ''); + tpl.set(':NS_LABEL', 'NS'); + elm.before(tpl.finalize()); + + if ((total_nses + 1) == App.Settings.NS_MAX ) { // added last NS + $('.additional-ns-add', form).addClass('hidden'); + } + + $(form).find('.ns-entry').each(function(i, o) + { + $(o).find('label').text('NS #' + (i + 1)); + $(o).find('input').attr('name', 'NS' + (i + 1)); + }); +} + +App.Actions.delete_ns = function(evt) +{ + var elm = $(evt.target); + + form = elm.parents('.form:first'); + var total_nses = $(form).find('.ns-entry').length; + if (total_nses == App.Settings.NS_MIN) { + return App.Helpers.alert('Minimum number of NS is ' + App.Settings.NS_MIN); + } + + var form = elm.parents('.form:first'); + $(elm).parents('.form:first').find('.additional-ns-add').removeClass('hidden'); + $(elm).parents('.ns-entry').remove(); + + $(form).find('.ns-entry').each(function(i, o) + { + $(o).find('label').text('NS #' + (i + 1)); + $(o).find('input').attr('name', 'NS' + (i + 1)); + }); +} + +App.Actions.view_full_ns_list = function(evt) +{ + var elm = $(evt.target); + App.Helpers.openInnerPopup(elm, $(elm).parents('.prop-box').find('.ns-full-list:first').html()); +} diff --git a/web/js/html.js b/web/js/html.js index 396e3569..64c440d2 100644 --- a/web/js/html.js +++ b/web/js/html.js @@ -1,6 +1,6 @@ App.HTML.setTplKeys = function(tpl, o, empty) { - var empty = empty || '-'; + var empty = empty || ''; fb.log(empty); tpl.set(':source', $.toJSON(o).replace(/'/gi, "\\'")) $(o).each(function(i, object) @@ -12,7 +12,7 @@ App.HTML.setTplKeys = function(tpl, o, empty) tpl.set(':' + key, val || ''); } else { - tpl.set(':' + key, val || '-'); + tpl.set(':' + key, val || ''); } }); }); @@ -138,14 +138,14 @@ App.HTML.Build.ip_entry = function(o) var tpl = App.Templates.get('ENTRY', 'ip'); tpl = App.HTML.setTplKeys(tpl, o); - if (App.Constants.SUSPENDED_YES == o.SUSPENDED) { + /*if (App.Constants.SUSPENDED_YES == o.SUSPENDED) { var sub_tpl = App.Templates.get('SUSPENDED_TPL_ENABLED', 'ip'); } else { var sub_tpl = App.Templates.get('SUSPENDED_TPL_DISABLED', 'ip'); - } + }*/ - tpl.set(':SUSPENDED_TPL', sub_tpl.finalize()); + tpl.set(':SUSPENDED_TPL', ''); return tpl.finalize(); } @@ -163,14 +163,14 @@ App.HTML.Build.dns_entry = function(o, is_new) tpl.set(':DATE', now.format("d.mm.yyyy")); } - if (App.Constants.SUSPENDED_YES == o.SUSPEND) { + /*if (App.Constants.SUSPENDED_YES == o.SUSPEND) { var sub_tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general'); } else { var sub_tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general'); - } + }*/ - tpl.set(':SUSPENDED_TPL', sub_tpl.finalize()); + tpl.set(':SUSPENDED_TPL', ''); return tpl.finalize(); } @@ -190,13 +190,41 @@ App.HTML.Build.user_entry = function(o, key) var tpl = App.Templates.get('ENTRY', 'user'); tpl = App.HTML.setTplKeys(tpl, o); - if (App.Constants.SUSPENDED_YES == o.SUSPENDED) { + /*if (App.Constants.SUSPENDED_YES == o.SUSPENDED) { var sub_tpl = App.Templates.get('SUSPENDED_TPL_SUSPENDED', 'general'); } else { var sub_tpl = App.Templates.get('SUSPENDED_TPL_NOT_SUSPENDED', 'general'); + }*/ + tpl.set(':SUSPENDED_TPL', '');//sub_tpl.finalize()); + + var ns = []; + var ns_full = []; + fb.info(o); + $([1,2,3,4,5,6,7,8]).each(function(i, index) + { + if (o['NS'+index].trim() != '') { + var tpl_ns = App.Templates.get('NS_RECORD', 'user'); + tpl_ns.set(':NAME', o['NS'+index]); + var tpl_finalized = tpl_ns.finalize(); + ns_full[ns_full.length++] = tpl_finalized; + if (i < App.Settings.USER_VISIBLE_NS) { + ns[ns.length++] = tpl_finalized; + } + } + }); + + if (ns_full.length <= App.Settings.USER_VISIBLE_NS) { + tpl.set(':NS', ns.done()); } - tpl.set(':SUSPENDED_TPL', sub_tpl.finalize()); + else { + var ns_custom = App.Templates.get('NS_MINIMIZED', 'user'); + ns_custom.set(':NS_MINI', ns.done()); + ns_custom.set(':NS_FULL', ns_full.done()); + ns_custom.set(':MORE_NUMBER', Math.abs(App.Settings.USER_VISIBLE_NS - ns_full.length)); + tpl.set(':NS', ns_custom.finalize()); + } + return tpl.finalize(); } @@ -220,7 +248,22 @@ App.HTML.Build.user_form = function(options, id) tpl.set(':save_button', 'SAVE'); } - options = !App.Helpers.isEmpty(options) ? options : {'CONTACT':'', 'PASSWORD':'','LOGIN_NAME':'','LNAME':'', 'FNAME':''}; + options = !App.Helpers.isEmpty(options) ? options : App.Empty.USER; + + // NS + var ns = []; + $([3,4,5,6,7,8]).each(function(i, index) + {fb.warn(options); + if (options['NS'+index].trim() != '') { + var tpl_ns = App.Templates.get('NS_INPUT', 'user'); + tpl_ns.set(':NS_LABEL', 'NS #' + (index)); + tpl_ns.set(':NAME', options['NS'+index]); + ns[ns.length++] = tpl_ns.finalize(); + } + }); + ns[ns.length++] = App.Templates.get('PLUS_ONE_NS', 'user').finalize(); + + tpl.set(':NS', ns.done()); tpl = App.HTML.setTplKeys(tpl, options, true); tpl = App.HTML.Build.user_selects(tpl, options); @@ -491,7 +534,7 @@ App.HTML.Build.db_selects = function(tpl, options) App.HTML.Build.ip_selects = function(tpl, options) { // OWNER - var users = App.Env.initialParams.IP.SYS_USERS || ['Skid']; + var users = App.Env.initialParams.IP.SYS_USERS; var opts = App.HTML.Build.options(users, options.OWNER); tpl.set(':owner_options', opts); diff --git a/web/js/model.js b/web/js/model.js index b7a0e5ff..c97828ce 100644 --- a/web/js/model.js +++ b/web/js/model.js @@ -77,6 +77,7 @@ App.Model.add = function(values, source_json) App.Ref.CONTENT..replaceWith(tpl);*/ // todo: reply.data; App.Pages.prepareHTML(); + App.Helpers.updateScreen(); } }); } @@ -114,8 +115,11 @@ App.Model.update = function(values, source_json, elm) App.Helpers.Warn('Changes were not applied'); } else { - var tpl = App.HTML.Build[build_method](reply.data); + /*var tpl = App.HTML.Build[build_method](reply.data); $(elm).replaceWith(tpl); + App.Helpers.updateScreen();*/ + // todo: reply.data; + App.Pages.prepareHTML(); App.Helpers.updateScreen(); } // TODO: ! diff --git a/web/js/templates.js b/web/js/templates.js index d8c2e2b6..a69f585a 100644 --- a/web/js/templates.js +++ b/web/js/templates.js @@ -32,7 +32,7 @@ App.Templates.html = { select_option: [''], error_elm: ['
~!:ERROR~!
'], SUSPENDED_TPL_NOT_SUSPENDED : ['enabled'], - SUSPENDED_TPL_SUSPENDED : ['disabled'] + SUSPENDED_TPL_SUSPENDED : ['suspended'] }, popup: { error: ['

Important: An Error Has Occured.


    Something went wrong and some of your actions can be not saved in system. Mostly, it happens when you have network connection errors.
,    However, please notify us about the situation. It would be helpfull if you will write us approximate time the error occured and last actions you were performing. You send your petition on this email: BLABLA,

Sorry for inconvinience. (We recommend you to reload the page)
'] @@ -47,17 +47,17 @@ App.Templates.html = { \ \
~!:title~!
\ -
\ + \
\ \ \ - \ + \
\
\ \
\ - \ + \  \
\
\ @@ -71,11 +71,11 @@ App.Templates.html = {
\
\ \ - \ + \
\
\ \ - \ + \
\
\ \ @@ -171,11 +171,11 @@ App.Templates.html = { \ \
~!:title~!
\ -
\ + \
\ \ - \ + \
\
\ \ @@ -192,7 +192,7 @@ App.Templates.html = {
\
\ \ - \ + \
\
\ \ @@ -276,12 +276,24 @@ App.Templates.html = { SUSPENDED_TPL_DISABLED : ['suspended'] }, user: { + NS_MINIMIZED: ['~!:NS_MINI~!\ + \ + ~!:MORE_NUMBER~! more\ + '], + /*NS_RECORD_POPUP_WRAP: ['
    ~!:CONTENT~!
'], + NS_RECORD_POPUP: ['
  • ~!:NAME~!
  • '],*/ + NS_RECORD: ['~!:NAME~!'], + NS_INPUT: ['
    \ + \ + \ +
    '], + PLUS_ONE_NS: [''], ENTRIES_WRAPPER: ['
    ~!:content~!
    '], - FORM: ['
    \ + FORM: ['
    \ \ \
    ~!:title~!
    \ -
    \ + \
    \ \ @@ -320,20 +332,21 @@ App.Templates.html = {
    \
    \ \ - \ + \
    \
    \ \ - \ + \
    \ -